JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java
1/*
2 * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser.
3 * Copyright (C) 2011, 2013-2020 The JavaParser Team.
4 *
5 * This file is part of JavaParser.
6 *
7 * JavaParser can be used either under the terms of
8 * a) the GNU Lesser General Public License as published by
9 *     the Free Software Foundation, either version 3 of the License, or
10 *     (at your option) any later version.
11 * b) the terms of the Apache License
12 *
13 * You should have received a copy of both licenses in LICENCE.LGPL and
14 * LICENCE.APACHE. Please refer to those files for details.
15 *
16 * JavaParser is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 */
21package com.github.javaparser.ast.visitor;
22
23import com.github.javaparser.ast.*;
24import com.github.javaparser.ast.body.*;
25import com.github.javaparser.ast.comments.BlockComment;
26import com.github.javaparser.ast.comments.JavadocComment;
27import com.github.javaparser.ast.comments.LineComment;
28import com.github.javaparser.ast.expr.*;
29import com.github.javaparser.ast.modules.*;
30import com.github.javaparser.ast.stmt.*;
31import com.github.javaparser.ast.type.*;
32
33public class NoCommentHashCodeVisitor implements GenericVisitor<IntegerVoid> {
34
35    private static final NoCommentHashCodeVisitor SINGLETON = new NoCommentHashCodeVisitor();
36
37    public static int hashCode(final Node node) {
38        return node.accept(SINGLETONnull);
39    }
40
41    public Integer visit(final AnnotationDeclaration nfinal Void arg) {
42        return (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
43    }
44
45    public Integer visit(final AnnotationMemberDeclaration nfinal Void arg) {
46        return (n.getDefaultValue().isPresent() ? n.getDefaultValue().get().accept(this, arg) : 0) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
47    }
48
49    public Integer visit(final ArrayAccessExpr nfinal Void arg) {
50        return (n.getIndex().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
51    }
52
53    public Integer visit(final ArrayCreationExpr nfinal Void arg) {
54        return (n.getElementType().accept(this, arg)) * 31 + (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getLevels().accept(this, arg));
55    }
56
57    public Integer visit(final ArrayCreationLevel nfinal Void arg) {
58        return (n.getAnnotations().accept(this, arg)) * 31 + (n.getDimension().isPresent() ? n.getDimension().get().accept(this, arg) : 0);
59    }
60
61    public Integer visit(final ArrayInitializerExpr nfinal Void arg) {
62        return (n.getValues().accept(this, arg));
63    }
64
65    public Integer visit(final ArrayType nfinal Void arg) {
66        return (n.getComponentType().accept(this, arg)) * 31 + (n.getOrigin().hashCode()) * 31 + (n.getAnnotations().accept(this, arg));
67    }
68
69    public Integer visit(final AssertStmt nfinal Void arg) {
70        return (n.getCheck().accept(this, arg)) * 31 + (n.getMessage().isPresent() ? n.getMessage().get().accept(this, arg) : 0);
71    }
72
73    public Integer visit(final AssignExpr nfinal Void arg) {
74        return (n.getOperator().hashCode()) * 31 + (n.getTarget().accept(this, arg)) * 31 + (n.getValue().accept(this, arg));
75    }
76
77    public Integer visit(final BinaryExpr nfinal Void arg) {
78        return (n.getLeft().accept(this, arg)) * 31 + (n.getOperator().hashCode()) * 31 + (n.getRight().accept(this, arg));
79    }
80
81    public Integer visit(final BlockComment nfinal Void arg) {
82        return 0;
83    }
84
85    public Integer visit(final BlockStmt nfinal Void arg) {
86        return (n.getStatements().accept(this, arg));
87    }
88
89    public Integer visit(final BooleanLiteralExpr nfinal Void arg) {
90        return (n.isValue() ? 1 : 0);
91    }
92
93    public Integer visit(final BreakStmt nfinal Void arg) {
94        return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0);
95    }
96
97    public Integer visit(final CastExpr nfinal Void arg) {
98        return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg));
99    }
100
101    public Integer visit(final CatchClause nfinal Void arg) {
102        return (n.getBody().accept(this, arg)) * 31 + (n.getParameter().accept(this, arg));
103    }
104
105    public Integer visit(final CharLiteralExpr nfinal Void arg) {
106        return (n.getValue().hashCode());
107    }
108
109    public Integer visit(final ClassExpr nfinal Void arg) {
110        return (n.getType().accept(this, arg));
111    }
112
113    public Integer visit(final ClassOrInterfaceDeclaration nfinal Void arg) {
114        return (n.getExtendedTypes().accept(this, arg)) * 31 + (n.getImplementedTypes().accept(this, arg)) * 31 + (n.isInterface() ? 1 : 0) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
115    }
116
117    public Integer visit(final ClassOrInterfaceType nfinal Void arg) {
118        return (n.getName().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getAnnotations().accept(this, arg));
119    }
120
121    public Integer visit(final CompilationUnit nfinal Void arg) {
122        return (n.getImports().accept(this, arg)) * 31 + (n.getModule().isPresent() ? n.getModule().get().accept(this, arg) : 0) * 31 + (n.getPackageDeclaration().isPresent() ? n.getPackageDeclaration().get().accept(this, arg) : 0) * 31 + (n.getTypes().accept(this, arg));
123    }
124
125    public Integer visit(final ConditionalExpr nfinal Void arg) {
126        return (n.getCondition().accept(this, arg)) * 31 + (n.getElseExpr().accept(this, arg)) * 31 + (n.getThenExpr().accept(this, arg));
127    }
128
129    public Integer visit(final ConstructorDeclaration nfinal Void arg) {
130        return (n.getBody().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
131    }
132
133    public Integer visit(final ContinueStmt nfinal Void arg) {
134        return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0);
135    }
136
137    public Integer visit(final DoStmt nfinal Void arg) {
138        return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg));
139    }
140
141    public Integer visit(final DoubleLiteralExpr nfinal Void arg) {
142        return (n.getValue().hashCode());
143    }
144
145    public Integer visit(final EmptyStmt nfinal Void arg) {
146        return 0;
147    }
148
149    public Integer visit(final EnclosedExpr nfinal Void arg) {
150        return (n.getInner().accept(this, arg));
151    }
152
153    public Integer visit(final EnumConstantDeclaration nfinal Void arg) {
154        return (n.getArguments().accept(this, arg)) * 31 + (n.getClassBody().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
155    }
156
157    public Integer visit(final EnumDeclaration nfinal Void arg) {
158        return (n.getEntries().accept(this, arg)) * 31 + (n.getImplementedTypes().accept(this, arg)) * 31 + (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
159    }
160
161    public Integer visit(final ExplicitConstructorInvocationStmt nfinal Void arg) {
162        return (n.getArguments().accept(this, arg)) * 31 + (n.getExpression().isPresent() ? n.getExpression().get().accept(this, arg) : 0) * 31 + (n.isThis() ? 1 : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0);
163    }
164
165    public Integer visit(final ExpressionStmt nfinal Void arg) {
166        return (n.getExpression().accept(this, arg));
167    }
168
169    public Integer visit(final FieldAccessExpr nfinal Void arg) {
170        return (n.getName().accept(this, arg)) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0);
171    }
172
173    public Integer visit(final FieldDeclaration nfinal Void arg) {
174        return (n.getModifiers().accept(this, arg)) * 31 + (n.getVariables().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
175    }
176
177    public Integer visit(final ForStmt nfinal Void arg) {
178        return (n.getBody().accept(this, arg)) * 31 + (n.getCompare().isPresent() ? n.getCompare().get().accept(this, arg) : 0) * 31 + (n.getInitialization().accept(this, arg)) * 31 + (n.getUpdate().accept(this, arg));
179    }
180
181    public Integer visit(final ForEachStmt nfinal Void arg) {
182        return (n.getBody().accept(this, arg)) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg));
183    }
184
185    public Integer visit(final IfStmt nfinal Void arg) {
186        return (n.getCondition().accept(this, arg)) * 31 + (n.getElseStmt().isPresent() ? n.getElseStmt().get().accept(this, arg) : 0) * 31 + (n.getThenStmt().accept(this, arg));
187    }
188
189    public Integer visit(final ImportDeclaration nfinal Void arg) {
190        return (n.isAsterisk() ? 1 : 0) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getName().accept(this, arg));
191    }
192
193    public Integer visit(final InitializerDeclaration nfinal Void arg) {
194        return (n.getBody().accept(this, arg)) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getAnnotations().accept(this, arg));
195    }
196
197    public Integer visit(final InstanceOfExpr nfinal Void arg) {
198        return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg));
199    }
200
201    public Integer visit(final IntegerLiteralExpr nfinal Void arg) {
202        return (n.getValue().hashCode());
203    }
204
205    public Integer visit(final IntersectionType nfinal Void arg) {
206        return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
207    }
208
209    public Integer visit(final JavadocComment nfinal Void arg) {
210        return 0;
211    }
212
213    public Integer visit(final LabeledStmt nfinal Void arg) {
214        return (n.getLabel().accept(this, arg)) * 31 + (n.getStatement().accept(this, arg));
215    }
216
217    public Integer visit(final LambdaExpr nfinal Void arg) {
218        return (n.getBody().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg));
219    }
220
221    public Integer visit(final LineComment nfinal Void arg) {
222        return 0;
223    }
224
225    public Integer visit(final LocalClassDeclarationStmt nfinal Void arg) {
226        return (n.getClassDeclaration().accept(this, arg));
227    }
228
229    public Integer visit(final LongLiteralExpr nfinal Void arg) {
230        return (n.getValue().hashCode());
231    }
232
233    public Integer visit(final MarkerAnnotationExpr nfinal Void arg) {
234        return (n.getName().accept(this, arg));
235    }
236
237    public Integer visit(final MemberValuePair nfinal Void arg) {
238        return (n.getName().accept(this, arg)) * 31 + (n.getValue().accept(this, arg));
239    }
240
241    public Integer visit(final MethodCallExpr nfinal Void arg) {
242        return (n.getArguments().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0);
243    }
244
245    public Integer visit(final MethodDeclaration nfinal Void arg) {
246        return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getReceiverParameter().isPresent() ? n.getReceiverParameter().get().accept(this, arg) : 0) * 31 + (n.getThrownExceptions().accept(this, arg)) * 31 + (n.getTypeParameters().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
247    }
248
249    public Integer visit(final MethodReferenceExpr nfinal Void arg) {
250        return (n.getIdentifier().hashCode()) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0);
251    }
252
253    public Integer visit(final NameExpr nfinal Void arg) {
254        return (n.getName().accept(this, arg));
255    }
256
257    public Integer visit(final Name nfinal Void arg) {
258        return (n.getIdentifier().hashCode()) * 31 + (n.getQualifier().isPresent() ? n.getQualifier().get().accept(this, arg) : 0);
259    }
260
261    public Integer visit(NodeList nVoid arg) {
262        int result = 0;
263        for (Object node : n) {
264            result += 31 * ((Visitablenode).accept(this, arg);
265        }
266        return result;
267    }
268
269    public Integer visit(final NormalAnnotationExpr nfinal Void arg) {
270        return (n.getPairs().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
271    }
272
273    public Integer visit(final NullLiteralExpr nfinal Void arg) {
274        return 0;
275    }
276
277    public Integer visit(final ObjectCreationExpr nfinal Void arg) {
278        return (n.getAnonymousClassBody().isPresent() ? n.getAnonymousClassBody().get().accept(this, arg) : 0) * 31 + (n.getArguments().accept(this, arg)) * 31 + (n.getScope().isPresent() ? n.getScope().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0);
279    }
280
281    public Integer visit(final PackageDeclaration nfinal Void arg) {
282        return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
283    }
284
285    public Integer visit(final Parameter nfinal Void arg) {
286        return (n.getAnnotations().accept(this, arg)) * 31 + (n.isVarArgs() ? 1 : 0) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getVarArgsAnnotations().accept(this, arg));
287    }
288
289    public Integer visit(final PrimitiveType nfinal Void arg) {
290        return (n.getType().hashCode()) * 31 + (n.getAnnotations().accept(this, arg));
291    }
292
293    public Integer visit(final ReturnStmt nfinal Void arg) {
294        return (n.getExpression().isPresent() ? n.getExpression().get().accept(this, arg) : 0);
295    }
296
297    public Integer visit(final SimpleName nfinal Void arg) {
298        return (n.getIdentifier().hashCode());
299    }
300
301    public Integer visit(final SingleMemberAnnotationExpr nfinal Void arg) {
302        return (n.getMemberValue().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
303    }
304
305    public Integer visit(final StringLiteralExpr nfinal Void arg) {
306        return (n.getValue().hashCode());
307    }
308
309    public Integer visit(final SuperExpr nfinal Void arg) {
310        return (n.getTypeName().isPresent() ? n.getTypeName().get().accept(this, arg) : 0);
311    }
312
313    public Integer visit(final SwitchEntry nfinal Void arg) {
314        return (n.getLabels().accept(this, arg)) * 31 + (n.getStatements().accept(this, arg)) * 31 + (n.getType().hashCode());
315    }
316
317    public Integer visit(final SwitchStmt nfinal Void arg) {
318        return (n.getEntries().accept(this, arg)) * 31 + (n.getSelector().accept(this, arg));
319    }
320
321    public Integer visit(final SynchronizedStmt nfinal Void arg) {
322        return (n.getBody().accept(this, arg)) * 31 + (n.getExpression().accept(this, arg));
323    }
324
325    public Integer visit(final ThisExpr nfinal Void arg) {
326        return (n.getTypeName().isPresent() ? n.getTypeName().get().accept(this, arg) : 0);
327    }
328
329    public Integer visit(final ThrowStmt nfinal Void arg) {
330        return (n.getExpression().accept(this, arg));
331    }
332
333    public Integer visit(final TryStmt nfinal Void arg) {
334        return (n.getCatchClauses().accept(this, arg)) * 31 + (n.getFinallyBlock().isPresent() ? n.getFinallyBlock().get().accept(this, arg) : 0) * 31 + (n.getResources().accept(this, arg)) * 31 + (n.getTryBlock().accept(this, arg));
335    }
336
337    public Integer visit(final TypeExpr nfinal Void arg) {
338        return (n.getType().accept(this, arg));
339    }
340
341    public Integer visit(final TypeParameter nfinal Void arg) {
342        return (n.getName().accept(this, arg)) * 31 + (n.getTypeBound().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
343    }
344
345    public Integer visit(final UnaryExpr nfinal Void arg) {
346        return (n.getExpression().accept(this, arg)) * 31 + (n.getOperator().hashCode());
347    }
348
349    public Integer visit(final UnionType nfinal Void arg) {
350        return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
351    }
352
353    public Integer visit(final UnknownType nfinal Void arg) {
354        return (n.getAnnotations().accept(this, arg));
355    }
356
357    public Integer visit(final VariableDeclarationExpr nfinal Void arg) {
358        return (n.getAnnotations().accept(this, arg)) * 31 + (n.getModifiers().accept(this, arg)) * 31 + (n.getVariables().accept(this, arg));
359    }
360
361    public Integer visit(final VariableDeclarator nfinal Void arg) {
362        return (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg));
363    }
364
365    public Integer visit(final VoidType nfinal Void arg) {
366        return (n.getAnnotations().accept(this, arg));
367    }
368
369    public Integer visit(final WhileStmt nfinal Void arg) {
370        return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg));
371    }
372
373    public Integer visit(final WildcardType nfinal Void arg) {
374        return (n.getExtendedType().isPresent() ? n.getExtendedType().get().accept(this, arg) : 0) * 31 + (n.getSuperType().isPresent() ? n.getSuperType().get().accept(this, arg) : 0) * 31 + (n.getAnnotations().accept(this, arg));
375    }
376
377    public Integer visit(final ModuleDeclaration nfinal Void arg) {
378        return (n.getAnnotations().accept(this, arg)) * 31 + (n.getDirectives().accept(this, arg)) * 31 + (n.isOpen() ? 1 : 0) * 31 + (n.getName().accept(this, arg));
379    }
380
381    public Integer visit(final ModuleRequiresDirective nfinal Void arg) {
382        return (n.getModifiers().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
383    }
384
385    @Override()
386    public Integer visit(final ModuleExportsDirective nfinal Void arg) {
387        return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
388    }
389
390    @Override()
391    public Integer visit(final ModuleProvidesDirective nfinal Void arg) {
392        return (n.getName().accept(this, arg)) * 31 + (n.getWith().accept(this, arg));
393    }
394
395    @Override()
396    public Integer visit(final ModuleUsesDirective nfinal Void arg) {
397        return (n.getName().accept(this, arg));
398    }
399
400    @Override
401    public Integer visit(final ModuleOpensDirective nfinal Void arg) {
402        return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
403    }
404
405    @Override
406    public Integer visit(final UnparsableStmt nfinal Void arg) {
407        return 0;
408    }
409
410    @Override
411    public Integer visit(final ReceiverParameter nfinal Void arg) {
412        return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg));
413    }
414
415    @Override
416    public Integer visit(final VarType nfinal Void arg) {
417        return (n.getAnnotations().accept(this, arg));
418    }
419
420    @Override
421    public Integer visit(final Modifier nfinal Void arg) {
422        return (n.getKeyword().hashCode());
423    }
424
425    @Override
426    public Integer visit(final SwitchExpr nfinal Void arg) {
427        return (n.getEntries().accept(this, arg)) * 31 + (n.getSelector().accept(this, arg));
428    }
429
430    @Override
431    public Integer visit(final YieldStmt nfinal Void arg) {
432        return (n.getExpression().accept(this, arg));
433    }
434
435    @Override
436    public Integer visit(final TextBlockLiteralExpr nfinal Void arg) {
437        return (n.getValue().hashCode());
438    }
439}
440
MembersX
NoCommentHashCodeVisitor:SINGLETON
NoCommentHashCodeVisitor:visit:Block:result
NoCommentHashCodeVisitor:hashCode
NoCommentHashCodeVisitor:visit
Members
X