aboutsummaryrefslogtreecommitdiffstats
path: root/javaparser-core/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'javaparser-core/src/main')
-rw-r--r--javaparser-core/src/main/java-templates/com/github/javaparser/JavaParserBuild.java19
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java217
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java65
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/JavaParser.java522
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/JavaToken.java796
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java152
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java59
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ParseResult.java128
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ParseStart.java65
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java271
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/Position.java140
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/Problem.java117
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/Providers.java111
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/Range.java120
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/TokenRange.java82
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java239
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java47
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java193
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java694
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java56
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java181
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/Modifier.java72
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/Node.java1004
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java542
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.java189
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationDeclaration.java142
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java275
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/BodyDeclaration.java339
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java428
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java286
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java248
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumConstantDeclaration.java239
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumDeclaration.java233
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java307
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/InitializerDeclaration.java174
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java348
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java311
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/ReceiverParameter.java223
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/TypeDeclaration.java246
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java281
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/comments/BlockComment.java126
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java220
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/comments/CommentsCollection.java112
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/comments/JavadocComment.java128
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/comments/LineComment.java125
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/AnnotationExpr.java137
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayAccessExpr.java177
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java281
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayInitializerExpr.java164
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/AssignExpr.java256
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/BinaryExpr.java261
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/BooleanLiteralExpr.java143
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/CastExpr.java180
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/CharLiteralExpr.java163
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/ClassExpr.java154
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/ConditionalExpr.java204
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/DoubleLiteralExpr.java141
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java162
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/Expression.java733
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java262
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/InstanceOfExpr.java181
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/IntegerLiteralExpr.java153
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java236
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralExpr.java104
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralStringValueExpr.java123
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/LongLiteralExpr.java157
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java128
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/MemberValuePair.java157
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java301
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java229
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/Name.java241
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/NameExpr.java165
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/NormalAnnotationExpr.java180
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/NullLiteralExpr.java119
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java355
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/SimpleName.java126
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java150
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/StringLiteralExpr.java173
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java173
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/ThisExpr.java176
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/TypeExpr.java155
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/UnaryExpr.java220
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/expr/VariableDeclarationExpr.java261
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDeclaration.java200
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsStmt.java164
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensStmt.java164
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesStmt.java165
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresStmt.java161
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleStmt.java152
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesStmt.java127
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java214
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java59
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java40
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBody.java38
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java71
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java61
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java40
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java92
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java41
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java88
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java91
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java328
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java73
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithName.java51
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java44
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java28
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java43
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java162
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithRange.java54
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithScope.java41
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java53
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java114
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java90
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java15
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java40
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithType.java78
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java83
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java60
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java161
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java20
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java9
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java20
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java20
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java20
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java21
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java22
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java20
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserver.java70
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserverAdapter.java48
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/observer/Observable.java44
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java298
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/observer/PropagatingAstObserver.java118
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java202
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java162
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java175
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/CatchClause.java169
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java177
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java181
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/EmptyStmt.java117
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java299
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExpressionStmt.java153
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java290
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForeachStmt.java211
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java260
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LabeledStmt.java181
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java157
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java178
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/Statement.java481
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java224
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchStmt.java214
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SynchronizedStmt.java181
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ThrowStmt.java154
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/TryStmt.java321
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/UnparsableStmt.java103
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java181
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java293
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java302
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/IntersectionType.java186
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/PrimitiveType.java247
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/ReferenceType.java110
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/Type.java371
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/TypeParameter.java246
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/UnionType.java195
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/UnknownType.java147
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/VarType.java134
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/VoidType.java142
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java307
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java10Validator.java19
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java11Validator.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_0Validator.java121
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_1Validator.java22
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_2Validator.java17
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_3Validator.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_4Validator.java11
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java5Validator.java52
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java6Validator.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java7Validator.java39
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java8Validator.java32
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java9Validator.java30
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/NoProblemsValidator.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/ProblemReporter.java34
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/ReservedKeywordValidator.java36
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/SimpleValidator.java20
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java24
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/TreeVisitorValidator.java22
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/TypedValidator.java24
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validator.java15
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validators.java45
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/VisitorValidator.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/CommonValidators.java70
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/ModifierValidator.java211
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java27
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java27
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java27
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/VarValidator.java93
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java1080
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java1389
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java2061
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java319
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java2054
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java603
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java518
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java1297
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java1154
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java510
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java596
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java510
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeVisitor.java111
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/Visitable.java44
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java314
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java773
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java599
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java167
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java163
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java119
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java31
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java122
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java67
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationExprMetaModel.java17
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayInitializerExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayTypeMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/AssertStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/AssignExprMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java180
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/BinaryExprMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/BlockCommentMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/BlockStmtMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/BodyDeclarationMetaModel.java17
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/BooleanLiteralExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/BreakStmtMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/CallableDeclarationMetaModel.java27
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/CastExprMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/CatchClauseMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/CharLiteralExprMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassOrInterfaceDeclarationMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassOrInterfaceTypeMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/CommentMetaModel.java17
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/CompilationUnitMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ConditionalExprMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ConstructorDeclarationMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ContinueStmtMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/DoStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/DoubleLiteralExprMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/EmptyStmtMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/EnclosedExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/EnumConstantDeclarationMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/EnumDeclarationMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ExplicitConstructorInvocationStmtMetaModel.java20
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ExpressionMetaModel.java15
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ExpressionStmtMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/FieldAccessExprMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/FieldDeclarationMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ForStmtMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ForeachStmtMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/IfStmtMetaModel.java24
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ImportDeclarationMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/InitializerDeclarationMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/InstanceOfExprMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/IntegerLiteralExprMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java17
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/IntersectionTypeMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/JavaParserMetaModel.java977
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/JavadocCommentMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/LabeledStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/LambdaExprMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/LineCommentMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/LiteralExprMetaModel.java15
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/LiteralStringValueExprMetaModel.java17
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/LocalClassDeclarationStmtMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/LongLiteralExprMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/MarkerAnnotationExprMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/MemberValuePairMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodCallExprMetaModel.java20
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodDeclarationMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodReferenceExprMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleDeclarationMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleExportsStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleOpensStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleProvidesStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleRequiresStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleStmtMetaModel.java15
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleUsesStmtMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/NameExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/NameMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/NodeMetaModel.java17
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/NormalAnnotationExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/NullLiteralExprMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ObjectCreationExprMetaModel.java22
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/PackageDeclarationMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ParameterMetaModel.java22
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/PrimitiveTypeMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java248
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ReceiverParameterMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ReferenceTypeMetaModel.java15
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ReturnStmtMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/SimpleNameMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/SingleMemberAnnotationExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/StatementMetaModel.java15
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/StringLiteralExprMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/SuperExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/SwitchEntryStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/SwitchStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/SynchronizedStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ThisExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/ThrowStmtMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/TryStmtMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeDeclarationMetaModel.java21
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeExprMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeMetaModel.java17
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeParameterMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/UnaryExprMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/UnionTypeMetaModel.java12
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/UnknownTypeMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/UnparsableStmtMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/VarTypeMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/VariableDeclarationExprMetaModel.java18
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/VariableDeclaratorMetaModel.java16
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/VoidTypeMetaModel.java10
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/WhileStmtMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/metamodel/WildcardTypeMetaModel.java14
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java953
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java106
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/JsonPrinter.java74
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java1609
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java45
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinterConfiguration.java188
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/Printable.java28
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java153
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java77
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java101
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java79
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmChar.java41
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmComment.java57
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java115
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java145
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java43
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java120
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java54
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java34
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java59
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java51
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java47
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java47
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java117
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java43
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java41
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java104
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java885
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java332
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java507
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java217
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java74
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java62
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java189
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java28
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java45
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java115
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java29
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java37
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java35
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java44
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java15
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java40
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java38
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java192
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java26
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java42
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java53
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java38
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java32
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java32
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java85
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java36
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java98
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java30
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java45
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java51
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java58
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java54
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java159
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedParameterDeclaration.java57
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java246
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java200
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java305
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java49
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java39
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java113
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java81
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java65
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java128
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java451
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java192
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java30
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java129
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java79
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java49
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java183
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java72
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java146
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java31
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java88
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java137
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/Log.java122
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java64
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java153
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java45
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java577
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java169
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java435
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java253
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java303
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java125
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java191
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/version/Java10PostProcessor.java24
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/version/Java11PostProcessor.java7
-rw-r--r--javaparser-core/src/main/java/com/github/javaparser/version/PostProcessors.java49
-rw-r--r--javaparser-core/src/main/javacc-support/com/github/javaparser/GeneratedJavaParserBase.java369
-rw-r--r--javaparser-core/src/main/javacc-support/com/github/javaparser/GeneratedJavaParserTokenManagerBase.java46
-rw-r--r--javaparser-core/src/main/javacc-support/com/github/javaparser/ModifierHolder.java24
-rw-r--r--javaparser-core/src/main/javacc-support/com/github/javaparser/RangedList.java33
-rw-r--r--javaparser-core/src/main/javacc-support/com/github/javaparser/TokenBase.java18
-rw-r--r--javaparser-core/src/main/javacc/java.jj2795
433 files changed, 65828 insertions, 0 deletions
diff --git a/javaparser-core/src/main/java-templates/com/github/javaparser/JavaParserBuild.java b/javaparser-core/src/main/java-templates/com/github/javaparser/JavaParserBuild.java
new file mode 100644
index 000000000..2e0ee9c8a
--- /dev/null
+++ b/javaparser-core/src/main/java-templates/com/github/javaparser/JavaParserBuild.java
@@ -0,0 +1,19 @@
+package com.github.javaparser;
+
+/**
+ * Some information that was available when this library was built by Maven.
+ */
+public class JavaParserBuild {
+ public static final String PROJECT_VERSION = "${project.version}";
+ public static final String PROJECT_NAME = "${project.name}";
+ public static final String PROJECT_BUILD_FINAL_NAME = "${project.build.finalName}";
+ public static final String MAVEN_VERSION = "${maven.version}";
+ public static final String MAVEN_BUILD_VERSION = "${maven.build.version}";
+ public static final String MAVEN_BUILD_TIMESTAMP = "${build.timestamp}";
+ public static final String JAVA_VENDOR ="${java.vendor}";
+ public static final String JAVA_VENDOR_URL ="${java.vendor.url}";
+ public static final String JAVA_VERSION ="${java.version}";
+ public static final String OS_ARCH ="${os.arch}";
+ public static final String OS_NAME ="${os.name}";
+ public static final String OS_VERSION ="${os.version}";
+} \ No newline at end of file
diff --git a/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java
new file mode 100644
index 000000000..869883cbf
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/CommentsInserter.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.utils.PositionUtils;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION;
+
+/**
+ * Assigns comments to nodes of the AST.
+ *
+ * @author Sebastian Kuerten
+ * @author Júlio Vilmar Gesser
+ */
+class CommentsInserter {
+ private final ParserConfiguration configuration;
+
+ CommentsInserter(ParserConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ /**
+ * Comments are attributed to the thing they comment and are removed from
+ * the comments.
+ */
+ private void insertComments(CompilationUnit cu, TreeSet<Comment> comments) {
+ if (comments.isEmpty())
+ return;
+
+ /* I should sort all the direct children and the comments, if a comment
+ is the first thing then it
+ a comment to the CompilationUnit */
+
+ // FIXME if there is no package it could be also a comment to the following class...
+ // so I could use some heuristics in these cases to distinguish the two
+ // cases
+
+ List<Node> children = cu.getChildNodes();
+
+ Comment firstComment = comments.iterator().next();
+ if (cu.getPackageDeclaration().isPresent()
+ && (children.isEmpty() || PositionUtils.areInOrder(
+ firstComment, cu.getPackageDeclaration().get()))) {
+ cu.setComment(firstComment);
+ comments.remove(firstComment);
+ }
+ }
+
+ /**
+ * This method try to attributes the nodes received to child of the node. It
+ * returns the node that were not attributed.
+ */
+ void insertComments(Node node, TreeSet<Comment> commentsToAttribute) {
+ if (commentsToAttribute.isEmpty())
+ return;
+
+ if (node instanceof CompilationUnit) {
+ insertComments((CompilationUnit) node, commentsToAttribute);
+ }
+
+ // the comments can:
+ // 1) Inside one of the child, then it is the child that have to
+ // associate them
+ // 2) If they are not inside a child they could be preceeding nothing, a
+ // comment or a child
+ // if they preceed a child they are assigned to it, otherweise they
+ // remain "orphans"
+
+ List<Node> children = node.getChildNodes();
+
+ for (Node child : children) {
+ TreeSet<Comment> commentsInsideChild = new TreeSet<>(NODE_BY_BEGIN_POSITION);
+ commentsInsideChild.addAll(
+ commentsToAttribute.stream()
+ .filter(c -> c.getRange().isPresent())
+ .filter(c -> PositionUtils.nodeContains(child, c,
+ configuration.isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution())).collect(Collectors.toList()));
+ commentsToAttribute.removeAll(commentsInsideChild);
+ insertComments(child, commentsInsideChild);
+ }
+
+ attributeLineCommentsOnSameLine(commentsToAttribute, children);
+
+ /* at this point I create an ordered list of all remaining comments and
+ children */
+ Comment previousComment = null;
+ final List<Comment> attributedComments = new LinkedList<>();
+ List<Node> childrenAndComments = new LinkedList<>();
+ // Avoid attributing comments to a meaningless container.
+ childrenAndComments.addAll(children);
+ commentsToAttribute.removeAll(attributedComments);
+
+ childrenAndComments.addAll(commentsToAttribute);
+ PositionUtils.sortByBeginPosition(childrenAndComments,
+ configuration.isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution());
+
+ for (Node thing : childrenAndComments) {
+ if (thing instanceof Comment) {
+ previousComment = (Comment) thing;
+ if (!previousComment.isOrphan()) {
+ previousComment = null;
+ }
+ } else {
+ if (previousComment != null && !thing.getComment().isPresent()) {
+ if (!configuration.isDoNotAssignCommentsPrecedingEmptyLines()
+ || !thereAreLinesBetween(previousComment, thing)) {
+ thing.setComment(previousComment);
+ attributedComments.add(previousComment);
+ previousComment = null;
+ }
+ }
+ }
+ }
+
+ commentsToAttribute.removeAll(attributedComments);
+
+ // all the remaining are orphan nodes
+ for (Comment c : commentsToAttribute) {
+ if (c.isOrphan()) {
+ node.addOrphanComment(c);
+ }
+ }
+ }
+
+ private void attributeLineCommentsOnSameLine(TreeSet<Comment> commentsToAttribute, List<Node> children) {
+ /* I can attribute in line comments to elements preceeding them, if
+ there is something contained in their line */
+ List<Comment> attributedComments = new LinkedList<>();
+ commentsToAttribute.stream()
+ .filter(comment -> comment.getRange().isPresent())
+ .filter(Comment::isLineComment)
+ .forEach(comment -> children.stream()
+ .filter(child -> child.getRange().isPresent())
+ .forEach(child -> {
+ Range commentRange = comment.getRange().get();
+ Range childRange = child.getRange().get();
+ if (childRange.end.line == commentRange.begin.line
+ && attributeLineCommentToNodeOrChild(child,
+ comment.asLineComment())) {
+ attributedComments.add(comment);
+ }
+ }));
+ commentsToAttribute.removeAll(attributedComments);
+ }
+
+ private boolean attributeLineCommentToNodeOrChild(Node node, LineComment lineComment) {
+ if (!node.getRange().isPresent() || !lineComment.getRange().isPresent()) {
+ return false;
+ }
+
+ // The node start and end at the same line as the comment,
+ // let's give to it the comment
+ if (node.getBegin().get().line == lineComment.getBegin().get().line
+ && !node.getComment().isPresent()) {
+ if (!(node instanceof Comment)) {
+ node.setComment(lineComment);
+ }
+ return true;
+ } else {
+ // try with all the children, sorted by reverse position (so the
+ // first one is the nearest to the comment
+ List<Node> children = new LinkedList<>();
+ children.addAll(node.getChildNodes());
+ PositionUtils.sortByBeginPosition(children);
+ Collections.reverse(children);
+
+ for (Node child : children) {
+ if (attributeLineCommentToNodeOrChild(child, lineComment)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+
+ private boolean thereAreLinesBetween(Node a, Node b) {
+ if (!a.getRange().isPresent() || !b.getRange().isPresent()) {
+ return true;
+ }
+ if (!PositionUtils.areInOrder(a, b)) {
+ return thereAreLinesBetween(b, a);
+ }
+ int endOfA = a.getEnd().get().line;
+ return b.getBegin().get().line > endOfA + 1;
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java
new file mode 100644
index 000000000..03df0d66f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/HasParentNode.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.Observable;
+
+import java.util.Optional;
+
+/**
+ * An object that has a parent node.
+ */
+public interface HasParentNode<T> extends Observable {
+
+ /**
+ * Return the parent node or null, if no parent is set.
+ */
+ Optional<Node> getParentNode();
+
+ /**
+ * Set the parent node.
+ *
+ * @param parentNode the parent node or null, to set no parent
+ * @return return <i>this</i>
+ */
+ T setParentNode(Node parentNode);
+
+ /**
+ * <i>this</i> for everything except NodeLists. NodeLists use their parent as their children parent.
+ */
+ Node getParentNodeForChildren();
+
+ /**
+ * Get the ancestor of the node having the given type, or null if no ancestor of the given type is found.
+ */
+ default <N> Optional<N> getAncestorOfType(Class<N> classType) {
+ Node parent = getParentNode().orElse(null);
+ while (parent != null) {
+ if (classType.isAssignableFrom(parent.getClass())) {
+ return Optional.of(classType.cast(parent));
+ }
+ parent = parent.getParentNode().orElse(null);
+ }
+ return Optional.empty();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java
new file mode 100644
index 000000000..7b8ee87a5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/JavaParser.java
@@ -0,0 +1,522 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.ImportDeclaration;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.PackageDeclaration;
+import com.github.javaparser.ast.body.BodyDeclaration;
+import com.github.javaparser.ast.body.Parameter;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
+import com.github.javaparser.ast.stmt.Statement;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.javadoc.Javadoc;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.file.Path;
+
+import static com.github.javaparser.ParseStart.*;
+import static com.github.javaparser.Problem.PROBLEM_BY_BEGIN_POSITION;
+import static com.github.javaparser.Providers.*;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * Parse Java source code and creates Abstract Syntax Trees.
+ *
+ * @author Júlio Vilmar Gesser
+ */
+public final class JavaParser {
+ private final ParserConfiguration configuration;
+
+ private GeneratedJavaParser astParser = null;
+ private static ParserConfiguration staticConfiguration = new ParserConfiguration();
+
+ /**
+ * Instantiate the parser with default configuration. Note that parsing can also be done with the static methods on
+ * this class.
+ * Creating an instance will reduce setup time between parsing files.
+ */
+ public JavaParser() {
+ this(new ParserConfiguration());
+ }
+
+ /**
+ * Instantiate the parser. Note that parsing can also be done with the static methods on this class.
+ * Creating an instance will reduce setup time between parsing files.
+ */
+ public JavaParser(ParserConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ /**
+ * Get the configuration for the static parse... methods.
+ * This is a STATIC field, so modifying it will directly change how all static parse... methods work!
+ */
+ public static ParserConfiguration getStaticConfiguration() {
+ return staticConfiguration;
+ }
+
+ /**
+ * Set the configuration for the static parse... methods.
+ * This is a STATIC field, so modifying it will directly change how all static parse... methods work!
+ */
+ public static void setStaticConfiguration(ParserConfiguration staticConfiguration) {
+ JavaParser.staticConfiguration = staticConfiguration;
+ }
+
+ /**
+ * Get the non-static configuration for this parser.
+ *
+ * @return The non-static configuration for this parser.
+ */
+ public ParserConfiguration getParserConfiguration() {
+ return this.configuration;
+ }
+
+ private GeneratedJavaParser getParserForProvider(Provider provider) {
+ if (astParser == null) {
+ astParser = new GeneratedJavaParser(provider);
+ } else {
+ astParser.reset(provider);
+ }
+ astParser.setTabSize(configuration.getTabSize());
+ astParser.setStoreTokens(configuration.isStoreTokens());
+ return astParser;
+ }
+
+ /**
+ * Parses source code.
+ * It takes the source code from a Provider.
+ * The start indicates what can be found in the source code (compilation unit, block, import...)
+ *
+ * @param start refer to the constants in ParseStart to see what can be parsed.
+ * @param provider refer to Providers to see how you can read source. The provider will be closed after parsing.
+ * @param <N> the subclass of Node that is the result of parsing in the start.
+ * @return the parse result, a collection of encountered problems, and some extra data.
+ */
+ public <N extends Node> ParseResult<N> parse(ParseStart<N> start, Provider provider) {
+ assertNotNull(start);
+ assertNotNull(provider);
+ final GeneratedJavaParser parser = getParserForProvider(provider);
+ try {
+ N resultNode = start.parse(parser);
+ ParseResult<N> result = new ParseResult<>(resultNode, parser.problems, parser.getTokens(),
+ parser.getCommentsCollection());
+
+ configuration.getPostProcessors().forEach(postProcessor ->
+ postProcessor.process(result, configuration));
+
+ result.getProblems().sort(PROBLEM_BY_BEGIN_POSITION);
+
+ return result;
+ } catch (Exception e) {
+ final String message = e.getMessage() == null ? "Unknown error" : e.getMessage();
+ parser.problems.add(new Problem(message, null, e));
+ return new ParseResult<>(null, parser.problems, parser.getTokens(), parser.getCommentsCollection());
+ } finally {
+ try {
+ provider.close();
+ } catch (IOException e) {
+ // Since we're done parsing and have our result, we don't care about any errors.
+ }
+ }
+ }
+
+ /**
+ * Parses the Java code contained in the {@link InputStream} and returns a
+ * {@link CompilationUnit} that represents it.
+ *
+ * @param in {@link InputStream} containing Java source code. It will be closed after parsing.
+ * @param encoding encoding of the source code
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static CompilationUnit parse(final InputStream in, Charset encoding) {
+ return simplifiedParse(COMPILATION_UNIT, provider(in, encoding));
+ }
+
+ /**
+ * Parses the Java code contained in the {@link InputStream} and returns a
+ * {@link CompilationUnit} that represents it.<br>
+ * Note: Uses UTF-8 encoding
+ *
+ * @param in {@link InputStream} containing Java source code. It will be closed after parsing.
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static CompilationUnit parse(final InputStream in) {
+ return parse(in, UTF8);
+ }
+
+ /**
+ * Parses the Java code contained in a {@link File} and returns a
+ * {@link CompilationUnit} that represents it.
+ *
+ * @param file {@link File} containing Java source code. It will be closed after parsing.
+ * @param encoding encoding of the source code
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ * @throws FileNotFoundException the file was not found
+ */
+ public static CompilationUnit parse(final File file, final Charset encoding) throws FileNotFoundException {
+ return simplifiedParse(COMPILATION_UNIT, provider(file, encoding)).setStorage(file.toPath());
+ }
+
+ /**
+ * Parses the Java code contained in a {@link File} and returns a
+ * {@link CompilationUnit} that represents it.<br>
+ * Note: Uses UTF-8 encoding
+ *
+ * @param file {@link File} containing Java source code. It will be closed after parsing.
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ * @throws FileNotFoundException the file was not found
+ */
+ public static CompilationUnit parse(final File file) throws FileNotFoundException {
+ return simplifiedParse(COMPILATION_UNIT, provider(file)).setStorage(file.toPath());
+ }
+
+ /**
+ * Parses the Java code contained in a file and returns a
+ * {@link CompilationUnit} that represents it.
+ *
+ * @param path path to a file containing Java source code
+ * @param encoding encoding of the source code
+ * @return CompilationUnit representing the Java source code
+ * @throws IOException the path could not be accessed
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static CompilationUnit parse(final Path path, final Charset encoding) throws IOException {
+ return simplifiedParse(COMPILATION_UNIT, provider(path, encoding)).setStorage(path);
+ }
+
+ /**
+ * Parses the Java code contained in a file and returns a
+ * {@link CompilationUnit} that represents it.<br>
+ * Note: Uses UTF-8 encoding
+ *
+ * @param path path to a file containing Java source code
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ * @throws IOException the path could not be accessed
+ */
+ public static CompilationUnit parse(final Path path) throws IOException {
+ return simplifiedParse(COMPILATION_UNIT, provider(path)).setStorage(path);
+ }
+
+ /**
+ * Parses the Java code contained in a resource and returns a
+ * {@link CompilationUnit} that represents it.<br>
+ * Note: Uses UTF-8 encoding
+ *
+ * @param path path to a resource containing Java source code. As resource is accessed through a class loader, a
+ * leading "/" is not allowed in pathToResource
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ * @throws IOException the path could not be accessed
+ */
+ public static CompilationUnit parseResource(final String path) throws IOException {
+ return simplifiedParse(COMPILATION_UNIT, resourceProvider(path));
+ }
+
+ /**
+ * Parses the Java code contained in a resource and returns a
+ * {@link CompilationUnit} that represents it.<br>
+ *
+ * @param path path to a resource containing Java source code. As resource is accessed through a class loader, a
+ * leading "/" is not allowed in pathToResource
+ * @param encoding encoding of the source code
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ * @throws IOException the path could not be accessed
+ */
+ public static CompilationUnit parseResource(final String path, Charset encoding) throws IOException {
+ return simplifiedParse(COMPILATION_UNIT, resourceProvider(path, encoding));
+ }
+
+ /**
+ * Parses the Java code contained in a resource and returns a
+ * {@link CompilationUnit} that represents it.<br>
+ *
+ * @param classLoader the classLoader that is asked to load the resource
+ * @param path path to a resource containing Java source code. As resource is accessed through a class loader, a
+ * leading "/" is not allowed in pathToResource
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ * @throws IOException the path could not be accessed
+ */
+ public static CompilationUnit parseResource(final ClassLoader classLoader, final String path, Charset encoding) throws IOException {
+ return simplifiedParse(COMPILATION_UNIT, resourceProvider(classLoader, path, encoding));
+ }
+
+ /**
+ * Parses Java code from a Reader and returns a
+ * {@link CompilationUnit} that represents it.<br>
+ *
+ * @param reader the reader containing Java source code. It will be closed after parsing.
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static CompilationUnit parse(final Reader reader) {
+ return simplifiedParse(COMPILATION_UNIT, provider(reader));
+ }
+
+ /**
+ * Parses the Java code contained in code and returns a
+ * {@link CompilationUnit} that represents it.
+ *
+ * @param code Java source code
+ * @return CompilationUnit representing the Java source code
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static CompilationUnit parse(String code) {
+ return simplifiedParse(COMPILATION_UNIT, provider(code));
+ }
+
+ /**
+ * Parses the Java block contained in a {@link String} and returns a
+ * {@link BlockStmt} that represents it.
+ *
+ * @param blockStatement {@link String} containing Java block code
+ * @return BlockStmt representing the Java block
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static BlockStmt parseBlock(final String blockStatement) {
+ return simplifiedParse(BLOCK, provider(blockStatement));
+ }
+
+ /**
+ * Parses the Java statement contained in a {@link String} and returns a
+ * {@link Statement} that represents it.
+ *
+ * @param statement {@link String} containing Java statement code
+ * @return Statement representing the Java statement
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static Statement parseStatement(final String statement) {
+ return simplifiedParse(STATEMENT, provider(statement));
+ }
+
+ private static <T extends Node> T simplifiedParse(ParseStart<T> context, Provider provider) {
+ ParseResult<T> result = new JavaParser(staticConfiguration).parse(context, provider);
+ if (result.isSuccessful()) {
+ return result.getResult().get();
+ }
+ throw new ParseProblemException(result.getProblems());
+ }
+
+ /**
+ * Parses the Java import contained in a {@link String} and returns a
+ * {@link ImportDeclaration} that represents it.
+ *
+ * @param importDeclaration {@link String} containing Java import code
+ * @return ImportDeclaration representing the Java import declaration
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static ImportDeclaration parseImport(final String importDeclaration) {
+ return simplifiedParse(IMPORT_DECLARATION, provider(importDeclaration));
+ }
+
+ /**
+ * Parses the Java expression contained in a {@link String} and returns a
+ * {@link Expression} that represents it.
+ *
+ * @param expression {@link String} containing Java expression
+ * @return Expression representing the Java expression
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends Expression> T parseExpression(final String expression) {
+ return (T) simplifiedParse(EXPRESSION, provider(expression));
+ }
+
+ /**
+ * Parses the Java annotation contained in a {@link String} and returns a
+ * {@link AnnotationExpr} that represents it.
+ *
+ * @param annotation {@link String} containing Java annotation
+ * @return AnnotationExpr representing the Java annotation
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static AnnotationExpr parseAnnotation(final String annotation) {
+ return simplifiedParse(ANNOTATION, provider(annotation));
+ }
+
+ /**
+ * Parses the Java annotation body declaration(e.g fields or methods) contained in a
+ * {@link String} and returns a {@link BodyDeclaration} that represents it.
+ *
+ * @param body {@link String} containing Java body declaration
+ * @return BodyDeclaration representing the Java annotation
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static BodyDeclaration<?> parseAnnotationBodyDeclaration(final String body) {
+ return simplifiedParse(ANNOTATION_BODY, provider(body));
+ }
+
+ /**
+ * Parses a Java class body declaration(e.g fields or methods) and returns a
+ * {@link BodyDeclaration} that represents it.
+ *
+ * @param body the body of a class
+ * @return BodyDeclaration representing the Java class body
+ * @throws ParseProblemException if the source code has parser errors
+ * @deprecated just use parseBodyDeclaration now.
+ */
+ @Deprecated
+ public static BodyDeclaration<?> parseClassBodyDeclaration(String body) {
+ return parseBodyDeclaration(body);
+ }
+
+ /**
+ * Parses a Java interface body declaration(e.g fields or methods) and returns a
+ * {@link BodyDeclaration} that represents it.
+ *
+ * @param body the body of an interface
+ * @return BodyDeclaration representing the Java interface body
+ * @throws ParseProblemException if the source code has parser errors
+ * @deprecated just use parseBodyDeclaration now.
+ */
+ @Deprecated
+ public static BodyDeclaration<?> parseInterfaceBodyDeclaration(String body) {
+ return parseBodyDeclaration(body);
+ }
+
+ /**
+ * Parses a Java class or interface body declaration(e.g fields or methods) and returns a
+ * {@link BodyDeclaration} that represents it.
+ *
+ * @param body the body of a class or interface
+ * @return BodyDeclaration representing the Java interface body
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static BodyDeclaration<?> parseBodyDeclaration(String body) {
+ return simplifiedParse(CLASS_BODY, provider(body));
+ }
+
+ /**
+ * Parses a Java class or interface type name and returns a {@link ClassOrInterfaceType} that represents it.
+ *
+ * @param type the type name like a.b.c.X or Y
+ * @return ClassOrInterfaceType representing the type
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static ClassOrInterfaceType parseClassOrInterfaceType(String type) {
+ return simplifiedParse(CLASS_OR_INTERFACE_TYPE, provider(type));
+ }
+
+ /**
+ * Parses a Java type name and returns a {@link Type} that represents it.
+ *
+ * @param type the type name like a.b.c.X, Y, or int
+ * @return ClassOrInterfaceType representing the type
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static Type parseType(String type) {
+ return simplifiedParse(TYPE, provider(type));
+ }
+
+ /**
+ * Parses a variable declaration expression and returns a {@link com.github.javaparser.ast.expr.VariableDeclarationExpr}
+ * that represents it.
+ *
+ * @param declaration a variable declaration like <code>int x=2;</code>
+ * @return VariableDeclarationExpr representing the type
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static VariableDeclarationExpr parseVariableDeclarationExpr(String declaration) {
+ return simplifiedParse(VARIABLE_DECLARATION_EXPR, provider(declaration));
+ }
+
+ /**
+ * Parses the content of a JavadocComment and returns a {@link com.github.javaparser.javadoc.Javadoc} that
+ * represents it.
+ *
+ * @param content a variable declaration like <code>content of my javadoc\n * second line\n * third line</code>
+ * @return Javadoc representing the content of the comment
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static Javadoc parseJavadoc(String content) {
+ return JavadocParser.parse(content);
+ }
+
+ /**
+ * Parses the this(...) and super(...) statements that may occur at the start of a constructor.
+ *
+ * @param statement a statement like super("hello");
+ * @return the AST for the statement.
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static ExplicitConstructorInvocationStmt parseExplicitConstructorInvocationStmt(String statement) {
+ return simplifiedParse(EXPLICIT_CONSTRUCTOR_INVOCATION_STMT, provider(statement));
+ }
+
+ /**
+ * Parses a qualified name (one that can have "."s in it) and returns it as a Name.
+ *
+ * @param qualifiedName a name like "com.laamella.parameter_source"
+ * @return the AST for the name
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static Name parseName(String qualifiedName) {
+ return simplifiedParse(NAME, provider(qualifiedName));
+ }
+
+ /**
+ * Parses a simple name (one that can NOT have "."s in it) and returns it as a SimpleName.
+ *
+ * @param name a name like "parameter_source"
+ * @return the AST for the name
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static SimpleName parseSimpleName(String name) {
+ return simplifiedParse(SIMPLE_NAME, provider(name));
+ }
+
+ /**
+ * Parses a single parameter (a type and a name) and returns it as a Parameter.
+ *
+ * @param parameter a parameter like "int[] x"
+ * @return the AST for the parameter
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static Parameter parseParameter(String parameter) {
+ return simplifiedParse(PARAMETER, provider(parameter));
+ }
+
+
+ /**
+ * Parses a package declaration and returns it as a PackageDeclaration.
+ *
+ * @param packageDeclaration a declaration like "package com.microsoft.java;"
+ * @return the AST for the parameter
+ * @throws ParseProblemException if the source code has parser errors
+ */
+ public static PackageDeclaration parsePackageDeclaration(String packageDeclaration) {
+ return simplifiedParse(PACKAGE_DECLARATION, provider(packageDeclaration));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavaToken.java b/javaparser-core/src/main/java/com/github/javaparser/JavaToken.java
new file mode 100644
index 000000000..ad56ff5d7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/JavaToken.java
@@ -0,0 +1,796 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser;
+
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+import static com.github.javaparser.utils.Utils.EOL;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+
+/**
+ * A token from a parsed source file.
+ * (Awkwardly named "Java"Token since JavaCC already generates an internal class Token.)
+ * It is a node in a double linked list called token list.
+ */
+public class JavaToken {
+
+ public static final JavaToken INVALID = new JavaToken();
+
+ private Range range;
+
+ private int kind;
+
+ private String text;
+
+ private JavaToken previousToken = null;
+
+ private JavaToken nextToken = null;
+
+ private JavaToken() {
+ this(null, 0, "INVALID", null, null);
+ }
+
+ public JavaToken(int kind, String text) {
+ this(null, kind, text, null, null);
+ }
+
+ JavaToken(Token token, List<JavaToken> tokens) {
+ // You could be puzzled by the following lines
+ //
+ // The reason why these lines are necessary is the fact that Java is ambiguous. There are cases where the
+ // sequence of characters ">>>" and ">>" should be recognized as the single tokens ">>>" and ">>". In other
+ // cases however we want to split those characters in single GT tokens (">").
+ //
+ // For example, in expressions ">>" and ">>>" are valid, while when defining types we could have this:
+ //
+ // List<List<Set<String>>>>
+ //
+ // You can see that the sequence ">>>>" should be interpreted as four consecutive ">" tokens closing a type
+ // parameter list.
+ //
+ // The JavaCC handle this case by first recognizing always the longest token, and then depending on the context
+ // putting back the unused chars in the stream. However in those cases the token provided is invalid: it has an
+ // image corresponding to the text originally recognized, without considering that after some characters could
+ // have been put back into the stream.
+ //
+ // So in the case of:
+ //
+ // List<List<Set<String>>>>
+ // ___ -> recognized as ">>>", then ">>" put back in the stream but Token(type=GT, image=">>>") passed to this class
+ // ___ -> recognized as ">>>", then ">>" put back in the stream but Token(type=GT, image=">>>") passed to this class
+ // __ -> recognized as ">>", then ">" put back in the stream but Token(type=GT, image=">>") passed to this class
+ // _ -> Token(type=GT, image=">") good!
+ //
+ // So given the image could be wrong but the type is correct, we look at the type of the token and we fix
+ // the image. Everybody is happy and we can keep this horrible thing as our little secret.
+ Range range = Range.range(token.beginLine, token.beginColumn, token.endLine, token.endColumn);
+ String text = token.image;
+ if (token.kind == GeneratedJavaParserConstants.GT) {
+ range = Range.range(token.beginLine, token.beginColumn, token.endLine, token.beginColumn);
+ text = ">";
+ } else if (token.kind == GeneratedJavaParserConstants.RSIGNEDSHIFT) {
+ range = Range.range(token.beginLine, token.beginColumn, token.endLine, token.beginColumn + 1);
+ text = ">>";
+ }
+ this.range = range;
+ this.kind = token.kind;
+ this.text = text;
+ if (!tokens.isEmpty()) {
+ final JavaToken previousToken = tokens.get(tokens.size() - 1);
+ this.previousToken = previousToken;
+ previousToken.nextToken = this;
+ } else {
+ previousToken = null;
+ }
+ }
+
+ /**
+ * Create a token of a certain kind.
+ */
+ public JavaToken(int kind) {
+ String content = GeneratedJavaParserConstants.tokenImage[kind];
+ if (content.startsWith("\"")) {
+ content = content.substring(1, content.length() - 1);
+ }
+ if (TokenTypes.isEndOfLineToken(kind)) {
+ content = EOL;
+ } else if (TokenTypes.isWhitespace(kind)) {
+ content = " ";
+ }
+ this.kind = kind;
+ this.text = content;
+ }
+
+ public JavaToken(Range range, int kind, String text, JavaToken previousToken, JavaToken nextToken) {
+ assertNotNull(text);
+ this.range = range;
+ this.kind = kind;
+ this.text = text;
+ this.previousToken = previousToken;
+ this.nextToken = nextToken;
+ }
+
+ public Optional<Range> getRange() {
+ return Optional.ofNullable(range);
+ }
+
+ public int getKind() {
+ return kind;
+ }
+
+ void setKind(int kind) {
+ this.kind = kind;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public Optional<JavaToken> getNextToken() {
+ return Optional.ofNullable(nextToken);
+ }
+
+ public Optional<JavaToken> getPreviousToken() {
+ return Optional.ofNullable(previousToken);
+ }
+
+ public void setRange(Range range) {
+ this.range = range;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String asString() {
+ return text;
+ }
+
+ /**
+ * @return the token range that goes from the beginning to the end of the token list this token is a part of.
+ */
+ public TokenRange toTokenRange() {
+ return new TokenRange(findFirstToken(), findLastToken());
+ }
+
+ @Override
+ public String toString() {
+ String text = getText().replace("\n", "\\n").replace("\r", "\\r").replace("\r\n", "\\r\\n").replace("\t", "\\t");
+ return f("\"%s\" <%s> %s", text, getKind(), getRange().map(Range::toString).orElse("(?)-(?)"));
+ }
+
+ /**
+ * Used by the parser while constructing nodes. No tokens should be invalid when the parser is done.
+ */
+ public boolean valid() {
+ return !invalid();
+ }
+
+ /**
+ * Used by the parser while constructing nodes. No tokens should be invalid when the parser is done.
+ */
+ public boolean invalid() {
+ return this == INVALID;
+ }
+
+ public enum Category {
+
+ WHITESPACE_NO_EOL,
+ EOL,
+ COMMENT,
+ IDENTIFIER,
+ KEYWORD,
+ LITERAL,
+ SEPARATOR,
+ OPERATOR;
+
+ public boolean isWhitespaceOrComment() {
+ return isWhitespace() || this == COMMENT;
+ }
+
+ public boolean isWhitespace() {
+ return this == WHITESPACE_NO_EOL || this == EOL;
+ }
+
+ public boolean isEndOfLine() {
+ return this == EOL;
+ }
+
+ public boolean isComment() {
+ return this == COMMENT;
+ }
+
+ public boolean isWhitespaceButNotEndOfLine() {
+ return this == WHITESPACE_NO_EOL;
+ }
+
+ public boolean isIdentifier() {
+ return this == IDENTIFIER;
+ }
+
+ public boolean isKeyword() {
+ return this == KEYWORD;
+ }
+
+ public boolean isLiteral() {
+ return this == LITERAL;
+ }
+
+ public boolean isSeparator() {
+ return this == SEPARATOR;
+ }
+
+ public boolean isOperator() {
+ return this == OPERATOR;
+ }
+ }
+
+ @Generated("com.github.javaparser.generator.core.other.TokenKindGenerator")
+ public enum Kind {
+
+ EOF(0),
+ SPACE(1),
+ WINDOWS_EOL(2),
+ UNIX_EOL(3),
+ OLD_MAC_EOL(4),
+ SINGLE_LINE_COMMENT(5),
+ ENTER_JAVADOC_COMMENT(6),
+ ENTER_MULTILINE_COMMENT(7),
+ JAVADOC_COMMENT(8),
+ MULTI_LINE_COMMENT(9),
+ COMMENT_CONTENT(10),
+ ABSTRACT(11),
+ ASSERT(12),
+ BOOLEAN(13),
+ BREAK(14),
+ BYTE(15),
+ CASE(16),
+ CATCH(17),
+ CHAR(18),
+ CLASS(19),
+ CONST(20),
+ CONTINUE(21),
+ _DEFAULT(22),
+ DO(23),
+ DOUBLE(24),
+ ELSE(25),
+ ENUM(26),
+ EXTENDS(27),
+ FALSE(28),
+ FINAL(29),
+ FINALLY(30),
+ FLOAT(31),
+ FOR(32),
+ GOTO(33),
+ IF(34),
+ IMPLEMENTS(35),
+ IMPORT(36),
+ INSTANCEOF(37),
+ INT(38),
+ INTERFACE(39),
+ LONG(40),
+ NATIVE(41),
+ NEW(42),
+ NULL(43),
+ PACKAGE(44),
+ PRIVATE(45),
+ PROTECTED(46),
+ PUBLIC(47),
+ RETURN(48),
+ SHORT(49),
+ STATIC(50),
+ STRICTFP(51),
+ SUPER(52),
+ SWITCH(53),
+ SYNCHRONIZED(54),
+ THIS(55),
+ THROW(56),
+ THROWS(57),
+ TRANSIENT(58),
+ TRUE(59),
+ TRY(60),
+ VOID(61),
+ VOLATILE(62),
+ WHILE(63),
+ REQUIRES(64),
+ TO(65),
+ WITH(66),
+ OPEN(67),
+ OPENS(68),
+ USES(69),
+ MODULE(70),
+ EXPORTS(71),
+ PROVIDES(72),
+ TRANSITIVE(73),
+ LONG_LITERAL(74),
+ INTEGER_LITERAL(75),
+ DECIMAL_LITERAL(76),
+ HEX_LITERAL(77),
+ OCTAL_LITERAL(78),
+ BINARY_LITERAL(79),
+ FLOATING_POINT_LITERAL(80),
+ DECIMAL_FLOATING_POINT_LITERAL(81),
+ DECIMAL_EXPONENT(82),
+ HEXADECIMAL_FLOATING_POINT_LITERAL(83),
+ HEXADECIMAL_EXPONENT(84),
+ HEX_DIGITS(85),
+ UNICODE_ESCAPE(86),
+ CHARACTER_LITERAL(87),
+ STRING_LITERAL(88),
+ IDENTIFIER(89),
+ LETTER(90),
+ PART_LETTER(91),
+ LPAREN(92),
+ RPAREN(93),
+ LBRACE(94),
+ RBRACE(95),
+ LBRACKET(96),
+ RBRACKET(97),
+ SEMICOLON(98),
+ COMMA(99),
+ DOT(100),
+ AT(101),
+ ASSIGN(102),
+ LT(103),
+ BANG(104),
+ TILDE(105),
+ HOOK(106),
+ COLON(107),
+ EQ(108),
+ LE(109),
+ GE(110),
+ NE(111),
+ SC_OR(112),
+ SC_AND(113),
+ INCR(114),
+ DECR(115),
+ PLUS(116),
+ MINUS(117),
+ STAR(118),
+ SLASH(119),
+ BIT_AND(120),
+ BIT_OR(121),
+ XOR(122),
+ REM(123),
+ LSHIFT(124),
+ PLUSASSIGN(125),
+ MINUSASSIGN(126),
+ STARASSIGN(127),
+ SLASHASSIGN(128),
+ ANDASSIGN(129),
+ ORASSIGN(130),
+ XORASSIGN(131),
+ REMASSIGN(132),
+ LSHIFTASSIGN(133),
+ RSIGNEDSHIFTASSIGN(134),
+ RUNSIGNEDSHIFTASSIGN(135),
+ ELLIPSIS(136),
+ ARROW(137),
+ DOUBLECOLON(138),
+ RUNSIGNEDSHIFT(139),
+ RSIGNEDSHIFT(140),
+ GT(141),
+ CTRL_Z(142);
+
+ private final int kind;
+
+ Kind(int kind) {
+ this.kind = kind;
+ }
+
+ public static Kind valueOf(int kind) {
+ switch(kind) {
+ case 142:
+ return CTRL_Z;
+ case 141:
+ return GT;
+ case 140:
+ return RSIGNEDSHIFT;
+ case 139:
+ return RUNSIGNEDSHIFT;
+ case 138:
+ return DOUBLECOLON;
+ case 137:
+ return ARROW;
+ case 136:
+ return ELLIPSIS;
+ case 135:
+ return RUNSIGNEDSHIFTASSIGN;
+ case 134:
+ return RSIGNEDSHIFTASSIGN;
+ case 133:
+ return LSHIFTASSIGN;
+ case 132:
+ return REMASSIGN;
+ case 131:
+ return XORASSIGN;
+ case 130:
+ return ORASSIGN;
+ case 129:
+ return ANDASSIGN;
+ case 128:
+ return SLASHASSIGN;
+ case 127:
+ return STARASSIGN;
+ case 126:
+ return MINUSASSIGN;
+ case 125:
+ return PLUSASSIGN;
+ case 124:
+ return LSHIFT;
+ case 123:
+ return REM;
+ case 122:
+ return XOR;
+ case 121:
+ return BIT_OR;
+ case 120:
+ return BIT_AND;
+ case 119:
+ return SLASH;
+ case 118:
+ return STAR;
+ case 117:
+ return MINUS;
+ case 116:
+ return PLUS;
+ case 115:
+ return DECR;
+ case 114:
+ return INCR;
+ case 113:
+ return SC_AND;
+ case 112:
+ return SC_OR;
+ case 111:
+ return NE;
+ case 110:
+ return GE;
+ case 109:
+ return LE;
+ case 108:
+ return EQ;
+ case 107:
+ return COLON;
+ case 106:
+ return HOOK;
+ case 105:
+ return TILDE;
+ case 104:
+ return BANG;
+ case 103:
+ return LT;
+ case 102:
+ return ASSIGN;
+ case 101:
+ return AT;
+ case 100:
+ return DOT;
+ case 99:
+ return COMMA;
+ case 98:
+ return SEMICOLON;
+ case 97:
+ return RBRACKET;
+ case 96:
+ return LBRACKET;
+ case 95:
+ return RBRACE;
+ case 94:
+ return LBRACE;
+ case 93:
+ return RPAREN;
+ case 92:
+ return LPAREN;
+ case 91:
+ return PART_LETTER;
+ case 90:
+ return LETTER;
+ case 89:
+ return IDENTIFIER;
+ case 88:
+ return STRING_LITERAL;
+ case 87:
+ return CHARACTER_LITERAL;
+ case 86:
+ return UNICODE_ESCAPE;
+ case 85:
+ return HEX_DIGITS;
+ case 84:
+ return HEXADECIMAL_EXPONENT;
+ case 83:
+ return HEXADECIMAL_FLOATING_POINT_LITERAL;
+ case 82:
+ return DECIMAL_EXPONENT;
+ case 81:
+ return DECIMAL_FLOATING_POINT_LITERAL;
+ case 80:
+ return FLOATING_POINT_LITERAL;
+ case 79:
+ return BINARY_LITERAL;
+ case 78:
+ return OCTAL_LITERAL;
+ case 77:
+ return HEX_LITERAL;
+ case 76:
+ return DECIMAL_LITERAL;
+ case 75:
+ return INTEGER_LITERAL;
+ case 74:
+ return LONG_LITERAL;
+ case 73:
+ return TRANSITIVE;
+ case 72:
+ return PROVIDES;
+ case 71:
+ return EXPORTS;
+ case 70:
+ return MODULE;
+ case 69:
+ return USES;
+ case 68:
+ return OPENS;
+ case 67:
+ return OPEN;
+ case 66:
+ return WITH;
+ case 65:
+ return TO;
+ case 64:
+ return REQUIRES;
+ case 63:
+ return WHILE;
+ case 62:
+ return VOLATILE;
+ case 61:
+ return VOID;
+ case 60:
+ return TRY;
+ case 59:
+ return TRUE;
+ case 58:
+ return TRANSIENT;
+ case 57:
+ return THROWS;
+ case 56:
+ return THROW;
+ case 55:
+ return THIS;
+ case 54:
+ return SYNCHRONIZED;
+ case 53:
+ return SWITCH;
+ case 52:
+ return SUPER;
+ case 51:
+ return STRICTFP;
+ case 50:
+ return STATIC;
+ case 49:
+ return SHORT;
+ case 48:
+ return RETURN;
+ case 47:
+ return PUBLIC;
+ case 46:
+ return PROTECTED;
+ case 45:
+ return PRIVATE;
+ case 44:
+ return PACKAGE;
+ case 43:
+ return NULL;
+ case 42:
+ return NEW;
+ case 41:
+ return NATIVE;
+ case 40:
+ return LONG;
+ case 39:
+ return INTERFACE;
+ case 38:
+ return INT;
+ case 37:
+ return INSTANCEOF;
+ case 36:
+ return IMPORT;
+ case 35:
+ return IMPLEMENTS;
+ case 34:
+ return IF;
+ case 33:
+ return GOTO;
+ case 32:
+ return FOR;
+ case 31:
+ return FLOAT;
+ case 30:
+ return FINALLY;
+ case 29:
+ return FINAL;
+ case 28:
+ return FALSE;
+ case 27:
+ return EXTENDS;
+ case 26:
+ return ENUM;
+ case 25:
+ return ELSE;
+ case 24:
+ return DOUBLE;
+ case 23:
+ return DO;
+ case 22:
+ return _DEFAULT;
+ case 21:
+ return CONTINUE;
+ case 20:
+ return CONST;
+ case 19:
+ return CLASS;
+ case 18:
+ return CHAR;
+ case 17:
+ return CATCH;
+ case 16:
+ return CASE;
+ case 15:
+ return BYTE;
+ case 14:
+ return BREAK;
+ case 13:
+ return BOOLEAN;
+ case 12:
+ return ASSERT;
+ case 11:
+ return ABSTRACT;
+ case 10:
+ return COMMENT_CONTENT;
+ case 9:
+ return MULTI_LINE_COMMENT;
+ case 8:
+ return JAVADOC_COMMENT;
+ case 7:
+ return ENTER_MULTILINE_COMMENT;
+ case 6:
+ return ENTER_JAVADOC_COMMENT;
+ case 5:
+ return SINGLE_LINE_COMMENT;
+ case 4:
+ return OLD_MAC_EOL;
+ case 3:
+ return UNIX_EOL;
+ case 2:
+ return WINDOWS_EOL;
+ case 1:
+ return SPACE;
+ case 0:
+ return EOF;
+ default:
+ throw new IllegalArgumentException(f("Token kind %i is unknown.", kind));
+ }
+ }
+
+ public int getKind() {
+ return kind;
+ }
+ }
+
+ public JavaToken.Category getCategory() {
+ return TokenTypes.getCategory(kind);
+ }
+
+ /**
+ * Inserts newToken into the token list just before this token.
+ */
+ public void insert(JavaToken newToken) {
+ assertNotNull(newToken);
+ getPreviousToken().ifPresent(p -> {
+ p.nextToken = newToken;
+ newToken.previousToken = p;
+ });
+ previousToken = newToken;
+ newToken.nextToken = this;
+ }
+
+ /**
+ * Inserts newToken into the token list just after this token.
+ */
+ public void insertAfter(JavaToken newToken) {
+ assertNotNull(newToken);
+ getNextToken().ifPresent(n -> {
+ n.previousToken = newToken;
+ newToken.nextToken = n;
+ });
+ nextToken = newToken;
+ newToken.previousToken = this;
+ }
+
+ /**
+ * Links the tokens around the current token together, making the current token disappear from the list.
+ */
+ public void deleteToken() {
+ final Optional<JavaToken> nextToken = getNextToken();
+ final Optional<JavaToken> previousToken = getPreviousToken();
+ previousToken.ifPresent(p -> p.nextToken = nextToken.orElse(null));
+ nextToken.ifPresent(n -> n.previousToken = previousToken.orElse(null));
+ }
+
+ /**
+ * Replaces the current token with newToken.
+ */
+ public void replaceToken(JavaToken newToken) {
+ assertNotNull(newToken);
+ getPreviousToken().ifPresent(p -> {
+ p.nextToken = newToken;
+ newToken.previousToken = p;
+ });
+ getNextToken().ifPresent(n -> {
+ n.previousToken = newToken;
+ newToken.nextToken = n;
+ });
+ }
+
+ /**
+ * @return the last token in the token list.
+ */
+ public JavaToken findLastToken() {
+ JavaToken current = this;
+ while (current.getNextToken().isPresent()) {
+ current = current.getNextToken().get();
+ }
+ return current;
+ }
+
+ /**
+ * @return the first token in the token list.
+ */
+ public JavaToken findFirstToken() {
+ JavaToken current = this;
+ while (current.getPreviousToken().isPresent()) {
+ current = current.getPreviousToken().get();
+ }
+ return current;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = kind;
+ result = 31 * result + text.hashCode();
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ JavaToken javaToken = (JavaToken) o;
+ if (kind != javaToken.kind)
+ return false;
+ if (!text.equals(javaToken.text))
+ return false;
+ return true;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java b/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java
new file mode 100644
index 000000000..bbe9797e2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/JavadocParser.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.javadoc.Javadoc;
+import com.github.javaparser.javadoc.JavadocBlockTag;
+import com.github.javaparser.javadoc.description.JavadocDescription;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.utils.Utils.*;
+import static com.github.javaparser.utils.Utils.nextWord;
+
+/**
+ * The class responsible for parsing the content of JavadocComments and produce JavadocDocuments.
+ */
+class JavadocParser {
+
+ private static String BLOCK_TAG_PREFIX = "@";
+ private static Pattern BLOCK_PATTERN = Pattern.compile("^" + BLOCK_TAG_PREFIX, Pattern.MULTILINE);
+
+ public static Javadoc parse(JavadocComment comment) {
+ return parse(comment.getContent());
+ }
+
+ public static Javadoc parse(String commentContent) {
+ List<String> cleanLines = cleanLines(normalizeEolInTextBlock(commentContent, EOL));
+ int indexOfFirstBlockTag = cleanLines.stream()
+ .filter(JavadocParser::isABlockLine)
+ .map(cleanLines::indexOf)
+ .findFirst()
+ .orElse(-1);
+ List<String> blockLines;
+ String descriptionText;
+ if (indexOfFirstBlockTag == -1) {
+ descriptionText = trimRight(String.join(EOL, cleanLines));
+ blockLines = Collections.emptyList();
+ } else {
+ descriptionText = trimRight(String.join(EOL, cleanLines.subList(0, indexOfFirstBlockTag)));
+
+ //Combine cleaned lines, but only starting with the first block tag till the end
+ //In this combined string it is easier to handle multiple lines which actually belong together
+ String tagBlock = cleanLines.subList(indexOfFirstBlockTag, cleanLines.size())
+ .stream()
+ .collect(Collectors.joining(EOL));
+
+ //Split up the entire tag back again, considering now that some lines belong to the same block tag.
+ //The pattern splits the block at each new line starting with the '@' symbol, thus the symbol
+ //then needs to be added again so that the block parsers handles everything correctly.
+ blockLines = BLOCK_PATTERN
+ .splitAsStream(tagBlock)
+ .filter(STRING_NOT_EMPTY)
+ .map(s -> BLOCK_TAG_PREFIX + s)
+ .collect(Collectors.toList());
+ }
+ Javadoc document = new Javadoc(JavadocDescription.parseText(descriptionText));
+ blockLines.forEach(l -> document.addBlockTag(parseBlockTag(l)));
+ return document;
+ }
+
+ private static JavadocBlockTag parseBlockTag(String line) {
+ line = line.trim().substring(1);
+ String tagName = nextWord(line);
+ String rest = line.substring(tagName.length()).trim();
+ return new JavadocBlockTag(tagName, rest);
+ }
+
+ private static boolean isABlockLine(String line) {
+ return line.trim().startsWith(BLOCK_TAG_PREFIX);
+ }
+
+ private static String trimRight(String string) {
+ while (!string.isEmpty() && Character.isWhitespace(string.charAt(string.length() - 1))) {
+ string = string.substring(0, string.length() - 1);
+ }
+ return string;
+ }
+
+ private static List<String> cleanLines(String content) {
+ String[] lines = content.split(EOL);
+ List<String> cleanedLines = Arrays.stream(lines).map(l -> {
+ int asteriskIndex = startsWithAsterisk(l);
+ if (asteriskIndex == -1) {
+ return l;
+ } else {
+ // if a line starts with space followed by an asterisk drop to the asterisk
+ // if there is a space immediately after the asterisk drop it also
+ if (l.length() > (asteriskIndex + 1)) {
+
+ char c = l.charAt(asteriskIndex + 1);
+ if (c == ' ' || c == '\t') {
+ return l.substring(asteriskIndex + 2);
+ }
+ }
+ return l.substring(asteriskIndex + 1);
+ }
+ }).collect(Collectors.toList());
+ // lines containing only whitespace are normalized to empty lines
+ cleanedLines = cleanedLines.stream().map(l -> l.trim().isEmpty() ? "" : l).collect(Collectors.toList());
+ // if the first starts with a space, remove it
+ if (!cleanedLines.get(0).isEmpty() && (cleanedLines.get(0).charAt(0) == ' ' || cleanedLines.get(0).charAt(0) == '\t')) {
+ cleanedLines.set(0, cleanedLines.get(0).substring(1));
+ }
+ // drop empty lines at the beginning and at the end
+ while (cleanedLines.size() > 0 && cleanedLines.get(0).trim().isEmpty()) {
+ cleanedLines = cleanedLines.subList(1, cleanedLines.size());
+ }
+ while (cleanedLines.size() > 0 && cleanedLines.get(cleanedLines.size() - 1).trim().isEmpty()) {
+ cleanedLines = cleanedLines.subList(0, cleanedLines.size() - 1);
+ }
+ return cleanedLines;
+ }
+
+ // Visible for testing
+ static int startsWithAsterisk(String line) {
+ if (line.startsWith("*")) {
+ return 0;
+ } else if ((line.startsWith(" ") || line.startsWith("\t")) && line.length() > 1) {
+ int res = startsWithAsterisk(line.substring(1));
+ if (res == -1) {
+ return -1;
+ } else {
+ return 1 + res;
+ }
+ } else {
+ return -1;
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java
new file mode 100644
index 000000000..50064dc7b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ParseProblemException.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import java.util.List;
+
+import static com.github.javaparser.utils.Utils.EOL;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.Collections.singletonList;
+
+/**
+ * Thrown when parsing problems occur during parsing with the static methods on JavaParser.
+ */
+public class ParseProblemException extends RuntimeException {
+ /**
+ * The problems that were encountered during parsing
+ */
+ private final List<Problem> problems;
+
+ public ParseProblemException(List<Problem> problems) {
+ super(createMessage(assertNotNull(problems)));
+ this.problems = problems;
+ }
+
+ public ParseProblemException(Throwable throwable) {
+ this(singletonList(new Problem(throwable.getMessage(), null, throwable)));
+ }
+
+ private static String createMessage(List<Problem> problems) {
+ StringBuilder message = new StringBuilder();
+ for (Problem problem : problems) {
+ message.append(problem.toString()).append(EOL);
+ }
+ return message.toString();
+ }
+
+ public List<Problem> getProblems() {
+ return problems;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java
new file mode 100644
index 000000000..4edc79a6d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ParseResult.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.comments.CommentsCollection;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+import static com.github.javaparser.utils.Utils.EOL;
+
+/**
+ * The results given when parsing with an instance of JavaParser.
+ */
+public class ParseResult<T> {
+ private final T result;
+ private final List<Problem> problems;
+ private final List<JavaToken> tokens;
+ private final CommentsCollection commentsCollection;
+
+ /**
+ * General constructor.
+ *
+ * @param result the AST, or empty if it wasn't created.
+ * @param problems a list of encountered parsing problems.
+ * @param tokens the complete list of tokens that were parsed, or empty if parsing failed completely.
+ */
+ public ParseResult(T result, List<Problem> problems, List<JavaToken> tokens, CommentsCollection commentsCollection) {
+ this.commentsCollection = commentsCollection;
+ this.result = result;
+ this.problems = problems;
+ this.tokens = tokens;
+ }
+
+ /**
+ * @return if parsing was successful, meaning no errors of any kind were encountered.
+ */
+ public boolean isSuccessful() {
+ return problems.isEmpty() && result != null;
+ }
+
+ /**
+ * Calls the consumer with the result if parsing was succesful.
+ */
+ public void ifSuccessful(Consumer<T> consumer) {
+ if (isSuccessful()) {
+ consumer.accept(result);
+ }
+ }
+
+ /**
+ * @return the list of encountered parsing problems. Empty when no problems were encountered.
+ */
+ public List<Problem> getProblems() {
+ return problems;
+ }
+
+ /**
+ * @return the <code>i</code>'th encountered parsing problem. May throw <code>IndexOutOfBoundsException</code>.
+ */
+ public Problem getProblem(int i) {
+ return getProblems().get(i);
+ }
+
+ /**
+ * @return the complete list of tokens that were parsed, or empty if parsing failed completely.
+ * @deprecated lists of tokens are now kept in every node.
+ * Calling this method is comparable to calling getResult().get().getTokenRange().get()
+ */
+ @Deprecated
+ public Optional<List<JavaToken>> getTokens() {
+ return Optional.ofNullable(tokens);
+ }
+
+ /**
+ * @return the complete collection of comments encountered while parsing.
+ */
+ public Optional<CommentsCollection> getCommentsCollection() {
+ return Optional.ofNullable(commentsCollection);
+ }
+
+ /**
+ * @return the AST of the parsed source code, or empty if parsing failed completely.
+ */
+ public Optional<T> getResult() {
+ return Optional.ofNullable(result);
+ }
+
+ @Override
+ public String toString() {
+ if (isSuccessful()) {
+ return "Parsing successful";
+ }
+ StringBuilder message = new StringBuilder("Parsing failed:").append(EOL);
+ for (Problem problem : problems) {
+ message.append(problem.toString()).append(EOL);
+ }
+ return message.toString();
+ }
+
+ /**
+ * A post processor that can be added to ParserConfiguration to add some processing right after parsing.
+ */
+ public interface PostProcessor {
+ void process(ParseResult<? extends Node> result, ParserConfiguration configuration);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java b/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java
new file mode 100644
index 000000000..ecb562c01
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ParseStart.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.ImportDeclaration;
+import com.github.javaparser.ast.PackageDeclaration;
+import com.github.javaparser.ast.body.BodyDeclaration;
+import com.github.javaparser.ast.body.Parameter;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt;
+import com.github.javaparser.ast.stmt.Statement;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+
+/**
+ * The start production for JavaParser.
+ * Tells JavaParser what piece of Java code it can expect.
+ * For example,
+ * COMPILATION_UNIT indicates a complete Java file,
+ * and CLASS_BODY would indicate the part of a class that is within { and }.
+ *
+ * @see JavaParser#parse(ParseStart, Provider)
+ */
+@FunctionalInterface
+public interface ParseStart<R> {
+ ParseStart<CompilationUnit> COMPILATION_UNIT = GeneratedJavaParser::CompilationUnit;
+ ParseStart<BlockStmt> BLOCK = GeneratedJavaParser::BlockParseStart;
+ ParseStart<Statement> STATEMENT = GeneratedJavaParser::BlockStatementParseStart;
+ ParseStart<ImportDeclaration> IMPORT_DECLARATION = GeneratedJavaParser::ImportDeclarationParseStart;
+ ParseStart<Expression> EXPRESSION = GeneratedJavaParser::ExpressionParseStart;
+ ParseStart<AnnotationExpr> ANNOTATION = GeneratedJavaParser::AnnotationParseStart;
+ ParseStart<BodyDeclaration<?>> ANNOTATION_BODY = GeneratedJavaParser::AnnotationBodyDeclarationParseStart;
+ ParseStart<BodyDeclaration<?>> CLASS_BODY = GeneratedJavaParser::ClassOrInterfaceBodyDeclarationParseStart;
+ ParseStart<ClassOrInterfaceType> CLASS_OR_INTERFACE_TYPE = GeneratedJavaParser::ClassOrInterfaceTypeParseStart;
+ ParseStart<Type> TYPE = GeneratedJavaParser::ResultTypeParseStart;
+ ParseStart<VariableDeclarationExpr> VARIABLE_DECLARATION_EXPR = GeneratedJavaParser::VariableDeclarationExpressionParseStart;
+ ParseStart<ExplicitConstructorInvocationStmt> EXPLICIT_CONSTRUCTOR_INVOCATION_STMT = GeneratedJavaParser::ExplicitConstructorInvocationParseStart;
+ ParseStart<Name> NAME = GeneratedJavaParser::NameParseStart;
+ ParseStart<SimpleName> SIMPLE_NAME = GeneratedJavaParser::SimpleNameParseStart;
+ ParseStart<Parameter> PARAMETER = GeneratedJavaParser::ParameterParseStart;
+ ParseStart<PackageDeclaration> PACKAGE_DECLARATION = GeneratedJavaParser::PackageDeclarationParseStart;
+
+ R parse(GeneratedJavaParser parser) throws ParseException;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java
new file mode 100644
index 000000000..e5be2b80a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ParserConfiguration.java
@@ -0,0 +1,271 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.validator.*;
+import com.github.javaparser.printer.lexicalpreservation.LexicalPreservingPrinter;
+import com.github.javaparser.resolution.SymbolResolver;
+import com.github.javaparser.version.Java10PostProcessor;
+import com.github.javaparser.version.Java11PostProcessor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static com.github.javaparser.ParserConfiguration.LanguageLevel.*;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * The configuration that is used by the parser.
+ * Note that this can be changed even when reusing the same JavaParser instance.
+ * It will pick up the changes.
+ */
+public class ParserConfiguration {
+ public enum LanguageLevel {
+ /** Does no post processing or validation. Only for people wanting the fastest parsing. */
+ RAW(null, null),
+ /** The most used Java version. */
+ POPULAR(new Java8Validator(), null),
+ /** The latest Java version that is available. */
+ CURRENT(new Java8Validator(), null),
+ /** The newest Java features supported. */
+ BLEEDING_EDGE(new Java11Validator(), new Java11PostProcessor()),
+ /** Java 1.0 */
+ JAVA_1_0(new Java1_0Validator(), null),
+ /** Java 1.1 */
+ JAVA_1_1(new Java1_1Validator(), null),
+ /** Java 1.2 */
+ JAVA_1_2(new Java1_2Validator(), null),
+ /** Java 1.3 */
+ JAVA_1_3(new Java1_3Validator(), null),
+ /** Java 1.4 */
+ JAVA_1_4(new Java1_4Validator(), null),
+ /** Java 5 */
+ JAVA_5(new Java5Validator(), null),
+ /** Java 6 */
+ JAVA_6(new Java6Validator(), null),
+ /** Java 7 */
+ JAVA_7(new Java7Validator(), null),
+ /** Java 8 */
+ JAVA_8(new Java8Validator(), null),
+ /** Java 9 */
+ JAVA_9(new Java9Validator(), null),
+ /** Java 10 */
+ JAVA_10(new Java10Validator(), new Java10PostProcessor()),
+ /** Java 11 (work in progress) */
+ JAVA_11_PREVIEW(new Java11Validator(), new Java11PostProcessor());
+
+ final Validator validator;
+ final ParseResult.PostProcessor postProcessor;
+
+ LanguageLevel(Validator validator, ParseResult.PostProcessor postProcessor) {
+ this.validator = validator;
+ this.postProcessor = postProcessor;
+ }
+ }
+
+ private boolean storeTokens = true;
+ private boolean attributeComments = true;
+ private boolean doNotAssignCommentsPrecedingEmptyLines = true;
+ private boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution = false;
+ private boolean lexicalPreservationEnabled = false;
+ private SymbolResolver symbolResolver = null;
+ private int tabSize = 1;
+ private LanguageLevel languageLevel = CURRENT;
+
+ private final List<ParseResult.PostProcessor> postProcessors = new ArrayList<>();
+
+ public ParserConfiguration() {
+ postProcessors.add((result, configuration) -> {
+ if (configuration.isLexicalPreservationEnabled()) {
+ if (configuration.isLexicalPreservationEnabled()) {
+ result.ifSuccessful(LexicalPreservingPrinter::setup);
+ }
+ }
+ });
+ postProcessors.add((result, configuration) -> {
+ if (configuration.isAttributeComments()) {
+ result.ifSuccessful(resultNode -> result
+ .getCommentsCollection().ifPresent(comments ->
+ new CommentsInserter(configuration).insertComments(resultNode, comments.copy().getComments())));
+ }
+ });
+ postProcessors.add((result, configuration) -> {
+ LanguageLevel languageLevel = getLanguageLevel();
+ if (languageLevel.postProcessor != null) {
+ languageLevel.postProcessor.process(result, configuration);
+ }
+ if (languageLevel.validator != null) {
+ languageLevel.validator.accept(result.getResult().get(), new ProblemReporter(newProblem -> result.getProblems().add(newProblem)));
+ }
+ });
+ postProcessors.add((result, configuration) -> configuration.getSymbolResolver().ifPresent(symbolResolver ->
+ result.ifSuccessful(resultNode -> {
+ if (resultNode instanceof CompilationUnit) {
+ resultNode.setData(Node.SYMBOL_RESOLVER_KEY, symbolResolver);
+ }
+ })
+ ));
+ }
+
+ public boolean isAttributeComments() {
+ return attributeComments;
+ }
+
+ /**
+ * Whether to run CommentsInserter, which will put the comments that were found in the source code into the comment
+ * and javadoc fields of the nodes it thinks they refer to.
+ */
+ public ParserConfiguration setAttributeComments(boolean attributeComments) {
+ this.attributeComments = attributeComments;
+ return this;
+ }
+
+ public boolean isDoNotAssignCommentsPrecedingEmptyLines() {
+ return doNotAssignCommentsPrecedingEmptyLines;
+ }
+
+ public ParserConfiguration setDoNotAssignCommentsPrecedingEmptyLines(boolean doNotAssignCommentsPrecedingEmptyLines) {
+ this.doNotAssignCommentsPrecedingEmptyLines = doNotAssignCommentsPrecedingEmptyLines;
+ return this;
+ }
+
+ public boolean isDoNotConsiderAnnotationsAsNodeStartForCodeAttribution() {
+ return doNotConsiderAnnotationsAsNodeStartForCodeAttribution;
+ }
+
+ public ParserConfiguration setDoNotConsiderAnnotationsAsNodeStartForCodeAttribution(boolean doNotConsiderAnnotationsAsNodeStartForCodeAttribution) {
+ this.doNotConsiderAnnotationsAsNodeStartForCodeAttribution = doNotConsiderAnnotationsAsNodeStartForCodeAttribution;
+ return this;
+ }
+
+ public ParserConfiguration setStoreTokens(boolean storeTokens) {
+ this.storeTokens = storeTokens;
+ if (!storeTokens) {
+ setAttributeComments(false);
+ }
+ return this;
+ }
+
+ public boolean isStoreTokens() {
+ return storeTokens;
+ }
+
+ public int getTabSize() {
+ return tabSize;
+ }
+
+ /**
+ * When a TAB character is encountered during parsing, the column position will be increased by this value.
+ * By default it is 1.
+ */
+ public ParserConfiguration setTabSize(int tabSize) {
+ this.tabSize = tabSize;
+ return this;
+ }
+
+ /**
+ * @deprecated use getLanguageLevel
+ */
+ @Deprecated
+ public Optional<Validator> getValidator() {
+ throw new IllegalStateException("method is deprecated");
+ }
+
+ /**
+ * @deprecated use setLanguageLevel, or getPostProcessors if you use a custom validator.
+ */
+ @Deprecated
+ public ParserConfiguration setValidator(Validator validator) {
+ // This whole method is a backwards compatability hack.
+ if (validator instanceof Java10Validator) {
+ setLanguageLevel(JAVA_10);
+ } else if (validator instanceof Java9Validator) {
+ setLanguageLevel(JAVA_9);
+ } else if (validator instanceof Java8Validator) {
+ setLanguageLevel(JAVA_8);
+ } else if (validator instanceof Java7Validator) {
+ setLanguageLevel(JAVA_7);
+ } else if (validator instanceof Java6Validator) {
+ setLanguageLevel(JAVA_6);
+ } else if (validator instanceof Java5Validator) {
+ setLanguageLevel(JAVA_5);
+ } else if (validator instanceof Java1_4Validator) {
+ setLanguageLevel(JAVA_1_4);
+ } else if (validator instanceof Java1_3Validator) {
+ setLanguageLevel(JAVA_1_3);
+ } else if (validator instanceof Java1_2Validator) {
+ setLanguageLevel(JAVA_1_2);
+ } else if (validator instanceof Java1_1Validator) {
+ setLanguageLevel(JAVA_1_1);
+ } else if (validator instanceof Java1_0Validator) {
+ setLanguageLevel(JAVA_1_0);
+ } else if (validator instanceof NoProblemsValidator) {
+ setLanguageLevel(RAW);
+ }
+ return this;
+ }
+
+ /**
+ * Disabled by default.
+ * When this is enabled, LexicalPreservingPrinter.print can be used to reproduce
+ * the original formatting of the file.
+ */
+ public ParserConfiguration setLexicalPreservationEnabled(boolean lexicalPreservationEnabled) {
+ this.lexicalPreservationEnabled = lexicalPreservationEnabled;
+ return this;
+ }
+
+ public boolean isLexicalPreservationEnabled() {
+ return lexicalPreservationEnabled;
+ }
+
+ /**
+ * Retrieve the SymbolResolver to be used while parsing, if any.
+ */
+ public Optional<SymbolResolver> getSymbolResolver() {
+ return Optional.ofNullable(symbolResolver);
+ }
+
+ /**
+ * Set the SymbolResolver to be injected while parsing.
+ */
+ public ParserConfiguration setSymbolResolver(SymbolResolver symbolResolver) {
+ this.symbolResolver = symbolResolver;
+ return this;
+ }
+
+ public List<ParseResult.PostProcessor> getPostProcessors() {
+ return postProcessors;
+ }
+
+ public ParserConfiguration setLanguageLevel(LanguageLevel languageLevel) {
+ this.languageLevel = assertNotNull(languageLevel);
+ return this;
+ }
+
+ public LanguageLevel getLanguageLevel() {
+ return languageLevel;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/Position.java b/javaparser-core/src/main/java/com/github/javaparser/Position.java
new file mode 100644
index 000000000..78e95d8d2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/Position.java
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import com.github.javaparser.ast.Node;
+
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * A position in a source file. Lines and columns start counting at 1.
+ */
+public class Position implements Comparable<Position> {
+ public final int line;
+ public final int column;
+
+ /**
+ * The first position in the file
+ */
+ public static final Position HOME = new Position(1, 1);
+
+ public Position(int line, int column) {
+ if (line < Node.ABSOLUTE_END_LINE) {
+ throw new IllegalArgumentException("Can't position at line " + line);
+ }
+ if (column < -1) {
+ throw new IllegalArgumentException("Can't position at column " + column);
+ }
+ this.line = line;
+ this.column = column;
+ }
+
+ /**
+ * Convenient factory method.
+ */
+ public static Position pos(int line, int column) {
+ return new Position(line, column);
+ }
+
+ public Position withColumn(int column) {
+ return new Position(this.line, column);
+ }
+
+ public Position withLine(int line) {
+ return new Position(line, this.column);
+ }
+
+ /**
+ * Check if the position is usable. Does not know what it is pointing at, so it can't check if the position is after
+ * the end of the source.
+ */
+ public boolean valid() {
+ return line > 0 && column > 0;
+ }
+
+ public boolean invalid() {
+ return !valid();
+ }
+
+ public Position orIfInvalid(Position anotherPosition) {
+ assertNotNull(anotherPosition);
+ if (valid() || anotherPosition.invalid()) {
+ return this;
+ }
+ return anotherPosition;
+ }
+
+ public boolean isAfter(Position position) {
+ assertNotNull(position);
+ if (position.line == Node.ABSOLUTE_BEGIN_LINE) return true;
+ if (line > position.line) {
+ return true;
+ } else if (line == position.line) {
+ return column > position.column;
+ }
+ return false;
+
+ }
+
+ public boolean isBefore(Position position) {
+ assertNotNull(position);
+ if (position.line == Node.ABSOLUTE_END_LINE) return true;
+ if (line < position.line) {
+ return true;
+ } else if (line == position.line) {
+ return column < position.column;
+ }
+ return false;
+ }
+
+ @Override
+ public int compareTo(Position o) {
+ assertNotNull(o);
+ if (isBefore(o)) {
+ return -1;
+ }
+ if (isAfter(o)) {
+ return 1;
+ }
+ return 0;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Position position = (Position) o;
+
+ return line == position.line && column == position.column;
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * line + column;
+ }
+
+ @Override
+ public String toString() {
+ return "(line " + line + ",col " + column + ")";
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/Problem.java b/javaparser-core/src/main/java/com/github/javaparser/Problem.java
new file mode 100644
index 000000000..2fc053226
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/Problem.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import java.util.Comparator;
+import java.util.Optional;
+
+import static com.github.javaparser.utils.Utils.EOL;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * A problem that was encountered during parsing.
+ */
+public class Problem {
+ private final String message;
+ private final TokenRange location;
+ private final Throwable cause;
+
+ public Problem(String message, TokenRange location, Throwable cause) {
+ assertNotNull(message);
+
+ this.message = message;
+ this.location = location;
+ this.cause = cause;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder str = new StringBuilder(getVerboseMessage());
+ if (cause != null) {
+ str.append(EOL).append("Problem stacktrace : ").append(EOL);
+ for (int i = 0; i < cause.getStackTrace().length; i++) {
+ StackTraceElement ste = cause.getStackTrace()[i];
+ str.append(" ").append(ste.toString());
+ if (i + 1 != cause.getStackTrace().length)
+ str.append(EOL);
+ }
+ }
+ return str.toString();
+ }
+
+ /**
+ * @return the message that was passed into the constructor.
+ */
+ public String getMessage() {
+ return message;
+ }
+
+ /**
+ * @return the message plus location information.
+ */
+ public String getVerboseMessage() {
+ return getLocation().map(l -> l.getBegin().getRange().map(r -> r.begin.toString()).orElse("(line ?,col ?)") + " " + message).orElse(message);
+ }
+
+ /**
+ * @return the location that was passed into the constructor.
+ */
+ public Optional<TokenRange> getLocation() {
+ return Optional.ofNullable(location);
+ }
+
+ /**
+ * @deprecated use getLocation()
+ */
+ @Deprecated
+ public Optional<TokenRange> getRange() {
+ return getLocation();
+ }
+
+ /**
+ * @return the cause that was passed into the constructor.
+ */
+ public Optional<Throwable> getCause() {
+ return Optional.ofNullable(cause);
+ }
+
+ /**
+ * Sorts problems on position.
+ */
+ public static Comparator<Problem> PROBLEM_BY_BEGIN_POSITION = (a, b) -> {
+ final Optional<Position> aBegin= a.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin));
+ final Optional<Position> bBegin = b.getLocation().flatMap(l -> l.getBegin().getRange().map(r -> r.begin));
+
+ if (aBegin.isPresent() && bBegin.isPresent()) {
+ return aBegin.get().compareTo(bBegin.get());
+ }
+ if (a.getLocation().isPresent() || b.getLocation().isPresent()) {
+ if (a.getLocation().isPresent()) {
+ return 1;
+ }
+ return -1;
+ }
+ return 0;
+ };
+
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/Providers.java b/javaparser-core/src/main/java/com/github/javaparser/Providers.java
new file mode 100644
index 000000000..f4b3df987
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/Providers.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * Factory for providers of source code for JavaParser. Providers that have no parameter for encoding but need it will
+ * use UTF-8.
+ */
+public final class Providers {
+ public static final Charset UTF8 = Charset.forName("utf-8");
+
+ private Providers() {
+ }
+
+ public static Provider provider(Reader reader) {
+ return new StreamProvider(assertNotNull(reader));
+ }
+
+ public static Provider provider(InputStream input, Charset encoding) {
+ assertNotNull(input);
+ assertNotNull(encoding);
+ try {
+ return new StreamProvider(input, encoding.name());
+ } catch (IOException e) {
+ // The only one that is thrown is UnsupportedCharacterEncodingException,
+ // and that's a fundamental problem, so runtime exception.
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static Provider provider(InputStream input) {
+ return provider(input, UTF8);
+ }
+
+ public static Provider provider(File file, Charset encoding) throws FileNotFoundException {
+ return provider(new FileInputStream(assertNotNull(file)), assertNotNull(encoding));
+ }
+
+ public static Provider provider(File file) throws FileNotFoundException {
+ return provider(assertNotNull(file), UTF8);
+ }
+
+ public static Provider provider(Path path, Charset encoding) throws IOException {
+ return provider(Files.newInputStream(assertNotNull(path)), assertNotNull(encoding));
+ }
+
+ public static Provider provider(Path path) throws IOException {
+ return provider(assertNotNull(path), UTF8);
+ }
+
+ public static Provider provider(String source) {
+ return new StringProvider(assertNotNull(source));
+ }
+
+
+ /**
+ * Provide a Provider from the resource found in class loader with the provided encoding.<br/> As resource is
+ * accessed through a class loader, a leading "/" is not allowed in pathToResource
+ */
+ public static Provider resourceProvider(ClassLoader classLoader, String pathToResource, Charset encoding) throws IOException {
+ InputStream resourceAsStream = classLoader.getResourceAsStream(pathToResource);
+ if (resourceAsStream == null) {
+ throw new IOException("Cannot find " + pathToResource);
+ }
+ return provider(resourceAsStream, encoding);
+ }
+
+ /**
+ * Provide a Provider from the resource found in the current class loader with the provided encoding.<br/> As
+ * resource is accessed through a class loader, a leading "/" is not allowed in pathToResource
+ */
+ public static Provider resourceProvider(String pathToResource, Charset encoding) throws IOException {
+ ClassLoader classLoader = Provider.class.getClassLoader();
+ return resourceProvider(classLoader, pathToResource, encoding);
+ }
+
+ /**
+ * Provide a Provider from the resource found in the current class loader with UTF-8 encoding.<br/> As resource is
+ * accessed through a class loader, a leading "/" is not allowed in pathToResource
+ */
+ public static Provider resourceProvider(String pathToResource) throws IOException {
+ return resourceProvider(pathToResource, UTF8);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/Range.java b/javaparser-core/src/main/java/com/github/javaparser/Range.java
new file mode 100644
index 000000000..dc5b329af
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/Range.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser;
+
+import static com.github.javaparser.Position.pos;
+
+/**
+ * A range of characters in a source file, from "begin" to "end", including the characters at "begin" and "end".
+ */
+public class Range {
+ public final Position begin;
+ public final Position end;
+
+ public Range(Position begin, Position end) {
+ if (begin == null) {
+ throw new IllegalArgumentException("begin can't be null");
+ }
+ if (end == null) {
+ throw new IllegalArgumentException("end can't be null");
+ }
+ this.begin = begin;
+ this.end = end;
+ }
+
+ public static Range range(Position begin, Position end) {
+ return new Range(begin, end);
+ }
+
+ public static Range range(int beginLine, int beginColumn, int endLine, int endColumn) {
+ return new Range(pos(beginLine, beginColumn), pos(endLine, endColumn));
+ }
+
+ public Range withBeginColumn(int column) {
+ return range(begin.withColumn(column), end);
+ }
+
+ public Range withBeginLine(int line) {
+ return range(begin.withLine(line), end);
+ }
+
+ public Range withEndColumn(int column) {
+ return range(begin, end.withColumn(column));
+ }
+
+ public Range withEndLine(int line) {
+ return range(begin, end.withLine(line));
+ }
+
+ public Range withBegin(Position begin) {
+ return range(begin, this.end);
+ }
+
+ public Range withEnd(Position end) {
+ return range(this.begin, end);
+ }
+
+ /**
+ * As strictlyContains, but two exactly matching ranges are also considered contained one in each other.
+ */
+ public boolean contains(Range other) {
+ return (begin.isBefore(other.begin) || begin.equals(other.begin)) &&
+ (end.isAfter(other.end) || end.equals(other.end));
+ }
+
+ /**
+ * Do this strictly contains other? It means that this has to be larger than other and it has to start as other
+ * or before and end as other or after.
+ */
+ public boolean strictlyContains(Range other) {
+ return begin.isBefore(other.begin) && end.isAfter(other.end);
+ }
+
+ public boolean isBefore(Position position) {
+ return end.isBefore(position);
+ }
+
+ public boolean isAfter(Position position) {
+ return begin.isAfter(position);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Range range = (Range) o;
+
+ return begin.equals(range.begin) && end.equals(range.end);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * begin.hashCode() + end.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return begin + "-" + end;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java b/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java
new file mode 100644
index 000000000..c0cb03879
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/TokenRange.java
@@ -0,0 +1,82 @@
+package com.github.javaparser;
+
+import java.util.Iterator;
+import java.util.Optional;
+
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * The range of tokens covered by this node.
+ */
+public class TokenRange implements Iterable<JavaToken> {
+ public static final TokenRange INVALID = new TokenRange(JavaToken.INVALID, JavaToken.INVALID);
+
+ private final JavaToken begin;
+ private final JavaToken end;
+
+ public TokenRange(JavaToken begin, JavaToken end) {
+ this.begin = assertNotNull(begin);
+ this.end = assertNotNull(end);
+ }
+
+ public JavaToken getBegin() {
+ return begin;
+ }
+
+ public JavaToken getEnd() {
+ return end;
+ }
+
+ public Optional<Range> toRange() {
+ if (begin.getRange().isPresent() && end.getRange().isPresent()) {
+ return Optional.of(new Range(begin.getRange().get().begin, end.getRange().get().end));
+ }
+ return Optional.empty();
+ }
+
+ public TokenRange withBegin(JavaToken begin) {
+ return new TokenRange(assertNotNull(begin), end);
+ }
+
+ public TokenRange withEnd(JavaToken end) {
+ return new TokenRange(begin, assertNotNull(end));
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder result = new StringBuilder();
+ for(JavaToken t: this) {
+ result.append(t.getText());
+ }
+ return result.toString();
+ }
+
+ @Override
+ public Iterator<JavaToken> iterator() {
+ return new Iterator<JavaToken>() {
+ private boolean hasNext = true;
+ private JavaToken current = begin;
+
+ @Override
+ public boolean hasNext() {
+ return hasNext;
+ }
+
+ @Override
+ public JavaToken next() {
+ JavaToken retval = current;
+ if(current == null){
+ throw new IllegalStateException("Attempting to move past end of range.");
+ }
+ if (current == end) {
+ hasNext = false;
+ }
+ current = current.getNextToken().orElse(null);
+ if(current == null && hasNext){
+ throw new IllegalStateException("End token is not linked to begin token.");
+ }
+ return retval;
+ }
+ };
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java
new file mode 100644
index 000000000..8b90aa755
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/TokenTypes.java
@@ -0,0 +1,239 @@
+package com.github.javaparser;
+
+import static com.github.javaparser.GeneratedJavaParserConstants.*;
+import static com.github.javaparser.utils.Utils.EOL;
+
+/**
+ * Complements GeneratedJavaParserConstants
+ */
+public class TokenTypes {
+ public static boolean isWhitespace(int kind) {
+ return getCategory(kind).isWhitespace();
+ }
+
+ /**
+ * @deprecated use isEndOfLineToken
+ */
+ @Deprecated
+ public static boolean isEndOfLineCharacter(int kind) {
+ return isEndOfLineToken(kind);
+ }
+
+ public static boolean isEndOfLineToken(int kind) {
+ return getCategory(kind).isEndOfLine();
+ }
+
+ public static boolean isWhitespaceOrComment(int kind) {
+ return getCategory(kind).isWhitespaceOrComment();
+ }
+
+ public static boolean isSpaceOrTab(int kind) {
+ return getCategory(kind).isWhitespaceButNotEndOfLine();
+ }
+
+ public static boolean isComment(int kind) {
+ return getCategory(kind).isComment();
+ }
+
+ /**
+ * @deprecated use eolTokenKind
+ */
+ @Deprecated
+ public static int eolToken() {
+ return eolTokenKind();
+ }
+
+ /**
+ * @return the kind of EOL token to use on the platform you're running on.
+ */
+ public static int eolTokenKind() {
+ if (EOL.equals("\n")) {
+ return UNIX_EOL;
+ }
+ if (EOL.equals("\r\n")) {
+ return WINDOWS_EOL;
+ }
+ if (EOL.equals("\r")) {
+ return OLD_MAC_EOL;
+ }
+ throw new AssertionError("Unknown EOL character sequence");
+ }
+
+ /**
+ * @return the token kind for a single space.
+ */
+ public static int spaceTokenKind() {
+ return SPACE;
+ }
+
+ /**
+ * @deprecated use spaceTokenKind
+ */
+ @Deprecated
+ public static int spaceToken() {
+ return spaceTokenKind();
+ }
+
+ /**
+ * Category of a token, a little more detailed than
+ * <a href="https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.5">The JLS</a>.
+ */
+ public static JavaToken.Category getCategory(int kind) {
+ switch (kind) {
+ case WINDOWS_EOL:
+ case UNIX_EOL:
+ case OLD_MAC_EOL:
+ return JavaToken.Category.EOL;
+ case EOF:
+ case SPACE:
+ case CTRL_Z:
+ return JavaToken.Category.WHITESPACE_NO_EOL;
+ case SINGLE_LINE_COMMENT:
+ case JAVADOC_COMMENT:
+ case MULTI_LINE_COMMENT:
+ return JavaToken.Category.COMMENT;
+ case ABSTRACT:
+ case ASSERT:
+ case BOOLEAN:
+ case BREAK:
+ case BYTE:
+ case CASE:
+ case CATCH:
+ case CHAR:
+ case CLASS:
+ case CONST:
+ case CONTINUE:
+ case _DEFAULT:
+ case DO:
+ case DOUBLE:
+ case ELSE:
+ case ENUM:
+ case EXTENDS:
+ case FALSE:
+ case FINAL:
+ case FINALLY:
+ case FLOAT:
+ case FOR:
+ case GOTO:
+ case IF:
+ case IMPLEMENTS:
+ case IMPORT:
+ case INSTANCEOF:
+ case INT:
+ case INTERFACE:
+ case LONG:
+ case NATIVE:
+ case NEW:
+ case NULL:
+ case PACKAGE:
+ case PRIVATE:
+ case PROTECTED:
+ case PUBLIC:
+ case RETURN:
+ case SHORT:
+ case STATIC:
+ case STRICTFP:
+ case SUPER:
+ case SWITCH:
+ case SYNCHRONIZED:
+ case THIS:
+ case THROW:
+ case THROWS:
+ case TRANSIENT:
+ case TRUE:
+ case TRY:
+ case VOID:
+ case VOLATILE:
+ case WHILE:
+ case REQUIRES:
+ case TO:
+ case WITH:
+ case OPEN:
+ case OPENS:
+ case USES:
+ case MODULE:
+ case EXPORTS:
+ case PROVIDES:
+ case TRANSITIVE:
+ return JavaToken.Category.KEYWORD;
+ case LONG_LITERAL:
+ case INTEGER_LITERAL:
+ case DECIMAL_LITERAL:
+ case HEX_LITERAL:
+ case OCTAL_LITERAL:
+ case BINARY_LITERAL:
+ case FLOATING_POINT_LITERAL:
+ case DECIMAL_FLOATING_POINT_LITERAL:
+ case DECIMAL_EXPONENT:
+ case HEXADECIMAL_FLOATING_POINT_LITERAL:
+ case HEXADECIMAL_EXPONENT:
+ case CHARACTER_LITERAL:
+ case STRING_LITERAL:
+ return JavaToken.Category.LITERAL;
+ case IDENTIFIER:
+ return JavaToken.Category.IDENTIFIER;
+ case LPAREN:
+ case RPAREN:
+ case LBRACE:
+ case RBRACE:
+ case LBRACKET:
+ case RBRACKET:
+ case SEMICOLON:
+ case COMMA:
+ case DOT:
+ case AT:
+ return JavaToken.Category.SEPARATOR;
+ case ASSIGN:
+ case LT:
+ case BANG:
+ case TILDE:
+ case HOOK:
+ case COLON:
+ case EQ:
+ case LE:
+ case GE:
+ case NE:
+ case SC_OR:
+ case SC_AND:
+ case INCR:
+ case DECR:
+ case PLUS:
+ case MINUS:
+ case STAR:
+ case SLASH:
+ case BIT_AND:
+ case BIT_OR:
+ case XOR:
+ case REM:
+ case LSHIFT:
+ case PLUSASSIGN:
+ case MINUSASSIGN:
+ case STARASSIGN:
+ case SLASHASSIGN:
+ case ANDASSIGN:
+ case ORASSIGN:
+ case XORASSIGN:
+ case REMASSIGN:
+ case LSHIFTASSIGN:
+ case RSIGNEDSHIFTASSIGN:
+ case RUNSIGNEDSHIFTASSIGN:
+ case ELLIPSIS:
+ case ARROW:
+ case DOUBLECOLON:
+ case RUNSIGNEDSHIFT:
+ case RSIGNEDSHIFT:
+ case GT:
+ return JavaToken.Category.OPERATOR;
+ // The following are tokens that are only used internally by the lexer
+ case ENTER_JAVADOC_COMMENT:
+ case ENTER_MULTILINE_COMMENT:
+ case COMMENT_CONTENT:
+ case HEX_DIGITS:
+ case LETTER:
+ case UNICODE_ESCAPE:
+ case PART_LETTER:
+ default:
+ throw new AssertionError("Invalid token kind " + kind);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java
new file mode 100644
index 000000000..63e96b87a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AccessSpecifier.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast;
+
+/**
+ * Access specifier. Represents one of the possible levels of
+ * access permitted by the language.
+ *
+ * @author Federico Tomassetti
+ * @since July 2014
+ */
+public enum AccessSpecifier {
+
+ PUBLIC("public"),
+ PRIVATE("private"),
+ PROTECTED("protected"),
+ DEFAULT("");
+
+ private String codeRepresenation;
+
+ AccessSpecifier(String codeRepresentation) {
+ this.codeRepresenation = codeRepresentation;
+ }
+
+ public String asString() {
+ return this.codeRepresenation;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java
new file mode 100644
index 000000000..33d58e49a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/AllFieldsConstructor.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.ast;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Tells tools that this is the constructor which directly initializes all fields (except "range" and "comment")
+ */
+@Target(ElementType.CONSTRUCTOR)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AllFieldsConstructor {
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java b/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java
new file mode 100644
index 000000000..09148fe7c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/ArrayCreationLevel.java
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast;
+
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.IntegerLiteralExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ArrayCreationLevelMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+
+/**
+ * In <code>new int[1][2];</code> there are two ArrayCreationLevel objects,
+ * the first one contains the expression "1",
+ * the second the expression "2".
+ */
+public final class ArrayCreationLevel extends Node implements NodeWithAnnotations<ArrayCreationLevel> {
+
+ @OptionalProperty
+ private Expression dimension;
+
+ private NodeList<AnnotationExpr> annotations = new NodeList<>();
+
+ public ArrayCreationLevel() {
+ this(null, null, new NodeList<>());
+ }
+
+ public ArrayCreationLevel(int dimension) {
+ this(null, new IntegerLiteralExpr("" + dimension), new NodeList<>());
+ }
+
+ public ArrayCreationLevel(Expression dimension) {
+ this(null, dimension, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ArrayCreationLevel(Expression dimension, NodeList<AnnotationExpr> annotations) {
+ this(null, dimension, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ArrayCreationLevel(TokenRange tokenRange, Expression dimension, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange);
+ setDimension(dimension);
+ setAnnotations(annotations);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ /**
+ * Sets the dimension
+ *
+ * @param dimension the dimension, can be null
+ * @return this, the ArrayCreationLevel
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayCreationLevel setDimension(final Expression dimension) {
+ if (dimension == this.dimension) {
+ return (ArrayCreationLevel) this;
+ }
+ notifyPropertyChange(ObservableProperty.DIMENSION, this.dimension, dimension);
+ if (this.dimension != null)
+ this.dimension.setParentNode(null);
+ this.dimension = dimension;
+ setAsParentNodeOf(dimension);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getDimension() {
+ return Optional.ofNullable(dimension);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayCreationLevel setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (ArrayCreationLevel) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ArrayCreationLevel removeDimension() {
+ return setDimension((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ if (dimension != null) {
+ if (node == dimension) {
+ removeDimension();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ArrayCreationLevel clone() {
+ return (ArrayCreationLevel) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ArrayCreationLevelMetaModel getMetaModel() {
+ return JavaParserMetaModel.arrayCreationLevelMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ if (dimension != null) {
+ if (node == dimension) {
+ setDimension((Expression) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java
new file mode 100644
index 000000000..fd8bb20a0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/CompilationUnit.java
@@ -0,0 +1,694 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast;
+
+import com.github.javaparser.JavaParser;
+import com.github.javaparser.ParseResult;
+import com.github.javaparser.ParseStart;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.body.AnnotationDeclaration;
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.body.EnumDeclaration;
+import com.github.javaparser.ast.body.TypeDeclaration;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.modules.ModuleDeclaration;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.CompilationUnitMetaModel;
+import com.github.javaparser.metamodel.InternalProperty;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.printer.PrettyPrinter;
+import com.github.javaparser.utils.ClassUtils;
+import com.github.javaparser.utils.CodeGenerationUtils;
+import com.github.javaparser.utils.Utils;
+import javax.annotation.Generated;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import static com.github.javaparser.JavaParser.parseName;
+import static com.github.javaparser.Providers.UTF8;
+import static com.github.javaparser.Providers.provider;
+import static com.github.javaparser.utils.CodeGenerationUtils.subtractPaths;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+
+/**
+ * <p>
+ * This class represents the entire compilation unit. Each java file denotes a
+ * compilation unit.
+ * </p>
+ * A compilation unit start with an optional package declaration,
+ * followed by zero or more import declarations,
+ * followed by zero or more type declarations.
+ *
+ * @author Julio Vilmar Gesser
+ * @see PackageDeclaration
+ * @see ImportDeclaration
+ * @see TypeDeclaration
+ * @see Storage
+ */
+public final class CompilationUnit extends Node {
+
+ @OptionalProperty
+ private PackageDeclaration packageDeclaration;
+
+ private NodeList<ImportDeclaration> imports;
+
+ private NodeList<TypeDeclaration<?>> types;
+
+ @OptionalProperty
+ private ModuleDeclaration module;
+
+ @InternalProperty
+ private Storage storage;
+
+ public CompilationUnit() {
+ this(null, null, new NodeList<>(), new NodeList<>(), null);
+ }
+
+ public CompilationUnit(String packageDeclaration) {
+ this(null, new PackageDeclaration(new Name(packageDeclaration)), new NodeList<>(), new NodeList<>(), null);
+ }
+
+ @AllFieldsConstructor
+ public CompilationUnit(PackageDeclaration packageDeclaration, NodeList<ImportDeclaration> imports, NodeList<TypeDeclaration<?>> types, ModuleDeclaration module) {
+ this(null, packageDeclaration, imports, types, module);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public CompilationUnit(TokenRange tokenRange, PackageDeclaration packageDeclaration, NodeList<ImportDeclaration> imports, NodeList<TypeDeclaration<?>> types, ModuleDeclaration module) {
+ super(tokenRange);
+ setPackageDeclaration(packageDeclaration);
+ setImports(imports);
+ setTypes(types);
+ setModule(module);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ /**
+ * Return a list containing all comments declared in this compilation unit.
+ * Including javadocs, line comments and block comments of all types,
+ * inner-classes and other members.<br>
+ * If there is no comment, an empty list is returned.
+ *
+ * @return list with all comments of this compilation unit.
+ * @see JavadocComment
+ * @see com.github.javaparser.ast.comments.LineComment
+ * @see com.github.javaparser.ast.comments.BlockComment
+ */
+ public List<Comment> getComments() {
+ return this.getAllContainedComments();
+ }
+
+ /**
+ * Retrieves the list of imports declared in this compilation unit or
+ * <code>null</code> if there is no import.
+ *
+ * @return the list of imports or <code>none</code> if there is no import
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ImportDeclaration> getImports() {
+ return imports;
+ }
+
+ public ImportDeclaration getImport(int i) {
+ return getImports().get(i);
+ }
+
+ /**
+ * Retrieves the package declaration of this compilation unit.<br>
+ * If this compilation unit has no package declaration (default package),
+ * <code>Optional.none()</code> is returned.
+ *
+ * @return the package declaration or <code>none</code>
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<PackageDeclaration> getPackageDeclaration() {
+ return Optional.ofNullable(packageDeclaration);
+ }
+
+ /**
+ * Return the list of top level types declared in this compilation unit.<br>
+ * If there are no types declared, <code>none</code> is returned.
+ *
+ * @return the list of types or <code>none</code> null if there is no type
+ * @see AnnotationDeclaration
+ * @see ClassOrInterfaceDeclaration
+ * @see EnumDeclaration
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<TypeDeclaration<?>> getTypes() {
+ return types;
+ }
+
+ /**
+ * Convenience method that wraps <code>getTypes()</code>.<br>
+ * If <code>i</code> is out of bounds, throws <code>IndexOutOfBoundsException.</code>
+ *
+ * @param i the index of the type declaration to retrieve
+ */
+ public TypeDeclaration<?> getType(int i) {
+ return getTypes().get(i);
+ }
+
+ /**
+ * Sets the list of imports of this compilation unit. The list is initially
+ * <code>null</code>.
+ *
+ * @param imports the list of imports
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public CompilationUnit setImports(final NodeList<ImportDeclaration> imports) {
+ assertNotNull(imports);
+ if (imports == this.imports) {
+ return (CompilationUnit) this;
+ }
+ notifyPropertyChange(ObservableProperty.IMPORTS, this.imports, imports);
+ if (this.imports != null)
+ this.imports.setParentNode(null);
+ this.imports = imports;
+ setAsParentNodeOf(imports);
+ return this;
+ }
+
+ public CompilationUnit setImport(int i, ImportDeclaration imports) {
+ getImports().set(i, imports);
+ return this;
+ }
+
+ public CompilationUnit addImport(ImportDeclaration imports) {
+ getImports().add(imports);
+ return this;
+ }
+
+ /**
+ * Sets or clear the package declarations of this compilation unit.
+ *
+ * @param packageDeclaration the packageDeclaration declaration to set or <code>null</code> to default package
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public CompilationUnit setPackageDeclaration(final PackageDeclaration packageDeclaration) {
+ if (packageDeclaration == this.packageDeclaration) {
+ return (CompilationUnit) this;
+ }
+ notifyPropertyChange(ObservableProperty.PACKAGE_DECLARATION, this.packageDeclaration, packageDeclaration);
+ if (this.packageDeclaration != null)
+ this.packageDeclaration.setParentNode(null);
+ this.packageDeclaration = packageDeclaration;
+ setAsParentNodeOf(packageDeclaration);
+ return this;
+ }
+
+ /**
+ * Sets the list of types declared in this compilation unit.
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public CompilationUnit setTypes(final NodeList<TypeDeclaration<?>> types) {
+ assertNotNull(types);
+ if (types == this.types) {
+ return (CompilationUnit) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPES, this.types, types);
+ if (this.types != null)
+ this.types.setParentNode(null);
+ this.types = types;
+ setAsParentNodeOf(types);
+ return this;
+ }
+
+ public CompilationUnit setType(int i, TypeDeclaration<?> type) {
+ NodeList<TypeDeclaration<?>> copy = new NodeList<>();
+ copy.addAll(getTypes());
+ getTypes().set(i, type);
+ notifyPropertyChange(ObservableProperty.TYPES, copy, types);
+ return this;
+ }
+
+ public CompilationUnit addType(TypeDeclaration<?> type) {
+ NodeList<TypeDeclaration<?>> copy = new NodeList<>();
+ copy.addAll(getTypes());
+ getTypes().add(type);
+ notifyPropertyChange(ObservableProperty.TYPES, copy, types);
+ return this;
+ }
+
+ /**
+ * sets the package declaration of this compilation unit
+ *
+ * @param name the name of the package
+ * @return this, the {@link CompilationUnit}
+ */
+ public CompilationUnit setPackageDeclaration(String name) {
+ setPackageDeclaration(new PackageDeclaration(parseName(name)));
+ return this;
+ }
+
+ /**
+ * Add an import to the list of {@link ImportDeclaration} of this compilation unit<br>
+ * shorthand for {@link #addImport(String, boolean, boolean)} with name,false,false
+ *
+ * @param name the import name
+ * @return this, the {@link CompilationUnit}
+ */
+ public CompilationUnit addImport(String name) {
+ return addImport(name, false, false);
+ }
+
+ /**
+ * Add an import to the list of {@link ImportDeclaration} of this compilation unit<br>
+ * shorthand for {@link #addImport(String)} with clazz.getName()
+ *
+ * @param clazz the class to import
+ * @return this, the {@link CompilationUnit}
+ * @throws RuntimeException if clazz is an anonymous or local class
+ */
+ public CompilationUnit addImport(Class<?> clazz) {
+ if (ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.getName().startsWith("java.lang"))
+ return this;
+ else if (clazz.isMemberClass())
+ return addImport(clazz.getName().replace("$", "."));
+ else if (clazz.isArray() && !ClassUtils.isPrimitiveOrWrapper(clazz.getComponentType()) && !clazz.getComponentType().getName().startsWith("java.lang"))
+ return addImport(clazz.getComponentType().getName());
+ else if (clazz.isAnonymousClass() || clazz.isLocalClass())
+ throw new RuntimeException(clazz.getName() + " is an anonymous or local class therefore it can't be added with addImport");
+ return addImport(clazz.getName());
+ }
+
+ /**
+ * Add an import to the list of {@link ImportDeclaration} of this compilation unit<br>
+ * <b>This method check if no import with the same name is already in the list</b>
+ *
+ * @param name the import name
+ * @param isStatic is it an "import static"
+ * @param isAsterisk does the import end with ".*"
+ * @return this, the {@link CompilationUnit}
+ */
+ public CompilationUnit addImport(String name, boolean isStatic, boolean isAsterisk) {
+ final StringBuilder i = new StringBuilder("import ");
+ if (isStatic) {
+ i.append("static ");
+ }
+ i.append(name);
+ if (isAsterisk) {
+ i.append(".*");
+ }
+ i.append(";");
+ ImportDeclaration importDeclaration = JavaParser.parseImport(i.toString());
+ if (getImports().stream().anyMatch(im -> im.toString().equals(importDeclaration.toString())))
+ return this;
+ else {
+ getImports().add(importDeclaration);
+ return this;
+ }
+ }
+
+ /**
+ * Add a public class to the types of this compilation unit
+ *
+ * @param name the class name
+ * @return the newly created class
+ */
+ public ClassOrInterfaceDeclaration addClass(String name) {
+ return addClass(name, Modifier.PUBLIC);
+ }
+
+ /**
+ * Add a class to the types of this compilation unit
+ *
+ * @param name the class name
+ * @param modifiers the modifiers (like Modifier.PUBLIC)
+ * @return the newly created class
+ */
+ public ClassOrInterfaceDeclaration addClass(String name, Modifier... modifiers) {
+ ClassOrInterfaceDeclaration classOrInterfaceDeclaration = new ClassOrInterfaceDeclaration(Arrays.stream(modifiers).collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), false, name);
+ getTypes().add(classOrInterfaceDeclaration);
+ return classOrInterfaceDeclaration;
+ }
+
+ /**
+ * Add a public interface class to the types of this compilation unit
+ *
+ * @param name the interface name
+ * @return the newly created class
+ */
+ public ClassOrInterfaceDeclaration addInterface(String name) {
+ return addInterface(name, Modifier.PUBLIC);
+ }
+
+ /**
+ * Add an interface to the types of this compilation unit
+ *
+ * @param name the interface name
+ * @param modifiers the modifiers (like Modifier.PUBLIC)
+ * @return the newly created class
+ */
+ public ClassOrInterfaceDeclaration addInterface(String name, Modifier... modifiers) {
+ ClassOrInterfaceDeclaration classOrInterfaceDeclaration = new ClassOrInterfaceDeclaration(Arrays.stream(modifiers).collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), true, name);
+ getTypes().add(classOrInterfaceDeclaration);
+ return classOrInterfaceDeclaration;
+ }
+
+ /**
+ * Add a public enum to the types of this compilation unit
+ *
+ * @param name the enum name
+ * @return the newly created class
+ */
+ public EnumDeclaration addEnum(String name) {
+ return addEnum(name, Modifier.PUBLIC);
+ }
+
+ /**
+ * Add an enum to the types of this compilation unit
+ *
+ * @param name the enum name
+ * @param modifiers the modifiers (like Modifier.PUBLIC)
+ * @return the newly created class
+ */
+ public EnumDeclaration addEnum(String name, Modifier... modifiers) {
+ EnumDeclaration enumDeclaration = new EnumDeclaration(Arrays.stream(modifiers).collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), name);
+ getTypes().add(enumDeclaration);
+ return enumDeclaration;
+ }
+
+ /**
+ * Add a public annotation declaration to the types of this compilation unit
+ *
+ * @param name the annotation name
+ * @return the newly created class
+ */
+ public AnnotationDeclaration addAnnotationDeclaration(String name) {
+ return addAnnotationDeclaration(name, Modifier.PUBLIC);
+ }
+
+ /**
+ * Add an annotation declaration to the types of this compilation unit
+ *
+ * @param name the annotation name
+ * @param modifiers the modifiers (like Modifier.PUBLIC)
+ * @return the newly created class
+ */
+ public AnnotationDeclaration addAnnotationDeclaration(String name, Modifier... modifiers) {
+ AnnotationDeclaration annotationDeclaration = new AnnotationDeclaration(Arrays.stream(modifiers).collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), name);
+ getTypes().add(annotationDeclaration);
+ return annotationDeclaration;
+ }
+
+ /**
+ * Try to get a top level class declaration by its name
+ *
+ * @param className the class name (case-sensitive)
+ */
+ public Optional<ClassOrInterfaceDeclaration> getClassByName(String className) {
+ return getTypes().stream().filter(type -> type.getNameAsString().equals(className) && type instanceof ClassOrInterfaceDeclaration && !((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map(t -> (ClassOrInterfaceDeclaration) t);
+ }
+
+ /**
+ * Try to get a top level interface declaration by its name
+ *
+ * @param interfaceName the interface name (case-sensitive)
+ */
+ public Optional<ClassOrInterfaceDeclaration> getInterfaceByName(String interfaceName) {
+ return getTypes().stream().filter(type -> type.getNameAsString().equals(interfaceName) && type instanceof ClassOrInterfaceDeclaration && ((ClassOrInterfaceDeclaration) type).isInterface()).findFirst().map(t -> (ClassOrInterfaceDeclaration) t);
+ }
+
+ /**
+ * Try to get a top level enum declaration by its name
+ *
+ * @param enumName the enum name (case-sensitive)
+ */
+ public Optional<EnumDeclaration> getEnumByName(String enumName) {
+ return getTypes().stream().filter(type -> type.getNameAsString().equals(enumName) && type instanceof EnumDeclaration).findFirst().map(t -> (EnumDeclaration) t);
+ }
+
+ /**
+ * @return the name that the primary type in this file should have, according to the filename in {@link Storage#getFileName()}.
+ * Empty if no file information is present (when this compilation unit wasn't parsed from a file.)
+ */
+ public Optional<String> getPrimaryTypeName() {
+ return getStorage().map(Storage::getFileName).map(Utils::removeFileExtension);
+ }
+
+ /**
+ * @return the type whose name corresponds to the file name.
+ * Empty if no file information is present (when this compilation unit wasn't parsed from a file.)
+ * If for some strange reason there are multiple types of this name, the first one is returned.
+ */
+ public Optional<TypeDeclaration<?>> getPrimaryType() {
+ return getPrimaryTypeName().flatMap(name -> getTypes().stream().filter(t -> t.getNameAsString().equals(name)).findFirst());
+ }
+
+ /**
+ * Try to get a top level annotation type declaration by its name
+ *
+ * @param annotationName the annotation name (case-sensitive)
+ */
+ public Optional<AnnotationDeclaration> getAnnotationDeclarationByName(String annotationName) {
+ return getTypes().stream().filter(type -> type.getNameAsString().equals(annotationName) && type instanceof AnnotationDeclaration).findFirst().map(t -> (AnnotationDeclaration) t);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < imports.size(); i++) {
+ if (imports.get(i) == node) {
+ imports.remove(i);
+ return true;
+ }
+ }
+ if (module != null) {
+ if (node == module) {
+ removeModule();
+ return true;
+ }
+ }
+ if (packageDeclaration != null) {
+ if (node == packageDeclaration) {
+ removePackageDeclaration();
+ return true;
+ }
+ }
+ for (int i = 0; i < types.size(); i++) {
+ if (types.get(i) == node) {
+ types.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public CompilationUnit removePackageDeclaration() {
+ return setPackageDeclaration((PackageDeclaration) null);
+ }
+
+ /**
+ * @return the module declared in this compilation unit.
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<ModuleDeclaration> getModule() {
+ return Optional.ofNullable(module);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public CompilationUnit setModule(final ModuleDeclaration module) {
+ if (module == this.module) {
+ return (CompilationUnit) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODULE, this.module, module);
+ if (this.module != null)
+ this.module.setParentNode(null);
+ this.module = module;
+ setAsParentNodeOf(module);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public CompilationUnit removeModule() {
+ return setModule((ModuleDeclaration) null);
+ }
+
+ /**
+ * @return information about where this compilation unit was loaded from, or empty if it wasn't loaded from a file.
+ */
+ public Optional<Storage> getStorage() {
+ return Optional.ofNullable(storage);
+ }
+
+ public CompilationUnit setStorage(Path path) {
+ this.storage = new Storage(this, path);
+ return this;
+ }
+
+ /**
+ * Information about where this compilation unit was loaded from.
+ * This class only stores the absolute location.
+ * For more flexibility use SourceRoot.
+ */
+ public static class Storage {
+
+ private final CompilationUnit compilationUnit;
+
+ private final Path path;
+
+ private Storage(CompilationUnit compilationUnit, Path path) {
+ this.compilationUnit = compilationUnit;
+ this.path = path.toAbsolutePath();
+ }
+
+ /**
+ * @return the path to the source for this CompilationUnit
+ */
+ public Path getPath() {
+ return path;
+ }
+
+ /**
+ * @return the CompilationUnit this Storage is about.
+ */
+ public CompilationUnit getCompilationUnit() {
+ return compilationUnit;
+ }
+
+ /**
+ * @return the source root directory, calculated from the path of this compiation unit, and the package
+ * declaration of this compilation unit. If the package declaration is invalid (when it does not match the end
+ * of the path) a RuntimeException is thrown.
+ */
+ public Path getSourceRoot() {
+ final Optional<String> pkgAsString = compilationUnit.getPackageDeclaration().map(NodeWithName::getNameAsString);
+ return pkgAsString.map(p -> Paths.get(CodeGenerationUtils.packageToPath(p))).map(pkg -> subtractPaths(getDirectory(), pkg)).orElse(getDirectory());
+ }
+
+ public String getFileName() {
+ return path.getFileName().toString();
+ }
+
+ public Path getDirectory() {
+ return path.getParent();
+ }
+
+ /**
+ * Saves the compilation unit to its original location
+ */
+ public void save() {
+ save(cu -> new PrettyPrinter().print(cu));
+ }
+
+ /**
+ * Saves a compilation unit to its original location with formatting according to the function
+ * passed as a parameter.
+ *
+ * @param makeOutput a function that formats the compilation unit
+ */
+ public void save(Function<CompilationUnit, String> makeOutput) {
+ try {
+ Files.createDirectories(path.getParent());
+ final String code = makeOutput.apply(getCompilationUnit());
+ Files.write(path, code.getBytes(UTF8));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public ParseResult<CompilationUnit> reparse(JavaParser javaParser) {
+ try {
+ return javaParser.parse(ParseStart.COMPILATION_UNIT, provider(getPath()));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public CompilationUnit clone() {
+ return (CompilationUnit) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public CompilationUnitMetaModel getMetaModel() {
+ return JavaParserMetaModel.compilationUnitMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < imports.size(); i++) {
+ if (imports.get(i) == node) {
+ imports.set(i, (ImportDeclaration) replacementNode);
+ return true;
+ }
+ }
+ if (module != null) {
+ if (node == module) {
+ setModule((ModuleDeclaration) replacementNode);
+ return true;
+ }
+ }
+ if (packageDeclaration != null) {
+ if (node == packageDeclaration) {
+ setPackageDeclaration((PackageDeclaration) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < types.size(); i++) {
+ if (types.get(i) == node) {
+ types.set(i, (TypeDeclaration) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java b/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java
new file mode 100644
index 000000000..2f2115d0e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/DataKey.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast;
+
+/**
+ * A key to a piece of data associated with a {@link Node} at runtime.
+ * The key contains type information that can be used to check the
+ * type of any user data value for the key when the value is set. DataKey is abstract in order to
+ * force the creation of a subtype. That subtype is used to test for identity when looking for the
+ * user data because actual object identity would suffer from problems under serialization.
+ * So, the correct way to declare a DataKey is like this:
+ * <p>
+ * <pre>
+ * <code>
+ * public static final DataKey&lt;Role&gt; ROLE = new DataKey&lt;Role&gt;() { };
+ * </code>
+ * </pre>
+ * <p>
+ * This code was taken from the <a href="http://wicket.apache.org/">Wicket project</a>.
+ *
+ * @param <T> The type of the object which is stored
+ * @see Node#getData(DataKey)
+ */
+public abstract class DataKey<T> {
+ @Override
+ public int hashCode() {
+ return getClass().hashCode();
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ return obj != null && getClass().equals(obj.getClass());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java
new file mode 100644
index 000000000..88ab096e5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/ImportDeclaration.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast;
+
+import com.github.javaparser.JavaParser;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.JavaParser.*;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ImportDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+
+/**
+ * An import declaration.
+ * <br/><code>import com.github.javaparser.JavaParser;</code>
+ * <br/><code>import com.github.javaparser.*;</code>
+ * <br/><code>import com.github.javaparser.JavaParser.*; </code>
+ * <br/><code>import static com.github.javaparser.JavaParser.*;</code>
+ * <br/><code>import static com.github.javaparser.JavaParser.parse;</code>
+ *
+ * <p>The name does not include the asterisk or the static keyword.</p>
+ * @author Julio Vilmar Gesser
+ */
+public final class ImportDeclaration extends Node implements NodeWithName<ImportDeclaration> {
+
+ private Name name;
+
+ private boolean isStatic;
+
+ private boolean isAsterisk;
+
+ private ImportDeclaration() {
+ this(null, new Name(), false, false);
+ }
+
+ public ImportDeclaration(String name, boolean isStatic, boolean isAsterisk) {
+ this(null, parseName(name), isStatic, isAsterisk);
+ }
+
+ @AllFieldsConstructor
+ public ImportDeclaration(Name name, boolean isStatic, boolean isAsterisk) {
+ this(null, name, isStatic, isAsterisk);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ImportDeclaration(TokenRange tokenRange, Name name, boolean isStatic, boolean isAsterisk) {
+ super(tokenRange);
+ setName(name);
+ setStatic(isStatic);
+ setAsterisk(isAsterisk);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ /**
+ * Retrieves the name of the import (.* is not included.)
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name getName() {
+ return name;
+ }
+
+ /**
+ * Return if the import ends with "*".
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean isAsterisk() {
+ return isAsterisk;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean isStatic() {
+ return isStatic;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ImportDeclaration setAsterisk(final boolean isAsterisk) {
+ if (isAsterisk == this.isAsterisk) {
+ return (ImportDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.ASTERISK, this.isAsterisk, isAsterisk);
+ this.isAsterisk = isAsterisk;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ImportDeclaration setName(final Name name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (ImportDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ImportDeclaration setStatic(final boolean isStatic) {
+ if (isStatic == this.isStatic) {
+ return (ImportDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.STATIC, this.isStatic, isStatic);
+ this.isStatic = isStatic;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ImportDeclaration clone() {
+ return (ImportDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ImportDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.importDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((Name) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Modifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Modifier.java
new file mode 100644
index 000000000..b6d0309af
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Modifier.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast;
+
+import java.util.EnumSet;
+
+/**
+ * One of the modifiers known in Java.
+ */
+public enum Modifier {
+ PUBLIC,
+ PROTECTED,
+ PRIVATE,
+ ABSTRACT,
+ STATIC,
+ FINAL,
+ TRANSIENT,
+ VOLATILE,
+ SYNCHRONIZED,
+ NATIVE,
+ STRICTFP,
+ TRANSITIVE,
+ DEFAULT;
+
+ final String codeRepresentation;
+
+ Modifier() {
+ this.codeRepresentation = name().toLowerCase();
+ }
+
+ /**
+ * @return the keyword represented by this modifier.
+ */
+ public String asString() {
+ return codeRepresentation;
+ }
+
+ public EnumSet<Modifier> toEnumSet() {
+ return EnumSet.of(this);
+ }
+
+ public static AccessSpecifier getAccessSpecifier(EnumSet<Modifier> modifiers) {
+ if (modifiers.contains(Modifier.PUBLIC)) {
+ return AccessSpecifier.PUBLIC;
+ } else if (modifiers.contains(Modifier.PROTECTED)) {
+ return AccessSpecifier.PROTECTED;
+ } else if (modifiers.contains(Modifier.PRIVATE)) {
+ return AccessSpecifier.PRIVATE;
+ } else {
+ return AccessSpecifier.DEFAULT;
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java
new file mode 100644
index 000000000..98d0bbcb6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/Node.java
@@ -0,0 +1,1004 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast;
+
+import com.github.javaparser.HasParentNode;
+import com.github.javaparser.Range;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.nodeTypes.NodeWithRange;
+import com.github.javaparser.ast.nodeTypes.NodeWithTokenRange;
+import com.github.javaparser.ast.observer.AstObserver;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.observer.PropagatingAstObserver;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.EqualsVisitor;
+import com.github.javaparser.ast.visitor.HashCodeVisitor;
+import com.github.javaparser.ast.visitor.Visitable;
+import com.github.javaparser.metamodel.*;
+import com.github.javaparser.printer.PrettyPrinter;
+import com.github.javaparser.printer.PrettyPrinterConfiguration;
+import com.github.javaparser.resolution.SymbolResolver;
+import javax.annotation.Generated;
+import java.util.*;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+import static com.github.javaparser.ast.Node.Parsedness.PARSED;
+import static com.github.javaparser.ast.Node.TreeTraversal.PREORDER;
+import static java.util.Collections.unmodifiableList;
+import static java.util.Spliterator.DISTINCT;
+import static java.util.Spliterator.NONNULL;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.metamodel.NodeMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+
+/**
+ * Base class for all nodes of the abstract syntax tree.
+ * <h2>Construction</h2>
+ * <p>The tree is built by instantiating the required nodes, then adding them to other nodes.
+ * If it is the parser who is building the tree, it will use the largest constructor,
+ * the one with "range" as the first parameter.
+ * If you want to manually instantiate nodes, we suggest to...
+ * <ul>
+ * <li>use a convenience method, like "addStatement(...)", or if none are available...</li>
+ * <li>use a convenient constructor, like ClassOrInterfaceType(String name), or if none are available...</li>
+ * <li>use the default constructor.</li>
+ * <li>Alternatively, use one of the JavaParser.parse(snippet) methods.</li>
+ * </ul>
+ * ... and use the various methods on the node to initialize it further, if needed.
+ * <h2>Parent/child</h2>
+ * <p>The parent node field is managed automatically and can be seen as read only.
+ * Note that there is only one parent,
+ * and trying to use the same node in two places will lead to unexpected behaviour.
+ * It is advised to clone() a node before moving it around.
+ * <h2>Comments</h2>
+ * <p>Each Node can have one associated comment which describes it and
+ * a number of "orphan comments" which it contains but are not specifically
+ * associated to any child.
+ * <h2>Positions</h2>
+ * <p>When the parser creates nodes, it sets their source code position in the "range" field.
+ * When you manually instantiate nodes, their range is not set.
+ * The top left character is position 1, 1.
+ * Note that since this is an <i>abstract</i> syntax tree,
+ * it leaves out a lot of text from the original source file,
+ * like where braces or comma's are exactly.
+ * Therefore there is no position information on everything in the original source file.
+ * <h2>Observers</h2>
+ * <p>It is possible to add observers to the the tree.
+ * Any change in the tree is sent as an event to any observers watching.
+ * <h2>Visitors</h2>
+ * <p>The most comfortable way of working with an abstract syntax tree is using visitors.
+ * You can use one of the visitors in the visitor package, or extend one of them.
+ * A visitor can be "run" by calling accept on a node:
+ * <pre>node.accept(visitor, argument);</pre>
+ * where argument is an object of your choice (often simply null.)
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class Node implements Cloneable, HasParentNode<Node>, Visitable, NodeWithRange<Node>, NodeWithTokenRange<Node> {
+
+ /**
+ * Different registration mode for observers on nodes.
+ */
+ public enum ObserverRegistrationMode {
+
+ /**
+ * Notify exclusively for changes happening on this node alone.
+ */
+ JUST_THIS_NODE,
+ /**
+ * Notify for changes happening on this node and all its descendants existing at the moment in
+ * which the observer was registered. Nodes attached later will not be observed.
+ */
+ THIS_NODE_AND_EXISTING_DESCENDANTS,
+ /**
+ * Notify for changes happening on this node and all its descendants. The descendants existing at the moment in
+ * which the observer was registered will be observed immediately. As new nodes are attached later they are
+ * automatically registered to be observed.
+ */
+ SELF_PROPAGATING
+ }
+
+ public enum Parsedness {
+
+ PARSED, UNPARSABLE
+ }
+
+ /**
+ * This can be used to sort nodes on position.
+ */
+ public static Comparator<NodeWithRange<?>> NODE_BY_BEGIN_POSITION = (a, b) -> {
+ if (a.getRange().isPresent() && b.getRange().isPresent()) {
+ return a.getRange().get().begin.compareTo(b.getRange().get().begin);
+ }
+ if (a.getRange().isPresent() || b.getRange().isPresent()) {
+ if (a.getRange().isPresent()) {
+ return 1;
+ }
+ return -1;
+ }
+ return 0;
+ };
+
+ private static final PrettyPrinter toStringPrinter = new PrettyPrinter(new PrettyPrinterConfiguration());
+
+ protected static final PrettyPrinterConfiguration prettyPrinterNoCommentsConfiguration = new PrettyPrinterConfiguration().setPrintComments(false);
+
+ @InternalProperty
+ private Range range;
+
+ @InternalProperty
+ private TokenRange tokenRange;
+
+ @InternalProperty
+ private Node parentNode;
+
+ @InternalProperty
+ private List<Node> childNodes = new LinkedList<>();
+
+ @InternalProperty
+ private List<Comment> orphanComments = new LinkedList<>();
+
+ @InternalProperty
+ private IdentityHashMap<DataKey<?>, Object> data = null;
+
+ @OptionalProperty
+ private Comment comment;
+
+ @InternalProperty
+ private List<AstObserver> observers = new ArrayList<>();
+
+ @InternalProperty
+ private Parsedness parsed = PARSED;
+
+ protected Node(TokenRange tokenRange) {
+ setTokenRange(tokenRange);
+ }
+
+ /**
+ * Called in every constructor for node specific code.
+ * It can't be written in the constructor itself because it will
+ * be overwritten during code generation.
+ */
+ protected void customInitialization() {
+ }
+
+ /**
+ * This is a comment associated with this node.
+ *
+ * @return comment property
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Comment> getComment() {
+ return Optional.ofNullable(comment);
+ }
+
+ /**
+ * @return the range of characters in the source code that this node covers.
+ */
+ public Optional<Range> getRange() {
+ return Optional.ofNullable(range);
+ }
+
+ /**
+ * @return the range of tokens that this node covers.
+ */
+ public Optional<TokenRange> getTokenRange() {
+ return Optional.ofNullable(tokenRange);
+ }
+
+ public Node setTokenRange(TokenRange tokenRange) {
+ this.tokenRange = tokenRange;
+ if (tokenRange == null || !(tokenRange.getBegin().getRange().isPresent() && tokenRange.getBegin().getRange().isPresent())) {
+ range = null;
+ } else {
+ range = new Range(tokenRange.getBegin().getRange().get().begin, tokenRange.getEnd().getRange().get().end);
+ }
+ return this;
+ }
+
+ /**
+ * @param range the range of characters in the source code that this node covers. null can be used to indicate that
+ * no range information is known, or that it is not of interest.
+ */
+ public Node setRange(Range range) {
+ if (this.range == range) {
+ return this;
+ }
+ notifyPropertyChange(ObservableProperty.RANGE, this.range, range);
+ this.range = range;
+ return this;
+ }
+
+ /**
+ * Use this to store additional information to this node.
+ *
+ * @param comment to be set
+ */
+ public final Node setComment(final Comment comment) {
+ if (this.comment == comment) {
+ return this;
+ }
+ if (comment != null && (this instanceof Comment)) {
+ throw new RuntimeException("A comment can not be commented");
+ }
+ notifyPropertyChange(ObservableProperty.COMMENT, this.comment, comment);
+ if (this.comment != null) {
+ this.comment.setCommentedNode(null);
+ }
+ this.comment = comment;
+ if (comment != null) {
+ this.comment.setCommentedNode(this);
+ }
+ return this;
+ }
+
+ /**
+ * Use this to store additional information to this node.
+ *
+ * @param comment to be set
+ */
+ public final Node setLineComment(String comment) {
+ return setComment(new LineComment(comment));
+ }
+
+ /**
+ * Use this to store additional information to this node.
+ *
+ * @param comment to be set
+ */
+ public final Node setBlockComment(String comment) {
+ return setComment(new BlockComment(comment));
+ }
+
+ /**
+ * Return the String representation of this node.
+ *
+ * @return the String representation of this node
+ */
+ @Override
+ public final String toString() {
+ return toStringPrinter.print(this);
+ }
+
+ public final String toString(PrettyPrinterConfiguration prettyPrinterConfiguration) {
+ return new PrettyPrinter(prettyPrinterConfiguration).print(this);
+ }
+
+ @Override
+ public final int hashCode() {
+ return HashCodeVisitor.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null || !(obj instanceof Node)) {
+ return false;
+ }
+ return EqualsVisitor.equals(this, (Node) obj);
+ }
+
+ @Override
+ public Optional<Node> getParentNode() {
+ return Optional.ofNullable(parentNode);
+ }
+
+ /**
+ * Contains all nodes that have this node set as their parent.
+ * You can add and remove nodes from this list by adding or removing nodes from the fields of this node.
+ *
+ * @return all nodes that have this node as their parent.
+ */
+ public List<Node> getChildNodes() {
+ return unmodifiableList(childNodes);
+ }
+
+ public void addOrphanComment(Comment comment) {
+ orphanComments.add(comment);
+ comment.setParentNode(this);
+ }
+
+ public boolean removeOrphanComment(Comment comment) {
+ boolean removed = orphanComments.remove(comment);
+ if (removed) {
+ comment.setParentNode(null);
+ }
+ return removed;
+ }
+
+ /**
+ * This is a list of Comment which are inside the node and are not associated
+ * with any meaningful AST Node.
+ * <p>
+ * For example, comments at the end of methods (immediately before the parenthesis)
+ * or at the end of CompilationUnit are orphan comments.
+ * <p>
+ * When more than one comment preceeds a statement, the one immediately preceding it
+ * it is associated with the statements, while the others are orphans.
+ * <p>
+ * Changes to this list are not persisted.
+ *
+ * @return all comments that cannot be attributed to a concept
+ */
+ public List<Comment> getOrphanComments() {
+ return new LinkedList<>(orphanComments);
+ }
+
+ /**
+ * This is the list of Comment which are contained in the Node either because
+ * they are properly associated to one of its children or because they are floating
+ * around inside the Node
+ *
+ * @return all Comments within the node as a list
+ */
+ public List<Comment> getAllContainedComments() {
+ List<Comment> comments = new LinkedList<>();
+ comments.addAll(getOrphanComments());
+ for (Node child : getChildNodes()) {
+ child.getComment().ifPresent(comments::add);
+ comments.addAll(child.getAllContainedComments());
+ }
+ return comments;
+ }
+
+ /**
+ * Assign a new parent to this node, removing it
+ * from the list of children of the previous parent, if any.
+ *
+ * @param newParentNode node to be set as parent
+ */
+ @Override
+ public Node setParentNode(Node newParentNode) {
+ if (newParentNode == parentNode) {
+ return this;
+ }
+ observers.forEach(o -> o.parentChange(this, parentNode, newParentNode));
+ // remove from old parent, if any
+ if (parentNode != null) {
+ final List<Node> parentChildNodes = parentNode.childNodes;
+ for (int i = 0; i < parentChildNodes.size(); i++) {
+ if (parentChildNodes.get(i) == this) {
+ parentChildNodes.remove(i);
+ }
+ }
+ }
+ parentNode = newParentNode;
+ // add to new parent, if any
+ if (parentNode != null) {
+ parentNode.childNodes.add(this);
+ }
+ return this;
+ }
+
+ protected void setAsParentNodeOf(Node childNode) {
+ if (childNode != null) {
+ childNode.setParentNode(getParentNodeForChildren());
+ }
+ }
+
+ public static final int ABSOLUTE_BEGIN_LINE = -1;
+
+ public static final int ABSOLUTE_END_LINE = -2;
+
+ /**
+ * @deprecated use getComment().isPresent()
+ */
+ @Deprecated
+ public boolean hasComment() {
+ return comment != null;
+ }
+
+ public void tryAddImportToParentCompilationUnit(Class<?> clazz) {
+ getAncestorOfType(CompilationUnit.class).ifPresent(p -> p.addImport(clazz));
+ }
+
+ /**
+ * Recursively finds all nodes of a certain type.
+ *
+ * @param clazz the type of node to find.
+ * @deprecated use find(Class)
+ */
+ public <N extends Node> List<N> getChildNodesByType(Class<N> clazz) {
+ List<N> nodes = new ArrayList<>();
+ for (Node child : getChildNodes()) {
+ if (clazz.isInstance(child)) {
+ nodes.add(clazz.cast(child));
+ }
+ nodes.addAll(child.getChildNodesByType(clazz));
+ }
+ return nodes;
+ }
+
+ /**
+ * @deprecated use findAll(Class)
+ */
+ @Deprecated
+ public <N extends Node> List<N> getNodesByType(Class<N> clazz) {
+ return getChildNodesByType(clazz);
+ }
+
+ /**
+ * Gets data for this node using the given key.
+ *
+ * @param <M> The type of the data.
+ * @param key The key for the data
+ * @return The data or null of no data was found for the given key
+ * @see DataKey
+ */
+ @SuppressWarnings("unchecked")
+ public <M> M getData(final DataKey<M> key) {
+ if (data == null) {
+ return null;
+ }
+ return (M) data.get(key);
+ }
+
+ /**
+ * Sets data for this node using the given key.
+ * For information on creating DataKey, see {@link DataKey}.
+ *
+ * @param <M> The type of data
+ * @param key The singleton key for the data
+ * @param object The data object
+ * @see DataKey
+ */
+ public <M> void setData(DataKey<M> key, M object) {
+ if (data == null) {
+ data = new IdentityHashMap<>();
+ }
+ data.put(key, object);
+ }
+
+ /**
+ * @return does this node have data for this key?
+ */
+ public boolean containsData(DataKey<?> key) {
+ if (data == null) {
+ return false;
+ }
+ return data.get(key) != null;
+ }
+
+ /**
+ * Try to remove this node from the parent
+ *
+ * @return true if removed, false if it is a required property of the parent, or if the parent isn't set.
+ * @throws RuntimeException if it fails in an unexpected way
+ */
+ public boolean remove() {
+ if (parentNode == null) {
+ return false;
+ }
+ return parentNode.remove(this);
+ }
+
+ /**
+ * Try to replace this node in the parent with the supplied node.
+ *
+ * @return true if removed, or if the parent isn't set.
+ * @throws RuntimeException if it fails in an unexpected way
+ */
+ public boolean replace(Node node) {
+ if (parentNode == null) {
+ return false;
+ }
+ return parentNode.replace(this, node);
+ }
+
+ /**
+ * Forcibly removes this node from the AST.
+ * If it cannot be removed from the parent with remove(),
+ * it will try to remove its parent instead,
+ * until it finds a node that can be removed,
+ * or no parent can be found.
+ * <p>
+ * Since everything at CompilationUnit level is removable,
+ * this method will only (silently) fail when the node is in a detached AST fragment.
+ */
+ public void removeForced() {
+ if (!remove()) {
+ getParentNode().ifPresent(Node::remove);
+ }
+ }
+
+ @Override
+ public Node getParentNodeForChildren() {
+ return this;
+ }
+
+ protected void setAsParentNodeOf(NodeList<? extends Node> list) {
+ if (list != null) {
+ list.setParentNode(getParentNodeForChildren());
+ }
+ }
+
+ public <P> void notifyPropertyChange(ObservableProperty property, P oldValue, P newValue) {
+ this.observers.forEach(o -> o.propertyChange(this, property, oldValue, newValue));
+ }
+
+ @Override
+ public void unregister(AstObserver observer) {
+ this.observers.remove(observer);
+ }
+
+ @Override
+ public void register(AstObserver observer) {
+ this.observers.add(observer);
+ }
+
+ /**
+ * Register a new observer for the given node. Depending on the mode specified also descendants, existing
+ * and new, could be observed. For more details see <i>ObserverRegistrationMode</i>.
+ */
+ public void register(AstObserver observer, ObserverRegistrationMode mode) {
+ if (mode == null) {
+ throw new IllegalArgumentException("Mode should be not null");
+ }
+ switch(mode) {
+ case JUST_THIS_NODE:
+ register(observer);
+ break;
+ case THIS_NODE_AND_EXISTING_DESCENDANTS:
+ registerForSubtree(observer);
+ break;
+ case SELF_PROPAGATING:
+ registerForSubtree(PropagatingAstObserver.transformInPropagatingObserver(observer));
+ break;
+ default:
+ throw new UnsupportedOperationException("This mode is not supported: " + mode);
+ }
+ }
+
+ /**
+ * Register the observer for the current node and all the contained node and nodelists, recursively.
+ */
+ public void registerForSubtree(AstObserver observer) {
+ register(observer);
+ this.getChildNodes().forEach(c -> c.registerForSubtree(observer));
+ for (PropertyMetaModel property : getMetaModel().getAllPropertyMetaModels()) {
+ if (property.isNodeList()) {
+ NodeList<?> nodeList = (NodeList<?>) property.getValue(this);
+ if (nodeList != null)
+ nodeList.register(observer);
+ }
+ }
+ }
+
+ @Override
+ public boolean isRegistered(AstObserver observer) {
+ return this.observers.contains(observer);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (comment != null) {
+ if (node == comment) {
+ removeComment();
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public Node removeComment() {
+ return setComment((Comment) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public Node clone() {
+ return (Node) accept(new CloneVisitor(), null);
+ }
+
+ /**
+ * @return get JavaParser specific node introspection information.
+ */
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public NodeMetaModel getMetaModel() {
+ return JavaParserMetaModel.nodeMetaModel;
+ }
+
+ /**
+ * @return whether this node was successfully parsed or not.
+ * If it was not, only the range and tokenRange fields will be valid.
+ */
+ public Parsedness getParsed() {
+ return parsed;
+ }
+
+ /**
+ * Used by the parser to flag unparsable nodes.
+ */
+ public Node setParsed(Parsedness parsed) {
+ this.parsed = parsed;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (comment != null) {
+ if (node == comment) {
+ setComment((Comment) replacementNode);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Finds the root node of this AST by finding the topmost parent.
+ */
+ public Node findRootNode() {
+ Node n = this;
+ while (n.getParentNode().isPresent()) {
+ n = n.getParentNode().get();
+ }
+ return n;
+ }
+
+ /**
+ * @return the containing CompilationUnit, or empty if this node is not inside a compilation unit.
+ */
+ public Optional<CompilationUnit> findCompilationUnit() {
+ Node rootNode = findRootNode();
+ if (rootNode instanceof CompilationUnit) {
+ return Optional.of((CompilationUnit) rootNode);
+ }
+ return Optional.empty();
+ }
+
+ protected SymbolResolver getSymbolResolver() {
+ return findCompilationUnit().map(cu -> {
+ SymbolResolver symbolResolver = cu.getData(SYMBOL_RESOLVER_KEY);
+ if (symbolResolver == null) {
+ throw new IllegalStateException("Symbol resolution not configured: to configure consider setting a SymbolResolver in the ParserConfiguration");
+ }
+ return symbolResolver;
+ }).orElseThrow(() -> new IllegalStateException("The node is not inserted in a CompilationUnit"));
+ }
+
+ // We need to expose it because we will need to use it to inject the SymbolSolver
+ public static final DataKey<SymbolResolver> SYMBOL_RESOLVER_KEY = new DataKey<SymbolResolver>() {
+ };
+
+ public enum TreeTraversal {
+
+ PREORDER, BREADTHFIRST, POSTORDER, PARENTS, DIRECT_CHILDREN
+ }
+
+ private Iterator<Node> treeIterator(TreeTraversal traversal) {
+ switch(traversal) {
+ case BREADTHFIRST:
+ return new BreadthFirstIterator(this);
+ case POSTORDER:
+ return new PostOrderIterator(this);
+ case PREORDER:
+ return new PreOrderIterator(this);
+ case DIRECT_CHILDREN:
+ return new DirectChildrenIterator(this);
+ case PARENTS:
+ return new ParentsVisitor(this);
+ default:
+ throw new IllegalArgumentException("Unknown traversal choice.");
+ }
+ }
+
+ private Iterable<Node> treeIterable(TreeTraversal traversal) {
+ return () -> treeIterator(traversal);
+ }
+
+ /**
+ * Make a stream of nodes using traversal algorithm "traversal".
+ */
+ public Stream<Node> stream(TreeTraversal traversal) {
+ return StreamSupport.stream(Spliterators.spliteratorUnknownSize(treeIterator(traversal), NONNULL | DISTINCT), false);
+ }
+
+ /**
+ * Make a stream of nodes using pre-order traversal.
+ */
+ public Stream<Node> stream() {
+ return StreamSupport.stream(Spliterators.spliteratorUnknownSize(treeIterator(PREORDER), NONNULL | DISTINCT), false);
+ }
+
+ /**
+ * Walks the AST, calling the consumer for every node, with traversal algorithm "traversal".
+ * <br/>This is the most general walk method. All other walk and findAll methods are based on this.
+ */
+ public void walk(TreeTraversal traversal, Consumer<Node> consumer) {
+ // Could be implemented as a call to the above walk method, but this is a little more efficient.
+ for (Node node : treeIterable(traversal)) {
+ consumer.accept(node);
+ }
+ }
+
+ /**
+ * Walks the AST, calling the consumer for every node with pre-order traversal.
+ */
+ public void walk(Consumer<Node> consumer) {
+ walk(PREORDER, consumer);
+ }
+
+ /**
+ * Walks the AST with pre-order traversal, calling the consumer for every node of type "nodeType".
+ */
+ public <T extends Node> void walk(Class<T> nodeType, Consumer<T> consumer) {
+ walk(TreeTraversal.PREORDER, node -> {
+ if (nodeType.isAssignableFrom(node.getClass())) {
+ consumer.accept(nodeType.cast(node));
+ }
+ });
+ }
+
+ /**
+ * Walks the AST with pre-order traversal, returning all nodes of type "nodeType".
+ */
+ public <T extends Node> List<T> findAll(Class<T> nodeType) {
+ final List<T> found = new ArrayList<>();
+ walk(nodeType, found::add);
+ return found;
+ }
+
+ /**
+ * Walks the AST with pre-order traversal, returning all nodes of type "nodeType" that match the predicate.
+ */
+ public <T extends Node> List<T> findAll(Class<T> nodeType, Predicate<T> predicate) {
+ final List<T> found = new ArrayList<>();
+ walk(nodeType, n -> {
+ if (predicate.test(n))
+ found.add(n);
+ });
+ return found;
+ }
+
+ /**
+ * Walks the AST, applying the function for every node, with traversal algorithm "traversal". If the function
+ * returns something else than null, the traversal is stopped and the function result is returned. <br/>This is the
+ * most general findFirst method. All other findFirst methods are based on this.
+ */
+ public <T> Optional<T> findFirst(TreeTraversal traversal, Function<Node, Optional<T>> consumer) {
+ for (Node node : treeIterable(traversal)) {
+ final Optional<T> result = consumer.apply(node);
+ if (result.isPresent()) {
+ return result;
+ }
+ }
+ return Optional.empty();
+ }
+
+ /**
+ * Walks the AST with pre-order traversal, returning the first node of type "nodeType" or empty() if none is found.
+ */
+ public <N extends Node> Optional<N> findFirst(Class<N> nodeType) {
+ return findFirst(TreeTraversal.PREORDER, node -> {
+ if (nodeType.isAssignableFrom(node.getClass())) {
+ return Optional.of(nodeType.cast(node));
+ }
+ return Optional.empty();
+ });
+ }
+
+ /**
+ * Walks the AST with pre-order traversal, returning the first node of type "nodeType" that matches "predicate" or empty() if none is
+ * found.
+ */
+ public <N extends Node> Optional<N> findFirst(Class<N> nodeType, Predicate<N> predicate) {
+ return findFirst(TreeTraversal.PREORDER, node -> {
+ if (nodeType.isAssignableFrom(node.getClass())) {
+ final N castNode = nodeType.cast(node);
+ if (predicate.test(castNode)) {
+ return Optional.of(castNode);
+ }
+ }
+ return Optional.empty();
+ });
+ }
+
+ /**
+ * Walks the parents of this node, returning the first node of type "nodeType" or empty() if none is found.
+ */
+ public <N extends Node> Optional<N> findParent(Class<N> nodeType) {
+ Node n = this;
+ while (n.getParentNode().isPresent()) {
+ n = n.getParentNode().get();
+ if (nodeType.isAssignableFrom(n.getClass())) {
+ return Optional.of(nodeType.cast(n));
+ }
+ }
+ return Optional.empty();
+ }
+
+ /**
+ * Performs a breadth-first node traversal starting with a given node.
+ *
+ * @see <a href="https://en.wikipedia.org/wiki/Breadth-first_search">Breadth-first traversal</a>
+ */
+ public static class BreadthFirstIterator implements Iterator<Node> {
+
+ private final Queue<Node> queue = new LinkedList<>();
+
+ public BreadthFirstIterator(Node node) {
+ queue.add(node);
+ }
+
+ @Override
+ public boolean hasNext() {
+ return !queue.isEmpty();
+ }
+
+ @Override
+ public Node next() {
+ Node next = queue.remove();
+ queue.addAll(next.getChildNodes());
+ return next;
+ }
+ }
+
+ /**
+ * Performs a simple traversal over all nodes that have the passed node as their parent.
+ */
+ public static class DirectChildrenIterator implements Iterator<Node> {
+
+ private final Iterator<Node> childrenIterator;
+
+ public DirectChildrenIterator(Node node) {
+ childrenIterator = new ArrayList<>(node.getChildNodes()).iterator();
+ }
+
+ @Override
+ public boolean hasNext() {
+ return childrenIterator.hasNext();
+ }
+
+ @Override
+ public Node next() {
+ return childrenIterator.next();
+ }
+ }
+
+ /**
+ * Iterates over the parent of the node, then the parent's parent, then the parent's parent's parent, until running
+ * out of parents.
+ */
+ public static class ParentsVisitor implements Iterator<Node> {
+
+ private Node node;
+
+ public ParentsVisitor(Node node) {
+ this.node = node;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return node.getParentNode().isPresent();
+ }
+
+ @Override
+ public Node next() {
+ node = node.getParentNode().orElse(null);
+ return node;
+ }
+ }
+
+ /**
+ * Performs a pre-order (or depth-first) node traversal starting with a given node.
+ *
+ * @see <a href="https://en.wikipedia.org/wiki/Pre-order">Pre-order traversal</a>
+ */
+ public static class PreOrderIterator implements Iterator<Node> {
+
+ private final Stack<Node> stack = new Stack<>();
+
+ public PreOrderIterator(Node node) {
+ stack.add(node);
+ }
+
+ @Override
+ public boolean hasNext() {
+ return !stack.isEmpty();
+ }
+
+ @Override
+ public Node next() {
+ Node next = stack.pop();
+ List<Node> children = next.getChildNodes();
+ for (int i = children.size() - 1; i >= 0; i--) {
+ stack.add(children.get(i));
+ }
+ return next;
+ }
+ }
+
+ /**
+ * Performs a post-order (or leaves-first) node traversal starting with a given node.
+ *
+ * @see <a href="https://en.wikipedia.org/wiki/Post-order">Post-order traversal</a>
+ */
+ public static class PostOrderIterator implements Iterator<Node> {
+
+ private final Stack<List<Node>> nodesStack = new Stack<>();
+
+ private final Stack<Integer> cursorStack = new Stack<>();
+
+ private final Node root;
+
+ private boolean hasNext = true;
+
+ public PostOrderIterator(Node root) {
+ this.root = root;
+ fillStackToLeaf(root);
+ }
+
+ private void fillStackToLeaf(Node node) {
+ while (true) {
+ List<Node> childNodes = new ArrayList<>(node.getChildNodes());
+ if (childNodes.isEmpty()) {
+ break;
+ }
+ nodesStack.push(childNodes);
+ cursorStack.push(0);
+ node = childNodes.get(0);
+ }
+ }
+
+ @Override
+ public boolean hasNext() {
+ return hasNext;
+ }
+
+ @Override
+ public Node next() {
+ final List<Node> nodes = nodesStack.peek();
+ final int cursor = cursorStack.peek();
+ final boolean levelHasNext = cursor < nodes.size();
+ if (levelHasNext) {
+ Node node = nodes.get(cursor);
+ fillStackToLeaf(node);
+ return nextFromLevel();
+ } else {
+ nodesStack.pop();
+ cursorStack.pop();
+ hasNext = !nodesStack.empty();
+ if (hasNext) {
+ return nextFromLevel();
+ }
+ return root;
+ }
+ }
+
+ private Node nextFromLevel() {
+ final List<Node> nodes = nodesStack.peek();
+ final int cursor = cursorStack.pop();
+ cursorStack.push(cursor + 1);
+ return nodes.get(cursor);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java
new file mode 100644
index 000000000..f370e960d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/NodeList.java
@@ -0,0 +1,542 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast;
+
+import com.github.javaparser.HasParentNode;
+import com.github.javaparser.ast.observer.AstObserver;
+import com.github.javaparser.ast.observer.Observable;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.Visitable;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.InternalProperty;
+
+import java.util.*;
+import java.util.function.*;
+import java.util.stream.Collector;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * A list of nodes.
+ * It usually has a parent node.
+ * Unlike normal Nodes, this does not mean that it is a child of that parent.
+ * Instead, this list will make every node it contains a child of its parent.
+ * This way, a NodeList does not create an extra level inside the AST.
+ *
+ * @param <N> the type of nodes contained.
+ */
+public class NodeList<N extends Node> implements List<N>, Iterable<N>, HasParentNode<NodeList<N>>, Visitable, Observable {
+ @InternalProperty
+ private List<N> innerList = new ArrayList<>(0);
+
+ private Node parentNode;
+
+ private List<AstObserver> observers = new ArrayList<>();
+
+ public NodeList() {
+ parentNode = null;
+ }
+
+ public NodeList(Collection<N> n) {
+ this.addAll(n);
+ }
+
+ public NodeList(N... n) {
+ this.addAll(Arrays.asList(n));
+ }
+
+ @Override
+ public boolean add(N node) {
+ notifyElementAdded(innerList.size(), node);
+ own(node);
+ return innerList.add(node);
+ }
+
+ private void own(N node) {
+ if (node == null) {
+ return;
+ }
+ setAsParentNodeOf(node);
+ }
+
+ public boolean remove(Node node) {
+ int index = innerList.indexOf(node);
+ if (index != -1) {
+ notifyElementRemoved(index, node);
+ node.setParentNode(null);
+ }
+ return innerList.remove(node);
+ }
+
+ public N removeFirst() {
+ return remove(0);
+ }
+
+ public N removeLast() {
+ return remove(innerList.size() - 1);
+ }
+
+ @SafeVarargs
+ public static <X extends Node> NodeList<X> nodeList(X... nodes) {
+ final NodeList<X> nodeList = new NodeList<>();
+ Collections.addAll(nodeList, nodes);
+ return nodeList;
+ }
+
+ public static <X extends Node> NodeList<X> nodeList(Collection<X> nodes) {
+ final NodeList<X> nodeList = new NodeList<>();
+ nodeList.addAll(nodes);
+ return nodeList;
+ }
+
+ public static <X extends Node> NodeList<X> nodeList(NodeList<X> nodes) {
+ final NodeList<X> nodeList = new NodeList<>();
+ nodeList.addAll(nodes);
+ return nodeList;
+ }
+
+ public boolean contains(N node) {
+ return innerList.contains(node);
+ }
+
+ @Override
+ public int size() {
+ return innerList.size();
+ }
+
+ @Override
+ public N get(int i) {
+ return innerList.get(i);
+ }
+
+ @Override
+ public Iterator<N> iterator() {
+ // TODO take care of "Iterator.remove"
+ return innerList.iterator();
+ }
+
+ @Override
+ public N set(int index, N element) {
+ if (index < 0 || index >= innerList.size()) {
+ throw new IllegalArgumentException("Illegal index. The index should be between 0 and " + innerList.size()
+ + " excluded. It is instead " + index);
+ }
+ if (element == innerList.get(index)) {
+ return element;
+ }
+ notifyElementReplaced(index, element);
+ innerList.get(index).setParentNode(null);
+ setAsParentNodeOf(element);
+ return innerList.set(index, element);
+ }
+
+ @Override
+ public N remove(int index) {
+ notifyElementRemoved(index, innerList.get(index));
+ N remove = innerList.remove(index);
+ if (remove != null)
+ remove.setParentNode(null);
+ return remove;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return innerList.isEmpty();
+ }
+
+ @Override
+ public void sort(Comparator<? super N> comparator) {
+ innerList.sort(comparator);
+ }
+
+ public void addAll(NodeList<N> otherList) {
+ for (N node : otherList) {
+ add(node);
+ }
+ }
+
+ @Override
+ public void add(int index, N node) {
+ notifyElementAdded(index, node);
+ own(node);
+ innerList.add(index, node);
+ }
+
+ /**
+ * Inserts the node before all other nodes.
+ */
+ public NodeList<N> addFirst(N node) {
+ add(0, node);
+ return this;
+ }
+
+ /**
+ * Inserts the node after all other nodes. (This is simply an alias for add.)
+ */
+ public NodeList<N> addLast(N node) {
+ add(node);
+ return this;
+ }
+
+ /**
+ * Inserts the node after afterThisNode.
+ *
+ * @throws IllegalArgumentException when afterThisNode is not in this list.
+ */
+ public NodeList<N> addAfter(N node, N afterThisNode) {
+ int i = indexOf(afterThisNode);
+ if (i == -1) {
+ throw new IllegalArgumentException("Can't find node to insert after.");
+ }
+ add(i + 1, node);
+ return this;
+ }
+
+ /**
+ * Inserts the node before beforeThisNode.
+ *
+ * @throws IllegalArgumentException when beforeThisNode is not in this list.
+ */
+ public NodeList<N> addBefore(N node, N beforeThisNode) {
+ int i = indexOf(beforeThisNode);
+ if (i == -1) {
+ throw new IllegalArgumentException("Can't find node to insert before.");
+ }
+ add(i, node);
+ return this;
+ }
+
+
+ @Override
+ public Optional<Node> getParentNode() {
+ return Optional.ofNullable(parentNode);
+ }
+
+ /**
+ * Sets the parentNode
+ *
+ * @param parentNode the parentNode
+ * @return this, the NodeList
+ */
+ @Override
+ public NodeList<N> setParentNode(Node parentNode) {
+ this.parentNode = parentNode;
+ setAsParentNodeOf(innerList);
+ return this;
+ }
+
+ @Override
+ public Node getParentNodeForChildren() {
+ return parentNode;
+ }
+
+ @Override
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ /**
+ * @see java.lang.Iterable#forEach(java.util.function.Consumer)
+ */
+ @Override
+ public void forEach(Consumer<? super N> action) {
+ innerList.forEach(action);
+ }
+
+ /**
+ * @see java.util.List#contains(java.lang.Object)
+ */
+ @Override
+ public boolean contains(Object o) {
+ return innerList.contains(o);
+ }
+
+ /**
+ * @see java.util.List#toArray()
+ */
+ @Override
+ public Object[] toArray() {
+ return innerList.toArray();
+ }
+
+ /**
+ * @see java.util.List#toArray(java.lang.Object[])
+ */
+ @Override
+ public <T> T[] toArray(T[] a) {
+ return innerList.toArray(a);
+ }
+
+ /**
+ * @see java.util.List#remove(java.lang.Object)
+ */
+ @Override
+ public boolean remove(Object o) {
+ if (o instanceof Node) {
+ return remove((Node) o);
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * @see java.util.List#containsAll(java.util.Collection)
+ */
+ @Override
+ public boolean containsAll(Collection<?> c) {
+ return innerList.containsAll(c);
+ }
+
+ /**
+ * @see java.util.List#addAll(java.util.Collection)
+ */
+ @Override
+ public boolean addAll(Collection<? extends N> c) {
+ c.forEach(this::add);
+ return !c.isEmpty();
+ }
+
+ /**
+ * @see java.util.List#addAll(int, java.util.Collection)
+ */
+ @Override
+ public boolean addAll(int index, Collection<? extends N> c) {
+ for (N e : c) {
+ add(index++, e);
+ }
+ return !c.isEmpty();
+ }
+
+ /**
+ * @see java.util.List#removeAll(java.util.Collection)
+ */
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ boolean changed = false;
+ for (Object e : c) {
+ changed = remove(e) || changed;
+ }
+ return changed;
+ }
+
+ /**
+ * @see java.util.List#retainAll(java.util.Collection)
+ */
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ boolean changed = false;
+ for (Object e : this.stream().filter(it -> !c.contains(it)).toArray()) {
+ if (!c.contains(e)) {
+ changed = remove(e) || changed;
+ }
+ }
+ return changed;
+ }
+
+ /**
+ * @see java.util.List#replaceAll(java.util.function.UnaryOperator)
+ */
+ @Override
+ public void replaceAll(UnaryOperator<N> operator) {
+ for (int i = 0; i < this.size(); i++) {
+ set(i, operator.apply(this.get(i)));
+ }
+ }
+
+ /**
+ * @see java.util.Collection#removeIf(java.util.function.Predicate)
+ */
+ @Override
+ public boolean removeIf(Predicate<? super N> filter) {
+ boolean changed = false;
+ for (Object e : this.stream().filter(filter).toArray()) {
+ changed = remove(e) || changed;
+ }
+ return changed;
+ }
+
+ /**
+ * @see java.util.List#clear()
+ */
+ @Override
+ public void clear() {
+ while (!isEmpty()) {
+ remove(0);
+ }
+ }
+
+ /**
+ * @see java.util.List#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object o) {
+ return innerList.equals(o);
+ }
+
+ /**
+ * @see java.util.List#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return innerList.hashCode();
+ }
+
+ /**
+ * @see java.util.List#indexOf(java.lang.Object)
+ */
+ @Override
+ public int indexOf(Object o) {
+ return innerList.indexOf(o);
+ }
+
+ /**
+ * @see java.util.List#lastIndexOf(java.lang.Object)
+ */
+ @Override
+ public int lastIndexOf(Object o) {
+ return innerList.lastIndexOf(o);
+ }
+
+ /**
+ * @see java.util.List#listIterator()
+ */
+ @Override
+ public ListIterator<N> listIterator() {
+ return innerList.listIterator();
+ }
+
+ /**
+ * @see java.util.List#listIterator(int)
+ */
+ @Override
+ public ListIterator<N> listIterator(int index) {
+ return innerList.listIterator(index);
+ }
+
+ /**
+ * @see java.util.Collection#parallelStream()
+ */
+ @Override
+ public Stream<N> parallelStream() {
+ return innerList.parallelStream();
+ }
+
+ /**
+ * @see java.util.List#subList(int, int)
+ */
+ @Override
+ public List<N> subList(int fromIndex, int toIndex) {
+ return innerList.subList(fromIndex, toIndex);
+ }
+
+ /**
+ * @see java.util.List#spliterator()
+ */
+ @Override
+ public Spliterator<N> spliterator() {
+ return innerList.spliterator();
+ }
+
+ private void notifyElementAdded(int index, Node nodeAddedOrRemoved) {
+ this.observers.forEach(o -> o.listChange(this, AstObserver.ListChangeType.ADDITION, index, nodeAddedOrRemoved));
+ }
+
+ private void notifyElementRemoved(int index, Node nodeAddedOrRemoved) {
+ this.observers.forEach(o -> o.listChange(this, AstObserver.ListChangeType.REMOVAL, index, nodeAddedOrRemoved));
+ }
+
+ private void notifyElementReplaced(int index, Node nodeAddedOrRemoved) {
+ this.observers.forEach(o -> o.listReplacement(this, index, this.get(index), nodeAddedOrRemoved));
+ }
+
+ @Override
+ public void unregister(AstObserver observer) {
+ this.observers.remove(observer);
+ }
+
+ @Override
+ public void register(AstObserver observer) {
+ this.observers.add(observer);
+ }
+
+ @Override
+ public boolean isRegistered(AstObserver observer) {
+ return this.observers.contains(observer);
+ }
+
+ /**
+ * Replaces the first node that is equal to "old" with "replacement".
+ *
+ * @return true if a replacement has happened.
+ */
+ public boolean replace(N old, N replacement) {
+ int i = indexOf(old);
+ if (i == -1) {
+ return false;
+ }
+ set(i, replacement);
+ return true;
+ }
+
+ /**
+ * @return the opposite of isEmpty()
+ */
+ public boolean isNonEmpty() {
+ return !isEmpty();
+ }
+
+ public void ifNonEmpty(Consumer<? super NodeList<N>> consumer) {
+ if (isNonEmpty())
+ consumer.accept(this);
+ }
+
+ public static <T extends Node> Collector<T, NodeList<T>, NodeList<T>> toNodeList() {
+ return Collector.of(NodeList::new, NodeList::add, (left, right) -> {
+ left.addAll(right);
+ return left;
+ });
+ }
+
+ private void setAsParentNodeOf(List<? extends Node> childNodes) {
+ if (childNodes != null) {
+ for (HasParentNode current : childNodes) {
+ current.setParentNode(getParentNodeForChildren());
+ }
+ }
+ }
+
+ private void setAsParentNodeOf(Node childNode) {
+ if (childNode != null) {
+ childNode.setParentNode(getParentNodeForChildren());
+ }
+ }
+
+ @Override
+ public String toString() {
+ return innerList.stream().map(Node::toString).collect(Collectors.joining(", ", "[", "]"));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.java
new file mode 100644
index 000000000..65a1ca74a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/PackageDeclaration.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast;
+
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.PackageDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+
+/**
+ * A package declaration.
+ * <br/><code>package com.github.javaparser.ast;</code>
+ * <br/><code>@Wonderful package anything.can.be.annotated.nowadays;</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class PackageDeclaration extends Node implements NodeWithAnnotations<PackageDeclaration>, NodeWithName<PackageDeclaration> {
+
+ private NodeList<AnnotationExpr> annotations = new NodeList<>();
+
+ private Name name;
+
+ public PackageDeclaration() {
+ this(null, new NodeList<>(), new Name());
+ }
+
+ public PackageDeclaration(Name name) {
+ this(null, new NodeList<>(), name);
+ }
+
+ @AllFieldsConstructor
+ public PackageDeclaration(NodeList<AnnotationExpr> annotations, Name name) {
+ this(null, annotations, name);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public PackageDeclaration(TokenRange tokenRange, NodeList<AnnotationExpr> annotations, Name name) {
+ super(tokenRange);
+ setAnnotations(annotations);
+ setName(name);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ /**
+ * Retrieves the list of annotations declared before the package
+ * declaration. Return <code>null</code> if there are no annotations.
+ *
+ * @return list of annotations or <code>null</code>
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ /**
+ * Return the name expression of the package.
+ *
+ * @return the name of the package
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name getName() {
+ return name;
+ }
+
+ /**
+ * @param annotations the annotations to set
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public PackageDeclaration setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (PackageDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return this;
+ }
+
+ /**
+ * Sets the name of this package declaration.
+ *
+ * @param name the name to set
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public PackageDeclaration setName(final Name name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (PackageDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public PackageDeclaration clone() {
+ return (PackageDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public PackageDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.packageDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((Name) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationDeclaration.java
new file mode 100644
index 000000000..aa793efb9
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationDeclaration.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.AnnotationDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An annotation type declaration.<br/><code>@interface X { ... }</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class AnnotationDeclaration extends TypeDeclaration<AnnotationDeclaration> implements NodeWithAbstractModifier<AnnotationDeclaration>, Resolvable<ResolvedAnnotationDeclaration> {
+
+ public AnnotationDeclaration() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>());
+ }
+
+ public AnnotationDeclaration(EnumSet<Modifier> modifiers, String name) {
+ this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public AnnotationDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members) {
+ this(null, modifiers, annotations, name, members);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public AnnotationDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members) {
+ super(tokenRange, modifiers, annotations, name, members);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public AnnotationDeclaration clone() {
+ return (AnnotationDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public AnnotationDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.annotationDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAnnotationDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AnnotationDeclaration asAnnotationDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAnnotationDeclaration(Consumer<AnnotationDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedAnnotationDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedAnnotationDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AnnotationDeclaration> toAnnotationDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java
new file mode 100644
index 000000000..48b6db6f5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/AnnotationMemberDeclaration.java
@@ -0,0 +1,275 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithPublicModifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.AnnotationMemberDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedAnnotationMemberDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
+import javax.annotation.Generated;
+import java.util.EnumSet;
+import java.util.Optional;
+import java.util.function.Consumer;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * The "int id();" in <code>@interface X { int id(); }</code>
+ * <p>
+ * <br/>All annotations preceding the type will be set on this object, not on the type. JavaParser doesn't know if it
+ * they are applicable to the method or the type.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class AnnotationMemberDeclaration extends BodyDeclaration<AnnotationMemberDeclaration> implements NodeWithJavadoc<AnnotationMemberDeclaration>, NodeWithSimpleName<AnnotationMemberDeclaration>, NodeWithType<AnnotationMemberDeclaration, Type>, NodeWithPublicModifier<AnnotationMemberDeclaration>, NodeWithAbstractModifier<AnnotationMemberDeclaration>, Resolvable<ResolvedAnnotationMemberDeclaration> {
+
+ private EnumSet<Modifier> modifiers;
+
+ private Type type;
+
+ private SimpleName name;
+
+ @OptionalProperty
+ private Expression defaultValue;
+
+ public AnnotationMemberDeclaration() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new ClassOrInterfaceType(), new SimpleName(), null);
+ }
+
+ public AnnotationMemberDeclaration(EnumSet<Modifier> modifiers, Type type, String name, Expression defaultValue) {
+ this(null, modifiers, new NodeList<>(), type, new SimpleName(name), defaultValue);
+ }
+
+ @AllFieldsConstructor
+ public AnnotationMemberDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, Type type, SimpleName name, Expression defaultValue) {
+ this(null, modifiers, annotations, type, name, defaultValue);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public AnnotationMemberDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, Type type, SimpleName name, Expression defaultValue) {
+ super(tokenRange, annotations);
+ setModifiers(modifiers);
+ setType(type);
+ setName(name);
+ setDefaultValue(defaultValue);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getDefaultValue() {
+ return Optional.ofNullable(defaultValue);
+ }
+
+ /**
+ * Return the modifiers of this member declaration.
+ *
+ * @return modifiers
+ * @see Modifier
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumSet<Modifier> getModifiers() {
+ return modifiers;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public AnnotationMemberDeclaration removeDefaultValue() {
+ return setDefaultValue((Expression) null);
+ }
+
+ /**
+ * Sets the default value
+ *
+ * @param defaultValue the default value, can be null
+ * @return this, the AnnotationMemberDeclaration
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AnnotationMemberDeclaration setDefaultValue(final Expression defaultValue) {
+ if (defaultValue == this.defaultValue) {
+ return (AnnotationMemberDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.DEFAULT_VALUE, this.defaultValue, defaultValue);
+ if (this.defaultValue != null)
+ this.defaultValue.setParentNode(null);
+ this.defaultValue = defaultValue;
+ setAsParentNodeOf(defaultValue);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AnnotationMemberDeclaration setModifiers(final EnumSet<Modifier> modifiers) {
+ assertNotNull(modifiers);
+ if (modifiers == this.modifiers) {
+ return (AnnotationMemberDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers);
+ this.modifiers = modifiers;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AnnotationMemberDeclaration setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (AnnotationMemberDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AnnotationMemberDeclaration setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (AnnotationMemberDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (defaultValue != null) {
+ if (node == defaultValue) {
+ removeDefaultValue();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public AnnotationMemberDeclaration clone() {
+ return (AnnotationMemberDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public AnnotationMemberDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.annotationMemberDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (defaultValue != null) {
+ if (node == defaultValue) {
+ setDefaultValue((Expression) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAnnotationMemberDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AnnotationMemberDeclaration asAnnotationMemberDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAnnotationMemberDeclaration(Consumer<AnnotationMemberDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedAnnotationMemberDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedAnnotationMemberDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AnnotationMemberDeclaration> toAnnotationMemberDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/BodyDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/BodyDeclaration.java
new file mode 100644
index 000000000..dc871e3cd
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/BodyDeclaration.java
@@ -0,0 +1,339 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.BodyDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+import java.util.Optional;
+
+/**
+ * Any declaration that can appear between the { and } of a class, interface, or enum.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class BodyDeclaration<T extends BodyDeclaration<?>> extends Node implements NodeWithAnnotations<T> {
+
+ private NodeList<AnnotationExpr> annotations;
+
+ public BodyDeclaration() {
+ this(null, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public BodyDeclaration(NodeList<AnnotationExpr> annotations) {
+ this(null, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public BodyDeclaration(TokenRange tokenRange, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange);
+ setAnnotations(annotations);
+ customInitialization();
+ }
+
+ protected BodyDeclaration(TokenRange range) {
+ this(range, new NodeList<>());
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return (T) this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public BodyDeclaration<?> clone() {
+ return (BodyDeclaration<?>) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public BodyDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.bodyDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAnnotationDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AnnotationDeclaration asAnnotationDeclaration() {
+ throw new IllegalStateException(f("%s is not an AnnotationDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAnnotationMemberDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AnnotationMemberDeclaration asAnnotationMemberDeclaration() {
+ throw new IllegalStateException(f("%s is not an AnnotationMemberDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isCallableDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public CallableDeclaration asCallableDeclaration() {
+ throw new IllegalStateException(f("%s is not an CallableDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isClassOrInterfaceDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ClassOrInterfaceDeclaration asClassOrInterfaceDeclaration() {
+ throw new IllegalStateException(f("%s is not an ClassOrInterfaceDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isConstructorDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ConstructorDeclaration asConstructorDeclaration() {
+ throw new IllegalStateException(f("%s is not an ConstructorDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isEnumConstantDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public EnumConstantDeclaration asEnumConstantDeclaration() {
+ throw new IllegalStateException(f("%s is not an EnumConstantDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isEnumDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public EnumDeclaration asEnumDeclaration() {
+ throw new IllegalStateException(f("%s is not an EnumDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isFieldDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public FieldDeclaration asFieldDeclaration() {
+ throw new IllegalStateException(f("%s is not an FieldDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isInitializerDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public InitializerDeclaration asInitializerDeclaration() {
+ throw new IllegalStateException(f("%s is not an InitializerDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isMethodDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public MethodDeclaration asMethodDeclaration() {
+ throw new IllegalStateException(f("%s is not an MethodDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isTypeDeclaration() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public TypeDeclaration asTypeDeclaration() {
+ throw new IllegalStateException(f("%s is not an TypeDeclaration", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAnnotationDeclaration(Consumer<AnnotationDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAnnotationMemberDeclaration(Consumer<AnnotationMemberDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifCallableDeclaration(Consumer<CallableDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifClassOrInterfaceDeclaration(Consumer<ClassOrInterfaceDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifConstructorDeclaration(Consumer<ConstructorDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifEnumConstantDeclaration(Consumer<EnumConstantDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifEnumDeclaration(Consumer<EnumDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifFieldDeclaration(Consumer<FieldDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifInitializerDeclaration(Consumer<InitializerDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifMethodDeclaration(Consumer<MethodDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifTypeDeclaration(Consumer<TypeDeclaration> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AnnotationDeclaration> toAnnotationDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AnnotationMemberDeclaration> toAnnotationMemberDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<CallableDeclaration> toCallableDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ClassOrInterfaceDeclaration> toClassOrInterfaceDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ConstructorDeclaration> toConstructorDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<EnumConstantDeclaration> toEnumConstantDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<EnumDeclaration> toEnumDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<FieldDeclaration> toFieldDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<InitializerDeclaration> toInitializerDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<MethodDeclaration> toMethodDeclaration() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<TypeDeclaration> toTypeDeclaration() {
+ return Optional.empty();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java
new file mode 100644
index 000000000..e2e41fe15
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/CallableDeclaration.java
@@ -0,0 +1,428 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2017 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.*;
+import com.github.javaparser.ast.nodeTypes.modifiers.*;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ArrayType;
+import com.github.javaparser.ast.type.ReferenceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.type.TypeParameter;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.CallableDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.OptionalProperty;
+import javax.annotation.Generated;
+import java.util.EnumSet;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.joining;
+import static java.util.stream.Collectors.toList;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+/**
+ * Represents a declaration which is callable eg. a method or a constructor.
+ */
+public abstract class CallableDeclaration<T extends CallableDeclaration<?>> extends BodyDeclaration<T> implements NodeWithAccessModifiers<T>, NodeWithDeclaration, NodeWithSimpleName<T>, NodeWithParameters<T>, NodeWithThrownExceptions<T>, NodeWithTypeParameters<T>, NodeWithJavadoc<T>, NodeWithAbstractModifier<T>, NodeWithStaticModifier<T>, NodeWithFinalModifier<T>, NodeWithStrictfpModifier<T> {
+
+ private EnumSet<Modifier> modifiers;
+
+ private NodeList<TypeParameter> typeParameters;
+
+ private SimpleName name;
+
+ private NodeList<Parameter> parameters;
+
+ private NodeList<ReferenceType> thrownExceptions;
+
+ @OptionalProperty
+ private ReceiverParameter receiverParameter;
+
+ @AllFieldsConstructor
+ CallableDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, ReceiverParameter receiverParameter) {
+ this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public CallableDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, ReceiverParameter receiverParameter) {
+ super(tokenRange, annotations);
+ setModifiers(modifiers);
+ setTypeParameters(typeParameters);
+ setName(name);
+ setParameters(parameters);
+ setThrownExceptions(thrownExceptions);
+ setReceiverParameter(receiverParameter);
+ customInitialization();
+ }
+
+ /**
+ * Return the modifiers of this member declaration.
+ *
+ * @return modifiers
+ * @see Modifier
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumSet<Modifier> getModifiers() {
+ return modifiers;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setModifiers(final EnumSet<Modifier> modifiers) {
+ assertNotNull(modifiers);
+ if (modifiers == this.modifiers) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers);
+ this.modifiers = modifiers;
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Parameter> getParameters() {
+ return parameters;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setParameters(final NodeList<Parameter> parameters) {
+ assertNotNull(parameters);
+ if (parameters == this.parameters) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.PARAMETERS, this.parameters, parameters);
+ if (this.parameters != null)
+ this.parameters.setParentNode(null);
+ this.parameters = parameters;
+ setAsParentNodeOf(parameters);
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ReferenceType> getThrownExceptions() {
+ return thrownExceptions;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setThrownExceptions(final NodeList<ReferenceType> thrownExceptions) {
+ assertNotNull(thrownExceptions);
+ if (thrownExceptions == this.thrownExceptions) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.THROWN_EXCEPTIONS, this.thrownExceptions, thrownExceptions);
+ if (this.thrownExceptions != null)
+ this.thrownExceptions.setParentNode(null);
+ this.thrownExceptions = thrownExceptions;
+ setAsParentNodeOf(thrownExceptions);
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<TypeParameter> getTypeParameters() {
+ return typeParameters;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setTypeParameters(final NodeList<TypeParameter> typeParameters) {
+ assertNotNull(typeParameters);
+ if (typeParameters == this.typeParameters) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_PARAMETERS, this.typeParameters, typeParameters);
+ if (this.typeParameters != null)
+ this.typeParameters.setParentNode(null);
+ this.typeParameters = typeParameters;
+ setAsParentNodeOf(typeParameters);
+ return (T) this;
+ }
+
+ public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows) {
+ return getDeclarationAsString(includingModifiers, includingThrows, true);
+ }
+
+ public String getDeclarationAsString() {
+ return getDeclarationAsString(true, true, true);
+ }
+
+ public abstract String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName);
+
+ protected String appendThrowsIfRequested(boolean includingThrows) {
+ StringBuilder sb = new StringBuilder();
+ if (includingThrows) {
+ boolean firstThrow = true;
+ for (ReferenceType thr : getThrownExceptions()) {
+ if (firstThrow) {
+ firstThrow = false;
+ sb.append(" throws ");
+ } else {
+ sb.append(", ");
+ }
+ sb.append(thr.toString(prettyPrinterNoCommentsConfiguration));
+ }
+ }
+ return sb.toString();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < parameters.size(); i++) {
+ if (parameters.get(i) == node) {
+ parameters.remove(i);
+ return true;
+ }
+ }
+ if (receiverParameter != null) {
+ if (node == receiverParameter) {
+ removeReceiverParameter();
+ return true;
+ }
+ }
+ for (int i = 0; i < thrownExceptions.size(); i++) {
+ if (thrownExceptions.get(i) == node) {
+ thrownExceptions.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < typeParameters.size(); i++) {
+ if (typeParameters.get(i) == node) {
+ typeParameters.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ /**
+ * A method or constructor signature.
+ * <p/>Note that since JavaParser has no real knowledge of types - only the text found in the source file - using
+ * this will fail in some cases. (java.util.String != String for example, and generics are not taken into account.)
+ */
+ public static class Signature {
+
+ private final String name;
+
+ private final List<Type> parameterTypes;
+
+ private Signature(String name, List<Type> parameterTypes) {
+ this.name = name;
+ this.parameterTypes = parameterTypes;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<Type> getParameterTypes() {
+ return parameterTypes;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Signature signature = (Signature) o;
+ if (!name.equals(signature.name))
+ return false;
+ if (!parameterTypes.equals(signature.parameterTypes))
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = name.hashCode();
+ result = 31 * result + parameterTypes.hashCode();
+ return result;
+ }
+
+ public String asString() {
+ return parameterTypes.stream().map(Type::asString).collect(joining(", ", name + "(", ")"));
+ }
+
+ @Override
+ public String toString() {
+ return asString();
+ }
+ }
+
+ public Signature getSignature() {
+ return new Signature(getName().getIdentifier(), getParameters().stream().map(this::getTypeWithVarargsAsArray).map(this::stripGenerics).map(this::stripAnnotations).collect(toList()));
+ }
+
+ private Type stripAnnotations(Type type) {
+ if (type instanceof NodeWithAnnotations) {
+ ((NodeWithAnnotations) type).setAnnotations(new NodeList<>());
+ }
+ return type;
+ }
+
+ private Type stripGenerics(Type type) {
+ if (type instanceof NodeWithTypeArguments) {
+ ((NodeWithTypeArguments) type).setTypeArguments((NodeList<Type>) null);
+ }
+ return type;
+ }
+
+ private Type getTypeWithVarargsAsArray(Parameter p) {
+ /* A signature includes the varargs ellipsis.
+ This is a field on parameter which we lose when we only get the type,
+ so we represent it as an additional [] on the type. */
+ Type t = p.getType().clone();
+ if (p.isVarArgs()) {
+ t = new ArrayType(t);
+ }
+ return t;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public CallableDeclaration<?> clone() {
+ return (CallableDeclaration<?>) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public CallableDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.callableDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ for (int i = 0; i < parameters.size(); i++) {
+ if (parameters.get(i) == node) {
+ parameters.set(i, (Parameter) replacementNode);
+ return true;
+ }
+ }
+ if (receiverParameter != null) {
+ if (node == receiverParameter) {
+ setReceiverParameter((ReceiverParameter) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < thrownExceptions.size(); i++) {
+ if (thrownExceptions.get(i) == node) {
+ thrownExceptions.set(i, (ReferenceType) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < typeParameters.size(); i++) {
+ if (typeParameters.get(i) == node) {
+ typeParameters.set(i, (TypeParameter) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isCallableDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public CallableDeclaration asCallableDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifCallableDeclaration(Consumer<CallableDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<ReceiverParameter> getReceiverParameter() {
+ return Optional.ofNullable(receiverParameter);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setReceiverParameter(final ReceiverParameter receiverParameter) {
+ if (receiverParameter == this.receiverParameter) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.RECEIVER_PARAMETER, this.receiverParameter, receiverParameter);
+ if (this.receiverParameter != null)
+ this.receiverParameter.setParentNode(null);
+ this.receiverParameter = receiverParameter;
+ setAsParentNodeOf(receiverParameter);
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public CallableDeclaration removeReceiverParameter() {
+ return setReceiverParameter((ReceiverParameter) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<CallableDeclaration> toCallableDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java
new file mode 100644
index 000000000..a275066ad
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ClassOrInterfaceDeclaration.java
@@ -0,0 +1,286 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithConstructors;
+import com.github.javaparser.ast.nodeTypes.NodeWithExtends;
+import com.github.javaparser.ast.nodeTypes.NodeWithImplements;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAbstractModifier;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.TypeParameter;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.ClassOrInterfaceDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedAnnotationDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
+import javax.annotation.Generated;
+import java.util.EnumSet;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A definition of a class or interface.<br/><code>class X { ... }</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ClassOrInterfaceDeclaration extends TypeDeclaration<ClassOrInterfaceDeclaration> implements NodeWithImplements<ClassOrInterfaceDeclaration>, NodeWithExtends<ClassOrInterfaceDeclaration>, NodeWithTypeParameters<ClassOrInterfaceDeclaration>, NodeWithAbstractModifier<ClassOrInterfaceDeclaration>, NodeWithFinalModifier<ClassOrInterfaceDeclaration>, NodeWithConstructors<ClassOrInterfaceDeclaration>, Resolvable<ResolvedReferenceTypeDeclaration> {
+
+ private boolean isInterface;
+
+ private NodeList<TypeParameter> typeParameters;
+
+ // Can contain more than one item if this is an interface
+ private NodeList<ClassOrInterfaceType> extendedTypes;
+
+ private NodeList<ClassOrInterfaceType> implementedTypes;
+
+ public ClassOrInterfaceDeclaration() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), false, new SimpleName(), new NodeList<>(), new NodeList<>(), new NodeList<>(), new NodeList<>());
+ }
+
+ public ClassOrInterfaceDeclaration(final EnumSet<Modifier> modifiers, final boolean isInterface, final String name) {
+ this(null, modifiers, new NodeList<>(), isInterface, new SimpleName(name), new NodeList<>(), new NodeList<>(), new NodeList<>(), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ClassOrInterfaceDeclaration(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final boolean isInterface, final SimpleName name, final NodeList<TypeParameter> typeParameters, final NodeList<ClassOrInterfaceType> extendedTypes, final NodeList<ClassOrInterfaceType> implementedTypes, final NodeList<BodyDeclaration<?>> members) {
+ this(null, modifiers, annotations, isInterface, name, typeParameters, extendedTypes, implementedTypes, members);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ClassOrInterfaceDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, boolean isInterface, SimpleName name, NodeList<TypeParameter> typeParameters, NodeList<ClassOrInterfaceType> extendedTypes, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<BodyDeclaration<?>> members) {
+ super(tokenRange, modifiers, annotations, name, members);
+ setInterface(isInterface);
+ setTypeParameters(typeParameters);
+ setExtendedTypes(extendedTypes);
+ setImplementedTypes(implementedTypes);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ClassOrInterfaceType> getExtendedTypes() {
+ return extendedTypes;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ClassOrInterfaceType> getImplementedTypes() {
+ return implementedTypes;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<TypeParameter> getTypeParameters() {
+ return typeParameters;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean isInterface() {
+ return isInterface;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceDeclaration setExtendedTypes(final NodeList<ClassOrInterfaceType> extendedTypes) {
+ assertNotNull(extendedTypes);
+ if (extendedTypes == this.extendedTypes) {
+ return (ClassOrInterfaceDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXTENDED_TYPES, this.extendedTypes, extendedTypes);
+ if (this.extendedTypes != null)
+ this.extendedTypes.setParentNode(null);
+ this.extendedTypes = extendedTypes;
+ setAsParentNodeOf(extendedTypes);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceDeclaration setImplementedTypes(final NodeList<ClassOrInterfaceType> implementedTypes) {
+ assertNotNull(implementedTypes);
+ if (implementedTypes == this.implementedTypes) {
+ return (ClassOrInterfaceDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.IMPLEMENTED_TYPES, this.implementedTypes, implementedTypes);
+ if (this.implementedTypes != null)
+ this.implementedTypes.setParentNode(null);
+ this.implementedTypes = implementedTypes;
+ setAsParentNodeOf(implementedTypes);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceDeclaration setInterface(final boolean isInterface) {
+ if (isInterface == this.isInterface) {
+ return (ClassOrInterfaceDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.INTERFACE, this.isInterface, isInterface);
+ this.isInterface = isInterface;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceDeclaration setTypeParameters(final NodeList<TypeParameter> typeParameters) {
+ assertNotNull(typeParameters);
+ if (typeParameters == this.typeParameters) {
+ return (ClassOrInterfaceDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_PARAMETERS, this.typeParameters, typeParameters);
+ if (this.typeParameters != null)
+ this.typeParameters.setParentNode(null);
+ this.typeParameters = typeParameters;
+ setAsParentNodeOf(typeParameters);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < extendedTypes.size(); i++) {
+ if (extendedTypes.get(i) == node) {
+ extendedTypes.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < implementedTypes.size(); i++) {
+ if (implementedTypes.get(i) == node) {
+ implementedTypes.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < typeParameters.size(); i++) {
+ if (typeParameters.get(i) == node) {
+ typeParameters.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ /**
+ * @return is this class's parent a LocalClassDeclarationStmt ?
+ */
+ public boolean isLocalClassDeclaration() {
+ return getParentNode().map(p -> p instanceof LocalClassDeclarationStmt).orElse(false);
+ }
+
+ /**
+ * @return is this an inner class?
+ * NOTE: many people are confused over terminology. Refer to https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html .
+ */
+ public boolean isInnerClass() {
+ return isNestedType() && !isInterface && !isStatic();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ClassOrInterfaceDeclaration clone() {
+ return (ClassOrInterfaceDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ClassOrInterfaceDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.classOrInterfaceDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < extendedTypes.size(); i++) {
+ if (extendedTypes.get(i) == node) {
+ extendedTypes.set(i, (ClassOrInterfaceType) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < implementedTypes.size(); i++) {
+ if (implementedTypes.get(i) == node) {
+ implementedTypes.set(i, (ClassOrInterfaceType) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < typeParameters.size(); i++) {
+ if (typeParameters.get(i) == node) {
+ typeParameters.set(i, (TypeParameter) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isClassOrInterfaceDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ClassOrInterfaceDeclaration asClassOrInterfaceDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifClassOrInterfaceDeclaration(Consumer<ClassOrInterfaceDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedReferenceTypeDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedReferenceTypeDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ClassOrInterfaceDeclaration> toClassOrInterfaceDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java
new file mode 100644
index 000000000..ab1dad9cb
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ConstructorDeclaration.java
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2017 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AccessSpecifier;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.*;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAccessModifiers;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.type.ReferenceType;
+import com.github.javaparser.ast.type.TypeParameter;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.EnumSet;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ConstructorDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A constructor declaration: <code>class X { X() { } }</code> where X(){} is the constructor declaration.
+ *
+ * <br/>All annotations preceding the name will be set on this object, not on the class.
+ * JavaParser doesn't know if it they are applicable to the method or the class.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ConstructorDeclaration extends CallableDeclaration<ConstructorDeclaration> implements NodeWithBlockStmt<ConstructorDeclaration>, NodeWithAccessModifiers<ConstructorDeclaration>, NodeWithJavadoc<ConstructorDeclaration>, NodeWithSimpleName<ConstructorDeclaration>, NodeWithParameters<ConstructorDeclaration>, NodeWithThrownExceptions<ConstructorDeclaration>, NodeWithTypeParameters<ConstructorDeclaration>, Resolvable<ResolvedConstructorDeclaration> {
+
+ private BlockStmt body;
+
+ public ConstructorDeclaration() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>(), new BlockStmt(), null);
+ }
+
+ public ConstructorDeclaration(String name) {
+ this(null, EnumSet.of(Modifier.PUBLIC), new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null);
+ }
+
+ public ConstructorDeclaration(EnumSet<Modifier> modifiers, String name) {
+ this(null, modifiers, new NodeList<>(), new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null);
+ }
+
+ public ConstructorDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body) {
+ this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, body, null);
+ }
+
+ @AllFieldsConstructor
+ public ConstructorDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) {
+ this(null, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, body, receiverParameter);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ConstructorDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) {
+ super(tokenRange, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter);
+ setBody(body);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BlockStmt getBody() {
+ return body;
+ }
+
+ /**
+ * Sets the body
+ *
+ * @param body the body, can not be null
+ * @return this, the ConstructorDeclaration
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ConstructorDeclaration setBody(final BlockStmt body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (ConstructorDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Override
+ public ConstructorDeclaration setModifiers(final EnumSet<Modifier> modifiers) {
+ return super.setModifiers(modifiers);
+ }
+
+ @Override
+ public ConstructorDeclaration setName(final SimpleName name) {
+ return super.setName(name);
+ }
+
+ @Override
+ public ConstructorDeclaration setParameters(final NodeList<Parameter> parameters) {
+ return super.setParameters(parameters);
+ }
+
+ @Override
+ public ConstructorDeclaration setThrownExceptions(final NodeList<ReferenceType> thrownExceptions) {
+ return super.setThrownExceptions(thrownExceptions);
+ }
+
+ @Override
+ public ConstructorDeclaration setTypeParameters(final NodeList<TypeParameter> typeParameters) {
+ return super.setTypeParameters(typeParameters);
+ }
+
+ /**
+ * The declaration returned has this schema:
+ * <p>
+ * [accessSpecifier] className ([paramType [paramName]])
+ * [throws exceptionsList]
+ */
+ @Override
+ public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName) {
+ StringBuilder sb = new StringBuilder();
+ if (includingModifiers) {
+ AccessSpecifier accessSpecifier = Modifier.getAccessSpecifier(getModifiers());
+ sb.append(accessSpecifier.asString());
+ sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " ");
+ }
+ sb.append(getName());
+ sb.append("(");
+ boolean firstParam = true;
+ for (Parameter param : getParameters()) {
+ if (firstParam) {
+ firstParam = false;
+ } else {
+ sb.append(", ");
+ }
+ if (includingParameterName) {
+ sb.append(param.toString(prettyPrinterNoCommentsConfiguration));
+ } else {
+ sb.append(param.getType().toString(prettyPrinterNoCommentsConfiguration));
+ }
+ }
+ sb.append(")");
+ sb.append(appendThrowsIfRequested(includingThrows));
+ return sb.toString();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ConstructorDeclaration clone() {
+ return (ConstructorDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ConstructorDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.constructorDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((BlockStmt) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isConstructorDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ConstructorDeclaration asConstructorDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifConstructorDeclaration(Consumer<ConstructorDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedConstructorDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedConstructorDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ConstructorDeclaration> toConstructorDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumConstantDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumConstantDeclaration.java
new file mode 100644
index 000000000..5a331e4a6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumConstantDeclaration.java
@@ -0,0 +1,239 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithArguments;
+import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.EnumConstantDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedEnumConstantDeclaration;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * One of the values an enum can take. A(1) and B(2) in this example: <code>enum X { A(1), B(2) }</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class EnumConstantDeclaration extends BodyDeclaration<EnumConstantDeclaration> implements NodeWithJavadoc<EnumConstantDeclaration>, NodeWithSimpleName<EnumConstantDeclaration>, NodeWithArguments<EnumConstantDeclaration>, Resolvable<ResolvedEnumConstantDeclaration> {
+
+ private SimpleName name;
+
+ private NodeList<Expression> arguments;
+
+ private NodeList<BodyDeclaration<?>> classBody;
+
+ public EnumConstantDeclaration() {
+ this(null, new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>());
+ }
+
+ public EnumConstantDeclaration(String name) {
+ this(null, new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public EnumConstantDeclaration(NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<Expression> arguments, NodeList<BodyDeclaration<?>> classBody) {
+ this(null, annotations, name, arguments, classBody);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public EnumConstantDeclaration(TokenRange tokenRange, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<Expression> arguments, NodeList<BodyDeclaration<?>> classBody) {
+ super(tokenRange, annotations);
+ setName(name);
+ setArguments(arguments);
+ setClassBody(classBody);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Expression> getArguments() {
+ return arguments;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<BodyDeclaration<?>> getClassBody() {
+ return classBody;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumConstantDeclaration setArguments(final NodeList<Expression> arguments) {
+ assertNotNull(arguments);
+ if (arguments == this.arguments) {
+ return (EnumConstantDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.ARGUMENTS, this.arguments, arguments);
+ if (this.arguments != null)
+ this.arguments.setParentNode(null);
+ this.arguments = arguments;
+ setAsParentNodeOf(arguments);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumConstantDeclaration setClassBody(final NodeList<BodyDeclaration<?>> classBody) {
+ assertNotNull(classBody);
+ if (classBody == this.classBody) {
+ return (EnumConstantDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.CLASS_BODY, this.classBody, classBody);
+ if (this.classBody != null)
+ this.classBody.setParentNode(null);
+ this.classBody = classBody;
+ setAsParentNodeOf(classBody);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumConstantDeclaration setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (EnumConstantDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments.get(i) == node) {
+ arguments.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < classBody.size(); i++) {
+ if (classBody.get(i) == node) {
+ classBody.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public EnumConstantDeclaration clone() {
+ return (EnumConstantDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public EnumConstantDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.enumConstantDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments.get(i) == node) {
+ arguments.set(i, (Expression) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < classBody.size(); i++) {
+ if (classBody.get(i) == node) {
+ classBody.set(i, (BodyDeclaration) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isEnumConstantDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public EnumConstantDeclaration asEnumConstantDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifEnumConstantDeclaration(Consumer<EnumConstantDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedEnumConstantDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedEnumConstantDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<EnumConstantDeclaration> toEnumConstantDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumDeclaration.java
new file mode 100644
index 000000000..44fb1e411
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/EnumDeclaration.java
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithConstructors;
+import com.github.javaparser.ast.nodeTypes.NodeWithImplements;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.EnumDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedEnumDeclaration;
+import javax.annotation.Generated;
+import java.util.EnumSet;
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * The declaration of an enum.<br/><code>enum X { ... }</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class EnumDeclaration extends TypeDeclaration<EnumDeclaration> implements NodeWithImplements<EnumDeclaration>, NodeWithConstructors<EnumDeclaration>, Resolvable<ResolvedEnumDeclaration> {
+
+ private NodeList<ClassOrInterfaceType> implementedTypes;
+
+ private NodeList<EnumConstantDeclaration> entries;
+
+ public EnumDeclaration() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>(), new NodeList<>(), new NodeList<>());
+ }
+
+ public EnumDeclaration(EnumSet<Modifier> modifiers, String name) {
+ this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>(), new NodeList<>(), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public EnumDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<EnumConstantDeclaration> entries, NodeList<BodyDeclaration<?>> members) {
+ this(null, modifiers, annotations, name, implementedTypes, entries, members);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public EnumDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<ClassOrInterfaceType> implementedTypes, NodeList<EnumConstantDeclaration> entries, NodeList<BodyDeclaration<?>> members) {
+ super(tokenRange, modifiers, annotations, name, members);
+ setImplementedTypes(implementedTypes);
+ setEntries(entries);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<EnumConstantDeclaration> getEntries() {
+ return entries;
+ }
+
+ public EnumConstantDeclaration getEntry(int i) {
+ return getEntries().get(i);
+ }
+
+ public EnumDeclaration setEntry(int i, EnumConstantDeclaration element) {
+ getEntries().set(i, element);
+ return this;
+ }
+
+ public EnumDeclaration addEntry(EnumConstantDeclaration element) {
+ getEntries().add(element);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ClassOrInterfaceType> getImplementedTypes() {
+ return implementedTypes;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumDeclaration setEntries(final NodeList<EnumConstantDeclaration> entries) {
+ assertNotNull(entries);
+ if (entries == this.entries) {
+ return (EnumDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.ENTRIES, this.entries, entries);
+ if (this.entries != null)
+ this.entries.setParentNode(null);
+ this.entries = entries;
+ setAsParentNodeOf(entries);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumDeclaration setImplementedTypes(final NodeList<ClassOrInterfaceType> implementedTypes) {
+ assertNotNull(implementedTypes);
+ if (implementedTypes == this.implementedTypes) {
+ return (EnumDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.IMPLEMENTED_TYPES, this.implementedTypes, implementedTypes);
+ if (this.implementedTypes != null)
+ this.implementedTypes.setParentNode(null);
+ this.implementedTypes = implementedTypes;
+ setAsParentNodeOf(implementedTypes);
+ return this;
+ }
+
+ public EnumConstantDeclaration addEnumConstant(String name) {
+ assertNonEmpty(name);
+ EnumConstantDeclaration enumConstant = new EnumConstantDeclaration(name);
+ getEntries().add(enumConstant);
+ return enumConstant;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < entries.size(); i++) {
+ if (entries.get(i) == node) {
+ entries.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < implementedTypes.size(); i++) {
+ if (implementedTypes.get(i) == node) {
+ implementedTypes.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public EnumDeclaration clone() {
+ return (EnumDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public EnumDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.enumDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < entries.size(); i++) {
+ if (entries.get(i) == node) {
+ entries.set(i, (EnumConstantDeclaration) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < implementedTypes.size(); i++) {
+ if (implementedTypes.get(i) == node) {
+ implementedTypes.set(i, (ClassOrInterfaceType) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isEnumDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public EnumDeclaration asEnumDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifEnumDeclaration(Consumer<EnumDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedEnumDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedEnumDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<EnumDeclaration> toEnumDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java
new file mode 100644
index 000000000..547e95ab9
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/FieldDeclaration.java
@@ -0,0 +1,307 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.AssignExpr;
+import com.github.javaparser.ast.expr.AssignExpr.Operator;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc;
+import com.github.javaparser.ast.nodeTypes.NodeWithVariables;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAccessModifiers;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.stmt.ReturnStmt;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.type.VoidType;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.FieldDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.ast.Modifier.*;
+import static com.github.javaparser.ast.NodeList.nodeList;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration;
+import java.util.function.Consumer;
+
+/**
+ * The declaration of a field in a class. "private static int a=15*15;" in this example: <code>class X { private static
+ * int a=15*15; }</code>
+ *
+ * <br/>All annotations preceding the type will be set on this object, not on the type.
+ * JavaParser doesn't know if it they are applicable to the method or the type.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class FieldDeclaration extends BodyDeclaration<FieldDeclaration> implements NodeWithJavadoc<FieldDeclaration>, NodeWithVariables<FieldDeclaration>, NodeWithAccessModifiers<FieldDeclaration>, NodeWithStaticModifier<FieldDeclaration>, NodeWithFinalModifier<FieldDeclaration>, Resolvable<ResolvedFieldDeclaration> {
+
+ private EnumSet<Modifier> modifiers;
+
+ @NonEmptyProperty
+ private NodeList<VariableDeclarator> variables;
+
+ public FieldDeclaration() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>());
+ }
+
+ public FieldDeclaration(EnumSet<Modifier> modifiers, VariableDeclarator variable) {
+ this(null, modifiers, new NodeList<>(), nodeList(variable));
+ }
+
+ public FieldDeclaration(EnumSet<Modifier> modifiers, NodeList<VariableDeclarator> variables) {
+ this(null, modifiers, new NodeList<>(), variables);
+ }
+
+ @AllFieldsConstructor
+ public FieldDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> variables) {
+ this(null, modifiers, annotations, variables);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public FieldDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> variables) {
+ super(tokenRange, annotations);
+ setModifiers(modifiers);
+ setVariables(variables);
+ customInitialization();
+ }
+
+ /**
+ * Creates a {@link FieldDeclaration}.
+ *
+ * @param modifiers modifiers
+ * @param type type
+ * @param name field name
+ */
+ public FieldDeclaration(EnumSet<Modifier> modifiers, Type type, String name) {
+ this(assertNotNull(modifiers), new VariableDeclarator(type, assertNotNull(name)));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ /**
+ * Return the modifiers of this member declaration.
+ *
+ * @return modifiers
+ * @see Modifier
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumSet<Modifier> getModifiers() {
+ return modifiers;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<VariableDeclarator> getVariables() {
+ return variables;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public FieldDeclaration setModifiers(final EnumSet<Modifier> modifiers) {
+ assertNotNull(modifiers);
+ if (modifiers == this.modifiers) {
+ return (FieldDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers);
+ this.modifiers = modifiers;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public FieldDeclaration setVariables(final NodeList<VariableDeclarator> variables) {
+ assertNotNull(variables);
+ if (variables == this.variables) {
+ return (FieldDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.VARIABLES, this.variables, variables);
+ if (this.variables != null)
+ this.variables.setParentNode(null);
+ this.variables = variables;
+ setAsParentNodeOf(variables);
+ return this;
+ }
+
+ /**
+ * Create a getter for this field, <b>will only work if this field declares only 1 identifier and if this field is
+ * already added to a ClassOrInterfaceDeclaration</b>
+ *
+ * @return the {@link MethodDeclaration} created
+ * @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a
+ * class or enum
+ */
+ public MethodDeclaration createGetter() {
+ if (getVariables().size() != 1)
+ throw new IllegalStateException("You can use this only when the field declares only 1 variable name");
+ Optional<ClassOrInterfaceDeclaration> parentClass = getAncestorOfType(ClassOrInterfaceDeclaration.class);
+ Optional<EnumDeclaration> parentEnum = getAncestorOfType(EnumDeclaration.class);
+ if (!(parentClass.isPresent() || parentEnum.isPresent()) || (parentClass.isPresent() && parentClass.get().isInterface()))
+ throw new IllegalStateException("You can use this only when the field is attached to a class or an enum");
+ VariableDeclarator variable = getVariable(0);
+ String fieldName = variable.getNameAsString();
+ String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length());
+ final MethodDeclaration getter;
+ getter = parentClass.map(clazz -> clazz.addMethod("get" + fieldNameUpper, PUBLIC)).orElseGet(() -> parentEnum.get().addMethod("get" + fieldNameUpper, PUBLIC));
+ getter.setType(variable.getType());
+ BlockStmt blockStmt = new BlockStmt();
+ getter.setBody(blockStmt);
+ blockStmt.addStatement(new ReturnStmt(fieldName));
+ return getter;
+ }
+
+ /**
+ * Create a setter for this field, <b>will only work if this field declares only 1 identifier and if this field is
+ * already added to a ClassOrInterfaceDeclaration</b>
+ *
+ * @return the {@link MethodDeclaration} created
+ * @throws IllegalStateException if there is more than 1 variable identifier or if this field isn't attached to a
+ * class or enum
+ */
+ public MethodDeclaration createSetter() {
+ if (getVariables().size() != 1)
+ throw new IllegalStateException("You can use this only when the field declares only 1 variable name");
+ Optional<ClassOrInterfaceDeclaration> parentClass = getAncestorOfType(ClassOrInterfaceDeclaration.class);
+ Optional<EnumDeclaration> parentEnum = getAncestorOfType(EnumDeclaration.class);
+ if (!(parentClass.isPresent() || parentEnum.isPresent()) || (parentClass.isPresent() && parentClass.get().isInterface()))
+ throw new IllegalStateException("You can use this only when the field is attached to a class or an enum");
+ VariableDeclarator variable = getVariable(0);
+ String fieldName = variable.getNameAsString();
+ String fieldNameUpper = fieldName.toUpperCase().substring(0, 1) + fieldName.substring(1, fieldName.length());
+ final MethodDeclaration setter;
+ setter = parentClass.map(clazz -> clazz.addMethod("set" + fieldNameUpper, PUBLIC)).orElseGet(() -> parentEnum.get().addMethod("set" + fieldNameUpper, PUBLIC));
+ setter.setType(new VoidType());
+ setter.getParameters().add(new Parameter(variable.getType(), fieldName));
+ BlockStmt blockStmt2 = new BlockStmt();
+ setter.setBody(blockStmt2);
+ blockStmt2.addStatement(new AssignExpr(new NameExpr("this." + fieldName), new NameExpr(fieldName), Operator.ASSIGN));
+ return setter;
+ }
+
+ public boolean isTransient() {
+ return getModifiers().contains(TRANSIENT);
+ }
+
+ public boolean isVolatile() {
+ return getModifiers().contains(VOLATILE);
+ }
+
+ public FieldDeclaration setTransient(boolean set) {
+ return setModifier(TRANSIENT, set);
+ }
+
+ public FieldDeclaration setVolatile(boolean set) {
+ return setModifier(VOLATILE, set);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < variables.size(); i++) {
+ if (variables.get(i) == node) {
+ variables.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public FieldDeclaration clone() {
+ return (FieldDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public FieldDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.fieldDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < variables.size(); i++) {
+ if (variables.get(i) == node) {
+ variables.set(i, (VariableDeclarator) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isFieldDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public FieldDeclaration asFieldDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifFieldDeclaration(Consumer<FieldDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedFieldDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedFieldDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<FieldDeclaration> toFieldDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/InitializerDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/InitializerDeclaration.java
new file mode 100644
index 000000000..06fe78e85
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/InitializerDeclaration.java
@@ -0,0 +1,174 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt;
+import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.InitializerDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A (possibly static) initializer body. "static { a=3; }" in this example: <code>class X { static { a=3; } } </code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class InitializerDeclaration extends BodyDeclaration<InitializerDeclaration> implements NodeWithJavadoc<InitializerDeclaration>, NodeWithBlockStmt<InitializerDeclaration> {
+
+ private boolean isStatic;
+
+ private BlockStmt body;
+
+ public InitializerDeclaration() {
+ this(null, false, new BlockStmt());
+ }
+
+ @AllFieldsConstructor
+ public InitializerDeclaration(boolean isStatic, BlockStmt body) {
+ this(null, isStatic, body);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public InitializerDeclaration(TokenRange tokenRange, boolean isStatic, BlockStmt body) {
+ super(tokenRange);
+ setStatic(isStatic);
+ setBody(body);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BlockStmt getBody() {
+ return body;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean isStatic() {
+ return isStatic;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public InitializerDeclaration setBody(final BlockStmt body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (InitializerDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public InitializerDeclaration setStatic(final boolean isStatic) {
+ if (isStatic == this.isStatic) {
+ return (InitializerDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.STATIC, this.isStatic, isStatic);
+ this.isStatic = isStatic;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public InitializerDeclaration clone() {
+ return (InitializerDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public InitializerDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.initializerDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((BlockStmt) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isInitializerDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public InitializerDeclaration asInitializerDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifInitializerDeclaration(Consumer<InitializerDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<InitializerDeclaration> toInitializerDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java
new file mode 100644
index 000000000..dff4cad55
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/MethodDeclaration.java
@@ -0,0 +1,348 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2017 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AccessSpecifier;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.*;
+import com.github.javaparser.ast.nodeTypes.modifiers.*;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.ReferenceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.type.TypeParameter;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.EnumSet;
+import java.util.Optional;
+import static com.github.javaparser.ast.Modifier.*;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.MethodDeclarationMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
+import java.util.function.Consumer;
+
+/**
+ * A method declaration. "public int abc() {return 1;}" in this example: <code>class X { public int abc() {return 1;}
+ * }</code>
+ *
+ * <br/>All annotations preceding the return type will be set on this object, not on the return type.
+ * JavaParser doesn't know if it they are applicable to the method or the type.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class MethodDeclaration extends CallableDeclaration<MethodDeclaration> implements NodeWithType<MethodDeclaration, Type>, NodeWithOptionalBlockStmt<MethodDeclaration>, NodeWithJavadoc<MethodDeclaration>, NodeWithDeclaration, NodeWithSimpleName<MethodDeclaration>, NodeWithParameters<MethodDeclaration>, NodeWithThrownExceptions<MethodDeclaration>, NodeWithTypeParameters<MethodDeclaration>, NodeWithAccessModifiers<MethodDeclaration>, NodeWithAbstractModifier<MethodDeclaration>, NodeWithStaticModifier<MethodDeclaration>, NodeWithFinalModifier<MethodDeclaration>, NodeWithStrictfpModifier<MethodDeclaration>, Resolvable<ResolvedMethodDeclaration> {
+
+ private Type type;
+
+ @OptionalProperty
+ private BlockStmt body;
+
+ public MethodDeclaration() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>(), new ClassOrInterfaceType(), new SimpleName(), new NodeList<>(), new NodeList<>(), new BlockStmt(), null);
+ }
+
+ public MethodDeclaration(final EnumSet<Modifier> modifiers, final Type type, final String name) {
+ this(null, modifiers, new NodeList<>(), new NodeList<>(), type, new SimpleName(name), new NodeList<>(), new NodeList<>(), new BlockStmt(), null);
+ }
+
+ public MethodDeclaration(final EnumSet<Modifier> modifiers, final String name, final Type type, final NodeList<Parameter> parameters) {
+ this(null, modifiers, new NodeList<>(), new NodeList<>(), type, new SimpleName(name), parameters, new NodeList<>(), new BlockStmt(), null);
+ }
+
+ public MethodDeclaration(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final NodeList<Parameter> parameters, final NodeList<ReferenceType> thrownExceptions, final BlockStmt body) {
+ this(null, modifiers, annotations, typeParameters, type, name, parameters, thrownExceptions, body, null);
+ }
+
+ @AllFieldsConstructor
+ public MethodDeclaration(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final NodeList<Parameter> parameters, final NodeList<ReferenceType> thrownExceptions, final BlockStmt body, ReceiverParameter receiverParameter) {
+ this(null, modifiers, annotations, typeParameters, type, name, parameters, thrownExceptions, body, receiverParameter);
+ }
+
+ /**
+ * @deprecated this constructor allows you to set "isDefault", but this is no longer a field of this node, but simply one of the modifiers. Use setDefault(boolean) or add DEFAULT to the modifiers set.
+ */
+ @Deprecated
+ public MethodDeclaration(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<TypeParameter> typeParameters, final Type type, final SimpleName name, final boolean isDefault, final NodeList<Parameter> parameters, final NodeList<ReferenceType> thrownExceptions, final BlockStmt body) {
+ this(null, modifiers, annotations, typeParameters, type, name, parameters, thrownExceptions, body, null);
+ setDefault(isDefault);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public MethodDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<TypeParameter> typeParameters, Type type, SimpleName name, NodeList<Parameter> parameters, NodeList<ReferenceType> thrownExceptions, BlockStmt body, ReceiverParameter receiverParameter) {
+ super(tokenRange, modifiers, annotations, typeParameters, name, parameters, thrownExceptions, receiverParameter);
+ setType(type);
+ setBody(body);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<BlockStmt> getBody() {
+ return Optional.ofNullable(body);
+ }
+
+ /**
+ * Sets the body
+ *
+ * @param body the body, can be null
+ * @return this, the MethodDeclaration
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodDeclaration setBody(final BlockStmt body) {
+ if (body == this.body) {
+ return (MethodDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodDeclaration setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (MethodDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Override
+ public MethodDeclaration setModifiers(final EnumSet<Modifier> modifiers) {
+ return super.setModifiers(modifiers);
+ }
+
+ @Override
+ public MethodDeclaration setName(final SimpleName name) {
+ return super.setName(name);
+ }
+
+ @Override
+ public MethodDeclaration setParameters(final NodeList<Parameter> parameters) {
+ return super.setParameters(parameters);
+ }
+
+ @Override
+ public MethodDeclaration setThrownExceptions(final NodeList<ReferenceType> thrownExceptions) {
+ return super.setThrownExceptions(thrownExceptions);
+ }
+
+ @Override
+ public MethodDeclaration setTypeParameters(final NodeList<TypeParameter> typeParameters) {
+ return super.setTypeParameters(typeParameters);
+ }
+
+ /**
+ * The declaration returned has this schema:
+ * <p>
+ * [accessSpecifier] [static] [abstract] [final] [native]
+ * [synchronized] returnType methodName ([paramType [paramName]])
+ * [throws exceptionsList]
+ *
+ * @return method declaration as String
+ */
+ @Override
+ public String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName) {
+ StringBuilder sb = new StringBuilder();
+ if (includingModifiers) {
+ AccessSpecifier accessSpecifier = getAccessSpecifier(getModifiers());
+ sb.append(accessSpecifier.asString());
+ sb.append(accessSpecifier == AccessSpecifier.DEFAULT ? "" : " ");
+ if (getModifiers().contains(STATIC)) {
+ sb.append("static ");
+ }
+ if (getModifiers().contains(ABSTRACT)) {
+ sb.append("abstract ");
+ }
+ if (getModifiers().contains(FINAL)) {
+ sb.append("final ");
+ }
+ if (getModifiers().contains(NATIVE)) {
+ sb.append("native ");
+ }
+ if (getModifiers().contains(SYNCHRONIZED)) {
+ sb.append("synchronized ");
+ }
+ }
+ sb.append(getType().toString(prettyPrinterNoCommentsConfiguration));
+ sb.append(" ");
+ sb.append(getName());
+ sb.append("(");
+ boolean firstParam = true;
+ for (Parameter param : getParameters()) {
+ if (firstParam) {
+ firstParam = false;
+ } else {
+ sb.append(", ");
+ }
+ if (includingParameterName) {
+ sb.append(param.toString(prettyPrinterNoCommentsConfiguration));
+ } else {
+ sb.append(param.getType().toString(prettyPrinterNoCommentsConfiguration));
+ if (param.isVarArgs()) {
+ sb.append("...");
+ }
+ }
+ }
+ sb.append(")");
+ sb.append(appendThrowsIfRequested(includingThrows));
+ return sb.toString();
+ }
+
+ public boolean isNative() {
+ return getModifiers().contains(NATIVE);
+ }
+
+ public boolean isSynchronized() {
+ return getModifiers().contains(SYNCHRONIZED);
+ }
+
+ public boolean isDefault() {
+ return getModifiers().contains(DEFAULT);
+ }
+
+ public MethodDeclaration setNative(boolean set) {
+ return setModifier(NATIVE, set);
+ }
+
+ public MethodDeclaration setSynchronized(boolean set) {
+ return setModifier(SYNCHRONIZED, set);
+ }
+
+ public MethodDeclaration setDefault(boolean set) {
+ return setModifier(DEFAULT, set);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (body != null) {
+ if (node == body) {
+ removeBody();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public MethodDeclaration removeBody() {
+ return setBody((BlockStmt) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public MethodDeclaration clone() {
+ return (MethodDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public MethodDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.methodDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (body != null) {
+ if (node == body) {
+ setBody((BlockStmt) replacementNode);
+ return true;
+ }
+ }
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isMethodDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public MethodDeclaration asMethodDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifMethodDeclaration(Consumer<MethodDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedMethodDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedMethodDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<MethodDeclaration> toMethodDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java
new file mode 100644
index 000000000..a7cf357a2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/Parameter.java
@@ -0,0 +1,311 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ParameterMetaModel;
+import java.util.EnumSet;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedParameterDeclaration;
+
+/**
+ * The parameters to a method or lambda. Lambda parameters may have inferred types, in that case "type" is UnknownType.
+ * <br/>Note that <a href="https://en.wikipedia.org/wiki/Parameter_(computer_programming)#Parameters_and_arguments">parameters
+ * are different from arguments.</a> <br/>"String x" and "float y" are the parameters in <code>int abc(String x, float
+ * y) {...}</code>
+ *
+ * <br/>All annotations preceding the type will be set on this object, not on the type.
+ * JavaParser doesn't know if it they are applicable to the parameter or the type.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class Parameter extends Node implements NodeWithType<Parameter, Type>, NodeWithAnnotations<Parameter>, NodeWithSimpleName<Parameter>, NodeWithFinalModifier<Parameter>, Resolvable<ResolvedParameterDeclaration> {
+
+ private Type type;
+
+ private boolean isVarArgs;
+
+ private NodeList<AnnotationExpr> varArgsAnnotations;
+
+ private EnumSet<Modifier> modifiers;
+
+ private NodeList<AnnotationExpr> annotations;
+
+ private SimpleName name;
+
+ public Parameter() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new ClassOrInterfaceType(), false, new NodeList<>(), new SimpleName());
+ }
+
+ public Parameter(Type type, SimpleName name) {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), type, false, new NodeList<>(), name);
+ }
+
+ /**
+ * Creates a new {@link Parameter}.
+ *
+ * @param type type of the parameter
+ * @param name name of the parameter
+ */
+ public Parameter(Type type, String name) {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), type, false, new NodeList<>(), new SimpleName(name));
+ }
+
+ public Parameter(EnumSet<Modifier> modifiers, Type type, SimpleName name) {
+ this(null, modifiers, new NodeList<>(), type, false, new NodeList<>(), name);
+ }
+
+ @AllFieldsConstructor
+ public Parameter(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, Type type, boolean isVarArgs, NodeList<AnnotationExpr> varArgsAnnotations, SimpleName name) {
+ this(null, modifiers, annotations, type, isVarArgs, varArgsAnnotations, name);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public Parameter(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, Type type, boolean isVarArgs, NodeList<AnnotationExpr> varArgsAnnotations, SimpleName name) {
+ super(tokenRange);
+ setModifiers(modifiers);
+ setAnnotations(annotations);
+ setType(type);
+ setVarArgs(isVarArgs);
+ setVarArgsAnnotations(varArgsAnnotations);
+ setName(name);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean isVarArgs() {
+ return isVarArgs;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Parameter setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (Parameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Parameter setVarArgs(final boolean isVarArgs) {
+ if (isVarArgs == this.isVarArgs) {
+ return (Parameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.VAR_ARGS, this.isVarArgs, isVarArgs);
+ this.isVarArgs = isVarArgs;
+ return this;
+ }
+
+ /**
+ * @return the list returned could be immutable (in that case it will be empty)
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ /**
+ * Return the modifiers of this parameter declaration.
+ *
+ * @return modifiers
+ * @see Modifier
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumSet<Modifier> getModifiers() {
+ return modifiers;
+ }
+
+ /**
+ * @param annotations a null value is currently treated as an empty list. This behavior could change in the future,
+ * so please avoid passing null
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Parameter setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (Parameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Parameter setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (Parameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Parameter setModifiers(final EnumSet<Modifier> modifiers) {
+ assertNotNull(modifiers);
+ if (modifiers == this.modifiers) {
+ return (Parameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers);
+ this.modifiers = modifiers;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < varArgsAnnotations.size(); i++) {
+ if (varArgsAnnotations.get(i) == node) {
+ varArgsAnnotations.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getVarArgsAnnotations() {
+ return varArgsAnnotations;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Parameter setVarArgsAnnotations(final NodeList<AnnotationExpr> varArgsAnnotations) {
+ assertNotNull(varArgsAnnotations);
+ if (varArgsAnnotations == this.varArgsAnnotations) {
+ return (Parameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.VAR_ARGS_ANNOTATIONS, this.varArgsAnnotations, varArgsAnnotations);
+ if (this.varArgsAnnotations != null)
+ this.varArgsAnnotations.setParentNode(null);
+ this.varArgsAnnotations = varArgsAnnotations;
+ setAsParentNodeOf(varArgsAnnotations);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public Parameter clone() {
+ return (Parameter) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ParameterMetaModel getMetaModel() {
+ return JavaParserMetaModel.parameterMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ for (int i = 0; i < varArgsAnnotations.size(); i++) {
+ if (varArgsAnnotations.get(i) == node) {
+ varArgsAnnotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ public ResolvedParameterDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedParameterDeclaration.class);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/ReceiverParameter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ReceiverParameter.java
new file mode 100644
index 000000000..b0038e1eb
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/ReceiverParameter.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ParameterMetaModel;
+import javax.annotation.Generated;
+import java.util.EnumSet;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.metamodel.ReceiverParameterMetaModel;
+
+/**
+ * The rather obscure <a href="http://blog.joda.org/2015/12/explicit-receiver-parameters.html">"receiver parameter" feature of Java</a>.
+ *
+ * <br/>All annotations preceding the type will be set on this object, not on the type.
+ * JavaParser doesn't know if it they are applicable to the receiver parameter or the type.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ReceiverParameter extends Node implements NodeWithType<ReceiverParameter, Type>, NodeWithAnnotations<ReceiverParameter>, NodeWithName<ReceiverParameter> {
+
+ private Type type;
+
+ private NodeList<AnnotationExpr> annotations;
+
+ private Name name;
+
+ public ReceiverParameter() {
+ this(null, new NodeList<>(), new ClassOrInterfaceType(), new Name());
+ }
+
+ public ReceiverParameter(Type type, Name name) {
+ this(null, new NodeList<>(), type, name);
+ }
+
+ /**
+ * Creates a new {@link ReceiverParameter}.
+ *
+ * @param type type of the parameter
+ * @param name name of the parameter
+ */
+ public ReceiverParameter(Type type, String name) {
+ this(null, new NodeList<>(), type, new Name(name));
+ }
+
+ @AllFieldsConstructor
+ public ReceiverParameter(NodeList<AnnotationExpr> annotations, Type type, Name name) {
+ this(null, annotations, type, name);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ReceiverParameter(TokenRange tokenRange, NodeList<AnnotationExpr> annotations, Type type, Name name) {
+ super(tokenRange);
+ setAnnotations(annotations);
+ setType(type);
+ setName(name);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ReceiverParameter setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (ReceiverParameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ /**
+ * @return the list returned could be immutable (in that case it will be empty)
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ /**
+ * @param annotations a null value is currently treated as an empty list. This behavior could change in the future,
+ * so please avoid passing null
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ReceiverParameter setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (ReceiverParameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ReceiverParameter clone() {
+ return (ReceiverParameter) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ReceiverParameterMetaModel getMetaModel() {
+ return JavaParserMetaModel.receiverParameterMetaModel;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ReceiverParameter setName(final Name name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (ReceiverParameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((Name) replacementNode);
+ return true;
+ }
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/TypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/TypeDeclaration.java
new file mode 100644
index 000000000..06f9753b1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/TypeDeclaration.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithJavadoc;
+import com.github.javaparser.ast.nodeTypes.NodeWithMembers;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithAccessModifiers;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStrictfpModifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.TypeDeclarationMetaModel;
+import javax.annotation.Generated;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.function.Consumer;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.toList;
+import com.github.javaparser.ast.Node;
+import java.util.Optional;
+
+/**
+ * A base class for all types of type declarations.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class TypeDeclaration<T extends TypeDeclaration<?>> extends BodyDeclaration<T> implements NodeWithSimpleName<T>, NodeWithJavadoc<T>, NodeWithMembers<T>, NodeWithAccessModifiers<T>, NodeWithStaticModifier<T>, NodeWithStrictfpModifier<T> {
+
+ private SimpleName name;
+
+ private EnumSet<Modifier> modifiers;
+
+ private NodeList<BodyDeclaration<?>> members;
+
+ public TypeDeclaration() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new SimpleName(), new NodeList<>());
+ }
+
+ public TypeDeclaration(EnumSet<Modifier> modifiers, String name) {
+ this(null, modifiers, new NodeList<>(), new SimpleName(name), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public TypeDeclaration(EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members) {
+ this(null, modifiers, annotations, name, members);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public TypeDeclaration(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, SimpleName name, NodeList<BodyDeclaration<?>> members) {
+ super(tokenRange, annotations);
+ setModifiers(modifiers);
+ setName(name);
+ setMembers(members);
+ customInitialization();
+ }
+
+ /**
+ * Adds the given declaration to the specified type.
+ *
+ * @param decl member declaration
+ */
+ public T addMember(BodyDeclaration<?> decl) {
+ NodeList<BodyDeclaration<?>> members = getMembers();
+ members.add(decl);
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<BodyDeclaration<?>> getMembers() {
+ return members;
+ }
+
+ /**
+ * Return the modifiers of this type declaration.
+ *
+ * @return modifiers
+ * @see Modifier
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumSet<Modifier> getModifiers() {
+ return modifiers;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setMembers(final NodeList<BodyDeclaration<?>> members) {
+ assertNotNull(members);
+ if (members == this.members) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.MEMBERS, this.members, members);
+ if (this.members != null)
+ this.members.setParentNode(null);
+ this.members = members;
+ setAsParentNodeOf(members);
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setModifiers(final EnumSet<Modifier> modifiers) {
+ assertNotNull(modifiers);
+ if (modifiers == this.modifiers) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers);
+ this.modifiers = modifiers;
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ @SuppressWarnings("unchecked")
+ public T setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (T) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return (T) this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < members.size(); i++) {
+ if (members.get(i) == node) {
+ members.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ /**
+ * @return is this type's parent a CompilationUnit?
+ */
+ public boolean isTopLevelType() {
+ return getParentNode().map(p -> p instanceof CompilationUnit).orElse(false);
+ }
+
+ /**
+ * @return methods or constructors whose signatures match the passed signature.
+ */
+ public List<CallableDeclaration<?>> getCallablesWithSignature(CallableDeclaration.Signature signature) {
+ return getMembers().stream().filter(m -> m instanceof CallableDeclaration).map(m -> ((CallableDeclaration<?>) m)).filter(m -> m.getSignature().equals(signature)).collect(toList());
+ }
+
+ /**
+ * @return is this type's parent a TypeDeclaration?
+ * NOTE: many people are confused over terminology. Refer to https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html .
+ */
+ public boolean isNestedType() {
+ return getParentNode().map(p -> p instanceof TypeDeclaration).orElse(false);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public TypeDeclaration<?> clone() {
+ return (TypeDeclaration<?>) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public TypeDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.typeDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < members.size(); i++) {
+ if (members.get(i) == node) {
+ members.set(i, (BodyDeclaration) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isTypeDeclaration() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public TypeDeclaration asTypeDeclaration() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifTypeDeclaration(Consumer<TypeDeclaration> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<TypeDeclaration> toTypeDeclaration() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java
new file mode 100644
index 000000000..0d342ac58
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/body/VariableDeclarator.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.body;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.nodeTypes.NodeWithVariables;
+import com.github.javaparser.ast.observer.AstObserverAdapter;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.metamodel.VariableDeclaratorMetaModel;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration;
+
+/**
+ * The declaration of a variable.<br/>In <code>int x = 14, y = 3;</code> "int x = 14" and "int y = 3" are
+ * VariableDeclarators.
+ * <p/>The type is on all of the variable declarators because, thanks to array brackets, each variable can have a different type.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class VariableDeclarator extends Node implements NodeWithType<VariableDeclarator, Type>, NodeWithSimpleName<VariableDeclarator>, Resolvable<ResolvedFieldDeclaration> {
+
+ private SimpleName name;
+
+ @OptionalProperty
+ @NonEmptyProperty
+ private Expression initializer;
+
+ private Type type;
+
+ public VariableDeclarator() {
+ this(null, new ClassOrInterfaceType(), new SimpleName(), null);
+ }
+
+ public VariableDeclarator(Type type, String variableName) {
+ this(null, type, new SimpleName(variableName), null);
+ }
+
+ public VariableDeclarator(Type type, SimpleName name) {
+ this(null, type, name, null);
+ }
+
+ public VariableDeclarator(Type type, String variableName, Expression initializer) {
+ this(null, type, new SimpleName(variableName), initializer);
+ }
+
+ /**
+ * Defines the declaration of a variable.
+ *
+ * @param name The identifier for this variable. IE. The variables name.
+ * @param initializer What this variable should be initialized to. An {@link com.github.javaparser.ast.expr.AssignExpr}
+ * is unnecessary as the <code>=</code> operator is already added.
+ */
+ @AllFieldsConstructor
+ public VariableDeclarator(Type type, SimpleName name, Expression initializer) {
+ this(null, type, name, initializer);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public VariableDeclarator(TokenRange tokenRange, Type type, SimpleName name, Expression initializer) {
+ super(tokenRange);
+ setType(type);
+ setName(name);
+ setInitializer(initializer);
+ customInitialization();
+ }
+
+ @Override
+ protected void customInitialization() {
+ // We register an observer on the type property. When it is changed the MaximumCommonType is changes as well,
+ // because it is derived from the type of the variables it contains, for this reason we notify about the change
+ register(new AstObserverAdapter() {
+
+ @Override
+ public void propertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) {
+ if (property == ObservableProperty.TYPE) {
+ VariableDeclarator vd = VariableDeclarator.this;
+ if (vd.getParentNode().isPresent() && vd.getParentNode().get() instanceof NodeWithVariables) {
+ NodeWithVariables nodeWithVariables = (NodeWithVariables) vd.getParentNode().get();
+ // We calculate the value the property will assume after the change will be completed
+ Optional<Type> currentMaxCommonType = nodeWithVariables.getMaximumCommonType();
+ List<Type> types = new LinkedList<>();
+ int index = nodeWithVariables.getVariables().indexOf(vd);
+ for (int i = 0; i < nodeWithVariables.getVariables().size(); i++) {
+ if (i == index) {
+ types.add((Type) newValue);
+ } else {
+ types.add(nodeWithVariables.getVariable(i).getType());
+ }
+ }
+ Optional<Type> newMaxCommonType = NodeWithVariables.calculateMaximumCommonType(types);
+ ((Node) nodeWithVariables).notifyPropertyChange(ObservableProperty.MAXIMUM_COMMON_TYPE, currentMaxCommonType.orElse(null), newMaxCommonType.orElse(null));
+ }
+ }
+ }
+ });
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getInitializer() {
+ return Optional.ofNullable(initializer);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public VariableDeclarator setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (VariableDeclarator) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ /**
+ * Sets the initializer expression
+ *
+ * @param initializer the initializer expression, can be null
+ * @return this, the VariableDeclarator
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public VariableDeclarator setInitializer(final Expression initializer) {
+ if (initializer == this.initializer) {
+ return (VariableDeclarator) this;
+ }
+ notifyPropertyChange(ObservableProperty.INITIALIZER, this.initializer, initializer);
+ if (this.initializer != null)
+ this.initializer.setParentNode(null);
+ this.initializer = initializer;
+ setAsParentNodeOf(initializer);
+ return this;
+ }
+
+ /**
+ * Will create a {@link NameExpr} with the initializer param
+ *
+ * @param init the initializer expression, can be null
+ * @return this, the VariableDeclarator
+ */
+ public VariableDeclarator setInitializer(String init) {
+ return setInitializer(new NameExpr(assertNonEmpty(init)));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public VariableDeclarator setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (VariableDeclarator) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (initializer != null) {
+ if (node == initializer) {
+ removeInitializer();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public VariableDeclarator removeInitializer() {
+ return setInitializer((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public VariableDeclarator clone() {
+ return (VariableDeclarator) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public VariableDeclaratorMetaModel getMetaModel() {
+ return JavaParserMetaModel.variableDeclaratorMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (initializer != null) {
+ if (node == initializer) {
+ setInitializer((Expression) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ public ResolvedFieldDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedFieldDeclaration.class);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/BlockComment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/BlockComment.java
new file mode 100644
index 000000000..8d30b2862
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/BlockComment.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.comments;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.BlockCommentMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * <p>
+ * AST node that represent block comments.
+ * </p>
+ * Block comments can has multi lines and are delimited by "/&#42;" and
+ * "&#42;/".
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class BlockComment extends Comment {
+
+ public BlockComment() {
+ this(null, "empty");
+ }
+
+ @AllFieldsConstructor
+ public BlockComment(String content) {
+ this(null, content);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public BlockComment(TokenRange tokenRange, String content) {
+ super(tokenRange, content);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public BlockComment clone() {
+ return (BlockComment) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public BlockCommentMetaModel getMetaModel() {
+ return JavaParserMetaModel.blockCommentMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBlockComment() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BlockComment asBlockComment() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBlockComment(Consumer<BlockComment> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BlockComment> toBlockComment() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java
new file mode 100644
index 000000000..0c5f6b4a3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/Comment.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.comments;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.CommentMetaModel;
+import com.github.javaparser.metamodel.InternalProperty;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+
+/**
+ * Abstract class for all AST nodes that represent comments.
+ *
+ * @author Julio Vilmar Gesser
+ * @see BlockComment
+ * @see LineComment
+ * @see JavadocComment
+ */
+public abstract class Comment extends Node {
+
+ private String content;
+
+ @InternalProperty
+ private Node commentedNode;
+
+ @AllFieldsConstructor
+ public Comment(String content) {
+ this(null, content);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public Comment(TokenRange tokenRange, String content) {
+ super(tokenRange);
+ setContent(content);
+ customInitialization();
+ }
+
+ /**
+ * Return the text of the comment.
+ *
+ * @return text of the comment
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public String getContent() {
+ return content;
+ }
+
+ /**
+ * Sets the text of the comment.
+ *
+ * @param content the text of the comment to set
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Comment setContent(final String content) {
+ assertNotNull(content);
+ if (content == this.content) {
+ return (Comment) this;
+ }
+ notifyPropertyChange(ObservableProperty.CONTENT, this.content, content);
+ this.content = content;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLineComment() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LineComment asLineComment() {
+ throw new IllegalStateException(f("%s is not an LineComment", this));
+ }
+
+ public Optional<Node> getCommentedNode() {
+ return Optional.ofNullable(this.commentedNode);
+ }
+
+ /**
+ * Sets the commentedNode
+ *
+ * @param commentedNode the commentedNode, can be null
+ * @return this, the Comment
+ */
+ public Comment setCommentedNode(Node commentedNode) {
+ notifyPropertyChange(ObservableProperty.COMMENTED_NODE, this.commentedNode, commentedNode);
+ if (commentedNode == null) {
+ this.commentedNode = null;
+ return this;
+ }
+ if (commentedNode == this) {
+ throw new IllegalArgumentException();
+ }
+ if (commentedNode instanceof Comment) {
+ throw new IllegalArgumentException();
+ }
+ this.commentedNode = commentedNode;
+ return this;
+ }
+
+ public boolean isOrphan() {
+ return this.commentedNode == null;
+ }
+
+ @Override
+ public boolean remove() {
+ // the other are orphan comments and remove should work with them
+ if (this.commentedNode != null) {
+ this.commentedNode.setComment(null);
+ return true;
+ } else if (this.getParentNode().isPresent()) {
+ return this.getParentNode().get().removeOrphanComment(this);
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public Comment clone() {
+ return (Comment) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public CommentMetaModel getMetaModel() {
+ return JavaParserMetaModel.commentMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBlockComment() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BlockComment asBlockComment() {
+ throw new IllegalStateException(f("%s is not an BlockComment", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isJavadocComment() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public JavadocComment asJavadocComment() {
+ throw new IllegalStateException(f("%s is not an JavadocComment", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBlockComment(Consumer<BlockComment> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifJavadocComment(Consumer<JavadocComment> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLineComment(Consumer<LineComment> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BlockComment> toBlockComment() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<JavadocComment> toJavadocComment() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LineComment> toLineComment() {
+ return Optional.empty();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/CommentsCollection.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/CommentsCollection.java
new file mode 100644
index 000000000..f3f25777e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/CommentsCollection.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.comments;
+
+import com.github.javaparser.Range;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.ast.Node.NODE_BY_BEGIN_POSITION;
+
+/**
+ * The comments contained in a certain parsed piece of source code.
+ */
+public class CommentsCollection {
+ private final TreeSet<Comment> comments = new TreeSet<>(NODE_BY_BEGIN_POSITION);
+
+ public CommentsCollection() {
+ }
+
+ public CommentsCollection(Collection<Comment> commentsToCopy) {
+ comments.addAll(commentsToCopy);
+ }
+
+ public Set<LineComment> getLineComments() {
+ return comments.stream()
+ .filter(comment -> comment instanceof LineComment)
+ .map(comment -> (LineComment) comment)
+ .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION)));
+ }
+
+ public Set<BlockComment> getBlockComments() {
+ return comments.stream()
+ .filter(comment -> comment instanceof BlockComment)
+ .map(comment -> (BlockComment) comment)
+ .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION)));
+ }
+
+ public Set<JavadocComment> getJavadocComments() {
+ return comments.stream()
+ .filter(comment -> comment instanceof JavadocComment)
+ .map(comment -> (JavadocComment) comment)
+ .collect(Collectors.toCollection(() -> new TreeSet<>(NODE_BY_BEGIN_POSITION)));
+ }
+
+ public void addComment(Comment comment) {
+ comments.add(comment);
+ }
+
+ public boolean contains(Comment comment) {
+ if (!comment.getRange().isPresent()) {
+ return false;
+ }
+ Range commentRange = comment.getRange().get();
+ for (Comment c : getComments()) {
+ if (!c.getRange().isPresent()) {
+ return false;
+ }
+ Range cRange = c.getRange().get();
+ // we tolerate a difference of one element in the end column:
+ // it depends how \r and \n are calculated...
+ if (cRange.begin.equals(commentRange.begin) &&
+ cRange.end.line == commentRange.end.line &&
+ Math.abs(cRange.end.column - commentRange.end.column) < 2) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public TreeSet<Comment> getComments() {
+ return comments;
+ }
+
+ public int size() {
+ return comments.size();
+ }
+
+ public CommentsCollection minus(CommentsCollection other) {
+ CommentsCollection result = new CommentsCollection();
+ result.comments.addAll(
+ comments.stream()
+ .filter(comment -> !other.contains(comment))
+ .collect(Collectors.toList()));
+ return result;
+ }
+
+ public CommentsCollection copy() {
+ return new CommentsCollection(comments);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/JavadocComment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/JavadocComment.java
new file mode 100644
index 000000000..d795997bd
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/JavadocComment.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.comments;
+
+import com.github.javaparser.JavaParser;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.javadoc.Javadoc;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavadocCommentMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A Javadoc comment. <code>/&#42;&#42; a comment &#42;/</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class JavadocComment extends Comment {
+
+ public JavadocComment() {
+ this(null, "empty");
+ }
+
+ @AllFieldsConstructor
+ public JavadocComment(String content) {
+ this(null, content);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public JavadocComment(TokenRange tokenRange, String content) {
+ super(tokenRange, content);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ public Javadoc parse() {
+ return JavaParser.parseJavadoc(getContent());
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public JavadocComment clone() {
+ return (JavadocComment) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public JavadocCommentMetaModel getMetaModel() {
+ return JavaParserMetaModel.javadocCommentMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isJavadocComment() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public JavadocComment asJavadocComment() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifJavadocComment(Consumer<JavadocComment> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<JavadocComment> toJavadocComment() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/comments/LineComment.java b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/LineComment.java
new file mode 100644
index 000000000..ddbce8024
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/comments/LineComment.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.comments;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.LineCommentMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * <p>
+ * AST node that represent line comments.
+ * </p>
+ * Line comments start with "//" and finish at the end of the line ("\n").
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class LineComment extends Comment {
+
+ public LineComment() {
+ this(null, "empty");
+ }
+
+ @AllFieldsConstructor
+ public LineComment(String content) {
+ this(null, content);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public LineComment(TokenRange tokenRange, String content) {
+ super(tokenRange, content);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLineComment() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public LineComment clone() {
+ return (LineComment) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public LineCommentMetaModel getMetaModel() {
+ return JavaParserMetaModel.lineCommentMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LineComment asLineComment() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLineComment(Consumer<LineComment> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LineComment> toLineComment() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AnnotationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AnnotationExpr.java
new file mode 100644
index 000000000..31c70fb5a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AnnotationExpr.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.AnnotationExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A base class for the different types of annotations.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class AnnotationExpr extends Expression implements NodeWithName<AnnotationExpr> {
+
+ protected Name name;
+
+ public AnnotationExpr() {
+ this(null, new Name());
+ }
+
+ @AllFieldsConstructor
+ public AnnotationExpr(Name name) {
+ this(null, name);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public AnnotationExpr(TokenRange tokenRange, Name name) {
+ super(tokenRange);
+ setName(name);
+ customInitialization();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AnnotationExpr setName(final Name name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (AnnotationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public AnnotationExpr clone() {
+ return (AnnotationExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public AnnotationExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.annotationExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((Name) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAnnotationExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AnnotationExpr asAnnotationExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAnnotationExpr(Consumer<AnnotationExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AnnotationExpr> toAnnotationExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayAccessExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayAccessExpr.java
new file mode 100644
index 000000000..6945dd9ae
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayAccessExpr.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ArrayAccessExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Array brackets [] being used to get a value from an array.
+ * In <br/><code>getNames()[15*15]</code> the name expression is getNames() and the index expression is 15*15.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ArrayAccessExpr extends Expression {
+
+ private Expression name;
+
+ private Expression index;
+
+ public ArrayAccessExpr() {
+ this(null, new NameExpr(), new IntegerLiteralExpr());
+ }
+
+ @AllFieldsConstructor
+ public ArrayAccessExpr(Expression name, Expression index) {
+ this(null, name, index);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ArrayAccessExpr(TokenRange tokenRange, Expression name, Expression index) {
+ super(tokenRange);
+ setName(name);
+ setIndex(index);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getIndex() {
+ return index;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayAccessExpr setIndex(final Expression index) {
+ assertNotNull(index);
+ if (index == this.index) {
+ return (ArrayAccessExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.INDEX, this.index, index);
+ if (this.index != null)
+ this.index.setParentNode(null);
+ this.index = index;
+ setAsParentNodeOf(index);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayAccessExpr setName(final Expression name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (ArrayAccessExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ArrayAccessExpr clone() {
+ return (ArrayAccessExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ArrayAccessExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.arrayAccessExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == index) {
+ setIndex((Expression) replacementNode);
+ return true;
+ }
+ if (node == name) {
+ setName((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isArrayAccessExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ArrayAccessExpr asArrayAccessExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifArrayAccessExpr(Consumer<ArrayAccessExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ArrayAccessExpr> toArrayAccessExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java
new file mode 100644
index 000000000..509925803
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayCreationExpr.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.Range;
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ArrayType;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.ArrayCreationExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.JavaParser.parseType;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.metamodel.OptionalProperty;
+import java.util.function.Consumer;
+
+/**
+ * <code>new int[5][4][][]</code> or <code>new int[][]{{1},{2,3}}</code>.
+ *
+ * <br/>"int" is the element type.
+ * <br/>All the brackets are stored in the levels field, from left to right.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ArrayCreationExpr extends Expression {
+
+ @NonEmptyProperty
+ private NodeList<ArrayCreationLevel> levels;
+
+ private Type elementType;
+
+ @OptionalProperty
+ private ArrayInitializerExpr initializer;
+
+ public ArrayCreationExpr() {
+ this(null, new ClassOrInterfaceType(), new NodeList<>(), new ArrayInitializerExpr());
+ }
+
+ @AllFieldsConstructor
+ public ArrayCreationExpr(Type elementType, NodeList<ArrayCreationLevel> levels, ArrayInitializerExpr initializer) {
+ this(null, elementType, levels, initializer);
+ }
+
+ public ArrayCreationExpr(Type elementType) {
+ this(null, elementType, new NodeList<>(), new ArrayInitializerExpr());
+ }
+
+ /**
+ * @deprecated range shouldn't be in utility constructors.
+ */
+ @Deprecated
+ public ArrayCreationExpr(Range range, Type elementType) {
+ this(null, elementType, new NodeList<>(), new ArrayInitializerExpr());
+ setRange(range);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ArrayCreationExpr(TokenRange tokenRange, Type elementType, NodeList<ArrayCreationLevel> levels, ArrayInitializerExpr initializer) {
+ super(tokenRange);
+ setElementType(elementType);
+ setLevels(levels);
+ setInitializer(initializer);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<ArrayInitializerExpr> getInitializer() {
+ return Optional.ofNullable(initializer);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getElementType() {
+ return elementType;
+ }
+
+ /**
+ * Sets the initializer
+ *
+ * @param initializer the initializer, can be null
+ * @return this, the ArrayCreationExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayCreationExpr setInitializer(final ArrayInitializerExpr initializer) {
+ if (initializer == this.initializer) {
+ return (ArrayCreationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.INITIALIZER, this.initializer, initializer);
+ if (this.initializer != null)
+ this.initializer.setParentNode(null);
+ this.initializer = initializer;
+ setAsParentNodeOf(initializer);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayCreationExpr setElementType(final Type elementType) {
+ assertNotNull(elementType);
+ if (elementType == this.elementType) {
+ return (ArrayCreationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.ELEMENT_TYPE, this.elementType, elementType);
+ if (this.elementType != null)
+ this.elementType.setParentNode(null);
+ this.elementType = elementType;
+ setAsParentNodeOf(elementType);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ArrayCreationLevel> getLevels() {
+ return levels;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayCreationExpr setLevels(final NodeList<ArrayCreationLevel> levels) {
+ assertNotNull(levels);
+ if (levels == this.levels) {
+ return (ArrayCreationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.LEVELS, this.levels, levels);
+ if (this.levels != null)
+ this.levels.setParentNode(null);
+ this.levels = levels;
+ setAsParentNodeOf(levels);
+ return this;
+ }
+
+ /**
+ * Takes the element type and wraps it in an ArrayType for every array creation level.
+ */
+ public Type createdType() {
+ Type result = elementType;
+ for (int i = 0; i < levels.size(); i++) {
+ result = new ArrayType(result, ArrayType.Origin.TYPE, new NodeList<>());
+ }
+ return result;
+ }
+
+ /**
+ * Sets this type to this class and try to import it to the {@link CompilationUnit} if needed
+ *
+ * @param typeClass the type
+ * @return this
+ */
+ public ArrayCreationExpr setElementType(Class<?> typeClass) {
+ tryAddImportToParentCompilationUnit(typeClass);
+ return setElementType(parseType(typeClass.getSimpleName()));
+ }
+
+ public ArrayCreationExpr setElementType(final String type) {
+ return setElementType(parseType(type));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (initializer != null) {
+ if (node == initializer) {
+ removeInitializer();
+ return true;
+ }
+ }
+ for (int i = 0; i < levels.size(); i++) {
+ if (levels.get(i) == node) {
+ levels.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ArrayCreationExpr removeInitializer() {
+ return setInitializer((ArrayInitializerExpr) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ArrayCreationExpr clone() {
+ return (ArrayCreationExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ArrayCreationExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.arrayCreationExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == elementType) {
+ setElementType((Type) replacementNode);
+ return true;
+ }
+ if (initializer != null) {
+ if (node == initializer) {
+ setInitializer((ArrayInitializerExpr) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < levels.size(); i++) {
+ if (levels.get(i) == node) {
+ levels.set(i, (ArrayCreationLevel) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isArrayCreationExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ArrayCreationExpr asArrayCreationExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifArrayCreationExpr(Consumer<ArrayCreationExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ArrayCreationExpr> toArrayCreationExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayInitializerExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayInitializerExpr.java
new file mode 100644
index 000000000..d585a1833
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ArrayInitializerExpr.java
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ArrayInitializerExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * The initialization of an array. In the following sample, the outer { } is an ArrayInitializerExpr.
+ * It has two expressions inside: two ArrayInitializerExprs.
+ * These have two expressions each, one has 1 and 1, the other two and two.
+ * <br/><code>new int[][]{{1, 1}, {2, 2}};</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ArrayInitializerExpr extends Expression {
+
+ private NodeList<Expression> values;
+
+ public ArrayInitializerExpr() {
+ this(null, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ArrayInitializerExpr(NodeList<Expression> values) {
+ this(null, values);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ArrayInitializerExpr(TokenRange tokenRange, NodeList<Expression> values) {
+ super(tokenRange);
+ setValues(values);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Expression> getValues() {
+ return values;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayInitializerExpr setValues(final NodeList<Expression> values) {
+ assertNotNull(values);
+ if (values == this.values) {
+ return (ArrayInitializerExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.VALUES, this.values, values);
+ if (this.values != null)
+ this.values.setParentNode(null);
+ this.values = values;
+ setAsParentNodeOf(values);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < values.size(); i++) {
+ if (values.get(i) == node) {
+ values.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ArrayInitializerExpr clone() {
+ return (ArrayInitializerExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ArrayInitializerExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.arrayInitializerExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < values.size(); i++) {
+ if (values.get(i) == node) {
+ values.set(i, (Expression) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isArrayInitializerExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ArrayInitializerExpr asArrayInitializerExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifArrayInitializerExpr(Consumer<ArrayInitializerExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ArrayInitializerExpr> toArrayInitializerExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AssignExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AssignExpr.java
new file mode 100644
index 000000000..fbb46874d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/AssignExpr.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.AssignExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.printer.Printable;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An assignment expression. It supports the operators that are found the the AssignExpr.Operator enum.
+ * <br/><code>a=5</code>
+ * <br/><code>time+=500</code>
+ * <br/><code>watch.time+=500</code>
+ * <br/><code>(((time)))=100*60</code>
+ * <br/><code>peanut[a]=true</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class AssignExpr extends Expression {
+
+ public enum Operator implements Printable {
+
+ ASSIGN("="),
+ PLUS("+="),
+ MINUS("-="),
+ MULTIPLY("*="),
+ DIVIDE("/="),
+ BINARY_AND("&="),
+ BINARY_OR("|="),
+ XOR("^="),
+ REMAINDER("%="),
+ LEFT_SHIFT("<<="),
+ SIGNED_RIGHT_SHIFT(">>="),
+ UNSIGNED_RIGHT_SHIFT(">>>=");
+
+ private final String codeRepresentation;
+
+ Operator(String codeRepresentation) {
+ this.codeRepresentation = codeRepresentation;
+ }
+
+ public String asString() {
+ return codeRepresentation;
+ }
+
+ public Optional<BinaryExpr.Operator> toBinaryOperator() {
+ switch(this) {
+ case PLUS:
+ return Optional.of(BinaryExpr.Operator.PLUS);
+ case MINUS:
+ return Optional.of(BinaryExpr.Operator.MINUS);
+ case MULTIPLY:
+ return Optional.of(BinaryExpr.Operator.MULTIPLY);
+ case DIVIDE:
+ return Optional.of(BinaryExpr.Operator.DIVIDE);
+ case BINARY_AND:
+ return Optional.of(BinaryExpr.Operator.BINARY_AND);
+ case BINARY_OR:
+ return Optional.of(BinaryExpr.Operator.BINARY_OR);
+ case XOR:
+ return Optional.of(BinaryExpr.Operator.XOR);
+ case REMAINDER:
+ return Optional.of(BinaryExpr.Operator.REMAINDER);
+ case LEFT_SHIFT:
+ return Optional.of(BinaryExpr.Operator.LEFT_SHIFT);
+ case SIGNED_RIGHT_SHIFT:
+ return Optional.of(BinaryExpr.Operator.SIGNED_RIGHT_SHIFT);
+ case UNSIGNED_RIGHT_SHIFT:
+ return Optional.of(BinaryExpr.Operator.UNSIGNED_RIGHT_SHIFT);
+ default:
+ return Optional.empty();
+ }
+ }
+ }
+
+ private Expression target;
+
+ private Expression value;
+
+ private Operator operator;
+
+ public AssignExpr() {
+ this(null, new NameExpr(), new StringLiteralExpr(), Operator.ASSIGN);
+ }
+
+ @AllFieldsConstructor
+ public AssignExpr(Expression target, Expression value, Operator operator) {
+ this(null, target, value, operator);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public AssignExpr(TokenRange tokenRange, Expression target, Expression value, Operator operator) {
+ super(tokenRange);
+ setTarget(target);
+ setValue(value);
+ setOperator(operator);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Operator getOperator() {
+ return operator;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getTarget() {
+ return target;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getValue() {
+ return value;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AssignExpr setOperator(final Operator operator) {
+ assertNotNull(operator);
+ if (operator == this.operator) {
+ return (AssignExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.OPERATOR, this.operator, operator);
+ this.operator = operator;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AssignExpr setTarget(final Expression target) {
+ assertNotNull(target);
+ if (target == this.target) {
+ return (AssignExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TARGET, this.target, target);
+ if (this.target != null)
+ this.target.setParentNode(null);
+ this.target = target;
+ setAsParentNodeOf(target);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AssignExpr setValue(final Expression value) {
+ assertNotNull(value);
+ if (value == this.value) {
+ return (AssignExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.VALUE, this.value, value);
+ if (this.value != null)
+ this.value.setParentNode(null);
+ this.value = value;
+ setAsParentNodeOf(value);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public AssignExpr clone() {
+ return (AssignExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public AssignExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.assignExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == target) {
+ setTarget((Expression) replacementNode);
+ return true;
+ }
+ if (node == value) {
+ setValue((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAssignExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AssignExpr asAssignExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAssignExpr(Consumer<AssignExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AssignExpr> toAssignExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BinaryExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BinaryExpr.java
new file mode 100644
index 000000000..5ec79c0af
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BinaryExpr.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.BinaryExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.printer.Printable;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An expression with an expression on the left, an expression on the right, and an operator in the middle.
+ * It supports the operators that are found the the BinaryExpr.Operator enum.
+ * <br/><code>a && b</code>
+ * <br/><code>155 * 33</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class BinaryExpr extends Expression {
+
+ public enum Operator implements Printable {
+
+ OR("||"),
+ AND("&&"),
+ BINARY_OR("|"),
+ BINARY_AND("&"),
+ XOR("^"),
+ EQUALS("=="),
+ NOT_EQUALS("!="),
+ LESS("<"),
+ GREATER(">"),
+ LESS_EQUALS("<="),
+ GREATER_EQUALS(">="),
+ LEFT_SHIFT("<<"),
+ SIGNED_RIGHT_SHIFT(">>"),
+ UNSIGNED_RIGHT_SHIFT(">>>"),
+ PLUS("+"),
+ MINUS("-"),
+ MULTIPLY("*"),
+ DIVIDE("/"),
+ REMAINDER("%");
+
+ private final String codeRepresentation;
+
+ Operator(String codeRepresentation) {
+ this.codeRepresentation = codeRepresentation;
+ }
+
+ public String asString() {
+ return codeRepresentation;
+ }
+
+ public Optional<AssignExpr.Operator> toAssignOperator() {
+ switch(this) {
+ case BINARY_OR:
+ return Optional.of(AssignExpr.Operator.BINARY_OR);
+ case BINARY_AND:
+ return Optional.of(AssignExpr.Operator.BINARY_AND);
+ case XOR:
+ return Optional.of(AssignExpr.Operator.XOR);
+ case LEFT_SHIFT:
+ return Optional.of(AssignExpr.Operator.LEFT_SHIFT);
+ case SIGNED_RIGHT_SHIFT:
+ return Optional.of(AssignExpr.Operator.SIGNED_RIGHT_SHIFT);
+ case UNSIGNED_RIGHT_SHIFT:
+ return Optional.of(AssignExpr.Operator.UNSIGNED_RIGHT_SHIFT);
+ case PLUS:
+ return Optional.of(AssignExpr.Operator.PLUS);
+ case MINUS:
+ return Optional.of(AssignExpr.Operator.MINUS);
+ case MULTIPLY:
+ return Optional.of(AssignExpr.Operator.MULTIPLY);
+ case DIVIDE:
+ return Optional.of(AssignExpr.Operator.DIVIDE);
+ case REMAINDER:
+ return Optional.of(AssignExpr.Operator.REMAINDER);
+ default:
+ return Optional.empty();
+ }
+ }
+ }
+
+ private Expression left;
+
+ private Expression right;
+
+ private Operator operator;
+
+ public BinaryExpr() {
+ this(null, new BooleanLiteralExpr(), new BooleanLiteralExpr(), Operator.EQUALS);
+ }
+
+ @AllFieldsConstructor
+ public BinaryExpr(Expression left, Expression right, Operator operator) {
+ this(null, left, right, operator);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public BinaryExpr(TokenRange tokenRange, Expression left, Expression right, Operator operator) {
+ super(tokenRange);
+ setLeft(left);
+ setRight(right);
+ setOperator(operator);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getLeft() {
+ return left;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Operator getOperator() {
+ return operator;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getRight() {
+ return right;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BinaryExpr setLeft(final Expression left) {
+ assertNotNull(left);
+ if (left == this.left) {
+ return (BinaryExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.LEFT, this.left, left);
+ if (this.left != null)
+ this.left.setParentNode(null);
+ this.left = left;
+ setAsParentNodeOf(left);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BinaryExpr setOperator(final Operator operator) {
+ assertNotNull(operator);
+ if (operator == this.operator) {
+ return (BinaryExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.OPERATOR, this.operator, operator);
+ this.operator = operator;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BinaryExpr setRight(final Expression right) {
+ assertNotNull(right);
+ if (right == this.right) {
+ return (BinaryExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.RIGHT, this.right, right);
+ if (this.right != null)
+ this.right.setParentNode(null);
+ this.right = right;
+ setAsParentNodeOf(right);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public BinaryExpr clone() {
+ return (BinaryExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public BinaryExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.binaryExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == left) {
+ setLeft((Expression) replacementNode);
+ return true;
+ }
+ if (node == right) {
+ setRight((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBinaryExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BinaryExpr asBinaryExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBinaryExpr(Consumer<BinaryExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BinaryExpr> toBinaryExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BooleanLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BooleanLiteralExpr.java
new file mode 100644
index 000000000..4be43b298
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/BooleanLiteralExpr.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.BooleanLiteralExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * The boolean literals.
+ * <br/><code>true</code>
+ * <br/><code>false</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class BooleanLiteralExpr extends LiteralExpr {
+
+ private boolean value;
+
+ public BooleanLiteralExpr() {
+ this(null, false);
+ }
+
+ @AllFieldsConstructor
+ public BooleanLiteralExpr(boolean value) {
+ this(null, value);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public BooleanLiteralExpr(TokenRange tokenRange, boolean value) {
+ super(tokenRange);
+ setValue(value);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean getValue() {
+ return value;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BooleanLiteralExpr setValue(final boolean value) {
+ if (value == this.value) {
+ return (BooleanLiteralExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.VALUE, this.value, value);
+ this.value = value;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public BooleanLiteralExpr clone() {
+ return (BooleanLiteralExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public BooleanLiteralExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.booleanLiteralExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBooleanLiteralExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BooleanLiteralExpr asBooleanLiteralExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBooleanLiteralExpr(Consumer<BooleanLiteralExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BooleanLiteralExpr> toBooleanLiteralExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CastExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CastExpr.java
new file mode 100644
index 000000000..174d24cad
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CastExpr.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.nodeTypes.NodeWithExpression;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.CastExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A typecast. The (long) in <code>(long)15</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class CastExpr extends Expression implements NodeWithType<CastExpr, Type>, NodeWithExpression<CastExpr> {
+
+ private Type type;
+
+ private Expression expression;
+
+ public CastExpr() {
+ this(null, new ClassOrInterfaceType(), new NameExpr());
+ }
+
+ @AllFieldsConstructor
+ public CastExpr(Type type, Expression expression) {
+ this(null, type, expression);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public CastExpr(TokenRange tokenRange, Type type, Expression expression) {
+ super(tokenRange);
+ setType(type);
+ setExpression(expression);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getExpression() {
+ return expression;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public CastExpr setExpression(final Expression expression) {
+ assertNotNull(expression);
+ if (expression == this.expression) {
+ return (CastExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression);
+ if (this.expression != null)
+ this.expression.setParentNode(null);
+ this.expression = expression;
+ setAsParentNodeOf(expression);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public CastExpr setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (CastExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public CastExpr clone() {
+ return (CastExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public CastExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.castExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == expression) {
+ setExpression((Expression) replacementNode);
+ return true;
+ }
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isCastExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public CastExpr asCastExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifCastExpr(Consumer<CastExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<CastExpr> toCastExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CharLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CharLiteralExpr.java
new file mode 100644
index 000000000..bc2db0023
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/CharLiteralExpr.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.CharLiteralExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.utils.StringEscapeUtils;
+import com.github.javaparser.utils.Utils;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A literal character.
+ * <br/><code>'a'</code>
+ * <br/><code>'\t'</code>
+ * <br/><code>'Ω'</code>
+ * <br/><code>'\177'</code>
+ * <br/><code>'💩'</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class CharLiteralExpr extends LiteralStringValueExpr {
+
+ public CharLiteralExpr() {
+ this(null, "?");
+ }
+
+ @AllFieldsConstructor
+ public CharLiteralExpr(String value) {
+ this(null, value);
+ }
+
+ /**
+ * Constructs a CharLiteralExpr with given escaped character.
+ *
+ * @param value a char
+ */
+ public CharLiteralExpr(char value) {
+ this(null, StringEscapeUtils.escapeJava(String.valueOf(value)));
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public CharLiteralExpr(TokenRange tokenRange, String value) {
+ super(tokenRange, value);
+ customInitialization();
+ }
+
+ /**
+ * Utility method that creates a new StringLiteralExpr. Escapes EOL characters.
+ */
+ public static CharLiteralExpr escape(String string) {
+ return new CharLiteralExpr(Utils.escapeEndOfLines(string));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ /**
+ * @return the unescaped value character of this literal
+ */
+ public char asChar() {
+ return StringEscapeUtils.unescapeJava(value).charAt(0);
+ }
+
+ /**
+ * Sets the given char as the literal value
+ *
+ * @param value a char
+ * @return this expression
+ */
+ public CharLiteralExpr setChar(char value) {
+ this.value = String.valueOf(value);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public CharLiteralExpr clone() {
+ return (CharLiteralExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public CharLiteralExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.charLiteralExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isCharLiteralExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public CharLiteralExpr asCharLiteralExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifCharLiteralExpr(Consumer<CharLiteralExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<CharLiteralExpr> toCharLiteralExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ClassExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ClassExpr.java
new file mode 100644
index 000000000..729bd4ff2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ClassExpr.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ClassExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Defines an expression that accesses the class of a type.
+ * <br/><code>Object.class</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ClassExpr extends Expression implements NodeWithType<ClassExpr, Type> {
+
+ private Type type;
+
+ public ClassExpr() {
+ this(null, new ClassOrInterfaceType());
+ }
+
+ @AllFieldsConstructor
+ public ClassExpr(Type type) {
+ this(null, type);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ClassExpr(TokenRange tokenRange, Type type) {
+ super(tokenRange);
+ setType(type);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassExpr setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (ClassExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ClassExpr clone() {
+ return (ClassExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ClassExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.classExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isClassExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ClassExpr asClassExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifClassExpr(Consumer<ClassExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ClassExpr> toClassExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ConditionalExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ConditionalExpr.java
new file mode 100644
index 000000000..bdc50a061
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ConditionalExpr.java
@@ -0,0 +1,204 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.nodeTypes.NodeWithCondition;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ConditionalExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * The ternary conditional expression.
+ * In <code>b==0?x:y</code>, b==0 is the condition, x is thenExpr, and y is elseExpr.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ConditionalExpr extends Expression implements NodeWithCondition<ConditionalExpr> {
+
+ private Expression condition;
+
+ private Expression thenExpr;
+
+ private Expression elseExpr;
+
+ public ConditionalExpr() {
+ this(null, new BooleanLiteralExpr(), new StringLiteralExpr(), new StringLiteralExpr());
+ }
+
+ @AllFieldsConstructor
+ public ConditionalExpr(Expression condition, Expression thenExpr, Expression elseExpr) {
+ this(null, condition, thenExpr, elseExpr);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ConditionalExpr(TokenRange tokenRange, Expression condition, Expression thenExpr, Expression elseExpr) {
+ super(tokenRange);
+ setCondition(condition);
+ setThenExpr(thenExpr);
+ setElseExpr(elseExpr);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getCondition() {
+ return condition;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getElseExpr() {
+ return elseExpr;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getThenExpr() {
+ return thenExpr;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ConditionalExpr setCondition(final Expression condition) {
+ assertNotNull(condition);
+ if (condition == this.condition) {
+ return (ConditionalExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition);
+ if (this.condition != null)
+ this.condition.setParentNode(null);
+ this.condition = condition;
+ setAsParentNodeOf(condition);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ConditionalExpr setElseExpr(final Expression elseExpr) {
+ assertNotNull(elseExpr);
+ if (elseExpr == this.elseExpr) {
+ return (ConditionalExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.ELSE_EXPR, this.elseExpr, elseExpr);
+ if (this.elseExpr != null)
+ this.elseExpr.setParentNode(null);
+ this.elseExpr = elseExpr;
+ setAsParentNodeOf(elseExpr);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ConditionalExpr setThenExpr(final Expression thenExpr) {
+ assertNotNull(thenExpr);
+ if (thenExpr == this.thenExpr) {
+ return (ConditionalExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.THEN_EXPR, this.thenExpr, thenExpr);
+ if (this.thenExpr != null)
+ this.thenExpr.setParentNode(null);
+ this.thenExpr = thenExpr;
+ setAsParentNodeOf(thenExpr);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ConditionalExpr clone() {
+ return (ConditionalExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ConditionalExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.conditionalExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == condition) {
+ setCondition((Expression) replacementNode);
+ return true;
+ }
+ if (node == elseExpr) {
+ setElseExpr((Expression) replacementNode);
+ return true;
+ }
+ if (node == thenExpr) {
+ setThenExpr((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isConditionalExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ConditionalExpr asConditionalExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifConditionalExpr(Consumer<ConditionalExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ConditionalExpr> toConditionalExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/DoubleLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/DoubleLiteralExpr.java
new file mode 100644
index 000000000..007fdf320
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/DoubleLiteralExpr.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.DoubleLiteralExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A float or a double constant. This value is stored exactly as found in the source.
+ * <br/><code>100.1f</code>
+ * <br/><code>23958D</code>
+ * <br/><code>0x4.5p1f</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class DoubleLiteralExpr extends LiteralStringValueExpr {
+
+ public DoubleLiteralExpr() {
+ this(null, "0");
+ }
+
+ @AllFieldsConstructor
+ public DoubleLiteralExpr(final String value) {
+ this(null, value);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public DoubleLiteralExpr(TokenRange tokenRange, String value) {
+ super(tokenRange, value);
+ customInitialization();
+ }
+
+ public DoubleLiteralExpr(final double value) {
+ this(null, String.valueOf(value));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ /**
+ * @return the literal value as a double
+ */
+ public double asDouble() {
+ return Double.parseDouble(value);
+ }
+
+ public DoubleLiteralExpr setDouble(double value) {
+ this.value = String.valueOf(value);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public DoubleLiteralExpr clone() {
+ return (DoubleLiteralExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public DoubleLiteralExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.doubleLiteralExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isDoubleLiteralExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public DoubleLiteralExpr asDoubleLiteralExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifDoubleLiteralExpr(Consumer<DoubleLiteralExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<DoubleLiteralExpr> toDoubleLiteralExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java
new file mode 100644
index 000000000..c3d56d887
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/EnclosedExpr.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.EnclosedExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import java.util.function.Consumer;
+
+/**
+ * An expression between ( ).
+ * <br/><code>(1+1)</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class EnclosedExpr extends Expression {
+
+ private Expression inner;
+
+ public EnclosedExpr() {
+ this(null, new StringLiteralExpr());
+ }
+
+ @AllFieldsConstructor
+ public EnclosedExpr(final Expression inner) {
+ this(null, inner);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public EnclosedExpr(TokenRange tokenRange, Expression inner) {
+ super(tokenRange);
+ setInner(inner);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getInner() {
+ return inner;
+ }
+
+ /**
+ * Sets the inner expression
+ *
+ * @param inner the inner expression, can be null
+ * @return this, the EnclosedExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnclosedExpr setInner(final Expression inner) {
+ assertNotNull(inner);
+ if (inner == this.inner) {
+ return (EnclosedExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.INNER, this.inner, inner);
+ if (this.inner != null)
+ this.inner.setParentNode(null);
+ this.inner = inner;
+ setAsParentNodeOf(inner);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public EnclosedExpr removeInner() {
+ return setInner((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public EnclosedExpr clone() {
+ return (EnclosedExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public EnclosedExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.enclosedExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == inner) {
+ setInner((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isEnclosedExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public EnclosedExpr asEnclosedExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifEnclosedExpr(Consumer<EnclosedExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<EnclosedExpr> toEnclosedExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Expression.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Expression.java
new file mode 100644
index 000000000..de9e52b4c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Expression.java
@@ -0,0 +1,733 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ExpressionMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.types.ResolvedType;
+import java.util.function.Consumer;
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+import java.util.Optional;
+
+/**
+ * A base class for all expressions.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class Expression extends Node {
+
+ @AllFieldsConstructor
+ public Expression() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public Expression(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public Expression clone() {
+ return (Expression) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ExpressionMetaModel getMetaModel() {
+ return JavaParserMetaModel.expressionMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAnnotationExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AnnotationExpr asAnnotationExpr() {
+ throw new IllegalStateException(f("%s is not an AnnotationExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isArrayAccessExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ArrayAccessExpr asArrayAccessExpr() {
+ throw new IllegalStateException(f("%s is not an ArrayAccessExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isArrayCreationExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ArrayCreationExpr asArrayCreationExpr() {
+ throw new IllegalStateException(f("%s is not an ArrayCreationExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isArrayInitializerExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ArrayInitializerExpr asArrayInitializerExpr() {
+ throw new IllegalStateException(f("%s is not an ArrayInitializerExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAssignExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AssignExpr asAssignExpr() {
+ throw new IllegalStateException(f("%s is not an AssignExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBinaryExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BinaryExpr asBinaryExpr() {
+ throw new IllegalStateException(f("%s is not an BinaryExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBooleanLiteralExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BooleanLiteralExpr asBooleanLiteralExpr() {
+ throw new IllegalStateException(f("%s is not an BooleanLiteralExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isCastExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public CastExpr asCastExpr() {
+ throw new IllegalStateException(f("%s is not an CastExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isCharLiteralExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public CharLiteralExpr asCharLiteralExpr() {
+ throw new IllegalStateException(f("%s is not an CharLiteralExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isClassExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ClassExpr asClassExpr() {
+ throw new IllegalStateException(f("%s is not an ClassExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isConditionalExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ConditionalExpr asConditionalExpr() {
+ throw new IllegalStateException(f("%s is not an ConditionalExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isDoubleLiteralExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public DoubleLiteralExpr asDoubleLiteralExpr() {
+ throw new IllegalStateException(f("%s is not an DoubleLiteralExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isEnclosedExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public EnclosedExpr asEnclosedExpr() {
+ throw new IllegalStateException(f("%s is not an EnclosedExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isFieldAccessExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public FieldAccessExpr asFieldAccessExpr() {
+ throw new IllegalStateException(f("%s is not an FieldAccessExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isInstanceOfExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public InstanceOfExpr asInstanceOfExpr() {
+ throw new IllegalStateException(f("%s is not an InstanceOfExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isIntegerLiteralExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public IntegerLiteralExpr asIntegerLiteralExpr() {
+ throw new IllegalStateException(f("%s is not an IntegerLiteralExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLambdaExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LambdaExpr asLambdaExpr() {
+ throw new IllegalStateException(f("%s is not an LambdaExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLiteralExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LiteralExpr asLiteralExpr() {
+ throw new IllegalStateException(f("%s is not an LiteralExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLiteralStringValueExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LiteralStringValueExpr asLiteralStringValueExpr() {
+ throw new IllegalStateException(f("%s is not an LiteralStringValueExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLongLiteralExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LongLiteralExpr asLongLiteralExpr() {
+ throw new IllegalStateException(f("%s is not an LongLiteralExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isMarkerAnnotationExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public MarkerAnnotationExpr asMarkerAnnotationExpr() {
+ throw new IllegalStateException(f("%s is not an MarkerAnnotationExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isMethodCallExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public MethodCallExpr asMethodCallExpr() {
+ throw new IllegalStateException(f("%s is not an MethodCallExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isMethodReferenceExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public MethodReferenceExpr asMethodReferenceExpr() {
+ throw new IllegalStateException(f("%s is not an MethodReferenceExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isNameExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public NameExpr asNameExpr() {
+ throw new IllegalStateException(f("%s is not an NameExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isNormalAnnotationExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public NormalAnnotationExpr asNormalAnnotationExpr() {
+ throw new IllegalStateException(f("%s is not an NormalAnnotationExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isNullLiteralExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public NullLiteralExpr asNullLiteralExpr() {
+ throw new IllegalStateException(f("%s is not an NullLiteralExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isObjectCreationExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ObjectCreationExpr asObjectCreationExpr() {
+ throw new IllegalStateException(f("%s is not an ObjectCreationExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSingleMemberAnnotationExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SingleMemberAnnotationExpr asSingleMemberAnnotationExpr() {
+ throw new IllegalStateException(f("%s is not an SingleMemberAnnotationExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isStringLiteralExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public StringLiteralExpr asStringLiteralExpr() {
+ throw new IllegalStateException(f("%s is not an StringLiteralExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSuperExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SuperExpr asSuperExpr() {
+ throw new IllegalStateException(f("%s is not an SuperExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isThisExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ThisExpr asThisExpr() {
+ throw new IllegalStateException(f("%s is not an ThisExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isTypeExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public TypeExpr asTypeExpr() {
+ throw new IllegalStateException(f("%s is not an TypeExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isUnaryExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public UnaryExpr asUnaryExpr() {
+ throw new IllegalStateException(f("%s is not an UnaryExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isVariableDeclarationExpr() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public VariableDeclarationExpr asVariableDeclarationExpr() {
+ throw new IllegalStateException(f("%s is not an VariableDeclarationExpr", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAnnotationExpr(Consumer<AnnotationExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifArrayAccessExpr(Consumer<ArrayAccessExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifArrayCreationExpr(Consumer<ArrayCreationExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifArrayInitializerExpr(Consumer<ArrayInitializerExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAssignExpr(Consumer<AssignExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBinaryExpr(Consumer<BinaryExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBooleanLiteralExpr(Consumer<BooleanLiteralExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifCastExpr(Consumer<CastExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifCharLiteralExpr(Consumer<CharLiteralExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifClassExpr(Consumer<ClassExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifConditionalExpr(Consumer<ConditionalExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifDoubleLiteralExpr(Consumer<DoubleLiteralExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifEnclosedExpr(Consumer<EnclosedExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifFieldAccessExpr(Consumer<FieldAccessExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifInstanceOfExpr(Consumer<InstanceOfExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifIntegerLiteralExpr(Consumer<IntegerLiteralExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLambdaExpr(Consumer<LambdaExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLiteralExpr(Consumer<LiteralExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLiteralStringValueExpr(Consumer<LiteralStringValueExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLongLiteralExpr(Consumer<LongLiteralExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifMarkerAnnotationExpr(Consumer<MarkerAnnotationExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifMethodCallExpr(Consumer<MethodCallExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifMethodReferenceExpr(Consumer<MethodReferenceExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifNameExpr(Consumer<NameExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifNormalAnnotationExpr(Consumer<NormalAnnotationExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifNullLiteralExpr(Consumer<NullLiteralExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifObjectCreationExpr(Consumer<ObjectCreationExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSingleMemberAnnotationExpr(Consumer<SingleMemberAnnotationExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifStringLiteralExpr(Consumer<StringLiteralExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSuperExpr(Consumer<SuperExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifThisExpr(Consumer<ThisExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifTypeExpr(Consumer<TypeExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifUnaryExpr(Consumer<UnaryExpr> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifVariableDeclarationExpr(Consumer<VariableDeclarationExpr> action) {
+ }
+
+ public ResolvedType calculateResolvedType() {
+ return getSymbolResolver().calculateType(this);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AnnotationExpr> toAnnotationExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ArrayAccessExpr> toArrayAccessExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ArrayCreationExpr> toArrayCreationExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ArrayInitializerExpr> toArrayInitializerExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AssignExpr> toAssignExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BinaryExpr> toBinaryExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BooleanLiteralExpr> toBooleanLiteralExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<CastExpr> toCastExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<CharLiteralExpr> toCharLiteralExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ClassExpr> toClassExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ConditionalExpr> toConditionalExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<DoubleLiteralExpr> toDoubleLiteralExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<EnclosedExpr> toEnclosedExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<FieldAccessExpr> toFieldAccessExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<InstanceOfExpr> toInstanceOfExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<IntegerLiteralExpr> toIntegerLiteralExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LambdaExpr> toLambdaExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LiteralExpr> toLiteralExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LiteralStringValueExpr> toLiteralStringValueExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LongLiteralExpr> toLongLiteralExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<MarkerAnnotationExpr> toMarkerAnnotationExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<MethodCallExpr> toMethodCallExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<MethodReferenceExpr> toMethodReferenceExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<NameExpr> toNameExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<NormalAnnotationExpr> toNormalAnnotationExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<NullLiteralExpr> toNullLiteralExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ObjectCreationExpr> toObjectCreationExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SingleMemberAnnotationExpr> toSingleMemberAnnotationExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<StringLiteralExpr> toStringLiteralExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SuperExpr> toSuperExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ThisExpr> toThisExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<TypeExpr> toTypeExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<UnaryExpr> toUnaryExpr() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<VariableDeclarationExpr> toVariableDeclarationExpr() {
+ return Optional.empty();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java
new file mode 100644
index 000000000..c6b9e0a94
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/FieldAccessExpr.java
@@ -0,0 +1,262 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.nodeTypes.NodeWithScope;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.FieldAccessExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import java.util.function.Consumer;
+
+/**
+ * Access of a field of an object.
+ * <br/>In <code>person.name</code> "name" is the name and "person" is the scope.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class FieldAccessExpr extends Expression implements NodeWithSimpleName<FieldAccessExpr>, NodeWithTypeArguments<FieldAccessExpr>, NodeWithScope<FieldAccessExpr> {
+
+ private Expression scope;
+
+ @OptionalProperty
+ private NodeList<Type> typeArguments;
+
+ private SimpleName name;
+
+ public FieldAccessExpr() {
+ this(null, new ThisExpr(), new NodeList<>(), new SimpleName());
+ }
+
+ public FieldAccessExpr(final Expression scope, final String name) {
+ this(null, scope, new NodeList<>(), new SimpleName(name));
+ }
+
+ @AllFieldsConstructor
+ public FieldAccessExpr(final Expression scope, final NodeList<Type> typeArguments, final SimpleName name) {
+ this(null, scope, typeArguments, name);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public FieldAccessExpr(TokenRange tokenRange, Expression scope, NodeList<Type> typeArguments, SimpleName name) {
+ super(tokenRange);
+ setScope(scope);
+ setTypeArguments(typeArguments);
+ setName(name);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public FieldAccessExpr setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (FieldAccessExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ /**
+ * Use {@link #getName} instead.
+ */
+ @Deprecated
+ public SimpleName getField() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getScope() {
+ return scope;
+ }
+
+ /**
+ * Use {@link #setName} with new SimpleName(field) instead.
+ */
+ @Deprecated
+ public FieldAccessExpr setField(final String field) {
+ setName(new SimpleName(field));
+ return this;
+ }
+
+ /**
+ * Use {@link #setName} instead.
+ */
+ @Deprecated
+ public FieldAccessExpr setFieldExpr(SimpleName inner) {
+ return setName(inner);
+ }
+
+ /**
+ * Sets the scope
+ *
+ * @param scope the scope, can not be null
+ * @return this, the FieldAccessExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public FieldAccessExpr setScope(final Expression scope) {
+ assertNotNull(scope);
+ if (scope == this.scope) {
+ return (FieldAccessExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope);
+ if (this.scope != null)
+ this.scope.setParentNode(null);
+ this.scope = scope;
+ setAsParentNodeOf(scope);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<NodeList<Type>> getTypeArguments() {
+ return Optional.ofNullable(typeArguments);
+ }
+
+ /**
+ * Sets the type arguments
+ *
+ * @param typeArguments the type arguments, can be null
+ * @return this, the FieldAccessExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public FieldAccessExpr setTypeArguments(final NodeList<Type> typeArguments) {
+ if (typeArguments == this.typeArguments) {
+ return (FieldAccessExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments);
+ if (this.typeArguments != null)
+ this.typeArguments.setParentNode(null);
+ this.typeArguments = typeArguments;
+ setAsParentNodeOf(typeArguments);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public FieldAccessExpr clone() {
+ return (FieldAccessExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public FieldAccessExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.fieldAccessExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.remove(i);
+ return true;
+ }
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ if (node == scope) {
+ setScope((Expression) replacementNode);
+ return true;
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.set(i, (Type) replacementNode);
+ return true;
+ }
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isFieldAccessExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public FieldAccessExpr asFieldAccessExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifFieldAccessExpr(Consumer<FieldAccessExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<FieldAccessExpr> toFieldAccessExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/InstanceOfExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/InstanceOfExpr.java
new file mode 100644
index 000000000..69a505b7c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/InstanceOfExpr.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.nodeTypes.NodeWithExpression;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.ReferenceType;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.InstanceOfExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Usage of the instanceof operator.
+ * <br/><code>tool instanceof Drill</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class InstanceOfExpr extends Expression implements NodeWithType<InstanceOfExpr, ReferenceType>, NodeWithExpression<InstanceOfExpr> {
+
+ private Expression expression;
+
+ private ReferenceType type;
+
+ public InstanceOfExpr() {
+ this(null, new NameExpr(), new ClassOrInterfaceType());
+ }
+
+ @AllFieldsConstructor
+ public InstanceOfExpr(final Expression expression, final ReferenceType type) {
+ this(null, expression, type);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public InstanceOfExpr(TokenRange tokenRange, Expression expression, ReferenceType type) {
+ super(tokenRange);
+ setExpression(expression);
+ setType(type);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getExpression() {
+ return expression;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ReferenceType getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public InstanceOfExpr setExpression(final Expression expression) {
+ assertNotNull(expression);
+ if (expression == this.expression) {
+ return (InstanceOfExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression);
+ if (this.expression != null)
+ this.expression.setParentNode(null);
+ this.expression = expression;
+ setAsParentNodeOf(expression);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public InstanceOfExpr setType(final ReferenceType type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (InstanceOfExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public InstanceOfExpr clone() {
+ return (InstanceOfExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public InstanceOfExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.instanceOfExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == expression) {
+ setExpression((Expression) replacementNode);
+ return true;
+ }
+ if (node == type) {
+ setType((ReferenceType) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isInstanceOfExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public InstanceOfExpr asInstanceOfExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifInstanceOfExpr(Consumer<InstanceOfExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<InstanceOfExpr> toInstanceOfExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/IntegerLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/IntegerLiteralExpr.java
new file mode 100644
index 000000000..a0d394986
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/IntegerLiteralExpr.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.IntegerLiteralExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * All ways to specify an int literal.
+ * <br/><code>8934</code>
+ * <br/><code>0x01</code>
+ * <br/><code>022</code>
+ * <br/><code>0B10101010</code>
+ * <br/><code>99999999L</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class IntegerLiteralExpr extends LiteralStringValueExpr {
+
+ public IntegerLiteralExpr() {
+ this(null, "0");
+ }
+
+ @AllFieldsConstructor
+ public IntegerLiteralExpr(final String value) {
+ this(null, value);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public IntegerLiteralExpr(TokenRange tokenRange, String value) {
+ super(tokenRange, value);
+ customInitialization();
+ }
+
+ public IntegerLiteralExpr(final int value) {
+ this(null, String.valueOf(value));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ /**
+ * @return the literal value as an integer while respecting different number representations
+ */
+ public int asInt() {
+ String result = value.replaceAll("_", "");
+ if (result.startsWith("0x") || result.startsWith("0X")) {
+ return Integer.parseUnsignedInt(result.substring(2), 16);
+ }
+ if (result.startsWith("0b") || result.startsWith("0B")) {
+ return Integer.parseUnsignedInt(result.substring(2), 2);
+ }
+ if (result.length() > 1 && result.startsWith("0")) {
+ return Integer.parseUnsignedInt(result.substring(1), 8);
+ }
+ return Integer.parseInt(result);
+ }
+
+ public IntegerLiteralExpr setInt(int value) {
+ this.value = String.valueOf(value);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public IntegerLiteralExpr clone() {
+ return (IntegerLiteralExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public IntegerLiteralExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.integerLiteralExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isIntegerLiteralExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public IntegerLiteralExpr asIntegerLiteralExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifIntegerLiteralExpr(Consumer<IntegerLiteralExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<IntegerLiteralExpr> toIntegerLiteralExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java
new file mode 100644
index 000000000..a69176f2a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LambdaExpr.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.Parameter;
+import com.github.javaparser.ast.nodeTypes.NodeWithParameters;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.stmt.ExpressionStmt;
+import com.github.javaparser.ast.stmt.ReturnStmt;
+import com.github.javaparser.ast.stmt.Statement;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.DerivedProperty;
+import com.github.javaparser.metamodel.LambdaExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+
+/**
+ * <h1>A lambda expression</h1>
+ * <h2>Java 1-7</h2>
+ * Does not exist.
+ * <h2>Java 8+</h2>
+ * <code>(a, b) -> a + b</code>
+ * <br/><code>a -> ...</code>
+ * <br/><code>(Long a) -> { println(a); }</code>
+ * <p/>The parameters are on the left side of the ->.
+ * If a parameter uses type inference (it has no type specified) then its type is set to <code>UnknownType</code>.
+ * If they are in ( ), "isEnclosingParameters" is true.
+ * <br/>The body is to the right of the ->.
+ * The body is either a BlockStatement when it is in { } braces, or an ExpressionStatement when it is not in braces.
+ *
+ * @author Raquel Pau
+ */
+public final class LambdaExpr extends Expression implements NodeWithParameters<LambdaExpr> {
+
+ private NodeList<Parameter> parameters;
+
+ private boolean isEnclosingParameters;
+
+ private Statement body;
+
+ public LambdaExpr() {
+ this(null, new NodeList<>(), new ReturnStmt(), false);
+ }
+
+ @AllFieldsConstructor
+ public LambdaExpr(NodeList<Parameter> parameters, Statement body, boolean isEnclosingParameters) {
+ this(null, parameters, body, isEnclosingParameters);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public LambdaExpr(TokenRange tokenRange, NodeList<Parameter> parameters, Statement body, boolean isEnclosingParameters) {
+ super(tokenRange);
+ setParameters(parameters);
+ setBody(body);
+ setEnclosingParameters(isEnclosingParameters);
+ customInitialization();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Parameter> getParameters() {
+ return parameters;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public LambdaExpr setParameters(final NodeList<Parameter> parameters) {
+ assertNotNull(parameters);
+ if (parameters == this.parameters) {
+ return (LambdaExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.PARAMETERS, this.parameters, parameters);
+ if (this.parameters != null)
+ this.parameters.setParentNode(null);
+ this.parameters = parameters;
+ setAsParentNodeOf(parameters);
+ return this;
+ }
+
+ /**
+ * @return a BlockStatement or an ExpressionStatement. See class Javadoc.
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Statement getBody() {
+ return body;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public LambdaExpr setBody(final Statement body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (LambdaExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean isEnclosingParameters() {
+ return isEnclosingParameters;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public LambdaExpr setEnclosingParameters(final boolean isEnclosingParameters) {
+ if (isEnclosingParameters == this.isEnclosingParameters) {
+ return (LambdaExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.ENCLOSING_PARAMETERS, this.isEnclosingParameters, isEnclosingParameters);
+ this.isEnclosingParameters = isEnclosingParameters;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < parameters.size(); i++) {
+ if (parameters.get(i) == node) {
+ parameters.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ /**
+ * @return if the body of this lambda is a simple expression, return that expression.
+ * Otherwise (when the body is a block) return Optional.empty().
+ */
+ @DerivedProperty
+ public Optional<Expression> getExpressionBody() {
+ if (body.isExpressionStmt()) {
+ return Optional.of(body.asExpressionStmt().getExpression());
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public LambdaExpr clone() {
+ return (LambdaExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public LambdaExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.lambdaExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((Statement) replacementNode);
+ return true;
+ }
+ for (int i = 0; i < parameters.size(); i++) {
+ if (parameters.get(i) == node) {
+ parameters.set(i, (Parameter) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLambdaExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LambdaExpr asLambdaExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLambdaExpr(Consumer<LambdaExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LambdaExpr> toLambdaExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralExpr.java
new file mode 100644
index 000000000..2c81560c6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralExpr.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.LiteralExprMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A base class for all literal expressions.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class LiteralExpr extends Expression {
+
+ @AllFieldsConstructor
+ public LiteralExpr() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public LiteralExpr(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public LiteralExpr clone() {
+ return (LiteralExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public LiteralExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.literalExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLiteralExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LiteralExpr asLiteralExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLiteralExpr(Consumer<LiteralExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LiteralExpr> toLiteralExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralStringValueExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralStringValueExpr.java
new file mode 100644
index 000000000..49561469e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LiteralStringValueExpr.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.LiteralStringValueExprMetaModel;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Any literal value that is stored internally as a String.
+ */
+public abstract class LiteralStringValueExpr extends LiteralExpr {
+
+ protected String value;
+
+ @AllFieldsConstructor
+ public LiteralStringValueExpr(final String value) {
+ this(null, value);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public LiteralStringValueExpr(TokenRange tokenRange, String value) {
+ super(tokenRange);
+ setValue(value);
+ customInitialization();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public String getValue() {
+ return value;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public LiteralStringValueExpr setValue(final String value) {
+ assertNotNull(value);
+ if (value == this.value) {
+ return (LiteralStringValueExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.VALUE, this.value, value);
+ this.value = value;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public LiteralStringValueExpr clone() {
+ return (LiteralStringValueExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public LiteralStringValueExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.literalStringValueExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLiteralStringValueExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LiteralStringValueExpr asLiteralStringValueExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLiteralStringValueExpr(Consumer<LiteralStringValueExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LiteralStringValueExpr> toLiteralStringValueExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LongLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LongLiteralExpr.java
new file mode 100644
index 000000000..d15442fbc
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/LongLiteralExpr.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.LongLiteralExprMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * All ways to specify a long literal.
+ * <br/><code>8934l</code>
+ * <br/><code>0x01L</code>
+ * <br/><code>022l</code>
+ * <br/><code>0B10101010L</code>
+ * <br/><code>99999999L</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class LongLiteralExpr extends LiteralStringValueExpr {
+
+ public LongLiteralExpr() {
+ this(null, "0");
+ }
+
+ @AllFieldsConstructor
+ public LongLiteralExpr(final String value) {
+ this(null, value);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public LongLiteralExpr(TokenRange tokenRange, String value) {
+ super(tokenRange, value);
+ customInitialization();
+ }
+
+ public LongLiteralExpr(final long value) {
+ this(null, String.valueOf(value));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ /**
+ * @return the literal value as an long while respecting different number representations
+ */
+ public long asLong() {
+ String result = value.replaceAll("_", "");
+ char lastChar = result.charAt(result.length() - 1);
+ if (lastChar == 'l' || lastChar == 'L') {
+ result = result.substring(0, result.length() - 1);
+ }
+ if (result.startsWith("0x") || result.startsWith("0X")) {
+ return Long.parseUnsignedLong(result.substring(2), 16);
+ }
+ if (result.startsWith("0b") || result.startsWith("0B")) {
+ return Long.parseUnsignedLong(result.substring(2), 2);
+ }
+ if (result.length() > 1 && result.startsWith("0")) {
+ return Long.parseUnsignedLong(result.substring(1), 8);
+ }
+ return Long.parseLong(result);
+ }
+
+ public LongLiteralExpr setLong(long value) {
+ this.value = String.valueOf(value);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public LongLiteralExpr clone() {
+ return (LongLiteralExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public LongLiteralExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.longLiteralExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLongLiteralExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LongLiteralExpr asLongLiteralExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLongLiteralExpr(Consumer<LongLiteralExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LongLiteralExpr> toLongLiteralExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java
new file mode 100644
index 000000000..e9ab8941d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MarkerAnnotationExpr.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.MarkerAnnotationExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import static com.github.javaparser.JavaParser.parseName;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An annotation that uses only the annotation type name.
+ * <br/><code>@Override</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class MarkerAnnotationExpr extends AnnotationExpr {
+
+ public MarkerAnnotationExpr() {
+ this(null, new Name());
+ }
+
+ public MarkerAnnotationExpr(final String name) {
+ this(null, parseName(name));
+ }
+
+ @AllFieldsConstructor
+ public MarkerAnnotationExpr(final Name name) {
+ this(null, name);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public MarkerAnnotationExpr(TokenRange tokenRange, Name name) {
+ super(tokenRange, name);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public MarkerAnnotationExpr clone() {
+ return (MarkerAnnotationExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public MarkerAnnotationExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.markerAnnotationExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isMarkerAnnotationExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public MarkerAnnotationExpr asMarkerAnnotationExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifMarkerAnnotationExpr(Consumer<MarkerAnnotationExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<MarkerAnnotationExpr> toMarkerAnnotationExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MemberValuePair.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MemberValuePair.java
new file mode 100644
index 000000000..8accb7b0f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MemberValuePair.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.MemberValuePairMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+
+/**
+ * A value for a member of an annotation.
+ * In <code>@Counters(a=15)</code> a=15 is a MemberValuePair. Its name is a, and its value is 15.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class MemberValuePair extends Node implements NodeWithSimpleName<MemberValuePair> {
+
+ private SimpleName name;
+
+ private Expression value;
+
+ public MemberValuePair() {
+ this(null, new SimpleName(), new StringLiteralExpr());
+ }
+
+ public MemberValuePair(final String name, final Expression value) {
+ this(null, new SimpleName(name), value);
+ }
+
+ @AllFieldsConstructor
+ public MemberValuePair(final SimpleName name, final Expression value) {
+ this(null, name, value);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public MemberValuePair(TokenRange tokenRange, SimpleName name, Expression value) {
+ super(tokenRange);
+ setName(name);
+ setValue(value);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getValue() {
+ return value;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MemberValuePair setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (MemberValuePair) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MemberValuePair setValue(final Expression value) {
+ assertNotNull(value);
+ if (value == this.value) {
+ return (MemberValuePair) this;
+ }
+ notifyPropertyChange(ObservableProperty.VALUE, this.value, value);
+ if (this.value != null)
+ this.value.setParentNode(null);
+ this.value = value;
+ setAsParentNodeOf(value);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public MemberValuePair clone() {
+ return (MemberValuePair) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public MemberValuePairMetaModel getMetaModel() {
+ return JavaParserMetaModel.memberValuePairMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ if (node == value) {
+ setValue((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java
new file mode 100644
index 000000000..dc914c9d4
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodCallExpr.java
@@ -0,0 +1,301 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.nodeTypes.NodeWithArguments;
+import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.MethodCallExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.resolution.SymbolResolver;
+import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
+import java.util.function.Consumer;
+
+/**
+ * A method call on an object. <br/><code>circle.circumference()</code> <br/>In <code>a.&lt;String&gt;bb(15);</code> a
+ * is the scope, String is a type argument, bb is the name and 15 is an argument.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class MethodCallExpr extends Expression implements NodeWithTypeArguments<MethodCallExpr>, NodeWithArguments<MethodCallExpr>, NodeWithSimpleName<MethodCallExpr>, NodeWithOptionalScope<MethodCallExpr> {
+
+ @OptionalProperty
+ private Expression scope;
+
+ @OptionalProperty
+ private NodeList<Type> typeArguments;
+
+ private SimpleName name;
+
+ private NodeList<Expression> arguments;
+
+ public MethodCallExpr() {
+ this(null, null, new NodeList<>(), new SimpleName(), new NodeList<>());
+ }
+
+ public MethodCallExpr(String name, Expression... arguments) {
+ this(null, null, new NodeList<>(), new SimpleName(name), new NodeList<>(arguments));
+ }
+
+ public MethodCallExpr(final Expression scope, final String name) {
+ this(null, scope, new NodeList<>(), new SimpleName(name), new NodeList<>());
+ }
+
+ public MethodCallExpr(final Expression scope, final SimpleName name) {
+ this(null, scope, new NodeList<>(), name, new NodeList<>());
+ }
+
+ public MethodCallExpr(final Expression scope, final String name, final NodeList<Expression> arguments) {
+ this(null, scope, new NodeList<>(), new SimpleName(name), arguments);
+ }
+
+ public MethodCallExpr(final Expression scope, final SimpleName name, final NodeList<Expression> arguments) {
+ this(null, scope, new NodeList<>(), name, arguments);
+ }
+
+ @AllFieldsConstructor
+ public MethodCallExpr(final Expression scope, final NodeList<Type> typeArguments, final SimpleName name, final NodeList<Expression> arguments) {
+ this(null, scope, typeArguments, name, arguments);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public MethodCallExpr(TokenRange tokenRange, Expression scope, NodeList<Type> typeArguments, SimpleName name, NodeList<Expression> arguments) {
+ super(tokenRange);
+ setScope(scope);
+ setTypeArguments(typeArguments);
+ setName(name);
+ setArguments(arguments);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Expression> getArguments() {
+ return arguments;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getScope() {
+ return Optional.ofNullable(scope);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodCallExpr setArguments(final NodeList<Expression> arguments) {
+ assertNotNull(arguments);
+ if (arguments == this.arguments) {
+ return (MethodCallExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.ARGUMENTS, this.arguments, arguments);
+ if (this.arguments != null)
+ this.arguments.setParentNode(null);
+ this.arguments = arguments;
+ setAsParentNodeOf(arguments);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodCallExpr setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (MethodCallExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodCallExpr setScope(final Expression scope) {
+ if (scope == this.scope) {
+ return (MethodCallExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope);
+ if (this.scope != null)
+ this.scope.setParentNode(null);
+ this.scope = scope;
+ setAsParentNodeOf(scope);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<NodeList<Type>> getTypeArguments() {
+ return Optional.ofNullable(typeArguments);
+ }
+
+ /**
+ * Sets the typeArguments
+ *
+ * @param typeArguments the typeArguments, can be null
+ * @return this, the MethodCallExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodCallExpr setTypeArguments(final NodeList<Type> typeArguments) {
+ if (typeArguments == this.typeArguments) {
+ return (MethodCallExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments);
+ if (this.typeArguments != null)
+ this.typeArguments.setParentNode(null);
+ this.typeArguments = typeArguments;
+ setAsParentNodeOf(typeArguments);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments.get(i) == node) {
+ arguments.remove(i);
+ return true;
+ }
+ }
+ if (scope != null) {
+ if (node == scope) {
+ removeScope();
+ return true;
+ }
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.remove(i);
+ return true;
+ }
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public MethodCallExpr removeScope() {
+ return setScope((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public MethodCallExpr clone() {
+ return (MethodCallExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public MethodCallExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.methodCallExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments.get(i) == node) {
+ arguments.set(i, (Expression) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ if (scope != null) {
+ if (node == scope) {
+ setScope((Expression) replacementNode);
+ return true;
+ }
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.set(i, (Type) replacementNode);
+ return true;
+ }
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isMethodCallExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public MethodCallExpr asMethodCallExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifMethodCallExpr(Consumer<MethodCallExpr> action) {
+ action.accept(this);
+ }
+
+ public ResolvedMethodDeclaration resolveInvokedMethod() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedMethodDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<MethodCallExpr> toMethodCallExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java
new file mode 100644
index 000000000..8ddaac00d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/MethodReferenceExpr.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.nodeTypes.NodeWithIdentifier;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.MethodReferenceExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import java.util.function.Consumer;
+
+/**
+ * Method reference expressions introduced in Java 8 specifically designed to simplify lambda Expressions.
+ * Note that the field "identifier", indicating the word to the right of the ::, is not always a method name,
+ * it can be "new".
+ * <br/>In <code>System.out::println;</code> the scope is System.out and the identifier is "println"
+ * <br/><code>(test ? stream.map(String::trim) : stream)::toArray;</code>
+ * <br/>In <code>Bar&lt;String>::&lt;Integer>new</code> the String type argument is on the scope,
+ * and the Integer type argument is on this MethodReferenceExpr.
+ *
+ * @author Raquel Pau
+ */
+public final class MethodReferenceExpr extends Expression implements NodeWithTypeArguments<MethodReferenceExpr>, NodeWithIdentifier<MethodReferenceExpr> {
+
+ private Expression scope;
+
+ @OptionalProperty
+ private NodeList<Type> typeArguments;
+
+ @NonEmptyProperty
+ private String identifier;
+
+ public MethodReferenceExpr() {
+ this(null, new ClassExpr(), null, "empty");
+ }
+
+ @AllFieldsConstructor
+ public MethodReferenceExpr(Expression scope, NodeList<Type> typeArguments, String identifier) {
+ this(null, scope, typeArguments, identifier);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public MethodReferenceExpr(TokenRange tokenRange, Expression scope, NodeList<Type> typeArguments, String identifier) {
+ super(tokenRange);
+ setScope(scope);
+ setTypeArguments(typeArguments);
+ setIdentifier(identifier);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getScope() {
+ return scope;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodReferenceExpr setScope(final Expression scope) {
+ assertNotNull(scope);
+ if (scope == this.scope) {
+ return (MethodReferenceExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope);
+ if (this.scope != null)
+ this.scope.setParentNode(null);
+ this.scope = scope;
+ setAsParentNodeOf(scope);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<NodeList<Type>> getTypeArguments() {
+ return Optional.ofNullable(typeArguments);
+ }
+
+ /**
+ * Sets the typeArguments
+ *
+ * @param typeArguments the typeArguments, can be null
+ * @return this, the MethodReferenceExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodReferenceExpr setTypeArguments(final NodeList<Type> typeArguments) {
+ if (typeArguments == this.typeArguments) {
+ return (MethodReferenceExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments);
+ if (this.typeArguments != null)
+ this.typeArguments.setParentNode(null);
+ this.typeArguments = typeArguments;
+ setAsParentNodeOf(typeArguments);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public MethodReferenceExpr setIdentifier(final String identifier) {
+ assertNonEmpty(identifier);
+ if (identifier == this.identifier) {
+ return (MethodReferenceExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.IDENTIFIER, this.identifier, identifier);
+ this.identifier = identifier;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.remove(i);
+ return true;
+ }
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public MethodReferenceExpr clone() {
+ return (MethodReferenceExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public MethodReferenceExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.methodReferenceExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == scope) {
+ setScope((Expression) replacementNode);
+ return true;
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.set(i, (Type) replacementNode);
+ return true;
+ }
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isMethodReferenceExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public MethodReferenceExpr asMethodReferenceExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifMethodReferenceExpr(Consumer<MethodReferenceExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<MethodReferenceExpr> toMethodReferenceExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Name.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Name.java
new file mode 100644
index 000000000..0eeabd3ce
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/Name.java
@@ -0,0 +1,241 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.JavaParser;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithIdentifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.NameMetaModel;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+
+/**
+ * A name that may consist of multiple identifiers.
+ * In other words: it.may.contain.dots.
+ * <p>
+ * The rightmost identifier is "identifier",
+ * The one to the left of it is "qualifier.identifier", etc.
+ * <p>
+ * You can construct one from a String with the name(...) method.
+ *
+ * @author Julio Vilmar Gesser
+ * @see SimpleName
+ */
+public final class Name extends Node implements NodeWithIdentifier<Name>, NodeWithAnnotations<Name> {
+
+ @NonEmptyProperty
+ private String identifier;
+
+ @OptionalProperty
+ private Name qualifier;
+
+ private NodeList<AnnotationExpr> annotations;
+
+ public Name() {
+ this(null, null, "empty", new NodeList<>());
+ }
+
+ public Name(final String identifier) {
+ this(null, null, identifier, new NodeList<>());
+ }
+
+ public Name(Name qualifier, final String identifier) {
+ this(null, qualifier, identifier, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public Name(Name qualifier, final String identifier, NodeList<AnnotationExpr> annotations) {
+ this(null, qualifier, identifier, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public Name(TokenRange tokenRange, Name qualifier, String identifier, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange);
+ setQualifier(qualifier);
+ setIdentifier(identifier);
+ setAnnotations(annotations);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name setIdentifier(final String identifier) {
+ assertNonEmpty(identifier);
+ if (identifier == this.identifier) {
+ return (Name) this;
+ }
+ notifyPropertyChange(ObservableProperty.IDENTIFIER, this.identifier, identifier);
+ this.identifier = identifier;
+ return this;
+ }
+
+ /**
+ * Creates a new {@link Name} from a qualified name.<br>
+ * The qualified name can contains "." (dot) characters.
+ *
+ * @param qualifiedName qualified name
+ * @return instanceof {@link Name}
+ * @deprecated use JavaParser.parseName instead
+ */
+ @Deprecated
+ public static Name parse(String qualifiedName) {
+ assertNonEmpty(qualifiedName);
+ return JavaParser.parseName(qualifiedName);
+ }
+
+ /**
+ * @return the complete qualified name. Only the identifiers and the dots, so no comments or whitespace.
+ */
+ public String asString() {
+ if (qualifier != null) {
+ return qualifier.asString() + "." + identifier;
+ }
+ return identifier;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Name> getQualifier() {
+ return Optional.ofNullable(qualifier);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name setQualifier(final Name qualifier) {
+ if (qualifier == this.qualifier) {
+ return (Name) this;
+ }
+ notifyPropertyChange(ObservableProperty.QUALIFIER, this.qualifier, qualifier);
+ if (this.qualifier != null)
+ this.qualifier.setParentNode(null);
+ this.qualifier = qualifier;
+ setAsParentNodeOf(qualifier);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ if (qualifier != null) {
+ if (node == qualifier) {
+ removeQualifier();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public Name removeQualifier() {
+ return setQualifier((Name) null);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (Name) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public Name clone() {
+ return (Name) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public NameMetaModel getMetaModel() {
+ return JavaParserMetaModel.nameMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ if (qualifier != null) {
+ if (node == qualifier) {
+ setQualifier((Name) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NameExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NameExpr.java
new file mode 100644
index 000000000..d87158983
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NameExpr.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.NameExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration;
+import com.github.javaparser.resolution.types.ResolvedUnionType;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Whenever a SimpleName is used in an expression, it is wrapped in NameExpr.
+ * <br/>In <code>int x = a + 3;</code> a is a SimpleName inside a NameExpr.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class NameExpr extends Expression implements NodeWithSimpleName<NameExpr>, Resolvable<ResolvedValueDeclaration> {
+
+ private SimpleName name;
+
+ public NameExpr() {
+ this(null, new SimpleName());
+ }
+
+ public NameExpr(final String name) {
+ this(null, new SimpleName(name));
+ }
+
+ @AllFieldsConstructor
+ public NameExpr(final SimpleName name) {
+ this(name.getTokenRange().orElse(null), name);
+ setRange(name.getRange().orElse(null));
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public NameExpr(TokenRange tokenRange, SimpleName name) {
+ super(tokenRange);
+ setName(name);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NameExpr setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (NameExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public NameExpr clone() {
+ return (NameExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public NameExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.nameExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isNameExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public NameExpr asNameExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifNameExpr(Consumer<NameExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedValueDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedValueDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<NameExpr> toNameExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NormalAnnotationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NormalAnnotationExpr.java
new file mode 100644
index 000000000..dd0fce54f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NormalAnnotationExpr.java
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.NormalAnnotationExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An annotation that has zero or more key-value pairs.<br/><code>@Mapping(a=5, d=10)</code>
+ * @author Julio Vilmar Gesser
+ */
+public final class NormalAnnotationExpr extends AnnotationExpr {
+
+ private NodeList<MemberValuePair> pairs;
+
+ public NormalAnnotationExpr() {
+ this(null, new Name(), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public NormalAnnotationExpr(final Name name, final NodeList<MemberValuePair> pairs) {
+ this(null, name, pairs);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public NormalAnnotationExpr(TokenRange tokenRange, Name name, NodeList<MemberValuePair> pairs) {
+ super(tokenRange, name);
+ setPairs(pairs);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<MemberValuePair> getPairs() {
+ return pairs;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NormalAnnotationExpr setPairs(final NodeList<MemberValuePair> pairs) {
+ assertNotNull(pairs);
+ if (pairs == this.pairs) {
+ return (NormalAnnotationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.PAIRS, this.pairs, pairs);
+ if (this.pairs != null)
+ this.pairs.setParentNode(null);
+ this.pairs = pairs;
+ setAsParentNodeOf(pairs);
+ return this;
+ }
+
+ /**
+ * adds a pair to this annotation
+ *
+ * @return this, the {@link NormalAnnotationExpr}
+ */
+ public NormalAnnotationExpr addPair(String key, String value) {
+ return addPair(key, new NameExpr(value));
+ }
+
+ /**
+ * adds a pair to this annotation
+ *
+ * @return this, the {@link NormalAnnotationExpr}
+ */
+ public NormalAnnotationExpr addPair(String key, NameExpr value) {
+ MemberValuePair memberValuePair = new MemberValuePair(key, value);
+ getPairs().add(memberValuePair);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < pairs.size(); i++) {
+ if (pairs.get(i) == node) {
+ pairs.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public NormalAnnotationExpr clone() {
+ return (NormalAnnotationExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public NormalAnnotationExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.normalAnnotationExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < pairs.size(); i++) {
+ if (pairs.get(i) == node) {
+ pairs.set(i, (MemberValuePair) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isNormalAnnotationExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public NormalAnnotationExpr asNormalAnnotationExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifNormalAnnotationExpr(Consumer<NormalAnnotationExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<NormalAnnotationExpr> toNormalAnnotationExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NullLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NullLiteralExpr.java
new file mode 100644
index 000000000..b71ed5b80
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/NullLiteralExpr.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.NullLiteralExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A literal "null".
+ * <br/><code>null</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class NullLiteralExpr extends LiteralExpr {
+
+ @AllFieldsConstructor
+ public NullLiteralExpr() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public NullLiteralExpr(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public NullLiteralExpr clone() {
+ return (NullLiteralExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public NullLiteralExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.nullLiteralExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isNullLiteralExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public NullLiteralExpr asNullLiteralExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifNullLiteralExpr(Consumer<NullLiteralExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<NullLiteralExpr> toNullLiteralExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java
new file mode 100644
index 000000000..c4fe045b7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ObjectCreationExpr.java
@@ -0,0 +1,355 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.BodyDeclaration;
+import com.github.javaparser.ast.nodeTypes.NodeWithArguments;
+import com.github.javaparser.ast.nodeTypes.NodeWithOptionalScope;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ObjectCreationExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
+import java.util.function.Consumer;
+
+/**
+ * A constructor call.
+ * <br/>In <code>new HashMap.Entry&lt;String, Long>(15) {public String getKey() {return null;}};</code>
+ * HashMap.Entry is the type, String and Long are type arguments, 15 is an argument, and everything in { }
+ * is the anonymous class body.
+ * <p/>In <code>class B { class C { public void a() { new B().new C(); } } }</code> the scope is <code>new B()</code>
+ * of ObjectCreationExpr <code>new B().new C()</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ObjectCreationExpr extends Expression implements NodeWithTypeArguments<ObjectCreationExpr>, NodeWithType<ObjectCreationExpr, ClassOrInterfaceType>, NodeWithArguments<ObjectCreationExpr>, NodeWithOptionalScope<ObjectCreationExpr> {
+
+ @OptionalProperty
+ private Expression scope;
+
+ private ClassOrInterfaceType type;
+
+ @OptionalProperty
+ private NodeList<Type> typeArguments;
+
+ private NodeList<Expression> arguments;
+
+ @OptionalProperty
+ private NodeList<BodyDeclaration<?>> anonymousClassBody;
+
+ public ObjectCreationExpr() {
+ this(null, null, new ClassOrInterfaceType(), new NodeList<>(), new NodeList<>(), null);
+ }
+
+ /**
+ * Defines a call to a constructor.
+ *
+ * @param scope may be null
+ * @param type this is the class that the constructor is being called for.
+ * @param arguments Any arguments to pass to the constructor
+ */
+ public ObjectCreationExpr(final Expression scope, final ClassOrInterfaceType type, final NodeList<Expression> arguments) {
+ this(null, scope, type, new NodeList<>(), arguments, null);
+ }
+
+ @AllFieldsConstructor
+ public ObjectCreationExpr(final Expression scope, final ClassOrInterfaceType type, final NodeList<Type> typeArguments, final NodeList<Expression> arguments, final NodeList<BodyDeclaration<?>> anonymousClassBody) {
+ this(null, scope, type, typeArguments, arguments, anonymousClassBody);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ObjectCreationExpr(TokenRange tokenRange, Expression scope, ClassOrInterfaceType type, NodeList<Type> typeArguments, NodeList<Expression> arguments, NodeList<BodyDeclaration<?>> anonymousClassBody) {
+ super(tokenRange);
+ setScope(scope);
+ setType(type);
+ setTypeArguments(typeArguments);
+ setArguments(arguments);
+ setAnonymousClassBody(anonymousClassBody);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<NodeList<BodyDeclaration<?>>> getAnonymousClassBody() {
+ return Optional.ofNullable(anonymousClassBody);
+ }
+
+ public void addAnonymousClassBody(BodyDeclaration<?> body) {
+ if (anonymousClassBody == null)
+ anonymousClassBody = new NodeList<>();
+ anonymousClassBody.add(body);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Expression> getArguments() {
+ return arguments;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getScope() {
+ return Optional.ofNullable(scope);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceType getType() {
+ return type;
+ }
+
+ /**
+ * Sets the anonymousClassBody<br>
+ * Null means no class body<br>
+ * Empty NodeList means new ClassName(){ }
+ *
+ * @param anonymousClassBody the anonymousClassBody, can be null or empty
+ * @return this, the ObjectCreationExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ObjectCreationExpr setAnonymousClassBody(final NodeList<BodyDeclaration<?>> anonymousClassBody) {
+ if (anonymousClassBody == this.anonymousClassBody) {
+ return (ObjectCreationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANONYMOUS_CLASS_BODY, this.anonymousClassBody, anonymousClassBody);
+ if (this.anonymousClassBody != null)
+ this.anonymousClassBody.setParentNode(null);
+ this.anonymousClassBody = anonymousClassBody;
+ setAsParentNodeOf(anonymousClassBody);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ObjectCreationExpr setArguments(final NodeList<Expression> arguments) {
+ assertNotNull(arguments);
+ if (arguments == this.arguments) {
+ return (ObjectCreationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.ARGUMENTS, this.arguments, arguments);
+ if (this.arguments != null)
+ this.arguments.setParentNode(null);
+ this.arguments = arguments;
+ setAsParentNodeOf(arguments);
+ return this;
+ }
+
+ /**
+ * Sets the scope
+ *
+ * @param scope the scope, can be null
+ * @return this, the ObjectCreationExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ObjectCreationExpr setScope(final Expression scope) {
+ if (scope == this.scope) {
+ return (ObjectCreationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope);
+ if (this.scope != null)
+ this.scope.setParentNode(null);
+ this.scope = scope;
+ setAsParentNodeOf(scope);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ObjectCreationExpr setType(final ClassOrInterfaceType type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (ObjectCreationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<NodeList<Type>> getTypeArguments() {
+ return Optional.ofNullable(typeArguments);
+ }
+
+ /**
+ * Sets the typeArguments
+ *
+ * @param typeArguments the typeArguments, can be null
+ * @return this, the ObjectCreationExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ObjectCreationExpr setTypeArguments(final NodeList<Type> typeArguments) {
+ if (typeArguments == this.typeArguments) {
+ return (ObjectCreationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments);
+ if (this.typeArguments != null)
+ this.typeArguments.setParentNode(null);
+ this.typeArguments = typeArguments;
+ setAsParentNodeOf(typeArguments);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (anonymousClassBody != null) {
+ for (int i = 0; i < anonymousClassBody.size(); i++) {
+ if (anonymousClassBody.get(i) == node) {
+ anonymousClassBody.remove(i);
+ return true;
+ }
+ }
+ }
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments.get(i) == node) {
+ arguments.remove(i);
+ return true;
+ }
+ }
+ if (scope != null) {
+ if (node == scope) {
+ removeScope();
+ return true;
+ }
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.remove(i);
+ return true;
+ }
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ObjectCreationExpr removeScope() {
+ return setScope((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ObjectCreationExpr clone() {
+ return (ObjectCreationExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ObjectCreationExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.objectCreationExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (anonymousClassBody != null) {
+ for (int i = 0; i < anonymousClassBody.size(); i++) {
+ if (anonymousClassBody.get(i) == node) {
+ anonymousClassBody.set(i, (BodyDeclaration) replacementNode);
+ return true;
+ }
+ }
+ }
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments.get(i) == node) {
+ arguments.set(i, (Expression) replacementNode);
+ return true;
+ }
+ }
+ if (scope != null) {
+ if (node == scope) {
+ setScope((Expression) replacementNode);
+ return true;
+ }
+ }
+ if (node == type) {
+ setType((ClassOrInterfaceType) replacementNode);
+ return true;
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.set(i, (Type) replacementNode);
+ return true;
+ }
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isObjectCreationExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ObjectCreationExpr asObjectCreationExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifObjectCreationExpr(Consumer<ObjectCreationExpr> action) {
+ action.accept(this);
+ }
+
+ public ResolvedConstructorDeclaration resolveInvokedConstructor() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedConstructorDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ObjectCreationExpr> toObjectCreationExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SimpleName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SimpleName.java
new file mode 100644
index 000000000..faaa541cd
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SimpleName.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithIdentifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import com.github.javaparser.metamodel.SimpleNameMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+
+/**
+ * A name that consists of a single identifier.
+ * In other words: it.does.NOT.contain.dots.
+ *
+ * @see Name
+ */
+public final class SimpleName extends Node implements NodeWithIdentifier<SimpleName> {
+
+ @NonEmptyProperty
+ private String identifier;
+
+ public SimpleName() {
+ this(null, "empty");
+ }
+
+ @AllFieldsConstructor
+ public SimpleName(final String identifier) {
+ this(null, identifier);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public SimpleName(TokenRange tokenRange, String identifier) {
+ super(tokenRange);
+ setIdentifier(identifier);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName setIdentifier(final String identifier) {
+ assertNonEmpty(identifier);
+ if (identifier == this.identifier) {
+ return (SimpleName) this;
+ }
+ notifyPropertyChange(ObservableProperty.IDENTIFIER, this.identifier, identifier);
+ this.identifier = identifier;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ public String asString() {
+ return identifier;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public SimpleName clone() {
+ return (SimpleName) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public SimpleNameMetaModel getMetaModel() {
+ return JavaParserMetaModel.simpleNameMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java
new file mode 100644
index 000000000..679c71475
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SingleMemberAnnotationExpr.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.SingleMemberAnnotationExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An annotation that has a single value. <br/><code>@Count(15)</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class SingleMemberAnnotationExpr extends AnnotationExpr {
+
+ private Expression memberValue;
+
+ public SingleMemberAnnotationExpr() {
+ this(null, new Name(), new StringLiteralExpr());
+ }
+
+ @AllFieldsConstructor
+ public SingleMemberAnnotationExpr(final Name name, final Expression memberValue) {
+ this(null, name, memberValue);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public SingleMemberAnnotationExpr(TokenRange tokenRange, Name name, Expression memberValue) {
+ super(tokenRange, name);
+ setMemberValue(memberValue);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getMemberValue() {
+ return memberValue;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SingleMemberAnnotationExpr setMemberValue(final Expression memberValue) {
+ assertNotNull(memberValue);
+ if (memberValue == this.memberValue) {
+ return (SingleMemberAnnotationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.MEMBER_VALUE, this.memberValue, memberValue);
+ if (this.memberValue != null)
+ this.memberValue.setParentNode(null);
+ this.memberValue = memberValue;
+ setAsParentNodeOf(memberValue);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public SingleMemberAnnotationExpr clone() {
+ return (SingleMemberAnnotationExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public SingleMemberAnnotationExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.singleMemberAnnotationExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == memberValue) {
+ setMemberValue((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSingleMemberAnnotationExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SingleMemberAnnotationExpr asSingleMemberAnnotationExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSingleMemberAnnotationExpr(Consumer<SingleMemberAnnotationExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SingleMemberAnnotationExpr> toSingleMemberAnnotationExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/StringLiteralExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/StringLiteralExpr.java
new file mode 100644
index 000000000..a7b4dd541
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/StringLiteralExpr.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.StringLiteralExprMetaModel;
+import com.github.javaparser.utils.StringEscapeUtils;
+import com.github.javaparser.utils.Utils;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A literal string.
+ * <br/><code>"Hello World!"</code>
+ * <br/><code>"\"\n"</code>
+ * <br/><code>"\u2122"</code>
+ * <br/><code>"â„¢"</code>
+ * <br/><code>"💩"</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class StringLiteralExpr extends LiteralStringValueExpr {
+
+ public StringLiteralExpr() {
+ this(null, "empty");
+ }
+
+ /**
+ * Creates a string literal expression from given string. Escapes EOL characters.
+ *
+ * @param value the value of the literal
+ */
+ @AllFieldsConstructor
+ public StringLiteralExpr(final String value) {
+ this(null, Utils.escapeEndOfLines(value));
+ }
+
+ /**
+ * Utility method that creates a new StringLiteralExpr. Escapes EOL characters.
+ *
+ * @deprecated Use {@link #StringLiteralExpr(String)} instead.
+ */
+ @Deprecated
+ public static StringLiteralExpr escape(String string) {
+ return new StringLiteralExpr(Utils.escapeEndOfLines(string));
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public StringLiteralExpr(TokenRange tokenRange, String value) {
+ super(tokenRange, value);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ /**
+ * Sets the content of this expressions to given value. Escapes EOL characters.
+ *
+ * @param value the new literal value
+ * @return self
+ */
+ public StringLiteralExpr setEscapedValue(String value) {
+ this.value = Utils.escapeEndOfLines(value);
+ return this;
+ }
+
+ /**
+ * @return the unescaped literal value
+ */
+ public String asString() {
+ return StringEscapeUtils.unescapeJava(value);
+ }
+
+ /**
+ * Escapes the given string from special characters and uses it as the literal value.
+ *
+ * @param value unescaped string
+ * @return this literal expression
+ */
+ public StringLiteralExpr setString(String value) {
+ this.value = StringEscapeUtils.escapeJava(value);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public StringLiteralExpr clone() {
+ return (StringLiteralExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public StringLiteralExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.stringLiteralExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isStringLiteralExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public StringLiteralExpr asStringLiteralExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifStringLiteralExpr(Consumer<StringLiteralExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<StringLiteralExpr> toStringLiteralExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java
new file mode 100644
index 000000000..2de37fb25
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/SuperExpr.java
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.metamodel.SuperExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+
+/**
+ * An occurrence of the "super" keyword. <br/><code>World.super.greet()</code> is a MethodCallExpr of method name greet,
+ * and scope "World.super" which is a SuperExpr with classExpr "World". <br/><code>super.name</code> is a
+ * FieldAccessExpr of field greet, and a SuperExpr as its scope. The SuperExpr has no classExpr.
+ *
+ * @author Julio Vilmar Gesser
+ * @see com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt
+ * @see ThisExpr
+ */
+public final class SuperExpr extends Expression {
+
+ @OptionalProperty
+ private Expression classExpr;
+
+ public SuperExpr() {
+ this(null, null);
+ }
+
+ @AllFieldsConstructor
+ public SuperExpr(final Expression classExpr) {
+ this(null, classExpr);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public SuperExpr(TokenRange tokenRange, Expression classExpr) {
+ super(tokenRange);
+ setClassExpr(classExpr);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getClassExpr() {
+ return Optional.ofNullable(classExpr);
+ }
+
+ /**
+ * Sets the classExpr
+ *
+ * @param classExpr the classExpr, can be null
+ * @return this, the SuperExpr
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SuperExpr setClassExpr(final Expression classExpr) {
+ if (classExpr == this.classExpr) {
+ return (SuperExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.CLASS_EXPR, this.classExpr, classExpr);
+ if (this.classExpr != null)
+ this.classExpr.setParentNode(null);
+ this.classExpr = classExpr;
+ setAsParentNodeOf(classExpr);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (classExpr != null) {
+ if (node == classExpr) {
+ removeClassExpr();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public SuperExpr removeClassExpr() {
+ return setClassExpr((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public SuperExpr clone() {
+ return (SuperExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public SuperExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.superExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (classExpr != null) {
+ if (node == classExpr) {
+ setClassExpr((Expression) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSuperExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SuperExpr asSuperExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSuperExpr(Consumer<SuperExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SuperExpr> toSuperExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ThisExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ThisExpr.java
new file mode 100644
index 000000000..dc9981d82
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/ThisExpr.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.body.TypeDeclaration;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.metamodel.ThisExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedTypeDeclaration;
+import java.util.function.Consumer;
+
+/**
+ * An occurrence of the "this" keyword. <br/><code>World.this.greet()</code> is a MethodCallExpr of method name greet,
+ * and scope "World.super" which is a ThisExpr with classExpr "World". <br/><code>this.name</code> is a
+ * FieldAccessExpr of field greet, and a ThisExpr as its scope. The ThisExpr has no classExpr.
+ *
+ * @author Julio Vilmar Gesser
+ * @see com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt
+ * @see ThisExpr
+ */
+public final class ThisExpr extends Expression implements Resolvable<ResolvedTypeDeclaration> {
+
+ @OptionalProperty
+ private Expression classExpr;
+
+ public ThisExpr() {
+ this(null, null);
+ }
+
+ @AllFieldsConstructor
+ public ThisExpr(final Expression classExpr) {
+ this(null, classExpr);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ThisExpr(TokenRange tokenRange, Expression classExpr) {
+ super(tokenRange);
+ setClassExpr(classExpr);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getClassExpr() {
+ return Optional.ofNullable(classExpr);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ThisExpr setClassExpr(final Expression classExpr) {
+ if (classExpr == this.classExpr) {
+ return (ThisExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.CLASS_EXPR, this.classExpr, classExpr);
+ if (this.classExpr != null)
+ this.classExpr.setParentNode(null);
+ this.classExpr = classExpr;
+ setAsParentNodeOf(classExpr);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (classExpr != null) {
+ if (node == classExpr) {
+ removeClassExpr();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ThisExpr removeClassExpr() {
+ return setClassExpr((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ThisExpr clone() {
+ return (ThisExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ThisExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.thisExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (classExpr != null) {
+ if (node == classExpr) {
+ setClassExpr((Expression) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isThisExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ThisExpr asThisExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifThisExpr(Consumer<ThisExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedTypeDeclaration resolve() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedTypeDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ThisExpr> toThisExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TypeExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TypeExpr.java
new file mode 100644
index 000000000..3d74b6eea
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/TypeExpr.java
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.TypeExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * This class is just instantiated as scopes for MethodReferenceExpr nodes to encapsulate Types.
+ * <br/>In <code>World::greet</code> the ClassOrInterfaceType "World" is wrapped in a TypeExpr
+ * before it is set as the scope of the MethodReferenceExpr.
+ *
+ * @author Raquel Pau
+ */
+public final class TypeExpr extends Expression implements NodeWithType<TypeExpr, Type> {
+
+ private Type type;
+
+ public TypeExpr() {
+ this(null, new ClassOrInterfaceType());
+ }
+
+ @AllFieldsConstructor
+ public TypeExpr(Type type) {
+ this(null, type);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public TypeExpr(TokenRange tokenRange, Type type) {
+ super(tokenRange);
+ setType(type);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public TypeExpr setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (TypeExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public TypeExpr clone() {
+ return (TypeExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public TypeExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.typeExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isTypeExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public TypeExpr asTypeExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifTypeExpr(Consumer<TypeExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<TypeExpr> toTypeExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/UnaryExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/UnaryExpr.java
new file mode 100644
index 000000000..4008544d9
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/UnaryExpr.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.nodeTypes.NodeWithExpression;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.DerivedProperty;
+import com.github.javaparser.metamodel.UnaryExprMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.printer.Printable;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An expression where an operator is applied to a single expression.
+ * It supports the operators that are found the the UnaryExpr.Operator enum.
+ * <br/><code>11++</code>
+ * <br/><code>++11</code>
+ * <br/><code>~1</code>
+ * <br/><code>-333</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class UnaryExpr extends Expression implements NodeWithExpression<UnaryExpr> {
+
+ public enum Operator implements Printable {
+
+ PLUS("+", false),
+ MINUS("-", false),
+ PREFIX_INCREMENT("++", false),
+ PREFIX_DECREMENT("--", false),
+ LOGICAL_COMPLEMENT("!", false),
+ BITWISE_COMPLEMENT("~", false),
+ POSTFIX_INCREMENT("++", true),
+ POSTFIX_DECREMENT("--", true);
+
+ private final String codeRepresentation;
+
+ private final boolean isPostfix;
+
+ Operator(String codeRepresentation, boolean isPostfix) {
+ this.codeRepresentation = codeRepresentation;
+ this.isPostfix = isPostfix;
+ }
+
+ public String asString() {
+ return codeRepresentation;
+ }
+
+ public boolean isPostfix() {
+ return isPostfix;
+ }
+
+ public boolean isPrefix() {
+ return !isPostfix();
+ }
+ }
+
+ private Expression expression;
+
+ private Operator operator;
+
+ public UnaryExpr() {
+ this(null, new IntegerLiteralExpr(), Operator.POSTFIX_INCREMENT);
+ }
+
+ @AllFieldsConstructor
+ public UnaryExpr(final Expression expression, final Operator operator) {
+ this(null, expression, operator);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public UnaryExpr(TokenRange tokenRange, Expression expression, Operator operator) {
+ super(tokenRange);
+ setExpression(expression);
+ setOperator(operator);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getExpression() {
+ return expression;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Operator getOperator() {
+ return operator;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public UnaryExpr setExpression(final Expression expression) {
+ assertNotNull(expression);
+ if (expression == this.expression) {
+ return (UnaryExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression);
+ if (this.expression != null)
+ this.expression.setParentNode(null);
+ this.expression = expression;
+ setAsParentNodeOf(expression);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public UnaryExpr setOperator(final Operator operator) {
+ assertNotNull(operator);
+ if (operator == this.operator) {
+ return (UnaryExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.OPERATOR, this.operator, operator);
+ this.operator = operator;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @DerivedProperty
+ public boolean isPostfix() {
+ return operator.isPostfix();
+ }
+
+ @DerivedProperty
+ public boolean isPrefix() {
+ return !isPostfix();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public UnaryExpr clone() {
+ return (UnaryExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public UnaryExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.unaryExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == expression) {
+ setExpression((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isUnaryExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public UnaryExpr asUnaryExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifUnaryExpr(Consumer<UnaryExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<UnaryExpr> toUnaryExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/expr/VariableDeclarationExpr.java b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/VariableDeclarationExpr.java
new file mode 100644
index 000000000..8745ce72b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/expr/VariableDeclarationExpr.java
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.expr;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.VariableDeclarator;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithVariables;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithFinalModifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import com.github.javaparser.metamodel.VariableDeclarationExprMetaModel;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.stream.Collectors;
+import static com.github.javaparser.ast.NodeList.nodeList;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A declaration of variables.
+ * It is an expression, so it can be put in places like the initializer of a for loop,
+ * or the resources part of the try statement.
+ * <br/><code>final int x=3, y=55</code>
+ *
+ * <br/>All annotations preceding the type will be set on this object, not on the type.
+ * JavaParser doesn't know if it they are applicable to the method or the type.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class VariableDeclarationExpr extends Expression implements NodeWithFinalModifier<VariableDeclarationExpr>, NodeWithAnnotations<VariableDeclarationExpr>, NodeWithVariables<VariableDeclarationExpr> {
+
+ private EnumSet<Modifier> modifiers;
+
+ private NodeList<AnnotationExpr> annotations;
+
+ @NonEmptyProperty
+ private NodeList<VariableDeclarator> variables;
+
+ public VariableDeclarationExpr() {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), new NodeList<>());
+ }
+
+ public VariableDeclarationExpr(final Type type, String variableName) {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), nodeList(new VariableDeclarator(type, variableName)));
+ }
+
+ public VariableDeclarationExpr(VariableDeclarator var) {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), nodeList(var));
+ }
+
+ public VariableDeclarationExpr(final Type type, String variableName, Modifier... modifiers) {
+ this(null, Arrays.stream(modifiers).collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), new NodeList<>(), nodeList(new VariableDeclarator(type, variableName)));
+ }
+
+ public VariableDeclarationExpr(VariableDeclarator var, Modifier... modifiers) {
+ this(null, Arrays.stream(modifiers).collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))), new NodeList<>(), nodeList(var));
+ }
+
+ public VariableDeclarationExpr(final NodeList<VariableDeclarator> variables) {
+ this(null, EnumSet.noneOf(Modifier.class), new NodeList<>(), variables);
+ }
+
+ public VariableDeclarationExpr(final EnumSet<Modifier> modifiers, final NodeList<VariableDeclarator> variables) {
+ this(null, modifiers, new NodeList<>(), variables);
+ }
+
+ @AllFieldsConstructor
+ public VariableDeclarationExpr(final EnumSet<Modifier> modifiers, final NodeList<AnnotationExpr> annotations, final NodeList<VariableDeclarator> variables) {
+ this(null, modifiers, annotations, variables);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public VariableDeclarationExpr(TokenRange tokenRange, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations, NodeList<VariableDeclarator> variables) {
+ super(tokenRange);
+ setModifiers(modifiers);
+ setAnnotations(annotations);
+ setVariables(variables);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ /**
+ * Return the modifiers of this variable declaration.
+ *
+ * @return modifiers
+ * @see Modifier
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumSet<Modifier> getModifiers() {
+ return modifiers;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<VariableDeclarator> getVariables() {
+ return variables;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public VariableDeclarationExpr setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (VariableDeclarationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public VariableDeclarationExpr setModifiers(final EnumSet<Modifier> modifiers) {
+ assertNotNull(modifiers);
+ if (modifiers == this.modifiers) {
+ return (VariableDeclarationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers);
+ this.modifiers = modifiers;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public VariableDeclarationExpr setVariables(final NodeList<VariableDeclarator> variables) {
+ assertNotNull(variables);
+ if (variables == this.variables) {
+ return (VariableDeclarationExpr) this;
+ }
+ notifyPropertyChange(ObservableProperty.VARIABLES, this.variables, variables);
+ if (this.variables != null)
+ this.variables.setParentNode(null);
+ this.variables = variables;
+ setAsParentNodeOf(variables);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < variables.size(); i++) {
+ if (variables.get(i) == node) {
+ variables.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public VariableDeclarationExpr clone() {
+ return (VariableDeclarationExpr) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public VariableDeclarationExprMetaModel getMetaModel() {
+ return JavaParserMetaModel.variableDeclarationExprMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < variables.size(); i++) {
+ if (variables.get(i) == node) {
+ variables.set(i, (VariableDeclarator) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isVariableDeclarationExpr() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public VariableDeclarationExpr asVariableDeclarationExpr() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifVariableDeclarationExpr(Consumer<VariableDeclarationExpr> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<VariableDeclarationExpr> toVariableDeclarationExpr() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDeclaration.java
new file mode 100644
index 000000000..547c2ccf7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleDeclaration.java
@@ -0,0 +1,200 @@
+package com.github.javaparser.ast.modules;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ModuleDeclarationMetaModel;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+
+/**
+ * A Java 9 Jigsaw module declaration. <code>@Foo module com.github.abc { requires a.B; }</code>
+ */
+public final class ModuleDeclaration extends Node implements NodeWithName<ModuleDeclaration>, NodeWithAnnotations<ModuleDeclaration> {
+
+ private Name name;
+
+ private NodeList<AnnotationExpr> annotations;
+
+ private boolean isOpen;
+
+ private NodeList<ModuleStmt> moduleStmts;
+
+ public ModuleDeclaration() {
+ this(null, new NodeList<>(), new Name(), false, new NodeList<>());
+ }
+
+ public ModuleDeclaration(Name name, boolean isOpen) {
+ this(null, new NodeList<>(), name, isOpen, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ModuleDeclaration(NodeList<AnnotationExpr> annotations, Name name, boolean isOpen, NodeList<ModuleStmt> moduleStmts) {
+ this(null, annotations, name, isOpen, moduleStmts);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ModuleDeclaration(TokenRange tokenRange, NodeList<AnnotationExpr> annotations, Name name, boolean isOpen, NodeList<ModuleStmt> moduleStmts) {
+ super(tokenRange);
+ setAnnotations(annotations);
+ setName(name);
+ setOpen(isOpen);
+ setModuleStmts(moduleStmts);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleDeclaration setName(final Name name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (ModuleDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleDeclaration setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (ModuleDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < moduleStmts.size(); i++) {
+ if (moduleStmts.get(i) == node) {
+ moduleStmts.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean isOpen() {
+ return isOpen;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleDeclaration setOpen(final boolean isOpen) {
+ if (isOpen == this.isOpen) {
+ return (ModuleDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.OPEN, this.isOpen, isOpen);
+ this.isOpen = isOpen;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ModuleStmt> getModuleStmts() {
+ return moduleStmts;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleDeclaration setModuleStmts(final NodeList<ModuleStmt> moduleStmts) {
+ assertNotNull(moduleStmts);
+ if (moduleStmts == this.moduleStmts) {
+ return (ModuleDeclaration) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODULE_STMTS, this.moduleStmts, moduleStmts);
+ if (this.moduleStmts != null)
+ this.moduleStmts.setParentNode(null);
+ this.moduleStmts = moduleStmts;
+ setAsParentNodeOf(moduleStmts);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ModuleDeclaration clone() {
+ return (ModuleDeclaration) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ModuleDeclarationMetaModel getMetaModel() {
+ return JavaParserMetaModel.moduleDeclarationMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < moduleStmts.size(); i++) {
+ if (moduleStmts.get(i) == node) {
+ moduleStmts.set(i, (ModuleStmt) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((Name) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsStmt.java
new file mode 100644
index 000000000..61440b1a7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleExportsStmt.java
@@ -0,0 +1,164 @@
+package com.github.javaparser.ast.modules;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ModuleExportsStmtMetaModel;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+public final class ModuleExportsStmt extends ModuleStmt implements NodeWithName<ModuleExportsStmt> {
+
+ private Name name;
+
+ private NodeList<Name> moduleNames;
+
+ public ModuleExportsStmt() {
+ this(null, new Name(), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ModuleExportsStmt(Name name, NodeList<Name> moduleNames) {
+ this(null, name, moduleNames);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ModuleExportsStmt(TokenRange tokenRange, Name name, NodeList<Name> moduleNames) {
+ super(tokenRange);
+ setName(name);
+ setModuleNames(moduleNames);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < moduleNames.size(); i++) {
+ if (moduleNames.get(i) == node) {
+ moduleNames.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleExportsStmt setName(final Name name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (ModuleExportsStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Name> getModuleNames() {
+ return moduleNames;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleExportsStmt setModuleNames(final NodeList<Name> moduleNames) {
+ assertNotNull(moduleNames);
+ if (moduleNames == this.moduleNames) {
+ return (ModuleExportsStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODULE_NAMES, this.moduleNames, moduleNames);
+ if (this.moduleNames != null)
+ this.moduleNames.setParentNode(null);
+ this.moduleNames = moduleNames;
+ setAsParentNodeOf(moduleNames);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ModuleExportsStmt clone() {
+ return (ModuleExportsStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ModuleExportsStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.moduleExportsStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < moduleNames.size(); i++) {
+ if (moduleNames.get(i) == node) {
+ moduleNames.set(i, (Name) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((Name) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleExportsStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleExportsStmt asModuleExportsStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleExportsStmt(Consumer<ModuleExportsStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleExportsStmt> toModuleExportsStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensStmt.java
new file mode 100644
index 000000000..25565dadd
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleOpensStmt.java
@@ -0,0 +1,164 @@
+package com.github.javaparser.ast.modules;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ModuleOpensStmtMetaModel;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+public final class ModuleOpensStmt extends ModuleStmt implements NodeWithName<ModuleOpensStmt> {
+
+ private Name name;
+
+ private NodeList<Name> moduleNames;
+
+ public ModuleOpensStmt() {
+ this(null, new Name(), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ModuleOpensStmt(Name name, NodeList<Name> moduleNames) {
+ this(null, name, moduleNames);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ModuleOpensStmt(TokenRange tokenRange, Name name, NodeList<Name> moduleNames) {
+ super(tokenRange);
+ setName(name);
+ setModuleNames(moduleNames);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < moduleNames.size(); i++) {
+ if (moduleNames.get(i) == node) {
+ moduleNames.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleOpensStmt setName(final Name name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (ModuleOpensStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Name> getModuleNames() {
+ return moduleNames;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleOpensStmt setModuleNames(final NodeList<Name> moduleNames) {
+ assertNotNull(moduleNames);
+ if (moduleNames == this.moduleNames) {
+ return (ModuleOpensStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODULE_NAMES, this.moduleNames, moduleNames);
+ if (this.moduleNames != null)
+ this.moduleNames.setParentNode(null);
+ this.moduleNames = moduleNames;
+ setAsParentNodeOf(moduleNames);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ModuleOpensStmt clone() {
+ return (ModuleOpensStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ModuleOpensStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.moduleOpensStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < moduleNames.size(); i++) {
+ if (moduleNames.get(i) == node) {
+ moduleNames.set(i, (Name) replacementNode);
+ return true;
+ }
+ }
+ if (node == name) {
+ setName((Name) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleOpensStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleOpensStmt asModuleOpensStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleOpensStmt(Consumer<ModuleOpensStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleOpensStmt> toModuleOpensStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesStmt.java
new file mode 100644
index 000000000..4ddbced06
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleProvidesStmt.java
@@ -0,0 +1,165 @@
+package com.github.javaparser.ast.modules;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ModuleProvidesStmtMetaModel;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+public final class ModuleProvidesStmt extends ModuleStmt implements NodeWithType<ModuleProvidesStmt, Type> {
+
+ private Type type;
+
+ private NodeList<Type> withTypes;
+
+ public ModuleProvidesStmt() {
+ this(null, new ClassOrInterfaceType(), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ModuleProvidesStmt(Type type, NodeList<Type> withTypes) {
+ this(null, type, withTypes);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ModuleProvidesStmt(TokenRange tokenRange, Type type, NodeList<Type> withTypes) {
+ super(tokenRange);
+ setType(type);
+ setWithTypes(withTypes);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < withTypes.size(); i++) {
+ if (withTypes.get(i) == node) {
+ withTypes.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleProvidesStmt setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (ModuleProvidesStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Type> getWithTypes() {
+ return withTypes;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleProvidesStmt setWithTypes(final NodeList<Type> withTypes) {
+ assertNotNull(withTypes);
+ if (withTypes == this.withTypes) {
+ return (ModuleProvidesStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.WITH_TYPES, this.withTypes, withTypes);
+ if (this.withTypes != null)
+ this.withTypes.setParentNode(null);
+ this.withTypes = withTypes;
+ setAsParentNodeOf(withTypes);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ModuleProvidesStmt clone() {
+ return (ModuleProvidesStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ModuleProvidesStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.moduleProvidesStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ for (int i = 0; i < withTypes.size(); i++) {
+ if (withTypes.get(i) == node) {
+ withTypes.set(i, (Type) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleProvidesStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleProvidesStmt asModuleProvidesStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleProvidesStmt(Consumer<ModuleProvidesStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleProvidesStmt> toModuleProvidesStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresStmt.java
new file mode 100644
index 000000000..cede81c2d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleRequiresStmt.java
@@ -0,0 +1,161 @@
+package com.github.javaparser.ast.modules;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.nodeTypes.NodeWithName;
+import com.github.javaparser.ast.nodeTypes.modifiers.NodeWithStaticModifier;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ModuleRequiresStmtMetaModel;
+import java.util.EnumSet;
+import static com.github.javaparser.ast.Modifier.TRANSITIVE;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A require statement in module-info.java. <code>require a.b.C;</code>
+ */
+public final class ModuleRequiresStmt extends ModuleStmt implements NodeWithStaticModifier<ModuleRequiresStmt>, NodeWithName<ModuleRequiresStmt> {
+
+ private EnumSet<Modifier> modifiers;
+
+ private Name name;
+
+ public ModuleRequiresStmt() {
+ this(null, EnumSet.noneOf(Modifier.class), new Name());
+ }
+
+ @AllFieldsConstructor
+ public ModuleRequiresStmt(EnumSet<Modifier> modifiers, Name name) {
+ this(null, modifiers, name);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ModuleRequiresStmt(TokenRange tokenRange, EnumSet<Modifier> modifiers, Name name) {
+ super(tokenRange);
+ setModifiers(modifiers);
+ setName(name);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public EnumSet<Modifier> getModifiers() {
+ return modifiers;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleRequiresStmt setModifiers(final EnumSet<Modifier> modifiers) {
+ assertNotNull(modifiers);
+ if (modifiers == this.modifiers) {
+ return (ModuleRequiresStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.MODIFIERS, this.modifiers, modifiers);
+ this.modifiers = modifiers;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Name getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleRequiresStmt setName(final Name name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (ModuleRequiresStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ public boolean isTransitive() {
+ return getModifiers().contains(TRANSITIVE);
+ }
+
+ public ModuleRequiresStmt setTransitive(boolean set) {
+ return setModifier(TRANSITIVE, set);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ModuleRequiresStmt clone() {
+ return (ModuleRequiresStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ModuleRequiresStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.moduleRequiresStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((Name) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleRequiresStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleRequiresStmt asModuleRequiresStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleRequiresStmt(Consumer<ModuleRequiresStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleRequiresStmt> toModuleRequiresStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleStmt.java
new file mode 100644
index 000000000..176c791b8
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleStmt.java
@@ -0,0 +1,152 @@
+package com.github.javaparser.ast.modules;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ModuleStmtMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+import java.util.Optional;
+
+public abstract class ModuleStmt extends Node {
+
+ @AllFieldsConstructor
+ public ModuleStmt() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ModuleStmt(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ModuleStmt clone() {
+ return (ModuleStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ModuleStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.moduleStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleExportsStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleExportsStmt asModuleExportsStmt() {
+ throw new IllegalStateException(f("%s is not an ModuleExportsStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleOpensStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleOpensStmt asModuleOpensStmt() {
+ throw new IllegalStateException(f("%s is not an ModuleOpensStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleProvidesStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleProvidesStmt asModuleProvidesStmt() {
+ throw new IllegalStateException(f("%s is not an ModuleProvidesStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleRequiresStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleRequiresStmt asModuleRequiresStmt() {
+ throw new IllegalStateException(f("%s is not an ModuleRequiresStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleUsesStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleUsesStmt asModuleUsesStmt() {
+ throw new IllegalStateException(f("%s is not an ModuleUsesStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleExportsStmt(Consumer<ModuleExportsStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleOpensStmt(Consumer<ModuleOpensStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleProvidesStmt(Consumer<ModuleProvidesStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleRequiresStmt(Consumer<ModuleRequiresStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleUsesStmt(Consumer<ModuleUsesStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleExportsStmt> toModuleExportsStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleOpensStmt> toModuleOpensStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleProvidesStmt> toModuleProvidesStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleRequiresStmt> toModuleRequiresStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleUsesStmt> toModuleUsesStmt() {
+ return Optional.empty();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesStmt.java
new file mode 100644
index 000000000..2bf985601
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/modules/ModuleUsesStmt.java
@@ -0,0 +1,127 @@
+package com.github.javaparser.ast.modules;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ModuleUsesStmtMetaModel;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+public final class ModuleUsesStmt extends ModuleStmt implements NodeWithType<ModuleUsesStmt, Type> {
+
+ private Type type;
+
+ public ModuleUsesStmt() {
+ this(null);
+ }
+
+ @AllFieldsConstructor
+ public ModuleUsesStmt(Type type) {
+ this(null, type);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ModuleUsesStmt(TokenRange tokenRange, Type type) {
+ super(tokenRange);
+ setType(type);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getType() {
+ return type;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ModuleUsesStmt setType(final Type type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (ModuleUsesStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ if (this.type != null)
+ this.type.setParentNode(null);
+ this.type = type;
+ setAsParentNodeOf(type);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ModuleUsesStmt clone() {
+ return (ModuleUsesStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ModuleUsesStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.moduleUsesStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == type) {
+ setType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isModuleUsesStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ModuleUsesStmt asModuleUsesStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifModuleUsesStmt(Consumer<ModuleUsesStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ModuleUsesStmt> toModuleUsesStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java
new file mode 100644
index 000000000..72060c612
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithAnnotations.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.*;
+
+import java.lang.annotation.Annotation;
+import java.util.Optional;
+
+import static com.github.javaparser.JavaParser.parseExpression;
+import static com.github.javaparser.JavaParser.parseName;
+
+/**
+ * A node that can be annotated.
+ *
+ * @author Federico Tomassetti
+ * @since July 2014
+ */
+public interface NodeWithAnnotations<N extends Node> {
+ NodeList<AnnotationExpr> getAnnotations();
+
+ N setAnnotations(NodeList<AnnotationExpr> annotations);
+
+ void tryAddImportToParentCompilationUnit(Class<?> clazz);
+
+ default AnnotationExpr getAnnotation(int i) {
+ return getAnnotations().get(i);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setAnnotation(int i, AnnotationExpr element) {
+ getAnnotations().set(i, element);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addAnnotation(AnnotationExpr element) {
+ getAnnotations().add(element);
+ return (N) this;
+ }
+
+ /**
+ * Annotates this
+ *
+ * @param name the name of the annotation
+ * @return this
+ */
+ @SuppressWarnings("unchecked")
+ default N addAnnotation(String name) {
+ NormalAnnotationExpr annotation = new NormalAnnotationExpr(
+ parseName(name), new NodeList<>());
+ getAnnotations().add(annotation);
+ return (N) this;
+ }
+
+ /**
+ * Annotates this
+ *
+ * @param name the name of the annotation
+ * @return the {@link NormalAnnotationExpr} added
+ */
+ @SuppressWarnings("unchecked")
+ default NormalAnnotationExpr addAndGetAnnotation(String name) {
+ NormalAnnotationExpr annotation = new NormalAnnotationExpr(
+ parseName(name), new NodeList<>());
+ getAnnotations().add(annotation);
+ return annotation;
+ }
+
+ /**
+ * Annotates this node and automatically add the import
+ *
+ * @param clazz the class of the annotation
+ * @return this
+ */
+ default N addAnnotation(Class<? extends Annotation> clazz) {
+ tryAddImportToParentCompilationUnit(clazz);
+ return addAnnotation(clazz.getSimpleName());
+ }
+
+ /**
+ * Annotates this node and automatically add the import
+ *
+ * @param clazz the class of the annotation
+ * @return the {@link NormalAnnotationExpr} added
+ */
+ default NormalAnnotationExpr addAndGetAnnotation(Class<? extends Annotation> clazz) {
+ tryAddImportToParentCompilationUnit(clazz);
+ return addAndGetAnnotation(clazz.getSimpleName());
+ }
+
+ /**
+ * Annotates this with a marker annotation
+ *
+ * @param name the name of the annotation
+ * @return this
+ */
+ @SuppressWarnings("unchecked")
+ default N addMarkerAnnotation(String name) {
+ MarkerAnnotationExpr markerAnnotationExpr = new MarkerAnnotationExpr(
+ parseName(name));
+ getAnnotations().add(markerAnnotationExpr);
+ return (N) this;
+ }
+
+ /**
+ * Annotates this with a marker annotation and automatically add the import
+ *
+ * @param clazz the class of the annotation
+ * @return this
+ */
+ default N addMarkerAnnotation(Class<? extends Annotation> clazz) {
+ tryAddImportToParentCompilationUnit(clazz);
+ return addMarkerAnnotation(clazz.getSimpleName());
+ }
+
+ /**
+ * Annotates this with a single member annotation
+ *
+ * @param name the name of the annotation
+ * @param expression the part between ()
+ * @return this
+ */
+ @SuppressWarnings("unchecked")
+ default N addSingleMemberAnnotation(String name, Expression expression) {
+ SingleMemberAnnotationExpr singleMemberAnnotationExpr = new SingleMemberAnnotationExpr(
+ parseName(name), expression);
+ getAnnotations().add(singleMemberAnnotationExpr);
+ return (N) this;
+ }
+
+ /**
+ * Annotates this with a single member annotation
+ *
+ * @param name the name of the annotation
+ * @param value the value, don't forget to add \"\" for a string value
+ * @return this
+ */
+ default N addSingleMemberAnnotation(String name, String value) {
+ return addSingleMemberAnnotation(name, parseExpression(value));
+ }
+
+ /**
+ * Annotates this with a single member annotation and automatically add the import
+ *
+ * @param clazz the class of the annotation
+ * @param value the value, don't forget to add \"\" for a string value
+ * @return this
+ */
+ default N addSingleMemberAnnotation(Class<? extends Annotation> clazz,
+ String value) {
+ tryAddImportToParentCompilationUnit(clazz);
+ return addSingleMemberAnnotation(clazz.getSimpleName(), value);
+ }
+
+ /**
+ * Check whether an annotation with this name is present on this element
+ *
+ * @param annotationName the name of the annotation
+ * @return true if found, false if not
+ */
+ default boolean isAnnotationPresent(String annotationName) {
+ return getAnnotations().stream().anyMatch(a -> a.getName().getIdentifier().equals(annotationName));
+ }
+
+ /**
+ * Check whether an annotation with this class is present on this element
+ *
+ * @param annotationClass the class of the annotation
+ * @return true if found, false if not
+ */
+ default boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
+ return isAnnotationPresent(annotationClass.getSimpleName());
+ }
+
+ /**
+ * Try to find an annotation by its name
+ *
+ * @param annotationName the name of the annotation
+ */
+ default Optional<AnnotationExpr> getAnnotationByName(String annotationName) {
+ return getAnnotations().stream().filter(a -> a.getName().getIdentifier().equals(annotationName)).findFirst();
+ }
+
+ /**
+ * Try to find an annotation by its class
+ *
+ * @param annotationClass the class of the annotation
+ */
+ default Optional<AnnotationExpr> getAnnotationByClass(Class<? extends Annotation> annotationClass) {
+ return getAnnotationByName(annotationClass.getSimpleName());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java
new file mode 100644
index 000000000..702707ca1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithArguments.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.Expression;
+
+import static com.github.javaparser.JavaParser.parseExpression;
+
+/**
+ * A node with arguments.
+ */
+public interface NodeWithArguments<N extends Node> {
+ N setArguments(NodeList<Expression> arguments);
+
+ NodeList<Expression> getArguments();
+
+ default Expression getArgument(int i) {
+ return getArguments().get(i);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addArgument(String arg) {
+ return addArgument(parseExpression(arg));
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addArgument(Expression arg) {
+ getArguments().add(arg);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setArgument(int i, Expression arg) {
+ getArguments().set(i, arg);
+ return (N) this;
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java
new file mode 100644
index 000000000..a23e3e266
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBlockStmt.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.stmt.BlockStmt;
+
+/**
+ * A node with a body that is a BlockStmt.
+ */
+public interface NodeWithBlockStmt<N extends Node> {
+ BlockStmt getBody();
+
+ N setBody(BlockStmt block);
+
+ default BlockStmt createBody() {
+ BlockStmt block = new BlockStmt();
+ setBody(block);
+ return block;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBody.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBody.java
new file mode 100644
index 000000000..2388824af
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithBody.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.stmt.Statement;
+
+public interface NodeWithBody<N extends Node> {
+ Statement getBody();
+
+ N setBody(final Statement body);
+
+ default BlockStmt createBlockStatementAsBody() {
+ BlockStmt b = new BlockStmt();
+ setBody(b);
+ return b;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java
new file mode 100644
index 000000000..4113f8b69
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithCondition.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Expression;
+
+public interface NodeWithCondition<N extends Node> {
+ Expression getCondition();
+
+ N setCondition(Expression condition);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java
new file mode 100644
index 000000000..b2f2507ee
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithConstructors.java
@@ -0,0 +1,71 @@
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.body.ConstructorDeclaration;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Optional;
+
+import static java.util.Collections.unmodifiableList;
+import static java.util.stream.Collectors.toCollection;
+import static java.util.stream.Collectors.toList;
+
+public interface NodeWithConstructors<N extends Node> extends NodeWithSimpleName<N>, NodeWithMembers<N> {
+ /**
+ * Try to find a {@link ConstructorDeclaration} with no parameters by its name
+ *
+ * @return the constructors found (multiple in case of polymorphism)
+ */
+ default Optional<ConstructorDeclaration> getDefaultConstructor() {
+ return getMembers().stream().filter(bd -> bd instanceof ConstructorDeclaration).map(bd -> (ConstructorDeclaration) bd).filter(cd -> cd.getParameters().isEmpty()).findFirst();
+ }
+
+ /**
+ * Adds a constructor to this
+ *
+ * @param modifiers the modifiers like {@link Modifier#PUBLIC}
+ * @return the created constructor
+ */
+ default ConstructorDeclaration addConstructor(Modifier... modifiers) {
+ ConstructorDeclaration constructorDeclaration = new ConstructorDeclaration();
+ constructorDeclaration.setModifiers(Arrays.stream(modifiers).collect(toCollection(() -> EnumSet.noneOf(Modifier.class))));
+ constructorDeclaration.setName(getName());
+ getMembers().add(constructorDeclaration);
+ return constructorDeclaration;
+ }
+
+ /**
+ * Find all constructors for this class.
+ *
+ * @return the constructors found. This list is immutable.
+ */
+ default List<ConstructorDeclaration> getConstructors() {
+ return unmodifiableList(getMembers().stream().filter(m -> m instanceof ConstructorDeclaration).map(m -> (ConstructorDeclaration) m).collect(toList()));
+ }
+
+ /**
+ * Try to find a {@link ConstructorDeclaration} by its parameters types
+ *
+ * @param paramTypes the types of parameters like "Map&lt;Integer,String&gt;","int" to match<br> void
+ * foo(Map&lt;Integer,String&gt; myMap,int number)
+ * @return the constructor found (multiple in case of overloading)
+ */
+ default Optional<ConstructorDeclaration> getConstructorByParameterTypes(String... paramTypes) {
+ return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst();
+ }
+
+ /**
+ * Try to find a {@link ConstructorDeclaration} by its parameters types
+ *
+ * @param paramTypes the types of parameters like "Map&lt;Integer,String&gt;","int" to match<br> void
+ * foo(Map&lt;Integer,String&gt; myMap,int number)
+ * @return the constructors found (multiple in case of overloading)
+ */
+ default Optional<ConstructorDeclaration> getConstructorByParameterTypes(Class<?>... paramTypes) {
+ return getConstructors().stream().filter(m -> m.hasParametersOfType(paramTypes)).findFirst();
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java
new file mode 100644
index 000000000..d490ed158
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithDeclaration.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+/**
+ * Node with a declaration representable as a String.
+ *
+ * @author Federico Tomassetti
+ * @since July 2014
+ */
+public interface NodeWithDeclaration {
+
+ /**
+ * As {@link NodeWithDeclaration#getDeclarationAsString(boolean, boolean, boolean)} including
+ * the modifiers, the throws clause and the parameters with both type and name.
+ *
+ * @return String representation of declaration
+ */
+ String getDeclarationAsString();
+
+ /**
+ * As {@link NodeWithDeclaration#getDeclarationAsString(boolean, boolean, boolean)} including
+ * the parameters with both type and name.
+ *
+ * @param includingModifiers flag to include the modifiers (if present) in the string produced
+ * @param includingThrows flag to include the throws clause (if present) in the string produced
+ * @return String representation of declaration based on parameter flags
+ */
+ String getDeclarationAsString(boolean includingModifiers, boolean includingThrows);
+
+ /**
+ * A simple representation of the element declaration.
+ * It should fit one string.
+ *
+ * @param includingModifiers flag to include the modifiers (if present) in the string produced
+ * @param includingThrows flag to include the throws clause (if present) in the string produced
+ * @param includingParameterName flag to include the parameter name (while the parameter type is always included) in
+ * the string produced
+ * @return String representation of declaration based on parameter flags
+ */
+ String getDeclarationAsString(boolean includingModifiers, boolean includingThrows, boolean includingParameterName);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java
new file mode 100644
index 000000000..3a1dd712f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExpression.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Expression;
+
+import static com.github.javaparser.JavaParser.parseExpression;
+
+/**
+ * A node that has an expression in it.
+ */
+public interface NodeWithExpression<N extends Node> {
+ Expression getExpression();
+
+ N setExpression(Expression expression);
+
+ default N setExpression(String expression) {
+ return setExpression(parseExpression(expression));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java
new file mode 100644
index 000000000..af4adf800
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithExtends.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+
+import static com.github.javaparser.JavaParser.parseClassOrInterfaceType;
+
+/**
+ * A node that extends other types.
+ */
+public interface NodeWithExtends<N extends Node> {
+ NodeList<ClassOrInterfaceType> getExtendedTypes();
+
+ void tryAddImportToParentCompilationUnit(Class<?> clazz);
+
+ default ClassOrInterfaceType getExtendedTypes(int i) {
+ return getExtendedTypes().get(i);
+ }
+
+ N setExtendedTypes(NodeList<ClassOrInterfaceType> extendsList);
+
+ @SuppressWarnings("unchecked")
+ default N setExtendedType(int i, ClassOrInterfaceType extend) {
+ getExtendedTypes().set(i, extend);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addExtendedType(ClassOrInterfaceType extend) {
+ getExtendedTypes().add(extend);
+ return (N) this;
+ }
+
+ /**
+ * @deprecated use addExtendedType
+ */
+ default N addExtends(Class<?> clazz) {
+ return addExtendedType(clazz);
+ }
+
+ /**
+ * @deprecated use addExtendedType
+ */
+ default N addExtends(String name) {
+ return addExtendedType(name);
+ }
+
+ /**
+ * Add an "extends" to this and automatically add the import
+ *
+ * @param clazz the class to extand from
+ * @return this
+ */
+ default N addExtendedType(Class<?> clazz) {
+ tryAddImportToParentCompilationUnit(clazz);
+ return addExtendedType(clazz.getSimpleName());
+ }
+
+ /**
+ * Add an "extends" to this
+ *
+ * @param name the name of the type to extends from
+ * @return this
+ */
+ @SuppressWarnings("unchecked")
+ default N addExtendedType(String name) {
+ getExtendedTypes().add(parseClassOrInterfaceType(name));
+ return (N) this;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java
new file mode 100644
index 000000000..22a583a44
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithIdentifier.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+
+public interface NodeWithIdentifier<N extends Node> {
+ String getIdentifier();
+
+ N setIdentifier(String identifier);
+
+ default String getId() {
+ return getIdentifier();
+ }
+
+ default N setId(String identifier) {
+ assertNonEmpty(identifier);
+ return setIdentifier(identifier);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java
new file mode 100644
index 000000000..84cee4d32
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithImplements.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+
+import static com.github.javaparser.JavaParser.parseClassOrInterfaceType;
+
+/**
+ * A node that implements other types.
+ */
+public interface NodeWithImplements<N extends Node> {
+ NodeList<ClassOrInterfaceType> getImplementedTypes();
+
+ default ClassOrInterfaceType getImplementedTypes(int i) {
+ return getImplementedTypes().get(i);
+ }
+
+ N setImplementedTypes(NodeList<ClassOrInterfaceType> implementsList);
+
+ void tryAddImportToParentCompilationUnit(Class<?> clazz);
+
+ @SuppressWarnings("unchecked")
+ default N setImplementedType(int i, ClassOrInterfaceType implement) {
+ getImplementedTypes().set(i, implement);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addImplementedType(ClassOrInterfaceType implement) {
+ getImplementedTypes().add(implement);
+ return (N) this;
+ }
+
+ /** @deprecated use addImplementedType instead */
+ default N addImplements(String name) {
+ return addImplementedType(name);
+ }
+
+ /** @deprecated use addImplementedType instead */
+ default N addImplements(Class<?> clazz) {
+ return addImplementedType(clazz);
+ }
+
+ /**
+ * Add an implements to this
+ *
+ * @param name the name of the type to extends from
+ * @return this
+ */
+ @SuppressWarnings("unchecked")
+ default N addImplementedType(String name) {
+ getImplementedTypes().add(parseClassOrInterfaceType(name));
+ return (N) this;
+ }
+
+ /**
+ * Add an implements to this and automatically add the import
+ *
+ * @param clazz the type to implements from
+ * @return this
+ */
+ default N addImplementedType(Class<?> clazz) {
+ tryAddImportToParentCompilationUnit(clazz);
+ return addImplementedType(clazz.getSimpleName());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java
new file mode 100644
index 000000000..592947e07
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithJavadoc.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.javadoc.Javadoc;
+
+import java.util.Optional;
+
+/**
+ * A node that can be documented with a Javadoc comment.
+ */
+public interface NodeWithJavadoc<N extends Node> {
+ Optional<Comment> getComment();
+
+ Node setComment(Comment comment);
+
+ /**
+ * Gets the JavadocComment for this node. You can set the JavadocComment by calling setJavadocComment passing a
+ * JavadocComment.
+ *
+ * @return The JavadocComment for this node wrapped in an optional as it may be absent.
+ */
+ default Optional<JavadocComment> getJavadocComment() {
+ return getComment()
+ .filter(comment -> comment instanceof JavadocComment)
+ .map(comment -> (JavadocComment) comment);
+ }
+
+ /**
+ * Gets the Javadoc for this node. You can set the Javadoc by calling setJavadocComment passing a Javadoc.
+ *
+ * @return The Javadoc for this node wrapped in an optional as it may be absent.
+ */
+ default Optional<Javadoc> getJavadoc() {
+ return getJavadocComment().map(JavadocComment::parse);
+ }
+
+ /**
+ * Use this to store additional information to this node.
+ *
+ * @param comment to be set
+ */
+ @SuppressWarnings("unchecked")
+ default N setJavadocComment(String comment) {
+ return setJavadocComment(new JavadocComment(" " + comment));
+ }
+
+ default N setJavadocComment(JavadocComment comment) {
+ setComment(comment);
+ return (N) this;
+ }
+
+ default N setJavadocComment(String indentation, Javadoc javadoc) {
+ return setJavadocComment(javadoc.toComment(indentation));
+ }
+
+ default N setJavadocComment(Javadoc javadoc) {
+ return setJavadocComment(javadoc.toComment());
+ }
+
+ default boolean removeJavaDocComment() {
+ return hasJavaDocComment() && getComment().get().remove();
+ }
+
+ default boolean hasJavaDocComment() {
+ return getComment().isPresent() && getComment().get() instanceof JavadocComment;
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java
new file mode 100644
index 000000000..6d5f0c3ff
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithMembers.java
@@ -0,0 +1,328 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.stmt.BlockStmt;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.type.VoidType;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Optional;
+
+import static com.github.javaparser.JavaParser.parseType;
+import static java.util.Collections.unmodifiableList;
+import static java.util.stream.Collectors.toCollection;
+import static java.util.stream.Collectors.toList;
+
+/**
+ * A node having members.
+ * <p>
+ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getMembers
+ * method.
+ */
+public interface NodeWithMembers<N extends Node> {
+ /**
+ * @return all members inside the braces of this node,
+ * like fields, methods, nested types, etc.
+ */
+ NodeList<BodyDeclaration<?>> getMembers();
+
+ void tryAddImportToParentCompilationUnit(Class<?> clazz);
+
+ default BodyDeclaration<?> getMember(int i) {
+ return getMembers().get(i);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setMember(int i, BodyDeclaration<?> member) {
+ getMembers().set(i, member);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addMember(BodyDeclaration<?> member) {
+ getMembers().add(member);
+ return (N) this;
+ }
+
+ N setMembers(NodeList<BodyDeclaration<?>> members);
+
+ /**
+ * Add a field to this and automatically add the import of the type if needed
+ *
+ * @param typeClass the type of the field
+ * @param name the name of the field
+ * @param modifiers the modifiers like {@link Modifier#PUBLIC}
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addField(Class<?> typeClass, String name, Modifier... modifiers) {
+ tryAddImportToParentCompilationUnit(typeClass);
+ return addField(typeClass.getSimpleName(), name, modifiers);
+ }
+
+ /**
+ * Add a field to this.
+ *
+ * @param type the type of the field
+ * @param name the name of the field
+ * @param modifiers the modifiers like {@link Modifier#PUBLIC}
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addField(String type, String name, Modifier... modifiers) {
+ return addField(parseType(type), name, modifiers);
+ }
+
+ /**
+ * Add a field to this.
+ *
+ * @param type the type of the field
+ * @param name the name of the field
+ * @param modifiers the modifiers like {@link Modifier#PUBLIC}
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addField(Type type, String name, Modifier... modifiers) {
+ FieldDeclaration fieldDeclaration = new FieldDeclaration();
+ VariableDeclarator variable = new VariableDeclarator(type, name);
+ fieldDeclaration.getVariables().add(variable);
+ fieldDeclaration.setModifiers(Arrays.stream(modifiers)
+ .collect(toCollection(() -> EnumSet.noneOf(Modifier.class))));
+ getMembers().add(fieldDeclaration);
+ return fieldDeclaration;
+ }
+
+ /**
+ * Add a field to this.
+ *
+ * @param type the type of the field
+ * @param name the name of the field
+ * @param initializer the initializer of the field
+ * @param modifiers the modifiers like {@link Modifier#PUBLIC}
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addFieldWithInitializer(Type type, String name, Expression initializer, Modifier... modifiers) {
+ FieldDeclaration declaration = addField(type, name, modifiers);
+ declaration.getVariables().iterator().next().setInitializer(initializer);
+ return declaration;
+ }
+
+ /**
+ * Add a private field to this.
+ *
+ * @param typeClass the type of the field
+ * @param name the name of the field
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addPrivateField(Class<?> typeClass, String name) {
+ return addField(typeClass, name, Modifier.PRIVATE);
+ }
+
+ /**
+ * Add a private field to this and automatically add the import of the type if
+ * needed.
+ *
+ * @param type the type of the field
+ * @param name the name of the field
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addPrivateField(String type, String name) {
+ return addField(type, name, Modifier.PRIVATE);
+ }
+
+ /**
+ * Add a public field to this.
+ *
+ * @param typeClass the type of the field
+ * @param name the name of the field
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addPublicField(Class<?> typeClass, String name) {
+ return addField(typeClass, name, Modifier.PUBLIC);
+ }
+
+ /**
+ * Add a public field to this and automatically add the import of the type if
+ * needed.
+ *
+ * @param type the type of the field
+ * @param name the name of the field
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addPublicField(String type, String name) {
+ return addField(type, name, Modifier.PUBLIC);
+ }
+
+ /**
+ * Add a protected field to this.
+ *
+ * @param typeClass the type of the field
+ * @param name the name of the field
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addProtectedField(Class<?> typeClass, String name) {
+ return addField(typeClass, name, Modifier.PROTECTED);
+ }
+
+ /**
+ * Add a protected field to this and automatically add the import of the type
+ * if needed.
+ *
+ * @param type the type of the field
+ * @param name the name of the field
+ * @return the {@link FieldDeclaration} created
+ */
+ default FieldDeclaration addProtectedField(String type, String name) {
+ return addField(type, name, Modifier.PROTECTED);
+ }
+
+ /**
+ * Adds a methods with void return by default to this.
+ *
+ * @param methodName the method name
+ * @param modifiers the modifiers like {@link Modifier#PUBLIC}
+ * @return the {@link MethodDeclaration} created
+ */
+ default MethodDeclaration addMethod(String methodName, Modifier... modifiers) {
+ MethodDeclaration methodDeclaration = new MethodDeclaration();
+ methodDeclaration.setName(methodName);
+ methodDeclaration.setType(new VoidType());
+ methodDeclaration.setModifiers(Arrays.stream(modifiers)
+ .collect(toCollection(() -> EnumSet.noneOf(Modifier.class))));
+ getMembers().add(methodDeclaration);
+ return methodDeclaration;
+ }
+
+ /**
+ * Add an initializer block ({@link InitializerDeclaration}) to this.
+ */
+ default BlockStmt addInitializer() {
+ BlockStmt block = new BlockStmt();
+ InitializerDeclaration initializerDeclaration = new InitializerDeclaration(false, block);
+ getMembers().add(initializerDeclaration);
+ return block;
+ }
+
+ /**
+ * Add a static initializer block ({@link InitializerDeclaration}) to this.
+ */
+ default BlockStmt addStaticInitializer() {
+ BlockStmt block = new BlockStmt();
+ InitializerDeclaration initializerDeclaration = new InitializerDeclaration(true, block);
+ getMembers().add(initializerDeclaration);
+ return block;
+ }
+
+ /**
+ * Try to find a {@link MethodDeclaration} by its name
+ *
+ * @param name the name of the method
+ * @return the methods found (multiple in case of overloading)
+ */
+ default List<MethodDeclaration> getMethodsByName(String name) {
+ return unmodifiableList(getMethods().stream()
+ .filter(m -> m.getNameAsString().equals(name))
+ .collect(toList()));
+ }
+
+ /**
+ * Find all methods in the members of this node.
+ *
+ * @return the methods found. This list is immutable.
+ */
+ default List<MethodDeclaration> getMethods() {
+ return unmodifiableList(getMembers().stream()
+ .filter(m -> m instanceof MethodDeclaration)
+ .map(m -> (MethodDeclaration) m)
+ .collect(toList()));
+ }
+
+ /**
+ * Try to find a {@link MethodDeclaration} by its parameters types
+ *
+ * @param paramTypes the types of parameters like "Map&lt;Integer,String&gt;","int" to match<br> void
+ * foo(Map&lt;Integer,String&gt; myMap,int number)
+ * @return the methods found (multiple in case of overloading)
+ */
+ default List<MethodDeclaration> getMethodsByParameterTypes(String... paramTypes) {
+ return unmodifiableList(getMethods().stream()
+ .filter(m -> m.hasParametersOfType(paramTypes))
+ .collect(toList()));
+ }
+
+ /**
+ * Try to find {@link MethodDeclaration}s by their name and parameters types
+ *
+ * @param paramTypes the types of parameters like "Map&lt;Integer,String&gt;","int" to match<br> void
+ * foo(Map&lt;Integer,String&gt; myMap,int number)
+ * @return the methods found (multiple in case of overloading)
+ */
+ default List<MethodDeclaration> getMethodsBySignature(String name, String... paramTypes) {
+ return unmodifiableList(getMethodsByName(name).stream()
+ .filter(m -> m.hasParametersOfType(paramTypes))
+ .collect(toList()));
+ }
+
+ /**
+ * Try to find a {@link MethodDeclaration} by its parameters types
+ *
+ * @param paramTypes the types of parameters like "Map&lt;Integer,String&gt;","int" to match<br> void
+ * foo(Map&lt;Integer,String&gt; myMap,int number)
+ * @return the methods found (multiple in case of overloading)
+ */
+ default List<MethodDeclaration> getMethodsByParameterTypes(Class<?>... paramTypes) {
+ return unmodifiableList(getMethods().stream()
+ .filter(m -> m.hasParametersOfType(paramTypes))
+ .collect(toList()));
+ }
+
+ /**
+ * Try to find a {@link FieldDeclaration} by its name
+ *
+ * @param name the name of the field
+ * @return null if not found, the FieldDeclaration otherwise
+ */
+ default Optional<FieldDeclaration> getFieldByName(String name) {
+ return getMembers().stream()
+ .filter(m -> m instanceof FieldDeclaration)
+ .map(f -> (FieldDeclaration) f)
+ .filter(f -> f.getVariables().stream()
+ .anyMatch(var -> var.getNameAsString().equals(name)))
+ .findFirst();
+ }
+
+ /**
+ * Find all fields in the members of this node.
+ *
+ * @return the fields found. This list is immutable.
+ */
+ default List<FieldDeclaration> getFields() {
+ return unmodifiableList(getMembers().stream()
+ .filter(m -> m instanceof FieldDeclaration)
+ .map(m -> (FieldDeclaration) m)
+ .collect(toList()));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java
new file mode 100644
index 000000000..3a499bfa3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithModifiers.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.stream.Collectors;
+
+/**
+ * A Node with Modifiers.
+ * Note that not all modifiers may be valid for this node.
+ */
+public interface NodeWithModifiers<N extends Node> {
+ /**
+ * Return the modifiers of this variable declaration.
+ * Warning: modifying the returned set will not trigger observers,
+ * you have to use setModifiers for that.
+ *
+ * @return modifiers
+ * @see Modifier
+ */
+ EnumSet<Modifier> getModifiers();
+
+ N setModifiers(EnumSet<Modifier> modifiers);
+
+ @SuppressWarnings("unchecked")
+ default N addModifier(Modifier... modifiers) {
+ EnumSet<Modifier> newModifiers = getModifiers().clone();
+ newModifiers.addAll(Arrays.stream(modifiers)
+ .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))));
+ setModifiers(newModifiers);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N removeModifier(Modifier... m) {
+ EnumSet<Modifier> newModifiers = getModifiers().clone();
+ newModifiers.removeAll(Arrays.stream(m)
+ .collect(Collectors.toCollection(() -> EnumSet.noneOf(Modifier.class))));
+ setModifiers(newModifiers);
+ return (N) this;
+ }
+ default N setModifier(Modifier m, boolean set) {
+ if (set) {
+ return addModifier(m);
+ } else {
+ return removeModifier(m);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithName.java
new file mode 100644
index 000000000..bc25cad05
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithName.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Name;
+
+import static com.github.javaparser.JavaParser.parseName;
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+
+/**
+ * A node with a (qualified) name.
+ * <p>
+ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getName method.
+ *
+ * @since 2.0.1
+ */
+public interface NodeWithName<N extends Node> {
+ Name getName();
+
+ N setName(Name name);
+
+ @SuppressWarnings("unchecked")
+ default N setName(String name) {
+ assertNonEmpty(name);
+ return setName(parseName(name));
+ }
+
+ default String getNameAsString() {
+ return getName().asString();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java
new file mode 100644
index 000000000..0bf89a4d2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalBlockStmt.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.stmt.BlockStmt;
+
+import java.util.Optional;
+
+/**
+ * A node with a body that is a BlockStmt, which is optional.
+ */
+public interface NodeWithOptionalBlockStmt<N extends Node> {
+ Optional<BlockStmt> getBody();
+
+ N setBody(BlockStmt block);
+
+ N removeBody();
+
+ default BlockStmt createBody() {
+ BlockStmt block = new BlockStmt();
+ setBody(block);
+ return block;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java
new file mode 100644
index 000000000..93ab11a5a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalLabel.java
@@ -0,0 +1,28 @@
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.SimpleName;
+
+import java.util.Optional;
+
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+
+/**
+ * A node that has an optional label.
+ */
+public interface NodeWithOptionalLabel<T extends Node> {
+ Optional<SimpleName> getLabel();
+
+ T setLabel(SimpleName label);
+
+ T removeLabel();
+
+ default T setLabel(String label) {
+ assertNonEmpty(label);
+ return setLabel(new SimpleName(label));
+ }
+
+ default Optional<String> getLabelAsString() {
+ return getLabel().flatMap(l -> Optional.of(l.getIdentifier()));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java
new file mode 100644
index 000000000..46bd59c84
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithOptionalScope.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2017 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Expression;
+
+import java.util.Optional;
+
+/**
+ * Represents a node which has an optional scope expression eg. method calls (object.method()).
+ */
+public interface NodeWithOptionalScope<N extends Node> extends NodeWithTraversableScope {
+
+ Optional<Expression> getScope();
+
+ N setScope(Expression scope);
+
+ N removeScope();
+
+ default Optional<Expression> traverseScope() {
+ return getScope();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java
new file mode 100644
index 000000000..517d8f574
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithParameters.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.Parameter;
+import com.github.javaparser.ast.type.Type;
+
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import static com.github.javaparser.JavaParser.parseType;
+import static java.util.stream.Collectors.toSet;
+
+public interface NodeWithParameters<N extends Node> {
+ NodeList<Parameter> getParameters();
+
+ default Parameter getParameter(int i) {
+ return getParameters().get(i);
+ }
+
+ void tryAddImportToParentCompilationUnit(Class<?> clazz);
+
+ @SuppressWarnings("unchecked")
+ default N setParameter(int i, Parameter parameter) {
+ getParameters().set(i, parameter);
+ return (N) this;
+ }
+
+ N setParameters(NodeList<Parameter> parameters);
+
+ default N addParameter(Type type, String name) {
+ return addParameter(new Parameter(type, name));
+ }
+
+ default N addParameter(Class<?> paramClass, String name) {
+ tryAddImportToParentCompilationUnit(paramClass);
+ return addParameter(parseType(paramClass.getSimpleName()), name);
+ }
+
+ /**
+ * Remember to import the class in the compilation unit yourself
+ *
+ * @param className the name of the class, ex : org.test.Foo or Foo if you added manually the import
+ * @param name the name of the parameter
+ */
+ default N addParameter(String className, String name) {
+ return addParameter(parseType(className), name);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addParameter(Parameter parameter) {
+ getParameters().add(parameter);
+ return (N) this;
+ }
+
+ default Parameter addAndGetParameter(Type type, String name) {
+ return addAndGetParameter(new Parameter(type, name));
+ }
+
+ default Parameter addAndGetParameter(Class<?> paramClass, String name) {
+ tryAddImportToParentCompilationUnit(paramClass);
+ return addAndGetParameter(parseType(paramClass.getSimpleName()), name);
+ }
+
+ /**
+ * Remember to import the class in the compilation unit yourself
+ *
+ * @param className the name of the class, ex : org.test.Foo or Foo if you added manually the import
+ * @param name the name of the parameter
+ * @return the {@link Parameter} created
+ */
+ default Parameter addAndGetParameter(String className, String name) {
+ return addAndGetParameter(parseType(className), name);
+ }
+
+ default Parameter addAndGetParameter(Parameter parameter) {
+ getParameters().add(parameter);
+ return parameter;
+ }
+
+ /**
+ * Try to find a {@link Parameter} by its name
+ *
+ * @param name the name of the param
+ * @return null if not found, the param found otherwise
+ */
+ default Optional<Parameter> getParameterByName(String name) {
+ return getParameters().stream()
+ .filter(p -> p.getNameAsString().equals(name)).findFirst();
+ }
+
+ /**
+ * Try to find a {@link Parameter} by its type
+ *
+ * @param type the type of the param
+ * @return null if not found, the param found otherwise
+ */
+ default Optional<Parameter> getParameterByType(String type) {
+ return getParameters().stream()
+ .filter(p -> p.getType().toString().equals(type)).findFirst();
+ }
+
+ /**
+ * Try to find a {@link Parameter} by its type
+ *
+ * @param type the type of the param <b>take care about generics, it wont work</b>
+ * @return null if not found, the param found otherwise
+ */
+ default Optional<Parameter> getParameterByType(Class<?> type) {
+ return getParameters().stream()
+ .filter(p -> p.getType().toString().equals(type.getSimpleName())).findFirst();
+ }
+
+ /**
+ * Check if the parameters have certain types.
+ *
+ * @param paramTypes the types of parameters like "Map&lt;Integer,String&gt;","int" to match<br> void
+ * foo(Map&lt;Integer,String&gt; myMap,int number)
+ * @return true if all parameters match
+ */
+ default boolean hasParametersOfType(String... paramTypes) {
+ return getParameters().stream()
+ .map(p -> p.getType().toString())
+ .collect(toSet())
+ .equals(Stream.of(paramTypes).collect(toSet()));
+ }
+
+ /**
+ * Check if the parameters have certain types. Note that this is a match in SimpleName, so "java.awt.List" and
+ * "java.util.List" are identical to this algorithm.
+ *
+ * @param paramTypes the types of parameters like "Map&lt;Integer,String&gt;","int" to match<br> void
+ * foo(Map&lt;Integer,String&gt; myMap,int number)
+ * @return true if all parameters match
+ */
+ default boolean hasParametersOfType(Class<?>... paramTypes) {
+ return getParameters().stream().map(p -> p.getType().toString())
+ .collect(toSet())
+ .equals(Stream.of(paramTypes).map(Class::getSimpleName).collect(toSet()));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithRange.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithRange.java
new file mode 100644
index 000000000..d1e2fb767
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithRange.java
@@ -0,0 +1,54 @@
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.Position;
+import com.github.javaparser.Range;
+import com.github.javaparser.ast.Node;
+
+import java.util.Optional;
+
+/**
+ * A node that has a Range, which is every Node.
+ *
+ */
+public interface NodeWithRange<N> {
+ Optional<Range> getRange();
+
+ N setRange(Range range);
+
+ /**
+ * The begin position of this node in the source file.
+ */
+ default Optional<Position> getBegin() {
+ return getRange().map(r -> r.begin);
+ }
+
+ /**
+ * The end position of this node in the source file.
+ */
+ default Optional<Position> getEnd() {
+ return getRange().map(r -> r.end);
+ }
+
+ default boolean containsWithin(Node other) {
+ if (getRange().isPresent() && other.getRange().isPresent()) {
+ return getRange().get().contains(other.getRange().get());
+ }
+ return false;
+ }
+
+ /**
+ * @deprecated use isAfter() on range
+ */
+ @Deprecated
+ default boolean isPositionedAfter(Position position) {
+ return getRange().map(r -> r.isAfter(position)).orElse(false);
+ }
+
+ /**
+ * @deprecated use isBefore() on range
+ */
+ @Deprecated
+ default boolean isPositionedBefore(Position position) {
+ return getRange().map(r -> r.isBefore(position)).orElse(false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithScope.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithScope.java
new file mode 100644
index 000000000..15ea3ac25
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithScope.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2017 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Expression;
+
+import java.util.Optional;
+
+/**
+ * Represents a node which has a required scope expression eg. field access (object.method).
+ */
+public interface NodeWithScope<N extends Node> extends NodeWithTraversableScope {
+
+ Expression getScope();
+
+ N setScope(Expression scope);
+
+ default Optional<Expression> traverseScope() {
+ return Optional.of(getScope());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java
new file mode 100644
index 000000000..ebd3957b8
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithSimpleName.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+
+/**
+ * A node with a name.
+ * <p>
+ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getName method.
+ */
+public interface NodeWithSimpleName<N extends Node> {
+ SimpleName getName();
+
+ N setName(SimpleName name);
+
+ @SuppressWarnings("unchecked")
+ default N setName(String name) {
+ assertNonEmpty(name);
+ return setName(new SimpleName(name));
+ }
+
+ default String getNameAsString() {
+ return getName().getIdentifier();
+ }
+
+ default NameExpr getNameAsExpression() {
+ return new NameExpr(getName());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java
new file mode 100644
index 000000000..4d2c90cec
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithStatements.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.JavaParser;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.stmt.ExpressionStmt;
+import com.github.javaparser.ast.stmt.Statement;
+
+import static com.github.javaparser.JavaParser.*;
+
+/**
+ * A node that contains a list of statements.
+ */
+public interface NodeWithStatements<N extends Node> {
+ NodeList<Statement> getStatements();
+
+ default Statement getStatement(int i) {
+ return getStatements().get(i);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setStatement(int i, Statement statement) {
+ getStatements().set(i, statement);
+ return (N) this;
+ }
+
+ N setStatements(final NodeList<Statement> statements);
+
+ @SuppressWarnings("unchecked")
+ default N addStatement(Statement statement) {
+ getStatements().add(statement);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addStatement(int index, final Statement statement) {
+ getStatements().add(index, statement);
+ return (N) this;
+ }
+
+ default N addStatement(Expression expr) {
+ return addStatement(new ExpressionStmt(expr));
+ }
+
+ /**
+ * It will use {@link JavaParser#parseStatement(String)} inside, so it should end with a semi column
+ */
+ default N addStatement(String statement) {
+ return addStatement(parseStatement(statement));
+ }
+
+ default N addStatement(int index, final Expression expr) {
+ Statement stmt = new ExpressionStmt(expr);
+ return addStatement(index, stmt);
+ }
+
+ default <A extends Statement> A addAndGetStatement(A statement) {
+ getStatements().add(statement);
+ return statement;
+ }
+
+ default Statement addAndGetStatement(int index, final Statement statement) {
+ getStatements().add(index, statement);
+ return statement;
+ }
+
+ default ExpressionStmt addAndGetStatement(Expression expr) {
+ ExpressionStmt statement = new ExpressionStmt(expr);
+ return addAndGetStatement(statement);
+ }
+
+ default ExpressionStmt addAndGetStatement(String statement) {
+ return addAndGetStatement(new NameExpr(statement));
+ }
+
+ default boolean isEmpty() {
+ return getStatements().isEmpty();
+ }
+
+ @SuppressWarnings("unchecked")
+ default N copyStatements(NodeList<Statement> nodeList) {
+ for (Statement n : nodeList) {
+ addStatement(n.clone());
+ }
+ return (N) this;
+ }
+
+ default N copyStatements(NodeWithStatements<?> other) {
+ return copyStatements(other.getStatements());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java
new file mode 100644
index 000000000..e1b9007f6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithThrownExceptions.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.type.ReferenceType;
+
+import static com.github.javaparser.JavaParser.parseClassOrInterfaceType;
+
+/**
+ * A node that declares the types of exception it throws.
+ */
+public interface NodeWithThrownExceptions<N extends Node> {
+ N setThrownExceptions(NodeList<ReferenceType> thrownExceptions);
+
+ NodeList<ReferenceType> getThrownExceptions();
+
+ void tryAddImportToParentCompilationUnit(Class<?> clazz);
+
+ default ReferenceType getThrownException(int i) {
+ return getThrownExceptions().get(i);
+ }
+
+ /**
+ * Adds this type to the throws clause
+ *
+ * @param throwType the exception type
+ * @return this
+ */
+ @SuppressWarnings("unchecked")
+ default N addThrownException(ReferenceType throwType) {
+ getThrownExceptions().add(throwType);
+ return (N) this;
+ }
+
+ /**
+ * Adds this class to the throws clause
+ *
+ * @param clazz the exception class
+ * @return this
+ */
+ default N addThrownException(Class<? extends Throwable> clazz) {
+ tryAddImportToParentCompilationUnit(clazz);
+ return addThrownException(parseClassOrInterfaceType(clazz.getSimpleName()));
+ }
+
+ /**
+ * Check whether this elements throws this exception class.
+ * Note that this is simply a text compare of the simple name of the class,
+ * no actual type resolution takes place.
+ *
+ * @param clazz the class of the exception
+ * @return true if found in throws clause, false if not
+ */
+ default boolean isThrown(Class<? extends Throwable> clazz) {
+ return isThrown(clazz.getSimpleName());
+ }
+
+ /**
+ * Check whether this elements throws this exception class
+ * Note that this is simply a text compare,
+ * no actual type resolution takes place.
+ *
+ * @param throwableName the class of the exception
+ * @return true if found in throws clause, false if not
+ */
+ default boolean isThrown(String throwableName) {
+ return getThrownExceptions().stream().anyMatch(t -> t.toString().equals(throwableName));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java
new file mode 100644
index 000000000..b043f6426
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTokenRange.java
@@ -0,0 +1,15 @@
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.TokenRange;
+
+import java.util.Optional;
+
+/**
+ * A node that has a Range, which is every Node.
+ *
+ */
+public interface NodeWithTokenRange<N> {
+ Optional<TokenRange> getTokenRange();
+
+ N setTokenRange(TokenRange range);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java
new file mode 100644
index 000000000..a1b9b3be5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTraversableScope.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2017 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.expr.Expression;
+
+import java.util.Optional;
+
+/**
+ * Represents a node which has a scope expression that can be traversed/walked.
+ * This unifies scope access for NodeWithScope and NodeWithOptionalScope.
+ */
+public interface NodeWithTraversableScope {
+
+ /**
+ * @return the scope of this node, regardless of optionality.
+ * An optional scope is returned directly.
+ * A required scope is returned in an "Optional", but will never be empty.
+ */
+ Optional<Expression> traverseScope();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithType.java
new file mode 100644
index 000000000..06e66fb91
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithType.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.type.Type;
+
+import static com.github.javaparser.JavaParser.parseType;
+import static com.github.javaparser.utils.Utils.assertNonEmpty;
+
+/**
+ * A node with a type.
+ * <p>
+ * The main reason for this interface is to permit users to manipulate homogeneously all nodes with getType/setType
+ * methods
+ *
+ * @since 2.3.1
+ */
+public interface NodeWithType<N extends Node, T extends Type> {
+ /**
+ * Gets the type
+ *
+ * @return the type
+ */
+ T getType();
+
+ /**
+ * Sets the type
+ *
+ * @param type the type
+ * @return this
+ */
+ N setType(T type);
+
+ void tryAddImportToParentCompilationUnit(Class<?> clazz);
+
+ /**
+ * Sets this type to this class and try to import it to the {@link CompilationUnit} if needed
+ *
+ * @param typeClass the type
+ * @return this
+ */
+ @SuppressWarnings("unchecked")
+ default N setType(Class<?> typeClass) {
+ tryAddImportToParentCompilationUnit(typeClass);
+ return setType((T) parseType(typeClass.getSimpleName()));
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setType(final String typeString) {
+ assertNonEmpty(typeString);
+ return setType((T) parseType(typeString));
+ }
+
+ default String getTypeAsString() {
+ return getType().asString();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java
new file mode 100644
index 000000000..0c72b225e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeArguments.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.metamodel.DerivedProperty;
+
+import java.util.Optional;
+
+import static com.github.javaparser.ast.NodeList.nodeList;
+
+/**
+ * A node that can have type arguments.
+ * <p>
+ * <pre>
+ * new X(); --> typeArguments == Optional is empty
+ * new X&lt;>(); --> typeArguments = [], diamondOperator = true
+ * new X&lt;C,D>(); --> typeArguments = [C,D], diamondOperator = false
+ * </pre>
+ */
+public interface NodeWithTypeArguments<N extends Node> {
+ /**
+ * @return the types that can be found in the type arguments: &lt;String, Integer&gt;.
+ */
+ Optional<NodeList<Type>> getTypeArguments();
+
+ /**
+ * Allows you to set the generic arguments
+ *
+ * @param typeArguments The list of types of the generics, can be null
+ */
+ N setTypeArguments(NodeList<Type> typeArguments);
+
+ /**
+ * @return whether the type arguments look like &lt;>.
+ */
+ @DerivedProperty
+ default boolean isUsingDiamondOperator() {
+ return getTypeArguments().isPresent() && getTypeArguments().get().isEmpty();
+ }
+
+ /**
+ * Sets the type arguments to &lt>.
+ */
+ @SuppressWarnings("unchecked")
+ default N setDiamondOperator() {
+ return setTypeArguments(new NodeList<>());
+ }
+
+ /**
+ * Removes all type arguments, including the surrounding &lt;>.
+ */
+ @SuppressWarnings("unchecked")
+ default N removeTypeArguments() {
+ return setTypeArguments((NodeList<Type>) null);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setTypeArguments(Type... typeArguments) {
+ return setTypeArguments(nodeList(typeArguments));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java
new file mode 100644
index 000000000..8817a7620
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithTypeParameters.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.type.TypeParameter;
+
+/**
+ * A node that can have type parameters.
+ * <pre>
+ * class X {} --> typeParameters == []
+ * class X&lt;> {} --> does not occur.
+ * class X&lt;C,D> {} --> typeParameters = [C,D]
+ * </pre>
+ */
+public interface NodeWithTypeParameters<N extends Node> {
+ NodeList<TypeParameter> getTypeParameters();
+
+ default TypeParameter getTypeParameter(int i) {
+ return getTypeParameters().get(i);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setTypeParameter(int i, TypeParameter typeParameter) {
+ getTypeParameters().set(i, typeParameter);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addTypeParameter(TypeParameter typeParameter) {
+ getTypeParameters().add(typeParameter);
+ return (N) this;
+ }
+
+ N setTypeParameters(NodeList<TypeParameter> typeParameters);
+
+ default boolean isGeneric() {
+ return getTypeParameters().size() > 0;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java
new file mode 100644
index 000000000..5daf38a14
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/NodeWithVariables.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.nodeTypes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.VariableDeclarator;
+import com.github.javaparser.ast.type.ArrayType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.metamodel.DerivedProperty;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * A node which has a list of variables.
+ */
+public interface NodeWithVariables<N extends Node> {
+ NodeList<VariableDeclarator> getVariables();
+
+ N setVariables(NodeList<VariableDeclarator> variables);
+
+ default VariableDeclarator getVariable(int i) {
+ return getVariables().get(i);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setVariable(int i, VariableDeclarator variableDeclarator) {
+ getVariables().set(i, variableDeclarator);
+ return (N) this;
+ }
+
+ @SuppressWarnings("unchecked")
+ default N addVariable(VariableDeclarator variableDeclarator) {
+ getVariables().add(variableDeclarator);
+ return (N) this;
+ }
+
+ /**
+ * Returns the type that is shared between all variables.
+ * This is a shortcut for when you are certain that all variables share one type.
+ * What makes this difficult is arrays, and being able to set the type.
+ * <br/>For <code>int a;</code> this is int.
+ * <br/>For <code>int a,b,c,d;</code> this is also int.
+ * <br/>For <code>int a,b[],c;</code> this is an assertion error since b is an int[], not an int.
+ * <br/>For <code>int a,b;</code>, then doing setType(String) on b, this is an assertion error. It is also a situation that you don't really want.
+ */
+ default Type getCommonType() {
+ NodeList<VariableDeclarator> variables = getVariables();
+ if (variables.isEmpty()) {
+ throw new AssertionError("There is no common type since there are no variables.");
+ }
+ Type type = variables.get(0).getType();
+ for (int i = 1; i < variables.size(); i++) {
+ if (!variables.get(i).getType().equals(type)) {
+ throw new AssertionError("The variables do not have a common type.");
+ }
+ }
+ return type;
+ }
+
+ /**
+ * Returns the element type.
+ * <br/>For <code>int a;</code> this is int.
+ * <br/>For <code>int a,b,c,d;</code> this is also int.
+ * <br/>For <code>int a,b[],c;</code> this is also int. Note: no mention of b being an array.
+ * <br/>For <code>int a,b;</code>, then doing setType(String) on b, then calling getElementType(). This is an assertion error. It is also a situation that you don't really want.
+ */
+ default Type getElementType() {
+ NodeList<VariableDeclarator> variables = getVariables();
+ if (variables.isEmpty()) {
+ throw new AssertionError("There is no element type since there are no variables.");
+ }
+ Type type = variables.get(0).getType().getElementType();
+ for (int i = 1; i < variables.size(); i++) {
+ if (!variables.get(i).getType().getElementType().equals(type)) {
+ throw new AssertionError("The variables do not have a common type.");
+ }
+ }
+ return type;
+ }
+
+ /**
+ * Returns the type that maximum shared type between all variables.
+ * The minimum common type does never include annotations on the array level.
+ * <p>
+ * <br/>For <code>int a;</code> this is int.
+ * <br/>For <code>int a,b,c,d;</code> this is also int.
+ * <br/>For <code>int a,b[],c;</code> this is also int.
+ * <br/>For <code>int[] a[][],b[],c[][];</code> this is int[][].
+ */
+ @DerivedProperty
+ default Optional<Type> getMaximumCommonType() {
+ return calculateMaximumCommonType(getVariables().stream().map(v -> v.getType()).collect(Collectors.toList()));
+ }
+
+ static Optional<Type> calculateMaximumCommonType(List<Type> types) {
+ // we use a local class because we cannot use an helper static method in an interface
+ class Helper {
+ // Conceptually: given a type we start from the Element Type and get as many array levels as indicated
+ // From the implementation point of view we start from the actual type and we remove how many array
+ // levels as needed to get the target level of arrays
+ // It returns null if the type has less array levels then the desired target
+ private Optional<Type> toArrayLevel(Type type, int level) {
+ if (level > type.getArrayLevel()) {
+ return Optional.empty();
+ }
+ for (int i = type.getArrayLevel(); i > level; i--) {
+ if (!(type instanceof ArrayType)) {
+ return Optional.empty();
+ }
+ type = ((ArrayType) type).getComponentType();
+ }
+ return Optional.of(type);
+ }
+ }
+
+ Helper helper = new Helper();
+ int level = 0;
+ boolean keepGoing = true;
+ // In practice we want to check for how many levels of arrays all the variables have the same type,
+ // including also the annotations
+ while (keepGoing) {
+ final int currentLevel = level;
+ // Now, given that equality on nodes consider the position the simplest way is to compare
+ // the pretty-printed string got for a node. We just check all them are the same and if they
+ // are we just just is not null
+ Object[] values = types.stream().map(v -> {
+ Optional<Type> t = helper.toArrayLevel(v, currentLevel);
+ return t.map(Node::toString).orElse(null);
+ }).distinct().toArray();
+ if (values.length == 1 && values[0] != null) {
+ level++;
+ } else {
+ keepGoing = false;
+ }
+ }
+ return helper.toArrayLevel(types.get(0), --level);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java
new file mode 100644
index 000000000..c81c4c616
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAbstractModifier.java
@@ -0,0 +1,20 @@
+package com.github.javaparser.ast.nodeTypes.modifiers;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
+
+import static com.github.javaparser.ast.Modifier.ABSTRACT;
+
+/**
+ * A node that can be abstract.
+ */
+public interface NodeWithAbstractModifier<N extends Node> extends NodeWithModifiers<N> {
+ default boolean isAbstract() {
+ return getModifiers().contains(ABSTRACT);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setAbstract(boolean set) {
+ return setModifier(ABSTRACT, set);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java
new file mode 100644
index 000000000..956962448
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithAccessModifiers.java
@@ -0,0 +1,9 @@
+package com.github.javaparser.ast.nodeTypes.modifiers;
+
+import com.github.javaparser.ast.Node;
+
+/**
+ * A node that can be public, protected, and/or private.
+ */
+public interface NodeWithAccessModifiers<N extends Node> extends NodeWithPublicModifier<N>, NodeWithPrivateModifier<N>, NodeWithProtectedModifier<N> {
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java
new file mode 100644
index 000000000..91aae402e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithFinalModifier.java
@@ -0,0 +1,20 @@
+package com.github.javaparser.ast.nodeTypes.modifiers;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
+
+import static com.github.javaparser.ast.Modifier.FINAL;
+
+/**
+ * A node that can be final.
+ */
+public interface NodeWithFinalModifier<N extends Node> extends NodeWithModifiers<N> {
+ default boolean isFinal() {
+ return getModifiers().contains(FINAL);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setFinal(boolean set) {
+ return setModifier(FINAL, set);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java
new file mode 100644
index 000000000..4aa022cfe
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPrivateModifier.java
@@ -0,0 +1,20 @@
+package com.github.javaparser.ast.nodeTypes.modifiers;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
+
+import static com.github.javaparser.ast.Modifier.*;
+
+/**
+ * A node that can be private.
+ */
+public interface NodeWithPrivateModifier<N extends Node> extends NodeWithModifiers<N> {
+ default boolean isPrivate() {
+ return getModifiers().contains(PRIVATE);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setPrivate(boolean set) {
+ return setModifier(PRIVATE, set);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java
new file mode 100644
index 000000000..d2200b74a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithProtectedModifier.java
@@ -0,0 +1,20 @@
+package com.github.javaparser.ast.nodeTypes.modifiers;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
+
+import static com.github.javaparser.ast.Modifier.*;
+
+/**
+ * A node that can be protected.
+ */
+public interface NodeWithProtectedModifier<N extends Node> extends NodeWithModifiers<N> {
+ default boolean isProtected() {
+ return getModifiers().contains(PROTECTED);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setProtected(boolean set) {
+ return setModifier(PROTECTED, set);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java
new file mode 100644
index 000000000..64b4067bf
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithPublicModifier.java
@@ -0,0 +1,21 @@
+package com.github.javaparser.ast.nodeTypes.modifiers;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
+
+import static com.github.javaparser.ast.Modifier.*;
+
+/**
+ * A node that can be public.
+ */
+public interface NodeWithPublicModifier<N extends Node> extends NodeWithModifiers<N> {
+ default boolean isPublic() {
+ return getModifiers().contains(PUBLIC);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setPublic(boolean set) {
+ return setModifier(PUBLIC, set);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java
new file mode 100644
index 000000000..5ac63ea40
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStaticModifier.java
@@ -0,0 +1,22 @@
+package com.github.javaparser.ast.nodeTypes.modifiers;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
+
+import static com.github.javaparser.ast.Modifier.STATIC;
+
+/**
+ * A node that can be static.
+ */
+public interface NodeWithStaticModifier<N extends Node> extends NodeWithModifiers<N> {
+
+ default boolean isStatic() {
+ return getModifiers().contains(STATIC);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setStatic(boolean set) {
+ return setModifier(STATIC, set);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java
new file mode 100644
index 000000000..1d8fb4112
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/nodeTypes/modifiers/NodeWithStrictfpModifier.java
@@ -0,0 +1,20 @@
+package com.github.javaparser.ast.nodeTypes.modifiers;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
+
+import static com.github.javaparser.ast.Modifier.STRICTFP;
+
+/**
+ * A node that can be strictfp.
+ */
+public interface NodeWithStrictfpModifier<N extends Node> extends NodeWithModifiers<N> {
+ default boolean isStrictfp() {
+ return getModifiers().contains(STRICTFP);
+ }
+
+ @SuppressWarnings("unchecked")
+ default N setStrictfp(boolean set) {
+ return setModifier(STRICTFP, set);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserver.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserver.java
new file mode 100644
index 000000000..6c41f4b02
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserver.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.observer;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+
+/**
+ * An Observer for an AST element (either a Node or a NodeList).
+ */
+public interface AstObserver {
+
+ /**
+ * Type of change occurring on a List
+ */
+ enum ListChangeType {
+ ADDITION,
+ REMOVAL
+ }
+
+ /**
+ * The value of a property is changed
+ *
+ * @param observedNode owner of the property
+ * @param property property changed
+ * @param oldValue value of the property before the change
+ * @param newValue value of the property after the change
+ */
+ void propertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue);
+
+ /**
+ * The parent of a node is changed
+ *
+ * @param observedNode node of which the parent is changed
+ * @param previousParent previous parent
+ * @param newParent new parent
+ */
+ void parentChange(Node observedNode, Node previousParent, Node newParent);
+
+ /**
+ * A list is changed
+ *
+ * @param observedNode list changed
+ * @param type type of change
+ * @param index position at which the changed occurred
+ * @param nodeAddedOrRemoved element added or removed
+ */
+ void listChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved);
+
+ void listReplacement(NodeList observedNode, int index, Node oldNode, Node newNode);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserverAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserverAdapter.java
new file mode 100644
index 000000000..82b91949d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/AstObserverAdapter.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.observer;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+
+public abstract class AstObserverAdapter implements AstObserver {
+
+ @Override
+ public void propertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) {
+ // do nothing
+ }
+
+ @Override
+ public void parentChange(Node observedNode, Node previousParent, Node newParent) {
+ // do nothing
+ }
+
+ @Override
+ public void listChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved) {
+ // do nothing
+ }
+
+ @Override
+ public void listReplacement(NodeList observedNode, int index, Node oldNode, Node newNode) {
+ // do nothing
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/Observable.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/Observable.java
new file mode 100644
index 000000000..ce0f926bf
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/Observable.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.observer;
+
+/**
+ * Observable element.
+ */
+public interface Observable {
+
+ /**
+ * Register an observer.
+ */
+ void register(AstObserver observer);
+
+ /**
+ * Unregister an observer. If the given observer was not registered there are no effects.
+ */
+ void unregister(AstObserver observer);
+
+ /**
+ * Was this observer registered?
+ * Note that equals is used to determine if the given observer was registered.
+ */
+ boolean isRegistered(AstObserver observer);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java
new file mode 100644
index 000000000..d7f82f36c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/ObservableProperty.java
@@ -0,0 +1,298 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.observer;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.utils.Utils;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.Optional;
+import java.util.Arrays;
+import javax.annotation.Generated;
+
+/**
+ * Properties considered by the AstObserver
+ */
+@Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+public enum ObservableProperty {
+
+ ANNOTATIONS(Type.MULTIPLE_REFERENCE),
+ ANONYMOUS_CLASS_BODY(Type.MULTIPLE_REFERENCE),
+ ARGUMENTS(Type.MULTIPLE_REFERENCE),
+ ASTERISK(Type.SINGLE_ATTRIBUTE),
+ BODY(Type.SINGLE_REFERENCE),
+ CATCH_CLAUSES(Type.MULTIPLE_REFERENCE),
+ CHECK(Type.SINGLE_REFERENCE),
+ CLASS_BODY(Type.MULTIPLE_REFERENCE),
+ CLASS_DECLARATION(Type.SINGLE_REFERENCE),
+ CLASS_EXPR(Type.SINGLE_REFERENCE),
+ COMMENT(Type.SINGLE_REFERENCE),
+ COMPARE(Type.SINGLE_REFERENCE),
+ COMPONENT_TYPE(Type.SINGLE_REFERENCE),
+ CONDITION(Type.SINGLE_REFERENCE),
+ CONTENT(Type.SINGLE_ATTRIBUTE),
+ DEFAULT_VALUE(Type.SINGLE_REFERENCE),
+ DIMENSION(Type.SINGLE_REFERENCE),
+ ELEMENTS(Type.MULTIPLE_REFERENCE),
+ ELEMENT_TYPE(Type.SINGLE_REFERENCE),
+ ELSE_EXPR(Type.SINGLE_REFERENCE),
+ ELSE_STMT(Type.SINGLE_REFERENCE),
+ ENCLOSING_PARAMETERS(Type.SINGLE_ATTRIBUTE),
+ ENTRIES(Type.MULTIPLE_REFERENCE),
+ EXPRESSION(Type.SINGLE_REFERENCE),
+ EXTENDED_TYPE(Type.SINGLE_REFERENCE),
+ EXTENDED_TYPES(Type.MULTIPLE_REFERENCE),
+ FINALLY_BLOCK(Type.SINGLE_REFERENCE),
+ IDENTIFIER(Type.SINGLE_ATTRIBUTE),
+ IMPLEMENTED_TYPES(Type.MULTIPLE_REFERENCE),
+ IMPORTS(Type.MULTIPLE_REFERENCE),
+ INDEX(Type.SINGLE_REFERENCE),
+ INITIALIZATION(Type.MULTIPLE_REFERENCE),
+ INITIALIZER(Type.SINGLE_REFERENCE),
+ INNER(Type.SINGLE_REFERENCE),
+ INTERFACE(Type.SINGLE_ATTRIBUTE),
+ ITERABLE(Type.SINGLE_REFERENCE),
+ LABEL(Type.SINGLE_REFERENCE),
+ LEFT(Type.SINGLE_REFERENCE),
+ LEVELS(Type.MULTIPLE_REFERENCE),
+ MEMBERS(Type.MULTIPLE_REFERENCE),
+ MEMBER_VALUE(Type.SINGLE_REFERENCE),
+ MESSAGE(Type.SINGLE_REFERENCE),
+ MODIFIERS(Type.MULTIPLE_ATTRIBUTE),
+ MODULE(Type.SINGLE_REFERENCE),
+ MODULE_NAMES(Type.MULTIPLE_REFERENCE),
+ MODULE_STMTS(Type.MULTIPLE_REFERENCE),
+ NAME(Type.SINGLE_REFERENCE),
+ OPEN(Type.SINGLE_ATTRIBUTE),
+ OPERATOR(Type.SINGLE_ATTRIBUTE),
+ ORIGIN(Type.SINGLE_ATTRIBUTE),
+ PACKAGE_DECLARATION(Type.SINGLE_REFERENCE),
+ PAIRS(Type.MULTIPLE_REFERENCE),
+ PARAMETER(Type.SINGLE_REFERENCE),
+ PARAMETERS(Type.MULTIPLE_REFERENCE),
+ QUALIFIER(Type.SINGLE_REFERENCE),
+ RECEIVER_PARAMETER(Type.SINGLE_REFERENCE),
+ RESOURCES(Type.MULTIPLE_REFERENCE),
+ RIGHT(Type.SINGLE_REFERENCE),
+ SCOPE(Type.SINGLE_REFERENCE),
+ SELECTOR(Type.SINGLE_REFERENCE),
+ STATEMENT(Type.SINGLE_REFERENCE),
+ STATEMENTS(Type.MULTIPLE_REFERENCE),
+ STATIC(Type.SINGLE_ATTRIBUTE),
+ SUPER_TYPE(Type.SINGLE_REFERENCE),
+ TARGET(Type.SINGLE_REFERENCE),
+ THEN_EXPR(Type.SINGLE_REFERENCE),
+ THEN_STMT(Type.SINGLE_REFERENCE),
+ THIS(Type.SINGLE_ATTRIBUTE),
+ THROWN_EXCEPTIONS(Type.MULTIPLE_REFERENCE),
+ TRY_BLOCK(Type.SINGLE_REFERENCE),
+ TYPE(Type.SINGLE_REFERENCE),
+ TYPES(Type.MULTIPLE_REFERENCE),
+ TYPE_ARGUMENTS(Type.MULTIPLE_REFERENCE),
+ TYPE_BOUND(Type.MULTIPLE_REFERENCE),
+ TYPE_PARAMETERS(Type.MULTIPLE_REFERENCE),
+ UPDATE(Type.MULTIPLE_REFERENCE),
+ VALUE(Type.SINGLE_REFERENCE),
+ VALUES(Type.MULTIPLE_REFERENCE),
+ VARIABLE(Type.SINGLE_REFERENCE),
+ VARIABLES(Type.MULTIPLE_REFERENCE),
+ VAR_ARGS(Type.SINGLE_ATTRIBUTE),
+ VAR_ARGS_ANNOTATIONS(Type.MULTIPLE_REFERENCE),
+ WITH_TYPES(Type.MULTIPLE_REFERENCE),
+ CASCADING_IF_STMT(Type.SINGLE_ATTRIBUTE, true),
+ ELSE_BLOCK(Type.SINGLE_ATTRIBUTE, true),
+ ELSE_BRANCH(Type.SINGLE_ATTRIBUTE, true),
+ EXPRESSION_BODY(Type.SINGLE_REFERENCE, true),
+ MAXIMUM_COMMON_TYPE(Type.SINGLE_REFERENCE, true),
+ POSTFIX(Type.SINGLE_ATTRIBUTE, true),
+ PREFIX(Type.SINGLE_ATTRIBUTE, true),
+ THEN_BLOCK(Type.SINGLE_ATTRIBUTE, true),
+ USING_DIAMOND_OPERATOR(Type.SINGLE_ATTRIBUTE, true),
+ RANGE,
+ COMMENTED_NODE;
+
+ enum Type {
+
+ SINGLE_ATTRIBUTE(false, false), SINGLE_REFERENCE(false, true), MULTIPLE_ATTRIBUTE(true, false), MULTIPLE_REFERENCE(true, true);
+
+ private boolean multiple;
+
+ private boolean node;
+
+ Type(boolean multiple, boolean node) {
+ this.multiple = multiple;
+ this.node = node;
+ }
+ }
+
+ private Type type;
+
+ private boolean derived;
+
+ public static ObservableProperty fromCamelCaseName(String camelCaseName) {
+ Optional<ObservableProperty> observableProperty = Arrays.stream(values()).filter(v -> v.camelCaseName().equals(camelCaseName)).findFirst();
+ if (observableProperty.isPresent()) {
+ return observableProperty.get();
+ } else {
+ throw new IllegalArgumentException("No property found with the given camel case name: " + camelCaseName);
+ }
+ }
+
+ ObservableProperty(Type type) {
+ this.type = type;
+ this.derived = false;
+ }
+
+ ObservableProperty(Type type, boolean derived) {
+ this.type = type;
+ this.derived = derived;
+ }
+
+ ObservableProperty() {
+ this(Type.SINGLE_REFERENCE, false);
+ }
+
+ public boolean isDerived() {
+ return derived;
+ }
+
+ public boolean isAboutNodes() {
+ return type.node;
+ }
+
+ public boolean isAboutValues() {
+ return !isAboutNodes();
+ }
+
+ public boolean isMultiple() {
+ return type.multiple;
+ }
+
+ public boolean isSingle() {
+ return !isMultiple();
+ }
+
+ public String camelCaseName() {
+ return Utils.screamingToCamelCase(name());
+ }
+
+ public Node getValueAsSingleReference(Node node) {
+ Object rawValue = getRawValue(node);
+ try {
+ if (rawValue instanceof Node) {
+ return (Node) rawValue;
+ } else if (rawValue instanceof Optional) {
+ Optional<Node> opt = (Optional<Node>) rawValue;
+ if (opt.isPresent()) {
+ return opt.get();
+ } else {
+ return null;
+ }
+ } else {
+ throw new RuntimeException(String.format("Property %s returned %s (%s)", this.name(), rawValue.toString(), rawValue.getClass().getCanonicalName()));
+ }
+ } catch (ClassCastException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private boolean hasMethod(Node node, String name) {
+ try {
+ node.getClass().getMethod(name);
+ return true;
+ } catch (NoSuchMethodException e) {
+ return false;
+ }
+ }
+
+ public NodeList<? extends Node> getValueAsMultipleReference(Node node) {
+ Object rawValue = getRawValue(node);
+ try {
+ if (rawValue == null) {
+ return null;
+ }
+ if (rawValue instanceof NodeList) {
+ return (NodeList) rawValue;
+ } else {
+ Optional<NodeList> opt = (Optional<NodeList>) rawValue;
+ if (opt.isPresent()) {
+ return opt.get();
+ } else {
+ return null;
+ }
+ }
+ } catch (ClassCastException e) {
+ throw new RuntimeException("Unable to get list value for " + this.name() + " from " + node + " (class: " + node.getClass().getSimpleName() + ")", e);
+ }
+ }
+
+ public Collection<?> getValueAsCollection(Node node) {
+ Object rawValue = getRawValue(node);
+ try {
+ return (Collection) rawValue;
+ } catch (ClassCastException e) {
+ throw new RuntimeException("Unable to get list value for " + this.name() + " from " + node + " (class: " + node.getClass().getSimpleName() + ")", e);
+ }
+ }
+
+ public String getValueAsStringAttribute(Node node) {
+ return (String) getRawValue(node);
+ }
+
+ public Boolean getValueAsBooleanAttribute(Node node) {
+ return (Boolean) getRawValue(node);
+ }
+
+ public Object getRawValue(Node node) {
+ String getterName = "get" + Utils.capitalize(camelCaseName());
+ if (!hasMethod(node, getterName)) {
+ getterName = "is" + Utils.capitalize(camelCaseName());
+ if (!hasMethod(node, getterName)) {
+ getterName = "has" + Utils.capitalize(camelCaseName());
+ }
+ }
+ try {
+ return node.getClass().getMethod(getterName).invoke(node);
+ } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException("Unable to get value for " + this.name() + " from " + node + " (" + node.getClass().getSimpleName() + ")", e);
+ }
+ }
+
+ public boolean isNull(Node node) {
+ return null == getRawValue(node);
+ }
+
+ public boolean isNullOrNotPresent(Node node) {
+ Object result = getRawValue(node);
+ if (result == null) {
+ return true;
+ }
+ if (result instanceof Optional) {
+ return !((Optional) result).isPresent();
+ }
+ return false;
+ }
+
+ public boolean isNullOrEmpty(Node node) {
+ return Utils.valueIsNullOrEmpty(getRawValue(node));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/observer/PropagatingAstObserver.java b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/PropagatingAstObserver.java
new file mode 100644
index 000000000..1579474c3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/observer/PropagatingAstObserver.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.observer;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+
+/**
+ * This AstObserver attach itself to all new nodes added to the nodes already observed.
+ */
+public abstract class PropagatingAstObserver implements AstObserver {
+
+ /**
+ * Wrap a given observer to make it self-propagating. If the given observer is an instance of PropagatingAstObserver
+ * the observer is returned without changes.
+ */
+ public static PropagatingAstObserver transformInPropagatingObserver(final AstObserver observer) {
+ if (observer instanceof PropagatingAstObserver) {
+ return (PropagatingAstObserver) observer;
+ }
+ return new PropagatingAstObserver() {
+ @Override
+ public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) {
+ observer.propertyChange(observedNode, property, oldValue, newValue);
+ }
+
+ @Override
+ public void concreteListChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved) {
+ observer.listChange(observedNode, type, index, nodeAddedOrRemoved);
+ }
+
+ @Override
+ public void parentChange(Node observedNode, Node previousParent, Node newParent) {
+ observer.parentChange(observedNode, previousParent, newParent);
+ }
+ };
+ }
+
+ @Override
+ public final void propertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) {
+ considerRemoving(oldValue);
+ considerAdding(newValue);
+ concretePropertyChange(observedNode, property, oldValue, newValue);
+ }
+
+ @Override
+ public final void listChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved) {
+ if (type == ListChangeType.REMOVAL) {
+ considerRemoving(nodeAddedOrRemoved);
+ } else if (type == ListChangeType.ADDITION) {
+ considerAdding(nodeAddedOrRemoved);
+ }
+ concreteListChange(observedNode, type, index, nodeAddedOrRemoved);
+ }
+
+ @Override
+ public void listReplacement(NodeList observedNode, int index, Node oldNode, Node newNode) {
+ if (oldNode == newNode) {
+ return;
+ }
+ considerRemoving(oldNode);
+ considerAdding(newNode);
+ concreteListReplacement(observedNode, index, oldNode, newNode);
+ }
+
+ public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) {
+ // do nothing
+ }
+
+ public void concreteListChange(NodeList observedNode, ListChangeType type, int index, Node nodeAddedOrRemoved) {
+ // do nothing
+ }
+
+ public void concreteListReplacement(NodeList observedNode, int index, Node oldValue, Node newValue) {
+ // do nothing
+ }
+
+ @Override
+ public void parentChange(Node observedNode, Node previousParent, Node newParent) {
+ // do nothing
+ }
+
+ private void considerRemoving(Object element) {
+ if (element instanceof Observable) {
+ if (((Observable) element).isRegistered(this)) {
+ ((Observable) element).unregister(this);
+ }
+ }
+ }
+
+ private void considerAdding(Object element) {
+ if (element instanceof Node) {
+ ((Node) element).registerForSubtree(this);
+ } else if (element instanceof Observable) {
+ ((Observable) element).register(this);
+ }
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java
new file mode 100644
index 000000000..a6eb59fe3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/AssertStmt.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.BooleanLiteralExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.AssertStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import java.util.function.Consumer;
+
+/**
+ * A usage of the keyword "assert"
+ * <br/>In <code>assert dead : "Wasn't expecting to be dead here";</code> the check is "dead" and the message is the string.
+ * @author Julio Vilmar Gesser
+ */
+public final class AssertStmt extends Statement {
+
+ private Expression check;
+
+ @OptionalProperty
+ private Expression message;
+
+ public AssertStmt() {
+ this(null, new BooleanLiteralExpr(), null);
+ }
+
+ public AssertStmt(final Expression check) {
+ this(null, check, null);
+ }
+
+ @AllFieldsConstructor
+ public AssertStmt(final Expression check, final Expression message) {
+ this(null, check, message);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public AssertStmt(TokenRange tokenRange, Expression check, Expression message) {
+ super(tokenRange);
+ setCheck(check);
+ setMessage(message);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getCheck() {
+ return check;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getMessage() {
+ return Optional.ofNullable(message);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AssertStmt setCheck(final Expression check) {
+ assertNotNull(check);
+ if (check == this.check) {
+ return (AssertStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.CHECK, this.check, check);
+ if (this.check != null)
+ this.check.setParentNode(null);
+ this.check = check;
+ setAsParentNodeOf(check);
+ return this;
+ }
+
+ /**
+ * Sets the message
+ *
+ * @param message the message, can be null
+ * @return this, the AssertStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public AssertStmt setMessage(final Expression message) {
+ if (message == this.message) {
+ return (AssertStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.MESSAGE, this.message, message);
+ if (this.message != null)
+ this.message.setParentNode(null);
+ this.message = message;
+ setAsParentNodeOf(message);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (message != null) {
+ if (node == message) {
+ removeMessage();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public AssertStmt removeMessage() {
+ return setMessage((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public AssertStmt clone() {
+ return (AssertStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public AssertStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.assertStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == check) {
+ setCheck((Expression) replacementNode);
+ return true;
+ }
+ if (message != null) {
+ if (node == message) {
+ setMessage((Expression) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAssertStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AssertStmt asAssertStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAssertStmt(Consumer<AssertStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AssertStmt> toAssertStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java
new file mode 100644
index 000000000..3e25b9647
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BlockStmt.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.nodeTypes.NodeWithStatements;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.BlockStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Statements in between { and }.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class BlockStmt extends Statement implements NodeWithStatements<BlockStmt> {
+
+ private NodeList<Statement> statements;
+
+ public BlockStmt() {
+ this(null, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public BlockStmt(final NodeList<Statement> statements) {
+ this(null, statements);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public BlockStmt(TokenRange tokenRange, NodeList<Statement> statements) {
+ super(tokenRange);
+ setStatements(statements);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Statement> getStatements() {
+ return statements;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BlockStmt setStatements(final NodeList<Statement> statements) {
+ assertNotNull(statements);
+ if (statements == this.statements) {
+ return (BlockStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.STATEMENTS, this.statements, statements);
+ if (this.statements != null)
+ this.statements.setParentNode(null);
+ this.statements = statements;
+ setAsParentNodeOf(statements);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < statements.size(); i++) {
+ if (statements.get(i) == node) {
+ statements.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public BlockStmt clone() {
+ return (BlockStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public BlockStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.blockStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < statements.size(); i++) {
+ if (statements.get(i) == node) {
+ statements.set(i, (Statement) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBlockStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BlockStmt asBlockStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBlockStmt(Consumer<BlockStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BlockStmt> toBlockStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java
new file mode 100644
index 000000000..4a0b411c4
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/BreakStmt.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.BreakStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import java.util.function.Consumer;
+
+/**
+ * A usage of the break keyword.
+ * <br/>In <code>break abc;</code> the label is abc.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class BreakStmt extends Statement {
+
+ @OptionalProperty
+ private SimpleName label;
+
+ public BreakStmt() {
+ this(null, new SimpleName());
+ }
+
+ public BreakStmt(final String label) {
+ this(null, new SimpleName(label));
+ }
+
+ @AllFieldsConstructor
+ public BreakStmt(final SimpleName label) {
+ this(null, label);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public BreakStmt(TokenRange tokenRange, SimpleName label) {
+ super(tokenRange);
+ setLabel(label);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<SimpleName> getLabel() {
+ return Optional.ofNullable(label);
+ }
+
+ /**
+ * Sets the label
+ *
+ * @param label the label, can be null
+ * @return this, the BreakStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BreakStmt setLabel(final SimpleName label) {
+ if (label == this.label) {
+ return (BreakStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.LABEL, this.label, label);
+ if (this.label != null)
+ this.label.setParentNode(null);
+ this.label = label;
+ setAsParentNodeOf(label);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (label != null) {
+ if (node == label) {
+ removeLabel();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public BreakStmt removeLabel() {
+ return setLabel((SimpleName) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public BreakStmt clone() {
+ return (BreakStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public BreakStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.breakStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (label != null) {
+ if (node == label) {
+ setLabel((SimpleName) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBreakStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BreakStmt asBreakStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBreakStmt(Consumer<BreakStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BreakStmt> toBreakStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/CatchClause.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/CatchClause.java
new file mode 100644
index 000000000..9eaa30efe
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/CatchClause.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.Parameter;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.EnumSet;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.CatchClauseMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+
+/**
+ * The catch part of a try-catch-finally. <br/>In <code>try { ... } catch (Exception e) { ... }</code> the CatchClause
+ * is <code>catch (Exception e) { ... }</code>. Exception e is the parameter. The { ... } is the body.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class CatchClause extends Node implements NodeWithBlockStmt<CatchClause> {
+
+ private Parameter parameter;
+
+ private BlockStmt body;
+
+ public CatchClause() {
+ this(null, new Parameter(), new BlockStmt());
+ }
+
+ public CatchClause(final EnumSet<Modifier> exceptModifier, final NodeList<AnnotationExpr> exceptAnnotations, final ClassOrInterfaceType exceptType, final SimpleName exceptName, final BlockStmt body) {
+ this(null, new Parameter(null, exceptModifier, exceptAnnotations, exceptType, false, new NodeList<>(), exceptName), body);
+ }
+
+ @AllFieldsConstructor
+ public CatchClause(final Parameter parameter, final BlockStmt body) {
+ this(null, parameter, body);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public CatchClause(TokenRange tokenRange, Parameter parameter, BlockStmt body) {
+ super(tokenRange);
+ setParameter(parameter);
+ setBody(body);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ /**
+ * Note that the type of the Parameter can be a UnionType. In this case, any annotations found at the start of the
+ * catch(@X A a |...) are found directly in the Parameter. Annotations that are on the second or later type -
+ * catch(A a | @X B b ...) are found on those types.
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Parameter getParameter() {
+ return parameter;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public CatchClause setParameter(final Parameter parameter) {
+ assertNotNull(parameter);
+ if (parameter == this.parameter) {
+ return (CatchClause) this;
+ }
+ notifyPropertyChange(ObservableProperty.PARAMETER, this.parameter, parameter);
+ if (this.parameter != null)
+ this.parameter.setParentNode(null);
+ this.parameter = parameter;
+ setAsParentNodeOf(parameter);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BlockStmt getBody() {
+ return body;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public CatchClause setBody(final BlockStmt body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (CatchClause) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public CatchClause clone() {
+ return (CatchClause) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public CatchClauseMetaModel getMetaModel() {
+ return JavaParserMetaModel.catchClauseMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((BlockStmt) replacementNode);
+ return true;
+ }
+ if (node == parameter) {
+ setParameter((Parameter) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java
new file mode 100644
index 000000000..b82995084
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ContinueStmt.java
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithOptionalLabel;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ContinueStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import java.util.function.Consumer;
+
+/**
+ * A continue statement with an optional label;
+ * <br/><code>continue brains;</code>
+ * <br/><code>continue;</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ContinueStmt extends Statement implements NodeWithOptionalLabel<ContinueStmt> {
+
+ @OptionalProperty
+ private SimpleName label;
+
+ public ContinueStmt() {
+ this(null, null);
+ }
+
+ public ContinueStmt(final String label) {
+ this(null, new SimpleName(label));
+ }
+
+ @AllFieldsConstructor
+ public ContinueStmt(final SimpleName label) {
+ this(null, label);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ContinueStmt(TokenRange tokenRange, SimpleName label) {
+ super(tokenRange);
+ setLabel(label);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<SimpleName> getLabel() {
+ return Optional.ofNullable(label);
+ }
+
+ /**
+ * Sets the label
+ *
+ * @param label the label, can be null
+ * @return this, the ContinueStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ContinueStmt setLabel(final SimpleName label) {
+ if (label == this.label) {
+ return (ContinueStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.LABEL, this.label, label);
+ if (this.label != null)
+ this.label.setParentNode(null);
+ this.label = label;
+ setAsParentNodeOf(label);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (label != null) {
+ if (node == label) {
+ removeLabel();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ContinueStmt removeLabel() {
+ return setLabel((SimpleName) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ContinueStmt clone() {
+ return (ContinueStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ContinueStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.continueStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (label != null) {
+ if (node == label) {
+ setLabel((SimpleName) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isContinueStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ContinueStmt asContinueStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifContinueStmt(Consumer<ContinueStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ContinueStmt> toContinueStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java
new file mode 100644
index 000000000..7c161ff8d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/DoStmt.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.BooleanLiteralExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.nodeTypes.NodeWithBody;
+import com.github.javaparser.ast.nodeTypes.NodeWithCondition;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.DoStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A do-while.
+ * <br/><code>do { ... } while ( a==0 );</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class DoStmt extends Statement implements NodeWithBody<DoStmt>, NodeWithCondition<DoStmt> {
+
+ private Statement body;
+
+ private Expression condition;
+
+ public DoStmt() {
+ this(null, new ReturnStmt(), new BooleanLiteralExpr());
+ }
+
+ @AllFieldsConstructor
+ public DoStmt(final Statement body, final Expression condition) {
+ this(null, body, condition);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public DoStmt(TokenRange tokenRange, Statement body, Expression condition) {
+ super(tokenRange);
+ setBody(body);
+ setCondition(condition);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Statement getBody() {
+ return body;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getCondition() {
+ return condition;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public DoStmt setBody(final Statement body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (DoStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public DoStmt setCondition(final Expression condition) {
+ assertNotNull(condition);
+ if (condition == this.condition) {
+ return (DoStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition);
+ if (this.condition != null)
+ this.condition.setParentNode(null);
+ this.condition = condition;
+ setAsParentNodeOf(condition);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public DoStmt clone() {
+ return (DoStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public DoStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.doStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((Statement) replacementNode);
+ return true;
+ }
+ if (node == condition) {
+ setCondition((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isDoStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public DoStmt asDoStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifDoStmt(Consumer<DoStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<DoStmt> toDoStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/EmptyStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/EmptyStmt.java
new file mode 100644
index 000000000..d73ede61b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/EmptyStmt.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.EmptyStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An empty statement is a ";" where a statement is expected.
+ * @author Julio Vilmar Gesser
+ */
+public final class EmptyStmt extends Statement {
+
+ @AllFieldsConstructor
+ public EmptyStmt() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public EmptyStmt(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public EmptyStmt clone() {
+ return (EmptyStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public EmptyStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.emptyStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isEmptyStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public EmptyStmt asEmptyStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifEmptyStmt(Consumer<EmptyStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<EmptyStmt> toEmptyStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java
new file mode 100644
index 000000000..2b9b9c200
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExplicitConstructorInvocationStmt.java
@@ -0,0 +1,299 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ExplicitConstructorInvocationStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
+import java.util.function.Consumer;
+
+/**
+ * A call to super or this in a constructor or initializer.
+ * <br/><code>class X { X() { super(15); } }</code>
+ * <br/><code>class X { X() { this(1, 2); } }</code>
+ *
+ * @author Julio Vilmar Gesser
+ * @see com.github.javaparser.ast.expr.SuperExpr
+ * @see com.github.javaparser.ast.expr.ThisExpr
+ */
+public final class ExplicitConstructorInvocationStmt extends Statement implements NodeWithTypeArguments<ExplicitConstructorInvocationStmt> {
+
+ @OptionalProperty
+ private NodeList<Type> typeArguments;
+
+ private boolean isThis;
+
+ @OptionalProperty
+ private Expression expression;
+
+ private NodeList<Expression> arguments;
+
+ public ExplicitConstructorInvocationStmt() {
+ this(null, new NodeList<>(), true, null, new NodeList<>());
+ }
+
+ public ExplicitConstructorInvocationStmt(final boolean isThis, final Expression expression, final NodeList<Expression> arguments) {
+ this(null, new NodeList<>(), isThis, expression, arguments);
+ }
+
+ @AllFieldsConstructor
+ public ExplicitConstructorInvocationStmt(final NodeList<Type> typeArguments, final boolean isThis, final Expression expression, final NodeList<Expression> arguments) {
+ this(null, typeArguments, isThis, expression, arguments);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ExplicitConstructorInvocationStmt(TokenRange tokenRange, NodeList<Type> typeArguments, boolean isThis, Expression expression, NodeList<Expression> arguments) {
+ super(tokenRange);
+ setTypeArguments(typeArguments);
+ setThis(isThis);
+ setExpression(expression);
+ setArguments(arguments);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Expression> getArguments() {
+ return arguments;
+ }
+
+ public Expression getArgument(int i) {
+ return getArguments().get(i);
+ }
+
+ public ExplicitConstructorInvocationStmt setArgument(int i, Expression argument) {
+ getArguments().set(i, argument);
+ return this;
+ }
+
+ public ExplicitConstructorInvocationStmt addArgument(Expression argument) {
+ getArguments().add(argument);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getExpression() {
+ return Optional.ofNullable(expression);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public boolean isThis() {
+ return isThis;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ExplicitConstructorInvocationStmt setArguments(final NodeList<Expression> arguments) {
+ assertNotNull(arguments);
+ if (arguments == this.arguments) {
+ return (ExplicitConstructorInvocationStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.ARGUMENTS, this.arguments, arguments);
+ if (this.arguments != null)
+ this.arguments.setParentNode(null);
+ this.arguments = arguments;
+ setAsParentNodeOf(arguments);
+ return this;
+ }
+
+ /**
+ * Sets the expression
+ *
+ * @param expression the expression, can be null
+ * @return this, the ExplicitConstructorInvocationStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ExplicitConstructorInvocationStmt setExpression(final Expression expression) {
+ if (expression == this.expression) {
+ return (ExplicitConstructorInvocationStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression);
+ if (this.expression != null)
+ this.expression.setParentNode(null);
+ this.expression = expression;
+ setAsParentNodeOf(expression);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ExplicitConstructorInvocationStmt setThis(final boolean isThis) {
+ if (isThis == this.isThis) {
+ return (ExplicitConstructorInvocationStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.THIS, this.isThis, isThis);
+ this.isThis = isThis;
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<NodeList<Type>> getTypeArguments() {
+ return Optional.ofNullable(typeArguments);
+ }
+
+ /**
+ * Sets the typeArguments
+ *
+ * @param typeArguments the typeArguments, can be null
+ * @return this, the ExplicitConstructorInvocationStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ExplicitConstructorInvocationStmt setTypeArguments(final NodeList<Type> typeArguments) {
+ if (typeArguments == this.typeArguments) {
+ return (ExplicitConstructorInvocationStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments);
+ if (this.typeArguments != null)
+ this.typeArguments.setParentNode(null);
+ this.typeArguments = typeArguments;
+ setAsParentNodeOf(typeArguments);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments.get(i) == node) {
+ arguments.remove(i);
+ return true;
+ }
+ }
+ if (expression != null) {
+ if (node == expression) {
+ removeExpression();
+ return true;
+ }
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.remove(i);
+ return true;
+ }
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ExplicitConstructorInvocationStmt removeExpression() {
+ return setExpression((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ExplicitConstructorInvocationStmt clone() {
+ return (ExplicitConstructorInvocationStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ExplicitConstructorInvocationStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.explicitConstructorInvocationStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < arguments.size(); i++) {
+ if (arguments.get(i) == node) {
+ arguments.set(i, (Expression) replacementNode);
+ return true;
+ }
+ }
+ if (expression != null) {
+ if (node == expression) {
+ setExpression((Expression) replacementNode);
+ return true;
+ }
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.set(i, (Type) replacementNode);
+ return true;
+ }
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isExplicitConstructorInvocationStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ExplicitConstructorInvocationStmt asExplicitConstructorInvocationStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifExplicitConstructorInvocationStmt(Consumer<ExplicitConstructorInvocationStmt> action) {
+ action.accept(this);
+ }
+
+ public ResolvedConstructorDeclaration resolveInvokedConstructor() {
+ return getSymbolResolver().resolveDeclaration(this, ResolvedConstructorDeclaration.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ExplicitConstructorInvocationStmt> toExplicitConstructorInvocationStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExpressionStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExpressionStmt.java
new file mode 100644
index 000000000..483c45dee
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ExpressionStmt.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.BooleanLiteralExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.nodeTypes.NodeWithExpression;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ExpressionStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Used to wrap an expression so that it can take the place of a statement.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ExpressionStmt extends Statement implements NodeWithExpression<ExpressionStmt> {
+
+ private Expression expression;
+
+ public ExpressionStmt() {
+ this(null, new BooleanLiteralExpr());
+ }
+
+ @AllFieldsConstructor
+ public ExpressionStmt(final Expression expression) {
+ this(null, expression);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ExpressionStmt(TokenRange tokenRange, Expression expression) {
+ super(tokenRange);
+ setExpression(expression);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getExpression() {
+ return expression;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ExpressionStmt setExpression(final Expression expression) {
+ assertNotNull(expression);
+ if (expression == this.expression) {
+ return (ExpressionStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression);
+ if (this.expression != null)
+ this.expression.setParentNode(null);
+ this.expression = expression;
+ setAsParentNodeOf(expression);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ExpressionStmt clone() {
+ return (ExpressionStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ExpressionStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.expressionStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == expression) {
+ setExpression((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isExpressionStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ExpressionStmt asExpressionStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifExpressionStmt(Consumer<ExpressionStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ExpressionStmt> toExpressionStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java
new file mode 100644
index 000000000..d288991df
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForStmt.java
@@ -0,0 +1,290 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.BooleanLiteralExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.nodeTypes.NodeWithBody;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.ForStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.OptionalProperty;
+import javax.annotation.Generated;
+import java.util.Optional;
+import java.util.function.Consumer;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * <h1>The classic for statement</h1>
+ * Examples:
+ * <ol>
+ * <li><code>for(int a=3, b=5; a<99; a++, b++) hello();</code></li>
+ * <li><code>for(a=3, b=5; a<99; a++) { hello(); }</code> </li>
+ * <li><code>for(a(),b();;) hello();</code> </li>
+ * </ol>
+ * <ul>
+ * <li><i>initialization</i> is a list of expressions.
+ * These can be any kind of expression as can be seen in example 3,
+ * but the common ones are a single VariableDeclarationExpr (which declares multiple variables) in example 1,
+ * or a list of AssignExpr's in example 2.</li>
+ * <li><i>compare</i> is an expression,
+ * in example 1 and 2 it is a BinaryExpr.
+ * In example 3 there is no expression, it is empty.</li>
+ * <li><i>update</i> is a list of expressions,
+ * in example 1 and 2 they are UnaryExpr's.
+ * In example 3 there is no expression, the list empty.</li>
+ * <li><i>body</i> is a statement,
+ * in example 1 and 3 it is an ExpressionStmt.
+ * in example 2 it is a BlockStmt.</li>
+ * </ul>
+ *
+ * @author Julio Vilmar Gesser
+ * @see com.github.javaparser.ast.expr.VariableDeclarationExpr
+ */
+public final class ForStmt extends Statement implements NodeWithBody<ForStmt> {
+
+ private NodeList<Expression> initialization;
+
+ @OptionalProperty
+ private Expression compare;
+
+ private NodeList<Expression> update;
+
+ private Statement body;
+
+ public ForStmt() {
+ this(null, new NodeList<>(), new BooleanLiteralExpr(), new NodeList<>(), new ReturnStmt());
+ }
+
+ @AllFieldsConstructor
+ public ForStmt(final NodeList<Expression> initialization, final Expression compare, final NodeList<Expression> update, final Statement body) {
+ this(null, initialization, compare, update, body);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ForStmt(TokenRange tokenRange, NodeList<Expression> initialization, Expression compare, NodeList<Expression> update, Statement body) {
+ super(tokenRange);
+ setInitialization(initialization);
+ setCompare(compare);
+ setUpdate(update);
+ setBody(body);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Statement getBody() {
+ return body;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getCompare() {
+ return Optional.ofNullable(compare);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Expression> getInitialization() {
+ return initialization;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Expression> getUpdate() {
+ return update;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ForStmt setBody(final Statement body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (ForStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ /**
+ * Sets the compare
+ *
+ * @param compare the compare, can be null
+ * @return this, the ForStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ForStmt setCompare(final Expression compare) {
+ if (compare == this.compare) {
+ return (ForStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.COMPARE, this.compare, compare);
+ if (this.compare != null)
+ this.compare.setParentNode(null);
+ this.compare = compare;
+ setAsParentNodeOf(compare);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ForStmt setInitialization(final NodeList<Expression> initialization) {
+ assertNotNull(initialization);
+ if (initialization == this.initialization) {
+ return (ForStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.INITIALIZATION, this.initialization, initialization);
+ if (this.initialization != null)
+ this.initialization.setParentNode(null);
+ this.initialization = initialization;
+ setAsParentNodeOf(initialization);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ForStmt setUpdate(final NodeList<Expression> update) {
+ assertNotNull(update);
+ if (update == this.update) {
+ return (ForStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.UPDATE, this.update, update);
+ if (this.update != null)
+ this.update.setParentNode(null);
+ this.update = update;
+ setAsParentNodeOf(update);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (compare != null) {
+ if (node == compare) {
+ removeCompare();
+ return true;
+ }
+ }
+ for (int i = 0; i < initialization.size(); i++) {
+ if (initialization.get(i) == node) {
+ initialization.remove(i);
+ return true;
+ }
+ }
+ for (int i = 0; i < update.size(); i++) {
+ if (update.get(i) == node) {
+ update.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ForStmt removeCompare() {
+ return setCompare((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ForStmt clone() {
+ return (ForStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ForStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.forStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((Statement) replacementNode);
+ return true;
+ }
+ if (compare != null) {
+ if (node == compare) {
+ setCompare((Expression) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < initialization.size(); i++) {
+ if (initialization.get(i) == node) {
+ initialization.set(i, (Expression) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < update.size(); i++) {
+ if (update.get(i) == node) {
+ update.set(i, (Expression) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isForStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ForStmt asForStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifForStmt(Consumer<ForStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ForStmt> toForStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForeachStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForeachStmt.java
new file mode 100644
index 000000000..7a04e5bcb
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ForeachStmt.java
@@ -0,0 +1,211 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.expr.VariableDeclarationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithBody;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ForeachStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A for-each statement.
+ * <br/><code>for(Object o: objects) { ... }</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ForeachStmt extends Statement implements NodeWithBody<ForeachStmt> {
+
+ private VariableDeclarationExpr variable;
+
+ private Expression iterable;
+
+ private Statement body;
+
+ public ForeachStmt() {
+ this(null, new VariableDeclarationExpr(), new NameExpr(), new ReturnStmt());
+ }
+
+ @AllFieldsConstructor
+ public ForeachStmt(final VariableDeclarationExpr variable, final Expression iterable, final Statement body) {
+ this(null, variable, iterable, body);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ForeachStmt(TokenRange tokenRange, VariableDeclarationExpr variable, Expression iterable, Statement body) {
+ super(tokenRange);
+ setVariable(variable);
+ setIterable(iterable);
+ setBody(body);
+ customInitialization();
+ }
+
+ public ForeachStmt(VariableDeclarationExpr variable, String iterable, BlockStmt body) {
+ this(null, variable, new NameExpr(iterable), body);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Statement getBody() {
+ return body;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getIterable() {
+ return iterable;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public VariableDeclarationExpr getVariable() {
+ return variable;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ForeachStmt setBody(final Statement body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (ForeachStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ForeachStmt setIterable(final Expression iterable) {
+ assertNotNull(iterable);
+ if (iterable == this.iterable) {
+ return (ForeachStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.ITERABLE, this.iterable, iterable);
+ if (this.iterable != null)
+ this.iterable.setParentNode(null);
+ this.iterable = iterable;
+ setAsParentNodeOf(iterable);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ForeachStmt setVariable(final VariableDeclarationExpr variable) {
+ assertNotNull(variable);
+ if (variable == this.variable) {
+ return (ForeachStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.VARIABLE, this.variable, variable);
+ if (this.variable != null)
+ this.variable.setParentNode(null);
+ this.variable = variable;
+ setAsParentNodeOf(variable);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ForeachStmt clone() {
+ return (ForeachStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ForeachStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.foreachStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((Statement) replacementNode);
+ return true;
+ }
+ if (node == iterable) {
+ setIterable((Expression) replacementNode);
+ return true;
+ }
+ if (node == variable) {
+ setVariable((VariableDeclarationExpr) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isForeachStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ForeachStmt asForeachStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifForeachStmt(Consumer<ForeachStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ForeachStmt> toForeachStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java
new file mode 100644
index 000000000..f873ff89a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/IfStmt.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.BooleanLiteralExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.nodeTypes.NodeWithCondition;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.DerivedProperty;
+import com.github.javaparser.metamodel.IfStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import java.util.function.Consumer;
+
+/**
+ * An if-then-else statement. The else is optional.
+ * <br/>In <code>if(a==5) hurray() else boo();</code> the condition is a==5,
+ * hurray() is the thenStmt, and boo() is the elseStmt.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class IfStmt extends Statement implements NodeWithCondition<IfStmt> {
+
+ private Expression condition;
+
+ private Statement thenStmt;
+
+ @OptionalProperty
+ private Statement elseStmt;
+
+ public IfStmt() {
+ this(null, new BooleanLiteralExpr(), new ReturnStmt(), null);
+ }
+
+ @AllFieldsConstructor
+ public IfStmt(final Expression condition, final Statement thenStmt, final Statement elseStmt) {
+ this(null, condition, thenStmt, elseStmt);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public IfStmt(TokenRange tokenRange, Expression condition, Statement thenStmt, Statement elseStmt) {
+ super(tokenRange);
+ setCondition(condition);
+ setThenStmt(thenStmt);
+ setElseStmt(elseStmt);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getCondition() {
+ return condition;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Statement> getElseStmt() {
+ return Optional.ofNullable(elseStmt);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Statement getThenStmt() {
+ return thenStmt;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public IfStmt setCondition(final Expression condition) {
+ assertNotNull(condition);
+ if (condition == this.condition) {
+ return (IfStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition);
+ if (this.condition != null)
+ this.condition.setParentNode(null);
+ this.condition = condition;
+ setAsParentNodeOf(condition);
+ return this;
+ }
+
+ /**
+ * Sets the elseStmt
+ *
+ * @param elseStmt the elseStmt, can be null
+ * @return this, the IfStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public IfStmt setElseStmt(final Statement elseStmt) {
+ if (elseStmt == this.elseStmt) {
+ return (IfStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.ELSE_STMT, this.elseStmt, elseStmt);
+ if (this.elseStmt != null)
+ this.elseStmt.setParentNode(null);
+ this.elseStmt = elseStmt;
+ setAsParentNodeOf(elseStmt);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public IfStmt setThenStmt(final Statement thenStmt) {
+ assertNotNull(thenStmt);
+ if (thenStmt == this.thenStmt) {
+ return (IfStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.THEN_STMT, this.thenStmt, thenStmt);
+ if (this.thenStmt != null)
+ this.thenStmt.setParentNode(null);
+ this.thenStmt = thenStmt;
+ setAsParentNodeOf(thenStmt);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (elseStmt != null) {
+ if (node == elseStmt) {
+ removeElseStmt();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public IfStmt removeElseStmt() {
+ return setElseStmt((Statement) null);
+ }
+
+ /**
+ * This method returns true if the then branch (which should be always present) is a block statement.
+ */
+ @DerivedProperty
+ public boolean hasThenBlock() {
+ return thenStmt instanceof BlockStmt;
+ }
+
+ /**
+ * This method returns true if the If Statement has an else branch and that branch is a block statement.
+ */
+ @DerivedProperty
+ public boolean hasElseBlock() {
+ return elseStmt instanceof BlockStmt;
+ }
+
+ /**
+ * This method returns true if the If Statement has an else branch and that branch is another If Statement.
+ */
+ @DerivedProperty
+ public boolean hasCascadingIfStmt() {
+ return elseStmt instanceof IfStmt;
+ }
+
+ /**
+ * This method returns true if the If Statement has an else branch.
+ */
+ @DerivedProperty
+ public boolean hasElseBranch() {
+ return elseStmt != null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public IfStmt clone() {
+ return (IfStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public IfStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.ifStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == condition) {
+ setCondition((Expression) replacementNode);
+ return true;
+ }
+ if (elseStmt != null) {
+ if (node == elseStmt) {
+ setElseStmt((Statement) replacementNode);
+ return true;
+ }
+ }
+ if (node == thenStmt) {
+ setThenStmt((Statement) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isIfStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public IfStmt asIfStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifIfStmt(Consumer<IfStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<IfStmt> toIfStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LabeledStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LabeledStmt.java
new file mode 100644
index 000000000..7906d0c6a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LabeledStmt.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.LabeledStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A statement that is labeled, like <code>label123: println("continuing");</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class LabeledStmt extends Statement {
+
+ private SimpleName label;
+
+ private Statement statement;
+
+ public LabeledStmt() {
+ this(null, new SimpleName(), new ReturnStmt());
+ }
+
+ public LabeledStmt(final String label, final Statement statement) {
+ this(null, new SimpleName(label), statement);
+ }
+
+ @AllFieldsConstructor
+ public LabeledStmt(final SimpleName label, final Statement statement) {
+ this(null, label, statement);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public LabeledStmt(TokenRange tokenRange, SimpleName label, Statement statement) {
+ super(tokenRange);
+ setLabel(label);
+ setStatement(statement);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Statement getStatement() {
+ return statement;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public LabeledStmt setStatement(final Statement statement) {
+ assertNotNull(statement);
+ if (statement == this.statement) {
+ return (LabeledStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.STATEMENT, this.statement, statement);
+ if (this.statement != null)
+ this.statement.setParentNode(null);
+ this.statement = statement;
+ setAsParentNodeOf(statement);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getLabel() {
+ return label;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public LabeledStmt setLabel(final SimpleName label) {
+ assertNotNull(label);
+ if (label == this.label) {
+ return (LabeledStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.LABEL, this.label, label);
+ if (this.label != null)
+ this.label.setParentNode(null);
+ this.label = label;
+ setAsParentNodeOf(label);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public LabeledStmt clone() {
+ return (LabeledStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public LabeledStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.labeledStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == label) {
+ setLabel((SimpleName) replacementNode);
+ return true;
+ }
+ if (node == statement) {
+ setStatement((Statement) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLabeledStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LabeledStmt asLabeledStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLabeledStmt(Consumer<LabeledStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LabeledStmt> toLabeledStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java
new file mode 100644
index 000000000..f78eebc3d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/LocalClassDeclarationStmt.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.LocalClassDeclarationStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * <h1>A class declaration inside a method.</h1>
+ * <h2>Java 1.0</h2>
+ * Not available.
+ * <h2>Java 1.1+</h2>
+ * A statement consisting of a class declaration.
+ * <br/><code>class X { void m() { <b>class Y { }</b> } }</code>
+ *
+ * @see ClassOrInterfaceDeclaration
+ * @author Julio Vilmar Gesser
+ */
+public final class LocalClassDeclarationStmt extends Statement {
+
+ private ClassOrInterfaceDeclaration classDeclaration;
+
+ public LocalClassDeclarationStmt() {
+ this(null, new ClassOrInterfaceDeclaration());
+ }
+
+ @AllFieldsConstructor
+ public LocalClassDeclarationStmt(final ClassOrInterfaceDeclaration classDeclaration) {
+ this(null, classDeclaration);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public LocalClassDeclarationStmt(TokenRange tokenRange, ClassOrInterfaceDeclaration classDeclaration) {
+ super(tokenRange);
+ setClassDeclaration(classDeclaration);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceDeclaration getClassDeclaration() {
+ return classDeclaration;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public LocalClassDeclarationStmt setClassDeclaration(final ClassOrInterfaceDeclaration classDeclaration) {
+ assertNotNull(classDeclaration);
+ if (classDeclaration == this.classDeclaration) {
+ return (LocalClassDeclarationStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.CLASS_DECLARATION, this.classDeclaration, classDeclaration);
+ if (this.classDeclaration != null)
+ this.classDeclaration.setParentNode(null);
+ this.classDeclaration = classDeclaration;
+ setAsParentNodeOf(classDeclaration);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public LocalClassDeclarationStmt clone() {
+ return (LocalClassDeclarationStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public LocalClassDeclarationStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.localClassDeclarationStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == classDeclaration) {
+ setClassDeclaration((ClassOrInterfaceDeclaration) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLocalClassDeclarationStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LocalClassDeclarationStmt asLocalClassDeclarationStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLocalClassDeclarationStmt(Consumer<LocalClassDeclarationStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LocalClassDeclarationStmt> toLocalClassDeclarationStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java
new file mode 100644
index 000000000..c9bdb4583
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ReturnStmt.java
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.metamodel.ReturnStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+
+/**
+ * The return statement, with an optional expression to return.
+ * <br/><code>return 5 * 5;</code>
+ * @author Julio Vilmar Gesser
+ */
+public final class ReturnStmt extends Statement {
+
+ @OptionalProperty
+ private Expression expression;
+
+ public ReturnStmt() {
+ this(null, null);
+ }
+
+ @AllFieldsConstructor
+ public ReturnStmt(final Expression expression) {
+ this(null, expression);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ReturnStmt(TokenRange tokenRange, Expression expression) {
+ super(tokenRange);
+ setExpression(expression);
+ customInitialization();
+ }
+
+ /**
+ * Will create a NameExpr with the string param
+ */
+ public ReturnStmt(String expression) {
+ this(null, new NameExpr(expression));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getExpression() {
+ return Optional.ofNullable(expression);
+ }
+
+ /**
+ * Sets the expression
+ *
+ * @param expression the expression, can be null
+ * @return this, the ReturnStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ReturnStmt setExpression(final Expression expression) {
+ if (expression == this.expression) {
+ return (ReturnStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression);
+ if (this.expression != null)
+ this.expression.setParentNode(null);
+ this.expression = expression;
+ setAsParentNodeOf(expression);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (expression != null) {
+ if (node == expression) {
+ removeExpression();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ReturnStmt removeExpression() {
+ return setExpression((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ReturnStmt clone() {
+ return (ReturnStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ReturnStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.returnStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (expression != null) {
+ if (node == expression) {
+ setExpression((Expression) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isReturnStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ReturnStmt asReturnStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifReturnStmt(Consumer<ReturnStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ReturnStmt> toReturnStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/Statement.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/Statement.java
new file mode 100644
index 000000000..75100e829
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/Statement.java
@@ -0,0 +1,481 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.StatementMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+import java.util.Optional;
+
+/**
+ * A base class for all statements.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class Statement extends Node {
+
+ @AllFieldsConstructor
+ public Statement() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public Statement(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public Statement clone() {
+ return (Statement) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public StatementMetaModel getMetaModel() {
+ return JavaParserMetaModel.statementMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isAssertStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public AssertStmt asAssertStmt() {
+ throw new IllegalStateException(f("%s is not an AssertStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBlockStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BlockStmt asBlockStmt() {
+ throw new IllegalStateException(f("%s is not an BlockStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isBreakStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public BreakStmt asBreakStmt() {
+ throw new IllegalStateException(f("%s is not an BreakStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isContinueStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ContinueStmt asContinueStmt() {
+ throw new IllegalStateException(f("%s is not an ContinueStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isDoStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public DoStmt asDoStmt() {
+ throw new IllegalStateException(f("%s is not an DoStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isEmptyStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public EmptyStmt asEmptyStmt() {
+ throw new IllegalStateException(f("%s is not an EmptyStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isExplicitConstructorInvocationStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ExplicitConstructorInvocationStmt asExplicitConstructorInvocationStmt() {
+ throw new IllegalStateException(f("%s is not an ExplicitConstructorInvocationStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isExpressionStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ExpressionStmt asExpressionStmt() {
+ throw new IllegalStateException(f("%s is not an ExpressionStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isForStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ForStmt asForStmt() {
+ throw new IllegalStateException(f("%s is not an ForStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isForeachStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ForeachStmt asForeachStmt() {
+ throw new IllegalStateException(f("%s is not an ForeachStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isIfStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public IfStmt asIfStmt() {
+ throw new IllegalStateException(f("%s is not an IfStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLabeledStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LabeledStmt asLabeledStmt() {
+ throw new IllegalStateException(f("%s is not an LabeledStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isLocalClassDeclarationStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public LocalClassDeclarationStmt asLocalClassDeclarationStmt() {
+ throw new IllegalStateException(f("%s is not an LocalClassDeclarationStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isReturnStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ReturnStmt asReturnStmt() {
+ throw new IllegalStateException(f("%s is not an ReturnStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSwitchEntryStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SwitchEntryStmt asSwitchEntryStmt() {
+ throw new IllegalStateException(f("%s is not an SwitchEntryStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSwitchStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SwitchStmt asSwitchStmt() {
+ throw new IllegalStateException(f("%s is not an SwitchStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSynchronizedStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SynchronizedStmt asSynchronizedStmt() {
+ throw new IllegalStateException(f("%s is not an SynchronizedStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isThrowStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ThrowStmt asThrowStmt() {
+ throw new IllegalStateException(f("%s is not an ThrowStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isTryStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public TryStmt asTryStmt() {
+ throw new IllegalStateException(f("%s is not an TryStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isUnparsableStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public UnparsableStmt asUnparsableStmt() {
+ throw new IllegalStateException(f("%s is not an UnparsableStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isWhileStmt() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public WhileStmt asWhileStmt() {
+ throw new IllegalStateException(f("%s is not an WhileStmt", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifAssertStmt(Consumer<AssertStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBlockStmt(Consumer<BlockStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifBreakStmt(Consumer<BreakStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifContinueStmt(Consumer<ContinueStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifDoStmt(Consumer<DoStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifEmptyStmt(Consumer<EmptyStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifExplicitConstructorInvocationStmt(Consumer<ExplicitConstructorInvocationStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifExpressionStmt(Consumer<ExpressionStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifForStmt(Consumer<ForStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifForeachStmt(Consumer<ForeachStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifIfStmt(Consumer<IfStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLabeledStmt(Consumer<LabeledStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifLocalClassDeclarationStmt(Consumer<LocalClassDeclarationStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifReturnStmt(Consumer<ReturnStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSwitchEntryStmt(Consumer<SwitchEntryStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSwitchStmt(Consumer<SwitchStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSynchronizedStmt(Consumer<SynchronizedStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifThrowStmt(Consumer<ThrowStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifTryStmt(Consumer<TryStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifUnparsableStmt(Consumer<UnparsableStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifWhileStmt(Consumer<WhileStmt> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<AssertStmt> toAssertStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BlockStmt> toBlockStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<BreakStmt> toBreakStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ContinueStmt> toContinueStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<DoStmt> toDoStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<EmptyStmt> toEmptyStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ExplicitConstructorInvocationStmt> toExplicitConstructorInvocationStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ExpressionStmt> toExpressionStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ForStmt> toForStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ForeachStmt> toForeachStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<IfStmt> toIfStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LabeledStmt> toLabeledStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<LocalClassDeclarationStmt> toLocalClassDeclarationStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ReturnStmt> toReturnStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SwitchEntryStmt> toSwitchEntryStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SwitchStmt> toSwitchStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SynchronizedStmt> toSynchronizedStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ThrowStmt> toThrowStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<TryStmt> toTryStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<UnparsableStmt> toUnparsableStmt() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<WhileStmt> toWhileStmt() {
+ return Optional.empty();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java
new file mode 100644
index 000000000..afa8fcecb
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchEntryStmt.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.nodeTypes.NodeWithStatements;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.metamodel.SwitchEntryStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+
+/**
+ * One case in a switch statement.
+ * <br/><pre>
+ * switch (i) {
+ * case 1:
+ * case 2:
+ * System.out.println(444);
+ * break;
+ * default:
+ * System.out.println(0);
+ * }
+ * </pre>
+ * This contains three SwitchEntryStmts.
+ * <br/>The first one has label 1 and no statements.
+ * <br/>The second has label 2 and two statements (the println and the break).
+ * <br/>The third, the default, has no label and one statement.
+ *
+ * @author Julio Vilmar Gesser
+ * @see SwitchStmt
+ */
+public final class SwitchEntryStmt extends Statement implements NodeWithStatements<SwitchEntryStmt> {
+
+ @OptionalProperty
+ private Expression label;
+
+ private NodeList<Statement> statements;
+
+ public SwitchEntryStmt() {
+ this(null, null, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public SwitchEntryStmt(final Expression label, final NodeList<Statement> statements) {
+ this(null, label, statements);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public SwitchEntryStmt(TokenRange tokenRange, Expression label, NodeList<Statement> statements) {
+ super(tokenRange);
+ setLabel(label);
+ setStatements(statements);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<Expression> getLabel() {
+ return Optional.ofNullable(label);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Statement> getStatements() {
+ return statements;
+ }
+
+ /**
+ * Sets the label
+ *
+ * @param label the label, can be null
+ * @return this, the SwitchEntryStmt
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SwitchEntryStmt setLabel(final Expression label) {
+ if (label == this.label) {
+ return (SwitchEntryStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.LABEL, this.label, label);
+ if (this.label != null)
+ this.label.setParentNode(null);
+ this.label = label;
+ setAsParentNodeOf(label);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SwitchEntryStmt setStatements(final NodeList<Statement> statements) {
+ assertNotNull(statements);
+ if (statements == this.statements) {
+ return (SwitchEntryStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.STATEMENTS, this.statements, statements);
+ if (this.statements != null)
+ this.statements.setParentNode(null);
+ this.statements = statements;
+ setAsParentNodeOf(statements);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (label != null) {
+ if (node == label) {
+ removeLabel();
+ return true;
+ }
+ }
+ for (int i = 0; i < statements.size(); i++) {
+ if (statements.get(i) == node) {
+ statements.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public SwitchEntryStmt removeLabel() {
+ return setLabel((Expression) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public SwitchEntryStmt clone() {
+ return (SwitchEntryStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public SwitchEntryStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.switchEntryStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (label != null) {
+ if (node == label) {
+ setLabel((Expression) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < statements.size(); i++) {
+ if (statements.get(i) == node) {
+ statements.set(i, (Statement) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSwitchEntryStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SwitchEntryStmt asSwitchEntryStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSwitchEntryStmt(Consumer<SwitchEntryStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SwitchEntryStmt> toSwitchEntryStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchStmt.java
new file mode 100644
index 000000000..36e88b27c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SwitchStmt.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.SwitchStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A switch statement.
+ * <br/>In <code>switch(a) { ... }</code> the selector is "a",
+ * and the contents of the { ... } are the entries.
+ *
+ * @author Julio Vilmar Gesser
+ * @see SwitchEntryStmt
+ */
+public final class SwitchStmt extends Statement {
+
+ private Expression selector;
+
+ private NodeList<SwitchEntryStmt> entries;
+
+ public SwitchStmt() {
+ this(null, new NameExpr(), new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public SwitchStmt(final Expression selector, final NodeList<SwitchEntryStmt> entries) {
+ this(null, selector, entries);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public SwitchStmt(TokenRange tokenRange, Expression selector, NodeList<SwitchEntryStmt> entries) {
+ super(tokenRange);
+ setSelector(selector);
+ setEntries(entries);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<SwitchEntryStmt> getEntries() {
+ return entries;
+ }
+
+ public SwitchEntryStmt getEntry(int i) {
+ return getEntries().get(i);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getSelector() {
+ return selector;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SwitchStmt setEntries(final NodeList<SwitchEntryStmt> entries) {
+ assertNotNull(entries);
+ if (entries == this.entries) {
+ return (SwitchStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.ENTRIES, this.entries, entries);
+ if (this.entries != null)
+ this.entries.setParentNode(null);
+ this.entries = entries;
+ setAsParentNodeOf(entries);
+ return this;
+ }
+
+ /**
+ * @deprecated use a method on getEntries instead
+ */
+ @Deprecated
+ public SwitchStmt setEntry(int i, SwitchEntryStmt entry) {
+ getEntries().set(i, entry);
+ return this;
+ }
+
+ /**
+ * @deprecated use a method on getEntries instead
+ */
+ @Deprecated
+ public SwitchStmt addEntry(SwitchEntryStmt entry) {
+ getEntries().add(entry);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SwitchStmt setSelector(final Expression selector) {
+ assertNotNull(selector);
+ if (selector == this.selector) {
+ return (SwitchStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.SELECTOR, this.selector, selector);
+ if (this.selector != null)
+ this.selector.setParentNode(null);
+ this.selector = selector;
+ setAsParentNodeOf(selector);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < entries.size(); i++) {
+ if (entries.get(i) == node) {
+ entries.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public SwitchStmt clone() {
+ return (SwitchStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public SwitchStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.switchStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < entries.size(); i++) {
+ if (entries.get(i) == node) {
+ entries.set(i, (SwitchEntryStmt) replacementNode);
+ return true;
+ }
+ }
+ if (node == selector) {
+ setSelector((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSwitchStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SwitchStmt asSwitchStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSwitchStmt(Consumer<SwitchStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SwitchStmt> toSwitchStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SynchronizedStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SynchronizedStmt.java
new file mode 100644
index 000000000..376d525b7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/SynchronizedStmt.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithBlockStmt;
+import com.github.javaparser.ast.nodeTypes.NodeWithExpression;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.SynchronizedStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Usage of the synchronized keyword.
+ * <br/>In <code>synchronized (a123) { ... }</code> the expression is a123 and { ... } is the body
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class SynchronizedStmt extends Statement implements NodeWithBlockStmt<SynchronizedStmt>, NodeWithExpression<SynchronizedStmt> {
+
+ private Expression expression;
+
+ private BlockStmt body;
+
+ public SynchronizedStmt() {
+ this(null, new NameExpr(), new BlockStmt());
+ }
+
+ @AllFieldsConstructor
+ public SynchronizedStmt(final Expression expression, final BlockStmt body) {
+ this(null, expression, body);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public SynchronizedStmt(TokenRange tokenRange, Expression expression, BlockStmt body) {
+ super(tokenRange);
+ setExpression(expression);
+ setBody(body);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getExpression() {
+ return expression;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SynchronizedStmt setExpression(final Expression expression) {
+ assertNotNull(expression);
+ if (expression == this.expression) {
+ return (SynchronizedStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression);
+ if (this.expression != null)
+ this.expression.setParentNode(null);
+ this.expression = expression;
+ setAsParentNodeOf(expression);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BlockStmt getBody() {
+ return body;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SynchronizedStmt setBody(final BlockStmt body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (SynchronizedStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public SynchronizedStmt clone() {
+ return (SynchronizedStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public SynchronizedStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.synchronizedStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((BlockStmt) replacementNode);
+ return true;
+ }
+ if (node == expression) {
+ setExpression((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isSynchronizedStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public SynchronizedStmt asSynchronizedStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifSynchronizedStmt(Consumer<SynchronizedStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<SynchronizedStmt> toSynchronizedStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ThrowStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ThrowStmt.java
new file mode 100644
index 000000000..736b8351e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/ThrowStmt.java
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.NameExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithExpression;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.ThrowStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Usage of the throw statement.
+ * <br/><code>throw new Exception()</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ThrowStmt extends Statement implements NodeWithExpression<ThrowStmt> {
+
+ private Expression expression;
+
+ public ThrowStmt() {
+ this(null, new NameExpr());
+ }
+
+ @AllFieldsConstructor
+ public ThrowStmt(final Expression expression) {
+ this(null, expression);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ThrowStmt(TokenRange tokenRange, Expression expression) {
+ super(tokenRange);
+ setExpression(expression);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getExpression() {
+ return expression;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ThrowStmt setExpression(final Expression expression) {
+ assertNotNull(expression);
+ if (expression == this.expression) {
+ return (ThrowStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXPRESSION, this.expression, expression);
+ if (this.expression != null)
+ this.expression.setParentNode(null);
+ this.expression = expression;
+ setAsParentNodeOf(expression);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ThrowStmt clone() {
+ return (ThrowStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ThrowStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.throwStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == expression) {
+ setExpression((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isThrowStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ThrowStmt asThrowStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifThrowStmt(Consumer<ThrowStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ThrowStmt> toThrowStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/TryStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/TryStmt.java
new file mode 100644
index 000000000..6e4a81a42
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/TryStmt.java
@@ -0,0 +1,321 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.metamodel.TryStmtMetaModel;
+import javax.annotation.Generated;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import java.util.function.Consumer;
+
+/**
+ * <h1>The try statement</h1>
+ * <h2>Java 1.0-6</h2>
+ * <pre>
+ * try {
+ * // ...
+ * } catch (IOException e) {
+ * // ...
+ * } finally {
+ * // ...
+ * }
+ * </pre>
+ * In this code, "// do things" is the content of the tryBlock, there is one catch clause that catches IOException e,
+ * and there is a finally block.
+ * <p>
+ * The catch and finally blocks are optional, but they should not be empty at the same time.
+ * <h2>Java 7-8</h2>
+ * <pre>
+ * try (InputStream i = new FileInputStream("file")) {
+ * // ...
+ * } catch (IOException|NullPointerException e) {
+ * // ...
+ * } finally {
+ * // ...
+ * }
+ * </pre>
+ * Java 7 introduced two things:
+ * <ul>
+ * <li>Resources can be specified after "try", but only variable declarations (VariableDeclarationExpr.)</li>
+ * <li>A single catch can catch multiple exception types. This uses the IntersectionType.</li>
+ * </ul>
+ * <h2>Java 9+</h2>
+ * <pre>
+ * try (r) {
+ * // ...
+ * } catch (IOException|NullPointerException e) {
+ * // ...
+ * } finally {
+ * // ...
+ * }
+ * </pre>
+ * Java 9 finishes resources: you can now refer to a resource that was declared somewhere else.
+ * The following types are allowed:
+ * <ul>
+ * <li>VariableDeclarationExpr: "X x = new X()" like in Java 7-8.</li>
+ * <li>NameExpr: "a".</li>
+ * <li>FieldAccessExpr: "x.y.z", "super.test" etc.</li>
+ * </ul>
+ *
+ * @author Julio Vilmar Gesser
+ * @see CatchClause
+ * @see com.github.javaparser.ast.type.IntersectionType
+ * @see com.github.javaparser.ast.expr.FieldAccessExpr
+ * @see com.github.javaparser.ast.expr.NameExpr
+ */
+public final class TryStmt extends Statement {
+
+ private NodeList<Expression> resources;
+
+ private BlockStmt tryBlock;
+
+ private NodeList<CatchClause> catchClauses;
+
+ @OptionalProperty
+ private BlockStmt finallyBlock;
+
+ public TryStmt() {
+ this(null, new NodeList<>(), new BlockStmt(), new NodeList<>(), null);
+ }
+
+ public TryStmt(final BlockStmt tryBlock, final NodeList<CatchClause> catchClauses, final BlockStmt finallyBlock) {
+ this(null, new NodeList<>(), tryBlock, catchClauses, finallyBlock);
+ }
+
+ @AllFieldsConstructor
+ public TryStmt(NodeList<Expression> resources, final BlockStmt tryBlock, final NodeList<CatchClause> catchClauses, final BlockStmt finallyBlock) {
+ this(null, resources, tryBlock, catchClauses, finallyBlock);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public TryStmt(TokenRange tokenRange, NodeList<Expression> resources, BlockStmt tryBlock, NodeList<CatchClause> catchClauses, BlockStmt finallyBlock) {
+ super(tokenRange);
+ setResources(resources);
+ setTryBlock(tryBlock);
+ setCatchClauses(catchClauses);
+ setFinallyBlock(finallyBlock);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<CatchClause> getCatchClauses() {
+ return catchClauses;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<BlockStmt> getFinallyBlock() {
+ return Optional.ofNullable(finallyBlock);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public BlockStmt getTryBlock() {
+ return tryBlock;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<Expression> getResources() {
+ return resources;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public TryStmt setCatchClauses(final NodeList<CatchClause> catchClauses) {
+ assertNotNull(catchClauses);
+ if (catchClauses == this.catchClauses) {
+ return (TryStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.CATCH_CLAUSES, this.catchClauses, catchClauses);
+ if (this.catchClauses != null)
+ this.catchClauses.setParentNode(null);
+ this.catchClauses = catchClauses;
+ setAsParentNodeOf(catchClauses);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public TryStmt setFinallyBlock(final BlockStmt finallyBlock) {
+ if (finallyBlock == this.finallyBlock) {
+ return (TryStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.FINALLY_BLOCK, this.finallyBlock, finallyBlock);
+ if (this.finallyBlock != null)
+ this.finallyBlock.setParentNode(null);
+ this.finallyBlock = finallyBlock;
+ setAsParentNodeOf(finallyBlock);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public TryStmt setTryBlock(final BlockStmt tryBlock) {
+ assertNotNull(tryBlock);
+ if (tryBlock == this.tryBlock) {
+ return (TryStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.TRY_BLOCK, this.tryBlock, tryBlock);
+ if (this.tryBlock != null)
+ this.tryBlock.setParentNode(null);
+ this.tryBlock = tryBlock;
+ setAsParentNodeOf(tryBlock);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public TryStmt setResources(final NodeList<Expression> resources) {
+ assertNotNull(resources);
+ if (resources == this.resources) {
+ return (TryStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.RESOURCES, this.resources, resources);
+ if (this.resources != null)
+ this.resources.setParentNode(null);
+ this.resources = resources;
+ setAsParentNodeOf(resources);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < catchClauses.size(); i++) {
+ if (catchClauses.get(i) == node) {
+ catchClauses.remove(i);
+ return true;
+ }
+ }
+ if (finallyBlock != null) {
+ if (node == finallyBlock) {
+ removeFinallyBlock();
+ return true;
+ }
+ }
+ for (int i = 0; i < resources.size(); i++) {
+ if (resources.get(i) == node) {
+ resources.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public TryStmt removeFinallyBlock() {
+ return setFinallyBlock((BlockStmt) null);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public TryStmt removeTryBlock() {
+ return setTryBlock((BlockStmt) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public TryStmt clone() {
+ return (TryStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public TryStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.tryStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < catchClauses.size(); i++) {
+ if (catchClauses.get(i) == node) {
+ catchClauses.set(i, (CatchClause) replacementNode);
+ return true;
+ }
+ }
+ if (finallyBlock != null) {
+ if (node == finallyBlock) {
+ setFinallyBlock((BlockStmt) replacementNode);
+ return true;
+ }
+ }
+ for (int i = 0; i < resources.size(); i++) {
+ if (resources.get(i) == node) {
+ resources.set(i, (Expression) replacementNode);
+ return true;
+ }
+ }
+ if (node == tryBlock) {
+ setTryBlock((BlockStmt) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isTryStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public TryStmt asTryStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifTryStmt(Consumer<TryStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<TryStmt> toTryStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/UnparsableStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/UnparsableStmt.java
new file mode 100644
index 000000000..2a7fc011b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/UnparsableStmt.java
@@ -0,0 +1,103 @@
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.ast.Node;
+import javax.annotation.Generated;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.UnparsableStmtMetaModel;
+import static com.github.javaparser.ast.Node.Parsedness.*;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A statement that had parse errors.
+ * Nothing is known about it except the tokens it covers.
+ */
+public final class UnparsableStmt extends Statement {
+
+ @AllFieldsConstructor
+ public UnparsableStmt() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public UnparsableStmt(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public UnparsableStmt clone() {
+ return (UnparsableStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public UnparsableStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.unparsableStmtMetaModel;
+ }
+
+ @Override
+ public Parsedness getParsed() {
+ return UNPARSABLE;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isUnparsableStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public UnparsableStmt asUnparsableStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifUnparsableStmt(Consumer<UnparsableStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<UnparsableStmt> toUnparsableStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java
new file mode 100644
index 000000000..5fb1f9971
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/stmt/WhileStmt.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.stmt;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.expr.BooleanLiteralExpr;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.nodeTypes.NodeWithBody;
+import com.github.javaparser.ast.nodeTypes.NodeWithCondition;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.WhileStmtMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A while statement.
+ * <br/><code>while(true) { ... }</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class WhileStmt extends Statement implements NodeWithBody<WhileStmt>, NodeWithCondition<WhileStmt> {
+
+ private Expression condition;
+
+ private Statement body;
+
+ public WhileStmt() {
+ this(null, new BooleanLiteralExpr(), new ReturnStmt());
+ }
+
+ @AllFieldsConstructor
+ public WhileStmt(final Expression condition, final Statement body) {
+ this(null, condition, body);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public WhileStmt(TokenRange tokenRange, Expression condition, Statement body) {
+ super(tokenRange);
+ setCondition(condition);
+ setBody(body);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Statement getBody() {
+ return body;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Expression getCondition() {
+ return condition;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public WhileStmt setBody(final Statement body) {
+ assertNotNull(body);
+ if (body == this.body) {
+ return (WhileStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.BODY, this.body, body);
+ if (this.body != null)
+ this.body.setParentNode(null);
+ this.body = body;
+ setAsParentNodeOf(body);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public WhileStmt setCondition(final Expression condition) {
+ assertNotNull(condition);
+ if (condition == this.condition) {
+ return (WhileStmt) this;
+ }
+ notifyPropertyChange(ObservableProperty.CONDITION, this.condition, condition);
+ if (this.condition != null)
+ this.condition.setParentNode(null);
+ this.condition = condition;
+ setAsParentNodeOf(condition);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public WhileStmt clone() {
+ return (WhileStmt) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public WhileStmtMetaModel getMetaModel() {
+ return JavaParserMetaModel.whileStmtMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == body) {
+ setBody((Statement) replacementNode);
+ return true;
+ }
+ if (node == condition) {
+ setCondition((Expression) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isWhileStmt() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public WhileStmt asWhileStmt() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifWhileStmt(Consumer<WhileStmt> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<WhileStmt> toWhileStmt() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java
new file mode 100644
index 000000000..76dba1f3f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ArrayType.java
@@ -0,0 +1,293 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.ArrayTypeMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.resolution.types.ResolvedArrayType;
+import com.github.javaparser.utils.Pair;
+import javax.annotation.Generated;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.ast.NodeList.nodeList;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import java.util.function.Consumer;
+
+/**
+ * To indicate that a type is an array, it gets wrapped in an ArrayType for every array level it has.
+ * So, int[][] becomes ArrayType(ArrayType(int)).
+ */
+public final class ArrayType extends ReferenceType implements NodeWithAnnotations<ArrayType> {
+
+ @Override
+ public ResolvedArrayType resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedArrayType.class);
+ }
+
+ /**
+ * The origin of a pair of array brackets [].
+ */
+ public enum Origin {
+
+ /**
+ * The [] were found on the name, like "int a[]" or "String abc()[][]"
+ */
+ NAME,
+ /**
+ * The [] were found on the type, like "int[] a" or "String[][] abc()"
+ */
+ TYPE
+ }
+
+ private Type componentType;
+
+ private Origin origin;
+
+ @AllFieldsConstructor
+ public ArrayType(Type componentType, Origin origin, NodeList<AnnotationExpr> annotations) {
+ this(null, componentType, origin, annotations);
+ }
+
+ public ArrayType(Type type, AnnotationExpr... annotations) {
+ this(type, Origin.TYPE, nodeList(annotations));
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ArrayType(TokenRange tokenRange, Type componentType, Origin origin, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange, annotations);
+ setComponentType(componentType);
+ setOrigin(origin);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type getComponentType() {
+ return componentType;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayType setComponentType(final Type componentType) {
+ assertNotNull(componentType);
+ if (componentType == this.componentType) {
+ return (ArrayType) this;
+ }
+ notifyPropertyChange(ObservableProperty.COMPONENT_TYPE, this.componentType, componentType);
+ if (this.componentType != null)
+ this.componentType.setParentNode(null);
+ this.componentType = componentType;
+ setAsParentNodeOf(componentType);
+ return this;
+ }
+
+ /**
+ * Takes lists of arrayBracketPairs, assumes the lists are ordered left to right and the pairs are ordered left to
+ * right, mirroring the actual code. The type gets wrapped in ArrayTypes so that the outermost ArrayType corresponds
+ * to the rightmost ArrayBracketPair.
+ */
+ @SafeVarargs
+ public static Type wrapInArrayTypes(Type type, List<ArrayBracketPair>... arrayBracketPairLists) {
+ for (int i = arrayBracketPairLists.length - 1; i >= 0; i--) {
+ final List<ArrayBracketPair> arrayBracketPairList = arrayBracketPairLists[i];
+ if (arrayBracketPairList != null) {
+ for (int j = arrayBracketPairList.size() - 1; j >= 0; j--) {
+ ArrayBracketPair pair = arrayBracketPairList.get(j);
+ TokenRange tokenRange = null;
+ if (type.getTokenRange().isPresent() && pair.getTokenRange().isPresent()) {
+ tokenRange = new TokenRange(type.getTokenRange().get().getBegin(), pair.getTokenRange().get().getEnd());
+ }
+ type = new ArrayType(tokenRange, type, pair.getOrigin(), pair.getAnnotations());
+ if (tokenRange != null) {
+ type.setRange(tokenRange.toRange().get());
+ }
+ }
+ }
+ }
+ return type;
+ }
+
+ /**
+ * Takes a type that may be an ArrayType. Unwraps ArrayTypes until the element type is found.
+ *
+ * @return a pair of the element type, and the unwrapped ArrayTypes, if any.
+ */
+ public static Pair<Type, List<ArrayBracketPair>> unwrapArrayTypes(Type type) {
+ final List<ArrayBracketPair> arrayBracketPairs = new ArrayList<>(0);
+ while (type instanceof ArrayType) {
+ ArrayType arrayType = (ArrayType) type;
+ arrayBracketPairs.add(new ArrayBracketPair(type.getTokenRange().orElse(null), arrayType.getOrigin(), arrayType.getAnnotations()));
+ type = arrayType.getComponentType();
+ }
+ return new Pair<>(type, arrayBracketPairs);
+ }
+
+ /**
+ * Helper class that stores information about a pair of brackets in a non-recursive way
+ * (unlike ArrayType.)
+ */
+ public static class ArrayBracketPair {
+
+ private TokenRange tokenRange;
+
+ private NodeList<AnnotationExpr> annotations = new NodeList<>();
+
+ private Origin origin;
+
+ public ArrayBracketPair(TokenRange tokenRange, Origin origin, NodeList<AnnotationExpr> annotations) {
+ setTokenRange(tokenRange);
+ setAnnotations(annotations);
+ setOrigin(origin);
+ }
+
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ public ArrayBracketPair setAnnotations(NodeList<AnnotationExpr> annotations) {
+ this.annotations = assertNotNull(annotations);
+ return this;
+ }
+
+ public ArrayBracketPair setTokenRange(TokenRange range) {
+ this.tokenRange = range;
+ return this;
+ }
+
+ public Optional<TokenRange> getTokenRange() {
+ return Optional.ofNullable(tokenRange);
+ }
+
+ public Origin getOrigin() {
+ return origin;
+ }
+
+ public ArrayBracketPair setOrigin(Origin origin) {
+ this.origin = assertNotNull(origin);
+ return this;
+ }
+ }
+
+ @Override
+ public ArrayType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ return (ArrayType) super.setAnnotations(annotations);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Origin getOrigin() {
+ return origin;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ArrayType setOrigin(final Origin origin) {
+ assertNotNull(origin);
+ if (origin == this.origin) {
+ return (ArrayType) this;
+ }
+ notifyPropertyChange(ObservableProperty.ORIGIN, this.origin, origin);
+ this.origin = origin;
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ return componentType.asString() + "[]";
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ArrayType clone() {
+ return (ArrayType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ArrayTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.arrayTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == componentType) {
+ setComponentType((Type) replacementNode);
+ return true;
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isArrayType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ArrayType asArrayType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifArrayType(Consumer<ArrayType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ArrayType> toArrayType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java
new file mode 100644
index 000000000..f3b6846c6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ClassOrInterfaceType.java
@@ -0,0 +1,302 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.ClassOrInterfaceTypeMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.joining;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.resolution.types.ResolvedReferenceType;
+import java.util.function.Consumer;
+
+/**
+ * A class or an interface type. <br/><code>Object</code> <br/><code>HashMap&lt;String, String></code>
+ * <br/><code>java.util.Punchcard</code>
+ * <p>
+ * <p>Note that the syntax is ambiguous here, and JavaParser does not know what is to the left of the class. It assumes
+ * cases like <code>Map.Entry</code> where Map is the scope of Entry. In <code>java.util.Punchcard</code>, it will not
+ * recognize that java and util are parts of the package name. Instead, it will set util as the scope of Punchcard, as a
+ * ClassOrInterfaceType (which it is not.) In turn, util will have java as its scope, also as a
+ * ClassOrInterfaceType</p>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class ClassOrInterfaceType extends ReferenceType implements NodeWithSimpleName<ClassOrInterfaceType>, NodeWithAnnotations<ClassOrInterfaceType>, NodeWithTypeArguments<ClassOrInterfaceType> {
+
+ @OptionalProperty
+ private ClassOrInterfaceType scope;
+
+ private SimpleName name;
+
+ @OptionalProperty
+ private NodeList<Type> typeArguments;
+
+ public ClassOrInterfaceType() {
+ this(null, null, new SimpleName(), null, new NodeList<>());
+ }
+
+ /**
+ * @deprecated use JavaParser.parseClassOrInterfaceType instead. This constructor does not understand generics.
+ */
+ public ClassOrInterfaceType(final String name) {
+ this(null, null, new SimpleName(name), null, new NodeList<>());
+ }
+
+ public ClassOrInterfaceType(final ClassOrInterfaceType scope, final String name) {
+ this(null, scope, new SimpleName(name), null, new NodeList<>());
+ }
+
+ public ClassOrInterfaceType(final ClassOrInterfaceType scope, final SimpleName name, final NodeList<Type> typeArguments) {
+ this(null, scope, name, typeArguments, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ClassOrInterfaceType(final ClassOrInterfaceType scope, final SimpleName name, final NodeList<Type> typeArguments, final NodeList<AnnotationExpr> annotations) {
+ this(null, scope, name, typeArguments, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ClassOrInterfaceType(TokenRange tokenRange, ClassOrInterfaceType scope, SimpleName name, NodeList<Type> typeArguments, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange, annotations);
+ setScope(scope);
+ setName(name);
+ setTypeArguments(typeArguments);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<ClassOrInterfaceType> getScope() {
+ return Optional.ofNullable(scope);
+ }
+
+ public boolean isBoxedType() {
+ return PrimitiveType.unboxMap.containsKey(name.getIdentifier());
+ }
+
+ public PrimitiveType toUnboxedType() throws UnsupportedOperationException {
+ if (!isBoxedType()) {
+ throw new UnsupportedOperationException(name + " isn't a boxed type.");
+ }
+ return new PrimitiveType(PrimitiveType.unboxMap.get(name.getIdentifier()));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceType setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (ClassOrInterfaceType) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ /**
+ * Sets the scope
+ *
+ * @param scope the scope, can be null
+ * @return this, the ClassOrInterfaceType
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceType setScope(final ClassOrInterfaceType scope) {
+ if (scope == this.scope) {
+ return (ClassOrInterfaceType) this;
+ }
+ notifyPropertyChange(ObservableProperty.SCOPE, this.scope, scope);
+ if (this.scope != null)
+ this.scope.setParentNode(null);
+ this.scope = scope;
+ setAsParentNodeOf(scope);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<NodeList<Type>> getTypeArguments() {
+ return Optional.ofNullable(typeArguments);
+ }
+
+ /**
+ * Sets the typeArguments
+ *
+ * @param typeArguments the typeArguments, can be null
+ * @return this, the ClassOrInterfaceType
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public ClassOrInterfaceType setTypeArguments(final NodeList<Type> typeArguments) {
+ if (typeArguments == this.typeArguments) {
+ return (ClassOrInterfaceType) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_ARGUMENTS, this.typeArguments, typeArguments);
+ if (this.typeArguments != null)
+ this.typeArguments.setParentNode(null);
+ this.typeArguments = typeArguments;
+ setAsParentNodeOf(typeArguments);
+ return this;
+ }
+
+ @Override
+ public ClassOrInterfaceType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ return (ClassOrInterfaceType) super.setAnnotations(annotations);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (scope != null) {
+ if (node == scope) {
+ removeScope();
+ return true;
+ }
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.remove(i);
+ return true;
+ }
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ StringBuilder str = new StringBuilder();
+ getScope().ifPresent(s -> str.append(s.asString()).append("."));
+ str.append(name.asString());
+ getTypeArguments().ifPresent(ta -> str.append(ta.stream().map(Type::asString).collect(joining(",", "<", ">"))));
+ return str.toString();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public ClassOrInterfaceType removeScope() {
+ return setScope((ClassOrInterfaceType) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ClassOrInterfaceType clone() {
+ return (ClassOrInterfaceType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ClassOrInterfaceTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.classOrInterfaceTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ if (scope != null) {
+ if (node == scope) {
+ setScope((ClassOrInterfaceType) replacementNode);
+ return true;
+ }
+ }
+ if (typeArguments != null) {
+ for (int i = 0; i < typeArguments.size(); i++) {
+ if (typeArguments.get(i) == node) {
+ typeArguments.set(i, (Type) replacementNode);
+ return true;
+ }
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isClassOrInterfaceType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ClassOrInterfaceType asClassOrInterfaceType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifClassOrInterfaceType(Consumer<ClassOrInterfaceType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedReferenceType resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedReferenceType.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ClassOrInterfaceType> toClassOrInterfaceType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/IntersectionType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/IntersectionType.java
new file mode 100644
index 000000000..6b1056bf2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/IntersectionType.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.IntersectionTypeMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.joining;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.types.ResolvedIntersectionType;
+import com.github.javaparser.resolution.types.ResolvedReferenceType;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Represents a set of types. A given value of this type has to be assignable to at all of the element types.
+ * As of Java 8 it is used in casts or while expressing bounds for generic types.
+ * <p>
+ * For example:
+ * <code>public class A&lt;T extends Serializable &amp; Cloneable&gt; { }</code>
+ * <p>
+ * Or:
+ * <code>void foo((Serializable &amp; Cloneable)myObject);</code>
+ *
+ * @since 3.0.0
+ */
+public final class IntersectionType extends Type implements NodeWithAnnotations<IntersectionType> {
+
+ @NonEmptyProperty
+ private NodeList<ReferenceType> elements;
+
+ @AllFieldsConstructor
+ public IntersectionType(NodeList<ReferenceType> elements) {
+ this(null, elements);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public IntersectionType(TokenRange tokenRange, NodeList<ReferenceType> elements) {
+ super(tokenRange);
+ setElements(elements);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ReferenceType> getElements() {
+ return elements;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public IntersectionType setElements(final NodeList<ReferenceType> elements) {
+ assertNotNull(elements);
+ if (elements == this.elements) {
+ return (IntersectionType) this;
+ }
+ notifyPropertyChange(ObservableProperty.ELEMENTS, this.elements, elements);
+ if (this.elements != null)
+ this.elements.setParentNode(null);
+ this.elements = elements;
+ setAsParentNodeOf(elements);
+ return this;
+ }
+
+ @Override
+ public IntersectionType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ return (IntersectionType) super.setAnnotations(annotations);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < elements.size(); i++) {
+ if (elements.get(i) == node) {
+ elements.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ return elements.stream().map(Type::asString).collect(joining("&"));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public IntersectionType clone() {
+ return (IntersectionType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public IntersectionTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.intersectionTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < elements.size(); i++) {
+ if (elements.get(i) == node) {
+ elements.set(i, (ReferenceType) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isIntersectionType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public IntersectionType asIntersectionType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifIntersectionType(Consumer<IntersectionType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedIntersectionType resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedIntersectionType.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<IntersectionType> toIntersectionType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/PrimitiveType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/PrimitiveType.java
new file mode 100644
index 000000000..e359b7f09
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/PrimitiveType.java
@@ -0,0 +1,247 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import static com.github.javaparser.JavaParser.parseClassOrInterfaceType;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.PrimitiveTypeMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.types.ResolvedPrimitiveType;
+import com.github.javaparser.resolution.types.ResolvedReferenceType;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A primitive type.
+ * <br/><code>int</code>
+ * <br/><code>boolean</code>
+ * <br/><code>short</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class PrimitiveType extends Type implements NodeWithAnnotations<PrimitiveType> {
+
+ public static PrimitiveType booleanType() {
+ return new PrimitiveType(Primitive.BOOLEAN);
+ }
+
+ public static PrimitiveType charType() {
+ return new PrimitiveType(Primitive.CHAR);
+ }
+
+ public static PrimitiveType byteType() {
+ return new PrimitiveType(Primitive.BYTE);
+ }
+
+ public static PrimitiveType shortType() {
+ return new PrimitiveType(Primitive.SHORT);
+ }
+
+ public static PrimitiveType intType() {
+ return new PrimitiveType(Primitive.INT);
+ }
+
+ public static PrimitiveType longType() {
+ return new PrimitiveType(Primitive.LONG);
+ }
+
+ public static PrimitiveType floatType() {
+ return new PrimitiveType(Primitive.FLOAT);
+ }
+
+ public static PrimitiveType doubleType() {
+ return new PrimitiveType(Primitive.DOUBLE);
+ }
+
+ public enum Primitive {
+
+ BOOLEAN("Boolean"),
+ CHAR("Character"),
+ BYTE("Byte"),
+ SHORT("Short"),
+ INT("Integer"),
+ LONG("Long"),
+ FLOAT("Float"),
+ DOUBLE("Double");
+
+ final String nameOfBoxedType;
+
+ private String codeRepresentation;
+
+ public ClassOrInterfaceType toBoxedType() {
+ return parseClassOrInterfaceType(nameOfBoxedType);
+ }
+
+ public String asString() {
+ return codeRepresentation;
+ }
+
+ Primitive(String nameOfBoxedType) {
+ this.nameOfBoxedType = nameOfBoxedType;
+ this.codeRepresentation = name().toLowerCase();
+ }
+ }
+
+ static final HashMap<String, Primitive> unboxMap = new HashMap<>();
+
+ static {
+ for (Primitive unboxedType : Primitive.values()) {
+ unboxMap.put(unboxedType.nameOfBoxedType, unboxedType);
+ }
+ }
+
+ private Primitive type;
+
+ public PrimitiveType() {
+ this(null, Primitive.INT, new NodeList<>());
+ }
+
+ public PrimitiveType(final Primitive type) {
+ this(null, type, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public PrimitiveType(final Primitive type, NodeList<AnnotationExpr> annotations) {
+ this(null, type, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public PrimitiveType(TokenRange tokenRange, Primitive type, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange, annotations);
+ setType(type);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Primitive getType() {
+ return type;
+ }
+
+ public ClassOrInterfaceType toBoxedType() {
+ return type.toBoxedType();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public PrimitiveType setType(final Primitive type) {
+ assertNotNull(type);
+ if (type == this.type) {
+ return (PrimitiveType) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE, this.type, type);
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public String asString() {
+ return type.asString();
+ }
+
+ @Override
+ public PrimitiveType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ return (PrimitiveType) super.setAnnotations(annotations);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public PrimitiveType clone() {
+ return (PrimitiveType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public PrimitiveTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.primitiveTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isPrimitiveType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public PrimitiveType asPrimitiveType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifPrimitiveType(Consumer<PrimitiveType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedPrimitiveType resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedPrimitiveType.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<PrimitiveType> toPrimitiveType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/ReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ReferenceType.java
new file mode 100644
index 000000000..f39ee0e4a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/ReferenceType.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.ReferenceTypeMetaModel;
+import javax.annotation.Generated;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * Base class for reference types.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class ReferenceType extends Type {
+
+ public ReferenceType() {
+ this(null, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public ReferenceType(NodeList<AnnotationExpr> annotations) {
+ this(null, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public ReferenceType(TokenRange tokenRange, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange, annotations);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public ReferenceType clone() {
+ return (ReferenceType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public ReferenceTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.referenceTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isReferenceType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ReferenceType asReferenceType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifReferenceType(Consumer<ReferenceType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ReferenceType> toReferenceType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/Type.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/Type.java
new file mode 100644
index 000000000..acaf5a9ed
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/Type.java
@@ -0,0 +1,371 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.DataKey;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.TypeMetaModel;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.Resolvable;
+import com.github.javaparser.resolution.SymbolResolver;
+import com.github.javaparser.resolution.types.ResolvedType;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+import java.util.Optional;
+
+/**
+ * Base class for types.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class Type extends Node implements Resolvable<Object> {
+
+ private NodeList<AnnotationExpr> annotations;
+
+ /**
+ * Several sub classes do not support annotations.
+ * This is a support constructor for them.
+ */
+ protected Type(TokenRange range) {
+ this(range, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public Type(NodeList<AnnotationExpr> annotations) {
+ this(null, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public Type(TokenRange tokenRange, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange);
+ setAnnotations(annotations);
+ customInitialization();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<AnnotationExpr> getAnnotations() {
+ return annotations;
+ }
+
+ public AnnotationExpr getAnnotation(int i) {
+ return getAnnotations().get(i);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Type setAnnotations(final NodeList<AnnotationExpr> annotations) {
+ assertNotNull(annotations);
+ if (annotations == this.annotations) {
+ return (Type) this;
+ }
+ notifyPropertyChange(ObservableProperty.ANNOTATIONS, this.annotations, annotations);
+ if (this.annotations != null)
+ this.annotations.setParentNode(null);
+ this.annotations = annotations;
+ setAsParentNodeOf(annotations);
+ return this;
+ }
+
+ /**
+ * Finds the element type, meaning: the type without ArrayTypes around it.
+ * <p>
+ * In "<code>int[] a[];</code>", the element type is int.
+ */
+ public Type getElementType() {
+ if (this instanceof ArrayType) {
+ return ((ArrayType) this).getComponentType().getElementType();
+ }
+ return this;
+ }
+
+ public int getArrayLevel() {
+ if (this instanceof ArrayType) {
+ return 1 + ((ArrayType) this).getComponentType().getArrayLevel();
+ } else {
+ return 0;
+ }
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ public abstract String asString();
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public Type clone() {
+ return (Type) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public TypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.typeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < annotations.size(); i++) {
+ if (annotations.get(i) == node) {
+ annotations.set(i, (AnnotationExpr) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isArrayType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ArrayType asArrayType() {
+ throw new IllegalStateException(f("%s is not an ArrayType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isClassOrInterfaceType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ClassOrInterfaceType asClassOrInterfaceType() {
+ throw new IllegalStateException(f("%s is not an ClassOrInterfaceType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isIntersectionType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public IntersectionType asIntersectionType() {
+ throw new IllegalStateException(f("%s is not an IntersectionType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isPrimitiveType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public PrimitiveType asPrimitiveType() {
+ throw new IllegalStateException(f("%s is not an PrimitiveType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isReferenceType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public ReferenceType asReferenceType() {
+ throw new IllegalStateException(f("%s is not an ReferenceType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isTypeParameter() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public TypeParameter asTypeParameter() {
+ throw new IllegalStateException(f("%s is not an TypeParameter", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isUnionType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public UnionType asUnionType() {
+ throw new IllegalStateException(f("%s is not an UnionType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isUnknownType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public UnknownType asUnknownType() {
+ throw new IllegalStateException(f("%s is not an UnknownType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isVoidType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public VoidType asVoidType() {
+ throw new IllegalStateException(f("%s is not an VoidType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isWildcardType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public WildcardType asWildcardType() {
+ throw new IllegalStateException(f("%s is not an WildcardType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifArrayType(Consumer<ArrayType> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifClassOrInterfaceType(Consumer<ClassOrInterfaceType> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifIntersectionType(Consumer<IntersectionType> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifPrimitiveType(Consumer<PrimitiveType> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifReferenceType(Consumer<ReferenceType> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifTypeParameter(Consumer<TypeParameter> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifUnionType(Consumer<UnionType> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifUnknownType(Consumer<UnknownType> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifVoidType(Consumer<VoidType> action) {
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifWildcardType(Consumer<WildcardType> action) {
+ }
+
+ @Override
+ public abstract ResolvedType resolve();
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ArrayType> toArrayType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ClassOrInterfaceType> toClassOrInterfaceType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<IntersectionType> toIntersectionType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<PrimitiveType> toPrimitiveType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<ReferenceType> toReferenceType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<TypeParameter> toTypeParameter() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<UnionType> toUnionType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<UnknownType> toUnknownType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<VoidType> toVoidType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<WildcardType> toWildcardType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isVarType() {
+ return false;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public VarType asVarType() {
+ throw new IllegalStateException(f("%s is not an VarType", this));
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<VarType> toVarType() {
+ return Optional.empty();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifVarType(Consumer<VarType> action) {
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/TypeParameter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/TypeParameter.java
new file mode 100644
index 000000000..c3f8cedab
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/TypeParameter.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.Range;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithSimpleName;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.joining;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.TypeParameterMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+import com.github.javaparser.resolution.types.ResolvedTypeVariable;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * A type parameter.
+ * <br/><code>&lt;<b>U</b>> U getU() { ... }</code>
+ * <br/><code>class D &lt;<b>@Brain T extends B & A & @Tripe C</b>> { ... }</code>
+ * <p>U and T are type parameter names.
+ * <br/>B, A, and C are type parameter bounds.
+ * <br/>Tripe is an annotation on type parameter bound C.
+ * <br/>Brain is an annotation on type parameter T.
+ *
+ * @author Julio Vilmar Gesser
+ * @see com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters
+ */
+public final class TypeParameter extends ReferenceType implements NodeWithSimpleName<TypeParameter>, NodeWithAnnotations<TypeParameter> {
+
+ private SimpleName name;
+
+ private NodeList<ClassOrInterfaceType> typeBound;
+
+ public TypeParameter() {
+ this(null, new SimpleName(), new NodeList<>(), new NodeList<>());
+ }
+
+ public TypeParameter(final String name) {
+ this(null, new SimpleName(name), new NodeList<>(), new NodeList<>());
+ }
+
+ public TypeParameter(final String name, final NodeList<ClassOrInterfaceType> typeBound) {
+ this(null, new SimpleName(name), typeBound, new NodeList<>());
+ }
+
+ /**
+ * @deprecated range shouldn't be in utility constructors.
+ */
+ @Deprecated
+ public TypeParameter(Range range, final SimpleName name, final NodeList<ClassOrInterfaceType> typeBound) {
+ this(null, name, typeBound, new NodeList<>());
+ setRange(range);
+ }
+
+ @AllFieldsConstructor
+ public TypeParameter(SimpleName name, NodeList<ClassOrInterfaceType> typeBound, NodeList<AnnotationExpr> annotations) {
+ this(null, name, typeBound, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public TypeParameter(TokenRange tokenRange, SimpleName name, NodeList<ClassOrInterfaceType> typeBound, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange, annotations);
+ setName(name);
+ setTypeBound(typeBound);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ /**
+ * Return the name of the paramenter.
+ *
+ * @return the name of the paramenter
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public SimpleName getName() {
+ return name;
+ }
+
+ /**
+ * Return the list of {@link ClassOrInterfaceType} that this parameter
+ * extends. Return <code>null</code> null if there are no type.
+ *
+ * @return list of types that this paramente extends or <code>null</code>
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ClassOrInterfaceType> getTypeBound() {
+ return typeBound;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public TypeParameter setName(final SimpleName name) {
+ assertNotNull(name);
+ if (name == this.name) {
+ return (TypeParameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.NAME, this.name, name);
+ if (this.name != null)
+ this.name.setParentNode(null);
+ this.name = name;
+ setAsParentNodeOf(name);
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public TypeParameter setTypeBound(final NodeList<ClassOrInterfaceType> typeBound) {
+ assertNotNull(typeBound);
+ if (typeBound == this.typeBound) {
+ return (TypeParameter) this;
+ }
+ notifyPropertyChange(ObservableProperty.TYPE_BOUND, this.typeBound, typeBound);
+ if (this.typeBound != null)
+ this.typeBound.setParentNode(null);
+ this.typeBound = typeBound;
+ setAsParentNodeOf(typeBound);
+ return this;
+ }
+
+ @Override
+ public TypeParameter setAnnotations(NodeList<AnnotationExpr> annotations) {
+ super.setAnnotations(annotations);
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < typeBound.size(); i++) {
+ if (typeBound.get(i) == node) {
+ typeBound.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ StringBuilder str = new StringBuilder(getNameAsString());
+ getTypeBound().ifNonEmpty(l -> str.append(l.stream().map(ClassOrInterfaceType::asString).collect(joining("&", " extends ", ""))));
+ return str.toString();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public TypeParameter clone() {
+ return (TypeParameter) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public TypeParameterMetaModel getMetaModel() {
+ return JavaParserMetaModel.typeParameterMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (node == name) {
+ setName((SimpleName) replacementNode);
+ return true;
+ }
+ for (int i = 0; i < typeBound.size(); i++) {
+ if (typeBound.get(i) == node) {
+ typeBound.set(i, (ClassOrInterfaceType) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isTypeParameter() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public TypeParameter asTypeParameter() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifTypeParameter(Consumer<TypeParameter> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedTypeVariable resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedTypeVariable.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<TypeParameter> toTypeParameter() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnionType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnionType.java
new file mode 100644
index 000000000..5fa78f10a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnionType.java
@@ -0,0 +1,195 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.joining;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.NonEmptyProperty;
+import com.github.javaparser.metamodel.UnionTypeMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.types.ResolvedReferenceType;
+import com.github.javaparser.resolution.types.ResolvedUnionType;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * <h1>The union type</h1>
+ * Represents a set of types. A given value of this type has to be assignable to at least one of the element types.
+ * <h2>Java 1-6</h2>
+ * Does not exist.
+ * <h2>Java 7+</h2>
+ * As of Java 7 it is used in catch clauses.
+ * <pre><code>
+ * try {
+ * ...
+ * } catch(<b>IOException | NullPointerException ex</b>) {
+ * ...
+ * }
+ * </pre>
+ *
+ * The types that make up the union type are its "elements"
+ */
+public final class UnionType extends Type implements NodeWithAnnotations<UnionType> {
+
+ @NonEmptyProperty
+ private NodeList<ReferenceType> elements;
+
+ public UnionType() {
+ this(null, new NodeList<>());
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public UnionType(TokenRange tokenRange, NodeList<ReferenceType> elements) {
+ super(tokenRange);
+ setElements(elements);
+ customInitialization();
+ }
+
+ @AllFieldsConstructor
+ public UnionType(NodeList<ReferenceType> elements) {
+ this(null, elements);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public NodeList<ReferenceType> getElements() {
+ return elements;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public UnionType setElements(final NodeList<ReferenceType> elements) {
+ assertNotNull(elements);
+ if (elements == this.elements) {
+ return (UnionType) this;
+ }
+ notifyPropertyChange(ObservableProperty.ELEMENTS, this.elements, elements);
+ if (this.elements != null)
+ this.elements.setParentNode(null);
+ this.elements = elements;
+ setAsParentNodeOf(elements);
+ return this;
+ }
+
+ @Override
+ public UnionType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ return (UnionType) super.setAnnotations(annotations);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < elements.size(); i++) {
+ if (elements.get(i) == node) {
+ elements.remove(i);
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ return elements.stream().map(Type::asString).collect(joining("|"));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public UnionType clone() {
+ return (UnionType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public UnionTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.unionTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ for (int i = 0; i < elements.size(); i++) {
+ if (elements.get(i) == node) {
+ elements.set(i, (ReferenceType) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isUnionType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public UnionType asUnionType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifUnionType(Consumer<UnionType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedUnionType resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedUnionType.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<UnionType> toUnionType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnknownType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnknownType.java
new file mode 100644
index 000000000..d415214f7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/UnknownType.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.UnknownTypeMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.types.ResolvedReferenceType;
+import com.github.javaparser.resolution.types.ResolvedType;
+import com.github.javaparser.resolution.types.ResolvedUnionType;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * An unknown parameter type object. It plays the role of a null object for
+ * lambda parameters that have no explicit type declared. As such, it has no
+ * lexical representation and hence gets no comment attributed.
+ * <p>
+ * <br/>In <code>DoubleToIntFunction d = <b>x</b> -> (int)x + 1;</code> the x parameter in bold has type UnknownType.
+ *
+ * @author Didier Villevalois
+ */
+public final class UnknownType extends Type {
+
+ @AllFieldsConstructor
+ public UnknownType() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public UnknownType(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ public UnknownType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ if (annotations.size() > 0) {
+ throw new IllegalStateException("Inferred lambda types cannot be annotated.");
+ }
+ return (UnknownType) super.setAnnotations(annotations);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ return "";
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public UnknownType clone() {
+ return (UnknownType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public UnknownTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.unknownTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isUnknownType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public UnknownType asUnknownType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifUnknownType(Consumer<UnknownType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedType resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedReferenceType.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<UnknownType> toUnknownType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/VarType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/VarType.java
new file mode 100644
index 000000000..3755c2fb8
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/VarType.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.VoidTypeMetaModel;
+import com.github.javaparser.resolution.types.ResolvedType;
+import com.github.javaparser.resolution.types.ResolvedVoidType;
+import javax.annotation.Generated;
+import java.util.Optional;
+import java.util.function.Consumer;
+import com.github.javaparser.metamodel.VarTypeMetaModel;
+
+public final class VarType extends Type {
+
+ @AllFieldsConstructor
+ public VarType() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public VarType(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ public VarType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ return (VarType) super.setAnnotations(annotations);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ return "var";
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public VarType clone() {
+ return (VarType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public VarTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.varTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ public ResolvedType resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedType.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isVarType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public VarType asVarType() {
+ return this;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<VarType> toVarType() {
+ return Optional.of(this);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifVarType(Consumer<VarType> action) {
+ action.accept(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/VoidType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/VoidType.java
new file mode 100644
index 000000000..860a9d675
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/VoidType.java
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import java.util.Arrays;
+import java.util.List;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.metamodel.VoidTypeMetaModel;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.types.ResolvedUnionType;
+import com.github.javaparser.resolution.types.ResolvedVoidType;
+import java.util.function.Consumer;
+import java.util.Optional;
+
+/**
+ * The return type of a {@link com.github.javaparser.ast.body.MethodDeclaration}
+ * when it returns void.
+ * <br/><code><b>void</b> helloWorld() { ... }</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class VoidType extends Type implements NodeWithAnnotations<VoidType> {
+
+ @AllFieldsConstructor
+ public VoidType() {
+ this(null);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public VoidType(TokenRange tokenRange) {
+ super(tokenRange);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Override
+ public VoidType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ return (VoidType) super.setAnnotations(annotations);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ return "void";
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public VoidType clone() {
+ return (VoidType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public VoidTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.voidTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ return super.replace(node, replacementNode);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isVoidType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public VoidType asVoidType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifVoidType(Consumer<VoidType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedVoidType resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedVoidType.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<VoidType> toVoidType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java
new file mode 100644
index 000000000..e37842e67
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/type/WildcardType.java
@@ -0,0 +1,307 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.type;
+
+import com.github.javaparser.ast.AllFieldsConstructor;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.visitor.CloneVisitor;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.metamodel.OptionalProperty;
+import com.github.javaparser.metamodel.WildcardTypeMetaModel;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import javax.annotation.Generated;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.resolution.types.ResolvedUnionType;
+import com.github.javaparser.resolution.types.ResolvedWildcard;
+import java.util.function.Consumer;
+
+/**
+ * A wildcard type argument.
+ * <br/><code>void printCollection(Collection&lt;<b>?</b>> c) { ... }</code>
+ * <br/><code>boolean addAll(Collection&lt;<b>? extends E</b>> c)</code>
+ * <br/><code>Reference(T referent, ReferenceQueue&lt;<b>? super T</b>> queue)</code>
+ *
+ * @author Julio Vilmar Gesser
+ */
+public final class WildcardType extends Type implements NodeWithAnnotations<WildcardType> {
+
+ @OptionalProperty
+ private ReferenceType extendedType;
+
+ @OptionalProperty
+ private ReferenceType superType;
+
+ public WildcardType() {
+ this(null, null, null, new NodeList<>());
+ }
+
+ public WildcardType(final ReferenceType extendedType) {
+ this(null, extendedType, null, new NodeList<>());
+ }
+
+ @AllFieldsConstructor
+ public WildcardType(final ReferenceType extendedType, final ReferenceType superType, final NodeList<AnnotationExpr> annotations) {
+ this(null, extendedType, superType, annotations);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public WildcardType(TokenRange tokenRange, ReferenceType extendedType, ReferenceType superType, NodeList<AnnotationExpr> annotations) {
+ super(tokenRange, annotations);
+ setExtendedType(extendedType);
+ setSuperType(superType);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <R, A> R accept(final GenericVisitor<R, A> v, final A arg) {
+ return v.visit(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.AcceptGenerator")
+ public <A> void accept(final VoidVisitor<A> v, final A arg) {
+ v.visit(this, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<ReferenceType> getExtendedType() {
+ return Optional.ofNullable(extendedType);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public Optional<ReferenceType> getSuperType() {
+ return Optional.ofNullable(superType);
+ }
+
+ /**
+ * @deprecated use getExtendedType instead.
+ */
+ @Deprecated
+ public Optional<ReferenceType> getExtendedTypes() {
+ return getExtendedType();
+ }
+
+ /**
+ * @deprecated use getSuperType instead.
+ */
+ @Deprecated
+ public Optional<ReferenceType> getSuperTypes() {
+ return getSuperType();
+ }
+
+ /**
+ * Sets the extended type
+ *
+ * @param extendedType the extends, can be null
+ * @return this, the WildcardType
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public WildcardType setExtendedType(final ReferenceType extendedType) {
+ if (extendedType == this.extendedType) {
+ return (WildcardType) this;
+ }
+ notifyPropertyChange(ObservableProperty.EXTENDED_TYPE, this.extendedType, extendedType);
+ if (this.extendedType != null)
+ this.extendedType.setParentNode(null);
+ this.extendedType = extendedType;
+ setAsParentNodeOf(extendedType);
+ return this;
+ }
+
+ /**
+ * Sets the extended type
+ *
+ * @param extendedType the extends, can be null
+ * @return this, the WildcardType
+ * @deprecated use setExtendedType instead,
+ */
+ @Deprecated
+ public WildcardType setExtendedTypes(final ReferenceType extendedType) {
+ return setExtendedType(extendedType);
+ }
+
+ /**
+ * Sets the supertype
+ *
+ * @param superType the super, can be null
+ * @return this, the WildcardType
+ */
+ @Generated("com.github.javaparser.generator.core.node.PropertyGenerator")
+ public WildcardType setSuperType(final ReferenceType superType) {
+ if (superType == this.superType) {
+ return (WildcardType) this;
+ }
+ notifyPropertyChange(ObservableProperty.SUPER_TYPE, this.superType, superType);
+ if (this.superType != null)
+ this.superType.setParentNode(null);
+ this.superType = superType;
+ setAsParentNodeOf(superType);
+ return this;
+ }
+
+ /**
+ * Sets the supertype
+ *
+ * @param superType the super, can be null
+ * @return this, the WildcardType
+ * @deprecated use setSuperType instead
+ */
+ @Deprecated
+ public WildcardType setSuperTypes(final ReferenceType superType) {
+ return setSuperType(superType);
+ }
+
+ @Override
+ public WildcardType setAnnotations(NodeList<AnnotationExpr> annotations) {
+ return (WildcardType) super.setAnnotations(annotations);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public boolean remove(Node node) {
+ if (node == null)
+ return false;
+ if (extendedType != null) {
+ if (node == extendedType) {
+ removeExtendedType();
+ return true;
+ }
+ }
+ if (superType != null) {
+ if (node == superType) {
+ removeSuperType();
+ return true;
+ }
+ }
+ return super.remove(node);
+ }
+
+ @Override
+ public String asString() {
+ StringBuilder str = new StringBuilder("?");
+ getExtendedType().ifPresent(t -> str.append(" extends ").append(t.asString()));
+ getSuperType().ifPresent(t -> str.append(" super ").append(t.asString()));
+ return str.toString();
+ }
+
+ @Deprecated
+ public WildcardType removeExtendedTypes() {
+ return removeExtendedType();
+ }
+
+ @Deprecated
+ public WildcardType removeSuperTypes() {
+ return removeSuperType();
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public WildcardType removeExtendedType() {
+ return setExtendedType((ReferenceType) null);
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.RemoveMethodGenerator")
+ public WildcardType removeSuperType() {
+ return setSuperType((ReferenceType) null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.CloneGenerator")
+ public WildcardType clone() {
+ return (WildcardType) accept(new CloneVisitor(), null);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.GetMetaModelGenerator")
+ public WildcardTypeMetaModel getMetaModel() {
+ return JavaParserMetaModel.wildcardTypeMetaModel;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.ReplaceMethodGenerator")
+ public boolean replace(Node node, Node replacementNode) {
+ if (node == null)
+ return false;
+ if (extendedType != null) {
+ if (node == extendedType) {
+ setExtendedType((ReferenceType) replacementNode);
+ return true;
+ }
+ }
+ if (superType != null) {
+ if (node == superType) {
+ setSuperType((ReferenceType) replacementNode);
+ return true;
+ }
+ }
+ return super.replace(node, replacementNode);
+ }
+
+ /**
+ * This constructor is used by the parser and is considered private.
+ */
+ @Generated("com.github.javaparser.generator.core.node.MainConstructorGenerator")
+ public WildcardType(TokenRange tokenRange, ReferenceType extendedType, ReferenceType superType) {
+ super(tokenRange);
+ setExtendedType(extendedType);
+ setSuperType(superType);
+ customInitialization();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public boolean isWildcardType() {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public WildcardType asWildcardType() {
+ return this;
+ }
+
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public void ifWildcardType(Consumer<WildcardType> action) {
+ action.accept(this);
+ }
+
+ @Override
+ public ResolvedWildcard resolve() {
+ return getSymbolResolver().toResolvedType(this, ResolvedWildcard.class);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.node.TypeCastingGenerator")
+ public Optional<WildcardType> toWildcardType() {
+ return Optional.of(this);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java10Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java10Validator.java
new file mode 100644
index 000000000..c7fda2f46
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java10Validator.java
@@ -0,0 +1,19 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.type.VarType;
+import com.github.javaparser.ast.validator.chunks.VarValidator;
+
+/**
+ * This validator validates according to Java 10 syntax rules.
+ */
+public class Java10Validator extends Java9Validator {
+
+ protected final Validator varOnlyOnLocalVariableDefinitionAndFor = new SingleNodeTypeValidator<>(VarType.class, new VarValidator(false));
+
+ public Java10Validator() {
+ super();
+ add(varOnlyOnLocalVariableDefinitionAndFor);
+ /* There is no validator that validates that "var" is not used in Java 9 and lower, since the parser will never create a VarType node,
+ because that is done by the Java10 postprocessor. You can add it by hand, but that is obscure enough to ignore. */
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java11Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java11Validator.java
new file mode 100644
index 000000000..0eb879aa0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java11Validator.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.type.VarType;
+import com.github.javaparser.ast.validator.chunks.VarValidator;
+
+/**
+ * This validator validates according to Java 11 syntax rules.
+ */
+public class Java11Validator extends Java10Validator {
+ protected final Validator varAlsoInLambdaParameters = new SingleNodeTypeValidator<>(VarType.class, new VarValidator(true));
+
+ public Java11Validator() {
+ super();
+ replace(varOnlyOnLocalVariableDefinitionAndFor, varAlsoInLambdaParameters);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_0Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_0Validator.java
new file mode 100644
index 000000000..0d1051d67
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_0Validator.java
@@ -0,0 +1,121 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.ImportDeclaration;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.expr.ClassExpr;
+import com.github.javaparser.ast.expr.LambdaExpr;
+import com.github.javaparser.ast.expr.StringLiteralExpr;
+import com.github.javaparser.ast.modules.ModuleDeclaration;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeParameters;
+import com.github.javaparser.ast.stmt.AssertStmt;
+import com.github.javaparser.ast.stmt.ForeachStmt;
+import com.github.javaparser.ast.stmt.SwitchEntryStmt;
+import com.github.javaparser.ast.stmt.TryStmt;
+import com.github.javaparser.ast.type.UnionType;
+import com.github.javaparser.ast.validator.chunks.CommonValidators;
+import com.github.javaparser.ast.validator.chunks.ModifierValidator;
+import com.github.javaparser.ast.validator.chunks.NoBinaryIntegerLiteralsValidator;
+import com.github.javaparser.ast.validator.chunks.NoUnderscoresInIntegerLiteralsValidator;
+
+/**
+ * This validator validates according to Java 1.0 syntax rules.
+ */
+public class Java1_0Validator extends Validators {
+ protected final Validator modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods
+ = new ModifierValidator(false, false, false);
+ protected final Validator noAssertKeyword = new SimpleValidator<>(AssertStmt.class,
+ n -> true,
+ (n, reporter) -> reporter.report(n, "'assert' keyword is not supported.")
+ );
+ protected final Validator noInnerClasses = new SimpleValidator<>(ClassOrInterfaceDeclaration.class,
+ n -> !n.isTopLevelType(),
+ (n, reporter) -> reporter.report(n, "inner classes or interfaces are not supported.")
+ );
+ protected final Validator noReflection = new SimpleValidator<>(ClassExpr.class,
+ n -> true,
+ (n, reporter) -> reporter.report(n, "Reflection is not supported.")
+ );
+ protected final Validator noGenerics = new TreeVisitorValidator((node, reporter) -> {
+ if (node instanceof NodeWithTypeArguments) {
+ if (((NodeWithTypeArguments<? extends Node>) node).getTypeArguments().isPresent()) {
+ reporter.report(node, "Generics are not supported.");
+ }
+ }
+ if (node instanceof NodeWithTypeParameters) {
+ if (((NodeWithTypeParameters<? extends Node>) node).getTypeParameters().isNonEmpty()) {
+ reporter.report(node, "Generics are not supported.");
+ }
+ }
+ });
+ protected final SingleNodeTypeValidator<TryStmt> tryWithoutResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> {
+ if (n.getCatchClauses().isEmpty() && !n.getFinallyBlock().isPresent()) {
+ reporter.report(n, "Try has no finally and no catch.");
+ }
+ if (n.getResources().isNonEmpty()) {
+ reporter.report(n, "Catch with resource is not supported.");
+ }
+ });
+ protected final Validator noAnnotations = new TreeVisitorValidator((node, reporter) -> {
+ if (node instanceof AnnotationExpr || node instanceof AnnotationDeclaration) {
+ reporter.report(node, "Annotations are not supported.");
+ }
+ });
+ protected final Validator noEnums = new SimpleValidator<>(EnumDeclaration.class,
+ n -> true,
+ (n, reporter) -> reporter.report(n, "Enumerations are not supported.")
+ );
+ protected final Validator noVarargs = new SimpleValidator<>(Parameter.class,
+ Parameter::isVarArgs,
+ (n, reporter) -> reporter.report(n, "Varargs are not supported.")
+ );
+ protected final Validator noForEach = new SimpleValidator<>(ForeachStmt.class,
+ n -> true,
+ (n, reporter) -> reporter.report(n, "For-each loops are not supported.")
+ );
+ protected final Validator noStaticImports = new SimpleValidator<>(ImportDeclaration.class,
+ ImportDeclaration::isStatic,
+ (n, reporter) -> reporter.report(n, "Static imports are not supported.")
+ );
+ protected final Validator noStringsInSwitch = new SimpleValidator<>(SwitchEntryStmt.class,
+ n -> n.getLabel().map(l -> l instanceof StringLiteralExpr).orElse(false),
+ (n, reporter) -> reporter.report(n.getLabel().get(), "Strings in switch statements are not supported.")
+ );
+ protected final Validator noBinaryIntegerLiterals = new NoBinaryIntegerLiteralsValidator();
+ protected final Validator noUnderscoresInIntegerLiterals = new NoUnderscoresInIntegerLiteralsValidator();
+ protected final Validator noMultiCatch = new SimpleValidator<>(UnionType.class,
+ n -> true,
+ (n, reporter) -> reporter.report(n, "Multi-catch is not supported.")
+ );
+ protected final Validator noLambdas = new SimpleValidator<>(LambdaExpr.class,
+ n -> true,
+ (n, reporter) -> reporter.report(n, "Lambdas are not supported.")
+ );
+ protected final Validator noModules = new SimpleValidator<>(ModuleDeclaration.class,
+ n -> true,
+ (n, reporter) -> reporter.report(n, "Modules are not supported.")
+ );
+
+ public Java1_0Validator() {
+ super(new CommonValidators());
+ add(modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods);
+ add(noAssertKeyword);
+ add(noInnerClasses);
+ add(noReflection);
+ add(noGenerics);
+ add(tryWithoutResources);
+ add(noAnnotations);
+ add(noEnums);
+ add(noVarargs);
+ add(noForEach);
+ add(noStaticImports);
+ add(noStringsInSwitch);
+ add(noBinaryIntegerLiterals);
+ add(noUnderscoresInIntegerLiterals);
+ add(noMultiCatch);
+ add(noLambdas);
+ add(noModules);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_1Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_1Validator.java
new file mode 100644
index 000000000..5279b7f95
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_1Validator.java
@@ -0,0 +1,22 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.stmt.LocalClassDeclarationStmt;
+
+/**
+ * This validator validates according to Java 1.1 syntax rules.
+ */
+public class Java1_1Validator extends Java1_0Validator {
+ protected final Validator innerClasses = new SingleNodeTypeValidator<>(ClassOrInterfaceDeclaration.class,
+ (n, reporter) -> n.getParentNode().ifPresent(p -> {
+ if (p instanceof LocalClassDeclarationStmt && n.isInterface())
+ reporter.report(n, "There is no such thing as a local interface.");
+ })
+ );
+
+ public Java1_1Validator() {
+ super();
+ replace(noInnerClasses, innerClasses);
+ remove(noReflection);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_2Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_2Validator.java
new file mode 100644
index 000000000..4ac7565b2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_2Validator.java
@@ -0,0 +1,17 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.validator.chunks.ModifierValidator;
+
+/**
+ * This validator validates according to Java 1.2 syntax rules.
+ */
+public class Java1_2Validator extends Java1_1Validator {
+ protected final Validator modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods = new ModifierValidator(true, false, false);
+ protected final Validator strictfpNotAllowed = new ReservedKeywordValidator("strictfp");
+
+ public Java1_2Validator() {
+ super();
+ replace(modifiersWithoutStrictfpAndDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods, modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods);
+ add(strictfpNotAllowed);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_3Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_3Validator.java
new file mode 100644
index 000000000..72830a117
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_3Validator.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.ast.validator;
+
+/**
+ * This validator validates according to Java 1.3 syntax rules.
+ */
+public class Java1_3Validator extends Java1_2Validator {
+ public Java1_3Validator() {
+ super();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_4Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_4Validator.java
new file mode 100644
index 000000000..2d4ad5e86
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java1_4Validator.java
@@ -0,0 +1,11 @@
+package com.github.javaparser.ast.validator;
+
+/**
+ * This validator validates according to Java 1.4 syntax rules.
+ */
+public class Java1_4Validator extends Java1_3Validator {
+ public Java1_4Validator() {
+ super();
+ remove(noAssertKeyword);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java5Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java5Validator.java
new file mode 100644
index 000000000..d8b1aab1b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java5Validator.java
@@ -0,0 +1,52 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.type.PrimitiveType;
+import com.github.javaparser.ast.type.Type;
+
+import java.util.Optional;
+
+/**
+ * This validator validates according to Java 5 syntax rules.
+ */
+public class Java5Validator extends Java1_4Validator {
+ Validator genericsWithoutDiamondOperator = new TreeVisitorValidator((node, reporter) -> {
+ if (node instanceof NodeWithTypeArguments) {
+ Optional<NodeList<Type>> typeArguments = ((NodeWithTypeArguments<? extends Node>) node).getTypeArguments();
+ if (typeArguments.isPresent() && typeArguments.get().isEmpty()) {
+ reporter.report(node, "The diamond operator is not supported.");
+ }
+ }
+ });
+
+ protected Validator noPrimitiveGenericArguments = new TreeVisitorValidator((node, reporter) -> {
+ if (node instanceof NodeWithTypeArguments) {
+ Optional<NodeList<Type>> typeArguments = ((NodeWithTypeArguments<? extends Node>) node).getTypeArguments();
+ typeArguments.ifPresent(types -> types.forEach(ty -> {
+ if (ty instanceof PrimitiveType) {
+ reporter.report(node, "Type arguments may not be primitive.");
+ }
+ }));
+ }
+ });
+
+ protected final Validator enumNotAllowed = new ReservedKeywordValidator("enum");
+
+ public Java5Validator() {
+ super();
+ replace(noGenerics, genericsWithoutDiamondOperator);
+ add(noPrimitiveGenericArguments);
+ add(enumNotAllowed);
+
+ // TODO validate annotations on classes, fields and methods but nowhere else
+ // The following is probably too simple.
+ remove(noAnnotations);
+
+ remove(noEnums);
+ remove(noVarargs);
+ remove(noForEach);
+ remove(noStaticImports);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java6Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java6Validator.java
new file mode 100644
index 000000000..705400318
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java6Validator.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.ast.validator;
+
+/**
+ * This validator validates according to Java 6 syntax rules.
+ */
+public class Java6Validator extends Java5Validator{
+ public Java6Validator() {
+ super();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java7Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java7Validator.java
new file mode 100644
index 000000000..995e83620
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java7Validator.java
@@ -0,0 +1,39 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.stmt.TryStmt;
+import com.github.javaparser.ast.type.UnionType;
+
+/**
+ * This validator validates according to Java 7 syntax rules.
+ */
+public class Java7Validator extends Java6Validator {
+ protected final SingleNodeTypeValidator<TryStmt> tryWithLimitedResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> {
+ if (n.getCatchClauses().isEmpty()
+ && n.getResources().isEmpty()
+ && !n.getFinallyBlock().isPresent()) {
+ reporter.report(n, "Try has no finally, no catch, and no resources.");
+ }
+ for (Expression resource : n.getResources()) {
+ if (!resource.isVariableDeclarationExpr()) {
+ reporter.report(n, "Try with resources only supports variable declarations.");
+ }
+ }
+ });
+ protected final SingleNodeTypeValidator<UnionType> multiCatch = new SingleNodeTypeValidator<>(UnionType.class, (n, reporter) -> {
+ // Case "0 elements" is caught elsewhere.
+ if (n.getElements().size() == 1) {
+ reporter.report(n, "Union type (multi catch) must have at least two elements.");
+ }
+ });
+
+ public Java7Validator() {
+ super();
+ remove(genericsWithoutDiamondOperator);
+ replace(tryWithoutResources, tryWithLimitedResources);
+ remove(noStringsInSwitch);
+ remove(noBinaryIntegerLiterals);
+ remove(noUnderscoresInIntegerLiterals);
+ replace(noMultiCatch, multiCatch);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java8Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java8Validator.java
new file mode 100644
index 000000000..e6aca92d0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java8Validator.java
@@ -0,0 +1,32 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.validator.chunks.ModifierValidator;
+
+/**
+ * This validator validates according to Java 7 syntax rules.
+ */
+public class Java8Validator extends Java7Validator {
+ protected final Validator modifiersWithoutPrivateInterfaceMethods = new ModifierValidator(true, true, false);
+ protected final Validator defaultMethodsInInterface = new SingleNodeTypeValidator<>(ClassOrInterfaceDeclaration.class,
+ (n, reporter) -> {
+ if (n.isInterface()) {
+ n.getMethods().forEach(m -> {
+ if (m.isDefault() && !m.getBody().isPresent()) {
+ reporter.report(m, "'default' methods must have a body.");
+ }
+ });
+ }
+ }
+ );
+
+ public Java8Validator() {
+ super();
+ replace(modifiersWithoutDefaultAndStaticInterfaceMethodsAndPrivateInterfaceMethods, modifiersWithoutPrivateInterfaceMethods);
+ add(defaultMethodsInInterface);
+ remove(noLambdas);
+
+ // TODO validate more annotation locations http://openjdk.java.net/jeps/104
+ // TODO validate repeating annotations http://openjdk.java.net/jeps/120
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java9Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java9Validator.java
new file mode 100644
index 000000000..2175c9af3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Java9Validator.java
@@ -0,0 +1,30 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.expr.VariableDeclarationExpr;
+import com.github.javaparser.ast.stmt.TryStmt;
+import com.github.javaparser.ast.validator.chunks.ModifierValidator;
+import com.github.javaparser.ast.validator.chunks.UnderscoreKeywordValidator;
+
+/**
+ * This validator validates according to Java 9 syntax rules.
+ */
+public class Java9Validator extends Java8Validator {
+ protected final Validator underscoreKeywordValidator = new UnderscoreKeywordValidator();
+ protected final Validator modifiers = new ModifierValidator(true, true, true);
+ protected final SingleNodeTypeValidator<TryStmt> tryWithResources = new SingleNodeTypeValidator<>(TryStmt.class, (n, reporter) -> {
+ if (n.getCatchClauses().isEmpty()
+ && n.getResources().isEmpty()
+ && !n.getFinallyBlock().isPresent()) {
+ reporter.report(n, "Try has no finally, no catch, and no resources.");
+ }
+ });
+
+ public Java9Validator() {
+ super();
+ add(underscoreKeywordValidator);
+ remove(noModules);
+ replace(modifiersWithoutPrivateInterfaceMethods, modifiers);
+ replace(tryWithLimitedResources, tryWithResources);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/NoProblemsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/NoProblemsValidator.java
new file mode 100644
index 000000000..002668892
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/NoProblemsValidator.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ParserConfiguration;
+import com.github.javaparser.ast.Node;
+
+/**
+ * Stub validator for when no validation is wanted.
+ *
+ * @deprecated when setting a language validator, try {@link com.github.javaparser.ParserConfiguration#setLanguageLevel(ParserConfiguration.LanguageLevel)} with RAW.
+ */
+@Deprecated
+public final class NoProblemsValidator implements Validator {
+ @Override
+ public void accept(Node node, ProblemReporter problemReporter) {
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/ProblemReporter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/ProblemReporter.java
new file mode 100644
index 000000000..eb54810c1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/ProblemReporter.java
@@ -0,0 +1,34 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.Problem;
+import com.github.javaparser.TokenRange;
+import com.github.javaparser.ast.nodeTypes.NodeWithTokenRange;
+
+import java.util.function.Consumer;
+
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+
+/**
+ * A simple interface where validators can report found problems.
+ */
+public class ProblemReporter {
+ private final Consumer<Problem> problemConsumer;
+
+ public ProblemReporter(Consumer<Problem> problemConsumer) {
+ this.problemConsumer = problemConsumer;
+ }
+
+ /**
+ * Report a problem.
+ *
+ * @param message description of the problem
+ * @param node the node in which the problem occurred, used to find the Range of the problem.
+ */
+ public void report(NodeWithTokenRange<?> node, String message, Object... args) {
+ report(node.getTokenRange().orElse(null), message, args);
+ }
+
+ public void report(TokenRange range, String message, Object... args) {
+ problemConsumer.accept(new Problem(f(message, args), range, null));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/ReservedKeywordValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/ReservedKeywordValidator.java
new file mode 100644
index 000000000..51a08bdca
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/ReservedKeywordValidator.java
@@ -0,0 +1,36 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.expr.SimpleName;
+
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+
+/**
+ * Validates that identifiers are not keywords - this for the few keywords that the parser
+ * accepts because they were added after Java 1.0.
+ */
+public class ReservedKeywordValidator extends VisitorValidator {
+ private final String keyword;
+ private final String error;
+
+ public ReservedKeywordValidator(String keyword) {
+ this.keyword = keyword;
+ error = f("'%s' cannot be used as an identifier as it is a keyword.", keyword);
+ }
+
+ @Override
+ public void visit(Name n, ProblemReporter arg) {
+ if (n.getIdentifier().equals(keyword)) {
+ arg.report(n, error);
+ }
+ super.visit(n, arg);
+ }
+
+ @Override
+ public void visit(SimpleName n, ProblemReporter arg) {
+ if (n.getIdentifier().equals(keyword)) {
+ arg.report(n, error);
+ }
+ super.visit(n, arg);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SimpleValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SimpleValidator.java
new file mode 100644
index 000000000..b705b9146
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SimpleValidator.java
@@ -0,0 +1,20 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.Node;
+
+import java.util.function.BiConsumer;
+import java.util.function.Predicate;
+
+/**
+ * Runs a validator on all nodes of a certain type,
+ * and adds a problem for all nodes that pass a condition.
+ */
+public class SimpleValidator<N extends Node> extends SingleNodeTypeValidator<N> {
+ public SimpleValidator(Class<N> type, Predicate<N> condition, BiConsumer<N, ProblemReporter> problemSupplier) {
+ super(type, (node, problemReporter) -> {
+ if (condition.test(node)) {
+ problemSupplier.accept(node, problemReporter);
+ }
+ });
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java
new file mode 100644
index 000000000..169849489
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/SingleNodeTypeValidator.java
@@ -0,0 +1,24 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.Node;
+
+/**
+ * Runs a validator on all nodes of a certain type.
+ */
+public class SingleNodeTypeValidator<N extends Node> implements Validator {
+ private final Class<N> type;
+ private final TypedValidator<N> validator;
+
+ public SingleNodeTypeValidator(Class<N> type, TypedValidator<N> validator) {
+ this.type = type;
+ this.validator = validator;
+ }
+
+ @Override
+ public void accept(Node node, ProblemReporter problemReporter) {
+ if (type.isInstance(node)) {
+ validator.accept(type.cast(node), problemReporter);
+ }
+ node.findAll(type).forEach(n -> validator.accept(n, problemReporter));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/TreeVisitorValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/TreeVisitorValidator.java
new file mode 100644
index 000000000..ae8e049e0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/TreeVisitorValidator.java
@@ -0,0 +1,22 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.Node;
+
+/**
+ * A validator that walks the whole tree, visiting every node.
+ */
+public class TreeVisitorValidator implements Validator {
+ private final Validator validator;
+
+ public TreeVisitorValidator(Validator validator) {
+ this.validator = validator;
+ }
+
+ @Override
+ public final void accept(Node node, ProblemReporter reporter) {
+ validator.accept(node, reporter);
+ for (Node child : node.getChildNodes()) {
+ accept(child, reporter);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/TypedValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/TypedValidator.java
new file mode 100644
index 000000000..588c53f11
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/TypedValidator.java
@@ -0,0 +1,24 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ParseResult;
+import com.github.javaparser.ast.Node;
+
+import java.util.function.BiConsumer;
+
+/**
+ * A validator that validates a known node type.
+ */
+public interface TypedValidator<N extends Node> extends BiConsumer<N, ProblemReporter> {
+ /**
+ * @param node the node that wants to be validated
+ * @param problemReporter when found, validation errors can be reported here
+ */
+ void accept(N node, ProblemReporter problemReporter);
+
+ @SuppressWarnings("unchecked")
+ default ParseResult.PostProcessor postProcessor() {
+ return (result, configuration) ->
+ result.getResult().ifPresent(node ->
+ accept((N) node, new ProblemReporter(problem -> result.getProblems().add(problem))));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validator.java
new file mode 100644
index 000000000..0d5752a03
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validator.java
@@ -0,0 +1,15 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.Node;
+
+/**
+ * A validator that can be run on a node to check for semantic errors.
+ * It is fully up to the implementor how to do this.
+ */
+public interface Validator extends TypedValidator<Node> {
+ /**
+ * @param node the node that wants to be validated
+ * @param problemReporter when found, validation errors can be reported here
+ */
+ void accept(Node node, ProblemReporter problemReporter);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validators.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validators.java
new file mode 100644
index 000000000..dd6926ab7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/Validators.java
@@ -0,0 +1,45 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.Node;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * A validator that will call a collection of validators.
+ */
+public class Validators implements Validator {
+ private final List<Validator> validators = new ArrayList<>();
+
+ public Validators(Validator... validators) {
+ this.validators.addAll(Arrays.asList(validators));
+ }
+
+ public List<Validator> getValidators() {
+ return validators;
+ }
+
+ public Validators remove(Validator validator) {
+ if (!validators.remove(validator)) {
+ throw new AssertionError("Trying to remove a validator that isn't there.");
+ }
+ return this;
+ }
+
+ public Validators replace(Validator oldValidator, Validator newValidator) {
+ remove(oldValidator);
+ add(newValidator);
+ return this;
+ }
+
+ public Validators add(Validator newValidator) {
+ validators.add(newValidator);
+ return this;
+ }
+
+ @Override
+ public void accept(Node node, ProblemReporter problemReporter) {
+ validators.forEach(v -> v.accept(node, problemReporter));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/VisitorValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/VisitorValidator.java
new file mode 100644
index 000000000..547092d67
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/VisitorValidator.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.ast.validator;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
+
+/**
+ * A validator that uses a visitor for validation.
+ * This class is the visitor too.
+ * Implement the "visit" methods you want to use for validation.
+ */
+public abstract class VisitorValidator extends VoidVisitorAdapter<ProblemReporter> implements Validator {
+ @Override
+ public void accept(Node node, ProblemReporter problemReporter) {
+ node.accept(this, problemReporter);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/CommonValidators.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/CommonValidators.java
new file mode 100644
index 000000000..5e5b7919e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/CommonValidators.java
@@ -0,0 +1,70 @@
+package com.github.javaparser.ast.validator.chunks;
+
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.body.InitializerDeclaration;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.validator.SimpleValidator;
+import com.github.javaparser.ast.validator.SingleNodeTypeValidator;
+import com.github.javaparser.ast.validator.TreeVisitorValidator;
+import com.github.javaparser.ast.validator.Validators;
+import com.github.javaparser.metamodel.NodeMetaModel;
+import com.github.javaparser.metamodel.PropertyMetaModel;
+
+import java.util.Optional;
+
+/**
+ * Contains validations that are valid for every Java version.
+ */
+public class CommonValidators extends Validators {
+ public CommonValidators() {
+ super(
+ new SimpleValidator<>(ClassOrInterfaceDeclaration.class,
+ n -> !n.isInterface() && n.getExtendedTypes().size() > 1,
+ (n, reporter) -> reporter.report(n.getExtendedTypes(1), "A class cannot extend more than one other class.")
+ ),
+ new SimpleValidator<>(ClassOrInterfaceDeclaration.class,
+ n -> n.isInterface() && !n.getImplementedTypes().isEmpty(),
+ (n, reporter) -> reporter.report(n.getImplementedTypes(0), "An interface cannot implement other interfaces.")
+ ),
+ new SingleNodeTypeValidator<>(ClassOrInterfaceDeclaration.class, (n, reporter) -> {
+ if (n.isInterface()) {
+ n.getMembers().forEach(mem -> {
+ if (mem instanceof InitializerDeclaration) {
+ reporter.report(mem, "An interface cannot have initializers.");
+ }
+ });
+ }
+ }
+ ),
+ new SingleNodeTypeValidator<>(AssignExpr.class, (n, reporter) -> {
+ // https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.26
+ Expression target = n.getTarget();
+ while (target instanceof EnclosedExpr) {
+ target = ((EnclosedExpr) target).getInner();
+ }
+ if (target instanceof NameExpr
+ || target instanceof ArrayAccessExpr
+ || target instanceof FieldAccessExpr) {
+ return;
+ }
+ reporter.report(n.getTarget(), "Illegal left hand side of an assignment.");
+ }
+ ),
+ new TreeVisitorValidator((node, problemReporter) -> {
+ NodeMetaModel mm = node.getMetaModel();
+ for (PropertyMetaModel ppm : mm.getAllPropertyMetaModels()) {
+ if (ppm.isNonEmpty()) {
+ if (ppm.isNodeList()) {
+ NodeList value = (NodeList) ppm.getValue(node);
+ if (value.isEmpty()) {
+ problemReporter.report(node, "%s.%s can not be empty.", mm.getTypeName(), ppm.getName());
+ }
+ }
+ // No need to check empty strings, it should be impossible to set them to ""
+ }
+ }
+ })
+ );
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/ModifierValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/ModifierValidator.java
new file mode 100644
index 000000000..0a01c3349
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/ModifierValidator.java
@@ -0,0 +1,211 @@
+package com.github.javaparser.ast.validator.chunks;
+
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.expr.LambdaExpr;
+import com.github.javaparser.ast.expr.VariableDeclarationExpr;
+import com.github.javaparser.ast.modules.ModuleRequiresStmt;
+import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
+import com.github.javaparser.ast.nodeTypes.NodeWithTokenRange;
+import com.github.javaparser.ast.stmt.CatchClause;
+import com.github.javaparser.ast.validator.ProblemReporter;
+import com.github.javaparser.ast.validator.VisitorValidator;
+import com.github.javaparser.utils.SeparatedItemStringBuilder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.github.javaparser.ast.Modifier.*;
+import static java.util.Arrays.asList;
+
+
+/**
+ * Verifies that only allowed modifiers are used where modifiers are expected.
+ */
+public class ModifierValidator extends VisitorValidator {
+ private final Modifier[] interfaceWithNothingSpecial = new Modifier[]{PUBLIC, PROTECTED, ABSTRACT, FINAL, SYNCHRONIZED, NATIVE, STRICTFP};
+ private final Modifier[] interfaceWithStaticAndDefault = new Modifier[]{PUBLIC, PROTECTED, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT};
+ private final Modifier[] interfaceWithStaticAndDefaultAndPrivate = new Modifier[]{PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP, DEFAULT};
+
+ private final boolean hasStrictfp;
+ private final boolean hasDefaultAndStaticInterfaceMethods;
+ private final boolean hasPrivateInterfaceMethods;
+
+ public ModifierValidator(boolean hasStrictfp, boolean hasDefaultAndStaticInterfaceMethods, boolean hasPrivateInterfaceMethods) {
+ this.hasStrictfp = hasStrictfp;
+ this.hasDefaultAndStaticInterfaceMethods = hasDefaultAndStaticInterfaceMethods;
+ this.hasPrivateInterfaceMethods = hasPrivateInterfaceMethods;
+ }
+
+ @Override
+ public void visit(ClassOrInterfaceDeclaration n, ProblemReporter reporter) {
+ if (n.isInterface()) {
+ validateInterfaceModifiers(n, reporter);
+ } else {
+ validateClassModifiers(n, reporter);
+ }
+ super.visit(n, reporter);
+ }
+
+ private void validateClassModifiers(ClassOrInterfaceDeclaration n, ProblemReporter reporter) {
+ if (n.isTopLevelType()) {
+ validateModifiers(n, reporter, PUBLIC, ABSTRACT, FINAL, STRICTFP);
+ } else if (n.isNestedType()) {
+ validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, STRICTFP);
+ } else if (n.isLocalClassDeclaration()) {
+ validateModifiers(n, reporter, ABSTRACT, FINAL, STRICTFP);
+ }
+ }
+
+ private void validateInterfaceModifiers(TypeDeclaration<?> n, ProblemReporter reporter) {
+ if (n.isTopLevelType()) {
+ validateModifiers(n, reporter, PUBLIC, ABSTRACT, STRICTFP);
+ } else if (n.isNestedType()) {
+ validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, STRICTFP);
+ }
+ }
+
+ @Override
+ public void visit(EnumDeclaration n, ProblemReporter reporter) {
+ if (n.isTopLevelType()) {
+ validateModifiers(n, reporter, PUBLIC, STRICTFP);
+ } else if (n.isNestedType()) {
+ validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, STATIC, STRICTFP);
+ }
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(AnnotationDeclaration n, ProblemReporter reporter) {
+ validateInterfaceModifiers(n, reporter);
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(AnnotationMemberDeclaration n, ProblemReporter reporter) {
+ validateModifiers(n, reporter, PUBLIC, ABSTRACT);
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(ConstructorDeclaration n, ProblemReporter reporter) {
+ validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE);
+ n.getParameters().forEach(p -> validateModifiers(p, reporter, FINAL));
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(FieldDeclaration n, ProblemReporter reporter) {
+ validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, STATIC, FINAL, TRANSIENT, VOLATILE);
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(MethodDeclaration n, ProblemReporter reporter) {
+ if (n.isAbstract()) {
+ final SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder("Cannot be 'abstract' and also '", "', '", "'.");
+ for (Modifier m : asList(PRIVATE, STATIC, FINAL, NATIVE, STRICTFP, SYNCHRONIZED)) {
+ if (n.getModifiers().contains(m)) {
+ builder.append(m.asString());
+ }
+ }
+ if (builder.hasItems()) {
+ reporter.report(n, builder.toString());
+ }
+ }
+ if (n.getParentNode().isPresent()) {
+ if (n.getParentNode().get() instanceof ClassOrInterfaceDeclaration) {
+ if (((ClassOrInterfaceDeclaration) n.getParentNode().get()).isInterface()) {
+ if (hasDefaultAndStaticInterfaceMethods) {
+ if (hasPrivateInterfaceMethods) {
+ validateModifiers(n, reporter, interfaceWithStaticAndDefaultAndPrivate);
+ } else {
+ validateModifiers(n, reporter, interfaceWithStaticAndDefault);
+ }
+ } else {
+ validateModifiers(n, reporter, interfaceWithNothingSpecial);
+ }
+ } else {
+ validateModifiers(n, reporter, PUBLIC, PROTECTED, PRIVATE, ABSTRACT, STATIC, FINAL, SYNCHRONIZED, NATIVE, STRICTFP);
+ }
+ }
+ }
+ n.getParameters().forEach(p -> validateModifiers(p, reporter, FINAL));
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(LambdaExpr n, ProblemReporter reporter) {
+ n.getParameters().forEach(p -> {
+ // Final is not allowed on inferred parameters, but those get caught by the parser.
+ validateModifiers(p, reporter, FINAL);
+ });
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(CatchClause n, ProblemReporter reporter) {
+ validateModifiers(n.getParameter(), reporter, FINAL);
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(VariableDeclarationExpr n, ProblemReporter reporter) {
+ validateModifiers(n, reporter, FINAL);
+ super.visit(n, reporter);
+ }
+
+ @Override
+ public void visit(ModuleRequiresStmt n, ProblemReporter reporter) {
+ validateModifiers(n, reporter, TRANSITIVE, STATIC);
+ super.visit(n, reporter);
+ }
+
+ private <T extends NodeWithModifiers<?> & NodeWithTokenRange<?>> void validateModifiers(T n, ProblemReporter reporter, Modifier... allowedModifiers) {
+ validateAtMostOneOf(n, reporter, PUBLIC, PROTECTED, PRIVATE);
+ validateAtMostOneOf(n, reporter, FINAL, ABSTRACT);
+ if (hasStrictfp) {
+ validateAtMostOneOf(n, reporter, NATIVE, STRICTFP);
+ } else {
+ allowedModifiers = removeModifierFromArray(STRICTFP, allowedModifiers);
+ }
+ for (Modifier m : n.getModifiers()) {
+ if (!arrayContains(allowedModifiers, m)) {
+ reporter.report(n, "'%s' is not allowed here.", m.asString());
+ }
+ }
+ }
+
+ private Modifier[] removeModifierFromArray(Modifier m, Modifier[] allowedModifiers) {
+ final List<Modifier> newModifiers = new ArrayList<>(asList(allowedModifiers));
+ newModifiers.remove(m);
+ allowedModifiers = newModifiers.toArray(new Modifier[0]);
+ return allowedModifiers;
+ }
+
+ private boolean arrayContains(Object[] items, Object searchItem) {
+ for (Object o : items) {
+ if (o == searchItem) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private <T extends NodeWithModifiers<?> & NodeWithTokenRange<?>> void validateAtMostOneOf(T t, ProblemReporter reporter, Modifier... modifiers) {
+ List<Modifier> foundModifiers = new ArrayList<>();
+ for (Modifier m : modifiers) {
+ if (t.getModifiers().contains(m)) {
+ foundModifiers.add(m);
+ }
+ }
+ if (foundModifiers.size() > 1) {
+ SeparatedItemStringBuilder builder = new SeparatedItemStringBuilder("Can have only one of '", "', '", "'.");
+ for (Modifier m : foundModifiers) {
+ builder.append(m.asString());
+ }
+ reporter.report(t, builder.toString());
+ }
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java
new file mode 100644
index 000000000..82e8dd7cc
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoBinaryIntegerLiteralsValidator.java
@@ -0,0 +1,27 @@
+package com.github.javaparser.ast.validator.chunks;
+
+import com.github.javaparser.ast.expr.IntegerLiteralExpr;
+import com.github.javaparser.ast.expr.LiteralStringValueExpr;
+import com.github.javaparser.ast.expr.LongLiteralExpr;
+import com.github.javaparser.ast.validator.ProblemReporter;
+import com.github.javaparser.ast.validator.VisitorValidator;
+
+public class NoBinaryIntegerLiteralsValidator extends VisitorValidator {
+ @Override
+ public void visit(IntegerLiteralExpr n, ProblemReporter arg) {
+ validate(n, arg);
+ super.visit(n, arg);
+ }
+
+ @Override
+ public void visit(LongLiteralExpr n, ProblemReporter arg) {
+ validate(n, arg);
+ super.visit(n, arg);
+ }
+
+ private static void validate(LiteralStringValueExpr n, ProblemReporter arg) {
+ if (n.getValue().toUpperCase().startsWith("0B")) {
+ arg.report(n, "Binary literal values are not supported.");
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java
new file mode 100644
index 000000000..901b7348f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/NoUnderscoresInIntegerLiteralsValidator.java
@@ -0,0 +1,27 @@
+package com.github.javaparser.ast.validator.chunks;
+
+import com.github.javaparser.ast.expr.IntegerLiteralExpr;
+import com.github.javaparser.ast.expr.LiteralStringValueExpr;
+import com.github.javaparser.ast.expr.LongLiteralExpr;
+import com.github.javaparser.ast.validator.ProblemReporter;
+import com.github.javaparser.ast.validator.VisitorValidator;
+
+public class NoUnderscoresInIntegerLiteralsValidator extends VisitorValidator {
+ @Override
+ public void visit(IntegerLiteralExpr n, ProblemReporter arg) {
+ validate(n, arg);
+ super.visit(n, arg);
+ }
+
+ @Override
+ public void visit(LongLiteralExpr n, ProblemReporter arg) {
+ validate(n, arg);
+ super.visit(n, arg);
+ }
+
+ private static void validate(LiteralStringValueExpr n, ProblemReporter arg) {
+ if (n.getValue().contains("_")) {
+ arg.report(n, "Underscores in literal values are not supported.");
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java
new file mode 100644
index 000000000..e812597bb
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/UnderscoreKeywordValidator.java
@@ -0,0 +1,27 @@
+package com.github.javaparser.ast.validator.chunks;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Name;
+import com.github.javaparser.ast.expr.SimpleName;
+import com.github.javaparser.ast.validator.ProblemReporter;
+import com.github.javaparser.ast.validator.VisitorValidator;
+
+public class UnderscoreKeywordValidator extends VisitorValidator {
+ @Override
+ public void visit(Name n, ProblemReporter arg) {
+ validateIdentifier(n, n.getIdentifier(), arg);
+ super.visit(n, arg);
+ }
+
+ @Override
+ public void visit(SimpleName n, ProblemReporter arg) {
+ validateIdentifier(n, n.getIdentifier(), arg);
+ super.visit(n, arg);
+ }
+
+ private static void validateIdentifier(Node n, String id, ProblemReporter arg) {
+ if (id.equals("_")) {
+ arg.report(n, "'_' is a reserved keyword.");
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/VarValidator.java b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/VarValidator.java
new file mode 100644
index 000000000..19357e83c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/validator/chunks/VarValidator.java
@@ -0,0 +1,93 @@
+package com.github.javaparser.ast.validator.chunks;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.body.Parameter;
+import com.github.javaparser.ast.body.VariableDeclarator;
+import com.github.javaparser.ast.expr.ArrayCreationExpr;
+import com.github.javaparser.ast.expr.LambdaExpr;
+import com.github.javaparser.ast.expr.NullLiteralExpr;
+import com.github.javaparser.ast.expr.VariableDeclarationExpr;
+import com.github.javaparser.ast.stmt.ExpressionStmt;
+import com.github.javaparser.ast.stmt.ForStmt;
+import com.github.javaparser.ast.stmt.ForeachStmt;
+import com.github.javaparser.ast.type.VarType;
+import com.github.javaparser.ast.validator.ProblemReporter;
+import com.github.javaparser.ast.validator.TypedValidator;
+
+import java.util.Optional;
+
+public class VarValidator implements TypedValidator<VarType> {
+ private boolean varAllowedInLambdaParameters;
+
+ public VarValidator(boolean varAllowedInLambdaParameters) {
+ this.varAllowedInLambdaParameters = varAllowedInLambdaParameters;
+ }
+
+ @Override
+ public void accept(VarType node, ProblemReporter reporter) {
+ // All allowed locations are within a VariableDeclaration inside a VariableDeclarationExpr inside something else.
+ Optional<VariableDeclarator> variableDeclarator = node.findParent(VariableDeclarator.class);
+ if (!variableDeclarator.isPresent()) {
+ // Java 11's var in lambda's
+ if (varAllowedInLambdaParameters) {
+ boolean valid = node
+ .findParent(Parameter.class)
+ .flatMap(Node::getParentNode)
+ .map((Node p) -> p instanceof LambdaExpr).orElse(false);
+ if (valid) {
+ return;
+ }
+ }
+ reportIllegalPosition(node, reporter);
+ return;
+ }
+ variableDeclarator.ifPresent(vd -> {
+ Optional<Node> variableDeclarationExpr = vd.getParentNode();
+ if (!variableDeclarationExpr.isPresent()) {
+ reportIllegalPosition(node, reporter);
+ return;
+ }
+ variableDeclarationExpr.ifPresent(vdeNode -> {
+ if (!(vdeNode instanceof VariableDeclarationExpr)) {
+ reportIllegalPosition(node, reporter);
+ return;
+ }
+ VariableDeclarationExpr vde = (VariableDeclarationExpr) vdeNode;
+ if (vde.getVariables().size() > 1) {
+ reporter.report(vde, "\"var\" only takes a single variable.");
+ }
+ Optional<Node> container = vdeNode.getParentNode();
+ if (!container.isPresent()) {
+ reportIllegalPosition(node, reporter);
+ return;
+ }
+ container.ifPresent(c -> {
+ boolean positionIsFine = c instanceof ForStmt || c instanceof ForeachStmt || c instanceof ExpressionStmt;
+ if (!positionIsFine) {
+ reportIllegalPosition(node, reporter);
+ }
+ // A local variable declaration ends up inside an ExpressionStmt.
+ if (c instanceof ExpressionStmt) {
+ if (!vd.getInitializer().isPresent()) {
+ reporter.report(node, "\"var\" needs an initializer.");
+ }
+ vd.getInitializer().ifPresent(initializer -> {
+ if (initializer instanceof NullLiteralExpr) {
+ reporter.report(node, "\"var\" cannot infer type from just null.");
+ }
+ if (initializer instanceof ArrayCreationExpr) {
+ reporter.report(node, "\"var\" cannot infer array types.");
+ }
+ });
+
+ }
+ });
+ });
+ });
+
+ }
+
+ private void reportIllegalPosition(VarType n, ProblemReporter reporter) {
+ reporter.report(n, "\"var\" is not allowed here.");
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java
new file mode 100644
index 000000000..4ae343ac6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/CloneVisitor.java
@@ -0,0 +1,1080 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.*;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import java.util.Optional;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that clones (copies) a node and all its children.
+ */
+public class CloneVisitor implements GenericVisitor<Visitable, Object> {
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final CompilationUnit n, final Object arg) {
+ NodeList<ImportDeclaration> imports = cloneList(n.getImports(), arg);
+ ModuleDeclaration module = cloneNode(n.getModule(), arg);
+ PackageDeclaration packageDeclaration = cloneNode(n.getPackageDeclaration(), arg);
+ NodeList<TypeDeclaration<?>> types = cloneList(n.getTypes(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ CompilationUnit r = new CompilationUnit(n.getTokenRange().orElse(null), packageDeclaration, imports, types, module);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final PackageDeclaration n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ PackageDeclaration r = new PackageDeclaration(n.getTokenRange().orElse(null), annotations, name);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final TypeParameter n, final Object arg) {
+ SimpleName name = cloneNode(n.getName(), arg);
+ NodeList<ClassOrInterfaceType> typeBound = cloneList(n.getTypeBound(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ TypeParameter r = new TypeParameter(n.getTokenRange().orElse(null), name, typeBound, annotations);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final LineComment n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ LineComment r = new LineComment(n.getTokenRange().orElse(null), n.getContent());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final BlockComment n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ BlockComment r = new BlockComment(n.getTokenRange().orElse(null), n.getContent());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ClassOrInterfaceDeclaration n, final Object arg) {
+ NodeList<ClassOrInterfaceType> extendedTypes = cloneList(n.getExtendedTypes(), arg);
+ NodeList<ClassOrInterfaceType> implementedTypes = cloneList(n.getImplementedTypes(), arg);
+ NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg);
+ NodeList<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ClassOrInterfaceDeclaration r = new ClassOrInterfaceDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, n.isInterface(), name, typeParameters, extendedTypes, implementedTypes, members);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final EnumDeclaration n, final Object arg) {
+ NodeList<EnumConstantDeclaration> entries = cloneList(n.getEntries(), arg);
+ NodeList<ClassOrInterfaceType> implementedTypes = cloneList(n.getImplementedTypes(), arg);
+ NodeList<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ EnumDeclaration r = new EnumDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, name, implementedTypes, entries, members);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final EnumConstantDeclaration n, final Object arg) {
+ NodeList<Expression> arguments = cloneList(n.getArguments(), arg);
+ NodeList<BodyDeclaration<?>> classBody = cloneList(n.getClassBody(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ EnumConstantDeclaration r = new EnumConstantDeclaration(n.getTokenRange().orElse(null), annotations, name, arguments, classBody);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final AnnotationDeclaration n, final Object arg) {
+ NodeList<BodyDeclaration<?>> members = cloneList(n.getMembers(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ AnnotationDeclaration r = new AnnotationDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, name, members);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final AnnotationMemberDeclaration n, final Object arg) {
+ Expression defaultValue = cloneNode(n.getDefaultValue(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ Type type = cloneNode(n.getType(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ AnnotationMemberDeclaration r = new AnnotationMemberDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, type, name, defaultValue);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final FieldDeclaration n, final Object arg) {
+ NodeList<VariableDeclarator> variables = cloneList(n.getVariables(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ FieldDeclaration r = new FieldDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, variables);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final VariableDeclarator n, final Object arg) {
+ Expression initializer = cloneNode(n.getInitializer(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ Type type = cloneNode(n.getType(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ VariableDeclarator r = new VariableDeclarator(n.getTokenRange().orElse(null), type, name, initializer);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ConstructorDeclaration n, final Object arg) {
+ BlockStmt body = cloneNode(n.getBody(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ NodeList<Parameter> parameters = cloneList(n.getParameters(), arg);
+ ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg);
+ NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg);
+ NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ConstructorDeclaration r = new ConstructorDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, typeParameters, name, parameters, thrownExceptions, body, receiverParameter);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final MethodDeclaration n, final Object arg) {
+ BlockStmt body = cloneNode(n.getBody(), arg);
+ Type type = cloneNode(n.getType(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ NodeList<Parameter> parameters = cloneList(n.getParameters(), arg);
+ ReceiverParameter receiverParameter = cloneNode(n.getReceiverParameter(), arg);
+ NodeList<ReferenceType> thrownExceptions = cloneList(n.getThrownExceptions(), arg);
+ NodeList<TypeParameter> typeParameters = cloneList(n.getTypeParameters(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ MethodDeclaration r = new MethodDeclaration(n.getTokenRange().orElse(null), n.getModifiers(), annotations, typeParameters, type, name, parameters, thrownExceptions, body, receiverParameter);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final Parameter n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ Type type = cloneNode(n.getType(), arg);
+ NodeList<AnnotationExpr> varArgsAnnotations = cloneList(n.getVarArgsAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ Parameter r = new Parameter(n.getTokenRange().orElse(null), n.getModifiers(), annotations, type, n.isVarArgs(), varArgsAnnotations, name);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final InitializerDeclaration n, final Object arg) {
+ BlockStmt body = cloneNode(n.getBody(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ InitializerDeclaration r = new InitializerDeclaration(n.getTokenRange().orElse(null), n.isStatic(), body);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final JavadocComment n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ JavadocComment r = new JavadocComment(n.getTokenRange().orElse(null), n.getContent());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ClassOrInterfaceType n, final Object arg) {
+ SimpleName name = cloneNode(n.getName(), arg);
+ ClassOrInterfaceType scope = cloneNode(n.getScope(), arg);
+ NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ClassOrInterfaceType r = new ClassOrInterfaceType(n.getTokenRange().orElse(null), scope, name, typeArguments, annotations);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final PrimitiveType n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ PrimitiveType r = new PrimitiveType(n.getTokenRange().orElse(null), n.getType(), annotations);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ArrayType n, final Object arg) {
+ Type componentType = cloneNode(n.getComponentType(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ArrayType r = new ArrayType(n.getTokenRange().orElse(null), componentType, n.getOrigin(), annotations);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ArrayCreationLevel n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Expression dimension = cloneNode(n.getDimension(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ArrayCreationLevel r = new ArrayCreationLevel(n.getTokenRange().orElse(null), dimension, annotations);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final IntersectionType n, final Object arg) {
+ NodeList<ReferenceType> elements = cloneList(n.getElements(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ IntersectionType r = new IntersectionType(n.getTokenRange().orElse(null), elements);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final UnionType n, final Object arg) {
+ NodeList<ReferenceType> elements = cloneList(n.getElements(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ UnionType r = new UnionType(n.getTokenRange().orElse(null), elements);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final VoidType n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ VoidType r = new VoidType(n.getTokenRange().orElse(null));
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final WildcardType n, final Object arg) {
+ ReferenceType extendedType = cloneNode(n.getExtendedType(), arg);
+ ReferenceType superType = cloneNode(n.getSuperType(), arg);
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ WildcardType r = new WildcardType(n.getTokenRange().orElse(null), extendedType, superType, annotations);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final UnknownType n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ UnknownType r = new UnknownType(n.getTokenRange().orElse(null));
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ArrayAccessExpr n, final Object arg) {
+ Expression index = cloneNode(n.getIndex(), arg);
+ Expression name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ArrayAccessExpr r = new ArrayAccessExpr(n.getTokenRange().orElse(null), name, index);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ArrayCreationExpr n, final Object arg) {
+ Type elementType = cloneNode(n.getElementType(), arg);
+ ArrayInitializerExpr initializer = cloneNode(n.getInitializer(), arg);
+ NodeList<ArrayCreationLevel> levels = cloneList(n.getLevels(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ArrayCreationExpr r = new ArrayCreationExpr(n.getTokenRange().orElse(null), elementType, levels, initializer);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ArrayInitializerExpr n, final Object arg) {
+ NodeList<Expression> values = cloneList(n.getValues(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ArrayInitializerExpr r = new ArrayInitializerExpr(n.getTokenRange().orElse(null), values);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final AssignExpr n, final Object arg) {
+ Expression target = cloneNode(n.getTarget(), arg);
+ Expression value = cloneNode(n.getValue(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ AssignExpr r = new AssignExpr(n.getTokenRange().orElse(null), target, value, n.getOperator());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final BinaryExpr n, final Object arg) {
+ Expression left = cloneNode(n.getLeft(), arg);
+ Expression right = cloneNode(n.getRight(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ BinaryExpr r = new BinaryExpr(n.getTokenRange().orElse(null), left, right, n.getOperator());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final CastExpr n, final Object arg) {
+ Expression expression = cloneNode(n.getExpression(), arg);
+ Type type = cloneNode(n.getType(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ CastExpr r = new CastExpr(n.getTokenRange().orElse(null), type, expression);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ClassExpr n, final Object arg) {
+ Type type = cloneNode(n.getType(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ClassExpr r = new ClassExpr(n.getTokenRange().orElse(null), type);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ConditionalExpr n, final Object arg) {
+ Expression condition = cloneNode(n.getCondition(), arg);
+ Expression elseExpr = cloneNode(n.getElseExpr(), arg);
+ Expression thenExpr = cloneNode(n.getThenExpr(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ConditionalExpr r = new ConditionalExpr(n.getTokenRange().orElse(null), condition, thenExpr, elseExpr);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final EnclosedExpr n, final Object arg) {
+ Expression inner = cloneNode(n.getInner(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ EnclosedExpr r = new EnclosedExpr(n.getTokenRange().orElse(null), inner);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final FieldAccessExpr n, final Object arg) {
+ SimpleName name = cloneNode(n.getName(), arg);
+ Expression scope = cloneNode(n.getScope(), arg);
+ NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ FieldAccessExpr r = new FieldAccessExpr(n.getTokenRange().orElse(null), scope, typeArguments, name);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final InstanceOfExpr n, final Object arg) {
+ Expression expression = cloneNode(n.getExpression(), arg);
+ ReferenceType type = cloneNode(n.getType(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ InstanceOfExpr r = new InstanceOfExpr(n.getTokenRange().orElse(null), expression, type);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final StringLiteralExpr n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ StringLiteralExpr r = new StringLiteralExpr(n.getTokenRange().orElse(null), n.getValue());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final IntegerLiteralExpr n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ IntegerLiteralExpr r = new IntegerLiteralExpr(n.getTokenRange().orElse(null), n.getValue());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final LongLiteralExpr n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ LongLiteralExpr r = new LongLiteralExpr(n.getTokenRange().orElse(null), n.getValue());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final CharLiteralExpr n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ CharLiteralExpr r = new CharLiteralExpr(n.getTokenRange().orElse(null), n.getValue());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final DoubleLiteralExpr n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ DoubleLiteralExpr r = new DoubleLiteralExpr(n.getTokenRange().orElse(null), n.getValue());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final BooleanLiteralExpr n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ BooleanLiteralExpr r = new BooleanLiteralExpr(n.getTokenRange().orElse(null), n.getValue());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final NullLiteralExpr n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ NullLiteralExpr r = new NullLiteralExpr(n.getTokenRange().orElse(null));
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final MethodCallExpr n, final Object arg) {
+ NodeList<Expression> arguments = cloneList(n.getArguments(), arg);
+ SimpleName name = cloneNode(n.getName(), arg);
+ Expression scope = cloneNode(n.getScope(), arg);
+ NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ MethodCallExpr r = new MethodCallExpr(n.getTokenRange().orElse(null), scope, typeArguments, name, arguments);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final NameExpr n, final Object arg) {
+ SimpleName name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ NameExpr r = new NameExpr(n.getTokenRange().orElse(null), name);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ObjectCreationExpr n, final Object arg) {
+ NodeList<BodyDeclaration<?>> anonymousClassBody = cloneList(n.getAnonymousClassBody().orElse(null), arg);
+ NodeList<Expression> arguments = cloneList(n.getArguments(), arg);
+ Expression scope = cloneNode(n.getScope(), arg);
+ ClassOrInterfaceType type = cloneNode(n.getType(), arg);
+ NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ObjectCreationExpr r = new ObjectCreationExpr(n.getTokenRange().orElse(null), scope, type, typeArguments, arguments, anonymousClassBody);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final Name n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Name qualifier = cloneNode(n.getQualifier(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ Name r = new Name(n.getTokenRange().orElse(null), qualifier, n.getIdentifier(), annotations);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final SimpleName n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ SimpleName r = new SimpleName(n.getTokenRange().orElse(null), n.getIdentifier());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ThisExpr n, final Object arg) {
+ Expression classExpr = cloneNode(n.getClassExpr(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ThisExpr r = new ThisExpr(n.getTokenRange().orElse(null), classExpr);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final SuperExpr n, final Object arg) {
+ Expression classExpr = cloneNode(n.getClassExpr(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ SuperExpr r = new SuperExpr(n.getTokenRange().orElse(null), classExpr);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final UnaryExpr n, final Object arg) {
+ Expression expression = cloneNode(n.getExpression(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ UnaryExpr r = new UnaryExpr(n.getTokenRange().orElse(null), expression, n.getOperator());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final VariableDeclarationExpr n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ NodeList<VariableDeclarator> variables = cloneList(n.getVariables(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ VariableDeclarationExpr r = new VariableDeclarationExpr(n.getTokenRange().orElse(null), n.getModifiers(), annotations, variables);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final MarkerAnnotationExpr n, final Object arg) {
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ MarkerAnnotationExpr r = new MarkerAnnotationExpr(n.getTokenRange().orElse(null), name);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final SingleMemberAnnotationExpr n, final Object arg) {
+ Expression memberValue = cloneNode(n.getMemberValue(), arg);
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ SingleMemberAnnotationExpr r = new SingleMemberAnnotationExpr(n.getTokenRange().orElse(null), name, memberValue);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final NormalAnnotationExpr n, final Object arg) {
+ NodeList<MemberValuePair> pairs = cloneList(n.getPairs(), arg);
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ NormalAnnotationExpr r = new NormalAnnotationExpr(n.getTokenRange().orElse(null), name, pairs);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final MemberValuePair n, final Object arg) {
+ SimpleName name = cloneNode(n.getName(), arg);
+ Expression value = cloneNode(n.getValue(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ MemberValuePair r = new MemberValuePair(n.getTokenRange().orElse(null), name, value);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ExplicitConstructorInvocationStmt n, final Object arg) {
+ NodeList<Expression> arguments = cloneList(n.getArguments(), arg);
+ Expression expression = cloneNode(n.getExpression(), arg);
+ NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ExplicitConstructorInvocationStmt r = new ExplicitConstructorInvocationStmt(n.getTokenRange().orElse(null), typeArguments, n.isThis(), expression, arguments);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final LocalClassDeclarationStmt n, final Object arg) {
+ ClassOrInterfaceDeclaration classDeclaration = cloneNode(n.getClassDeclaration(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ LocalClassDeclarationStmt r = new LocalClassDeclarationStmt(n.getTokenRange().orElse(null), classDeclaration);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final AssertStmt n, final Object arg) {
+ Expression check = cloneNode(n.getCheck(), arg);
+ Expression message = cloneNode(n.getMessage(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ AssertStmt r = new AssertStmt(n.getTokenRange().orElse(null), check, message);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final BlockStmt n, final Object arg) {
+ NodeList<Statement> statements = cloneList(n.getStatements(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ BlockStmt r = new BlockStmt(n.getTokenRange().orElse(null), statements);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final LabeledStmt n, final Object arg) {
+ SimpleName label = cloneNode(n.getLabel(), arg);
+ Statement statement = cloneNode(n.getStatement(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ LabeledStmt r = new LabeledStmt(n.getTokenRange().orElse(null), label, statement);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final EmptyStmt n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ EmptyStmt r = new EmptyStmt(n.getTokenRange().orElse(null));
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ExpressionStmt n, final Object arg) {
+ Expression expression = cloneNode(n.getExpression(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ExpressionStmt r = new ExpressionStmt(n.getTokenRange().orElse(null), expression);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final SwitchStmt n, final Object arg) {
+ NodeList<SwitchEntryStmt> entries = cloneList(n.getEntries(), arg);
+ Expression selector = cloneNode(n.getSelector(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ SwitchStmt r = new SwitchStmt(n.getTokenRange().orElse(null), selector, entries);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final SwitchEntryStmt n, final Object arg) {
+ Expression label = cloneNode(n.getLabel(), arg);
+ NodeList<Statement> statements = cloneList(n.getStatements(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ SwitchEntryStmt r = new SwitchEntryStmt(n.getTokenRange().orElse(null), label, statements);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final BreakStmt n, final Object arg) {
+ SimpleName label = cloneNode(n.getLabel(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ BreakStmt r = new BreakStmt(n.getTokenRange().orElse(null), label);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ReturnStmt n, final Object arg) {
+ Expression expression = cloneNode(n.getExpression(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ReturnStmt r = new ReturnStmt(n.getTokenRange().orElse(null), expression);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final IfStmt n, final Object arg) {
+ Expression condition = cloneNode(n.getCondition(), arg);
+ Statement elseStmt = cloneNode(n.getElseStmt(), arg);
+ Statement thenStmt = cloneNode(n.getThenStmt(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ IfStmt r = new IfStmt(n.getTokenRange().orElse(null), condition, thenStmt, elseStmt);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final WhileStmt n, final Object arg) {
+ Statement body = cloneNode(n.getBody(), arg);
+ Expression condition = cloneNode(n.getCondition(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ WhileStmt r = new WhileStmt(n.getTokenRange().orElse(null), condition, body);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ContinueStmt n, final Object arg) {
+ SimpleName label = cloneNode(n.getLabel(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ContinueStmt r = new ContinueStmt(n.getTokenRange().orElse(null), label);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final DoStmt n, final Object arg) {
+ Statement body = cloneNode(n.getBody(), arg);
+ Expression condition = cloneNode(n.getCondition(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ DoStmt r = new DoStmt(n.getTokenRange().orElse(null), body, condition);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ForeachStmt n, final Object arg) {
+ Statement body = cloneNode(n.getBody(), arg);
+ Expression iterable = cloneNode(n.getIterable(), arg);
+ VariableDeclarationExpr variable = cloneNode(n.getVariable(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ForeachStmt r = new ForeachStmt(n.getTokenRange().orElse(null), variable, iterable, body);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ForStmt n, final Object arg) {
+ Statement body = cloneNode(n.getBody(), arg);
+ Expression compare = cloneNode(n.getCompare(), arg);
+ NodeList<Expression> initialization = cloneList(n.getInitialization(), arg);
+ NodeList<Expression> update = cloneList(n.getUpdate(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ForStmt r = new ForStmt(n.getTokenRange().orElse(null), initialization, compare, update, body);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ThrowStmt n, final Object arg) {
+ Expression expression = cloneNode(n.getExpression(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ThrowStmt r = new ThrowStmt(n.getTokenRange().orElse(null), expression);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final SynchronizedStmt n, final Object arg) {
+ BlockStmt body = cloneNode(n.getBody(), arg);
+ Expression expression = cloneNode(n.getExpression(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ SynchronizedStmt r = new SynchronizedStmt(n.getTokenRange().orElse(null), expression, body);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final TryStmt n, final Object arg) {
+ NodeList<CatchClause> catchClauses = cloneList(n.getCatchClauses(), arg);
+ BlockStmt finallyBlock = cloneNode(n.getFinallyBlock(), arg);
+ NodeList<Expression> resources = cloneList(n.getResources(), arg);
+ BlockStmt tryBlock = cloneNode(n.getTryBlock(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ TryStmt r = new TryStmt(n.getTokenRange().orElse(null), resources, tryBlock, catchClauses, finallyBlock);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final CatchClause n, final Object arg) {
+ BlockStmt body = cloneNode(n.getBody(), arg);
+ Parameter parameter = cloneNode(n.getParameter(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ CatchClause r = new CatchClause(n.getTokenRange().orElse(null), parameter, body);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final LambdaExpr n, final Object arg) {
+ Statement body = cloneNode(n.getBody(), arg);
+ NodeList<Parameter> parameters = cloneList(n.getParameters(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ LambdaExpr r = new LambdaExpr(n.getTokenRange().orElse(null), parameters, body, n.isEnclosingParameters());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final MethodReferenceExpr n, final Object arg) {
+ Expression scope = cloneNode(n.getScope(), arg);
+ NodeList<Type> typeArguments = cloneList(n.getTypeArguments().orElse(null), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ MethodReferenceExpr r = new MethodReferenceExpr(n.getTokenRange().orElse(null), scope, typeArguments, n.getIdentifier());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final TypeExpr n, final Object arg) {
+ Type type = cloneNode(n.getType(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ TypeExpr r = new TypeExpr(n.getTokenRange().orElse(null), type);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ public Visitable visit(NodeList n, Object arg) {
+ NodeList<Node> newNodes = new NodeList<>();
+ for (Object node : n) {
+ Node resultNode = (Node) ((Node) node).accept(this, arg);
+ if (resultNode != null) {
+ newNodes.add(resultNode);
+ }
+ }
+ return newNodes;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Node visit(final ImportDeclaration n, final Object arg) {
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ImportDeclaration r = new ImportDeclaration(n.getTokenRange().orElse(null), name, n.isStatic(), n.isAsterisk());
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ModuleDeclaration n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ NodeList<ModuleStmt> moduleStmts = cloneList(n.getModuleStmts(), arg);
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ModuleDeclaration r = new ModuleDeclaration(n.getTokenRange().orElse(null), annotations, name, n.isOpen(), moduleStmts);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ModuleRequiresStmt n, final Object arg) {
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ModuleRequiresStmt r = new ModuleRequiresStmt(n.getTokenRange().orElse(null), n.getModifiers(), name);
+ r.setComment(comment);
+ return r;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T extends Node> T cloneNode(Optional<T> node, Object arg) {
+ if (!node.isPresent()) {
+ return null;
+ }
+ Node r = (Node) node.get().accept(this, arg);
+ if (r == null) {
+ return null;
+ }
+ return (T) r;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T extends Node> T cloneNode(T node, Object arg) {
+ if (node == null) {
+ return null;
+ }
+ Node r = (Node) node.accept(this, arg);
+ if (r == null) {
+ return null;
+ }
+ return (T) r;
+ }
+
+ private <N extends Node> NodeList<N> cloneList(NodeList<N> list, Object arg) {
+ if (list == null) {
+ return null;
+ }
+ return (NodeList<N>) list.accept(this, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ModuleExportsStmt n, final Object arg) {
+ NodeList<Name> moduleNames = cloneList(n.getModuleNames(), arg);
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ModuleExportsStmt r = new ModuleExportsStmt(n.getTokenRange().orElse(null), name, moduleNames);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ModuleProvidesStmt n, final Object arg) {
+ Type type = cloneNode(n.getType(), arg);
+ NodeList<Type> withTypes = cloneList(n.getWithTypes(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ModuleProvidesStmt r = new ModuleProvidesStmt(n.getTokenRange().orElse(null), type, withTypes);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ModuleUsesStmt n, final Object arg) {
+ Type type = cloneNode(n.getType(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ModuleUsesStmt r = new ModuleUsesStmt(n.getTokenRange().orElse(null), type);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ModuleOpensStmt n, final Object arg) {
+ NodeList<Name> moduleNames = cloneList(n.getModuleNames(), arg);
+ Name name = cloneNode(n.getName(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ModuleOpensStmt r = new ModuleOpensStmt(n.getTokenRange().orElse(null), name, moduleNames);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final UnparsableStmt n, final Object arg) {
+ Comment comment = cloneNode(n.getComment(), arg);
+ UnparsableStmt r = new UnparsableStmt(n.getTokenRange().orElse(null));
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.CloneVisitorGenerator")
+ public Visitable visit(final ReceiverParameter n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Name name = cloneNode(n.getName(), arg);
+ Type type = cloneNode(n.getType(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ ReceiverParameter r = new ReceiverParameter(n.getTokenRange().orElse(null), annotations, type, name);
+ r.setComment(comment);
+ return r;
+ }
+
+ @Override
+ public Visitable visit(final VarType n, final Object arg) {
+ NodeList<AnnotationExpr> annotations = cloneList(n.getAnnotations(), arg);
+ Comment comment = cloneNode(n.getComment(), arg);
+ VarType r = new VarType(n.getTokenRange().orElse(null));
+ r.setComment(comment);
+ return r;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java
new file mode 100644
index 000000000..2062185a1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/EqualsVisitor.java
@@ -0,0 +1,1389 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import java.util.List;
+import java.util.Optional;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that calculates deep node equality by comparing all properties and child nodes of the node.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public class EqualsVisitor implements GenericVisitor<Boolean, Visitable> {
+
+ private static final EqualsVisitor SINGLETON = new EqualsVisitor();
+
+ public static boolean equals(final Node n, final Node n2) {
+ return SINGLETON.nodeEquals(n, n2);
+ }
+
+ private EqualsVisitor() {
+ // hide constructor
+ }
+
+ /**
+ * Check for equality that can be applied to each kind of node,
+ * to not repeat it in every method we store that here.
+ */
+ private boolean commonNodeEquality(Node n, Node n2) {
+ if (!nodeEquals(n.getComment(), n2.getComment())) {
+ return false;
+ }
+ return nodesEquals(n.getOrphanComments(), n2.getOrphanComments());
+ }
+
+ private <T extends Node> boolean nodesEquals(final List<T> nodes1, final List<T> nodes2) {
+ if (nodes1 == null) {
+ return nodes2 == null;
+ } else if (nodes2 == null) {
+ return false;
+ }
+ if (nodes1.size() != nodes2.size()) {
+ return false;
+ }
+ for (int i = 0; i < nodes1.size(); i++) {
+ if (!nodeEquals(nodes1.get(i), nodes2.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private <N extends Node> boolean nodesEquals(NodeList<N> n, NodeList<N> n2) {
+ if (n == n2) {
+ return true;
+ }
+ if (n == null || n2 == null) {
+ return false;
+ }
+ if (n.size() != n2.size()) {
+ return false;
+ }
+ for (int i = 0; i < n.size(); i++) {
+ if (!nodeEquals(n.get(i), n2.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private <T extends Node> boolean nodeEquals(final T n, final T n2) {
+ if (n == n2) {
+ return true;
+ }
+ if (n == null || n2 == null) {
+ return false;
+ }
+ if (n.getClass() != n2.getClass()) {
+ return false;
+ }
+ if (!commonNodeEquality(n, n2)) {
+ return false;
+ }
+ return n.accept(this, n2);
+ }
+
+ private <T extends Node> boolean nodeEquals(final Optional<T> n, final Optional<T> n2) {
+ return nodeEquals(n.orElse(null), n2.orElse(null));
+ }
+
+ private <T extends Node> boolean nodesEquals(final Optional<NodeList<T>> n, final Optional<NodeList<T>> n2) {
+ return nodesEquals(n.orElse(null), n2.orElse(null));
+ }
+
+ private boolean objEquals(final Object n, final Object n2) {
+ if (n == n2) {
+ return true;
+ }
+ if (n == null || n2 == null) {
+ return false;
+ }
+ return n.equals(n2);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final CompilationUnit n, final Visitable arg) {
+ final CompilationUnit n2 = (CompilationUnit) arg;
+ if (!nodesEquals(n.getImports(), n2.getImports()))
+ return false;
+ if (!nodeEquals(n.getModule(), n2.getModule()))
+ return false;
+ if (!nodeEquals(n.getPackageDeclaration(), n2.getPackageDeclaration()))
+ return false;
+ if (!nodesEquals(n.getTypes(), n2.getTypes()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final PackageDeclaration n, final Visitable arg) {
+ final PackageDeclaration n2 = (PackageDeclaration) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final TypeParameter n, final Visitable arg) {
+ final TypeParameter n2 = (TypeParameter) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getTypeBound(), n2.getTypeBound()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final LineComment n, final Visitable arg) {
+ final LineComment n2 = (LineComment) arg;
+ if (!objEquals(n.getContent(), n2.getContent()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final BlockComment n, final Visitable arg) {
+ final BlockComment n2 = (BlockComment) arg;
+ if (!objEquals(n.getContent(), n2.getContent()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ClassOrInterfaceDeclaration n, final Visitable arg) {
+ final ClassOrInterfaceDeclaration n2 = (ClassOrInterfaceDeclaration) arg;
+ if (!nodesEquals(n.getExtendedTypes(), n2.getExtendedTypes()))
+ return false;
+ if (!nodesEquals(n.getImplementedTypes(), n2.getImplementedTypes()))
+ return false;
+ if (!objEquals(n.isInterface(), n2.isInterface()))
+ return false;
+ if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters()))
+ return false;
+ if (!nodesEquals(n.getMembers(), n2.getMembers()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final EnumDeclaration n, final Visitable arg) {
+ final EnumDeclaration n2 = (EnumDeclaration) arg;
+ if (!nodesEquals(n.getEntries(), n2.getEntries()))
+ return false;
+ if (!nodesEquals(n.getImplementedTypes(), n2.getImplementedTypes()))
+ return false;
+ if (!nodesEquals(n.getMembers(), n2.getMembers()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final EnumConstantDeclaration n, final Visitable arg) {
+ final EnumConstantDeclaration n2 = (EnumConstantDeclaration) arg;
+ if (!nodesEquals(n.getArguments(), n2.getArguments()))
+ return false;
+ if (!nodesEquals(n.getClassBody(), n2.getClassBody()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final AnnotationDeclaration n, final Visitable arg) {
+ final AnnotationDeclaration n2 = (AnnotationDeclaration) arg;
+ if (!nodesEquals(n.getMembers(), n2.getMembers()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final AnnotationMemberDeclaration n, final Visitable arg) {
+ final AnnotationMemberDeclaration n2 = (AnnotationMemberDeclaration) arg;
+ if (!nodeEquals(n.getDefaultValue(), n2.getDefaultValue()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final FieldDeclaration n, final Visitable arg) {
+ final FieldDeclaration n2 = (FieldDeclaration) arg;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodesEquals(n.getVariables(), n2.getVariables()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final VariableDeclarator n, final Visitable arg) {
+ final VariableDeclarator n2 = (VariableDeclarator) arg;
+ if (!nodeEquals(n.getInitializer(), n2.getInitializer()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ConstructorDeclaration n, final Visitable arg) {
+ final ConstructorDeclaration n2 = (ConstructorDeclaration) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getParameters(), n2.getParameters()))
+ return false;
+ if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter()))
+ return false;
+ if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions()))
+ return false;
+ if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final MethodDeclaration n, final Visitable arg) {
+ final MethodDeclaration n2 = (MethodDeclaration) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getParameters(), n2.getParameters()))
+ return false;
+ if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter()))
+ return false;
+ if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions()))
+ return false;
+ if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final Parameter n, final Visitable arg) {
+ final Parameter n2 = (Parameter) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!objEquals(n.isVarArgs(), n2.isVarArgs()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getVarArgsAnnotations(), n2.getVarArgsAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final InitializerDeclaration n, final Visitable arg) {
+ final InitializerDeclaration n2 = (InitializerDeclaration) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!objEquals(n.isStatic(), n2.isStatic()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final JavadocComment n, final Visitable arg) {
+ final JavadocComment n2 = (JavadocComment) arg;
+ if (!objEquals(n.getContent(), n2.getContent()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ClassOrInterfaceType n, final Visitable arg) {
+ final ClassOrInterfaceType n2 = (ClassOrInterfaceType) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final PrimitiveType n, final Visitable arg) {
+ final PrimitiveType n2 = (PrimitiveType) arg;
+ if (!objEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ArrayType n, final Visitable arg) {
+ final ArrayType n2 = (ArrayType) arg;
+ if (!nodeEquals(n.getComponentType(), n2.getComponentType()))
+ return false;
+ if (!objEquals(n.getOrigin(), n2.getOrigin()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ArrayCreationLevel n, final Visitable arg) {
+ final ArrayCreationLevel n2 = (ArrayCreationLevel) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getDimension(), n2.getDimension()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final IntersectionType n, final Visitable arg) {
+ final IntersectionType n2 = (IntersectionType) arg;
+ if (!nodesEquals(n.getElements(), n2.getElements()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final UnionType n, final Visitable arg) {
+ final UnionType n2 = (UnionType) arg;
+ if (!nodesEquals(n.getElements(), n2.getElements()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final VoidType n, final Visitable arg) {
+ final VoidType n2 = (VoidType) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final WildcardType n, final Visitable arg) {
+ final WildcardType n2 = (WildcardType) arg;
+ if (!nodeEquals(n.getExtendedType(), n2.getExtendedType()))
+ return false;
+ if (!nodeEquals(n.getSuperType(), n2.getSuperType()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final UnknownType n, final Visitable arg) {
+ final UnknownType n2 = (UnknownType) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ArrayAccessExpr n, final Visitable arg) {
+ final ArrayAccessExpr n2 = (ArrayAccessExpr) arg;
+ if (!nodeEquals(n.getIndex(), n2.getIndex()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ArrayCreationExpr n, final Visitable arg) {
+ final ArrayCreationExpr n2 = (ArrayCreationExpr) arg;
+ if (!nodeEquals(n.getElementType(), n2.getElementType()))
+ return false;
+ if (!nodeEquals(n.getInitializer(), n2.getInitializer()))
+ return false;
+ if (!nodesEquals(n.getLevels(), n2.getLevels()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ArrayInitializerExpr n, final Visitable arg) {
+ final ArrayInitializerExpr n2 = (ArrayInitializerExpr) arg;
+ if (!nodesEquals(n.getValues(), n2.getValues()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final AssignExpr n, final Visitable arg) {
+ final AssignExpr n2 = (AssignExpr) arg;
+ if (!objEquals(n.getOperator(), n2.getOperator()))
+ return false;
+ if (!nodeEquals(n.getTarget(), n2.getTarget()))
+ return false;
+ if (!nodeEquals(n.getValue(), n2.getValue()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final BinaryExpr n, final Visitable arg) {
+ final BinaryExpr n2 = (BinaryExpr) arg;
+ if (!nodeEquals(n.getLeft(), n2.getLeft()))
+ return false;
+ if (!objEquals(n.getOperator(), n2.getOperator()))
+ return false;
+ if (!nodeEquals(n.getRight(), n2.getRight()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final CastExpr n, final Visitable arg) {
+ final CastExpr n2 = (CastExpr) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ClassExpr n, final Visitable arg) {
+ final ClassExpr n2 = (ClassExpr) arg;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ConditionalExpr n, final Visitable arg) {
+ final ConditionalExpr n2 = (ConditionalExpr) arg;
+ if (!nodeEquals(n.getCondition(), n2.getCondition()))
+ return false;
+ if (!nodeEquals(n.getElseExpr(), n2.getElseExpr()))
+ return false;
+ if (!nodeEquals(n.getThenExpr(), n2.getThenExpr()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final EnclosedExpr n, final Visitable arg) {
+ final EnclosedExpr n2 = (EnclosedExpr) arg;
+ if (!nodeEquals(n.getInner(), n2.getInner()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final FieldAccessExpr n, final Visitable arg) {
+ final FieldAccessExpr n2 = (FieldAccessExpr) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final InstanceOfExpr n, final Visitable arg) {
+ final InstanceOfExpr n2 = (InstanceOfExpr) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final StringLiteralExpr n, final Visitable arg) {
+ final StringLiteralExpr n2 = (StringLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final IntegerLiteralExpr n, final Visitable arg) {
+ final IntegerLiteralExpr n2 = (IntegerLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final LongLiteralExpr n, final Visitable arg) {
+ final LongLiteralExpr n2 = (LongLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final CharLiteralExpr n, final Visitable arg) {
+ final CharLiteralExpr n2 = (CharLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final DoubleLiteralExpr n, final Visitable arg) {
+ final DoubleLiteralExpr n2 = (DoubleLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final BooleanLiteralExpr n, final Visitable arg) {
+ final BooleanLiteralExpr n2 = (BooleanLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final NullLiteralExpr n, final Visitable arg) {
+ final NullLiteralExpr n2 = (NullLiteralExpr) arg;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final MethodCallExpr n, final Visitable arg) {
+ final MethodCallExpr n2 = (MethodCallExpr) arg;
+ if (!nodesEquals(n.getArguments(), n2.getArguments()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final NameExpr n, final Visitable arg) {
+ final NameExpr n2 = (NameExpr) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ObjectCreationExpr n, final Visitable arg) {
+ final ObjectCreationExpr n2 = (ObjectCreationExpr) arg;
+ if (!nodesEquals(n.getAnonymousClassBody(), n2.getAnonymousClassBody()))
+ return false;
+ if (!nodesEquals(n.getArguments(), n2.getArguments()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final Name n, final Visitable arg) {
+ final Name n2 = (Name) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!objEquals(n.getIdentifier(), n2.getIdentifier()))
+ return false;
+ if (!nodeEquals(n.getQualifier(), n2.getQualifier()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final SimpleName n, final Visitable arg) {
+ final SimpleName n2 = (SimpleName) arg;
+ if (!objEquals(n.getIdentifier(), n2.getIdentifier()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ThisExpr n, final Visitable arg) {
+ final ThisExpr n2 = (ThisExpr) arg;
+ if (!nodeEquals(n.getClassExpr(), n2.getClassExpr()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final SuperExpr n, final Visitable arg) {
+ final SuperExpr n2 = (SuperExpr) arg;
+ if (!nodeEquals(n.getClassExpr(), n2.getClassExpr()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final UnaryExpr n, final Visitable arg) {
+ final UnaryExpr n2 = (UnaryExpr) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!objEquals(n.getOperator(), n2.getOperator()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final VariableDeclarationExpr n, final Visitable arg) {
+ final VariableDeclarationExpr n2 = (VariableDeclarationExpr) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodesEquals(n.getVariables(), n2.getVariables()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final MarkerAnnotationExpr n, final Visitable arg) {
+ final MarkerAnnotationExpr n2 = (MarkerAnnotationExpr) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final SingleMemberAnnotationExpr n, final Visitable arg) {
+ final SingleMemberAnnotationExpr n2 = (SingleMemberAnnotationExpr) arg;
+ if (!nodeEquals(n.getMemberValue(), n2.getMemberValue()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final NormalAnnotationExpr n, final Visitable arg) {
+ final NormalAnnotationExpr n2 = (NormalAnnotationExpr) arg;
+ if (!nodesEquals(n.getPairs(), n2.getPairs()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final MemberValuePair n, final Visitable arg) {
+ final MemberValuePair n2 = (MemberValuePair) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getValue(), n2.getValue()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ExplicitConstructorInvocationStmt n, final Visitable arg) {
+ final ExplicitConstructorInvocationStmt n2 = (ExplicitConstructorInvocationStmt) arg;
+ if (!nodesEquals(n.getArguments(), n2.getArguments()))
+ return false;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!objEquals(n.isThis(), n2.isThis()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final LocalClassDeclarationStmt n, final Visitable arg) {
+ final LocalClassDeclarationStmt n2 = (LocalClassDeclarationStmt) arg;
+ if (!nodeEquals(n.getClassDeclaration(), n2.getClassDeclaration()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final AssertStmt n, final Visitable arg) {
+ final AssertStmt n2 = (AssertStmt) arg;
+ if (!nodeEquals(n.getCheck(), n2.getCheck()))
+ return false;
+ if (!nodeEquals(n.getMessage(), n2.getMessage()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final BlockStmt n, final Visitable arg) {
+ final BlockStmt n2 = (BlockStmt) arg;
+ if (!nodesEquals(n.getStatements(), n2.getStatements()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final LabeledStmt n, final Visitable arg) {
+ final LabeledStmt n2 = (LabeledStmt) arg;
+ if (!nodeEquals(n.getLabel(), n2.getLabel()))
+ return false;
+ if (!nodeEquals(n.getStatement(), n2.getStatement()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final EmptyStmt n, final Visitable arg) {
+ final EmptyStmt n2 = (EmptyStmt) arg;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ExpressionStmt n, final Visitable arg) {
+ final ExpressionStmt n2 = (ExpressionStmt) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final SwitchStmt n, final Visitable arg) {
+ final SwitchStmt n2 = (SwitchStmt) arg;
+ if (!nodesEquals(n.getEntries(), n2.getEntries()))
+ return false;
+ if (!nodeEquals(n.getSelector(), n2.getSelector()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final SwitchEntryStmt n, final Visitable arg) {
+ final SwitchEntryStmt n2 = (SwitchEntryStmt) arg;
+ if (!nodeEquals(n.getLabel(), n2.getLabel()))
+ return false;
+ if (!nodesEquals(n.getStatements(), n2.getStatements()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final BreakStmt n, final Visitable arg) {
+ final BreakStmt n2 = (BreakStmt) arg;
+ if (!nodeEquals(n.getLabel(), n2.getLabel()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ReturnStmt n, final Visitable arg) {
+ final ReturnStmt n2 = (ReturnStmt) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final IfStmt n, final Visitable arg) {
+ final IfStmt n2 = (IfStmt) arg;
+ if (!nodeEquals(n.getCondition(), n2.getCondition()))
+ return false;
+ if (!nodeEquals(n.getElseStmt(), n2.getElseStmt()))
+ return false;
+ if (!nodeEquals(n.getThenStmt(), n2.getThenStmt()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final WhileStmt n, final Visitable arg) {
+ final WhileStmt n2 = (WhileStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getCondition(), n2.getCondition()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ContinueStmt n, final Visitable arg) {
+ final ContinueStmt n2 = (ContinueStmt) arg;
+ if (!nodeEquals(n.getLabel(), n2.getLabel()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final DoStmt n, final Visitable arg) {
+ final DoStmt n2 = (DoStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getCondition(), n2.getCondition()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ForeachStmt n, final Visitable arg) {
+ final ForeachStmt n2 = (ForeachStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getIterable(), n2.getIterable()))
+ return false;
+ if (!nodeEquals(n.getVariable(), n2.getVariable()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ForStmt n, final Visitable arg) {
+ final ForStmt n2 = (ForStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getCompare(), n2.getCompare()))
+ return false;
+ if (!nodesEquals(n.getInitialization(), n2.getInitialization()))
+ return false;
+ if (!nodesEquals(n.getUpdate(), n2.getUpdate()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ThrowStmt n, final Visitable arg) {
+ final ThrowStmt n2 = (ThrowStmt) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final SynchronizedStmt n, final Visitable arg) {
+ final SynchronizedStmt n2 = (SynchronizedStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final TryStmt n, final Visitable arg) {
+ final TryStmt n2 = (TryStmt) arg;
+ if (!nodesEquals(n.getCatchClauses(), n2.getCatchClauses()))
+ return false;
+ if (!nodeEquals(n.getFinallyBlock(), n2.getFinallyBlock()))
+ return false;
+ if (!nodesEquals(n.getResources(), n2.getResources()))
+ return false;
+ if (!nodeEquals(n.getTryBlock(), n2.getTryBlock()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final CatchClause n, final Visitable arg) {
+ final CatchClause n2 = (CatchClause) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getParameter(), n2.getParameter()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final LambdaExpr n, final Visitable arg) {
+ final LambdaExpr n2 = (LambdaExpr) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!objEquals(n.isEnclosingParameters(), n2.isEnclosingParameters()))
+ return false;
+ if (!nodesEquals(n.getParameters(), n2.getParameters()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final MethodReferenceExpr n, final Visitable arg) {
+ final MethodReferenceExpr n2 = (MethodReferenceExpr) arg;
+ if (!objEquals(n.getIdentifier(), n2.getIdentifier()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final TypeExpr n, final Visitable arg) {
+ final TypeExpr n2 = (TypeExpr) arg;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ImportDeclaration n, final Visitable arg) {
+ final ImportDeclaration n2 = (ImportDeclaration) arg;
+ if (!objEquals(n.isAsterisk(), n2.isAsterisk()))
+ return false;
+ if (!objEquals(n.isStatic(), n2.isStatic()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ public Boolean visit(NodeList n, Visitable arg) {
+ return nodesEquals((NodeList<Node>) n, (NodeList<Node>) arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ModuleDeclaration n, final Visitable arg) {
+ final ModuleDeclaration n2 = (ModuleDeclaration) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!objEquals(n.isOpen(), n2.isOpen()))
+ return false;
+ if (!nodesEquals(n.getModuleStmts(), n2.getModuleStmts()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ModuleRequiresStmt n, final Visitable arg) {
+ final ModuleRequiresStmt n2 = (ModuleRequiresStmt) arg;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ModuleExportsStmt n, final Visitable arg) {
+ final ModuleExportsStmt n2 = (ModuleExportsStmt) arg;
+ if (!nodesEquals(n.getModuleNames(), n2.getModuleNames()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ModuleProvidesStmt n, final Visitable arg) {
+ final ModuleProvidesStmt n2 = (ModuleProvidesStmt) arg;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getWithTypes(), n2.getWithTypes()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ModuleUsesStmt n, final Visitable arg) {
+ final ModuleUsesStmt n2 = (ModuleUsesStmt) arg;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ModuleOpensStmt n, final Visitable arg) {
+ final ModuleOpensStmt n2 = (ModuleOpensStmt) arg;
+ if (!nodesEquals(n.getModuleNames(), n2.getModuleNames()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final UnparsableStmt n, final Visitable arg) {
+ final UnparsableStmt n2 = (UnparsableStmt) arg;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.EqualsVisitorGenerator")
+ public Boolean visit(final ReceiverParameter n, final Visitable arg) {
+ final ReceiverParameter n2 = (ReceiverParameter) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+
+ @Override
+ public Boolean visit(final VarType n, final Visitable arg) {
+ final VarType n2 = (VarType) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getComment(), n2.getComment()))
+ return false;
+ return true;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java
new file mode 100644
index 000000000..2defdfa9f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericListVisitorAdapter.java
@@ -0,0 +1,2061 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * A visitor that has a return value of ({@link List List<R>}), and has a default implementation for all its visit
+ * methods that visits their children in an unspecified order, and all visit methods
+ * that returns a value be added to a flattened {@link List List<R>}.
+ *
+ * @author Enno Boland
+ */
+public abstract class GenericListVisitorAdapter<R, A> implements GenericVisitor<List<R>, A> {
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final AnnotationDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getMembers().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final AnnotationMemberDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getDefaultValue().isPresent()) {
+ tmp = n.getDefaultValue().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ArrayAccessExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getIndex().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ArrayCreationExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getElementType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getInitializer().isPresent()) {
+ tmp = n.getInitializer().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getLevels().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ArrayCreationLevel n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getDimension().isPresent()) {
+ tmp = n.getDimension().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ArrayInitializerExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getValues().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ArrayType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getComponentType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final AssertStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getCheck().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getMessage().isPresent()) {
+ tmp = n.getMessage().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final AssignExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getTarget().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getValue().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final BinaryExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getLeft().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getRight().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final BlockComment n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final BlockStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getStatements().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final BooleanLiteralExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final BreakStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getLabel().isPresent()) {
+ tmp = n.getLabel().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final CastExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getExpression().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final CatchClause n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getParameter().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final CharLiteralExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ClassExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ClassOrInterfaceDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getExtendedTypes().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getImplementedTypes().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getTypeParameters().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getMembers().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ClassOrInterfaceType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getScope().isPresent()) {
+ tmp = n.getScope().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getTypeArguments().isPresent()) {
+ tmp = n.getTypeArguments().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final CompilationUnit n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getImports().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getModule().isPresent()) {
+ tmp = n.getModule().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getPackageDeclaration().isPresent()) {
+ tmp = n.getPackageDeclaration().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getTypes().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ConditionalExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getCondition().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getElseExpr().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getThenExpr().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ConstructorDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getParameters().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getReceiverParameter().isPresent()) {
+ tmp = n.getReceiverParameter().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getThrownExceptions().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getTypeParameters().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ContinueStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getLabel().isPresent()) {
+ tmp = n.getLabel().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final DoStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getCondition().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final DoubleLiteralExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final EmptyStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final EnclosedExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getInner().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final EnumConstantDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getArguments().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getClassBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final EnumDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getEntries().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getImplementedTypes().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getMembers().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ExplicitConstructorInvocationStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getArguments().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getExpression().isPresent()) {
+ tmp = n.getExpression().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getTypeArguments().isPresent()) {
+ tmp = n.getTypeArguments().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ExpressionStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getExpression().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final FieldAccessExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getScope().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getTypeArguments().isPresent()) {
+ tmp = n.getTypeArguments().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final FieldDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getVariables().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ForStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getCompare().isPresent()) {
+ tmp = n.getCompare().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getInitialization().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getUpdate().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ForeachStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getIterable().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getVariable().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final IfStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getCondition().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getElseStmt().isPresent()) {
+ tmp = n.getElseStmt().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getThenStmt().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ImportDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final InitializerDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final InstanceOfExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getExpression().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final IntegerLiteralExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final IntersectionType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getElements().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final JavadocComment n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final LabeledStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getLabel().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getStatement().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final LambdaExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getParameters().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final LineComment n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final LocalClassDeclarationStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getClassDeclaration().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final LongLiteralExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final MarkerAnnotationExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final MemberValuePair n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getValue().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final MethodCallExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getArguments().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getScope().isPresent()) {
+ tmp = n.getScope().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getTypeArguments().isPresent()) {
+ tmp = n.getTypeArguments().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final MethodDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getBody().isPresent()) {
+ tmp = n.getBody().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getParameters().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getReceiverParameter().isPresent()) {
+ tmp = n.getReceiverParameter().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getThrownExceptions().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getTypeParameters().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final MethodReferenceExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getScope().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getTypeArguments().isPresent()) {
+ tmp = n.getTypeArguments().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final NameExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final Name n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getQualifier().isPresent()) {
+ tmp = n.getQualifier().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final NormalAnnotationExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getPairs().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final NullLiteralExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ObjectCreationExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getAnonymousClassBody().isPresent()) {
+ tmp = n.getAnonymousClassBody().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getArguments().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getScope().isPresent()) {
+ tmp = n.getScope().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getTypeArguments().isPresent()) {
+ tmp = n.getTypeArguments().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final PackageDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final Parameter n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getVarArgsAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final PrimitiveType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ReturnStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getExpression().isPresent()) {
+ tmp = n.getExpression().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final SimpleName n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final SingleMemberAnnotationExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getMemberValue().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final StringLiteralExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final SuperExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getClassExpr().isPresent()) {
+ tmp = n.getClassExpr().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final SwitchEntryStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getLabel().isPresent()) {
+ tmp = n.getLabel().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getStatements().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final SwitchStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getEntries().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getSelector().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final SynchronizedStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getExpression().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ThisExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getClassExpr().isPresent()) {
+ tmp = n.getClassExpr().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ThrowStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getExpression().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final TryStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getCatchClauses().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getFinallyBlock().isPresent()) {
+ tmp = n.getFinallyBlock().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getResources().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getTryBlock().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final TypeExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final TypeParameter n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getTypeBound().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final UnaryExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getExpression().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final UnionType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getElements().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final UnknownType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final VariableDeclarationExpr n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getVariables().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final VariableDeclarator n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getInitializer().isPresent()) {
+ tmp = n.getInitializer().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final VoidType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final WhileStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getBody().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getCondition().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final WildcardType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getExtendedType().isPresent()) {
+ tmp = n.getExtendedType().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getSuperType().isPresent()) {
+ tmp = n.getSuperType().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ public List<R> visit(NodeList n, A arg) {
+ return ((NodeList<? extends Node>) n).stream().filter(Objects::nonNull).flatMap(v -> v.accept(this, arg).stream()).collect(Collectors.toList());
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ModuleDeclaration n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getModuleStmts().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ModuleExportsStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getModuleNames().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ModuleOpensStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getModuleNames().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ModuleProvidesStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getWithTypes().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ModuleRequiresStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ModuleUsesStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final UnparsableStmt n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericListVisitorAdapterGenerator")
+ public List<R> visit(final ReceiverParameter n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getName().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ {
+ tmp = n.getType().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+
+ @Override
+ public List<R> visit(final VarType n, final A arg) {
+ List<R> result = new ArrayList<>();
+ List<R> tmp;
+ {
+ tmp = n.getAnnotations().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ if (n.getComment().isPresent()) {
+ tmp = n.getComment().get().accept(this, arg);
+ if (tmp != null)
+ result.addAll(tmp);
+ }
+ return result;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java
new file mode 100644
index 000000000..494013cc3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitor.java
@@ -0,0 +1,319 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that has a return value.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public interface GenericVisitor<R, A> {
+
+ // - Compilation Unit ----------------------------------
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(CompilationUnit n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(PackageDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(TypeParameter n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(LineComment n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(BlockComment n, A arg);
+
+ // - Body ----------------------------------------------
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ClassOrInterfaceDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(EnumDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(EnumConstantDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(AnnotationDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(AnnotationMemberDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(FieldDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(VariableDeclarator n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ConstructorDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(MethodDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(Parameter n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(InitializerDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(JavadocComment n, A arg);
+
+ // - Type ----------------------------------------------
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ClassOrInterfaceType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(PrimitiveType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ArrayType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ArrayCreationLevel n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(IntersectionType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(UnionType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(VoidType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(WildcardType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(UnknownType n, A arg);
+
+ // - Expression ----------------------------------------
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ArrayAccessExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ArrayCreationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ArrayInitializerExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(AssignExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(BinaryExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(CastExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ClassExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ConditionalExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(EnclosedExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(FieldAccessExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(InstanceOfExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(StringLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(IntegerLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(LongLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(CharLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(DoubleLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(BooleanLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(NullLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(MethodCallExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(NameExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ObjectCreationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ThisExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(SuperExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(UnaryExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(VariableDeclarationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(MarkerAnnotationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(SingleMemberAnnotationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(NormalAnnotationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(MemberValuePair n, A arg);
+
+ // - Statements ----------------------------------------
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ExplicitConstructorInvocationStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(LocalClassDeclarationStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(AssertStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(BlockStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(LabeledStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(EmptyStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ExpressionStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(SwitchStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(SwitchEntryStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(BreakStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ReturnStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(IfStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(WhileStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ContinueStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(DoStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ForeachStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ForStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ThrowStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(SynchronizedStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(TryStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(CatchClause n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(LambdaExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(MethodReferenceExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(TypeExpr n, A arg);
+
+ R visit(NodeList n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(Name n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(SimpleName n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ImportDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ModuleDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ModuleRequiresStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ModuleExportsStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ModuleProvidesStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ModuleUsesStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ModuleOpensStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(UnparsableStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorGenerator")
+ R visit(ReceiverParameter n, A arg);
+
+ R visit(VarType n, A arg);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java
new file mode 100644
index 000000000..3d5de4fbb
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorAdapter.java
@@ -0,0 +1,2054 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that has a return value (R), and has a default implementation for all its visit
+ * methods that visits their children in an unspecified order, and the first visit method
+ * that returns a value will stop the visitation and be the end result.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class GenericVisitorAdapter<R, A> implements GenericVisitor<R, A> {
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final AnnotationDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getMembers().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final AnnotationMemberDeclaration n, final A arg) {
+ R result;
+ if (n.getDefaultValue().isPresent()) {
+ result = n.getDefaultValue().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ArrayAccessExpr n, final A arg) {
+ R result;
+ {
+ result = n.getIndex().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ArrayCreationExpr n, final A arg) {
+ R result;
+ {
+ result = n.getElementType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getInitializer().isPresent()) {
+ result = n.getInitializer().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getLevels().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ArrayInitializerExpr n, final A arg) {
+ R result;
+ {
+ result = n.getValues().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final AssertStmt n, final A arg) {
+ R result;
+ {
+ result = n.getCheck().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getMessage().isPresent()) {
+ result = n.getMessage().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final AssignExpr n, final A arg) {
+ R result;
+ {
+ result = n.getTarget().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getValue().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final BinaryExpr n, final A arg) {
+ R result;
+ {
+ result = n.getLeft().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getRight().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final BlockStmt n, final A arg) {
+ R result;
+ {
+ result = n.getStatements().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final BooleanLiteralExpr n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final BreakStmt n, final A arg) {
+ R result;
+ if (n.getLabel().isPresent()) {
+ result = n.getLabel().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final CastExpr n, final A arg) {
+ R result;
+ {
+ result = n.getExpression().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final CatchClause n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getParameter().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final CharLiteralExpr n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ClassExpr n, final A arg) {
+ R result;
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ClassOrInterfaceDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getExtendedTypes().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getImplementedTypes().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getTypeParameters().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getMembers().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ClassOrInterfaceType n, final A arg) {
+ R result;
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getScope().isPresent()) {
+ result = n.getScope().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getTypeArguments().isPresent()) {
+ result = n.getTypeArguments().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final CompilationUnit n, final A arg) {
+ R result;
+ {
+ result = n.getImports().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getModule().isPresent()) {
+ result = n.getModule().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getPackageDeclaration().isPresent()) {
+ result = n.getPackageDeclaration().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getTypes().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ConditionalExpr n, final A arg) {
+ R result;
+ {
+ result = n.getCondition().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getElseExpr().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getThenExpr().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ConstructorDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getParameters().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getReceiverParameter().isPresent()) {
+ result = n.getReceiverParameter().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getThrownExceptions().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getTypeParameters().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ContinueStmt n, final A arg) {
+ R result;
+ if (n.getLabel().isPresent()) {
+ result = n.getLabel().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final DoStmt n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getCondition().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final DoubleLiteralExpr n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final EmptyStmt n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final EnclosedExpr n, final A arg) {
+ R result;
+ {
+ result = n.getInner().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final EnumConstantDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getArguments().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getClassBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final EnumDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getEntries().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getImplementedTypes().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getMembers().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ExplicitConstructorInvocationStmt n, final A arg) {
+ R result;
+ {
+ result = n.getArguments().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getExpression().isPresent()) {
+ result = n.getExpression().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getTypeArguments().isPresent()) {
+ result = n.getTypeArguments().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ExpressionStmt n, final A arg) {
+ R result;
+ {
+ result = n.getExpression().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final FieldAccessExpr n, final A arg) {
+ R result;
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getScope().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getTypeArguments().isPresent()) {
+ result = n.getTypeArguments().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final FieldDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getVariables().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ForeachStmt n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getIterable().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getVariable().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ForStmt n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getCompare().isPresent()) {
+ result = n.getCompare().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getInitialization().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getUpdate().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final IfStmt n, final A arg) {
+ R result;
+ {
+ result = n.getCondition().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getElseStmt().isPresent()) {
+ result = n.getElseStmt().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getThenStmt().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final InitializerDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final InstanceOfExpr n, final A arg) {
+ R result;
+ {
+ result = n.getExpression().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final IntegerLiteralExpr n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final JavadocComment n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final LabeledStmt n, final A arg) {
+ R result;
+ {
+ result = n.getLabel().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getStatement().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final LongLiteralExpr n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final MarkerAnnotationExpr n, final A arg) {
+ R result;
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final MemberValuePair n, final A arg) {
+ R result;
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getValue().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final MethodCallExpr n, final A arg) {
+ R result;
+ {
+ result = n.getArguments().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getScope().isPresent()) {
+ result = n.getScope().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getTypeArguments().isPresent()) {
+ result = n.getTypeArguments().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final MethodDeclaration n, final A arg) {
+ R result;
+ if (n.getBody().isPresent()) {
+ result = n.getBody().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getParameters().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getReceiverParameter().isPresent()) {
+ result = n.getReceiverParameter().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getThrownExceptions().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getTypeParameters().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final NameExpr n, final A arg) {
+ R result;
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final NormalAnnotationExpr n, final A arg) {
+ R result;
+ {
+ result = n.getPairs().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final NullLiteralExpr n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ObjectCreationExpr n, final A arg) {
+ R result;
+ if (n.getAnonymousClassBody().isPresent()) {
+ result = n.getAnonymousClassBody().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getArguments().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getScope().isPresent()) {
+ result = n.getScope().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getTypeArguments().isPresent()) {
+ result = n.getTypeArguments().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final PackageDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final Parameter n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getVarArgsAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final PrimitiveType n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final Name n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getQualifier().isPresent()) {
+ result = n.getQualifier().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final SimpleName n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ArrayType n, final A arg) {
+ R result;
+ {
+ result = n.getComponentType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ArrayCreationLevel n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getDimension().isPresent()) {
+ result = n.getDimension().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final IntersectionType n, final A arg) {
+ R result;
+ {
+ result = n.getElements().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final UnionType n, final A arg) {
+ R result;
+ {
+ result = n.getElements().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ReturnStmt n, final A arg) {
+ R result;
+ if (n.getExpression().isPresent()) {
+ result = n.getExpression().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final SingleMemberAnnotationExpr n, final A arg) {
+ R result;
+ {
+ result = n.getMemberValue().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final StringLiteralExpr n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final SuperExpr n, final A arg) {
+ R result;
+ if (n.getClassExpr().isPresent()) {
+ result = n.getClassExpr().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final SwitchEntryStmt n, final A arg) {
+ R result;
+ if (n.getLabel().isPresent()) {
+ result = n.getLabel().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getStatements().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final SwitchStmt n, final A arg) {
+ R result;
+ {
+ result = n.getEntries().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getSelector().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final SynchronizedStmt n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getExpression().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ThisExpr n, final A arg) {
+ R result;
+ if (n.getClassExpr().isPresent()) {
+ result = n.getClassExpr().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ThrowStmt n, final A arg) {
+ R result;
+ {
+ result = n.getExpression().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final TryStmt n, final A arg) {
+ R result;
+ {
+ result = n.getCatchClauses().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getFinallyBlock().isPresent()) {
+ result = n.getFinallyBlock().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getResources().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getTryBlock().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final LocalClassDeclarationStmt n, final A arg) {
+ R result;
+ {
+ result = n.getClassDeclaration().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final TypeParameter n, final A arg) {
+ R result;
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getTypeBound().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final UnaryExpr n, final A arg) {
+ R result;
+ {
+ result = n.getExpression().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final UnknownType n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final VariableDeclarationExpr n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getVariables().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final VariableDeclarator n, final A arg) {
+ R result;
+ if (n.getInitializer().isPresent()) {
+ result = n.getInitializer().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final VoidType n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final WhileStmt n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getCondition().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final WildcardType n, final A arg) {
+ R result;
+ if (n.getExtendedType().isPresent()) {
+ result = n.getExtendedType().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getSuperType().isPresent()) {
+ result = n.getSuperType().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final LambdaExpr n, final A arg) {
+ R result;
+ {
+ result = n.getBody().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getParameters().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final MethodReferenceExpr n, final A arg) {
+ R result;
+ {
+ result = n.getScope().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getTypeArguments().isPresent()) {
+ result = n.getTypeArguments().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final TypeExpr n, final A arg) {
+ R result;
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ImportDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final BlockComment n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final LineComment n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ public R visit(NodeList n, A arg) {
+ for (final Object v : n) {
+ R result = ((Node) v).accept(this, arg);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ModuleDeclaration n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getModuleStmts().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ModuleRequiresStmt n, final A arg) {
+ R result;
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ModuleExportsStmt n, final A arg) {
+ R result;
+ {
+ result = n.getModuleNames().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ModuleProvidesStmt n, final A arg) {
+ R result;
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getWithTypes().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ModuleUsesStmt n, final A arg) {
+ R result;
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ModuleOpensStmt n, final A arg) {
+ R result;
+ {
+ result = n.getModuleNames().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final UnparsableStmt n, final A arg) {
+ R result;
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorAdapterGenerator")
+ public R visit(final ReceiverParameter n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getName().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ {
+ result = n.getType().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+
+ @Override
+ public R visit(final VarType n, final A arg) {
+ R result;
+ {
+ result = n.getAnnotations().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ if (n.getComment().isPresent()) {
+ result = n.getComment().get().accept(this, arg);
+ if (result != null)
+ return result;
+ }
+ return null;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java
new file mode 100644
index 000000000..2cd9a0fdc
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/GenericVisitorWithDefaults.java
@@ -0,0 +1,603 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that has a return value (R), and has default methods that are used when a specific visit method is not
+ * overridden.
+ */
+public abstract class GenericVisitorWithDefaults<R, A> implements GenericVisitor<R, A> {
+
+ /**
+ * This will be called by every node visit method that is not overridden.
+ */
+ public R defaultAction(Node n, A arg) {
+ return null;
+ }
+
+ /**
+ * This will be called by the NodeList visit method when it is not overridden.
+ */
+ public R defaultAction(NodeList n, A arg) {
+ return null;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final AnnotationDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final AnnotationMemberDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ArrayAccessExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ArrayCreationExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ArrayInitializerExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final AssertStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final AssignExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final BinaryExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final BlockStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final BooleanLiteralExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final BreakStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final CastExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final CatchClause n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final CharLiteralExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ClassExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ClassOrInterfaceDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ClassOrInterfaceType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final CompilationUnit n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ConditionalExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ConstructorDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ContinueStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final DoStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final DoubleLiteralExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final EmptyStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final EnclosedExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final EnumConstantDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final EnumDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ExplicitConstructorInvocationStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ExpressionStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final FieldAccessExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final FieldDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ForeachStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ForStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final IfStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final InitializerDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final InstanceOfExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final IntegerLiteralExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final JavadocComment n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final LabeledStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final LongLiteralExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final MarkerAnnotationExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final MemberValuePair n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final MethodCallExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final MethodDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final NameExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final NormalAnnotationExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final NullLiteralExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ObjectCreationExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final PackageDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final Parameter n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final PrimitiveType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final Name n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final SimpleName n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ArrayType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ArrayCreationLevel n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final IntersectionType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final UnionType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ReturnStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final SingleMemberAnnotationExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final StringLiteralExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final SuperExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final SwitchEntryStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final SwitchStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final SynchronizedStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ThisExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ThrowStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final TryStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final LocalClassDeclarationStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final TypeParameter n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final UnaryExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final UnknownType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final VariableDeclarationExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final VariableDeclarator n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final VoidType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final WhileStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final WildcardType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final LambdaExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final MethodReferenceExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final TypeExpr n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ImportDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final BlockComment n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final LineComment n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ public R visit(NodeList n, A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ModuleDeclaration n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ModuleRequiresStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ModuleExportsStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ModuleProvidesStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ModuleUsesStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ModuleOpensStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final UnparsableStmt n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.GenericVisitorWithDefaultsGenerator")
+ public R visit(final ReceiverParameter n, final A arg) {
+ return defaultAction(n, arg);
+ }
+
+ @Override
+ public R visit(final VarType n, final A arg) {
+ return defaultAction(n, arg);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java
new file mode 100644
index 000000000..92da13e8f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/HashCodeVisitor.java
@@ -0,0 +1,518 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that calculates a deep hash code for a node by using the hash codes of all its properties,
+ * and the hash codes of all its child nodes (by visiting those too.)
+ */
+public class HashCodeVisitor implements GenericVisitor<Integer, Void> {
+
+ private static final HashCodeVisitor SINGLETON = new HashCodeVisitor();
+
+ private HashCodeVisitor() {
+ // hide constructor
+ }
+
+ public static int hashCode(final Node node) {
+ return node.accept(SINGLETON, null);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final AnnotationDeclaration n, final Void arg) {
+ return (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final AnnotationMemberDeclaration n, final Void arg) {
+ return (n.getDefaultValue().isPresent() ? n.getDefaultValue().get().accept(this, arg) : 0) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ArrayAccessExpr n, final Void arg) {
+ return (n.getIndex().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ArrayCreationExpr n, final Void arg) {
+ return (n.getElementType().accept(this, arg)) * 31 + (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getLevels().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ArrayCreationLevel n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getDimension().isPresent() ? n.getDimension().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ArrayInitializerExpr n, final Void arg) {
+ return (n.getValues().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ArrayType n, final Void arg) {
+ return (n.getComponentType().accept(this, arg)) * 31 + (n.getOrigin().hashCode()) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final AssertStmt n, final Void arg) {
+ return (n.getCheck().accept(this, arg)) * 31 + (n.getMessage().isPresent() ? n.getMessage().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final AssignExpr n, final Void arg) {
+ return (n.getOperator().hashCode()) * 31 + (n.getTarget().accept(this, arg)) * 31 + (n.getValue().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final BinaryExpr n, final Void arg) {
+ return (n.getLeft().accept(this, arg)) * 31 + (n.getOperator().hashCode()) * 31 + (n.getRight().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final BlockComment n, final Void arg) {
+ return (n.getContent().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final BlockStmt n, final Void arg) {
+ return (n.getStatements().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final BooleanLiteralExpr n, final Void arg) {
+ return (n.getValue() ? 1 : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final BreakStmt n, final Void arg) {
+ return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final CastExpr n, final Void arg) {
+ return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final CatchClause n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getParameter().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final CharLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ClassExpr n, final Void arg) {
+ return (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ClassOrInterfaceDeclaration n, final Void arg) {
+ 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().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ClassOrInterfaceType n, final Void arg) {
+ 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)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final CompilationUnit n, final Void arg) {
+ 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)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ConditionalExpr n, final Void arg) {
+ return (n.getCondition().accept(this, arg)) * 31 + (n.getElseExpr().accept(this, arg)) * 31 + (n.getThenExpr().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ConstructorDeclaration n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 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)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ContinueStmt n, final Void arg) {
+ return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final DoStmt n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final DoubleLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final EmptyStmt n, final Void arg) {
+ return (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final EnclosedExpr n, final Void arg) {
+ return (n.getInner().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final EnumConstantDeclaration n, final Void arg) {
+ return (n.getArguments().accept(this, arg)) * 31 + (n.getClassBody().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final EnumDeclaration n, final Void arg) {
+ return (n.getEntries().accept(this, arg)) * 31 + (n.getImplementedTypes().accept(this, arg)) * 31 + (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ExplicitConstructorInvocationStmt n, final Void arg) {
+ 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) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ExpressionStmt n, final Void arg) {
+ return (n.getExpression().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final FieldAccessExpr n, final Void arg) {
+ return (n.getName().accept(this, arg)) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final FieldDeclaration n, final Void arg) {
+ return (n.getModifiers().hashCode()) * 31 + (n.getVariables().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ForStmt n, final Void arg) {
+ 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)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ForeachStmt n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final IfStmt n, final Void arg) {
+ return (n.getCondition().accept(this, arg)) * 31 + (n.getElseStmt().isPresent() ? n.getElseStmt().get().accept(this, arg) : 0) * 31 + (n.getThenStmt().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ImportDeclaration n, final Void arg) {
+ return (n.isAsterisk() ? 1 : 0) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final InitializerDeclaration n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final InstanceOfExpr n, final Void arg) {
+ return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final IntegerLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final IntersectionType n, final Void arg) {
+ return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final JavadocComment n, final Void arg) {
+ return (n.getContent().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final LabeledStmt n, final Void arg) {
+ return (n.getLabel().accept(this, arg)) * 31 + (n.getStatement().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final LambdaExpr n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final LineComment n, final Void arg) {
+ return (n.getContent().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final LocalClassDeclarationStmt n, final Void arg) {
+ return (n.getClassDeclaration().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final LongLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final MarkerAnnotationExpr n, final Void arg) {
+ return (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final MemberValuePair n, final Void arg) {
+ return (n.getName().accept(this, arg)) * 31 + (n.getValue().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final MethodCallExpr n, final Void arg) {
+ 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) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final MethodDeclaration n, final Void arg) {
+ return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 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)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final MethodReferenceExpr n, final Void arg) {
+ return (n.getIdentifier().hashCode()) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final NameExpr n, final Void arg) {
+ return (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final Name n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getIdentifier().hashCode()) * 31 + (n.getQualifier().isPresent() ? n.getQualifier().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ public Integer visit(NodeList n, Void arg) {
+ int result = 0;
+ for (Object node : n) {
+ result += 31 * ((Visitable) node).accept(this, arg);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final NormalAnnotationExpr n, final Void arg) {
+ return (n.getPairs().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final NullLiteralExpr n, final Void arg) {
+ return (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ObjectCreationExpr n, final Void arg) {
+ 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) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final PackageDeclaration n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final Parameter n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.isVarArgs() ? 1 : 0) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getVarArgsAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final PrimitiveType n, final Void arg) {
+ return (n.getType().hashCode()) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ReturnStmt n, final Void arg) {
+ return (n.getExpression().isPresent() ? n.getExpression().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final SimpleName n, final Void arg) {
+ return (n.getIdentifier().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final SingleMemberAnnotationExpr n, final Void arg) {
+ return (n.getMemberValue().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final StringLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final SuperExpr n, final Void arg) {
+ return (n.getClassExpr().isPresent() ? n.getClassExpr().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final SwitchEntryStmt n, final Void arg) {
+ return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0) * 31 + (n.getStatements().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final SwitchStmt n, final Void arg) {
+ return (n.getEntries().accept(this, arg)) * 31 + (n.getSelector().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final SynchronizedStmt n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getExpression().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ThisExpr n, final Void arg) {
+ return (n.getClassExpr().isPresent() ? n.getClassExpr().get().accept(this, arg) : 0) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ThrowStmt n, final Void arg) {
+ return (n.getExpression().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final TryStmt n, final Void arg) {
+ 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)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final TypeExpr n, final Void arg) {
+ return (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final TypeParameter n, final Void arg) {
+ return (n.getName().accept(this, arg)) * 31 + (n.getTypeBound().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final UnaryExpr n, final Void arg) {
+ return (n.getExpression().accept(this, arg)) * 31 + (n.getOperator().hashCode()) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final UnionType n, final Void arg) {
+ return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final UnknownType n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final VariableDeclarationExpr n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getVariables().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final VariableDeclarator n, final Void arg) {
+ return (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final VoidType n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final WhileStmt n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final WildcardType n, final Void arg) {
+ 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)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ModuleDeclaration n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.isOpen() ? 1 : 0) * 31 + (n.getModuleStmts().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ModuleRequiresStmt n, final Void arg) {
+ return (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ModuleExportsStmt n, final Void arg) {
+ return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ModuleProvidesStmt n, final Void arg) {
+ return (n.getType().accept(this, arg)) * 31 + (n.getWithTypes().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ModuleUsesStmt n, final Void arg) {
+ return (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ModuleOpensStmt n, final Void arg) {
+ return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final UnparsableStmt n, final Void arg) {
+ return (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.HashCodeVisitorGenerator")
+ public Integer visit(final ReceiverParameter n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+
+ @Override
+ public Integer visit(final VarType n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getComment().isPresent() ? n.getComment().get().accept(this, arg) : 0);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java
new file mode 100644
index 000000000..c7808641d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ModifierVisitor.java
@@ -0,0 +1,1297 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import com.github.javaparser.utils.Pair;
+import javax.annotation.Generated;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * This visitor can be used to save time when some specific nodes needs
+ * to be changed. To do that just extend this class and override the methods
+ * from the nodes who needs to be changed, returning the changed node.
+ * Returning null will remove the node.
+ *
+ * If a node is removed that was required in its parent node,
+ * the parent node will be removed too.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public class ModifierVisitor<A> implements GenericVisitor<Visitable, A> {
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final AnnotationDeclaration n, final A arg) {
+ NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setMembers(members);
+ n.setName(name);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final AnnotationMemberDeclaration n, final A arg) {
+ Expression defaultValue = n.getDefaultValue().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ Type type = (Type) n.getType().accept(this, arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null || type == null)
+ return null;
+ n.setDefaultValue(defaultValue);
+ n.setName(name);
+ n.setType(type);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ArrayAccessExpr n, final A arg) {
+ Expression index = (Expression) n.getIndex().accept(this, arg);
+ Expression name = (Expression) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (index == null || name == null)
+ return null;
+ n.setIndex(index);
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ArrayCreationExpr n, final A arg) {
+ Type elementType = (Type) n.getElementType().accept(this, arg);
+ ArrayInitializerExpr initializer = n.getInitializer().map(s -> (ArrayInitializerExpr) s.accept(this, arg)).orElse(null);
+ NodeList<ArrayCreationLevel> levels = modifyList(n.getLevels(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (elementType == null || levels.isEmpty())
+ return null;
+ n.setElementType(elementType);
+ n.setInitializer(initializer);
+ n.setLevels(levels);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ArrayInitializerExpr n, final A arg) {
+ NodeList<Expression> values = modifyList(n.getValues(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setValues(values);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final AssertStmt n, final A arg) {
+ Expression check = (Expression) n.getCheck().accept(this, arg);
+ Expression message = n.getMessage().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (check == null)
+ return null;
+ n.setCheck(check);
+ n.setMessage(message);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final AssignExpr n, final A arg) {
+ Expression target = (Expression) n.getTarget().accept(this, arg);
+ Expression value = (Expression) n.getValue().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (target == null || value == null)
+ return null;
+ n.setTarget(target);
+ n.setValue(value);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final BinaryExpr n, final A arg) {
+ Expression left = (Expression) n.getLeft().accept(this, arg);
+ Expression right = (Expression) n.getRight().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (left == null)
+ return right;
+ if (right == null)
+ return left;
+ n.setLeft(left);
+ n.setRight(right);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final BlockStmt n, final A arg) {
+ NodeList<Statement> statements = modifyList(n.getStatements(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setStatements(statements);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final BooleanLiteralExpr n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final BreakStmt n, final A arg) {
+ SimpleName label = n.getLabel().map(s -> (SimpleName) s.accept(this, arg)).orElse(null);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setLabel(label);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final CastExpr n, final A arg) {
+ Expression expression = (Expression) n.getExpression().accept(this, arg);
+ Type type = (Type) n.getType().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (expression == null || type == null)
+ return null;
+ n.setExpression(expression);
+ n.setType(type);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final CatchClause n, final A arg) {
+ BlockStmt body = (BlockStmt) n.getBody().accept(this, arg);
+ Parameter parameter = (Parameter) n.getParameter().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null || parameter == null)
+ return null;
+ n.setBody(body);
+ n.setParameter(parameter);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final CharLiteralExpr n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ClassExpr n, final A arg) {
+ Type type = (Type) n.getType().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (type == null)
+ return null;
+ n.setType(type);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ClassOrInterfaceDeclaration n, final A arg) {
+ NodeList<ClassOrInterfaceType> extendedTypes = modifyList(n.getExtendedTypes(), arg);
+ NodeList<ClassOrInterfaceType> implementedTypes = modifyList(n.getImplementedTypes(), arg);
+ NodeList<TypeParameter> typeParameters = modifyList(n.getTypeParameters(), arg);
+ NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setExtendedTypes(extendedTypes);
+ n.setImplementedTypes(implementedTypes);
+ n.setTypeParameters(typeParameters);
+ n.setMembers(members);
+ n.setName(name);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ClassOrInterfaceType n, final A arg) {
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ ClassOrInterfaceType scope = n.getScope().map(s -> (ClassOrInterfaceType) s.accept(this, arg)).orElse(null);
+ NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setName(name);
+ n.setScope(scope);
+ n.setTypeArguments(typeArguments);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final CompilationUnit n, final A arg) {
+ NodeList<ImportDeclaration> imports = modifyList(n.getImports(), arg);
+ ModuleDeclaration module = n.getModule().map(s -> (ModuleDeclaration) s.accept(this, arg)).orElse(null);
+ PackageDeclaration packageDeclaration = n.getPackageDeclaration().map(s -> (PackageDeclaration) s.accept(this, arg)).orElse(null);
+ NodeList<TypeDeclaration<?>> types = modifyList(n.getTypes(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setImports(imports);
+ n.setModule(module);
+ n.setPackageDeclaration(packageDeclaration);
+ n.setTypes(types);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ConditionalExpr n, final A arg) {
+ Expression condition = (Expression) n.getCondition().accept(this, arg);
+ Expression elseExpr = (Expression) n.getElseExpr().accept(this, arg);
+ Expression thenExpr = (Expression) n.getThenExpr().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (condition == null || elseExpr == null || thenExpr == null)
+ return null;
+ n.setCondition(condition);
+ n.setElseExpr(elseExpr);
+ n.setThenExpr(thenExpr);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ConstructorDeclaration n, final A arg) {
+ BlockStmt body = (BlockStmt) n.getBody().accept(this, arg);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ NodeList<Parameter> parameters = modifyList(n.getParameters(), arg);
+ ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null);
+ NodeList<ReferenceType> thrownExceptions = modifyList(n.getThrownExceptions(), arg);
+ NodeList<TypeParameter> typeParameters = modifyList(n.getTypeParameters(), arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null || name == null)
+ return null;
+ n.setBody(body);
+ n.setName(name);
+ n.setParameters(parameters);
+ n.setReceiverParameter(receiverParameter);
+ n.setThrownExceptions(thrownExceptions);
+ n.setTypeParameters(typeParameters);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ContinueStmt n, final A arg) {
+ SimpleName label = n.getLabel().map(s -> (SimpleName) s.accept(this, arg)).orElse(null);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setLabel(label);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final DoStmt n, final A arg) {
+ Statement body = (Statement) n.getBody().accept(this, arg);
+ Expression condition = (Expression) n.getCondition().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null || condition == null)
+ return null;
+ n.setBody(body);
+ n.setCondition(condition);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final DoubleLiteralExpr n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final EmptyStmt n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final EnclosedExpr n, final A arg) {
+ Expression inner = (Expression) n.getInner().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (inner == null)
+ return null;
+ n.setInner(inner);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final EnumConstantDeclaration n, final A arg) {
+ NodeList<Expression> arguments = modifyList(n.getArguments(), arg);
+ NodeList<BodyDeclaration<?>> classBody = modifyList(n.getClassBody(), arg);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setArguments(arguments);
+ n.setClassBody(classBody);
+ n.setName(name);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final EnumDeclaration n, final A arg) {
+ NodeList<EnumConstantDeclaration> entries = modifyList(n.getEntries(), arg);
+ NodeList<ClassOrInterfaceType> implementedTypes = modifyList(n.getImplementedTypes(), arg);
+ NodeList<BodyDeclaration<?>> members = modifyList(n.getMembers(), arg);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setEntries(entries);
+ n.setImplementedTypes(implementedTypes);
+ n.setMembers(members);
+ n.setName(name);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ExplicitConstructorInvocationStmt n, final A arg) {
+ NodeList<Expression> arguments = modifyList(n.getArguments(), arg);
+ Expression expression = n.getExpression().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setArguments(arguments);
+ n.setExpression(expression);
+ n.setTypeArguments(typeArguments);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ExpressionStmt n, final A arg) {
+ Expression expression = (Expression) n.getExpression().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (expression == null)
+ return null;
+ n.setExpression(expression);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final FieldAccessExpr n, final A arg) {
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ Expression scope = (Expression) n.getScope().accept(this, arg);
+ NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null || scope == null)
+ return null;
+ n.setName(name);
+ n.setScope(scope);
+ n.setTypeArguments(typeArguments);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final FieldDeclaration n, final A arg) {
+ NodeList<VariableDeclarator> variables = modifyList(n.getVariables(), arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (variables.isEmpty())
+ return null;
+ n.setVariables(variables);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ForeachStmt n, final A arg) {
+ Statement body = (Statement) n.getBody().accept(this, arg);
+ Expression iterable = (Expression) n.getIterable().accept(this, arg);
+ VariableDeclarationExpr variable = (VariableDeclarationExpr) n.getVariable().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null || iterable == null || variable == null)
+ return null;
+ n.setBody(body);
+ n.setIterable(iterable);
+ n.setVariable(variable);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ForStmt n, final A arg) {
+ Statement body = (Statement) n.getBody().accept(this, arg);
+ Expression compare = n.getCompare().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ NodeList<Expression> initialization = modifyList(n.getInitialization(), arg);
+ NodeList<Expression> update = modifyList(n.getUpdate(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null)
+ return null;
+ n.setBody(body);
+ n.setCompare(compare);
+ n.setInitialization(initialization);
+ n.setUpdate(update);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final IfStmt n, final A arg) {
+ Expression condition = (Expression) n.getCondition().accept(this, arg);
+ Statement elseStmt = n.getElseStmt().map(s -> (Statement) s.accept(this, arg)).orElse(null);
+ Statement thenStmt = (Statement) n.getThenStmt().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (condition == null || thenStmt == null)
+ return null;
+ n.setCondition(condition);
+ n.setElseStmt(elseStmt);
+ n.setThenStmt(thenStmt);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final InitializerDeclaration n, final A arg) {
+ BlockStmt body = (BlockStmt) n.getBody().accept(this, arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null)
+ return null;
+ n.setBody(body);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final InstanceOfExpr n, final A arg) {
+ Expression expression = (Expression) n.getExpression().accept(this, arg);
+ ReferenceType type = (ReferenceType) n.getType().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (expression == null || type == null)
+ return null;
+ n.setExpression(expression);
+ n.setType(type);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final IntegerLiteralExpr n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final JavadocComment n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final LabeledStmt n, final A arg) {
+ SimpleName label = (SimpleName) n.getLabel().accept(this, arg);
+ Statement statement = (Statement) n.getStatement().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (label == null || statement == null)
+ return null;
+ n.setLabel(label);
+ n.setStatement(statement);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final LongLiteralExpr n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final MarkerAnnotationExpr n, final A arg) {
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final MemberValuePair n, final A arg) {
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ Expression value = (Expression) n.getValue().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null || value == null)
+ return null;
+ n.setName(name);
+ n.setValue(value);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final MethodCallExpr n, final A arg) {
+ NodeList<Expression> arguments = modifyList(n.getArguments(), arg);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ Expression scope = n.getScope().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setArguments(arguments);
+ n.setName(name);
+ n.setScope(scope);
+ n.setTypeArguments(typeArguments);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final MethodDeclaration n, final A arg) {
+ BlockStmt body = n.getBody().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null);
+ Type type = (Type) n.getType().accept(this, arg);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ NodeList<Parameter> parameters = modifyList(n.getParameters(), arg);
+ ReceiverParameter receiverParameter = n.getReceiverParameter().map(s -> (ReceiverParameter) s.accept(this, arg)).orElse(null);
+ NodeList<ReferenceType> thrownExceptions = modifyList(n.getThrownExceptions(), arg);
+ NodeList<TypeParameter> typeParameters = modifyList(n.getTypeParameters(), arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (type == null || name == null)
+ return null;
+ n.setBody(body);
+ n.setType(type);
+ n.setName(name);
+ n.setParameters(parameters);
+ n.setReceiverParameter(receiverParameter);
+ n.setThrownExceptions(thrownExceptions);
+ n.setTypeParameters(typeParameters);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final NameExpr n, final A arg) {
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final NormalAnnotationExpr n, final A arg) {
+ NodeList<MemberValuePair> pairs = modifyList(n.getPairs(), arg);
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setPairs(pairs);
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final NullLiteralExpr n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ObjectCreationExpr n, final A arg) {
+ NodeList<BodyDeclaration<?>> anonymousClassBody = modifyList(n.getAnonymousClassBody(), arg);
+ NodeList<Expression> arguments = modifyList(n.getArguments(), arg);
+ Expression scope = n.getScope().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ ClassOrInterfaceType type = (ClassOrInterfaceType) n.getType().accept(this, arg);
+ NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (type == null)
+ return null;
+ n.setAnonymousClassBody(anonymousClassBody);
+ n.setArguments(arguments);
+ n.setScope(scope);
+ n.setType(type);
+ n.setTypeArguments(typeArguments);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final PackageDeclaration n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setAnnotations(annotations);
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final Parameter n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ Type type = (Type) n.getType().accept(this, arg);
+ NodeList<AnnotationExpr> varArgsAnnotations = modifyList(n.getVarArgsAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null || type == null)
+ return null;
+ n.setAnnotations(annotations);
+ n.setName(name);
+ n.setType(type);
+ n.setVarArgsAnnotations(varArgsAnnotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final Name n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Name qualifier = n.getQualifier().map(s -> (Name) s.accept(this, arg)).orElse(null);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setAnnotations(annotations);
+ n.setQualifier(qualifier);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final PrimitiveType n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final SimpleName n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ArrayType n, final A arg) {
+ Type componentType = (Type) n.getComponentType().accept(this, arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (componentType == null)
+ return null;
+ n.setComponentType(componentType);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ArrayCreationLevel n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Expression dimension = n.getDimension().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setAnnotations(annotations);
+ n.setDimension(dimension);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final IntersectionType n, final A arg) {
+ NodeList<ReferenceType> elements = modifyList(n.getElements(), arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (elements.isEmpty())
+ return null;
+ n.setElements(elements);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final UnionType n, final A arg) {
+ NodeList<ReferenceType> elements = modifyList(n.getElements(), arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (elements.isEmpty())
+ return null;
+ n.setElements(elements);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ReturnStmt n, final A arg) {
+ Expression expression = n.getExpression().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setExpression(expression);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final SingleMemberAnnotationExpr n, final A arg) {
+ Expression memberValue = (Expression) n.getMemberValue().accept(this, arg);
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (memberValue == null || name == null)
+ return null;
+ n.setMemberValue(memberValue);
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final StringLiteralExpr n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final SuperExpr n, final A arg) {
+ Expression classExpr = n.getClassExpr().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setClassExpr(classExpr);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final SwitchEntryStmt n, final A arg) {
+ Expression label = n.getLabel().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ NodeList<Statement> statements = modifyList(n.getStatements(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setLabel(label);
+ n.setStatements(statements);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final SwitchStmt n, final A arg) {
+ NodeList<SwitchEntryStmt> entries = modifyList(n.getEntries(), arg);
+ Expression selector = (Expression) n.getSelector().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (selector == null)
+ return null;
+ n.setEntries(entries);
+ n.setSelector(selector);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final SynchronizedStmt n, final A arg) {
+ BlockStmt body = (BlockStmt) n.getBody().accept(this, arg);
+ Expression expression = (Expression) n.getExpression().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null || expression == null)
+ return null;
+ n.setBody(body);
+ n.setExpression(expression);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ThisExpr n, final A arg) {
+ Expression classExpr = n.getClassExpr().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setClassExpr(classExpr);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ThrowStmt n, final A arg) {
+ Expression expression = (Expression) n.getExpression().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (expression == null)
+ return null;
+ n.setExpression(expression);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final TryStmt n, final A arg) {
+ NodeList<CatchClause> catchClauses = modifyList(n.getCatchClauses(), arg);
+ BlockStmt finallyBlock = n.getFinallyBlock().map(s -> (BlockStmt) s.accept(this, arg)).orElse(null);
+ NodeList<Expression> resources = modifyList(n.getResources(), arg);
+ BlockStmt tryBlock = (BlockStmt) n.getTryBlock().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (tryBlock == null)
+ return null;
+ n.setCatchClauses(catchClauses);
+ n.setFinallyBlock(finallyBlock);
+ n.setResources(resources);
+ n.setTryBlock(tryBlock);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final LocalClassDeclarationStmt n, final A arg) {
+ ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) n.getClassDeclaration().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (classDeclaration == null)
+ return null;
+ n.setClassDeclaration(classDeclaration);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final TypeParameter n, final A arg) {
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ NodeList<ClassOrInterfaceType> typeBound = modifyList(n.getTypeBound(), arg);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setName(name);
+ n.setTypeBound(typeBound);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final UnaryExpr n, final A arg) {
+ Expression expression = (Expression) n.getExpression().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (expression == null)
+ return null;
+ n.setExpression(expression);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final UnknownType n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final VariableDeclarationExpr n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ NodeList<VariableDeclarator> variables = modifyList(n.getVariables(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (variables.isEmpty())
+ return null;
+ n.setAnnotations(annotations);
+ n.setVariables(variables);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final VariableDeclarator n, final A arg) {
+ Expression initializer = n.getInitializer().map(s -> (Expression) s.accept(this, arg)).orElse(null);
+ SimpleName name = (SimpleName) n.getName().accept(this, arg);
+ Type type = (Type) n.getType().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null || type == null)
+ return null;
+ n.setInitializer(initializer);
+ n.setName(name);
+ n.setType(type);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final VoidType n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final WhileStmt n, final A arg) {
+ Statement body = (Statement) n.getBody().accept(this, arg);
+ Expression condition = (Expression) n.getCondition().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null || condition == null)
+ return null;
+ n.setBody(body);
+ n.setCondition(condition);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final WildcardType n, final A arg) {
+ ReferenceType extendedType = n.getExtendedType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null);
+ ReferenceType superType = n.getSuperType().map(s -> (ReferenceType) s.accept(this, arg)).orElse(null);
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setExtendedType(extendedType);
+ n.setSuperType(superType);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final LambdaExpr n, final A arg) {
+ Statement body = (Statement) n.getBody().accept(this, arg);
+ NodeList<Parameter> parameters = modifyList(n.getParameters(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (body == null)
+ return null;
+ n.setBody(body);
+ n.setParameters(parameters);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final MethodReferenceExpr n, final A arg) {
+ Expression scope = (Expression) n.getScope().accept(this, arg);
+ NodeList<Type> typeArguments = modifyList(n.getTypeArguments(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (scope == null)
+ return null;
+ n.setScope(scope);
+ n.setTypeArguments(typeArguments);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final TypeExpr n, final A arg) {
+ Type type = (Type) n.getType().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (type == null)
+ return null;
+ n.setType(type);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ public Visitable visit(NodeList n, A arg) {
+ if (n.isEmpty()) {
+ return n;
+ }
+ final List<Pair<Node, Node>> changeList = new ArrayList<>();
+ final List<Node> listCopy = new ArrayList<>(n);
+ for (Node node : listCopy) {
+ final Node newNode = (Node) node.accept(this, arg);
+ changeList.add(new Pair<>(node, newNode));
+ }
+ for (Pair<Node, Node> change : changeList) {
+ if (change.b == null) {
+ n.remove(change.a);
+ } else {
+ final int i = n.indexOf(change.a);
+ // If the user removed this item by hand, ignore the change.
+ if (i != -1) {
+ n.set(i, change.b);
+ }
+ }
+ }
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Node visit(final ImportDeclaration n, final A arg) {
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final BlockComment n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final LineComment n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ private <N extends Node> NodeList<N> modifyList(NodeList<N> list, A arg) {
+ return (NodeList<N>) list.accept(this, arg);
+ }
+
+ private <N extends Node> NodeList<N> modifyList(Optional<NodeList<N>> list, A arg) {
+ return list.map(ns -> modifyList(ns, arg)).orElse(null);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ModuleDeclaration n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ NodeList<ModuleStmt> moduleStmts = modifyList(n.getModuleStmts(), arg);
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setAnnotations(annotations);
+ n.setModuleStmts(moduleStmts);
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ModuleRequiresStmt n, final A arg) {
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ModuleExportsStmt n, final A arg) {
+ NodeList<Name> moduleNames = modifyList(n.getModuleNames(), arg);
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setModuleNames(moduleNames);
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ModuleProvidesStmt n, final A arg) {
+ Type type = (Type) n.getType().accept(this, arg);
+ NodeList<Type> withTypes = modifyList(n.getWithTypes(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (type == null)
+ return null;
+ n.setType(type);
+ n.setWithTypes(withTypes);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ModuleUsesStmt n, final A arg) {
+ Type type = (Type) n.getType().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (type == null)
+ return null;
+ n.setType(type);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ModuleOpensStmt n, final A arg) {
+ NodeList<Name> moduleNames = modifyList(n.getModuleNames(), arg);
+ Name name = (Name) n.getName().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null)
+ return null;
+ n.setModuleNames(moduleNames);
+ n.setName(name);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final UnparsableStmt n, final A arg) {
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ModifierVisitorGenerator")
+ public Visitable visit(final ReceiverParameter n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Name name = (Name) n.getName().accept(this, arg);
+ Type type = (Type) n.getType().accept(this, arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ if (name == null || type == null)
+ return null;
+ n.setAnnotations(annotations);
+ n.setName(name);
+ n.setType(type);
+ n.setComment(comment);
+ return n;
+ }
+
+ @Override
+ public Visitable visit(final VarType n, final A arg) {
+ NodeList<AnnotationExpr> annotations = modifyList(n.getAnnotations(), arg);
+ Comment comment = n.getComment().map(s -> (Comment) s.accept(this, arg)).orElse(null);
+ n.setAnnotations(annotations);
+ n.setComment(comment);
+ return n;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java
new file mode 100644
index 000000000..b3c1dceff
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentEqualsVisitor.java
@@ -0,0 +1,1154 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+import java.util.Optional;
+
+public class NoCommentEqualsVisitor implements GenericVisitor<Boolean, Visitable> {
+
+ private static final NoCommentEqualsVisitor SINGLETON = new NoCommentEqualsVisitor();
+
+ public static boolean equals(final Node n, final Node n2) {
+ return SINGLETON.nodeEquals(n, n2);
+ }
+
+ private <N extends Node> boolean nodesEquals(NodeList<N> n, NodeList<N> n2) {
+ if (n == n2) {
+ return true;
+ }
+ if (n == null || n2 == null) {
+ return false;
+ }
+ if (n.size() != n2.size()) {
+ return false;
+ }
+ for (int i = 0; i < n.size(); i++) {
+ if (!nodeEquals(n.get(i), n2.get(i))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private <T extends Node> boolean nodeEquals(final T n, final T n2) {
+ if (n == n2) {
+ return true;
+ }
+ if (n == null || n2 == null) {
+ return false;
+ }
+ if (n.getClass() != n2.getClass()) {
+ return false;
+ }
+ return n.accept(this, n2);
+ }
+
+ private <T extends Node> boolean nodeEquals(final Optional<T> n, final Optional<T> n2) {
+ return nodeEquals(n.orElse(null), n2.orElse(null));
+ }
+
+ private <T extends Node> boolean nodesEquals(final Optional<NodeList<T>> n, final Optional<NodeList<T>> n2) {
+ return nodesEquals(n.orElse(null), n2.orElse(null));
+ }
+
+ private boolean objEquals(final Object n, final Object n2) {
+ if (n == n2) {
+ return true;
+ }
+ if (n == null || n2 == null) {
+ return false;
+ }
+ return n.equals(n2);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final CompilationUnit n, final Visitable arg) {
+ final CompilationUnit n2 = (CompilationUnit) arg;
+ if (!nodesEquals(n.getImports(), n2.getImports()))
+ return false;
+ if (!nodeEquals(n.getModule(), n2.getModule()))
+ return false;
+ if (!nodeEquals(n.getPackageDeclaration(), n2.getPackageDeclaration()))
+ return false;
+ if (!nodesEquals(n.getTypes(), n2.getTypes()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final PackageDeclaration n, final Visitable arg) {
+ final PackageDeclaration n2 = (PackageDeclaration) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final TypeParameter n, final Visitable arg) {
+ final TypeParameter n2 = (TypeParameter) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getTypeBound(), n2.getTypeBound()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final LineComment n, final Visitable arg) {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final BlockComment n, final Visitable arg) {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ClassOrInterfaceDeclaration n, final Visitable arg) {
+ final ClassOrInterfaceDeclaration n2 = (ClassOrInterfaceDeclaration) arg;
+ if (!nodesEquals(n.getExtendedTypes(), n2.getExtendedTypes()))
+ return false;
+ if (!nodesEquals(n.getImplementedTypes(), n2.getImplementedTypes()))
+ return false;
+ if (!objEquals(n.isInterface(), n2.isInterface()))
+ return false;
+ if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters()))
+ return false;
+ if (!nodesEquals(n.getMembers(), n2.getMembers()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final EnumDeclaration n, final Visitable arg) {
+ final EnumDeclaration n2 = (EnumDeclaration) arg;
+ if (!nodesEquals(n.getEntries(), n2.getEntries()))
+ return false;
+ if (!nodesEquals(n.getImplementedTypes(), n2.getImplementedTypes()))
+ return false;
+ if (!nodesEquals(n.getMembers(), n2.getMembers()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final EnumConstantDeclaration n, final Visitable arg) {
+ final EnumConstantDeclaration n2 = (EnumConstantDeclaration) arg;
+ if (!nodesEquals(n.getArguments(), n2.getArguments()))
+ return false;
+ if (!nodesEquals(n.getClassBody(), n2.getClassBody()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final AnnotationDeclaration n, final Visitable arg) {
+ final AnnotationDeclaration n2 = (AnnotationDeclaration) arg;
+ if (!nodesEquals(n.getMembers(), n2.getMembers()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final AnnotationMemberDeclaration n, final Visitable arg) {
+ final AnnotationMemberDeclaration n2 = (AnnotationMemberDeclaration) arg;
+ if (!nodeEquals(n.getDefaultValue(), n2.getDefaultValue()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final FieldDeclaration n, final Visitable arg) {
+ final FieldDeclaration n2 = (FieldDeclaration) arg;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodesEquals(n.getVariables(), n2.getVariables()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final VariableDeclarator n, final Visitable arg) {
+ final VariableDeclarator n2 = (VariableDeclarator) arg;
+ if (!nodeEquals(n.getInitializer(), n2.getInitializer()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ConstructorDeclaration n, final Visitable arg) {
+ final ConstructorDeclaration n2 = (ConstructorDeclaration) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getParameters(), n2.getParameters()))
+ return false;
+ if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter()))
+ return false;
+ if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions()))
+ return false;
+ if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final MethodDeclaration n, final Visitable arg) {
+ final MethodDeclaration n2 = (MethodDeclaration) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodesEquals(n.getParameters(), n2.getParameters()))
+ return false;
+ if (!nodeEquals(n.getReceiverParameter(), n2.getReceiverParameter()))
+ return false;
+ if (!nodesEquals(n.getThrownExceptions(), n2.getThrownExceptions()))
+ return false;
+ if (!nodesEquals(n.getTypeParameters(), n2.getTypeParameters()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final Parameter n, final Visitable arg) {
+ final Parameter n2 = (Parameter) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!objEquals(n.isVarArgs(), n2.isVarArgs()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getVarArgsAnnotations(), n2.getVarArgsAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final InitializerDeclaration n, final Visitable arg) {
+ final InitializerDeclaration n2 = (InitializerDeclaration) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!objEquals(n.isStatic(), n2.isStatic()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final JavadocComment n, final Visitable arg) {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ClassOrInterfaceType n, final Visitable arg) {
+ final ClassOrInterfaceType n2 = (ClassOrInterfaceType) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final PrimitiveType n, final Visitable arg) {
+ final PrimitiveType n2 = (PrimitiveType) arg;
+ if (!objEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ArrayType n, final Visitable arg) {
+ final ArrayType n2 = (ArrayType) arg;
+ if (!nodeEquals(n.getComponentType(), n2.getComponentType()))
+ return false;
+ if (!objEquals(n.getOrigin(), n2.getOrigin()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ArrayCreationLevel n, final Visitable arg) {
+ final ArrayCreationLevel n2 = (ArrayCreationLevel) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getDimension(), n2.getDimension()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final IntersectionType n, final Visitable arg) {
+ final IntersectionType n2 = (IntersectionType) arg;
+ if (!nodesEquals(n.getElements(), n2.getElements()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final UnionType n, final Visitable arg) {
+ final UnionType n2 = (UnionType) arg;
+ if (!nodesEquals(n.getElements(), n2.getElements()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final VoidType n, final Visitable arg) {
+ final VoidType n2 = (VoidType) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final WildcardType n, final Visitable arg) {
+ final WildcardType n2 = (WildcardType) arg;
+ if (!nodeEquals(n.getExtendedType(), n2.getExtendedType()))
+ return false;
+ if (!nodeEquals(n.getSuperType(), n2.getSuperType()))
+ return false;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final UnknownType n, final Visitable arg) {
+ final UnknownType n2 = (UnknownType) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ArrayAccessExpr n, final Visitable arg) {
+ final ArrayAccessExpr n2 = (ArrayAccessExpr) arg;
+ if (!nodeEquals(n.getIndex(), n2.getIndex()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ArrayCreationExpr n, final Visitable arg) {
+ final ArrayCreationExpr n2 = (ArrayCreationExpr) arg;
+ if (!nodeEquals(n.getElementType(), n2.getElementType()))
+ return false;
+ if (!nodeEquals(n.getInitializer(), n2.getInitializer()))
+ return false;
+ if (!nodesEquals(n.getLevels(), n2.getLevels()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ArrayInitializerExpr n, final Visitable arg) {
+ final ArrayInitializerExpr n2 = (ArrayInitializerExpr) arg;
+ if (!nodesEquals(n.getValues(), n2.getValues()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final AssignExpr n, final Visitable arg) {
+ final AssignExpr n2 = (AssignExpr) arg;
+ if (!objEquals(n.getOperator(), n2.getOperator()))
+ return false;
+ if (!nodeEquals(n.getTarget(), n2.getTarget()))
+ return false;
+ if (!nodeEquals(n.getValue(), n2.getValue()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final BinaryExpr n, final Visitable arg) {
+ final BinaryExpr n2 = (BinaryExpr) arg;
+ if (!nodeEquals(n.getLeft(), n2.getLeft()))
+ return false;
+ if (!objEquals(n.getOperator(), n2.getOperator()))
+ return false;
+ if (!nodeEquals(n.getRight(), n2.getRight()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final CastExpr n, final Visitable arg) {
+ final CastExpr n2 = (CastExpr) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ClassExpr n, final Visitable arg) {
+ final ClassExpr n2 = (ClassExpr) arg;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ConditionalExpr n, final Visitable arg) {
+ final ConditionalExpr n2 = (ConditionalExpr) arg;
+ if (!nodeEquals(n.getCondition(), n2.getCondition()))
+ return false;
+ if (!nodeEquals(n.getElseExpr(), n2.getElseExpr()))
+ return false;
+ if (!nodeEquals(n.getThenExpr(), n2.getThenExpr()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final EnclosedExpr n, final Visitable arg) {
+ final EnclosedExpr n2 = (EnclosedExpr) arg;
+ if (!nodeEquals(n.getInner(), n2.getInner()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final FieldAccessExpr n, final Visitable arg) {
+ final FieldAccessExpr n2 = (FieldAccessExpr) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final InstanceOfExpr n, final Visitable arg) {
+ final InstanceOfExpr n2 = (InstanceOfExpr) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final StringLiteralExpr n, final Visitable arg) {
+ final StringLiteralExpr n2 = (StringLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final IntegerLiteralExpr n, final Visitable arg) {
+ final IntegerLiteralExpr n2 = (IntegerLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final LongLiteralExpr n, final Visitable arg) {
+ final LongLiteralExpr n2 = (LongLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final CharLiteralExpr n, final Visitable arg) {
+ final CharLiteralExpr n2 = (CharLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final DoubleLiteralExpr n, final Visitable arg) {
+ final DoubleLiteralExpr n2 = (DoubleLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final BooleanLiteralExpr n, final Visitable arg) {
+ final BooleanLiteralExpr n2 = (BooleanLiteralExpr) arg;
+ if (!objEquals(n.getValue(), n2.getValue()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final NullLiteralExpr n, final Visitable arg) {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final MethodCallExpr n, final Visitable arg) {
+ final MethodCallExpr n2 = (MethodCallExpr) arg;
+ if (!nodesEquals(n.getArguments(), n2.getArguments()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final NameExpr n, final Visitable arg) {
+ final NameExpr n2 = (NameExpr) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ObjectCreationExpr n, final Visitable arg) {
+ final ObjectCreationExpr n2 = (ObjectCreationExpr) arg;
+ if (!nodesEquals(n.getAnonymousClassBody(), n2.getAnonymousClassBody()))
+ return false;
+ if (!nodesEquals(n.getArguments(), n2.getArguments()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final Name n, final Visitable arg) {
+ final Name n2 = (Name) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!objEquals(n.getIdentifier(), n2.getIdentifier()))
+ return false;
+ if (!nodeEquals(n.getQualifier(), n2.getQualifier()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final SimpleName n, final Visitable arg) {
+ final SimpleName n2 = (SimpleName) arg;
+ if (!objEquals(n.getIdentifier(), n2.getIdentifier()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ThisExpr n, final Visitable arg) {
+ final ThisExpr n2 = (ThisExpr) arg;
+ if (!nodeEquals(n.getClassExpr(), n2.getClassExpr()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final SuperExpr n, final Visitable arg) {
+ final SuperExpr n2 = (SuperExpr) arg;
+ if (!nodeEquals(n.getClassExpr(), n2.getClassExpr()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final UnaryExpr n, final Visitable arg) {
+ final UnaryExpr n2 = (UnaryExpr) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!objEquals(n.getOperator(), n2.getOperator()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final VariableDeclarationExpr n, final Visitable arg) {
+ final VariableDeclarationExpr n2 = (VariableDeclarationExpr) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodesEquals(n.getVariables(), n2.getVariables()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final MarkerAnnotationExpr n, final Visitable arg) {
+ final MarkerAnnotationExpr n2 = (MarkerAnnotationExpr) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final SingleMemberAnnotationExpr n, final Visitable arg) {
+ final SingleMemberAnnotationExpr n2 = (SingleMemberAnnotationExpr) arg;
+ if (!nodeEquals(n.getMemberValue(), n2.getMemberValue()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final NormalAnnotationExpr n, final Visitable arg) {
+ final NormalAnnotationExpr n2 = (NormalAnnotationExpr) arg;
+ if (!nodesEquals(n.getPairs(), n2.getPairs()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final MemberValuePair n, final Visitable arg) {
+ final MemberValuePair n2 = (MemberValuePair) arg;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getValue(), n2.getValue()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ExplicitConstructorInvocationStmt n, final Visitable arg) {
+ final ExplicitConstructorInvocationStmt n2 = (ExplicitConstructorInvocationStmt) arg;
+ if (!nodesEquals(n.getArguments(), n2.getArguments()))
+ return false;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ if (!objEquals(n.isThis(), n2.isThis()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final LocalClassDeclarationStmt n, final Visitable arg) {
+ final LocalClassDeclarationStmt n2 = (LocalClassDeclarationStmt) arg;
+ if (!nodeEquals(n.getClassDeclaration(), n2.getClassDeclaration()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final AssertStmt n, final Visitable arg) {
+ final AssertStmt n2 = (AssertStmt) arg;
+ if (!nodeEquals(n.getCheck(), n2.getCheck()))
+ return false;
+ if (!nodeEquals(n.getMessage(), n2.getMessage()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final BlockStmt n, final Visitable arg) {
+ final BlockStmt n2 = (BlockStmt) arg;
+ if (!nodesEquals(n.getStatements(), n2.getStatements()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final LabeledStmt n, final Visitable arg) {
+ final LabeledStmt n2 = (LabeledStmt) arg;
+ if (!nodeEquals(n.getLabel(), n2.getLabel()))
+ return false;
+ if (!nodeEquals(n.getStatement(), n2.getStatement()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final EmptyStmt n, final Visitable arg) {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ExpressionStmt n, final Visitable arg) {
+ final ExpressionStmt n2 = (ExpressionStmt) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final SwitchStmt n, final Visitable arg) {
+ final SwitchStmt n2 = (SwitchStmt) arg;
+ if (!nodesEquals(n.getEntries(), n2.getEntries()))
+ return false;
+ if (!nodeEquals(n.getSelector(), n2.getSelector()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final SwitchEntryStmt n, final Visitable arg) {
+ final SwitchEntryStmt n2 = (SwitchEntryStmt) arg;
+ if (!nodeEquals(n.getLabel(), n2.getLabel()))
+ return false;
+ if (!nodesEquals(n.getStatements(), n2.getStatements()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final BreakStmt n, final Visitable arg) {
+ final BreakStmt n2 = (BreakStmt) arg;
+ if (!nodeEquals(n.getLabel(), n2.getLabel()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ReturnStmt n, final Visitable arg) {
+ final ReturnStmt n2 = (ReturnStmt) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final IfStmt n, final Visitable arg) {
+ final IfStmt n2 = (IfStmt) arg;
+ if (!nodeEquals(n.getCondition(), n2.getCondition()))
+ return false;
+ if (!nodeEquals(n.getElseStmt(), n2.getElseStmt()))
+ return false;
+ if (!nodeEquals(n.getThenStmt(), n2.getThenStmt()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final WhileStmt n, final Visitable arg) {
+ final WhileStmt n2 = (WhileStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getCondition(), n2.getCondition()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ContinueStmt n, final Visitable arg) {
+ final ContinueStmt n2 = (ContinueStmt) arg;
+ if (!nodeEquals(n.getLabel(), n2.getLabel()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final DoStmt n, final Visitable arg) {
+ final DoStmt n2 = (DoStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getCondition(), n2.getCondition()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ForeachStmt n, final Visitable arg) {
+ final ForeachStmt n2 = (ForeachStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getIterable(), n2.getIterable()))
+ return false;
+ if (!nodeEquals(n.getVariable(), n2.getVariable()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ForStmt n, final Visitable arg) {
+ final ForStmt n2 = (ForStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getCompare(), n2.getCompare()))
+ return false;
+ if (!nodesEquals(n.getInitialization(), n2.getInitialization()))
+ return false;
+ if (!nodesEquals(n.getUpdate(), n2.getUpdate()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ThrowStmt n, final Visitable arg) {
+ final ThrowStmt n2 = (ThrowStmt) arg;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final SynchronizedStmt n, final Visitable arg) {
+ final SynchronizedStmt n2 = (SynchronizedStmt) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getExpression(), n2.getExpression()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final TryStmt n, final Visitable arg) {
+ final TryStmt n2 = (TryStmt) arg;
+ if (!nodesEquals(n.getCatchClauses(), n2.getCatchClauses()))
+ return false;
+ if (!nodeEquals(n.getFinallyBlock(), n2.getFinallyBlock()))
+ return false;
+ if (!nodesEquals(n.getResources(), n2.getResources()))
+ return false;
+ if (!nodeEquals(n.getTryBlock(), n2.getTryBlock()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final CatchClause n, final Visitable arg) {
+ final CatchClause n2 = (CatchClause) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!nodeEquals(n.getParameter(), n2.getParameter()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final LambdaExpr n, final Visitable arg) {
+ final LambdaExpr n2 = (LambdaExpr) arg;
+ if (!nodeEquals(n.getBody(), n2.getBody()))
+ return false;
+ if (!objEquals(n.isEnclosingParameters(), n2.isEnclosingParameters()))
+ return false;
+ if (!nodesEquals(n.getParameters(), n2.getParameters()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final MethodReferenceExpr n, final Visitable arg) {
+ final MethodReferenceExpr n2 = (MethodReferenceExpr) arg;
+ if (!objEquals(n.getIdentifier(), n2.getIdentifier()))
+ return false;
+ if (!nodeEquals(n.getScope(), n2.getScope()))
+ return false;
+ if (!nodesEquals(n.getTypeArguments(), n2.getTypeArguments()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final TypeExpr n, final Visitable arg) {
+ final TypeExpr n2 = (TypeExpr) arg;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ImportDeclaration n, final Visitable arg) {
+ final ImportDeclaration n2 = (ImportDeclaration) arg;
+ if (!objEquals(n.isAsterisk(), n2.isAsterisk()))
+ return false;
+ if (!objEquals(n.isStatic(), n2.isStatic()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ public Boolean visit(NodeList n, Visitable arg) {
+ return nodesEquals((NodeList<Node>) n, (NodeList<Node>) arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ModuleDeclaration n, final Visitable arg) {
+ final ModuleDeclaration n2 = (ModuleDeclaration) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!objEquals(n.isOpen(), n2.isOpen()))
+ return false;
+ if (!nodesEquals(n.getModuleStmts(), n2.getModuleStmts()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ModuleRequiresStmt n, final Visitable arg) {
+ final ModuleRequiresStmt n2 = (ModuleRequiresStmt) arg;
+ if (!objEquals(n.getModifiers(), n2.getModifiers()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ModuleExportsStmt n, final Visitable arg) {
+ final ModuleExportsStmt n2 = (ModuleExportsStmt) arg;
+ if (!nodesEquals(n.getModuleNames(), n2.getModuleNames()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ModuleProvidesStmt n, final Visitable arg) {
+ final ModuleProvidesStmt n2 = (ModuleProvidesStmt) arg;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ if (!nodesEquals(n.getWithTypes(), n2.getWithTypes()))
+ return false;
+ return true;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ModuleUsesStmt n, final Visitable arg) {
+ final ModuleUsesStmt n2 = (ModuleUsesStmt) arg;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ModuleOpensStmt n, final Visitable arg) {
+ final ModuleOpensStmt n2 = (ModuleOpensStmt) arg;
+ if (!nodesEquals(n.getModuleNames(), n2.getModuleNames()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final UnparsableStmt n, final Visitable arg) {
+ return true;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentEqualsVisitorGenerator")
+ public Boolean visit(final ReceiverParameter n, final Visitable arg) {
+ final ReceiverParameter n2 = (ReceiverParameter) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ if (!nodeEquals(n.getName(), n2.getName()))
+ return false;
+ if (!nodeEquals(n.getType(), n2.getType()))
+ return false;
+ return true;
+ }
+
+ @Override
+ public Boolean visit(final VarType n, final Visitable arg) {
+ final VarType n2 = (VarType) arg;
+ if (!nodesEquals(n.getAnnotations(), n2.getAnnotations()))
+ return false;
+ return true;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java
new file mode 100644
index 000000000..774e5d914
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/NoCommentHashCodeVisitor.java
@@ -0,0 +1,510 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+public class NoCommentHashCodeVisitor implements GenericVisitor<Integer, Void> {
+
+ private static final NoCommentHashCodeVisitor SINGLETON = new NoCommentHashCodeVisitor();
+
+ public static int hashCode(final Node node) {
+ return node.accept(SINGLETON, null);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final AnnotationDeclaration n, final Void arg) {
+ return (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final AnnotationMemberDeclaration n, final Void arg) {
+ return (n.getDefaultValue().isPresent() ? n.getDefaultValue().get().accept(this, arg) : 0) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ArrayAccessExpr n, final Void arg) {
+ return (n.getIndex().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ArrayCreationExpr n, final Void arg) {
+ return (n.getElementType().accept(this, arg)) * 31 + (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getLevels().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ArrayCreationLevel n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getDimension().isPresent() ? n.getDimension().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ArrayInitializerExpr n, final Void arg) {
+ return (n.getValues().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ArrayType n, final Void arg) {
+ return (n.getComponentType().accept(this, arg)) * 31 + (n.getOrigin().hashCode()) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final AssertStmt n, final Void arg) {
+ return (n.getCheck().accept(this, arg)) * 31 + (n.getMessage().isPresent() ? n.getMessage().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final AssignExpr n, final Void arg) {
+ return (n.getOperator().hashCode()) * 31 + (n.getTarget().accept(this, arg)) * 31 + (n.getValue().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final BinaryExpr n, final Void arg) {
+ return (n.getLeft().accept(this, arg)) * 31 + (n.getOperator().hashCode()) * 31 + (n.getRight().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final BlockComment n, final Void arg) {
+ return 0;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final BlockStmt n, final Void arg) {
+ return (n.getStatements().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final BooleanLiteralExpr n, final Void arg) {
+ return (n.getValue() ? 1 : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final BreakStmt n, final Void arg) {
+ return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final CastExpr n, final Void arg) {
+ return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final CatchClause n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getParameter().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final CharLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode());
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ClassExpr n, final Void arg) {
+ return (n.getType().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ClassOrInterfaceDeclaration n, final Void arg) {
+ 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().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ClassOrInterfaceType n, final Void arg) {
+ 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));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final CompilationUnit n, final Void arg) {
+ 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));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ConditionalExpr n, final Void arg) {
+ return (n.getCondition().accept(this, arg)) * 31 + (n.getElseExpr().accept(this, arg)) * 31 + (n.getThenExpr().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ConstructorDeclaration n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 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));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ContinueStmt n, final Void arg) {
+ return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final DoStmt n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final DoubleLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode());
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final EmptyStmt n, final Void arg) {
+ return 0;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final EnclosedExpr n, final Void arg) {
+ return (n.getInner().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final EnumConstantDeclaration n, final Void arg) {
+ return (n.getArguments().accept(this, arg)) * 31 + (n.getClassBody().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final EnumDeclaration n, final Void arg) {
+ return (n.getEntries().accept(this, arg)) * 31 + (n.getImplementedTypes().accept(this, arg)) * 31 + (n.getMembers().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ExplicitConstructorInvocationStmt n, final Void arg) {
+ 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);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ExpressionStmt n, final Void arg) {
+ return (n.getExpression().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final FieldAccessExpr n, final Void arg) {
+ return (n.getName().accept(this, arg)) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final FieldDeclaration n, final Void arg) {
+ return (n.getModifiers().hashCode()) * 31 + (n.getVariables().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ForStmt n, final Void arg) {
+ 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));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ForeachStmt n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getIterable().accept(this, arg)) * 31 + (n.getVariable().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final IfStmt n, final Void arg) {
+ return (n.getCondition().accept(this, arg)) * 31 + (n.getElseStmt().isPresent() ? n.getElseStmt().get().accept(this, arg) : 0) * 31 + (n.getThenStmt().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ImportDeclaration n, final Void arg) {
+ return (n.isAsterisk() ? 1 : 0) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final InitializerDeclaration n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.isStatic() ? 1 : 0) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final InstanceOfExpr n, final Void arg) {
+ return (n.getExpression().accept(this, arg)) * 31 + (n.getType().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final IntegerLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode());
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final IntersectionType n, final Void arg) {
+ return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final JavadocComment n, final Void arg) {
+ return 0;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final LabeledStmt n, final Void arg) {
+ return (n.getLabel().accept(this, arg)) * 31 + (n.getStatement().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final LambdaExpr n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.isEnclosingParameters() ? 1 : 0) * 31 + (n.getParameters().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final LineComment n, final Void arg) {
+ return 0;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final LocalClassDeclarationStmt n, final Void arg) {
+ return (n.getClassDeclaration().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final LongLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode());
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final MarkerAnnotationExpr n, final Void arg) {
+ return (n.getName().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final MemberValuePair n, final Void arg) {
+ return (n.getName().accept(this, arg)) * 31 + (n.getValue().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final MethodCallExpr n, final Void arg) {
+ 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);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final MethodDeclaration n, final Void arg) {
+ return (n.getBody().isPresent() ? n.getBody().get().accept(this, arg) : 0) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 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));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final MethodReferenceExpr n, final Void arg) {
+ return (n.getIdentifier().hashCode()) * 31 + (n.getScope().accept(this, arg)) * 31 + (n.getTypeArguments().isPresent() ? n.getTypeArguments().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final NameExpr n, final Void arg) {
+ return (n.getName().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final Name n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getIdentifier().hashCode()) * 31 + (n.getQualifier().isPresent() ? n.getQualifier().get().accept(this, arg) : 0);
+ }
+
+ public Integer visit(NodeList n, Void arg) {
+ int result = 0;
+ for (Object node : n) {
+ result += 31 * ((Visitable) node).accept(this, arg);
+ }
+ return result;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final NormalAnnotationExpr n, final Void arg) {
+ return (n.getPairs().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final NullLiteralExpr n, final Void arg) {
+ return 0;
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ObjectCreationExpr n, final Void arg) {
+ 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);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final PackageDeclaration n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final Parameter n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.isVarArgs() ? 1 : 0) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg)) * 31 + (n.getVarArgsAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final PrimitiveType n, final Void arg) {
+ return (n.getType().hashCode()) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ReturnStmt n, final Void arg) {
+ return (n.getExpression().isPresent() ? n.getExpression().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final SimpleName n, final Void arg) {
+ return (n.getIdentifier().hashCode());
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final SingleMemberAnnotationExpr n, final Void arg) {
+ return (n.getMemberValue().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final StringLiteralExpr n, final Void arg) {
+ return (n.getValue().hashCode());
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final SuperExpr n, final Void arg) {
+ return (n.getClassExpr().isPresent() ? n.getClassExpr().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final SwitchEntryStmt n, final Void arg) {
+ return (n.getLabel().isPresent() ? n.getLabel().get().accept(this, arg) : 0) * 31 + (n.getStatements().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final SwitchStmt n, final Void arg) {
+ return (n.getEntries().accept(this, arg)) * 31 + (n.getSelector().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final SynchronizedStmt n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getExpression().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ThisExpr n, final Void arg) {
+ return (n.getClassExpr().isPresent() ? n.getClassExpr().get().accept(this, arg) : 0);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ThrowStmt n, final Void arg) {
+ return (n.getExpression().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final TryStmt n, final Void arg) {
+ 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));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final TypeExpr n, final Void arg) {
+ return (n.getType().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final TypeParameter n, final Void arg) {
+ return (n.getName().accept(this, arg)) * 31 + (n.getTypeBound().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final UnaryExpr n, final Void arg) {
+ return (n.getExpression().accept(this, arg)) * 31 + (n.getOperator().hashCode());
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final UnionType n, final Void arg) {
+ return (n.getElements().accept(this, arg)) * 31 + (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final UnknownType n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final VariableDeclarationExpr n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getModifiers().hashCode()) * 31 + (n.getVariables().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final VariableDeclarator n, final Void arg) {
+ return (n.getInitializer().isPresent() ? n.getInitializer().get().accept(this, arg) : 0) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final VoidType n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final WhileStmt n, final Void arg) {
+ return (n.getBody().accept(this, arg)) * 31 + (n.getCondition().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final WildcardType n, final Void arg) {
+ 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));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ModuleDeclaration n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.isOpen() ? 1 : 0) * 31 + (n.getModuleStmts().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ModuleRequiresStmt n, final Void arg) {
+ return (n.getModifiers().hashCode()) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ModuleExportsStmt n, final Void arg) {
+ return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ModuleProvidesStmt n, final Void arg) {
+ return (n.getType().accept(this, arg)) * 31 + (n.getWithTypes().accept(this, arg));
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ModuleUsesStmt n, final Void arg) {
+ return (n.getType().accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ModuleOpensStmt n, final Void arg) {
+ return (n.getModuleNames().accept(this, arg)) * 31 + (n.getName().accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final UnparsableStmt n, final Void arg) {
+ return 0;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.NoCommentHashCodeVisitorGenerator")
+ public Integer visit(final ReceiverParameter n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg)) * 31 + (n.getName().accept(this, arg)) * 31 + (n.getType().accept(this, arg));
+ }
+
+ @Override
+ public Integer visit(final VarType n, final Void arg) {
+ return (n.getAnnotations().accept(this, arg));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java
new file mode 100644
index 000000000..7c642bbdb
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityEqualsVisitor.java
@@ -0,0 +1,596 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that calculates deep node equality by comparing all properties and child nodes of the node.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public class ObjectIdentityEqualsVisitor implements GenericVisitor<Boolean, Visitable> {
+
+ private static final ObjectIdentityEqualsVisitor SINGLETON = new ObjectIdentityEqualsVisitor();
+
+ public static boolean equals(final Node n, final Node n2) {
+ return n.accept(SINGLETON, n2);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final CompilationUnit n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final PackageDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final TypeParameter n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final LineComment n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final BlockComment n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ClassOrInterfaceDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final EnumDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final EnumConstantDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final AnnotationDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final AnnotationMemberDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final FieldDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final VariableDeclarator n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ConstructorDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final MethodDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final Parameter n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final InitializerDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final JavadocComment n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ClassOrInterfaceType n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final PrimitiveType n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ArrayType n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ArrayCreationLevel n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final IntersectionType n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final UnionType n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final VoidType n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final WildcardType n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final UnknownType n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ArrayAccessExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ArrayCreationExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ArrayInitializerExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final AssignExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final BinaryExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final CastExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ClassExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ConditionalExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final EnclosedExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final FieldAccessExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final InstanceOfExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final StringLiteralExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final IntegerLiteralExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final LongLiteralExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final CharLiteralExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final DoubleLiteralExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final BooleanLiteralExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final NullLiteralExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final MethodCallExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final NameExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ObjectCreationExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final Name n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final SimpleName n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ThisExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final SuperExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final UnaryExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final VariableDeclarationExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final MarkerAnnotationExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final SingleMemberAnnotationExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final NormalAnnotationExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final MemberValuePair n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ExplicitConstructorInvocationStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final LocalClassDeclarationStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final AssertStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final BlockStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final LabeledStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final EmptyStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ExpressionStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final SwitchStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final SwitchEntryStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final BreakStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ReturnStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final IfStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final WhileStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ContinueStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final DoStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ForeachStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ForStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ThrowStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final SynchronizedStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final TryStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final CatchClause n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final LambdaExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final MethodReferenceExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final TypeExpr n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ImportDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ public Boolean visit(NodeList n, Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ModuleDeclaration n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ModuleRequiresStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ModuleExportsStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ModuleProvidesStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ModuleUsesStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ModuleOpensStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final UnparsableStmt n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityEqualsVisitorGenerator")
+ public Boolean visit(final ReceiverParameter n, final Visitable arg) {
+ return n == arg;
+ }
+
+ @Override
+ public Boolean visit(final VarType n, final Visitable arg) {
+ return n == arg;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java
new file mode 100644
index 000000000..c53cf79a8
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/ObjectIdentityHashCodeVisitor.java
@@ -0,0 +1,510 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that calculates a deep hash code for a node by using the hash codes of all its properties,
+ * and the hash codes of all its child nodes (by visiting those too.)
+ */
+public class ObjectIdentityHashCodeVisitor implements GenericVisitor<Integer, Void> {
+
+ private static final ObjectIdentityHashCodeVisitor SINGLETON = new ObjectIdentityHashCodeVisitor();
+
+ public static int hashCode(final Node node) {
+ return node.accept(SINGLETON, null);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final AnnotationDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final AnnotationMemberDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ArrayAccessExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ArrayCreationExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ArrayCreationLevel n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ArrayInitializerExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ArrayType n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final AssertStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final AssignExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final BinaryExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final BlockComment n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final BlockStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final BooleanLiteralExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final BreakStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final CastExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final CatchClause n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final CharLiteralExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ClassExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ClassOrInterfaceDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ClassOrInterfaceType n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final CompilationUnit n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ConditionalExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ConstructorDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ContinueStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final DoStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final DoubleLiteralExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final EmptyStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final EnclosedExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final EnumConstantDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final EnumDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ExplicitConstructorInvocationStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ExpressionStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final FieldAccessExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final FieldDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ForStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ForeachStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final IfStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ImportDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final InitializerDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final InstanceOfExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final IntegerLiteralExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final IntersectionType n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final JavadocComment n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final LabeledStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final LambdaExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final LineComment n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final LocalClassDeclarationStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final LongLiteralExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final MarkerAnnotationExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final MemberValuePair n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final MethodCallExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final MethodDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final MethodReferenceExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final NameExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final Name n, final Void arg) {
+ return n.hashCode();
+ }
+
+ public Integer visit(NodeList n, Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final NormalAnnotationExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final NullLiteralExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ObjectCreationExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final PackageDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final Parameter n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final PrimitiveType n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ReturnStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final SimpleName n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final SingleMemberAnnotationExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final StringLiteralExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final SuperExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final SwitchEntryStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final SwitchStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final SynchronizedStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ThisExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ThrowStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final TryStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final TypeExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final TypeParameter n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final UnaryExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final UnionType n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final UnknownType n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final VariableDeclarationExpr n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final VariableDeclarator n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final VoidType n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final WhileStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final WildcardType n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ModuleDeclaration n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ModuleRequiresStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ModuleExportsStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ModuleProvidesStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Override()
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ModuleUsesStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ModuleOpensStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final UnparsableStmt n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.ObjectIdentityHashCodeVisitorGenerator")
+ public Integer visit(final ReceiverParameter n, final Void arg) {
+ return n.hashCode();
+ }
+
+ @Override
+ public Integer visit(final VarType n, final Void arg) {
+ return n.hashCode();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeVisitor.java
new file mode 100644
index 000000000..3c4aecd9f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/TreeVisitor.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.Node;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * Iterate over all the nodes in (a part of) the AST. In contrast to the visit methods in Node, these methods are
+ * implemented in a simple recursive way which should be more efficient. A disadvantage is that they cannot be quit in
+ * the middle of their traversal.
+ */
+public abstract class TreeVisitor {
+
+ public void visitLeavesFirst(Node node) {
+ for (Node child : node.getChildNodes()) {
+ visitLeavesFirst(child);
+ }
+ process(node);
+ }
+
+ /**
+ * Performs a pre-order node traversal starting with a given node. When each node is visited, {@link #process(Node)}
+ * is called for further processing.
+ *
+ * @param node The node at which the traversal begins.
+ * @see <a href="https://en.wikipedia.org/wiki/Pre-order">Pre-order traversal</a>
+ */
+ public void visitPreOrder(Node node) {
+ process(node);
+ new ArrayList<>(node.getChildNodes()).forEach(this::visitPreOrder);
+ }
+
+ /**
+ * Performs a post-order node traversal starting with a given node. When each node is visited, {@link
+ * #process(Node)} is called for further processing.
+ *
+ * @param node The node at which the traversal begins.
+ * @see <a href="https://en.wikipedia.org/wiki/Post-order">Post-order traversal</a>
+ */
+ public void visitPostOrder(Node node) {
+ new ArrayList<>(node.getChildNodes()).forEach(this::visitPostOrder);
+ process(node);
+ }
+
+ /**
+ * Performs a pre-order node traversal starting with a given node. When each node is visited, {@link #process(Node)}
+ * is called for further processing.
+ *
+ * @param node The node at which the traversal begins.
+ * @see <a href="https://en.wikipedia.org/wiki/Pre-order">Pre-order traversal</a>
+ * @deprecated As of release 3.1.0, replaced by {@link #visitPreOrder(Node)}
+ */
+ @Deprecated
+ public void visitDepthFirst(Node node) {
+ visitPreOrder(node);
+ }
+
+ /**
+ * https://en.wikipedia.org/wiki/Breadth-first_search
+ *
+ * @param node the start node, and the first one that is passed to process(node).
+ */
+ public void visitBreadthFirst(Node node) {
+ final Queue<Node> queue = new LinkedList<>();
+ queue.offer(node);
+ while (queue.size() > 0) {
+ final Node head = queue.peek();
+ for (Node child : head.getChildNodes()) {
+ queue.offer(child);
+ }
+ process(queue.poll());
+ }
+ }
+
+ /**
+ * Process the given node.
+ *
+ * @param node The current node to process.
+ */
+ public abstract void process(Node node);
+
+ /**
+ * Performs a simple traversal over all nodes that have the passed node as their parent.
+ */
+ public void visitDirectChildren(Node node) {
+ new ArrayList<>(node.getChildNodes()).forEach(this::process);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/Visitable.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/Visitable.java
new file mode 100644
index 000000000..32c01a134
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/Visitable.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.ast.visitor;
+
+public interface Visitable {
+ /**
+ * Accept method for visitor support.
+ *
+ * @param <R> the type of the return value of the visitor
+ * @param <A> the type the user argument passed to the visitor
+ * @param v the visitor implementation
+ * @param arg the argument passed to the visitor (of type A)
+ * @return the result of the visit (of type R)
+ */
+ <R, A> R accept(GenericVisitor<R, A> v, A arg);
+
+ /**
+ * Accept method for visitor support.
+ *
+ * @param <A> the type the argument passed for the visitor
+ * @param v the visitor implementation
+ * @param arg any value relevant for the visitor (of type A)
+ */
+ <A> void accept(VoidVisitor<A> v, A arg);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java
new file mode 100644
index 000000000..37c9c1c3b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitor.java
@@ -0,0 +1,314 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that does not return anything.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public interface VoidVisitor<A> {
+
+ void visit(NodeList n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(AnnotationDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(AnnotationMemberDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ArrayAccessExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ArrayCreationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ArrayCreationLevel n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ArrayInitializerExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ArrayType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(AssertStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(AssignExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(BinaryExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(BlockComment n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(BlockStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(BooleanLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(BreakStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(CastExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(CatchClause n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(CharLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ClassExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ClassOrInterfaceDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ClassOrInterfaceType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(CompilationUnit n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ConditionalExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ConstructorDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ContinueStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(DoStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(DoubleLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(EmptyStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(EnclosedExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(EnumConstantDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(EnumDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ExplicitConstructorInvocationStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ExpressionStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(FieldAccessExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(FieldDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ForStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ForeachStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(IfStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ImportDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(InitializerDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(InstanceOfExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(IntegerLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(IntersectionType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(JavadocComment n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(LabeledStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(LambdaExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(LineComment n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(LocalClassDeclarationStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(LongLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(MarkerAnnotationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(MemberValuePair n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(MethodCallExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(MethodDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(MethodReferenceExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(NameExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(Name n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(NormalAnnotationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(NullLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ObjectCreationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(PackageDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(Parameter n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(PrimitiveType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ReturnStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(SimpleName n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(SingleMemberAnnotationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(StringLiteralExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(SuperExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(SwitchEntryStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(SwitchStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(SynchronizedStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ThisExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ThrowStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(TryStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(TypeExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(TypeParameter n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(UnaryExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(UnionType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(UnknownType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(VariableDeclarationExpr n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(VariableDeclarator n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(VoidType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(WhileStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(WildcardType n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ModuleDeclaration n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ModuleRequiresStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ModuleExportsStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ModuleProvidesStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ModuleUsesStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ModuleOpensStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(UnparsableStmt n, A arg);
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorGenerator")
+ void visit(ReceiverParameter n, A arg);
+
+ void visit(VarType n, A arg);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java
new file mode 100644
index 000000000..1ee82669a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorAdapter.java
@@ -0,0 +1,773 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that returns nothing, and has a default implementation for all its visit
+ * methods that simply visit their children in an unspecified order.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public abstract class VoidVisitorAdapter<A> implements VoidVisitor<A> {
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final AnnotationDeclaration n, final A arg) {
+ n.getMembers().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final AnnotationMemberDeclaration n, final A arg) {
+ n.getDefaultValue().ifPresent(l -> l.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getType().accept(this, arg);
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ArrayAccessExpr n, final A arg) {
+ n.getIndex().accept(this, arg);
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ArrayCreationExpr n, final A arg) {
+ n.getElementType().accept(this, arg);
+ n.getInitializer().ifPresent(l -> l.accept(this, arg));
+ n.getLevels().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ArrayInitializerExpr n, final A arg) {
+ n.getValues().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final AssertStmt n, final A arg) {
+ n.getCheck().accept(this, arg);
+ n.getMessage().ifPresent(l -> l.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final AssignExpr n, final A arg) {
+ n.getTarget().accept(this, arg);
+ n.getValue().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final BinaryExpr n, final A arg) {
+ n.getLeft().accept(this, arg);
+ n.getRight().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final BlockComment n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final BlockStmt n, final A arg) {
+ n.getStatements().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final BooleanLiteralExpr n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final BreakStmt n, final A arg) {
+ n.getLabel().ifPresent(l -> l.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final CastExpr n, final A arg) {
+ n.getExpression().accept(this, arg);
+ n.getType().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final CatchClause n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getParameter().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final CharLiteralExpr n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ClassExpr n, final A arg) {
+ n.getType().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ClassOrInterfaceDeclaration n, final A arg) {
+ n.getExtendedTypes().forEach(p -> p.accept(this, arg));
+ n.getImplementedTypes().forEach(p -> p.accept(this, arg));
+ n.getTypeParameters().forEach(p -> p.accept(this, arg));
+ n.getMembers().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ClassOrInterfaceType n, final A arg) {
+ n.getName().accept(this, arg);
+ n.getScope().ifPresent(l -> l.accept(this, arg));
+ n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final CompilationUnit n, final A arg) {
+ n.getImports().forEach(p -> p.accept(this, arg));
+ n.getModule().ifPresent(l -> l.accept(this, arg));
+ n.getPackageDeclaration().ifPresent(l -> l.accept(this, arg));
+ n.getTypes().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ConditionalExpr n, final A arg) {
+ n.getCondition().accept(this, arg);
+ n.getElseExpr().accept(this, arg);
+ n.getThenExpr().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ConstructorDeclaration n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getName().accept(this, arg);
+ n.getParameters().forEach(p -> p.accept(this, arg));
+ n.getReceiverParameter().ifPresent(l -> l.accept(this, arg));
+ n.getThrownExceptions().forEach(p -> p.accept(this, arg));
+ n.getTypeParameters().forEach(p -> p.accept(this, arg));
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ContinueStmt n, final A arg) {
+ n.getLabel().ifPresent(l -> l.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final DoStmt n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getCondition().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final DoubleLiteralExpr n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final EmptyStmt n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final EnclosedExpr n, final A arg) {
+ n.getInner().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final EnumConstantDeclaration n, final A arg) {
+ n.getArguments().forEach(p -> p.accept(this, arg));
+ n.getClassBody().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final EnumDeclaration n, final A arg) {
+ n.getEntries().forEach(p -> p.accept(this, arg));
+ n.getImplementedTypes().forEach(p -> p.accept(this, arg));
+ n.getMembers().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ExplicitConstructorInvocationStmt n, final A arg) {
+ n.getArguments().forEach(p -> p.accept(this, arg));
+ n.getExpression().ifPresent(l -> l.accept(this, arg));
+ n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ExpressionStmt n, final A arg) {
+ n.getExpression().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final FieldAccessExpr n, final A arg) {
+ n.getName().accept(this, arg);
+ n.getScope().accept(this, arg);
+ n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final FieldDeclaration n, final A arg) {
+ n.getVariables().forEach(p -> p.accept(this, arg));
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ForeachStmt n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getIterable().accept(this, arg);
+ n.getVariable().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ForStmt n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getCompare().ifPresent(l -> l.accept(this, arg));
+ n.getInitialization().forEach(p -> p.accept(this, arg));
+ n.getUpdate().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final IfStmt n, final A arg) {
+ n.getCondition().accept(this, arg);
+ n.getElseStmt().ifPresent(l -> l.accept(this, arg));
+ n.getThenStmt().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final InitializerDeclaration n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final InstanceOfExpr n, final A arg) {
+ n.getExpression().accept(this, arg);
+ n.getType().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final IntegerLiteralExpr n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final JavadocComment n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final LabeledStmt n, final A arg) {
+ n.getLabel().accept(this, arg);
+ n.getStatement().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final LineComment n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final LongLiteralExpr n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final MarkerAnnotationExpr n, final A arg) {
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final MemberValuePair n, final A arg) {
+ n.getName().accept(this, arg);
+ n.getValue().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final MethodCallExpr n, final A arg) {
+ n.getArguments().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getScope().ifPresent(l -> l.accept(this, arg));
+ n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final MethodDeclaration n, final A arg) {
+ n.getBody().ifPresent(l -> l.accept(this, arg));
+ n.getType().accept(this, arg);
+ n.getName().accept(this, arg);
+ n.getParameters().forEach(p -> p.accept(this, arg));
+ n.getReceiverParameter().ifPresent(l -> l.accept(this, arg));
+ n.getThrownExceptions().forEach(p -> p.accept(this, arg));
+ n.getTypeParameters().forEach(p -> p.accept(this, arg));
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final NameExpr n, final A arg) {
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final NormalAnnotationExpr n, final A arg) {
+ n.getPairs().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final NullLiteralExpr n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ObjectCreationExpr n, final A arg) {
+ n.getAnonymousClassBody().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
+ n.getArguments().forEach(p -> p.accept(this, arg));
+ n.getScope().ifPresent(l -> l.accept(this, arg));
+ n.getType().accept(this, arg);
+ n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final PackageDeclaration n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final Parameter n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getType().accept(this, arg);
+ n.getVarArgsAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final PrimitiveType n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final Name n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getQualifier().ifPresent(l -> l.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final SimpleName n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ArrayType n, final A arg) {
+ n.getComponentType().accept(this, arg);
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ArrayCreationLevel n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getDimension().ifPresent(l -> l.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final IntersectionType n, final A arg) {
+ n.getElements().forEach(p -> p.accept(this, arg));
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final UnionType n, final A arg) {
+ n.getElements().forEach(p -> p.accept(this, arg));
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ReturnStmt n, final A arg) {
+ n.getExpression().ifPresent(l -> l.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final SingleMemberAnnotationExpr n, final A arg) {
+ n.getMemberValue().accept(this, arg);
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final StringLiteralExpr n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final SuperExpr n, final A arg) {
+ n.getClassExpr().ifPresent(l -> l.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final SwitchEntryStmt n, final A arg) {
+ n.getLabel().ifPresent(l -> l.accept(this, arg));
+ n.getStatements().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final SwitchStmt n, final A arg) {
+ n.getEntries().forEach(p -> p.accept(this, arg));
+ n.getSelector().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final SynchronizedStmt n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getExpression().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ThisExpr n, final A arg) {
+ n.getClassExpr().ifPresent(l -> l.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ThrowStmt n, final A arg) {
+ n.getExpression().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final TryStmt n, final A arg) {
+ n.getCatchClauses().forEach(p -> p.accept(this, arg));
+ n.getFinallyBlock().ifPresent(l -> l.accept(this, arg));
+ n.getResources().forEach(p -> p.accept(this, arg));
+ n.getTryBlock().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final LocalClassDeclarationStmt n, final A arg) {
+ n.getClassDeclaration().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final TypeParameter n, final A arg) {
+ n.getName().accept(this, arg);
+ n.getTypeBound().forEach(p -> p.accept(this, arg));
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final UnaryExpr n, final A arg) {
+ n.getExpression().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final UnknownType n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final VariableDeclarationExpr n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getVariables().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final VariableDeclarator n, final A arg) {
+ n.getInitializer().ifPresent(l -> l.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getType().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final VoidType n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final WhileStmt n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getCondition().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final WildcardType n, final A arg) {
+ n.getExtendedType().ifPresent(l -> l.accept(this, arg));
+ n.getSuperType().ifPresent(l -> l.accept(this, arg));
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final LambdaExpr n, final A arg) {
+ n.getBody().accept(this, arg);
+ n.getParameters().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final MethodReferenceExpr n, final A arg) {
+ n.getScope().accept(this, arg);
+ n.getTypeArguments().ifPresent(l -> l.forEach(v -> v.accept(this, arg)));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final TypeExpr n, final A arg) {
+ n.getType().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ public void visit(NodeList n, A arg) {
+ for (Object node : n) {
+ ((Node) node).accept(this, arg);
+ }
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ImportDeclaration n, final A arg) {
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ModuleDeclaration n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getModuleStmts().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ModuleRequiresStmt n, final A arg) {
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ModuleExportsStmt n, final A arg) {
+ n.getModuleNames().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ModuleProvidesStmt n, final A arg) {
+ n.getType().accept(this, arg);
+ n.getWithTypes().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ModuleUsesStmt n, final A arg) {
+ n.getType().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ModuleOpensStmt n, final A arg) {
+ n.getModuleNames().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final UnparsableStmt n, final A arg) {
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorAdapterGenerator")
+ public void visit(final ReceiverParameter n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getName().accept(this, arg);
+ n.getType().accept(this, arg);
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+
+ @Override
+ public void visit(final VarType n, final A arg) {
+ n.getAnnotations().forEach(p -> p.accept(this, arg));
+ n.getComment().ifPresent(l -> l.accept(this, arg));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java
new file mode 100644
index 000000000..6622567e6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/ast/visitor/VoidVisitorWithDefaults.java
@@ -0,0 +1,599 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.ast.visitor;
+
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import javax.annotation.Generated;
+
+/**
+ * A visitor that returns nothing, and has default methods that are used when a specific visit method is not
+ * overridden.
+ */
+public abstract class VoidVisitorWithDefaults<A> implements VoidVisitor<A> {
+
+ /**
+ * This will be called by every node visit method that is not overridden.
+ */
+ public void defaultAction(Node n, A arg) {
+ }
+
+ /**
+ * This will be called by the NodeList visit method when it is not overridden.
+ */
+ public void defaultAction(NodeList n, A arg) {
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final AnnotationDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final AnnotationMemberDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ArrayAccessExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ArrayCreationExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ArrayInitializerExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final AssertStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final AssignExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final BinaryExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final BlockComment n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final BlockStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final BooleanLiteralExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final BreakStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final CastExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final CatchClause n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final CharLiteralExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ClassExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ClassOrInterfaceDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ClassOrInterfaceType n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final CompilationUnit n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ConditionalExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ConstructorDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ContinueStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final DoStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final DoubleLiteralExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final EmptyStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final EnclosedExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final EnumConstantDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final EnumDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ExplicitConstructorInvocationStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ExpressionStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final FieldAccessExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final FieldDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ForeachStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ForStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final IfStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final InitializerDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final InstanceOfExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final IntegerLiteralExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final JavadocComment n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final LabeledStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final LineComment n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final LongLiteralExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final MarkerAnnotationExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final MemberValuePair n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final MethodCallExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final MethodDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final NameExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final NormalAnnotationExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final NullLiteralExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ObjectCreationExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final PackageDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final Parameter n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final PrimitiveType n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final Name n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final SimpleName n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ArrayType n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ArrayCreationLevel n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final IntersectionType n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final UnionType n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ReturnStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final SingleMemberAnnotationExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final StringLiteralExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final SuperExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final SwitchEntryStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final SwitchStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final SynchronizedStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ThisExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ThrowStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final TryStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final LocalClassDeclarationStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final TypeParameter n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final UnaryExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final UnknownType n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final VariableDeclarationExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final VariableDeclarator n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final VoidType n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final WhileStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final WildcardType n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final LambdaExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final MethodReferenceExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final TypeExpr n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ public void visit(NodeList n, A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ImportDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ModuleDeclaration n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ModuleRequiresStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ModuleExportsStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ModuleProvidesStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ModuleUsesStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ModuleOpensStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final UnparsableStmt n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ @Generated("com.github.javaparser.generator.core.visitor.VoidVisitorWithDefaultsGenerator")
+ public void visit(final ReceiverParameter n, final A arg) {
+ defaultAction(n, arg);
+ }
+
+ @Override
+ public void visit(final VarType n, final A arg) {
+ defaultAction(n, arg);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java
new file mode 100644
index 000000000..ba606c2f3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/Javadoc.java
@@ -0,0 +1,167 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.javadoc;
+
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.javadoc.description.JavadocDescription;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static com.github.javaparser.utils.Utils.*;
+
+/**
+ * The structured content of a single Javadoc comment.
+ * <p>
+ * It is composed by a description and a list of block tags.
+ * <p>
+ * An example would be the text contained in this very Javadoc comment. At the moment
+ * of this writing this comment does not contain any block tags (such as <code>@see AnotherClass</code>)
+ */
+public class Javadoc {
+
+ private JavadocDescription description;
+ private List<JavadocBlockTag> blockTags;
+
+ public Javadoc(JavadocDescription description) {
+ this.description = description;
+ this.blockTags = new LinkedList<>();
+ }
+
+ public Javadoc addBlockTag(JavadocBlockTag blockTag) {
+ this.blockTags.add(blockTag);
+ return this;
+ }
+
+ /**
+ * For tags like "@return good things" where
+ * tagName is "return",
+ * and the rest is content.
+ */
+ public Javadoc addBlockTag(String tagName, String content) {
+ return addBlockTag(new JavadocBlockTag(tagName, content));
+ }
+
+ /**
+ * For tags like "@param abc this is a parameter" where
+ * tagName is "param",
+ * parameter is "abc"
+ * and the rest is content.
+ */
+ public Javadoc addBlockTag(String tagName, String parameter, String content) {
+ return addBlockTag(tagName, parameter + " " + content);
+ }
+
+ public Javadoc addBlockTag(String tagName) {
+ return addBlockTag(tagName, "");
+ }
+
+ /**
+ * Return the text content of the document. It does not containing trailing spaces and asterisks
+ * at the start of the line.
+ */
+ public String toText() {
+ StringBuilder sb = new StringBuilder();
+ if (!description.isEmpty()) {
+ sb.append(description.toText());
+ sb.append(EOL);
+ }
+ if (!blockTags.isEmpty()) {
+ sb.append(EOL);
+ }
+ blockTags.forEach(bt -> {
+ sb.append(bt.toText());
+ sb.append(EOL);
+ });
+ return sb.toString();
+ }
+
+ /**
+ * Create a JavadocComment, by formatting the text of the Javadoc using no indentation (expecting the pretty printer to do the formatting.)
+ */
+ public JavadocComment toComment() {
+ return toComment("");
+ }
+
+ /**
+ * Create a JavadocComment, by formatting the text of the Javadoc using the given indentation.
+ */
+ public JavadocComment toComment(String indentation) {
+ for (char c : indentation.toCharArray()) {
+ if (!Character.isWhitespace(c)) {
+ throw new IllegalArgumentException("The indentation string should be composed only by whitespace characters");
+ }
+ }
+ StringBuilder sb = new StringBuilder();
+ sb.append(EOL);
+ final String text = toText();
+ if (!text.isEmpty()) {
+ for (String line : text.split(EOL)) {
+ sb.append(indentation);
+ sb.append(" * ");
+ sb.append(line);
+ sb.append(EOL);
+ }
+ }
+ sb.append(indentation);
+ sb.append(" ");
+ return new JavadocComment(sb.toString());
+ }
+
+ public JavadocDescription getDescription() {
+ return description;
+ }
+
+ /**
+ * @return the current List of associated JavadocBlockTags
+ */
+ public List<JavadocBlockTag> getBlockTags() {
+ return this.blockTags;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Javadoc document = (Javadoc) o;
+
+ return description.equals(document.description) && blockTags.equals(document.blockTags);
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result = description.hashCode();
+ result = 31 * result + blockTags.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "Javadoc{" +
+ "description=" + description +
+ ", blockTags=" + blockTags +
+ '}';
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java
new file mode 100644
index 000000000..f33993170
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/JavadocBlockTag.java
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.javadoc;
+
+import com.github.javaparser.javadoc.description.JavadocDescription;
+
+import java.util.Optional;
+
+import static com.github.javaparser.utils.Utils.nextWord;
+import static com.github.javaparser.utils.Utils.screamingToCamelCase;
+
+/**
+ * A block tag.
+ * <p>
+ * Typically they are found at the end of Javadoc comments.
+ * <p>
+ * Examples:
+ * <code>@see AnotherClass</code>
+ * <code>@since v0.0.1</code>
+ * <code>@author Jim O'Java</code>
+ */
+public class JavadocBlockTag {
+
+ /**
+ * The type of tag: it could either correspond to a known tag (param, return, etc.) or represent
+ * an unknown tag.
+ */
+ public enum Type {
+ AUTHOR,
+ DEPRECATED,
+ EXCEPTION,
+ PARAM,
+ RETURN,
+ SEE,
+ SERIAL,
+ SERIAL_DATA,
+ SERIAL_FIELD,
+ SINCE,
+ THROWS,
+ VERSION,
+ UNKNOWN;
+
+ Type() {
+ this.keyword = screamingToCamelCase(name());
+ }
+
+ private String keyword;
+
+ boolean hasName() {
+ return this == PARAM;
+ }
+
+ static Type fromName(String tagName) {
+ for (Type t : Type.values()) {
+ if (t.keyword.equals(tagName)) {
+ return t;
+ }
+ }
+ return UNKNOWN;
+ }
+
+ }
+
+ private Type type;
+ private JavadocDescription content;
+ private Optional<String> name = Optional.empty();
+ private String tagName;
+
+ public JavadocBlockTag(Type type, String content) {
+ this.type = type;
+ this.tagName = type.keyword;
+ if (type.hasName()) {
+ this.name = Optional.of(nextWord(content));
+ content = content.substring(this.name.get().length()).trim();
+ }
+ this.content = JavadocDescription.parseText(content);
+ }
+
+ public JavadocBlockTag(String tagName, String content) {
+ this(Type.fromName(tagName), content);
+ this.tagName = tagName;
+ }
+
+ public static JavadocBlockTag createParamBlockTag(String paramName, String content) {
+ return new JavadocBlockTag(Type.PARAM, paramName + " " + content);
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public JavadocDescription getContent() {
+ return content;
+ }
+
+ public Optional<String> getName() {
+ return name;
+ }
+
+ public String getTagName() {
+ return tagName;
+ }
+
+ public String toText() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("@");
+ sb.append(tagName);
+ name.ifPresent(s -> sb.append(" ").append(s));
+ if (!content.isEmpty()) {
+ sb.append(" ");
+ sb.append(content.toText());
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ JavadocBlockTag that = (JavadocBlockTag) o;
+
+ if (type != that.type) return false;
+ if (!content.equals(that.content)) return false;
+ return name.equals(that.name);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = type.hashCode();
+ result = 31 * result + content.hashCode();
+ result = 31 * result + name.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "JavadocBlockTag{" +
+ "type=" + type +
+ ", content='" + content + '\'' +
+ ", name=" + name +
+ '}';
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java
new file mode 100644
index 000000000..82f818a98
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescription.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.javadoc.description;
+
+import com.github.javaparser.utils.Pair;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * A javadoc text, potentially containing inline tags.
+ *
+ * For example <code>This class is totally unrelated to {@link com.github.javaparser.Range}</code>
+ */
+public class JavadocDescription {
+
+ private List<JavadocDescriptionElement> elements;
+
+ public static JavadocDescription parseText(String text) {
+ JavadocDescription instance = new JavadocDescription();
+ int index = 0;
+ Pair<Integer, Integer> nextInlineTagPos;
+ while ((nextInlineTagPos = indexOfNextInlineTag(text, index)) != null) {
+ if (nextInlineTagPos.a != index) {
+ instance.addElement(new JavadocSnippet(text.substring(index, nextInlineTagPos.a + 1)));
+ }
+ instance.addElement(JavadocInlineTag.fromText(text.substring(nextInlineTagPos.a, nextInlineTagPos.b + 1)));
+ index = nextInlineTagPos.b;
+ }
+ if (index < text.length()) {
+ instance.addElement(new JavadocSnippet(text.substring(index)));
+ }
+ return instance;
+ }
+
+ private static Pair<Integer, Integer> indexOfNextInlineTag(String text, int start) {
+ int index = text.indexOf("{@", start);
+ if (index == -1) {
+ return null;
+ }
+ // we are interested only in complete inline tags
+ int closeIndex = text.indexOf("}", index);
+ if (closeIndex == -1) {
+ return null;
+ }
+ return new Pair<>(index, closeIndex);
+ }
+
+ public JavadocDescription() {
+ elements = new LinkedList<>();
+ }
+
+ public JavadocDescription(List<JavadocDescriptionElement> elements) {
+ this();
+
+ this.elements.addAll(elements);
+ }
+
+ public boolean addElement(JavadocDescriptionElement element) {
+ return this.elements.add(element);
+ }
+
+ public List<JavadocDescriptionElement> getElements() {
+ return this.elements;
+ }
+
+ public String toText() {
+ StringBuilder sb = new StringBuilder();
+ elements.forEach(e -> sb.append(e.toText()));
+ return sb.toString();
+ }
+
+ public boolean isEmpty() {
+ return toText().isEmpty();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ JavadocDescription that = (JavadocDescription) o;
+
+ return elements.equals(that.elements);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return elements.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "JavadocDescription{" +
+ "elements=" + elements +
+ '}';
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java
new file mode 100644
index 000000000..3d75b6c02
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocDescriptionElement.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.javadoc.description;
+
+/**
+ * An element of a description: either an inline tag or a piece of text.
+ * <p>
+ * So for example <code>a text</code> or <code>{@link String}</code> could be valid description elements.
+ */
+public interface JavadocDescriptionElement {
+ String toText();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java
new file mode 100644
index 000000000..8125bd510
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocInlineTag.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2017 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.javadoc.description;
+
+import static com.github.javaparser.utils.Utils.nextWord;
+import static com.github.javaparser.utils.Utils.screamingToCamelCase;
+
+/**
+ * An inline tag contained in a Javadoc description.
+ * <p>
+ * For example <code>{@link String}</code>
+ */
+public class JavadocInlineTag implements JavadocDescriptionElement {
+
+ public static JavadocDescriptionElement fromText(String text) {
+ if (!text.startsWith("{@")) {
+ throw new IllegalArgumentException(String.format("Expected to start with '{@'. Text '%s'", text));
+ }
+ if (!text.endsWith("}")) {
+ throw new IllegalArgumentException(String.format("Expected to end with '}'. Text '%s'", text));
+ }
+ text = text.substring(2, text.length() - 1);
+ String tagName = nextWord(text);
+ Type type = Type.fromName(tagName);
+ String content = text.substring(tagName.length());
+ return new JavadocInlineTag(tagName, type, content);
+ }
+
+ /**
+ * The type of tag: it could either correspond to a known tag (code, docRoot, etc.) or represent
+ * an unknown tag.
+ */
+ public enum Type {
+ CODE,
+ DOC_ROOT,
+ INHERIT_DOC,
+ LINK,
+ LINKPLAIN,
+ LITERAL,
+ VALUE,
+ UNKNOWN;
+
+ Type() {
+ this.keyword = screamingToCamelCase(name());
+ }
+
+ private String keyword;
+
+ static JavadocInlineTag.Type fromName(String tagName) {
+ for (JavadocInlineTag.Type t : JavadocInlineTag.Type.values()) {
+ if (t.keyword.equals(tagName)) {
+ return t;
+ }
+ }
+ return UNKNOWN;
+ }
+
+ }
+
+ private String tagName;
+ private Type type;
+ private String content;
+
+ public JavadocInlineTag(String tagName, Type type, String content) {
+ this.tagName = tagName;
+ this.type = type;
+ this.content = content;
+ }
+
+ @Override
+ public String toText() {
+ return "@" + tagName + this.content;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ JavadocInlineTag that = (JavadocInlineTag) o;
+
+ if (tagName != null ? !tagName.equals(that.tagName) : that.tagName != null) return false;
+ if (type != that.type) return false;
+ return content != null ? content.equals(that.content) : that.content == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = tagName != null ? tagName.hashCode() : 0;
+ result = 31 * result + (type != null ? type.hashCode() : 0);
+ result = 31 * result + (content != null ? content.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "JavadocInlineTag{" +
+ "tagName='" + tagName + '\'' +
+ ", type=" + type +
+ ", content='" + content + '\'' +
+ '}';
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java
new file mode 100644
index 000000000..50b32cb31
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/javadoc/description/JavadocSnippet.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.javadoc.description;
+
+/**
+ * A piece of text inside a Javadoc description.
+ * <p>
+ * For example in <code>A class totally unrelated to {@link String}, I swear!</code> we would have two snippets: one
+ * before and one after the inline tag (<code>{@link String}</code>).
+ */
+public class JavadocSnippet implements JavadocDescriptionElement {
+ private String text;
+
+ public JavadocSnippet(String text) {
+ if (text == null) {
+ throw new NullPointerException();
+ }
+ this.text = text;
+ }
+
+ @Override
+ public String toText() {
+ return this.text;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ JavadocSnippet that = (JavadocSnippet) o;
+
+ return text.equals(that.text);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return text.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "JavadocSnippet{" +
+ "text='" + text + '\'' +
+ '}';
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java
new file mode 100644
index 000000000..e4a7fdc9f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationDeclarationMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class AnnotationDeclarationMetaModel extends TypeDeclarationMetaModel {
+
+ AnnotationDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.AnnotationDeclaration.class, "AnnotationDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationExprMetaModel.java
new file mode 100644
index 000000000..f4e892aca
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationExprMetaModel.java
@@ -0,0 +1,17 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class AnnotationExprMetaModel extends ExpressionMetaModel {
+
+ AnnotationExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.AnnotationExpr.class, "AnnotationExpr", "com.github.javaparser.ast.expr", true, false);
+ }
+
+ protected AnnotationExprMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java
new file mode 100644
index 000000000..d15b967c1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AnnotationMemberDeclarationMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class AnnotationMemberDeclarationMetaModel extends BodyDeclarationMetaModel {
+
+ AnnotationMemberDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.AnnotationMemberDeclaration.class, "AnnotationMemberDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel defaultValuePropertyMetaModel;
+
+ public PropertyMetaModel modifiersPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java
new file mode 100644
index 000000000..b6dd15777
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayAccessExprMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ArrayAccessExprMetaModel extends ExpressionMetaModel {
+
+ ArrayAccessExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ArrayAccessExpr.class, "ArrayAccessExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel indexPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java
new file mode 100644
index 000000000..a120f3428
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationExprMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ArrayCreationExprMetaModel extends ExpressionMetaModel {
+
+ ArrayCreationExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ArrayCreationExpr.class, "ArrayCreationExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel elementTypePropertyMetaModel;
+
+ public PropertyMetaModel initializerPropertyMetaModel;
+
+ public PropertyMetaModel levelsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java
new file mode 100644
index 000000000..b99f92ea5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayCreationLevelMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ArrayCreationLevelMetaModel extends NodeMetaModel {
+
+ ArrayCreationLevelMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.ArrayCreationLevel.class, "ArrayCreationLevel", "com.github.javaparser.ast", false, false);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+
+ public PropertyMetaModel dimensionPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayInitializerExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayInitializerExprMetaModel.java
new file mode 100644
index 000000000..685910f0c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayInitializerExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ArrayInitializerExprMetaModel extends ExpressionMetaModel {
+
+ ArrayInitializerExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ArrayInitializerExpr.class, "ArrayInitializerExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel valuesPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayTypeMetaModel.java
new file mode 100644
index 000000000..58f3f621a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ArrayTypeMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ArrayTypeMetaModel extends ReferenceTypeMetaModel {
+
+ ArrayTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.ArrayType.class, "ArrayType", "com.github.javaparser.ast.type", false, false);
+ }
+
+ public PropertyMetaModel componentTypePropertyMetaModel;
+
+ public PropertyMetaModel originPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AssertStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AssertStmtMetaModel.java
new file mode 100644
index 000000000..c250832f0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AssertStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class AssertStmtMetaModel extends StatementMetaModel {
+
+ AssertStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.AssertStmt.class, "AssertStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel checkPropertyMetaModel;
+
+ public PropertyMetaModel messagePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/AssignExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AssignExprMetaModel.java
new file mode 100644
index 000000000..8a0de9a31
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/AssignExprMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class AssignExprMetaModel extends ExpressionMetaModel {
+
+ AssignExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.AssignExpr.class, "AssignExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel operatorPropertyMetaModel;
+
+ public PropertyMetaModel targetPropertyMetaModel;
+
+ public PropertyMetaModel valuePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java
new file mode 100644
index 000000000..86e53fdb9
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BaseNodeMetaModel.java
@@ -0,0 +1,180 @@
+package com.github.javaparser.metamodel;
+
+import com.github.javaparser.ast.Node;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+import static com.github.javaparser.utils.Utils.decapitalize;
+
+/**
+ * Meta-data about all classes in the AST. These are all Nodes, except NodeList.
+ */
+public abstract class BaseNodeMetaModel {
+ private final Optional<BaseNodeMetaModel> superNodeMetaModel;
+ private final List<PropertyMetaModel> declaredPropertyMetaModels = new ArrayList<>();
+ private final List<PropertyMetaModel> derivedPropertyMetaModels = new ArrayList<>();
+ private final List<PropertyMetaModel> constructorParameters = new ArrayList<>();
+ private final Class<? extends Node> type;
+ private final String name;
+ private final String packageName;
+ private final boolean isAbstract;
+ private final boolean hasWildcard;
+
+ public BaseNodeMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ this.superNodeMetaModel = superNodeMetaModel;
+ this.type = type;
+ this.name = name;
+ this.packageName = packageName;
+ this.isAbstract = isAbstract;
+ this.hasWildcard = hasWildcard;
+ }
+
+ /**
+ * @return is this the meta model for this node class?
+ */
+ public boolean is(Class<? extends Node> c) {
+ return type.equals(c);
+ }
+
+ /**
+ * @return package name + class name
+ */
+ public String getQualifiedClassName() {
+ return packageName + "." + name;
+ }
+
+ /**
+ * @return the meta model for the node that this node extends. Note that this is to be used to find properties
+ * defined in superclasses of a Node.
+ */
+ public Optional<BaseNodeMetaModel> getSuperNodeMetaModel() {
+ return superNodeMetaModel;
+ }
+
+ /**
+ * @return a list of all properties declared directly in this node (not its parent nodes.) These are also available
+ * as fields.
+ */
+ public List<PropertyMetaModel> getDeclaredPropertyMetaModels() {
+ return declaredPropertyMetaModels;
+ }
+
+ public List<PropertyMetaModel> getDerivedPropertyMetaModels() {
+ return derivedPropertyMetaModels;
+ }
+
+ /**
+ * @return a list of all properties that describe the parameters to the all-fields (but not "range" and "comment")
+ * constructor, in the order of appearance in the constructor parameter list.
+ */
+ public List<PropertyMetaModel> getConstructorParameters() {
+ return constructorParameters;
+ }
+
+ /**
+ * @return a list of all properties in this node and its parents. Note that a new list is created every time this
+ * method is called.
+ */
+ public List<PropertyMetaModel> getAllPropertyMetaModels() {
+ List<PropertyMetaModel> allPropertyMetaModels = new ArrayList<>(getDeclaredPropertyMetaModels());
+ BaseNodeMetaModel walkNode = this;
+ while (walkNode.getSuperNodeMetaModel().isPresent()) {
+ walkNode = walkNode.getSuperNodeMetaModel().get();
+ allPropertyMetaModels.addAll(walkNode.getDeclaredPropertyMetaModels());
+ }
+ return allPropertyMetaModels;
+ }
+
+ public boolean isInstanceOfMetaModel(BaseNodeMetaModel baseMetaModel) {
+ if (this == baseMetaModel) {
+ return true;
+ }
+ if (isRootNode()) {
+ return false;
+ }
+ return getSuperNodeMetaModel().get().isInstanceOfMetaModel(baseMetaModel);
+ }
+
+ /**
+ * @return the class for this AST node type.
+ */
+ public Class<? extends Node> getType() {
+ return type;
+ }
+
+ /**
+ * @return the package containing this AST node class.
+ */
+ public String getPackageName() {
+ return packageName;
+ }
+
+ /**
+ * @return whether this AST node is abstract.
+ */
+ public boolean isAbstract() {
+ return isAbstract;
+ }
+
+ /**
+ * @return whether this AST node has a &lt;?&gt; at the end of its type.
+ */
+ public boolean hasWildcard() {
+ return hasWildcard;
+ }
+
+ /**
+ * @return whether this AST node is the root node, meaning that it is the meta model for "Node": "NodeMetaModel".
+ */
+ public boolean isRootNode() {
+ return !superNodeMetaModel.isPresent();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ BaseNodeMetaModel classMetaModel = (BaseNodeMetaModel) o;
+
+ if (!type.equals(classMetaModel.type)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return type.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+
+ /**
+ * @return the type name, with generics.
+ */
+ public String getTypeNameGenerified() {
+ if (hasWildcard) {
+ return getTypeName() + "<?>";
+ }
+ return getTypeName();
+ }
+
+ /**
+ * @return the raw type name, so nothing but the name.
+ */
+ public String getTypeName() {
+ return type.getSimpleName();
+ }
+
+ /**
+ * The name of the field in JavaParserMetaModel for this node meta model.
+ */
+ public String getMetaModelFieldName() {
+ return decapitalize(getClass().getSimpleName());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BinaryExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BinaryExprMetaModel.java
new file mode 100644
index 000000000..f160ac867
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BinaryExprMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class BinaryExprMetaModel extends ExpressionMetaModel {
+
+ BinaryExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.BinaryExpr.class, "BinaryExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel leftPropertyMetaModel;
+
+ public PropertyMetaModel operatorPropertyMetaModel;
+
+ public PropertyMetaModel rightPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BlockCommentMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BlockCommentMetaModel.java
new file mode 100644
index 000000000..166397da2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BlockCommentMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class BlockCommentMetaModel extends CommentMetaModel {
+
+ BlockCommentMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.comments.BlockComment.class, "BlockComment", "com.github.javaparser.ast.comments", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BlockStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BlockStmtMetaModel.java
new file mode 100644
index 000000000..847809d3d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BlockStmtMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class BlockStmtMetaModel extends StatementMetaModel {
+
+ BlockStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.BlockStmt.class, "BlockStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel statementsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BodyDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BodyDeclarationMetaModel.java
new file mode 100644
index 000000000..c45d595ea
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BodyDeclarationMetaModel.java
@@ -0,0 +1,17 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class BodyDeclarationMetaModel extends NodeMetaModel {
+
+ BodyDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.BodyDeclaration.class, "BodyDeclaration", "com.github.javaparser.ast.body", true, true);
+ }
+
+ protected BodyDeclarationMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BooleanLiteralExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BooleanLiteralExprMetaModel.java
new file mode 100644
index 000000000..eff913d97
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BooleanLiteralExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class BooleanLiteralExprMetaModel extends LiteralExprMetaModel {
+
+ BooleanLiteralExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.BooleanLiteralExpr.class, "BooleanLiteralExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel valuePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/BreakStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BreakStmtMetaModel.java
new file mode 100644
index 000000000..39f723259
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/BreakStmtMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class BreakStmtMetaModel extends StatementMetaModel {
+
+ BreakStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.BreakStmt.class, "BreakStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel labelPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/CallableDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CallableDeclarationMetaModel.java
new file mode 100644
index 000000000..040762f0e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CallableDeclarationMetaModel.java
@@ -0,0 +1,27 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class CallableDeclarationMetaModel extends BodyDeclarationMetaModel {
+
+ CallableDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.CallableDeclaration.class, "CallableDeclaration", "com.github.javaparser.ast.body", true, true);
+ }
+
+ protected CallableDeclarationMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+
+ public PropertyMetaModel modifiersPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel parametersPropertyMetaModel;
+
+ public PropertyMetaModel receiverParameterPropertyMetaModel;
+
+ public PropertyMetaModel thrownExceptionsPropertyMetaModel;
+
+ public PropertyMetaModel typeParametersPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/CastExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CastExprMetaModel.java
new file mode 100644
index 000000000..9671d9b95
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CastExprMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class CastExprMetaModel extends ExpressionMetaModel {
+
+ CastExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.CastExpr.class, "CastExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel expressionPropertyMetaModel;
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/CatchClauseMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CatchClauseMetaModel.java
new file mode 100644
index 000000000..34cd102b0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CatchClauseMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class CatchClauseMetaModel extends NodeMetaModel {
+
+ CatchClauseMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.CatchClause.class, "CatchClause", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel parameterPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/CharLiteralExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CharLiteralExprMetaModel.java
new file mode 100644
index 000000000..d88595b6e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CharLiteralExprMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class CharLiteralExprMetaModel extends LiteralStringValueExprMetaModel {
+
+ CharLiteralExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.CharLiteralExpr.class, "CharLiteralExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassExprMetaModel.java
new file mode 100644
index 000000000..fea3a125f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ClassExprMetaModel extends ExpressionMetaModel {
+
+ ClassExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ClassExpr.class, "ClassExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassOrInterfaceDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassOrInterfaceDeclarationMetaModel.java
new file mode 100644
index 000000000..7f0eff9bc
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassOrInterfaceDeclarationMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ClassOrInterfaceDeclarationMetaModel extends TypeDeclarationMetaModel {
+
+ ClassOrInterfaceDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.ClassOrInterfaceDeclaration.class, "ClassOrInterfaceDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel extendedTypesPropertyMetaModel;
+
+ public PropertyMetaModel implementedTypesPropertyMetaModel;
+
+ public PropertyMetaModel isInterfacePropertyMetaModel;
+
+ public PropertyMetaModel typeParametersPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassOrInterfaceTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassOrInterfaceTypeMetaModel.java
new file mode 100644
index 000000000..b2747ed64
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ClassOrInterfaceTypeMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ClassOrInterfaceTypeMetaModel extends ReferenceTypeMetaModel {
+
+ ClassOrInterfaceTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.ClassOrInterfaceType.class, "ClassOrInterfaceType", "com.github.javaparser.ast.type", false, false);
+ }
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel scopePropertyMetaModel;
+
+ public PropertyMetaModel typeArgumentsPropertyMetaModel;
+
+ public PropertyMetaModel usingDiamondOperatorPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/CommentMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CommentMetaModel.java
new file mode 100644
index 000000000..8cdd7a9ef
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CommentMetaModel.java
@@ -0,0 +1,17 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class CommentMetaModel extends NodeMetaModel {
+
+ CommentMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.comments.Comment.class, "Comment", "com.github.javaparser.ast.comments", true, false);
+ }
+
+ protected CommentMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+
+ public PropertyMetaModel contentPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/CompilationUnitMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CompilationUnitMetaModel.java
new file mode 100644
index 000000000..34eacb70a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/CompilationUnitMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class CompilationUnitMetaModel extends NodeMetaModel {
+
+ CompilationUnitMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.CompilationUnit.class, "CompilationUnit", "com.github.javaparser.ast", false, false);
+ }
+
+ public PropertyMetaModel importsPropertyMetaModel;
+
+ public PropertyMetaModel modulePropertyMetaModel;
+
+ public PropertyMetaModel packageDeclarationPropertyMetaModel;
+
+ public PropertyMetaModel typesPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ConditionalExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ConditionalExprMetaModel.java
new file mode 100644
index 000000000..dbc91191b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ConditionalExprMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ConditionalExprMetaModel extends ExpressionMetaModel {
+
+ ConditionalExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ConditionalExpr.class, "ConditionalExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel conditionPropertyMetaModel;
+
+ public PropertyMetaModel elseExprPropertyMetaModel;
+
+ public PropertyMetaModel thenExprPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ConstructorDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ConstructorDeclarationMetaModel.java
new file mode 100644
index 000000000..4d0b9f32d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ConstructorDeclarationMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ConstructorDeclarationMetaModel extends CallableDeclarationMetaModel {
+
+ ConstructorDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.ConstructorDeclaration.class, "ConstructorDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ContinueStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ContinueStmtMetaModel.java
new file mode 100644
index 000000000..d07db7049
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ContinueStmtMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ContinueStmtMetaModel extends StatementMetaModel {
+
+ ContinueStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ContinueStmt.class, "ContinueStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel labelPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java
new file mode 100644
index 000000000..3a29d7870
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DerivedProperty.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Indicate a derived property of a Node,
+ * meaning it does supply useful information,
+ * but it does so by taking information from other properties.
+ * (Used during generation of the meta model.)
+ */
+@Retention(RUNTIME)
+@Target(METHOD)
+public @interface DerivedProperty {
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DoStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DoStmtMetaModel.java
new file mode 100644
index 000000000..45451c715
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DoStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class DoStmtMetaModel extends StatementMetaModel {
+
+ DoStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.DoStmt.class, "DoStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel conditionPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/DoubleLiteralExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DoubleLiteralExprMetaModel.java
new file mode 100644
index 000000000..2b772731f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/DoubleLiteralExprMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class DoubleLiteralExprMetaModel extends LiteralStringValueExprMetaModel {
+
+ DoubleLiteralExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.DoubleLiteralExpr.class, "DoubleLiteralExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/EmptyStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/EmptyStmtMetaModel.java
new file mode 100644
index 000000000..0943326ca
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/EmptyStmtMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class EmptyStmtMetaModel extends StatementMetaModel {
+
+ EmptyStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.EmptyStmt.class, "EmptyStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnclosedExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnclosedExprMetaModel.java
new file mode 100644
index 000000000..4dd99b83b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnclosedExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class EnclosedExprMetaModel extends ExpressionMetaModel {
+
+ EnclosedExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.EnclosedExpr.class, "EnclosedExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel innerPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnumConstantDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnumConstantDeclarationMetaModel.java
new file mode 100644
index 000000000..2067e6d58
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnumConstantDeclarationMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class EnumConstantDeclarationMetaModel extends BodyDeclarationMetaModel {
+
+ EnumConstantDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.EnumConstantDeclaration.class, "EnumConstantDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel argumentsPropertyMetaModel;
+
+ public PropertyMetaModel classBodyPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnumDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnumDeclarationMetaModel.java
new file mode 100644
index 000000000..d4ed81397
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/EnumDeclarationMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class EnumDeclarationMetaModel extends TypeDeclarationMetaModel {
+
+ EnumDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.EnumDeclaration.class, "EnumDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel entriesPropertyMetaModel;
+
+ public PropertyMetaModel implementedTypesPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExplicitConstructorInvocationStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExplicitConstructorInvocationStmtMetaModel.java
new file mode 100644
index 000000000..9d47b430c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExplicitConstructorInvocationStmtMetaModel.java
@@ -0,0 +1,20 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ExplicitConstructorInvocationStmtMetaModel extends StatementMetaModel {
+
+ ExplicitConstructorInvocationStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt.class, "ExplicitConstructorInvocationStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel argumentsPropertyMetaModel;
+
+ public PropertyMetaModel expressionPropertyMetaModel;
+
+ public PropertyMetaModel isThisPropertyMetaModel;
+
+ public PropertyMetaModel typeArgumentsPropertyMetaModel;
+
+ public PropertyMetaModel usingDiamondOperatorPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExpressionMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExpressionMetaModel.java
new file mode 100644
index 000000000..dc773684e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExpressionMetaModel.java
@@ -0,0 +1,15 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class ExpressionMetaModel extends NodeMetaModel {
+
+ ExpressionMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.Expression.class, "Expression", "com.github.javaparser.ast.expr", true, false);
+ }
+
+ protected ExpressionMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExpressionStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExpressionStmtMetaModel.java
new file mode 100644
index 000000000..69d7a59ce
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ExpressionStmtMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ExpressionStmtMetaModel extends StatementMetaModel {
+
+ ExpressionStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ExpressionStmt.class, "ExpressionStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel expressionPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/FieldAccessExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/FieldAccessExprMetaModel.java
new file mode 100644
index 000000000..b9e820e74
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/FieldAccessExprMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class FieldAccessExprMetaModel extends ExpressionMetaModel {
+
+ FieldAccessExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.FieldAccessExpr.class, "FieldAccessExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel scopePropertyMetaModel;
+
+ public PropertyMetaModel typeArgumentsPropertyMetaModel;
+
+ public PropertyMetaModel usingDiamondOperatorPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/FieldDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/FieldDeclarationMetaModel.java
new file mode 100644
index 000000000..9f12fae84
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/FieldDeclarationMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class FieldDeclarationMetaModel extends BodyDeclarationMetaModel {
+
+ FieldDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.FieldDeclaration.class, "FieldDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel modifiersPropertyMetaModel;
+
+ public PropertyMetaModel variablesPropertyMetaModel;
+
+ public PropertyMetaModel maximumCommonTypePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ForStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ForStmtMetaModel.java
new file mode 100644
index 000000000..c63039ebc
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ForStmtMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ForStmtMetaModel extends StatementMetaModel {
+
+ ForStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ForStmt.class, "ForStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel comparePropertyMetaModel;
+
+ public PropertyMetaModel initializationPropertyMetaModel;
+
+ public PropertyMetaModel updatePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ForeachStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ForeachStmtMetaModel.java
new file mode 100644
index 000000000..8a8dc4e71
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ForeachStmtMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ForeachStmtMetaModel extends StatementMetaModel {
+
+ ForeachStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ForeachStmt.class, "ForeachStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel iterablePropertyMetaModel;
+
+ public PropertyMetaModel variablePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/IfStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/IfStmtMetaModel.java
new file mode 100644
index 000000000..91f4027ed
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/IfStmtMetaModel.java
@@ -0,0 +1,24 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class IfStmtMetaModel extends StatementMetaModel {
+
+ IfStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.IfStmt.class, "IfStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel conditionPropertyMetaModel;
+
+ public PropertyMetaModel elseStmtPropertyMetaModel;
+
+ public PropertyMetaModel thenStmtPropertyMetaModel;
+
+ public PropertyMetaModel cascadingIfStmtPropertyMetaModel;
+
+ public PropertyMetaModel elseBlockPropertyMetaModel;
+
+ public PropertyMetaModel elseBranchPropertyMetaModel;
+
+ public PropertyMetaModel thenBlockPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ImportDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ImportDeclarationMetaModel.java
new file mode 100644
index 000000000..3c1e4f825
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ImportDeclarationMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ImportDeclarationMetaModel extends NodeMetaModel {
+
+ ImportDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.ImportDeclaration.class, "ImportDeclaration", "com.github.javaparser.ast", false, false);
+ }
+
+ public PropertyMetaModel isAsteriskPropertyMetaModel;
+
+ public PropertyMetaModel isStaticPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InitializerDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InitializerDeclarationMetaModel.java
new file mode 100644
index 000000000..035038c37
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InitializerDeclarationMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class InitializerDeclarationMetaModel extends BodyDeclarationMetaModel {
+
+ InitializerDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.InitializerDeclaration.class, "InitializerDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel isStaticPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InstanceOfExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InstanceOfExprMetaModel.java
new file mode 100644
index 000000000..9b4534c91
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InstanceOfExprMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class InstanceOfExprMetaModel extends ExpressionMetaModel {
+
+ InstanceOfExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.InstanceOfExpr.class, "InstanceOfExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel expressionPropertyMetaModel;
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/IntegerLiteralExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/IntegerLiteralExprMetaModel.java
new file mode 100644
index 000000000..b7932170b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/IntegerLiteralExprMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class IntegerLiteralExprMetaModel extends LiteralStringValueExprMetaModel {
+
+ IntegerLiteralExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.IntegerLiteralExpr.class, "IntegerLiteralExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java
new file mode 100644
index 000000000..83c5970b2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/InternalProperty.java
@@ -0,0 +1,17 @@
+package com.github.javaparser.metamodel;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Indicate an internal property of a Node,
+ * meaning it is not part of the meta model.
+ * (Used during generation of the meta model.)
+ */
+@Retention(RUNTIME)
+@Target(FIELD)
+public @interface InternalProperty {
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/IntersectionTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/IntersectionTypeMetaModel.java
new file mode 100644
index 000000000..73ad36f71
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/IntersectionTypeMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class IntersectionTypeMetaModel extends TypeMetaModel {
+
+ IntersectionTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.IntersectionType.class, "IntersectionType", "com.github.javaparser.ast.type", false, false);
+ }
+
+ public PropertyMetaModel elementsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavaParserMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavaParserMetaModel.java
new file mode 100644
index 000000000..bffbd3711
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavaParserMetaModel.java
@@ -0,0 +1,977 @@
+package com.github.javaparser.metamodel;
+
+import com.github.javaparser.ast.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * The model contains meta-data about all nodes in the AST.
+ */
+public final class JavaParserMetaModel {
+
+ private JavaParserMetaModel() {
+ }
+
+ private static final List<BaseNodeMetaModel> nodeMetaModels = new ArrayList<>();
+
+ private static void initializeConstructorParameters() {
+ bodyDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.modifiersPropertyMetaModel);
+ callableDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.typeParametersPropertyMetaModel);
+ callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.namePropertyMetaModel);
+ callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.parametersPropertyMetaModel);
+ callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel);
+ callableDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.receiverParameterPropertyMetaModel);
+ typeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel);
+ annotationExprMetaModel.getConstructorParameters().add(annotationExprMetaModel.namePropertyMetaModel);
+ typeDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.modifiersPropertyMetaModel);
+ typeDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ typeDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.namePropertyMetaModel);
+ typeDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.membersPropertyMetaModel);
+ referenceTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel);
+ literalStringValueExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel);
+ stringLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel);
+ moduleDeclarationMetaModel.getConstructorParameters().add(moduleDeclarationMetaModel.annotationsPropertyMetaModel);
+ moduleDeclarationMetaModel.getConstructorParameters().add(moduleDeclarationMetaModel.namePropertyMetaModel);
+ moduleDeclarationMetaModel.getConstructorParameters().add(moduleDeclarationMetaModel.isOpenPropertyMetaModel);
+ moduleDeclarationMetaModel.getConstructorParameters().add(moduleDeclarationMetaModel.moduleStmtsPropertyMetaModel);
+ arrayCreationLevelMetaModel.getConstructorParameters().add(arrayCreationLevelMetaModel.dimensionPropertyMetaModel);
+ arrayCreationLevelMetaModel.getConstructorParameters().add(arrayCreationLevelMetaModel.annotationsPropertyMetaModel);
+ compilationUnitMetaModel.getConstructorParameters().add(compilationUnitMetaModel.packageDeclarationPropertyMetaModel);
+ compilationUnitMetaModel.getConstructorParameters().add(compilationUnitMetaModel.importsPropertyMetaModel);
+ compilationUnitMetaModel.getConstructorParameters().add(compilationUnitMetaModel.typesPropertyMetaModel);
+ compilationUnitMetaModel.getConstructorParameters().add(compilationUnitMetaModel.modulePropertyMetaModel);
+ packageDeclarationMetaModel.getConstructorParameters().add(packageDeclarationMetaModel.annotationsPropertyMetaModel);
+ packageDeclarationMetaModel.getConstructorParameters().add(packageDeclarationMetaModel.namePropertyMetaModel);
+ annotationDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.modifiersPropertyMetaModel);
+ annotationDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ annotationDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.namePropertyMetaModel);
+ annotationDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.membersPropertyMetaModel);
+ annotationMemberDeclarationMetaModel.getConstructorParameters().add(annotationMemberDeclarationMetaModel.modifiersPropertyMetaModel);
+ annotationMemberDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ annotationMemberDeclarationMetaModel.getConstructorParameters().add(annotationMemberDeclarationMetaModel.typePropertyMetaModel);
+ annotationMemberDeclarationMetaModel.getConstructorParameters().add(annotationMemberDeclarationMetaModel.namePropertyMetaModel);
+ annotationMemberDeclarationMetaModel.getConstructorParameters().add(annotationMemberDeclarationMetaModel.defaultValuePropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.modifiersPropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(classOrInterfaceDeclarationMetaModel.isInterfacePropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.namePropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(classOrInterfaceDeclarationMetaModel.typeParametersPropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(classOrInterfaceDeclarationMetaModel.extendedTypesPropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(classOrInterfaceDeclarationMetaModel.implementedTypesPropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.membersPropertyMetaModel);
+ constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.modifiersPropertyMetaModel);
+ constructorDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.typeParametersPropertyMetaModel);
+ constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.namePropertyMetaModel);
+ constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.parametersPropertyMetaModel);
+ constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel);
+ constructorDeclarationMetaModel.getConstructorParameters().add(constructorDeclarationMetaModel.bodyPropertyMetaModel);
+ constructorDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.receiverParameterPropertyMetaModel);
+ enumConstantDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ enumConstantDeclarationMetaModel.getConstructorParameters().add(enumConstantDeclarationMetaModel.namePropertyMetaModel);
+ enumConstantDeclarationMetaModel.getConstructorParameters().add(enumConstantDeclarationMetaModel.argumentsPropertyMetaModel);
+ enumConstantDeclarationMetaModel.getConstructorParameters().add(enumConstantDeclarationMetaModel.classBodyPropertyMetaModel);
+ enumDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.modifiersPropertyMetaModel);
+ enumDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ enumDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.namePropertyMetaModel);
+ enumDeclarationMetaModel.getConstructorParameters().add(enumDeclarationMetaModel.implementedTypesPropertyMetaModel);
+ enumDeclarationMetaModel.getConstructorParameters().add(enumDeclarationMetaModel.entriesPropertyMetaModel);
+ enumDeclarationMetaModel.getConstructorParameters().add(typeDeclarationMetaModel.membersPropertyMetaModel);
+ fieldDeclarationMetaModel.getConstructorParameters().add(fieldDeclarationMetaModel.modifiersPropertyMetaModel);
+ fieldDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ fieldDeclarationMetaModel.getConstructorParameters().add(fieldDeclarationMetaModel.variablesPropertyMetaModel);
+ initializerDeclarationMetaModel.getConstructorParameters().add(initializerDeclarationMetaModel.isStaticPropertyMetaModel);
+ initializerDeclarationMetaModel.getConstructorParameters().add(initializerDeclarationMetaModel.bodyPropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.modifiersPropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.typeParametersPropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(methodDeclarationMetaModel.typePropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.namePropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.parametersPropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(methodDeclarationMetaModel.bodyPropertyMetaModel);
+ methodDeclarationMetaModel.getConstructorParameters().add(callableDeclarationMetaModel.receiverParameterPropertyMetaModel);
+ parameterMetaModel.getConstructorParameters().add(parameterMetaModel.modifiersPropertyMetaModel);
+ parameterMetaModel.getConstructorParameters().add(parameterMetaModel.annotationsPropertyMetaModel);
+ parameterMetaModel.getConstructorParameters().add(parameterMetaModel.typePropertyMetaModel);
+ parameterMetaModel.getConstructorParameters().add(parameterMetaModel.isVarArgsPropertyMetaModel);
+ parameterMetaModel.getConstructorParameters().add(parameterMetaModel.varArgsAnnotationsPropertyMetaModel);
+ parameterMetaModel.getConstructorParameters().add(parameterMetaModel.namePropertyMetaModel);
+ receiverParameterMetaModel.getConstructorParameters().add(receiverParameterMetaModel.annotationsPropertyMetaModel);
+ receiverParameterMetaModel.getConstructorParameters().add(receiverParameterMetaModel.typePropertyMetaModel);
+ receiverParameterMetaModel.getConstructorParameters().add(receiverParameterMetaModel.namePropertyMetaModel);
+ variableDeclaratorMetaModel.getConstructorParameters().add(variableDeclaratorMetaModel.typePropertyMetaModel);
+ variableDeclaratorMetaModel.getConstructorParameters().add(variableDeclaratorMetaModel.namePropertyMetaModel);
+ variableDeclaratorMetaModel.getConstructorParameters().add(variableDeclaratorMetaModel.initializerPropertyMetaModel);
+ commentMetaModel.getConstructorParameters().add(commentMetaModel.contentPropertyMetaModel);
+ blockCommentMetaModel.getConstructorParameters().add(commentMetaModel.contentPropertyMetaModel);
+ javadocCommentMetaModel.getConstructorParameters().add(commentMetaModel.contentPropertyMetaModel);
+ lineCommentMetaModel.getConstructorParameters().add(commentMetaModel.contentPropertyMetaModel);
+ arrayAccessExprMetaModel.getConstructorParameters().add(arrayAccessExprMetaModel.namePropertyMetaModel);
+ arrayAccessExprMetaModel.getConstructorParameters().add(arrayAccessExprMetaModel.indexPropertyMetaModel);
+ arrayCreationExprMetaModel.getConstructorParameters().add(arrayCreationExprMetaModel.elementTypePropertyMetaModel);
+ arrayCreationExprMetaModel.getConstructorParameters().add(arrayCreationExprMetaModel.levelsPropertyMetaModel);
+ arrayCreationExprMetaModel.getConstructorParameters().add(arrayCreationExprMetaModel.initializerPropertyMetaModel);
+ arrayInitializerExprMetaModel.getConstructorParameters().add(arrayInitializerExprMetaModel.valuesPropertyMetaModel);
+ assignExprMetaModel.getConstructorParameters().add(assignExprMetaModel.targetPropertyMetaModel);
+ assignExprMetaModel.getConstructorParameters().add(assignExprMetaModel.valuePropertyMetaModel);
+ assignExprMetaModel.getConstructorParameters().add(assignExprMetaModel.operatorPropertyMetaModel);
+ binaryExprMetaModel.getConstructorParameters().add(binaryExprMetaModel.leftPropertyMetaModel);
+ binaryExprMetaModel.getConstructorParameters().add(binaryExprMetaModel.rightPropertyMetaModel);
+ binaryExprMetaModel.getConstructorParameters().add(binaryExprMetaModel.operatorPropertyMetaModel);
+ booleanLiteralExprMetaModel.getConstructorParameters().add(booleanLiteralExprMetaModel.valuePropertyMetaModel);
+ castExprMetaModel.getConstructorParameters().add(castExprMetaModel.typePropertyMetaModel);
+ castExprMetaModel.getConstructorParameters().add(castExprMetaModel.expressionPropertyMetaModel);
+ charLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel);
+ classExprMetaModel.getConstructorParameters().add(classExprMetaModel.typePropertyMetaModel);
+ conditionalExprMetaModel.getConstructorParameters().add(conditionalExprMetaModel.conditionPropertyMetaModel);
+ conditionalExprMetaModel.getConstructorParameters().add(conditionalExprMetaModel.thenExprPropertyMetaModel);
+ conditionalExprMetaModel.getConstructorParameters().add(conditionalExprMetaModel.elseExprPropertyMetaModel);
+ doubleLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel);
+ enclosedExprMetaModel.getConstructorParameters().add(enclosedExprMetaModel.innerPropertyMetaModel);
+ fieldAccessExprMetaModel.getConstructorParameters().add(fieldAccessExprMetaModel.scopePropertyMetaModel);
+ fieldAccessExprMetaModel.getConstructorParameters().add(fieldAccessExprMetaModel.typeArgumentsPropertyMetaModel);
+ fieldAccessExprMetaModel.getConstructorParameters().add(fieldAccessExprMetaModel.namePropertyMetaModel);
+ instanceOfExprMetaModel.getConstructorParameters().add(instanceOfExprMetaModel.expressionPropertyMetaModel);
+ instanceOfExprMetaModel.getConstructorParameters().add(instanceOfExprMetaModel.typePropertyMetaModel);
+ integerLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel);
+ lambdaExprMetaModel.getConstructorParameters().add(lambdaExprMetaModel.parametersPropertyMetaModel);
+ lambdaExprMetaModel.getConstructorParameters().add(lambdaExprMetaModel.bodyPropertyMetaModel);
+ lambdaExprMetaModel.getConstructorParameters().add(lambdaExprMetaModel.isEnclosingParametersPropertyMetaModel);
+ longLiteralExprMetaModel.getConstructorParameters().add(literalStringValueExprMetaModel.valuePropertyMetaModel);
+ markerAnnotationExprMetaModel.getConstructorParameters().add(annotationExprMetaModel.namePropertyMetaModel);
+ memberValuePairMetaModel.getConstructorParameters().add(memberValuePairMetaModel.namePropertyMetaModel);
+ memberValuePairMetaModel.getConstructorParameters().add(memberValuePairMetaModel.valuePropertyMetaModel);
+ methodCallExprMetaModel.getConstructorParameters().add(methodCallExprMetaModel.scopePropertyMetaModel);
+ methodCallExprMetaModel.getConstructorParameters().add(methodCallExprMetaModel.typeArgumentsPropertyMetaModel);
+ methodCallExprMetaModel.getConstructorParameters().add(methodCallExprMetaModel.namePropertyMetaModel);
+ methodCallExprMetaModel.getConstructorParameters().add(methodCallExprMetaModel.argumentsPropertyMetaModel);
+ methodReferenceExprMetaModel.getConstructorParameters().add(methodReferenceExprMetaModel.scopePropertyMetaModel);
+ methodReferenceExprMetaModel.getConstructorParameters().add(methodReferenceExprMetaModel.typeArgumentsPropertyMetaModel);
+ methodReferenceExprMetaModel.getConstructorParameters().add(methodReferenceExprMetaModel.identifierPropertyMetaModel);
+ nameExprMetaModel.getConstructorParameters().add(nameExprMetaModel.namePropertyMetaModel);
+ nameMetaModel.getConstructorParameters().add(nameMetaModel.qualifierPropertyMetaModel);
+ nameMetaModel.getConstructorParameters().add(nameMetaModel.identifierPropertyMetaModel);
+ nameMetaModel.getConstructorParameters().add(nameMetaModel.annotationsPropertyMetaModel);
+ normalAnnotationExprMetaModel.getConstructorParameters().add(annotationExprMetaModel.namePropertyMetaModel);
+ normalAnnotationExprMetaModel.getConstructorParameters().add(normalAnnotationExprMetaModel.pairsPropertyMetaModel);
+ objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.scopePropertyMetaModel);
+ objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.typePropertyMetaModel);
+ objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.typeArgumentsPropertyMetaModel);
+ objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.argumentsPropertyMetaModel);
+ objectCreationExprMetaModel.getConstructorParameters().add(objectCreationExprMetaModel.anonymousClassBodyPropertyMetaModel);
+ simpleNameMetaModel.getConstructorParameters().add(simpleNameMetaModel.identifierPropertyMetaModel);
+ singleMemberAnnotationExprMetaModel.getConstructorParameters().add(annotationExprMetaModel.namePropertyMetaModel);
+ singleMemberAnnotationExprMetaModel.getConstructorParameters().add(singleMemberAnnotationExprMetaModel.memberValuePropertyMetaModel);
+ superExprMetaModel.getConstructorParameters().add(superExprMetaModel.classExprPropertyMetaModel);
+ thisExprMetaModel.getConstructorParameters().add(thisExprMetaModel.classExprPropertyMetaModel);
+ typeExprMetaModel.getConstructorParameters().add(typeExprMetaModel.typePropertyMetaModel);
+ unaryExprMetaModel.getConstructorParameters().add(unaryExprMetaModel.expressionPropertyMetaModel);
+ unaryExprMetaModel.getConstructorParameters().add(unaryExprMetaModel.operatorPropertyMetaModel);
+ variableDeclarationExprMetaModel.getConstructorParameters().add(variableDeclarationExprMetaModel.modifiersPropertyMetaModel);
+ variableDeclarationExprMetaModel.getConstructorParameters().add(variableDeclarationExprMetaModel.annotationsPropertyMetaModel);
+ variableDeclarationExprMetaModel.getConstructorParameters().add(variableDeclarationExprMetaModel.variablesPropertyMetaModel);
+ importDeclarationMetaModel.getConstructorParameters().add(importDeclarationMetaModel.namePropertyMetaModel);
+ importDeclarationMetaModel.getConstructorParameters().add(importDeclarationMetaModel.isStaticPropertyMetaModel);
+ importDeclarationMetaModel.getConstructorParameters().add(importDeclarationMetaModel.isAsteriskPropertyMetaModel);
+ assertStmtMetaModel.getConstructorParameters().add(assertStmtMetaModel.checkPropertyMetaModel);
+ assertStmtMetaModel.getConstructorParameters().add(assertStmtMetaModel.messagePropertyMetaModel);
+ blockStmtMetaModel.getConstructorParameters().add(blockStmtMetaModel.statementsPropertyMetaModel);
+ breakStmtMetaModel.getConstructorParameters().add(breakStmtMetaModel.labelPropertyMetaModel);
+ catchClauseMetaModel.getConstructorParameters().add(catchClauseMetaModel.parameterPropertyMetaModel);
+ catchClauseMetaModel.getConstructorParameters().add(catchClauseMetaModel.bodyPropertyMetaModel);
+ continueStmtMetaModel.getConstructorParameters().add(continueStmtMetaModel.labelPropertyMetaModel);
+ doStmtMetaModel.getConstructorParameters().add(doStmtMetaModel.bodyPropertyMetaModel);
+ doStmtMetaModel.getConstructorParameters().add(doStmtMetaModel.conditionPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.getConstructorParameters().add(explicitConstructorInvocationStmtMetaModel.typeArgumentsPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.getConstructorParameters().add(explicitConstructorInvocationStmtMetaModel.isThisPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.getConstructorParameters().add(explicitConstructorInvocationStmtMetaModel.expressionPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.getConstructorParameters().add(explicitConstructorInvocationStmtMetaModel.argumentsPropertyMetaModel);
+ expressionStmtMetaModel.getConstructorParameters().add(expressionStmtMetaModel.expressionPropertyMetaModel);
+ foreachStmtMetaModel.getConstructorParameters().add(foreachStmtMetaModel.variablePropertyMetaModel);
+ foreachStmtMetaModel.getConstructorParameters().add(foreachStmtMetaModel.iterablePropertyMetaModel);
+ foreachStmtMetaModel.getConstructorParameters().add(foreachStmtMetaModel.bodyPropertyMetaModel);
+ forStmtMetaModel.getConstructorParameters().add(forStmtMetaModel.initializationPropertyMetaModel);
+ forStmtMetaModel.getConstructorParameters().add(forStmtMetaModel.comparePropertyMetaModel);
+ forStmtMetaModel.getConstructorParameters().add(forStmtMetaModel.updatePropertyMetaModel);
+ forStmtMetaModel.getConstructorParameters().add(forStmtMetaModel.bodyPropertyMetaModel);
+ ifStmtMetaModel.getConstructorParameters().add(ifStmtMetaModel.conditionPropertyMetaModel);
+ ifStmtMetaModel.getConstructorParameters().add(ifStmtMetaModel.thenStmtPropertyMetaModel);
+ ifStmtMetaModel.getConstructorParameters().add(ifStmtMetaModel.elseStmtPropertyMetaModel);
+ labeledStmtMetaModel.getConstructorParameters().add(labeledStmtMetaModel.labelPropertyMetaModel);
+ labeledStmtMetaModel.getConstructorParameters().add(labeledStmtMetaModel.statementPropertyMetaModel);
+ returnStmtMetaModel.getConstructorParameters().add(returnStmtMetaModel.expressionPropertyMetaModel);
+ switchEntryStmtMetaModel.getConstructorParameters().add(switchEntryStmtMetaModel.labelPropertyMetaModel);
+ switchEntryStmtMetaModel.getConstructorParameters().add(switchEntryStmtMetaModel.statementsPropertyMetaModel);
+ switchStmtMetaModel.getConstructorParameters().add(switchStmtMetaModel.selectorPropertyMetaModel);
+ switchStmtMetaModel.getConstructorParameters().add(switchStmtMetaModel.entriesPropertyMetaModel);
+ synchronizedStmtMetaModel.getConstructorParameters().add(synchronizedStmtMetaModel.expressionPropertyMetaModel);
+ synchronizedStmtMetaModel.getConstructorParameters().add(synchronizedStmtMetaModel.bodyPropertyMetaModel);
+ throwStmtMetaModel.getConstructorParameters().add(throwStmtMetaModel.expressionPropertyMetaModel);
+ tryStmtMetaModel.getConstructorParameters().add(tryStmtMetaModel.resourcesPropertyMetaModel);
+ tryStmtMetaModel.getConstructorParameters().add(tryStmtMetaModel.tryBlockPropertyMetaModel);
+ tryStmtMetaModel.getConstructorParameters().add(tryStmtMetaModel.catchClausesPropertyMetaModel);
+ tryStmtMetaModel.getConstructorParameters().add(tryStmtMetaModel.finallyBlockPropertyMetaModel);
+ localClassDeclarationStmtMetaModel.getConstructorParameters().add(localClassDeclarationStmtMetaModel.classDeclarationPropertyMetaModel);
+ whileStmtMetaModel.getConstructorParameters().add(whileStmtMetaModel.conditionPropertyMetaModel);
+ whileStmtMetaModel.getConstructorParameters().add(whileStmtMetaModel.bodyPropertyMetaModel);
+ arrayTypeMetaModel.getConstructorParameters().add(arrayTypeMetaModel.componentTypePropertyMetaModel);
+ arrayTypeMetaModel.getConstructorParameters().add(arrayTypeMetaModel.originPropertyMetaModel);
+ arrayTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel);
+ classOrInterfaceTypeMetaModel.getConstructorParameters().add(classOrInterfaceTypeMetaModel.scopePropertyMetaModel);
+ classOrInterfaceTypeMetaModel.getConstructorParameters().add(classOrInterfaceTypeMetaModel.namePropertyMetaModel);
+ classOrInterfaceTypeMetaModel.getConstructorParameters().add(classOrInterfaceTypeMetaModel.typeArgumentsPropertyMetaModel);
+ classOrInterfaceTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel);
+ intersectionTypeMetaModel.getConstructorParameters().add(intersectionTypeMetaModel.elementsPropertyMetaModel);
+ primitiveTypeMetaModel.getConstructorParameters().add(primitiveTypeMetaModel.typePropertyMetaModel);
+ primitiveTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel);
+ typeParameterMetaModel.getConstructorParameters().add(typeParameterMetaModel.namePropertyMetaModel);
+ typeParameterMetaModel.getConstructorParameters().add(typeParameterMetaModel.typeBoundPropertyMetaModel);
+ typeParameterMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel);
+ unionTypeMetaModel.getConstructorParameters().add(unionTypeMetaModel.elementsPropertyMetaModel);
+ wildcardTypeMetaModel.getConstructorParameters().add(wildcardTypeMetaModel.extendedTypePropertyMetaModel);
+ wildcardTypeMetaModel.getConstructorParameters().add(wildcardTypeMetaModel.superTypePropertyMetaModel);
+ wildcardTypeMetaModel.getConstructorParameters().add(typeMetaModel.annotationsPropertyMetaModel);
+ moduleRequiresStmtMetaModel.getConstructorParameters().add(moduleRequiresStmtMetaModel.modifiersPropertyMetaModel);
+ moduleRequiresStmtMetaModel.getConstructorParameters().add(moduleRequiresStmtMetaModel.namePropertyMetaModel);
+ moduleExportsStmtMetaModel.getConstructorParameters().add(moduleExportsStmtMetaModel.namePropertyMetaModel);
+ moduleExportsStmtMetaModel.getConstructorParameters().add(moduleExportsStmtMetaModel.moduleNamesPropertyMetaModel);
+ moduleProvidesStmtMetaModel.getConstructorParameters().add(moduleProvidesStmtMetaModel.typePropertyMetaModel);
+ moduleProvidesStmtMetaModel.getConstructorParameters().add(moduleProvidesStmtMetaModel.withTypesPropertyMetaModel);
+ moduleUsesStmtMetaModel.getConstructorParameters().add(moduleUsesStmtMetaModel.typePropertyMetaModel);
+ moduleOpensStmtMetaModel.getConstructorParameters().add(moduleOpensStmtMetaModel.namePropertyMetaModel);
+ moduleOpensStmtMetaModel.getConstructorParameters().add(moduleOpensStmtMetaModel.moduleNamesPropertyMetaModel);
+ }
+
+ public static List<BaseNodeMetaModel> getNodeMetaModels() {
+ return nodeMetaModels;
+ }
+
+ private static void initializeNodeMetaModels() {
+ nodeMetaModels.add(annotationDeclarationMetaModel);
+ nodeMetaModels.add(annotationExprMetaModel);
+ nodeMetaModels.add(annotationMemberDeclarationMetaModel);
+ nodeMetaModels.add(arrayAccessExprMetaModel);
+ nodeMetaModels.add(arrayCreationExprMetaModel);
+ nodeMetaModels.add(arrayCreationLevelMetaModel);
+ nodeMetaModels.add(arrayInitializerExprMetaModel);
+ nodeMetaModels.add(arrayTypeMetaModel);
+ nodeMetaModels.add(assertStmtMetaModel);
+ nodeMetaModels.add(assignExprMetaModel);
+ nodeMetaModels.add(binaryExprMetaModel);
+ nodeMetaModels.add(blockCommentMetaModel);
+ nodeMetaModels.add(blockStmtMetaModel);
+ nodeMetaModels.add(bodyDeclarationMetaModel);
+ nodeMetaModels.add(booleanLiteralExprMetaModel);
+ nodeMetaModels.add(breakStmtMetaModel);
+ nodeMetaModels.add(callableDeclarationMetaModel);
+ nodeMetaModels.add(castExprMetaModel);
+ nodeMetaModels.add(catchClauseMetaModel);
+ nodeMetaModels.add(charLiteralExprMetaModel);
+ nodeMetaModels.add(classExprMetaModel);
+ nodeMetaModels.add(classOrInterfaceDeclarationMetaModel);
+ nodeMetaModels.add(classOrInterfaceTypeMetaModel);
+ nodeMetaModels.add(commentMetaModel);
+ nodeMetaModels.add(compilationUnitMetaModel);
+ nodeMetaModels.add(conditionalExprMetaModel);
+ nodeMetaModels.add(constructorDeclarationMetaModel);
+ nodeMetaModels.add(continueStmtMetaModel);
+ nodeMetaModels.add(doStmtMetaModel);
+ nodeMetaModels.add(doubleLiteralExprMetaModel);
+ nodeMetaModels.add(emptyStmtMetaModel);
+ nodeMetaModels.add(enclosedExprMetaModel);
+ nodeMetaModels.add(enumConstantDeclarationMetaModel);
+ nodeMetaModels.add(enumDeclarationMetaModel);
+ nodeMetaModels.add(explicitConstructorInvocationStmtMetaModel);
+ nodeMetaModels.add(expressionMetaModel);
+ nodeMetaModels.add(expressionStmtMetaModel);
+ nodeMetaModels.add(fieldAccessExprMetaModel);
+ nodeMetaModels.add(fieldDeclarationMetaModel);
+ nodeMetaModels.add(forStmtMetaModel);
+ nodeMetaModels.add(foreachStmtMetaModel);
+ nodeMetaModels.add(ifStmtMetaModel);
+ nodeMetaModels.add(importDeclarationMetaModel);
+ nodeMetaModels.add(initializerDeclarationMetaModel);
+ nodeMetaModels.add(instanceOfExprMetaModel);
+ nodeMetaModels.add(integerLiteralExprMetaModel);
+ nodeMetaModels.add(intersectionTypeMetaModel);
+ nodeMetaModels.add(javadocCommentMetaModel);
+ nodeMetaModels.add(labeledStmtMetaModel);
+ nodeMetaModels.add(lambdaExprMetaModel);
+ nodeMetaModels.add(lineCommentMetaModel);
+ nodeMetaModels.add(literalExprMetaModel);
+ nodeMetaModels.add(literalStringValueExprMetaModel);
+ nodeMetaModels.add(localClassDeclarationStmtMetaModel);
+ nodeMetaModels.add(longLiteralExprMetaModel);
+ nodeMetaModels.add(markerAnnotationExprMetaModel);
+ nodeMetaModels.add(memberValuePairMetaModel);
+ nodeMetaModels.add(methodCallExprMetaModel);
+ nodeMetaModels.add(methodDeclarationMetaModel);
+ nodeMetaModels.add(methodReferenceExprMetaModel);
+ nodeMetaModels.add(moduleDeclarationMetaModel);
+ nodeMetaModels.add(moduleExportsStmtMetaModel);
+ nodeMetaModels.add(moduleOpensStmtMetaModel);
+ nodeMetaModels.add(moduleProvidesStmtMetaModel);
+ nodeMetaModels.add(moduleRequiresStmtMetaModel);
+ nodeMetaModels.add(moduleStmtMetaModel);
+ nodeMetaModels.add(moduleUsesStmtMetaModel);
+ nodeMetaModels.add(nameExprMetaModel);
+ nodeMetaModels.add(nameMetaModel);
+ nodeMetaModels.add(nodeMetaModel);
+ nodeMetaModels.add(normalAnnotationExprMetaModel);
+ nodeMetaModels.add(nullLiteralExprMetaModel);
+ nodeMetaModels.add(objectCreationExprMetaModel);
+ nodeMetaModels.add(packageDeclarationMetaModel);
+ nodeMetaModels.add(parameterMetaModel);
+ nodeMetaModels.add(primitiveTypeMetaModel);
+ nodeMetaModels.add(receiverParameterMetaModel);
+ nodeMetaModels.add(referenceTypeMetaModel);
+ nodeMetaModels.add(returnStmtMetaModel);
+ nodeMetaModels.add(simpleNameMetaModel);
+ nodeMetaModels.add(singleMemberAnnotationExprMetaModel);
+ nodeMetaModels.add(statementMetaModel);
+ nodeMetaModels.add(stringLiteralExprMetaModel);
+ nodeMetaModels.add(superExprMetaModel);
+ nodeMetaModels.add(switchEntryStmtMetaModel);
+ nodeMetaModels.add(switchStmtMetaModel);
+ nodeMetaModels.add(synchronizedStmtMetaModel);
+ nodeMetaModels.add(thisExprMetaModel);
+ nodeMetaModels.add(throwStmtMetaModel);
+ nodeMetaModels.add(tryStmtMetaModel);
+ nodeMetaModels.add(typeDeclarationMetaModel);
+ nodeMetaModels.add(typeExprMetaModel);
+ nodeMetaModels.add(typeMetaModel);
+ nodeMetaModels.add(typeParameterMetaModel);
+ nodeMetaModels.add(unaryExprMetaModel);
+ nodeMetaModels.add(unionTypeMetaModel);
+ nodeMetaModels.add(unknownTypeMetaModel);
+ nodeMetaModels.add(unparsableStmtMetaModel);
+ nodeMetaModels.add(varTypeMetaModel);
+ nodeMetaModels.add(variableDeclarationExprMetaModel);
+ nodeMetaModels.add(variableDeclaratorMetaModel);
+ nodeMetaModels.add(voidTypeMetaModel);
+ nodeMetaModels.add(whileStmtMetaModel);
+ nodeMetaModels.add(wildcardTypeMetaModel);
+ }
+
+ private static void initializePropertyMetaModels() {
+ nodeMetaModel.commentPropertyMetaModel = new PropertyMetaModel(nodeMetaModel, "comment", com.github.javaparser.ast.comments.Comment.class, Optional.of(commentMetaModel), true, false, false, false, false);
+ nodeMetaModel.getDeclaredPropertyMetaModels().add(nodeMetaModel.commentPropertyMetaModel);
+ bodyDeclarationMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(bodyDeclarationMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ bodyDeclarationMetaModel.getDeclaredPropertyMetaModels().add(bodyDeclarationMetaModel.annotationsPropertyMetaModel);
+ callableDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false);
+ callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.modifiersPropertyMetaModel);
+ callableDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.namePropertyMetaModel);
+ callableDeclarationMetaModel.parametersPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "parameters", com.github.javaparser.ast.body.Parameter.class, Optional.of(parameterMetaModel), false, false, true, false, false);
+ callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.parametersPropertyMetaModel);
+ callableDeclarationMetaModel.receiverParameterPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "receiverParameter", com.github.javaparser.ast.body.ReceiverParameter.class, Optional.of(receiverParameterMetaModel), true, false, false, false, false);
+ callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.receiverParameterPropertyMetaModel);
+ callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "thrownExceptions", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), false, false, true, false, false);
+ callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.thrownExceptionsPropertyMetaModel);
+ callableDeclarationMetaModel.typeParametersPropertyMetaModel = new PropertyMetaModel(callableDeclarationMetaModel, "typeParameters", com.github.javaparser.ast.type.TypeParameter.class, Optional.of(typeParameterMetaModel), false, false, true, false, false);
+ callableDeclarationMetaModel.getDeclaredPropertyMetaModels().add(callableDeclarationMetaModel.typeParametersPropertyMetaModel);
+ typeMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(typeMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ typeMetaModel.getDeclaredPropertyMetaModels().add(typeMetaModel.annotationsPropertyMetaModel);
+ annotationExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(annotationExprMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false);
+ annotationExprMetaModel.getDeclaredPropertyMetaModels().add(annotationExprMetaModel.namePropertyMetaModel);
+ typeDeclarationMetaModel.membersPropertyMetaModel = new PropertyMetaModel(typeDeclarationMetaModel, "members", com.github.javaparser.ast.body.BodyDeclaration.class, Optional.of(bodyDeclarationMetaModel), false, false, true, false, true);
+ typeDeclarationMetaModel.getDeclaredPropertyMetaModels().add(typeDeclarationMetaModel.membersPropertyMetaModel);
+ typeDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(typeDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false);
+ typeDeclarationMetaModel.getDeclaredPropertyMetaModels().add(typeDeclarationMetaModel.modifiersPropertyMetaModel);
+ typeDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(typeDeclarationMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ typeDeclarationMetaModel.getDeclaredPropertyMetaModels().add(typeDeclarationMetaModel.namePropertyMetaModel);
+ literalStringValueExprMetaModel.valuePropertyMetaModel = new PropertyMetaModel(literalStringValueExprMetaModel, "value", java.lang.String.class, Optional.empty(), false, false, false, false, false);
+ literalStringValueExprMetaModel.getDeclaredPropertyMetaModels().add(literalStringValueExprMetaModel.valuePropertyMetaModel);
+ moduleDeclarationMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(moduleDeclarationMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ moduleDeclarationMetaModel.getDeclaredPropertyMetaModels().add(moduleDeclarationMetaModel.annotationsPropertyMetaModel);
+ moduleDeclarationMetaModel.isOpenPropertyMetaModel = new PropertyMetaModel(moduleDeclarationMetaModel, "isOpen", boolean.class, Optional.empty(), false, false, false, false, false);
+ moduleDeclarationMetaModel.getDeclaredPropertyMetaModels().add(moduleDeclarationMetaModel.isOpenPropertyMetaModel);
+ moduleDeclarationMetaModel.moduleStmtsPropertyMetaModel = new PropertyMetaModel(moduleDeclarationMetaModel, "moduleStmts", com.github.javaparser.ast.modules.ModuleStmt.class, Optional.of(moduleStmtMetaModel), false, false, true, false, false);
+ moduleDeclarationMetaModel.getDeclaredPropertyMetaModels().add(moduleDeclarationMetaModel.moduleStmtsPropertyMetaModel);
+ moduleDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(moduleDeclarationMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false);
+ moduleDeclarationMetaModel.getDeclaredPropertyMetaModels().add(moduleDeclarationMetaModel.namePropertyMetaModel);
+ arrayCreationLevelMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(arrayCreationLevelMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ arrayCreationLevelMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationLevelMetaModel.annotationsPropertyMetaModel);
+ arrayCreationLevelMetaModel.dimensionPropertyMetaModel = new PropertyMetaModel(arrayCreationLevelMetaModel, "dimension", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ arrayCreationLevelMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationLevelMetaModel.dimensionPropertyMetaModel);
+ compilationUnitMetaModel.importsPropertyMetaModel = new PropertyMetaModel(compilationUnitMetaModel, "imports", com.github.javaparser.ast.ImportDeclaration.class, Optional.of(importDeclarationMetaModel), false, false, true, false, false);
+ compilationUnitMetaModel.getDeclaredPropertyMetaModels().add(compilationUnitMetaModel.importsPropertyMetaModel);
+ compilationUnitMetaModel.modulePropertyMetaModel = new PropertyMetaModel(compilationUnitMetaModel, "module", com.github.javaparser.ast.modules.ModuleDeclaration.class, Optional.of(moduleDeclarationMetaModel), true, false, false, false, false);
+ compilationUnitMetaModel.getDeclaredPropertyMetaModels().add(compilationUnitMetaModel.modulePropertyMetaModel);
+ compilationUnitMetaModel.packageDeclarationPropertyMetaModel = new PropertyMetaModel(compilationUnitMetaModel, "packageDeclaration", com.github.javaparser.ast.PackageDeclaration.class, Optional.of(packageDeclarationMetaModel), true, false, false, false, false);
+ compilationUnitMetaModel.getDeclaredPropertyMetaModels().add(compilationUnitMetaModel.packageDeclarationPropertyMetaModel);
+ compilationUnitMetaModel.typesPropertyMetaModel = new PropertyMetaModel(compilationUnitMetaModel, "types", com.github.javaparser.ast.body.TypeDeclaration.class, Optional.of(typeDeclarationMetaModel), false, false, true, false, true);
+ compilationUnitMetaModel.getDeclaredPropertyMetaModels().add(compilationUnitMetaModel.typesPropertyMetaModel);
+ packageDeclarationMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(packageDeclarationMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ packageDeclarationMetaModel.getDeclaredPropertyMetaModels().add(packageDeclarationMetaModel.annotationsPropertyMetaModel);
+ packageDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(packageDeclarationMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false);
+ packageDeclarationMetaModel.getDeclaredPropertyMetaModels().add(packageDeclarationMetaModel.namePropertyMetaModel);
+ annotationMemberDeclarationMetaModel.defaultValuePropertyMetaModel = new PropertyMetaModel(annotationMemberDeclarationMetaModel, "defaultValue", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ annotationMemberDeclarationMetaModel.getDeclaredPropertyMetaModels().add(annotationMemberDeclarationMetaModel.defaultValuePropertyMetaModel);
+ annotationMemberDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(annotationMemberDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false);
+ annotationMemberDeclarationMetaModel.getDeclaredPropertyMetaModels().add(annotationMemberDeclarationMetaModel.modifiersPropertyMetaModel);
+ annotationMemberDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(annotationMemberDeclarationMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ annotationMemberDeclarationMetaModel.getDeclaredPropertyMetaModels().add(annotationMemberDeclarationMetaModel.namePropertyMetaModel);
+ annotationMemberDeclarationMetaModel.typePropertyMetaModel = new PropertyMetaModel(annotationMemberDeclarationMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ annotationMemberDeclarationMetaModel.getDeclaredPropertyMetaModels().add(annotationMemberDeclarationMetaModel.typePropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.extendedTypesPropertyMetaModel = new PropertyMetaModel(classOrInterfaceDeclarationMetaModel, "extendedTypes", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, true, false, false);
+ classOrInterfaceDeclarationMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceDeclarationMetaModel.extendedTypesPropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.implementedTypesPropertyMetaModel = new PropertyMetaModel(classOrInterfaceDeclarationMetaModel, "implementedTypes", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, true, false, false);
+ classOrInterfaceDeclarationMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceDeclarationMetaModel.implementedTypesPropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.isInterfacePropertyMetaModel = new PropertyMetaModel(classOrInterfaceDeclarationMetaModel, "isInterface", boolean.class, Optional.empty(), false, false, false, false, false);
+ classOrInterfaceDeclarationMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceDeclarationMetaModel.isInterfacePropertyMetaModel);
+ classOrInterfaceDeclarationMetaModel.typeParametersPropertyMetaModel = new PropertyMetaModel(classOrInterfaceDeclarationMetaModel, "typeParameters", com.github.javaparser.ast.type.TypeParameter.class, Optional.of(typeParameterMetaModel), false, false, true, false, false);
+ classOrInterfaceDeclarationMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceDeclarationMetaModel.typeParametersPropertyMetaModel);
+ constructorDeclarationMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(constructorDeclarationMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false);
+ constructorDeclarationMetaModel.getDeclaredPropertyMetaModels().add(constructorDeclarationMetaModel.bodyPropertyMetaModel);
+ enumConstantDeclarationMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(enumConstantDeclarationMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false);
+ enumConstantDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumConstantDeclarationMetaModel.argumentsPropertyMetaModel);
+ enumConstantDeclarationMetaModel.classBodyPropertyMetaModel = new PropertyMetaModel(enumConstantDeclarationMetaModel, "classBody", com.github.javaparser.ast.body.BodyDeclaration.class, Optional.of(bodyDeclarationMetaModel), false, false, true, false, true);
+ enumConstantDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumConstantDeclarationMetaModel.classBodyPropertyMetaModel);
+ enumConstantDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(enumConstantDeclarationMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ enumConstantDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumConstantDeclarationMetaModel.namePropertyMetaModel);
+ enumDeclarationMetaModel.entriesPropertyMetaModel = new PropertyMetaModel(enumDeclarationMetaModel, "entries", com.github.javaparser.ast.body.EnumConstantDeclaration.class, Optional.of(enumConstantDeclarationMetaModel), false, false, true, false, false);
+ enumDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumDeclarationMetaModel.entriesPropertyMetaModel);
+ enumDeclarationMetaModel.implementedTypesPropertyMetaModel = new PropertyMetaModel(enumDeclarationMetaModel, "implementedTypes", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, true, false, false);
+ enumDeclarationMetaModel.getDeclaredPropertyMetaModels().add(enumDeclarationMetaModel.implementedTypesPropertyMetaModel);
+ fieldDeclarationMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(fieldDeclarationMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false);
+ fieldDeclarationMetaModel.getDeclaredPropertyMetaModels().add(fieldDeclarationMetaModel.modifiersPropertyMetaModel);
+ fieldDeclarationMetaModel.variablesPropertyMetaModel = new PropertyMetaModel(fieldDeclarationMetaModel, "variables", com.github.javaparser.ast.body.VariableDeclarator.class, Optional.of(variableDeclaratorMetaModel), false, true, true, false, false);
+ fieldDeclarationMetaModel.getDeclaredPropertyMetaModels().add(fieldDeclarationMetaModel.variablesPropertyMetaModel);
+ fieldDeclarationMetaModel.maximumCommonTypePropertyMetaModel = new PropertyMetaModel(fieldDeclarationMetaModel, "maximumCommonType", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, false, false, false);
+ fieldDeclarationMetaModel.getDerivedPropertyMetaModels().add(fieldDeclarationMetaModel.maximumCommonTypePropertyMetaModel);
+ initializerDeclarationMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(initializerDeclarationMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false);
+ initializerDeclarationMetaModel.getDeclaredPropertyMetaModels().add(initializerDeclarationMetaModel.bodyPropertyMetaModel);
+ initializerDeclarationMetaModel.isStaticPropertyMetaModel = new PropertyMetaModel(initializerDeclarationMetaModel, "isStatic", boolean.class, Optional.empty(), false, false, false, false, false);
+ initializerDeclarationMetaModel.getDeclaredPropertyMetaModels().add(initializerDeclarationMetaModel.isStaticPropertyMetaModel);
+ methodDeclarationMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(methodDeclarationMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), true, false, false, false, false);
+ methodDeclarationMetaModel.getDeclaredPropertyMetaModels().add(methodDeclarationMetaModel.bodyPropertyMetaModel);
+ methodDeclarationMetaModel.typePropertyMetaModel = new PropertyMetaModel(methodDeclarationMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ methodDeclarationMetaModel.getDeclaredPropertyMetaModels().add(methodDeclarationMetaModel.typePropertyMetaModel);
+ parameterMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.annotationsPropertyMetaModel);
+ parameterMetaModel.isVarArgsPropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "isVarArgs", boolean.class, Optional.empty(), false, false, false, false, false);
+ parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.isVarArgsPropertyMetaModel);
+ parameterMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false);
+ parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.modifiersPropertyMetaModel);
+ parameterMetaModel.namePropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.namePropertyMetaModel);
+ parameterMetaModel.typePropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.typePropertyMetaModel);
+ parameterMetaModel.varArgsAnnotationsPropertyMetaModel = new PropertyMetaModel(parameterMetaModel, "varArgsAnnotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ parameterMetaModel.getDeclaredPropertyMetaModels().add(parameterMetaModel.varArgsAnnotationsPropertyMetaModel);
+ receiverParameterMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(receiverParameterMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ receiverParameterMetaModel.getDeclaredPropertyMetaModels().add(receiverParameterMetaModel.annotationsPropertyMetaModel);
+ receiverParameterMetaModel.namePropertyMetaModel = new PropertyMetaModel(receiverParameterMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false);
+ receiverParameterMetaModel.getDeclaredPropertyMetaModels().add(receiverParameterMetaModel.namePropertyMetaModel);
+ receiverParameterMetaModel.typePropertyMetaModel = new PropertyMetaModel(receiverParameterMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ receiverParameterMetaModel.getDeclaredPropertyMetaModels().add(receiverParameterMetaModel.typePropertyMetaModel);
+ variableDeclaratorMetaModel.initializerPropertyMetaModel = new PropertyMetaModel(variableDeclaratorMetaModel, "initializer", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, true, false, false, false);
+ variableDeclaratorMetaModel.getDeclaredPropertyMetaModels().add(variableDeclaratorMetaModel.initializerPropertyMetaModel);
+ variableDeclaratorMetaModel.namePropertyMetaModel = new PropertyMetaModel(variableDeclaratorMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ variableDeclaratorMetaModel.getDeclaredPropertyMetaModels().add(variableDeclaratorMetaModel.namePropertyMetaModel);
+ variableDeclaratorMetaModel.typePropertyMetaModel = new PropertyMetaModel(variableDeclaratorMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ variableDeclaratorMetaModel.getDeclaredPropertyMetaModels().add(variableDeclaratorMetaModel.typePropertyMetaModel);
+ commentMetaModel.contentPropertyMetaModel = new PropertyMetaModel(commentMetaModel, "content", java.lang.String.class, Optional.empty(), false, false, false, false, false);
+ commentMetaModel.getDeclaredPropertyMetaModels().add(commentMetaModel.contentPropertyMetaModel);
+ arrayAccessExprMetaModel.indexPropertyMetaModel = new PropertyMetaModel(arrayAccessExprMetaModel, "index", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ arrayAccessExprMetaModel.getDeclaredPropertyMetaModels().add(arrayAccessExprMetaModel.indexPropertyMetaModel);
+ arrayAccessExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(arrayAccessExprMetaModel, "name", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ arrayAccessExprMetaModel.getDeclaredPropertyMetaModels().add(arrayAccessExprMetaModel.namePropertyMetaModel);
+ arrayCreationExprMetaModel.elementTypePropertyMetaModel = new PropertyMetaModel(arrayCreationExprMetaModel, "elementType", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ arrayCreationExprMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationExprMetaModel.elementTypePropertyMetaModel);
+ arrayCreationExprMetaModel.initializerPropertyMetaModel = new PropertyMetaModel(arrayCreationExprMetaModel, "initializer", com.github.javaparser.ast.expr.ArrayInitializerExpr.class, Optional.of(arrayInitializerExprMetaModel), true, false, false, false, false);
+ arrayCreationExprMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationExprMetaModel.initializerPropertyMetaModel);
+ arrayCreationExprMetaModel.levelsPropertyMetaModel = new PropertyMetaModel(arrayCreationExprMetaModel, "levels", com.github.javaparser.ast.ArrayCreationLevel.class, Optional.of(arrayCreationLevelMetaModel), false, true, true, false, false);
+ arrayCreationExprMetaModel.getDeclaredPropertyMetaModels().add(arrayCreationExprMetaModel.levelsPropertyMetaModel);
+ arrayInitializerExprMetaModel.valuesPropertyMetaModel = new PropertyMetaModel(arrayInitializerExprMetaModel, "values", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false);
+ arrayInitializerExprMetaModel.getDeclaredPropertyMetaModels().add(arrayInitializerExprMetaModel.valuesPropertyMetaModel);
+ assignExprMetaModel.operatorPropertyMetaModel = new PropertyMetaModel(assignExprMetaModel, "operator", com.github.javaparser.ast.expr.AssignExpr.Operator.class, Optional.empty(), false, false, false, false, false);
+ assignExprMetaModel.getDeclaredPropertyMetaModels().add(assignExprMetaModel.operatorPropertyMetaModel);
+ assignExprMetaModel.targetPropertyMetaModel = new PropertyMetaModel(assignExprMetaModel, "target", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ assignExprMetaModel.getDeclaredPropertyMetaModels().add(assignExprMetaModel.targetPropertyMetaModel);
+ assignExprMetaModel.valuePropertyMetaModel = new PropertyMetaModel(assignExprMetaModel, "value", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ assignExprMetaModel.getDeclaredPropertyMetaModels().add(assignExprMetaModel.valuePropertyMetaModel);
+ binaryExprMetaModel.leftPropertyMetaModel = new PropertyMetaModel(binaryExprMetaModel, "left", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ binaryExprMetaModel.getDeclaredPropertyMetaModels().add(binaryExprMetaModel.leftPropertyMetaModel);
+ binaryExprMetaModel.operatorPropertyMetaModel = new PropertyMetaModel(binaryExprMetaModel, "operator", com.github.javaparser.ast.expr.BinaryExpr.Operator.class, Optional.empty(), false, false, false, false, false);
+ binaryExprMetaModel.getDeclaredPropertyMetaModels().add(binaryExprMetaModel.operatorPropertyMetaModel);
+ binaryExprMetaModel.rightPropertyMetaModel = new PropertyMetaModel(binaryExprMetaModel, "right", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ binaryExprMetaModel.getDeclaredPropertyMetaModels().add(binaryExprMetaModel.rightPropertyMetaModel);
+ booleanLiteralExprMetaModel.valuePropertyMetaModel = new PropertyMetaModel(booleanLiteralExprMetaModel, "value", boolean.class, Optional.empty(), false, false, false, false, false);
+ booleanLiteralExprMetaModel.getDeclaredPropertyMetaModels().add(booleanLiteralExprMetaModel.valuePropertyMetaModel);
+ castExprMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(castExprMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ castExprMetaModel.getDeclaredPropertyMetaModels().add(castExprMetaModel.expressionPropertyMetaModel);
+ castExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(castExprMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ castExprMetaModel.getDeclaredPropertyMetaModels().add(castExprMetaModel.typePropertyMetaModel);
+ classExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(classExprMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ classExprMetaModel.getDeclaredPropertyMetaModels().add(classExprMetaModel.typePropertyMetaModel);
+ conditionalExprMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(conditionalExprMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ conditionalExprMetaModel.getDeclaredPropertyMetaModels().add(conditionalExprMetaModel.conditionPropertyMetaModel);
+ conditionalExprMetaModel.elseExprPropertyMetaModel = new PropertyMetaModel(conditionalExprMetaModel, "elseExpr", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ conditionalExprMetaModel.getDeclaredPropertyMetaModels().add(conditionalExprMetaModel.elseExprPropertyMetaModel);
+ conditionalExprMetaModel.thenExprPropertyMetaModel = new PropertyMetaModel(conditionalExprMetaModel, "thenExpr", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ conditionalExprMetaModel.getDeclaredPropertyMetaModels().add(conditionalExprMetaModel.thenExprPropertyMetaModel);
+ enclosedExprMetaModel.innerPropertyMetaModel = new PropertyMetaModel(enclosedExprMetaModel, "inner", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ enclosedExprMetaModel.getDeclaredPropertyMetaModels().add(enclosedExprMetaModel.innerPropertyMetaModel);
+ fieldAccessExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(fieldAccessExprMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ fieldAccessExprMetaModel.getDeclaredPropertyMetaModels().add(fieldAccessExprMetaModel.namePropertyMetaModel);
+ fieldAccessExprMetaModel.scopePropertyMetaModel = new PropertyMetaModel(fieldAccessExprMetaModel, "scope", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ fieldAccessExprMetaModel.getDeclaredPropertyMetaModels().add(fieldAccessExprMetaModel.scopePropertyMetaModel);
+ fieldAccessExprMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(fieldAccessExprMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false);
+ fieldAccessExprMetaModel.getDeclaredPropertyMetaModels().add(fieldAccessExprMetaModel.typeArgumentsPropertyMetaModel);
+ fieldAccessExprMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(fieldAccessExprMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false);
+ fieldAccessExprMetaModel.getDerivedPropertyMetaModels().add(fieldAccessExprMetaModel.usingDiamondOperatorPropertyMetaModel);
+ instanceOfExprMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(instanceOfExprMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ instanceOfExprMetaModel.getDeclaredPropertyMetaModels().add(instanceOfExprMetaModel.expressionPropertyMetaModel);
+ instanceOfExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(instanceOfExprMetaModel, "type", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), false, false, false, false, false);
+ instanceOfExprMetaModel.getDeclaredPropertyMetaModels().add(instanceOfExprMetaModel.typePropertyMetaModel);
+ lambdaExprMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false);
+ lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.bodyPropertyMetaModel);
+ lambdaExprMetaModel.isEnclosingParametersPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "isEnclosingParameters", boolean.class, Optional.empty(), false, false, false, false, false);
+ lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.isEnclosingParametersPropertyMetaModel);
+ lambdaExprMetaModel.parametersPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "parameters", com.github.javaparser.ast.body.Parameter.class, Optional.of(parameterMetaModel), false, false, true, false, false);
+ lambdaExprMetaModel.getDeclaredPropertyMetaModels().add(lambdaExprMetaModel.parametersPropertyMetaModel);
+ lambdaExprMetaModel.expressionBodyPropertyMetaModel = new PropertyMetaModel(lambdaExprMetaModel, "expressionBody", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ lambdaExprMetaModel.getDerivedPropertyMetaModels().add(lambdaExprMetaModel.expressionBodyPropertyMetaModel);
+ memberValuePairMetaModel.namePropertyMetaModel = new PropertyMetaModel(memberValuePairMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ memberValuePairMetaModel.getDeclaredPropertyMetaModels().add(memberValuePairMetaModel.namePropertyMetaModel);
+ memberValuePairMetaModel.valuePropertyMetaModel = new PropertyMetaModel(memberValuePairMetaModel, "value", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ memberValuePairMetaModel.getDeclaredPropertyMetaModels().add(memberValuePairMetaModel.valuePropertyMetaModel);
+ methodCallExprMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false);
+ methodCallExprMetaModel.getDeclaredPropertyMetaModels().add(methodCallExprMetaModel.argumentsPropertyMetaModel);
+ methodCallExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ methodCallExprMetaModel.getDeclaredPropertyMetaModels().add(methodCallExprMetaModel.namePropertyMetaModel);
+ methodCallExprMetaModel.scopePropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "scope", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ methodCallExprMetaModel.getDeclaredPropertyMetaModels().add(methodCallExprMetaModel.scopePropertyMetaModel);
+ methodCallExprMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false);
+ methodCallExprMetaModel.getDeclaredPropertyMetaModels().add(methodCallExprMetaModel.typeArgumentsPropertyMetaModel);
+ methodCallExprMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(methodCallExprMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false);
+ methodCallExprMetaModel.getDerivedPropertyMetaModels().add(methodCallExprMetaModel.usingDiamondOperatorPropertyMetaModel);
+ methodReferenceExprMetaModel.identifierPropertyMetaModel = new PropertyMetaModel(methodReferenceExprMetaModel, "identifier", java.lang.String.class, Optional.empty(), false, true, false, false, false);
+ methodReferenceExprMetaModel.getDeclaredPropertyMetaModels().add(methodReferenceExprMetaModel.identifierPropertyMetaModel);
+ methodReferenceExprMetaModel.scopePropertyMetaModel = new PropertyMetaModel(methodReferenceExprMetaModel, "scope", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ methodReferenceExprMetaModel.getDeclaredPropertyMetaModels().add(methodReferenceExprMetaModel.scopePropertyMetaModel);
+ methodReferenceExprMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(methodReferenceExprMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false);
+ methodReferenceExprMetaModel.getDeclaredPropertyMetaModels().add(methodReferenceExprMetaModel.typeArgumentsPropertyMetaModel);
+ methodReferenceExprMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(methodReferenceExprMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false);
+ methodReferenceExprMetaModel.getDerivedPropertyMetaModels().add(methodReferenceExprMetaModel.usingDiamondOperatorPropertyMetaModel);
+ nameExprMetaModel.namePropertyMetaModel = new PropertyMetaModel(nameExprMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ nameExprMetaModel.getDeclaredPropertyMetaModels().add(nameExprMetaModel.namePropertyMetaModel);
+ nameMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(nameMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ nameMetaModel.getDeclaredPropertyMetaModels().add(nameMetaModel.annotationsPropertyMetaModel);
+ nameMetaModel.identifierPropertyMetaModel = new PropertyMetaModel(nameMetaModel, "identifier", java.lang.String.class, Optional.empty(), false, true, false, false, false);
+ nameMetaModel.getDeclaredPropertyMetaModels().add(nameMetaModel.identifierPropertyMetaModel);
+ nameMetaModel.qualifierPropertyMetaModel = new PropertyMetaModel(nameMetaModel, "qualifier", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), true, false, false, false, false);
+ nameMetaModel.getDeclaredPropertyMetaModels().add(nameMetaModel.qualifierPropertyMetaModel);
+ normalAnnotationExprMetaModel.pairsPropertyMetaModel = new PropertyMetaModel(normalAnnotationExprMetaModel, "pairs", com.github.javaparser.ast.expr.MemberValuePair.class, Optional.of(memberValuePairMetaModel), false, false, true, false, false);
+ normalAnnotationExprMetaModel.getDeclaredPropertyMetaModels().add(normalAnnotationExprMetaModel.pairsPropertyMetaModel);
+ objectCreationExprMetaModel.anonymousClassBodyPropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "anonymousClassBody", com.github.javaparser.ast.body.BodyDeclaration.class, Optional.of(bodyDeclarationMetaModel), true, false, true, false, true);
+ objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.anonymousClassBodyPropertyMetaModel);
+ objectCreationExprMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false);
+ objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.argumentsPropertyMetaModel);
+ objectCreationExprMetaModel.scopePropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "scope", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.scopePropertyMetaModel);
+ objectCreationExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "type", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, false, false, false);
+ objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.typePropertyMetaModel);
+ objectCreationExprMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false);
+ objectCreationExprMetaModel.getDeclaredPropertyMetaModels().add(objectCreationExprMetaModel.typeArgumentsPropertyMetaModel);
+ objectCreationExprMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(objectCreationExprMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false);
+ objectCreationExprMetaModel.getDerivedPropertyMetaModels().add(objectCreationExprMetaModel.usingDiamondOperatorPropertyMetaModel);
+ simpleNameMetaModel.identifierPropertyMetaModel = new PropertyMetaModel(simpleNameMetaModel, "identifier", java.lang.String.class, Optional.empty(), false, true, false, false, false);
+ simpleNameMetaModel.getDeclaredPropertyMetaModels().add(simpleNameMetaModel.identifierPropertyMetaModel);
+ singleMemberAnnotationExprMetaModel.memberValuePropertyMetaModel = new PropertyMetaModel(singleMemberAnnotationExprMetaModel, "memberValue", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ singleMemberAnnotationExprMetaModel.getDeclaredPropertyMetaModels().add(singleMemberAnnotationExprMetaModel.memberValuePropertyMetaModel);
+ superExprMetaModel.classExprPropertyMetaModel = new PropertyMetaModel(superExprMetaModel, "classExpr", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ superExprMetaModel.getDeclaredPropertyMetaModels().add(superExprMetaModel.classExprPropertyMetaModel);
+ thisExprMetaModel.classExprPropertyMetaModel = new PropertyMetaModel(thisExprMetaModel, "classExpr", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ thisExprMetaModel.getDeclaredPropertyMetaModels().add(thisExprMetaModel.classExprPropertyMetaModel);
+ typeExprMetaModel.typePropertyMetaModel = new PropertyMetaModel(typeExprMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ typeExprMetaModel.getDeclaredPropertyMetaModels().add(typeExprMetaModel.typePropertyMetaModel);
+ unaryExprMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(unaryExprMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ unaryExprMetaModel.getDeclaredPropertyMetaModels().add(unaryExprMetaModel.expressionPropertyMetaModel);
+ unaryExprMetaModel.operatorPropertyMetaModel = new PropertyMetaModel(unaryExprMetaModel, "operator", com.github.javaparser.ast.expr.UnaryExpr.Operator.class, Optional.empty(), false, false, false, false, false);
+ unaryExprMetaModel.getDeclaredPropertyMetaModels().add(unaryExprMetaModel.operatorPropertyMetaModel);
+ unaryExprMetaModel.postfixPropertyMetaModel = new PropertyMetaModel(unaryExprMetaModel, "postfix", boolean.class, Optional.empty(), false, false, false, false, false);
+ unaryExprMetaModel.getDerivedPropertyMetaModels().add(unaryExprMetaModel.postfixPropertyMetaModel);
+ unaryExprMetaModel.prefixPropertyMetaModel = new PropertyMetaModel(unaryExprMetaModel, "prefix", boolean.class, Optional.empty(), false, false, false, false, false);
+ unaryExprMetaModel.getDerivedPropertyMetaModels().add(unaryExprMetaModel.prefixPropertyMetaModel);
+ variableDeclarationExprMetaModel.annotationsPropertyMetaModel = new PropertyMetaModel(variableDeclarationExprMetaModel, "annotations", com.github.javaparser.ast.expr.AnnotationExpr.class, Optional.of(annotationExprMetaModel), false, false, true, false, false);
+ variableDeclarationExprMetaModel.getDeclaredPropertyMetaModels().add(variableDeclarationExprMetaModel.annotationsPropertyMetaModel);
+ variableDeclarationExprMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(variableDeclarationExprMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false);
+ variableDeclarationExprMetaModel.getDeclaredPropertyMetaModels().add(variableDeclarationExprMetaModel.modifiersPropertyMetaModel);
+ variableDeclarationExprMetaModel.variablesPropertyMetaModel = new PropertyMetaModel(variableDeclarationExprMetaModel, "variables", com.github.javaparser.ast.body.VariableDeclarator.class, Optional.of(variableDeclaratorMetaModel), false, true, true, false, false);
+ variableDeclarationExprMetaModel.getDeclaredPropertyMetaModels().add(variableDeclarationExprMetaModel.variablesPropertyMetaModel);
+ variableDeclarationExprMetaModel.maximumCommonTypePropertyMetaModel = new PropertyMetaModel(variableDeclarationExprMetaModel, "maximumCommonType", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, false, false, false);
+ variableDeclarationExprMetaModel.getDerivedPropertyMetaModels().add(variableDeclarationExprMetaModel.maximumCommonTypePropertyMetaModel);
+ importDeclarationMetaModel.isAsteriskPropertyMetaModel = new PropertyMetaModel(importDeclarationMetaModel, "isAsterisk", boolean.class, Optional.empty(), false, false, false, false, false);
+ importDeclarationMetaModel.getDeclaredPropertyMetaModels().add(importDeclarationMetaModel.isAsteriskPropertyMetaModel);
+ importDeclarationMetaModel.isStaticPropertyMetaModel = new PropertyMetaModel(importDeclarationMetaModel, "isStatic", boolean.class, Optional.empty(), false, false, false, false, false);
+ importDeclarationMetaModel.getDeclaredPropertyMetaModels().add(importDeclarationMetaModel.isStaticPropertyMetaModel);
+ importDeclarationMetaModel.namePropertyMetaModel = new PropertyMetaModel(importDeclarationMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false);
+ importDeclarationMetaModel.getDeclaredPropertyMetaModels().add(importDeclarationMetaModel.namePropertyMetaModel);
+ assertStmtMetaModel.checkPropertyMetaModel = new PropertyMetaModel(assertStmtMetaModel, "check", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ assertStmtMetaModel.getDeclaredPropertyMetaModels().add(assertStmtMetaModel.checkPropertyMetaModel);
+ assertStmtMetaModel.messagePropertyMetaModel = new PropertyMetaModel(assertStmtMetaModel, "message", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ assertStmtMetaModel.getDeclaredPropertyMetaModels().add(assertStmtMetaModel.messagePropertyMetaModel);
+ blockStmtMetaModel.statementsPropertyMetaModel = new PropertyMetaModel(blockStmtMetaModel, "statements", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, true, false, false);
+ blockStmtMetaModel.getDeclaredPropertyMetaModels().add(blockStmtMetaModel.statementsPropertyMetaModel);
+ breakStmtMetaModel.labelPropertyMetaModel = new PropertyMetaModel(breakStmtMetaModel, "label", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), true, false, false, false, false);
+ breakStmtMetaModel.getDeclaredPropertyMetaModels().add(breakStmtMetaModel.labelPropertyMetaModel);
+ catchClauseMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(catchClauseMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false);
+ catchClauseMetaModel.getDeclaredPropertyMetaModels().add(catchClauseMetaModel.bodyPropertyMetaModel);
+ catchClauseMetaModel.parameterPropertyMetaModel = new PropertyMetaModel(catchClauseMetaModel, "parameter", com.github.javaparser.ast.body.Parameter.class, Optional.of(parameterMetaModel), false, false, false, false, false);
+ catchClauseMetaModel.getDeclaredPropertyMetaModels().add(catchClauseMetaModel.parameterPropertyMetaModel);
+ continueStmtMetaModel.labelPropertyMetaModel = new PropertyMetaModel(continueStmtMetaModel, "label", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), true, false, false, false, false);
+ continueStmtMetaModel.getDeclaredPropertyMetaModels().add(continueStmtMetaModel.labelPropertyMetaModel);
+ doStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(doStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false);
+ doStmtMetaModel.getDeclaredPropertyMetaModels().add(doStmtMetaModel.bodyPropertyMetaModel);
+ doStmtMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(doStmtMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ doStmtMetaModel.getDeclaredPropertyMetaModels().add(doStmtMetaModel.conditionPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.argumentsPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "arguments", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false);
+ explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.argumentsPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.expressionPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.isThisPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "isThis", boolean.class, Optional.empty(), false, false, false, false, false);
+ explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.isThisPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false);
+ explicitConstructorInvocationStmtMetaModel.getDeclaredPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.typeArgumentsPropertyMetaModel);
+ explicitConstructorInvocationStmtMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(explicitConstructorInvocationStmtMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false);
+ explicitConstructorInvocationStmtMetaModel.getDerivedPropertyMetaModels().add(explicitConstructorInvocationStmtMetaModel.usingDiamondOperatorPropertyMetaModel);
+ expressionStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(expressionStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ expressionStmtMetaModel.getDeclaredPropertyMetaModels().add(expressionStmtMetaModel.expressionPropertyMetaModel);
+ foreachStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(foreachStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false);
+ foreachStmtMetaModel.getDeclaredPropertyMetaModels().add(foreachStmtMetaModel.bodyPropertyMetaModel);
+ foreachStmtMetaModel.iterablePropertyMetaModel = new PropertyMetaModel(foreachStmtMetaModel, "iterable", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ foreachStmtMetaModel.getDeclaredPropertyMetaModels().add(foreachStmtMetaModel.iterablePropertyMetaModel);
+ foreachStmtMetaModel.variablePropertyMetaModel = new PropertyMetaModel(foreachStmtMetaModel, "variable", com.github.javaparser.ast.expr.VariableDeclarationExpr.class, Optional.of(variableDeclarationExprMetaModel), false, false, false, false, false);
+ foreachStmtMetaModel.getDeclaredPropertyMetaModels().add(foreachStmtMetaModel.variablePropertyMetaModel);
+ forStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false);
+ forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.bodyPropertyMetaModel);
+ forStmtMetaModel.comparePropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "compare", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.comparePropertyMetaModel);
+ forStmtMetaModel.initializationPropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "initialization", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false);
+ forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.initializationPropertyMetaModel);
+ forStmtMetaModel.updatePropertyMetaModel = new PropertyMetaModel(forStmtMetaModel, "update", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false);
+ forStmtMetaModel.getDeclaredPropertyMetaModels().add(forStmtMetaModel.updatePropertyMetaModel);
+ ifStmtMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ ifStmtMetaModel.getDeclaredPropertyMetaModels().add(ifStmtMetaModel.conditionPropertyMetaModel);
+ ifStmtMetaModel.elseStmtPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "elseStmt", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), true, false, false, false, false);
+ ifStmtMetaModel.getDeclaredPropertyMetaModels().add(ifStmtMetaModel.elseStmtPropertyMetaModel);
+ ifStmtMetaModel.thenStmtPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "thenStmt", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false);
+ ifStmtMetaModel.getDeclaredPropertyMetaModels().add(ifStmtMetaModel.thenStmtPropertyMetaModel);
+ ifStmtMetaModel.cascadingIfStmtPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "cascadingIfStmt", boolean.class, Optional.empty(), false, false, false, false, false);
+ ifStmtMetaModel.getDerivedPropertyMetaModels().add(ifStmtMetaModel.cascadingIfStmtPropertyMetaModel);
+ ifStmtMetaModel.elseBlockPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "elseBlock", boolean.class, Optional.empty(), false, false, false, false, false);
+ ifStmtMetaModel.getDerivedPropertyMetaModels().add(ifStmtMetaModel.elseBlockPropertyMetaModel);
+ ifStmtMetaModel.elseBranchPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "elseBranch", boolean.class, Optional.empty(), false, false, false, false, false);
+ ifStmtMetaModel.getDerivedPropertyMetaModels().add(ifStmtMetaModel.elseBranchPropertyMetaModel);
+ ifStmtMetaModel.thenBlockPropertyMetaModel = new PropertyMetaModel(ifStmtMetaModel, "thenBlock", boolean.class, Optional.empty(), false, false, false, false, false);
+ ifStmtMetaModel.getDerivedPropertyMetaModels().add(ifStmtMetaModel.thenBlockPropertyMetaModel);
+ labeledStmtMetaModel.labelPropertyMetaModel = new PropertyMetaModel(labeledStmtMetaModel, "label", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ labeledStmtMetaModel.getDeclaredPropertyMetaModels().add(labeledStmtMetaModel.labelPropertyMetaModel);
+ labeledStmtMetaModel.statementPropertyMetaModel = new PropertyMetaModel(labeledStmtMetaModel, "statement", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false);
+ labeledStmtMetaModel.getDeclaredPropertyMetaModels().add(labeledStmtMetaModel.statementPropertyMetaModel);
+ returnStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(returnStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ returnStmtMetaModel.getDeclaredPropertyMetaModels().add(returnStmtMetaModel.expressionPropertyMetaModel);
+ switchEntryStmtMetaModel.labelPropertyMetaModel = new PropertyMetaModel(switchEntryStmtMetaModel, "label", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), true, false, false, false, false);
+ switchEntryStmtMetaModel.getDeclaredPropertyMetaModels().add(switchEntryStmtMetaModel.labelPropertyMetaModel);
+ switchEntryStmtMetaModel.statementsPropertyMetaModel = new PropertyMetaModel(switchEntryStmtMetaModel, "statements", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, true, false, false);
+ switchEntryStmtMetaModel.getDeclaredPropertyMetaModels().add(switchEntryStmtMetaModel.statementsPropertyMetaModel);
+ switchStmtMetaModel.entriesPropertyMetaModel = new PropertyMetaModel(switchStmtMetaModel, "entries", com.github.javaparser.ast.stmt.SwitchEntryStmt.class, Optional.of(switchEntryStmtMetaModel), false, false, true, false, false);
+ switchStmtMetaModel.getDeclaredPropertyMetaModels().add(switchStmtMetaModel.entriesPropertyMetaModel);
+ switchStmtMetaModel.selectorPropertyMetaModel = new PropertyMetaModel(switchStmtMetaModel, "selector", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ switchStmtMetaModel.getDeclaredPropertyMetaModels().add(switchStmtMetaModel.selectorPropertyMetaModel);
+ synchronizedStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(synchronizedStmtMetaModel, "body", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false);
+ synchronizedStmtMetaModel.getDeclaredPropertyMetaModels().add(synchronizedStmtMetaModel.bodyPropertyMetaModel);
+ synchronizedStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(synchronizedStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ synchronizedStmtMetaModel.getDeclaredPropertyMetaModels().add(synchronizedStmtMetaModel.expressionPropertyMetaModel);
+ throwStmtMetaModel.expressionPropertyMetaModel = new PropertyMetaModel(throwStmtMetaModel, "expression", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ throwStmtMetaModel.getDeclaredPropertyMetaModels().add(throwStmtMetaModel.expressionPropertyMetaModel);
+ tryStmtMetaModel.catchClausesPropertyMetaModel = new PropertyMetaModel(tryStmtMetaModel, "catchClauses", com.github.javaparser.ast.stmt.CatchClause.class, Optional.of(catchClauseMetaModel), false, false, true, false, false);
+ tryStmtMetaModel.getDeclaredPropertyMetaModels().add(tryStmtMetaModel.catchClausesPropertyMetaModel);
+ tryStmtMetaModel.finallyBlockPropertyMetaModel = new PropertyMetaModel(tryStmtMetaModel, "finallyBlock", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), true, false, false, false, false);
+ tryStmtMetaModel.getDeclaredPropertyMetaModels().add(tryStmtMetaModel.finallyBlockPropertyMetaModel);
+ tryStmtMetaModel.resourcesPropertyMetaModel = new PropertyMetaModel(tryStmtMetaModel, "resources", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, true, false, false);
+ tryStmtMetaModel.getDeclaredPropertyMetaModels().add(tryStmtMetaModel.resourcesPropertyMetaModel);
+ tryStmtMetaModel.tryBlockPropertyMetaModel = new PropertyMetaModel(tryStmtMetaModel, "tryBlock", com.github.javaparser.ast.stmt.BlockStmt.class, Optional.of(blockStmtMetaModel), false, false, false, false, false);
+ tryStmtMetaModel.getDeclaredPropertyMetaModels().add(tryStmtMetaModel.tryBlockPropertyMetaModel);
+ localClassDeclarationStmtMetaModel.classDeclarationPropertyMetaModel = new PropertyMetaModel(localClassDeclarationStmtMetaModel, "classDeclaration", com.github.javaparser.ast.body.ClassOrInterfaceDeclaration.class, Optional.of(classOrInterfaceDeclarationMetaModel), false, false, false, false, false);
+ localClassDeclarationStmtMetaModel.getDeclaredPropertyMetaModels().add(localClassDeclarationStmtMetaModel.classDeclarationPropertyMetaModel);
+ whileStmtMetaModel.bodyPropertyMetaModel = new PropertyMetaModel(whileStmtMetaModel, "body", com.github.javaparser.ast.stmt.Statement.class, Optional.of(statementMetaModel), false, false, false, false, false);
+ whileStmtMetaModel.getDeclaredPropertyMetaModels().add(whileStmtMetaModel.bodyPropertyMetaModel);
+ whileStmtMetaModel.conditionPropertyMetaModel = new PropertyMetaModel(whileStmtMetaModel, "condition", com.github.javaparser.ast.expr.Expression.class, Optional.of(expressionMetaModel), false, false, false, false, false);
+ whileStmtMetaModel.getDeclaredPropertyMetaModels().add(whileStmtMetaModel.conditionPropertyMetaModel);
+ arrayTypeMetaModel.componentTypePropertyMetaModel = new PropertyMetaModel(arrayTypeMetaModel, "componentType", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ arrayTypeMetaModel.getDeclaredPropertyMetaModels().add(arrayTypeMetaModel.componentTypePropertyMetaModel);
+ arrayTypeMetaModel.originPropertyMetaModel = new PropertyMetaModel(arrayTypeMetaModel, "origin", com.github.javaparser.ast.type.ArrayType.Origin.class, Optional.empty(), false, false, false, false, false);
+ arrayTypeMetaModel.getDeclaredPropertyMetaModels().add(arrayTypeMetaModel.originPropertyMetaModel);
+ classOrInterfaceTypeMetaModel.namePropertyMetaModel = new PropertyMetaModel(classOrInterfaceTypeMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ classOrInterfaceTypeMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceTypeMetaModel.namePropertyMetaModel);
+ classOrInterfaceTypeMetaModel.scopePropertyMetaModel = new PropertyMetaModel(classOrInterfaceTypeMetaModel, "scope", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), true, false, false, false, false);
+ classOrInterfaceTypeMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceTypeMetaModel.scopePropertyMetaModel);
+ classOrInterfaceTypeMetaModel.typeArgumentsPropertyMetaModel = new PropertyMetaModel(classOrInterfaceTypeMetaModel, "typeArguments", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), true, false, true, false, false);
+ classOrInterfaceTypeMetaModel.getDeclaredPropertyMetaModels().add(classOrInterfaceTypeMetaModel.typeArgumentsPropertyMetaModel);
+ classOrInterfaceTypeMetaModel.usingDiamondOperatorPropertyMetaModel = new PropertyMetaModel(classOrInterfaceTypeMetaModel, "usingDiamondOperator", boolean.class, Optional.empty(), false, false, false, false, false);
+ classOrInterfaceTypeMetaModel.getDerivedPropertyMetaModels().add(classOrInterfaceTypeMetaModel.usingDiamondOperatorPropertyMetaModel);
+ intersectionTypeMetaModel.elementsPropertyMetaModel = new PropertyMetaModel(intersectionTypeMetaModel, "elements", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), false, true, true, false, false);
+ intersectionTypeMetaModel.getDeclaredPropertyMetaModels().add(intersectionTypeMetaModel.elementsPropertyMetaModel);
+ primitiveTypeMetaModel.typePropertyMetaModel = new PropertyMetaModel(primitiveTypeMetaModel, "type", com.github.javaparser.ast.type.PrimitiveType.Primitive.class, Optional.empty(), false, false, false, false, false);
+ primitiveTypeMetaModel.getDeclaredPropertyMetaModels().add(primitiveTypeMetaModel.typePropertyMetaModel);
+ typeParameterMetaModel.namePropertyMetaModel = new PropertyMetaModel(typeParameterMetaModel, "name", com.github.javaparser.ast.expr.SimpleName.class, Optional.of(simpleNameMetaModel), false, false, false, false, false);
+ typeParameterMetaModel.getDeclaredPropertyMetaModels().add(typeParameterMetaModel.namePropertyMetaModel);
+ typeParameterMetaModel.typeBoundPropertyMetaModel = new PropertyMetaModel(typeParameterMetaModel, "typeBound", com.github.javaparser.ast.type.ClassOrInterfaceType.class, Optional.of(classOrInterfaceTypeMetaModel), false, false, true, false, false);
+ typeParameterMetaModel.getDeclaredPropertyMetaModels().add(typeParameterMetaModel.typeBoundPropertyMetaModel);
+ unionTypeMetaModel.elementsPropertyMetaModel = new PropertyMetaModel(unionTypeMetaModel, "elements", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), false, true, true, false, false);
+ unionTypeMetaModel.getDeclaredPropertyMetaModels().add(unionTypeMetaModel.elementsPropertyMetaModel);
+ wildcardTypeMetaModel.extendedTypePropertyMetaModel = new PropertyMetaModel(wildcardTypeMetaModel, "extendedType", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), true, false, false, false, false);
+ wildcardTypeMetaModel.getDeclaredPropertyMetaModels().add(wildcardTypeMetaModel.extendedTypePropertyMetaModel);
+ wildcardTypeMetaModel.superTypePropertyMetaModel = new PropertyMetaModel(wildcardTypeMetaModel, "superType", com.github.javaparser.ast.type.ReferenceType.class, Optional.of(referenceTypeMetaModel), true, false, false, false, false);
+ wildcardTypeMetaModel.getDeclaredPropertyMetaModels().add(wildcardTypeMetaModel.superTypePropertyMetaModel);
+ moduleRequiresStmtMetaModel.modifiersPropertyMetaModel = new PropertyMetaModel(moduleRequiresStmtMetaModel, "modifiers", com.github.javaparser.ast.Modifier.class, Optional.empty(), false, false, false, true, false);
+ moduleRequiresStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleRequiresStmtMetaModel.modifiersPropertyMetaModel);
+ moduleRequiresStmtMetaModel.namePropertyMetaModel = new PropertyMetaModel(moduleRequiresStmtMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false);
+ moduleRequiresStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleRequiresStmtMetaModel.namePropertyMetaModel);
+ moduleExportsStmtMetaModel.moduleNamesPropertyMetaModel = new PropertyMetaModel(moduleExportsStmtMetaModel, "moduleNames", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, true, false, false);
+ moduleExportsStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleExportsStmtMetaModel.moduleNamesPropertyMetaModel);
+ moduleExportsStmtMetaModel.namePropertyMetaModel = new PropertyMetaModel(moduleExportsStmtMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false);
+ moduleExportsStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleExportsStmtMetaModel.namePropertyMetaModel);
+ moduleProvidesStmtMetaModel.typePropertyMetaModel = new PropertyMetaModel(moduleProvidesStmtMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ moduleProvidesStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleProvidesStmtMetaModel.typePropertyMetaModel);
+ moduleProvidesStmtMetaModel.withTypesPropertyMetaModel = new PropertyMetaModel(moduleProvidesStmtMetaModel, "withTypes", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, true, false, false);
+ moduleProvidesStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleProvidesStmtMetaModel.withTypesPropertyMetaModel);
+ moduleUsesStmtMetaModel.typePropertyMetaModel = new PropertyMetaModel(moduleUsesStmtMetaModel, "type", com.github.javaparser.ast.type.Type.class, Optional.of(typeMetaModel), false, false, false, false, false);
+ moduleUsesStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleUsesStmtMetaModel.typePropertyMetaModel);
+ moduleOpensStmtMetaModel.moduleNamesPropertyMetaModel = new PropertyMetaModel(moduleOpensStmtMetaModel, "moduleNames", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, true, false, false);
+ moduleOpensStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleOpensStmtMetaModel.moduleNamesPropertyMetaModel);
+ moduleOpensStmtMetaModel.namePropertyMetaModel = new PropertyMetaModel(moduleOpensStmtMetaModel, "name", com.github.javaparser.ast.expr.Name.class, Optional.of(nameMetaModel), false, false, false, false, false);
+ moduleOpensStmtMetaModel.getDeclaredPropertyMetaModels().add(moduleOpensStmtMetaModel.namePropertyMetaModel);
+ }
+
+ public static Optional<BaseNodeMetaModel> getNodeMetaModel(Class<? extends Node> c) {
+ for (BaseNodeMetaModel nodeMetaModel : nodeMetaModels) {
+ if (nodeMetaModel.getTypeNameGenerified().equals(c.getSimpleName())) {
+ return Optional.of(nodeMetaModel);
+ }
+ }
+ return Optional.empty();
+ }
+
+ public static final NodeMetaModel nodeMetaModel = new NodeMetaModel(Optional.empty());
+
+ public static final BodyDeclarationMetaModel bodyDeclarationMetaModel = new BodyDeclarationMetaModel(Optional.of(nodeMetaModel));
+
+ public static final CallableDeclarationMetaModel callableDeclarationMetaModel = new CallableDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel));
+
+ public static final StatementMetaModel statementMetaModel = new StatementMetaModel(Optional.of(nodeMetaModel));
+
+ public static final ExpressionMetaModel expressionMetaModel = new ExpressionMetaModel(Optional.of(nodeMetaModel));
+
+ public static final TypeMetaModel typeMetaModel = new TypeMetaModel(Optional.of(nodeMetaModel));
+
+ public static final AnnotationExprMetaModel annotationExprMetaModel = new AnnotationExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final TypeDeclarationMetaModel typeDeclarationMetaModel = new TypeDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel));
+
+ public static final ReferenceTypeMetaModel referenceTypeMetaModel = new ReferenceTypeMetaModel(Optional.of(typeMetaModel));
+
+ public static final LiteralExprMetaModel literalExprMetaModel = new LiteralExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final LiteralStringValueExprMetaModel literalStringValueExprMetaModel = new LiteralStringValueExprMetaModel(Optional.of(literalExprMetaModel));
+
+ public static final StringLiteralExprMetaModel stringLiteralExprMetaModel = new StringLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel));
+
+ public static final ModuleDeclarationMetaModel moduleDeclarationMetaModel = new ModuleDeclarationMetaModel(Optional.of(nodeMetaModel));
+
+ public static final ModuleStmtMetaModel moduleStmtMetaModel = new ModuleStmtMetaModel(Optional.of(nodeMetaModel));
+
+ public static final ArrayCreationLevelMetaModel arrayCreationLevelMetaModel = new ArrayCreationLevelMetaModel(Optional.of(nodeMetaModel));
+
+ public static final CompilationUnitMetaModel compilationUnitMetaModel = new CompilationUnitMetaModel(Optional.of(nodeMetaModel));
+
+ public static final PackageDeclarationMetaModel packageDeclarationMetaModel = new PackageDeclarationMetaModel(Optional.of(nodeMetaModel));
+
+ public static final AnnotationDeclarationMetaModel annotationDeclarationMetaModel = new AnnotationDeclarationMetaModel(Optional.of(typeDeclarationMetaModel));
+
+ public static final AnnotationMemberDeclarationMetaModel annotationMemberDeclarationMetaModel = new AnnotationMemberDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel));
+
+ public static final ClassOrInterfaceDeclarationMetaModel classOrInterfaceDeclarationMetaModel = new ClassOrInterfaceDeclarationMetaModel(Optional.of(typeDeclarationMetaModel));
+
+ public static final ConstructorDeclarationMetaModel constructorDeclarationMetaModel = new ConstructorDeclarationMetaModel(Optional.of(callableDeclarationMetaModel));
+
+ public static final EnumConstantDeclarationMetaModel enumConstantDeclarationMetaModel = new EnumConstantDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel));
+
+ public static final EnumDeclarationMetaModel enumDeclarationMetaModel = new EnumDeclarationMetaModel(Optional.of(typeDeclarationMetaModel));
+
+ public static final FieldDeclarationMetaModel fieldDeclarationMetaModel = new FieldDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel));
+
+ public static final InitializerDeclarationMetaModel initializerDeclarationMetaModel = new InitializerDeclarationMetaModel(Optional.of(bodyDeclarationMetaModel));
+
+ public static final MethodDeclarationMetaModel methodDeclarationMetaModel = new MethodDeclarationMetaModel(Optional.of(callableDeclarationMetaModel));
+
+ public static final ParameterMetaModel parameterMetaModel = new ParameterMetaModel(Optional.of(nodeMetaModel));
+
+ public static final ReceiverParameterMetaModel receiverParameterMetaModel = new ReceiverParameterMetaModel(Optional.of(nodeMetaModel));
+
+ public static final VariableDeclaratorMetaModel variableDeclaratorMetaModel = new VariableDeclaratorMetaModel(Optional.of(nodeMetaModel));
+
+ public static final CommentMetaModel commentMetaModel = new CommentMetaModel(Optional.of(nodeMetaModel));
+
+ public static final BlockCommentMetaModel blockCommentMetaModel = new BlockCommentMetaModel(Optional.of(commentMetaModel));
+
+ public static final JavadocCommentMetaModel javadocCommentMetaModel = new JavadocCommentMetaModel(Optional.of(commentMetaModel));
+
+ public static final LineCommentMetaModel lineCommentMetaModel = new LineCommentMetaModel(Optional.of(commentMetaModel));
+
+ public static final ArrayAccessExprMetaModel arrayAccessExprMetaModel = new ArrayAccessExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final ArrayCreationExprMetaModel arrayCreationExprMetaModel = new ArrayCreationExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final ArrayInitializerExprMetaModel arrayInitializerExprMetaModel = new ArrayInitializerExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final AssignExprMetaModel assignExprMetaModel = new AssignExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final BinaryExprMetaModel binaryExprMetaModel = new BinaryExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final BooleanLiteralExprMetaModel booleanLiteralExprMetaModel = new BooleanLiteralExprMetaModel(Optional.of(literalExprMetaModel));
+
+ public static final CastExprMetaModel castExprMetaModel = new CastExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final CharLiteralExprMetaModel charLiteralExprMetaModel = new CharLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel));
+
+ public static final ClassExprMetaModel classExprMetaModel = new ClassExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final ConditionalExprMetaModel conditionalExprMetaModel = new ConditionalExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final DoubleLiteralExprMetaModel doubleLiteralExprMetaModel = new DoubleLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel));
+
+ public static final EnclosedExprMetaModel enclosedExprMetaModel = new EnclosedExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final FieldAccessExprMetaModel fieldAccessExprMetaModel = new FieldAccessExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final InstanceOfExprMetaModel instanceOfExprMetaModel = new InstanceOfExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final IntegerLiteralExprMetaModel integerLiteralExprMetaModel = new IntegerLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel));
+
+ public static final LambdaExprMetaModel lambdaExprMetaModel = new LambdaExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final LongLiteralExprMetaModel longLiteralExprMetaModel = new LongLiteralExprMetaModel(Optional.of(literalStringValueExprMetaModel));
+
+ public static final MarkerAnnotationExprMetaModel markerAnnotationExprMetaModel = new MarkerAnnotationExprMetaModel(Optional.of(annotationExprMetaModel));
+
+ public static final MemberValuePairMetaModel memberValuePairMetaModel = new MemberValuePairMetaModel(Optional.of(nodeMetaModel));
+
+ public static final MethodCallExprMetaModel methodCallExprMetaModel = new MethodCallExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final MethodReferenceExprMetaModel methodReferenceExprMetaModel = new MethodReferenceExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final NameExprMetaModel nameExprMetaModel = new NameExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final NameMetaModel nameMetaModel = new NameMetaModel(Optional.of(nodeMetaModel));
+
+ public static final NormalAnnotationExprMetaModel normalAnnotationExprMetaModel = new NormalAnnotationExprMetaModel(Optional.of(annotationExprMetaModel));
+
+ public static final NullLiteralExprMetaModel nullLiteralExprMetaModel = new NullLiteralExprMetaModel(Optional.of(literalExprMetaModel));
+
+ public static final ObjectCreationExprMetaModel objectCreationExprMetaModel = new ObjectCreationExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final SimpleNameMetaModel simpleNameMetaModel = new SimpleNameMetaModel(Optional.of(nodeMetaModel));
+
+ public static final SingleMemberAnnotationExprMetaModel singleMemberAnnotationExprMetaModel = new SingleMemberAnnotationExprMetaModel(Optional.of(annotationExprMetaModel));
+
+ public static final SuperExprMetaModel superExprMetaModel = new SuperExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final ThisExprMetaModel thisExprMetaModel = new ThisExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final TypeExprMetaModel typeExprMetaModel = new TypeExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final UnaryExprMetaModel unaryExprMetaModel = new UnaryExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final VariableDeclarationExprMetaModel variableDeclarationExprMetaModel = new VariableDeclarationExprMetaModel(Optional.of(expressionMetaModel));
+
+ public static final ImportDeclarationMetaModel importDeclarationMetaModel = new ImportDeclarationMetaModel(Optional.of(nodeMetaModel));
+
+ public static final AssertStmtMetaModel assertStmtMetaModel = new AssertStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final BlockStmtMetaModel blockStmtMetaModel = new BlockStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final BreakStmtMetaModel breakStmtMetaModel = new BreakStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final CatchClauseMetaModel catchClauseMetaModel = new CatchClauseMetaModel(Optional.of(nodeMetaModel));
+
+ public static final ContinueStmtMetaModel continueStmtMetaModel = new ContinueStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final DoStmtMetaModel doStmtMetaModel = new DoStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final EmptyStmtMetaModel emptyStmtMetaModel = new EmptyStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final ExplicitConstructorInvocationStmtMetaModel explicitConstructorInvocationStmtMetaModel = new ExplicitConstructorInvocationStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final ExpressionStmtMetaModel expressionStmtMetaModel = new ExpressionStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final ForeachStmtMetaModel foreachStmtMetaModel = new ForeachStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final ForStmtMetaModel forStmtMetaModel = new ForStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final IfStmtMetaModel ifStmtMetaModel = new IfStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final LabeledStmtMetaModel labeledStmtMetaModel = new LabeledStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final ReturnStmtMetaModel returnStmtMetaModel = new ReturnStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final SwitchEntryStmtMetaModel switchEntryStmtMetaModel = new SwitchEntryStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final SwitchStmtMetaModel switchStmtMetaModel = new SwitchStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final SynchronizedStmtMetaModel synchronizedStmtMetaModel = new SynchronizedStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final ThrowStmtMetaModel throwStmtMetaModel = new ThrowStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final TryStmtMetaModel tryStmtMetaModel = new TryStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final LocalClassDeclarationStmtMetaModel localClassDeclarationStmtMetaModel = new LocalClassDeclarationStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final WhileStmtMetaModel whileStmtMetaModel = new WhileStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final UnparsableStmtMetaModel unparsableStmtMetaModel = new UnparsableStmtMetaModel(Optional.of(statementMetaModel));
+
+ public static final ArrayTypeMetaModel arrayTypeMetaModel = new ArrayTypeMetaModel(Optional.of(referenceTypeMetaModel));
+
+ public static final ClassOrInterfaceTypeMetaModel classOrInterfaceTypeMetaModel = new ClassOrInterfaceTypeMetaModel(Optional.of(referenceTypeMetaModel));
+
+ public static final IntersectionTypeMetaModel intersectionTypeMetaModel = new IntersectionTypeMetaModel(Optional.of(typeMetaModel));
+
+ public static final PrimitiveTypeMetaModel primitiveTypeMetaModel = new PrimitiveTypeMetaModel(Optional.of(typeMetaModel));
+
+ public static final TypeParameterMetaModel typeParameterMetaModel = new TypeParameterMetaModel(Optional.of(referenceTypeMetaModel));
+
+ public static final UnionTypeMetaModel unionTypeMetaModel = new UnionTypeMetaModel(Optional.of(typeMetaModel));
+
+ public static final UnknownTypeMetaModel unknownTypeMetaModel = new UnknownTypeMetaModel(Optional.of(typeMetaModel));
+
+ public static final VoidTypeMetaModel voidTypeMetaModel = new VoidTypeMetaModel(Optional.of(typeMetaModel));
+
+ public static final WildcardTypeMetaModel wildcardTypeMetaModel = new WildcardTypeMetaModel(Optional.of(typeMetaModel));
+
+ public static final VarTypeMetaModel varTypeMetaModel = new VarTypeMetaModel(Optional.of(typeMetaModel));
+
+ public static final ModuleRequiresStmtMetaModel moduleRequiresStmtMetaModel = new ModuleRequiresStmtMetaModel(Optional.of(moduleStmtMetaModel));
+
+ public static final ModuleExportsStmtMetaModel moduleExportsStmtMetaModel = new ModuleExportsStmtMetaModel(Optional.of(moduleStmtMetaModel));
+
+ public static final ModuleProvidesStmtMetaModel moduleProvidesStmtMetaModel = new ModuleProvidesStmtMetaModel(Optional.of(moduleStmtMetaModel));
+
+ public static final ModuleUsesStmtMetaModel moduleUsesStmtMetaModel = new ModuleUsesStmtMetaModel(Optional.of(moduleStmtMetaModel));
+
+ public static final ModuleOpensStmtMetaModel moduleOpensStmtMetaModel = new ModuleOpensStmtMetaModel(Optional.of(moduleStmtMetaModel));
+
+ static {
+ initializeNodeMetaModels();
+ initializePropertyMetaModels();
+ initializeConstructorParameters();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavadocCommentMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavadocCommentMetaModel.java
new file mode 100644
index 000000000..4da20077c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/JavadocCommentMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class JavadocCommentMetaModel extends CommentMetaModel {
+
+ JavadocCommentMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.comments.JavadocComment.class, "JavadocComment", "com.github.javaparser.ast.comments", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LabeledStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LabeledStmtMetaModel.java
new file mode 100644
index 000000000..d8532efac
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LabeledStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class LabeledStmtMetaModel extends StatementMetaModel {
+
+ LabeledStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.LabeledStmt.class, "LabeledStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel labelPropertyMetaModel;
+
+ public PropertyMetaModel statementPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LambdaExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LambdaExprMetaModel.java
new file mode 100644
index 000000000..ad50a65a6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LambdaExprMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class LambdaExprMetaModel extends ExpressionMetaModel {
+
+ LambdaExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.LambdaExpr.class, "LambdaExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel isEnclosingParametersPropertyMetaModel;
+
+ public PropertyMetaModel parametersPropertyMetaModel;
+
+ public PropertyMetaModel expressionBodyPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LineCommentMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LineCommentMetaModel.java
new file mode 100644
index 000000000..dfc8bbdf7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LineCommentMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class LineCommentMetaModel extends CommentMetaModel {
+
+ LineCommentMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.comments.LineComment.class, "LineComment", "com.github.javaparser.ast.comments", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LiteralExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LiteralExprMetaModel.java
new file mode 100644
index 000000000..47f9fcdec
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LiteralExprMetaModel.java
@@ -0,0 +1,15 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class LiteralExprMetaModel extends ExpressionMetaModel {
+
+ LiteralExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.LiteralExpr.class, "LiteralExpr", "com.github.javaparser.ast.expr", true, false);
+ }
+
+ protected LiteralExprMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LiteralStringValueExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LiteralStringValueExprMetaModel.java
new file mode 100644
index 000000000..6ed8578b9
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LiteralStringValueExprMetaModel.java
@@ -0,0 +1,17 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class LiteralStringValueExprMetaModel extends LiteralExprMetaModel {
+
+ LiteralStringValueExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.LiteralStringValueExpr.class, "LiteralStringValueExpr", "com.github.javaparser.ast.expr", true, false);
+ }
+
+ protected LiteralStringValueExprMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+
+ public PropertyMetaModel valuePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LocalClassDeclarationStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LocalClassDeclarationStmtMetaModel.java
new file mode 100644
index 000000000..d936eb093
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LocalClassDeclarationStmtMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class LocalClassDeclarationStmtMetaModel extends StatementMetaModel {
+
+ LocalClassDeclarationStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.LocalClassDeclarationStmt.class, "LocalClassDeclarationStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel classDeclarationPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/LongLiteralExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LongLiteralExprMetaModel.java
new file mode 100644
index 000000000..42006b536
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/LongLiteralExprMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class LongLiteralExprMetaModel extends LiteralStringValueExprMetaModel {
+
+ LongLiteralExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.LongLiteralExpr.class, "LongLiteralExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/MarkerAnnotationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MarkerAnnotationExprMetaModel.java
new file mode 100644
index 000000000..0371b5142
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MarkerAnnotationExprMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class MarkerAnnotationExprMetaModel extends AnnotationExprMetaModel {
+
+ MarkerAnnotationExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.MarkerAnnotationExpr.class, "MarkerAnnotationExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/MemberValuePairMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MemberValuePairMetaModel.java
new file mode 100644
index 000000000..652181847
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MemberValuePairMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class MemberValuePairMetaModel extends NodeMetaModel {
+
+ MemberValuePairMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.MemberValuePair.class, "MemberValuePair", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel valuePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodCallExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodCallExprMetaModel.java
new file mode 100644
index 000000000..728407c28
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodCallExprMetaModel.java
@@ -0,0 +1,20 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class MethodCallExprMetaModel extends ExpressionMetaModel {
+
+ MethodCallExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.MethodCallExpr.class, "MethodCallExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel argumentsPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel scopePropertyMetaModel;
+
+ public PropertyMetaModel typeArgumentsPropertyMetaModel;
+
+ public PropertyMetaModel usingDiamondOperatorPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodDeclarationMetaModel.java
new file mode 100644
index 000000000..74aaeae69
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodDeclarationMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class MethodDeclarationMetaModel extends CallableDeclarationMetaModel {
+
+ MethodDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.MethodDeclaration.class, "MethodDeclaration", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodReferenceExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodReferenceExprMetaModel.java
new file mode 100644
index 000000000..4968046c1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/MethodReferenceExprMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class MethodReferenceExprMetaModel extends ExpressionMetaModel {
+
+ MethodReferenceExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.MethodReferenceExpr.class, "MethodReferenceExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel identifierPropertyMetaModel;
+
+ public PropertyMetaModel scopePropertyMetaModel;
+
+ public PropertyMetaModel typeArgumentsPropertyMetaModel;
+
+ public PropertyMetaModel usingDiamondOperatorPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleDeclarationMetaModel.java
new file mode 100644
index 000000000..0cf3c3e7a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleDeclarationMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ModuleDeclarationMetaModel extends NodeMetaModel {
+
+ ModuleDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleDeclaration.class, "ModuleDeclaration", "com.github.javaparser.ast.modules", false, false);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+
+ public PropertyMetaModel isOpenPropertyMetaModel;
+
+ public PropertyMetaModel moduleStmtsPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleExportsStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleExportsStmtMetaModel.java
new file mode 100644
index 000000000..7b6af7e10
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleExportsStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ModuleExportsStmtMetaModel extends ModuleStmtMetaModel {
+
+ ModuleExportsStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleExportsStmt.class, "ModuleExportsStmt", "com.github.javaparser.ast.modules", false, false);
+ }
+
+ public PropertyMetaModel moduleNamesPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleOpensStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleOpensStmtMetaModel.java
new file mode 100644
index 000000000..16a5a4847
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleOpensStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ModuleOpensStmtMetaModel extends ModuleStmtMetaModel {
+
+ ModuleOpensStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleOpensStmt.class, "ModuleOpensStmt", "com.github.javaparser.ast.modules", false, false);
+ }
+
+ public PropertyMetaModel moduleNamesPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleProvidesStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleProvidesStmtMetaModel.java
new file mode 100644
index 000000000..2c3bffc1a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleProvidesStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ModuleProvidesStmtMetaModel extends ModuleStmtMetaModel {
+
+ ModuleProvidesStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleProvidesStmt.class, "ModuleProvidesStmt", "com.github.javaparser.ast.modules", false, false);
+ }
+
+ public PropertyMetaModel typePropertyMetaModel;
+
+ public PropertyMetaModel withTypesPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleRequiresStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleRequiresStmtMetaModel.java
new file mode 100644
index 000000000..320a81167
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleRequiresStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ModuleRequiresStmtMetaModel extends ModuleStmtMetaModel {
+
+ ModuleRequiresStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleRequiresStmt.class, "ModuleRequiresStmt", "com.github.javaparser.ast.modules", false, false);
+ }
+
+ public PropertyMetaModel modifiersPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleStmtMetaModel.java
new file mode 100644
index 000000000..63ca214e8
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleStmtMetaModel.java
@@ -0,0 +1,15 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class ModuleStmtMetaModel extends NodeMetaModel {
+
+ ModuleStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleStmt.class, "ModuleStmt", "com.github.javaparser.ast.modules", true, false);
+ }
+
+ protected ModuleStmtMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleUsesStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleUsesStmtMetaModel.java
new file mode 100644
index 000000000..bac904356
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ModuleUsesStmtMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ModuleUsesStmtMetaModel extends ModuleStmtMetaModel {
+
+ ModuleUsesStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.modules.ModuleUsesStmt.class, "ModuleUsesStmt", "com.github.javaparser.ast.modules", false, false);
+ }
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NameExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NameExprMetaModel.java
new file mode 100644
index 000000000..bed296190
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NameExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class NameExprMetaModel extends ExpressionMetaModel {
+
+ NameExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.NameExpr.class, "NameExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NameMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NameMetaModel.java
new file mode 100644
index 000000000..cd54085d0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NameMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class NameMetaModel extends NodeMetaModel {
+
+ NameMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.Name.class, "Name", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+
+ public PropertyMetaModel identifierPropertyMetaModel;
+
+ public PropertyMetaModel qualifierPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NodeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NodeMetaModel.java
new file mode 100644
index 000000000..332dfd4fc
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NodeMetaModel.java
@@ -0,0 +1,17 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class NodeMetaModel extends BaseNodeMetaModel {
+
+ NodeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.Node.class, "Node", "com.github.javaparser.ast", true, false);
+ }
+
+ protected NodeMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+
+ public PropertyMetaModel commentPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java
new file mode 100644
index 000000000..7be7fdcc6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NonEmptyProperty.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Indicate that leaving this property empty does not lead to a correct AST.
+ * Empty means either empty string or empty collection.
+ * (Used during generation of the meta model.)
+ */
+@Retention(RUNTIME)
+@Target({FIELD, METHOD})
+public @interface NonEmptyProperty {
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NormalAnnotationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NormalAnnotationExprMetaModel.java
new file mode 100644
index 000000000..a88a77700
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NormalAnnotationExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class NormalAnnotationExprMetaModel extends AnnotationExprMetaModel {
+
+ NormalAnnotationExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.NormalAnnotationExpr.class, "NormalAnnotationExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel pairsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/NullLiteralExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NullLiteralExprMetaModel.java
new file mode 100644
index 000000000..698fb302e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/NullLiteralExprMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class NullLiteralExprMetaModel extends LiteralExprMetaModel {
+
+ NullLiteralExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.NullLiteralExpr.class, "NullLiteralExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ObjectCreationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ObjectCreationExprMetaModel.java
new file mode 100644
index 000000000..4149d1dfd
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ObjectCreationExprMetaModel.java
@@ -0,0 +1,22 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ObjectCreationExprMetaModel extends ExpressionMetaModel {
+
+ ObjectCreationExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ObjectCreationExpr.class, "ObjectCreationExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel anonymousClassBodyPropertyMetaModel;
+
+ public PropertyMetaModel argumentsPropertyMetaModel;
+
+ public PropertyMetaModel scopePropertyMetaModel;
+
+ public PropertyMetaModel typePropertyMetaModel;
+
+ public PropertyMetaModel typeArgumentsPropertyMetaModel;
+
+ public PropertyMetaModel usingDiamondOperatorPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java
new file mode 100644
index 000000000..5052e3bcf
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/OptionalProperty.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Indicate an optional property of a Node.
+ * (Used during generation of the meta model.)
+ */
+@Retention(RUNTIME)
+@Target(FIELD)
+public @interface OptionalProperty {
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PackageDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PackageDeclarationMetaModel.java
new file mode 100644
index 000000000..3ae52b4f1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PackageDeclarationMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class PackageDeclarationMetaModel extends NodeMetaModel {
+
+ PackageDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.PackageDeclaration.class, "PackageDeclaration", "com.github.javaparser.ast", false, false);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ParameterMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ParameterMetaModel.java
new file mode 100644
index 000000000..034b5c7e4
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ParameterMetaModel.java
@@ -0,0 +1,22 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ParameterMetaModel extends NodeMetaModel {
+
+ ParameterMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.Parameter.class, "Parameter", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+
+ public PropertyMetaModel isVarArgsPropertyMetaModel;
+
+ public PropertyMetaModel modifiersPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel typePropertyMetaModel;
+
+ public PropertyMetaModel varArgsAnnotationsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PrimitiveTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PrimitiveTypeMetaModel.java
new file mode 100644
index 000000000..71ee28c5c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PrimitiveTypeMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class PrimitiveTypeMetaModel extends TypeMetaModel {
+
+ PrimitiveTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.PrimitiveType.class, "PrimitiveType", "com.github.javaparser.ast.type", false, false);
+ }
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java
new file mode 100644
index 000000000..5dcf4afb5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/PropertyMetaModel.java
@@ -0,0 +1,248 @@
+package com.github.javaparser.metamodel;
+
+import com.github.javaparser.ast.Node;
+
+import java.lang.reflect.Field;
+import java.util.Optional;
+
+import static com.github.javaparser.utils.CodeGenerationUtils.getterName;
+import static com.github.javaparser.utils.CodeGenerationUtils.setterName;
+
+/**
+ * Meta-data about a property of a node in the AST.
+ */
+public class PropertyMetaModel {
+ private final BaseNodeMetaModel containingNodeMetaModel;
+ private final String name;
+ private final Class<?> type;
+ private final Optional<BaseNodeMetaModel> nodeReference;
+ private final boolean isOptional;
+ private final boolean isNonEmpty;
+ private final boolean isNodeList;
+ private final boolean isEnumSet;
+ private final boolean hasWildcard;
+
+ public PropertyMetaModel(BaseNodeMetaModel containingNodeMetaModel, String name, Class<?> type, Optional<BaseNodeMetaModel> nodeReference, boolean isOptional, boolean isNonEmpty, boolean isNodeList, boolean isEnumSet, boolean hasWildcard) {
+ this.containingNodeMetaModel = containingNodeMetaModel;
+ this.name = name;
+ this.type = type;
+ this.nodeReference = nodeReference;
+ this.isOptional = isOptional;
+ this.isNonEmpty = isNonEmpty;
+ this.isNodeList = isNodeList;
+ this.isEnumSet = isEnumSet;
+ this.hasWildcard = hasWildcard;
+ }
+
+ /**
+ * @return is this the field fieldName on class c?
+ */
+ public boolean is(Class<? extends Node> c, String fieldName) {
+ return containingNodeMetaModel.is(c) && name.equals(fieldName);
+ }
+
+ /**
+ * @return is this fields called fieldName?
+ */
+ public boolean is(String fieldName) {
+ return name.equals(fieldName);
+ }
+
+ /**
+ * @return the name used in the AST for the setter
+ */
+ public String getSetterMethodName() {
+ return setterName(name);
+ }
+
+ /**
+ * @return the name used in the AST for the getter
+ */
+ public String getGetterMethodName() {
+ return getterName(type, name);
+ }
+
+ /**
+ * @return the NodeMetaModel that "has" this property.
+ */
+ public BaseNodeMetaModel getContainingNodeMetaModel() {
+ return containingNodeMetaModel;
+ }
+
+ /**
+ * @return the name of the property. This is equal to the name of the field in the AST.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return if this property is a String or a NodeList: whether it may be empty.
+ */
+ public boolean isNonEmpty() {
+ return isNonEmpty;
+ }
+
+ /**
+ * @return the class of the field.
+ */
+ public Class<?> getType() {
+ return type;
+ }
+
+ /**
+ * @return if this property is a Node, this will get the node meta model.
+ */
+ public Optional<BaseNodeMetaModel> getNodeReference() {
+ return nodeReference;
+ }
+
+ /**
+ * @return whether this property is optional.
+ */
+ public boolean isOptional() {
+ return isOptional;
+ }
+
+ /**
+ * @return whether this property is not optional.
+ */
+ public boolean isRequired() {
+ return !isOptional;
+ }
+
+ /**
+ * @return whether this property is contained in a NodeList.
+ */
+ public boolean isNodeList() {
+ return isNodeList;
+ }
+
+ /**
+ * @return whether this property is contained in an EnumSet.
+ */
+ public boolean isEnumSet() {
+ return isEnumSet;
+ }
+
+ /**
+ * @return whether this property has a wildcard following it, like BodyDeclaration&lt;?&gt;.
+ */
+ public boolean hasWildcard() {
+ return hasWildcard;
+ }
+
+ /**
+ * @return whether this property is not a list or set.
+ */
+ public boolean isSingular() {
+ return !(isNodeList || isEnumSet);
+ }
+
+ @Override
+ public String toString() {
+ return "(" + getTypeName() + ")\t" + containingNodeMetaModel + "#" + name;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ PropertyMetaModel that = (PropertyMetaModel) o;
+
+ if (!name.equals(that.name)) return false;
+ if (!type.equals(that.type)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = name.hashCode();
+ result = 31 * result + type.hashCode();
+ return result;
+ }
+
+ /**
+ * @return the type of a single element of this property, so no Optional or NodeList or EnumSet.
+ */
+ public String getTypeNameGenerified() {
+ if (hasWildcard) {
+ return getTypeName() + "<?>";
+ }
+ return getTypeName();
+ }
+
+ /**
+ * @return the raw type of a single element of this property, so nothing but the name.
+ */
+ public String getTypeName() {
+ return type.getSimpleName();
+ }
+
+ /**
+ * @return the type that is returned from getters in the AST.
+ */
+ public String getTypeNameForGetter() {
+ if (isOptional) {
+ return "Optional<" + getTypeNameForSetter() + ">";
+ }
+ return getTypeNameForSetter();
+ }
+
+ /**
+ * @return the type that is passed to setters in the AST.
+ */
+ public String getTypeNameForSetter() {
+ if (isNodeList) {
+ return "NodeList<" + getTypeNameGenerified() + ">";
+ }
+ if (isEnumSet) {
+ return "EnumSet<" + getTypeNameGenerified() + ">";
+ }
+ return getTypeNameGenerified();
+ }
+
+ /**
+ * @return is this property an AST Node?
+ */
+ public boolean isNode() {
+ return getNodeReference().isPresent();
+ }
+
+ /**
+ * The name of the field in the containing BaseNodeMetaModel for this property meta model.
+ */
+ public String getMetaModelFieldName() {
+ return getName() + "PropertyMetaModel";
+ }
+
+ /**
+ * @return is this property an attribute, meaning: not a node?
+ */
+ public boolean isAttribute() {
+ return !isNode();
+ }
+
+ /**
+ * Introspects the node to get the value from this field.
+ * Note that an optional empty field will return null here.
+ */
+ public Object getValue(Node node) {
+ try {
+ for (Class<?> c = node.getClass(); c != null; c = c.getSuperclass()) {
+ Field[] fields = c.getDeclaredFields();
+ for (Field classField : fields) {
+ if (classField.getName().equals(getName())) {
+ classField.setAccessible(true);
+ return classField.get(node);
+ }
+ }
+ }
+ throw new NoSuchFieldError(getName());
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReceiverParameterMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReceiverParameterMetaModel.java
new file mode 100644
index 000000000..e0fb46355
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReceiverParameterMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ReceiverParameterMetaModel extends NodeMetaModel {
+
+ ReceiverParameterMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.ReceiverParameter.class, "ReceiverParameter", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReferenceTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReferenceTypeMetaModel.java
new file mode 100644
index 000000000..fa0361ba5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReferenceTypeMetaModel.java
@@ -0,0 +1,15 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class ReferenceTypeMetaModel extends TypeMetaModel {
+
+ ReferenceTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.ReferenceType.class, "ReferenceType", "com.github.javaparser.ast.type", true, false);
+ }
+
+ protected ReferenceTypeMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReturnStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReturnStmtMetaModel.java
new file mode 100644
index 000000000..27af5ec88
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ReturnStmtMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ReturnStmtMetaModel extends StatementMetaModel {
+
+ ReturnStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ReturnStmt.class, "ReturnStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel expressionPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/SimpleNameMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SimpleNameMetaModel.java
new file mode 100644
index 000000000..1c042966f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SimpleNameMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class SimpleNameMetaModel extends NodeMetaModel {
+
+ SimpleNameMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.SimpleName.class, "SimpleName", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel identifierPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/SingleMemberAnnotationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SingleMemberAnnotationExprMetaModel.java
new file mode 100644
index 000000000..a5223cda3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SingleMemberAnnotationExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class SingleMemberAnnotationExprMetaModel extends AnnotationExprMetaModel {
+
+ SingleMemberAnnotationExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.SingleMemberAnnotationExpr.class, "SingleMemberAnnotationExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel memberValuePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/StatementMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/StatementMetaModel.java
new file mode 100644
index 000000000..8433ab0b6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/StatementMetaModel.java
@@ -0,0 +1,15 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class StatementMetaModel extends NodeMetaModel {
+
+ StatementMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.Statement.class, "Statement", "com.github.javaparser.ast.stmt", true, false);
+ }
+
+ protected StatementMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/StringLiteralExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/StringLiteralExprMetaModel.java
new file mode 100644
index 000000000..1dc0acf55
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/StringLiteralExprMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class StringLiteralExprMetaModel extends LiteralStringValueExprMetaModel {
+
+ StringLiteralExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.StringLiteralExpr.class, "StringLiteralExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/SuperExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SuperExprMetaModel.java
new file mode 100644
index 000000000..745df8bb7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SuperExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class SuperExprMetaModel extends ExpressionMetaModel {
+
+ SuperExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.SuperExpr.class, "SuperExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel classExprPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/SwitchEntryStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SwitchEntryStmtMetaModel.java
new file mode 100644
index 000000000..b8e625210
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SwitchEntryStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class SwitchEntryStmtMetaModel extends StatementMetaModel {
+
+ SwitchEntryStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.SwitchEntryStmt.class, "SwitchEntryStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel labelPropertyMetaModel;
+
+ public PropertyMetaModel statementsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/SwitchStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SwitchStmtMetaModel.java
new file mode 100644
index 000000000..dc9df0eea
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SwitchStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class SwitchStmtMetaModel extends StatementMetaModel {
+
+ SwitchStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.SwitchStmt.class, "SwitchStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel entriesPropertyMetaModel;
+
+ public PropertyMetaModel selectorPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/SynchronizedStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SynchronizedStmtMetaModel.java
new file mode 100644
index 000000000..01a870979
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/SynchronizedStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class SynchronizedStmtMetaModel extends StatementMetaModel {
+
+ SynchronizedStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.SynchronizedStmt.class, "SynchronizedStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel expressionPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ThisExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ThisExprMetaModel.java
new file mode 100644
index 000000000..fbfd5a5bb
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ThisExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ThisExprMetaModel extends ExpressionMetaModel {
+
+ ThisExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.ThisExpr.class, "ThisExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel classExprPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/ThrowStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ThrowStmtMetaModel.java
new file mode 100644
index 000000000..c5bd2e195
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/ThrowStmtMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class ThrowStmtMetaModel extends StatementMetaModel {
+
+ ThrowStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.ThrowStmt.class, "ThrowStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel expressionPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/TryStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TryStmtMetaModel.java
new file mode 100644
index 000000000..28756db5e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TryStmtMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class TryStmtMetaModel extends StatementMetaModel {
+
+ TryStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.TryStmt.class, "TryStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel catchClausesPropertyMetaModel;
+
+ public PropertyMetaModel finallyBlockPropertyMetaModel;
+
+ public PropertyMetaModel resourcesPropertyMetaModel;
+
+ public PropertyMetaModel tryBlockPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeDeclarationMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeDeclarationMetaModel.java
new file mode 100644
index 000000000..f7f0d00ab
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeDeclarationMetaModel.java
@@ -0,0 +1,21 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class TypeDeclarationMetaModel extends BodyDeclarationMetaModel {
+
+ TypeDeclarationMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.TypeDeclaration.class, "TypeDeclaration", "com.github.javaparser.ast.body", true, true);
+ }
+
+ protected TypeDeclarationMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+
+ public PropertyMetaModel membersPropertyMetaModel;
+
+ public PropertyMetaModel modifiersPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeExprMetaModel.java
new file mode 100644
index 000000000..8d0b90dad
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeExprMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class TypeExprMetaModel extends ExpressionMetaModel {
+
+ TypeExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.TypeExpr.class, "TypeExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeMetaModel.java
new file mode 100644
index 000000000..76b084b32
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeMetaModel.java
@@ -0,0 +1,17 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+import com.github.javaparser.ast.Node;
+
+public class TypeMetaModel extends NodeMetaModel {
+
+ TypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.Type.class, "Type", "com.github.javaparser.ast.type", true, false);
+ }
+
+ protected TypeMetaModel(Optional<BaseNodeMetaModel> superNodeMetaModel, Class<? extends Node> type, String name, String packageName, boolean isAbstract, boolean hasWildcard) {
+ super(superNodeMetaModel, type, name, packageName, isAbstract, hasWildcard);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeParameterMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeParameterMetaModel.java
new file mode 100644
index 000000000..2e8740206
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/TypeParameterMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class TypeParameterMetaModel extends ReferenceTypeMetaModel {
+
+ TypeParameterMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.TypeParameter.class, "TypeParameter", "com.github.javaparser.ast.type", false, false);
+ }
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel typeBoundPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnaryExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnaryExprMetaModel.java
new file mode 100644
index 000000000..309af9a92
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnaryExprMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class UnaryExprMetaModel extends ExpressionMetaModel {
+
+ UnaryExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.UnaryExpr.class, "UnaryExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel expressionPropertyMetaModel;
+
+ public PropertyMetaModel operatorPropertyMetaModel;
+
+ public PropertyMetaModel postfixPropertyMetaModel;
+
+ public PropertyMetaModel prefixPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnionTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnionTypeMetaModel.java
new file mode 100644
index 000000000..14e81becd
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnionTypeMetaModel.java
@@ -0,0 +1,12 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class UnionTypeMetaModel extends TypeMetaModel {
+
+ UnionTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.UnionType.class, "UnionType", "com.github.javaparser.ast.type", false, false);
+ }
+
+ public PropertyMetaModel elementsPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnknownTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnknownTypeMetaModel.java
new file mode 100644
index 000000000..d83518b79
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnknownTypeMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class UnknownTypeMetaModel extends TypeMetaModel {
+
+ UnknownTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.UnknownType.class, "UnknownType", "com.github.javaparser.ast.type", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnparsableStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnparsableStmtMetaModel.java
new file mode 100644
index 000000000..7d18f74ab
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/UnparsableStmtMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class UnparsableStmtMetaModel extends StatementMetaModel {
+
+ UnparsableStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.UnparsableStmt.class, "UnparsableStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/VarTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/VarTypeMetaModel.java
new file mode 100644
index 000000000..1ada830c5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/VarTypeMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class VarTypeMetaModel extends TypeMetaModel {
+
+ VarTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.VarType.class, "VarType", "com.github.javaparser.ast.type", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/VariableDeclarationExprMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/VariableDeclarationExprMetaModel.java
new file mode 100644
index 000000000..c9c30c0b5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/VariableDeclarationExprMetaModel.java
@@ -0,0 +1,18 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class VariableDeclarationExprMetaModel extends ExpressionMetaModel {
+
+ VariableDeclarationExprMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.expr.VariableDeclarationExpr.class, "VariableDeclarationExpr", "com.github.javaparser.ast.expr", false, false);
+ }
+
+ public PropertyMetaModel annotationsPropertyMetaModel;
+
+ public PropertyMetaModel modifiersPropertyMetaModel;
+
+ public PropertyMetaModel variablesPropertyMetaModel;
+
+ public PropertyMetaModel maximumCommonTypePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/VariableDeclaratorMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/VariableDeclaratorMetaModel.java
new file mode 100644
index 000000000..83f12aca6
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/VariableDeclaratorMetaModel.java
@@ -0,0 +1,16 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class VariableDeclaratorMetaModel extends NodeMetaModel {
+
+ VariableDeclaratorMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.body.VariableDeclarator.class, "VariableDeclarator", "com.github.javaparser.ast.body", false, false);
+ }
+
+ public PropertyMetaModel initializerPropertyMetaModel;
+
+ public PropertyMetaModel namePropertyMetaModel;
+
+ public PropertyMetaModel typePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/VoidTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/VoidTypeMetaModel.java
new file mode 100644
index 000000000..bb92f5613
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/VoidTypeMetaModel.java
@@ -0,0 +1,10 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class VoidTypeMetaModel extends TypeMetaModel {
+
+ VoidTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.VoidType.class, "VoidType", "com.github.javaparser.ast.type", false, false);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/WhileStmtMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/WhileStmtMetaModel.java
new file mode 100644
index 000000000..83a122d9f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/WhileStmtMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class WhileStmtMetaModel extends StatementMetaModel {
+
+ WhileStmtMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.stmt.WhileStmt.class, "WhileStmt", "com.github.javaparser.ast.stmt", false, false);
+ }
+
+ public PropertyMetaModel bodyPropertyMetaModel;
+
+ public PropertyMetaModel conditionPropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/metamodel/WildcardTypeMetaModel.java b/javaparser-core/src/main/java/com/github/javaparser/metamodel/WildcardTypeMetaModel.java
new file mode 100644
index 000000000..0d4b9fc7e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/metamodel/WildcardTypeMetaModel.java
@@ -0,0 +1,14 @@
+package com.github.javaparser.metamodel;
+
+import java.util.Optional;
+
+public class WildcardTypeMetaModel extends TypeMetaModel {
+
+ WildcardTypeMetaModel(Optional<BaseNodeMetaModel> superBaseNodeMetaModel) {
+ super(superBaseNodeMetaModel, com.github.javaparser.ast.type.WildcardType.class, "WildcardType", "com.github.javaparser.ast.type", false, false);
+ }
+
+ public PropertyMetaModel extendedTypePropertyMetaModel;
+
+ public PropertyMetaModel superTypePropertyMetaModel;
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java
new file mode 100644
index 000000000..e45ed7580
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/ConcreteSyntaxModel.java
@@ -0,0 +1,953 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer;
+
+import com.github.javaparser.GeneratedJavaParserConstants;
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import com.github.javaparser.metamodel.JavaParserMetaModel;
+import com.github.javaparser.printer.concretesyntaxmodel.CsmConditional;
+import com.github.javaparser.printer.concretesyntaxmodel.CsmElement;
+import com.github.javaparser.printer.concretesyntaxmodel.CsmMix;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.GeneratedJavaParserConstants.*;
+import static com.github.javaparser.ast.observer.ObservableProperty.*;
+import static com.github.javaparser.printer.concretesyntaxmodel.CsmConditional.Condition.*;
+import static com.github.javaparser.printer.concretesyntaxmodel.CsmElement.*;
+import static com.github.javaparser.utils.Utils.EOL;
+
+/**
+ * The Concrete Syntax Model for a single node type. It knows the syntax used to represent a certain element in Java
+ * code.
+ */
+public class ConcreteSyntaxModel {
+
+ private static final Map<Class, CsmElement> concreteSyntaxModelByClass = new HashMap<>();
+ private static Optional<String> initializationError;
+
+ private static CsmElement modifiers() {
+ return list(ObservableProperty.MODIFIERS, space(), none(), space());
+ }
+
+ /**
+ * Build a mix collecting all the elements specified.
+ */
+ private static CsmElement mix(CsmElement... elements) {
+ return new CsmMix(Arrays.asList(elements));
+ }
+
+ private static CsmElement memberAnnotations() {
+ return list(ObservableProperty.ANNOTATIONS, newline(), none(), newline());
+ }
+
+ private static CsmElement annotations() {
+ return list(ObservableProperty.ANNOTATIONS, space(), none(), newline());
+ }
+
+ private static CsmElement typeParameters() {
+ return list(ObservableProperty.TYPE_PARAMETERS, CsmElement.sequence(CsmElement.comma(), CsmElement.space()), CsmElement.token(GeneratedJavaParserConstants.LT),
+ CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants.GT), CsmElement.space()));
+ }
+
+ private static CsmElement typeArguments() {
+ return list(ObservableProperty.TYPE_ARGUMENTS, CsmElement.sequence(CsmElement.comma(), CsmElement.space()), CsmElement.token(GeneratedJavaParserConstants.LT),
+ CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants.GT)));
+ }
+
+ static {
+
+ ///
+ /// Body
+ ///
+
+ concreteSyntaxModelByClass.put(AnnotationDeclaration.class, CsmElement.sequence(
+ CsmElement.comment(),
+ memberAnnotations(),
+ modifiers(),
+ CsmElement.token(GeneratedJavaParserConstants.AT),
+ CsmElement.token(GeneratedJavaParserConstants.INTERFACE),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.space(),
+ CsmElement.token(LBRACE),
+ CsmElement.newline(),
+ CsmElement.indent(),
+ CsmElement.list(ObservableProperty.MEMBERS, CsmElement.newline(), CsmElement.none(), CsmElement.none(), CsmElement.newline()),
+ CsmElement.unindent(),
+ CsmElement.token(RBRACE)
+ ));
+
+ concreteSyntaxModelByClass.put(AnnotationMemberDeclaration.class, CsmElement.sequence(
+ CsmElement.comment(),
+ memberAnnotations(),
+ modifiers(),
+ CsmElement.child(ObservableProperty.TYPE),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.token(LPAREN),
+ CsmElement.token(RPAREN),
+ CsmElement.conditional(ObservableProperty.DEFAULT_VALUE, IS_PRESENT, CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants._DEFAULT), CsmElement.space(), CsmElement.child(DEFAULT_VALUE))),
+ CsmElement.semicolon()
+ ));
+
+ concreteSyntaxModelByClass.put(ClassOrInterfaceDeclaration.class, sequence(
+ comment(),
+ list(ObservableProperty.ANNOTATIONS, newline(), none(), newline()),
+ modifiers(),
+ conditional(ObservableProperty.INTERFACE, FLAG, token(GeneratedJavaParserConstants.INTERFACE), token(GeneratedJavaParserConstants.CLASS)),
+ space(),
+ child(ObservableProperty.NAME),
+ list(TYPE_PARAMETERS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)),
+ list(ObservableProperty.EXTENDED_TYPES,
+ sequence(string(GeneratedJavaParserConstants.COMMA), space()),
+ sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space()),
+ none()),
+ list(ObservableProperty.IMPLEMENTED_TYPES, sequence(string(GeneratedJavaParserConstants.COMMA), space()), sequence(
+ space(),
+ token(GeneratedJavaParserConstants.IMPLEMENTS),
+ space()), none()),
+ space(),
+ block(sequence(newline(), list(ObservableProperty.MEMBERS, sequence(newline(), newline()), CsmElement.newline(), newline())))
+ ));
+
+ concreteSyntaxModelByClass.put(ConstructorDeclaration.class, sequence(
+ comment(),
+ memberAnnotations(),
+ modifiers(),
+ typeParameters(),
+ child(ObservableProperty.NAME),
+ token(GeneratedJavaParserConstants.LPAREN),
+ list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()),
+ token(GeneratedJavaParserConstants.RPAREN),
+ list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()),
+ space(),
+ child(ObservableProperty.BODY)
+ ));
+
+ concreteSyntaxModelByClass.put(EnumConstantDeclaration.class, sequence(
+ comment(),
+ memberAnnotations(),
+ child(ObservableProperty.NAME),
+ list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), token(GeneratedJavaParserConstants.LPAREN), token(GeneratedJavaParserConstants.RPAREN)),
+ conditional(CLASS_BODY, IS_NOT_EMPTY, sequence(space(), token(GeneratedJavaParserConstants.LBRACE), CsmElement.newline(), CsmElement.indent(), CsmElement.newline(),
+ list(ObservableProperty.CLASS_BODY, newline(), newline(), none(), CsmElement.newline()),
+ unindent(),
+ token(RBRACE), CsmElement.newline()))
+ ));
+
+ concreteSyntaxModelByClass.put(EnumDeclaration.class, sequence(
+ comment(),
+ annotations(),
+ modifiers(),
+ token(GeneratedJavaParserConstants.ENUM),
+ space(),
+ child(ObservableProperty.NAME),
+ list(ObservableProperty.IMPLEMENTED_TYPES,
+ sequence(comma(), space()),
+ sequence(space(), token(GeneratedJavaParserConstants.IMPLEMENTS), space()),
+ none()),
+ space(),
+ token(GeneratedJavaParserConstants.LBRACE),
+ CsmElement.newline(),
+ CsmElement.indent(),
+ CsmElement.newline(),
+ list(ObservableProperty.ENTRIES,
+ sequence(comma(), space()),
+ CsmElement.none(),
+ none()),
+ conditional(ObservableProperty.MEMBERS, IS_EMPTY,
+ conditional(ObservableProperty.ENTRIES, IS_NOT_EMPTY, newline()),
+ sequence(CsmElement.semicolon(), newline(), CsmElement.newline(), list(ObservableProperty.MEMBERS, newline(), newline(), none(), CsmElement.newline()))),
+ unindent(),
+ token(RBRACE)
+ ));
+
+ concreteSyntaxModelByClass.put(FieldDeclaration.class, sequence(
+ orphanCommentsBeforeThis(),
+ comment(),
+ annotations(),
+ modifiers(),
+ conditional(ObservableProperty.VARIABLES, IS_NOT_EMPTY, child(ObservableProperty.MAXIMUM_COMMON_TYPE)),
+ space(),
+ list(ObservableProperty.VARIABLES, sequence(comma(), space())),
+ semicolon()));
+
+ concreteSyntaxModelByClass.put(InitializerDeclaration.class, sequence(
+ comment(),
+ conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())),
+ child(ObservableProperty.BODY)));
+
+ concreteSyntaxModelByClass.put(MethodDeclaration.class, sequence(
+ orphanCommentsBeforeThis(),
+ comment(),
+ mix(memberAnnotations(), modifiers()),
+ typeParameters(),
+ child(ObservableProperty.TYPE),
+ space(),
+ child(ObservableProperty.NAME),
+ token(GeneratedJavaParserConstants.LPAREN),
+ conditional(ObservableProperty.RECEIVER_PARAMETER, IS_PRESENT, sequence(child(ObservableProperty.RECEIVER_PARAMETER), comma(), space())),
+ list(ObservableProperty.PARAMETERS, sequence(comma(), space()), none(), none()),
+ token(GeneratedJavaParserConstants.RPAREN),
+ list(ObservableProperty.THROWN_EXCEPTIONS, sequence(comma(), space()), sequence(space(), token(GeneratedJavaParserConstants.THROWS), space()), none()),
+ conditional(ObservableProperty.BODY, IS_PRESENT, sequence(space(), child(ObservableProperty.BODY)), semicolon())
+ ));
+
+ concreteSyntaxModelByClass.put(Parameter.class, sequence(
+ comment(),
+ list(ObservableProperty.ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.space()),
+ modifiers(),
+ child(ObservableProperty.TYPE),
+ conditional(ObservableProperty.VAR_ARGS, FLAG, CsmElement.sequence(
+ list(ObservableProperty.VAR_ARGS_ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.none()),
+ token(GeneratedJavaParserConstants.ELLIPSIS))),
+ space(),
+ child(ObservableProperty.NAME)));
+
+ concreteSyntaxModelByClass.put(ReceiverParameter.class, sequence(
+ comment(),
+ list(ObservableProperty.ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.space()),
+ child(ObservableProperty.TYPE),
+ space(),
+ child(ObservableProperty.NAME)));
+
+ concreteSyntaxModelByClass.put(VariableDeclarator.class, sequence(
+ comment(),
+ child(ObservableProperty.NAME),
+ // FIXME: we should introduce a derived property
+ // list(ObservableProperty.EXTRA_ARRAY_LEVELS),
+ conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), token(GeneratedJavaParserConstants.ASSIGN), space(),
+ child(ObservableProperty.INITIALIZER)))
+ ));
+
+ ///
+ /// Expressions
+ ///
+
+ concreteSyntaxModelByClass.put(ArrayAccessExpr.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.token(GeneratedJavaParserConstants.LBRACKET),
+ CsmElement.child(ObservableProperty.INDEX),
+ CsmElement.token(GeneratedJavaParserConstants.RBRACKET)
+ ));
+
+ concreteSyntaxModelByClass.put(ArrayCreationExpr.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.NEW),
+ space(),
+ CsmElement.child(ObservableProperty.ELEMENT_TYPE),
+ list(ObservableProperty.LEVELS),
+ conditional(ObservableProperty.INITIALIZER, IS_PRESENT, sequence(space(), child(ObservableProperty.INITIALIZER)))
+ ));
+
+ concreteSyntaxModelByClass.put(ArrayInitializerExpr.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.LBRACE),
+ list(ObservableProperty.VALUES, sequence(comma(), space()), space(), space()),
+ orphanCommentsEnding(),
+ token(RBRACE)));
+
+ concreteSyntaxModelByClass.put(AssignExpr.class, sequence(
+ comment(),
+ child(ObservableProperty.TARGET),
+ space(),
+ attribute(ObservableProperty.OPERATOR),
+ space(),
+ child(ObservableProperty.VALUE)
+ ));
+
+ concreteSyntaxModelByClass.put(BinaryExpr.class, sequence(
+ comment(),
+ child(ObservableProperty.LEFT),
+ space(),
+ attribute(ObservableProperty.OPERATOR),
+ space(),
+ child(ObservableProperty.RIGHT)
+ ));
+
+ concreteSyntaxModelByClass.put(BooleanLiteralExpr.class, sequence(
+ comment(), attribute(VALUE)
+ ));
+
+ concreteSyntaxModelByClass.put(CastExpr.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.LPAREN),
+ child(ObservableProperty.TYPE),
+ token(GeneratedJavaParserConstants.RPAREN),
+ space(),
+ child(ObservableProperty.EXPRESSION)
+ ));
+
+ concreteSyntaxModelByClass.put(CharLiteralExpr.class, sequence(
+ comment(),
+ charToken(ObservableProperty.VALUE)
+ ));
+
+ concreteSyntaxModelByClass.put(ClassExpr.class, sequence(
+ comment(), child(ObservableProperty.TYPE), token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.CLASS)));
+
+ concreteSyntaxModelByClass.put(ConditionalExpr.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.child(ObservableProperty.CONDITION),
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.HOOK),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.THEN_EXPR),
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.COLON),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.ELSE_EXPR)
+ ));
+
+ concreteSyntaxModelByClass.put(DoubleLiteralExpr.class, sequence(
+ comment(),
+ attribute(ObservableProperty.VALUE)
+ ));
+
+ concreteSyntaxModelByClass.put(EnclosedExpr.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.LPAREN),
+ child(ObservableProperty.INNER),
+ token(GeneratedJavaParserConstants.RPAREN)
+ ));
+
+ concreteSyntaxModelByClass.put(FieldAccessExpr.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.child(SCOPE),
+ CsmElement.token(GeneratedJavaParserConstants.DOT),
+ child(ObservableProperty.NAME)
+ ));
+
+ concreteSyntaxModelByClass.put(InstanceOfExpr.class, sequence(
+ comment(),
+ child(ObservableProperty.EXPRESSION),
+ space(),
+ token(GeneratedJavaParserConstants.INSTANCEOF),
+ space(),
+ child(ObservableProperty.TYPE)
+ ));
+
+ concreteSyntaxModelByClass.put(IntegerLiteralExpr.class, sequence(
+ comment(),
+ attribute(ObservableProperty.VALUE)
+ ));
+
+ concreteSyntaxModelByClass.put(LambdaExpr.class, sequence(
+ comment(),
+ conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.LPAREN)),
+ list(ObservableProperty.PARAMETERS, sequence(comma(), space())),
+ conditional(ObservableProperty.ENCLOSING_PARAMETERS, FLAG, token(GeneratedJavaParserConstants.RPAREN)),
+ space(),
+ token(GeneratedJavaParserConstants.ARROW),
+ space(),
+ conditional(ObservableProperty.EXPRESSION_BODY, IS_PRESENT, child(ObservableProperty.EXPRESSION_BODY), child(ObservableProperty.BODY))
+ ));
+
+ concreteSyntaxModelByClass.put(LongLiteralExpr.class, sequence(
+ comment(),
+ attribute(ObservableProperty.VALUE)
+ ));
+
+ concreteSyntaxModelByClass.put(MarkerAnnotationExpr.class, sequence(comment(), token(GeneratedJavaParserConstants.AT), attribute(ObservableProperty.NAME)));
+
+ concreteSyntaxModelByClass.put(MemberValuePair.class, CsmElement.sequence(CsmElement.comment(),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.ASSIGN),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.VALUE)));
+
+ concreteSyntaxModelByClass.put(MethodCallExpr.class, sequence(
+ comment(),
+ conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))),
+ typeArguments(),
+ child(ObservableProperty.NAME),
+ token(GeneratedJavaParserConstants.LPAREN),
+ list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()),
+ token(GeneratedJavaParserConstants.RPAREN)
+ ));
+
+ concreteSyntaxModelByClass.put(MethodReferenceExpr.class, sequence(
+ comment(),
+ child(ObservableProperty.SCOPE),
+ token(GeneratedJavaParserConstants.DOUBLECOLON),
+ typeArguments(),
+ attribute(ObservableProperty.IDENTIFIER)
+ ));
+
+ concreteSyntaxModelByClass.put(Name.class, sequence(
+ comment(),
+ conditional(ObservableProperty.QUALIFIER, IS_PRESENT, sequence(child(ObservableProperty.QUALIFIER), token(GeneratedJavaParserConstants.DOT))),
+ list(ObservableProperty.ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.space()),
+ attribute(ObservableProperty.IDENTIFIER),
+ orphanCommentsEnding()
+ ));
+
+ concreteSyntaxModelByClass.put(NameExpr.class, sequence(
+ comment(),
+ child(ObservableProperty.NAME),
+ orphanCommentsEnding()
+ ));
+
+ concreteSyntaxModelByClass.put(NormalAnnotationExpr.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.AT),
+ child(ObservableProperty.NAME),
+ token(GeneratedJavaParserConstants.LPAREN),
+ list(ObservableProperty.PAIRS, sequence(comma(), space())),
+ token(GeneratedJavaParserConstants.RPAREN)
+ ));
+
+ concreteSyntaxModelByClass.put(NullLiteralExpr.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.NULL)
+ ));
+
+ concreteSyntaxModelByClass.put(ObjectCreationExpr.class, sequence(
+ comment(),
+ conditional(ObservableProperty.SCOPE, IS_PRESENT, sequence(child(ObservableProperty.SCOPE), token(GeneratedJavaParserConstants.DOT))),
+ token(GeneratedJavaParserConstants.NEW),
+ space(),
+ list(ObservableProperty.TYPE_ARGUMENTS, CsmElement.sequence(CsmElement.comma(), CsmElement.space()), CsmElement.token(LT), CsmElement.token(GT)),
+ conditional(ObservableProperty.TYPE_ARGUMENTS, IS_NOT_EMPTY, space()),
+ child(ObservableProperty.TYPE),
+ token(GeneratedJavaParserConstants.LPAREN),
+ list(ObservableProperty.ARGUMENTS, sequence(comma(), space()), none(), none()),
+ token(GeneratedJavaParserConstants.RPAREN),
+ conditional(ObservableProperty.ANONYMOUS_CLASS_BODY, IS_PRESENT,
+ CsmElement.sequence(
+ CsmElement.space(), CsmElement.token(LBRACE), CsmElement.newline(), CsmElement.indent(),
+ CsmElement.list(ObservableProperty.ANONYMOUS_CLASS_BODY,
+ CsmElement.newline(),
+ CsmElement.newline(),
+ CsmElement.newline(),
+ CsmElement.newline()),
+ CsmElement.unindent(),
+ CsmElement.token(RBRACE)
+ ))
+ ));
+
+ concreteSyntaxModelByClass.put(SimpleName.class, attribute(ObservableProperty.IDENTIFIER));
+
+ concreteSyntaxModelByClass.put(SingleMemberAnnotationExpr.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.AT),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.token(GeneratedJavaParserConstants.LPAREN),
+ CsmElement.child(ObservableProperty.MEMBER_VALUE),
+ CsmElement.token(GeneratedJavaParserConstants.RPAREN)));
+
+ concreteSyntaxModelByClass.put(StringLiteralExpr.class, sequence(
+ comment(),
+ stringToken(ObservableProperty.VALUE)
+ ));
+
+ concreteSyntaxModelByClass.put(SuperExpr.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.conditional(ObservableProperty.CLASS_EXPR, IS_PRESENT, CsmElement.sequence(CsmElement.child(ObservableProperty.CLASS_EXPR), CsmElement.token(GeneratedJavaParserConstants.DOT))),
+ CsmElement.token(GeneratedJavaParserConstants.SUPER)
+ ));
+
+ concreteSyntaxModelByClass.put(ThisExpr.class, sequence(
+ comment(),
+ conditional(ObservableProperty.CLASS_EXPR, IS_PRESENT, sequence(child(CLASS_EXPR), token(GeneratedJavaParserConstants.DOT))),
+ token(GeneratedJavaParserConstants.THIS)
+ ));
+
+ concreteSyntaxModelByClass.put(TypeExpr.class, sequence(
+ comment(),
+ child(ObservableProperty.TYPE)
+ ));
+
+ concreteSyntaxModelByClass.put(UnaryExpr.class, sequence(
+ conditional(ObservableProperty.PREFIX, FLAG, attribute(ObservableProperty.OPERATOR)),
+ child(ObservableProperty.EXPRESSION),
+ conditional(ObservableProperty.POSTFIX, FLAG, attribute(ObservableProperty.OPERATOR))
+ ));
+
+ concreteSyntaxModelByClass.put(VariableDeclarationExpr.class, sequence(
+ comment(),
+ list(ObservableProperty.ANNOTATIONS, CsmElement.space(), CsmElement.none(), CsmElement.space()),
+ modifiers(),
+ child(ObservableProperty.MAXIMUM_COMMON_TYPE),
+ space(),
+ list(ObservableProperty.VARIABLES, sequence(comma(), space()))
+ ));
+
+ ///
+ /// Statements
+ ///
+
+ concreteSyntaxModelByClass.put(AssertStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.ASSERT),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.CHECK),
+ CsmElement.conditional(ObservableProperty.MESSAGE, IS_PRESENT, CsmElement.sequence(
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.COLON),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.MESSAGE)
+ )),
+ CsmElement.semicolon()
+ ));
+
+ concreteSyntaxModelByClass.put(BlockStmt.class, sequence(
+ orphanCommentsBeforeThis(),
+ comment(),
+ token(GeneratedJavaParserConstants.LBRACE),
+ newline(),
+ list(ObservableProperty.STATEMENTS, newline(), indent(), sequence(newline(), unindent())),
+ orphanCommentsEnding(),
+ token(RBRACE)
+ ));
+
+ concreteSyntaxModelByClass.put(BreakStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.BREAK),
+ CsmElement.conditional(ObservableProperty.LABEL, IS_PRESENT, CsmElement.sequence(CsmElement.space(), CsmElement.child(ObservableProperty.LABEL))),
+ CsmElement.semicolon()
+ ));
+
+ concreteSyntaxModelByClass.put(CatchClause.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.CATCH),
+ CsmElement.space(),
+ CsmElement.token(LPAREN),
+ CsmElement.child(ObservableProperty.PARAMETER),
+ CsmElement.token(RPAREN),
+ CsmElement.space(),
+ CsmElement.child(BODY)
+ ));
+
+ concreteSyntaxModelByClass.put(ContinueStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.CONTINUE),
+ CsmElement.conditional(ObservableProperty.LABEL, IS_PRESENT, CsmElement.sequence(CsmElement.space(), CsmElement.child(ObservableProperty.LABEL))),
+ CsmElement.semicolon()
+ ));
+
+ concreteSyntaxModelByClass.put(DoStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.DO),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.BODY),
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.WHILE),
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.LPAREN),
+ child(ObservableProperty.CONDITION),
+ CsmElement.token(GeneratedJavaParserConstants.RPAREN),
+ CsmElement.semicolon()
+ ));
+
+ concreteSyntaxModelByClass.put(EmptyStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.SEMICOLON)
+ ));
+
+ concreteSyntaxModelByClass.put(UnparsableStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.SEMICOLON)
+ ));
+
+ concreteSyntaxModelByClass.put(ExplicitConstructorInvocationStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.conditional(ObservableProperty.THIS, FLAG,
+ CsmElement.sequence(typeArguments(), CsmElement.token(GeneratedJavaParserConstants.THIS)),
+ CsmElement.sequence(
+ CsmElement.conditional(ObservableProperty.EXPRESSION, IS_PRESENT, CsmElement.sequence(CsmElement.child(ObservableProperty.EXPRESSION), CsmElement.token(GeneratedJavaParserConstants.DOT))),
+ typeArguments(),
+ CsmElement.token(GeneratedJavaParserConstants.SUPER)
+ )),
+ CsmElement.token(GeneratedJavaParserConstants.LPAREN),
+ CsmElement.list(ObservableProperty.ARGUMENTS, CsmElement.sequence(CsmElement.comma(), CsmElement.space())),
+ CsmElement.token(GeneratedJavaParserConstants.RPAREN),
+ CsmElement.semicolon()
+ ));
+
+ concreteSyntaxModelByClass.put(ExpressionStmt.class, sequence(
+ orphanCommentsBeforeThis(),
+ comment(),
+ child(ObservableProperty.EXPRESSION),
+ semicolon()
+ ));
+
+ concreteSyntaxModelByClass.put(ForeachStmt.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.FOR),
+ space(),
+ token(GeneratedJavaParserConstants.LPAREN),
+ child(ObservableProperty.VARIABLE),
+ space(),
+ token(GeneratedJavaParserConstants.COLON),
+ space(),
+ child(ObservableProperty.ITERABLE),
+ token(GeneratedJavaParserConstants.RPAREN),
+ space(),
+ child(ObservableProperty.BODY)
+ ));
+
+ concreteSyntaxModelByClass.put(ForStmt.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.FOR),
+ space(),
+ token(GeneratedJavaParserConstants.LPAREN),
+ list(ObservableProperty.INITIALIZATION, sequence(comma(), space())),
+ semicolon(),
+ space(),
+ child(ObservableProperty.COMPARE),
+ semicolon(),
+ space(),
+ list(ObservableProperty.UPDATE, sequence(comma(), space())),
+ token(GeneratedJavaParserConstants.RPAREN),
+ space(),
+ child(ObservableProperty.BODY)
+ ));
+
+ concreteSyntaxModelByClass.put(IfStmt.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.IF),
+ space(),
+ token(GeneratedJavaParserConstants.LPAREN),
+ child(ObservableProperty.CONDITION),
+ token(GeneratedJavaParserConstants.RPAREN),
+ conditional(ObservableProperty.THEN_BLOCK, CsmConditional.Condition.FLAG,
+ sequence(space(), child(ObservableProperty.THEN_STMT),
+ conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, space())),
+ sequence(newline(), CsmElement.indent(), child(ObservableProperty.THEN_STMT),
+ conditional(ObservableProperty.ELSE_STMT, IS_PRESENT, newline()),
+ unindent())),
+ conditional(ObservableProperty.ELSE_STMT, IS_PRESENT,
+ sequence(token(GeneratedJavaParserConstants.ELSE),
+ conditional(Arrays.asList(ObservableProperty.ELSE_BLOCK, ObservableProperty.CASCADING_IF_STMT), CsmConditional.Condition.FLAG,
+ sequence(space(), child(ObservableProperty.ELSE_STMT)),
+ sequence(newline(), CsmElement.indent(), child(ObservableProperty.ELSE_STMT), unindent()))))
+ ));
+
+ concreteSyntaxModelByClass.put(LabeledStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.child(ObservableProperty.LABEL),
+ CsmElement.token(GeneratedJavaParserConstants.COLON),
+ CsmElement.space(),
+ child(ObservableProperty.STATEMENT)
+ ));
+
+ concreteSyntaxModelByClass.put(LocalClassDeclarationStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.child(ObservableProperty.CLASS_DECLARATION)
+ ));
+
+ concreteSyntaxModelByClass.put(ReturnStmt.class, sequence(comment(), token(GeneratedJavaParserConstants.RETURN),
+ conditional(ObservableProperty.EXPRESSION, IS_PRESENT, sequence(space(), child(ObservableProperty.EXPRESSION))),
+ semicolon()));
+
+ concreteSyntaxModelByClass.put(SwitchEntryStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.conditional(ObservableProperty.LABEL, IS_PRESENT,
+ CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants.CASE), CsmElement.space(), CsmElement.child(ObservableProperty.LABEL), CsmElement.token(GeneratedJavaParserConstants.COLON)),
+ CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants._DEFAULT), CsmElement.token(GeneratedJavaParserConstants.COLON))),
+ CsmElement.newline(),
+ CsmElement.indent(),
+ CsmElement.list(ObservableProperty.STATEMENTS, CsmElement.newline(), CsmElement.none(), CsmElement.newline()),
+ CsmElement.unindent()
+ ));
+
+ concreteSyntaxModelByClass.put(SwitchStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.SWITCH),
+ CsmElement.token(GeneratedJavaParserConstants.LPAREN),
+ CsmElement.child(ObservableProperty.SELECTOR),
+ CsmElement.token(GeneratedJavaParserConstants.RPAREN),
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.LBRACE),
+ CsmElement.newline(),
+ CsmElement.list(ObservableProperty.ENTRIES, CsmElement.none(), CsmElement.indent(), CsmElement.unindent()),
+ CsmElement.token(GeneratedJavaParserConstants.RBRACE)
+ ));
+
+ concreteSyntaxModelByClass.put(SynchronizedStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.SYNCHRONIZED),
+ CsmElement.space(),
+ CsmElement.token(LPAREN),
+ CsmElement.child(EXPRESSION),
+ CsmElement.token(RPAREN),
+ CsmElement.space(),
+ CsmElement.child(BODY)
+ ));
+
+ concreteSyntaxModelByClass.put(ThrowStmt.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.THROW),
+ space(),
+ child(ObservableProperty.EXPRESSION),
+ semicolon()
+ ));
+
+ concreteSyntaxModelByClass.put(TryStmt.class, CsmElement.sequence(
+ CsmElement.comment(),
+ CsmElement.token(GeneratedJavaParserConstants.TRY),
+ CsmElement.space(),
+ CsmElement.conditional(ObservableProperty.RESOURCES, CsmConditional.Condition.IS_NOT_EMPTY, CsmElement.sequence(
+ CsmElement.token(LPAREN),
+ list(ObservableProperty.RESOURCES, CsmElement.sequence(CsmElement.semicolon(), CsmElement.newline()), CsmElement.indent(), CsmElement.unindent()),
+ CsmElement.token(RPAREN),
+ CsmElement.space())),
+ CsmElement.child(ObservableProperty.TRY_BLOCK),
+ CsmElement.list(ObservableProperty.CATCH_CLAUSES),
+ CsmElement.conditional(ObservableProperty.FINALLY_BLOCK, IS_PRESENT, CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.FINALLY), CsmElement.space(), CsmElement.child(ObservableProperty.FINALLY_BLOCK)))
+ ));
+
+ concreteSyntaxModelByClass.put(WhileStmt.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.WHILE),
+ space(),
+ token(GeneratedJavaParserConstants.LPAREN),
+ child(ObservableProperty.CONDITION),
+ token(GeneratedJavaParserConstants.RPAREN),
+ space(),
+ child(ObservableProperty.BODY)
+ ));
+
+ ///
+ /// Types
+ ///
+
+ concreteSyntaxModelByClass.put(ArrayType.class, sequence(
+ child(ObservableProperty.COMPONENT_TYPE),
+ list(ObservableProperty.ANNOTATIONS),
+ string(GeneratedJavaParserConstants.LBRACKET),
+ string(GeneratedJavaParserConstants.RBRACKET)));
+
+ concreteSyntaxModelByClass.put(ClassOrInterfaceType.class, sequence(comment(),
+ conditional(SCOPE, IS_PRESENT, sequence(child(SCOPE), string(GeneratedJavaParserConstants.DOT))),
+ list(ANNOTATIONS, space()),
+ child(NAME),
+ conditional(ObservableProperty.USING_DIAMOND_OPERATOR, FLAG,
+ sequence(string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)),
+ list(TYPE_ARGUMENTS, sequence(comma(), space()), string(GeneratedJavaParserConstants.LT), string(GeneratedJavaParserConstants.GT)))));
+
+ concreteSyntaxModelByClass.put(IntersectionType.class, CsmElement.sequence(
+ CsmElement.comment(),
+ annotations(),
+ CsmElement.list(ObservableProperty.ELEMENTS, CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.BIT_AND), CsmElement.space()))));
+
+ concreteSyntaxModelByClass.put(PrimitiveType.class, sequence(
+ comment(),
+ list(ObservableProperty.ANNOTATIONS),
+ attribute(ObservableProperty.TYPE)));
+
+ concreteSyntaxModelByClass.put(TypeParameter.class, sequence(
+ comment(),
+ annotations(),
+ child(ObservableProperty.NAME),
+ list(ObservableProperty.TYPE_BOUND,
+ sequence(
+ space(),
+ token(GeneratedJavaParserConstants.BIT_AND),
+ space()),
+ sequence(
+ space(),
+ token(GeneratedJavaParserConstants.EXTENDS),
+ space()),
+ none())
+ ));
+
+ concreteSyntaxModelByClass.put(UnionType.class, CsmElement.sequence(
+ CsmElement.comment(),
+ annotations(),
+ CsmElement.list(ObservableProperty.ELEMENTS, CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.BIT_OR), CsmElement.space()))
+ ));
+
+ concreteSyntaxModelByClass.put(UnknownType.class, none());
+
+ concreteSyntaxModelByClass.put(VoidType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.VOID)));
+
+ concreteSyntaxModelByClass.put(VarType.class, sequence(comment(), annotations(), string(GeneratedJavaParserConstants.IDENTIFIER, "var")));
+
+ concreteSyntaxModelByClass.put(WildcardType.class, sequence(comment(), annotations(), token(GeneratedJavaParserConstants.HOOK),
+ CsmElement.conditional(ObservableProperty.EXTENDED_TYPE, IS_PRESENT, CsmElement.sequence(space(), token(GeneratedJavaParserConstants.EXTENDS), space(), CsmElement.child(EXTENDED_TYPE))),
+ CsmElement.conditional(ObservableProperty.SUPER_TYPE, IS_PRESENT, CsmElement.sequence(space(), token(GeneratedJavaParserConstants.SUPER), space(), CsmElement.child(SUPER_TYPE)))));
+
+ ///
+ /// Top Level
+ ///
+
+ concreteSyntaxModelByClass.put(ArrayCreationLevel.class, sequence(
+ annotations(),
+ token(GeneratedJavaParserConstants.LBRACKET),
+ child(ObservableProperty.DIMENSION),
+ token(GeneratedJavaParserConstants.RBRACKET)
+ ));
+
+ concreteSyntaxModelByClass.put(CompilationUnit.class, sequence(
+ comment(),
+ child(ObservableProperty.PACKAGE_DECLARATION),
+ list(ObservableProperty.IMPORTS, none(), none(), newline()),
+ list(TYPES, newline(), CsmElement.newline(), CsmElement.none(), CsmElement.newline()),
+ child(ObservableProperty.MODULE),
+ orphanCommentsEnding()));
+
+ concreteSyntaxModelByClass.put(ImportDeclaration.class, sequence(
+ comment(),
+ token(GeneratedJavaParserConstants.IMPORT),
+ space(),
+ conditional(ObservableProperty.STATIC, FLAG, sequence(token(GeneratedJavaParserConstants.STATIC), space())),
+ child(ObservableProperty.NAME),
+ conditional(ASTERISK, FLAG, sequence(token(GeneratedJavaParserConstants.DOT), token(GeneratedJavaParserConstants.STAR))),
+ semicolon(),
+ newline(),
+ orphanCommentsEnding()
+ ));
+
+ concreteSyntaxModelByClass.put(PackageDeclaration.class, sequence(
+ comment(),
+ list(ObservableProperty.ANNOTATIONS),
+ token(GeneratedJavaParserConstants.PACKAGE),
+ space(),
+ child(ObservableProperty.NAME),
+ semicolon(),
+ newline(),
+ newline(),
+ orphanCommentsEnding()));
+
+ ///
+ /// Module info
+ ///
+
+ concreteSyntaxModelByClass.put(ModuleDeclaration.class, CsmElement.sequence(
+ annotations(),
+ CsmElement.conditional(ObservableProperty.OPEN, FLAG, CsmElement.sequence(CsmElement.token(GeneratedJavaParserConstants.OPEN), CsmElement.space())),
+ CsmElement.token(GeneratedJavaParserConstants.MODULE),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.space(),
+ CsmElement.token(GeneratedJavaParserConstants.LBRACE),
+ CsmElement.newline(),
+ CsmElement.indent(),
+ CsmElement.list(ObservableProperty.MODULE_STMTS),
+ CsmElement.unindent(),
+ CsmElement.token(GeneratedJavaParserConstants.RBRACE),
+ CsmElement.newline()
+ ));
+
+ concreteSyntaxModelByClass.put(ModuleExportsStmt.class, CsmElement.sequence(
+ CsmElement.token(GeneratedJavaParserConstants.EXPORTS),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.list(ObservableProperty.MODULE_NAMES,
+ CsmElement.sequence(CsmElement.comma(), CsmElement.space()),
+ CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.TO), CsmElement.space()),
+ CsmElement.none()),
+ CsmElement.semicolon(),
+ CsmElement.newline()
+ ));
+
+ concreteSyntaxModelByClass.put(ModuleOpensStmt.class, CsmElement.sequence(
+ CsmElement.token(GeneratedJavaParserConstants.OPENS),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.list(ObservableProperty.MODULE_NAMES,
+ CsmElement.sequence(CsmElement.comma(), CsmElement.space()),
+ CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.TO), CsmElement.space()),
+ CsmElement.none()),
+ CsmElement.semicolon(),
+ CsmElement.newline()
+ ));
+
+ concreteSyntaxModelByClass.put(ModuleProvidesStmt.class, CsmElement.sequence(
+ CsmElement.token(GeneratedJavaParserConstants.PROVIDES),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.TYPE),
+ CsmElement.list(ObservableProperty.WITH_TYPES,
+ CsmElement.sequence(CsmElement.comma(), CsmElement.space()),
+ CsmElement.sequence(CsmElement.space(), CsmElement.token(GeneratedJavaParserConstants.WITH), CsmElement.space()),
+ CsmElement.none()),
+ CsmElement.semicolon(),
+ CsmElement.newline()
+ ));
+
+ concreteSyntaxModelByClass.put(ModuleRequiresStmt.class, CsmElement.sequence(
+ CsmElement.token(GeneratedJavaParserConstants.REQUIRES),
+ CsmElement.space(),
+ modifiers(),
+ CsmElement.child(ObservableProperty.NAME),
+ CsmElement.semicolon(),
+ CsmElement.newline()
+ ));
+
+ concreteSyntaxModelByClass.put(ModuleUsesStmt.class, CsmElement.sequence(
+ CsmElement.token(GeneratedJavaParserConstants.USES),
+ CsmElement.space(),
+ CsmElement.child(ObservableProperty.TYPE),
+ CsmElement.semicolon(),
+ CsmElement.newline()
+ ));
+
+ List<String> unsupportedNodeClassNames = JavaParserMetaModel.getNodeMetaModels().stream()
+ .filter(c -> !c.isAbstract() && !Comment.class.isAssignableFrom(c.getType()) && !concreteSyntaxModelByClass.containsKey(c.getType()))
+ .map(nm -> nm.getType().getSimpleName())
+ .collect(Collectors.toList());
+ if (unsupportedNodeClassNames.isEmpty()) {
+ initializationError = Optional.empty();
+ } else {
+ initializationError = Optional.of("The CSM should include support for these classes: " + String.join(", ", unsupportedNodeClassNames));
+ }
+ }
+
+ private ConcreteSyntaxModel() {
+
+ }
+
+ public static void genericPrettyPrint(Node node, SourcePrinter printer) {
+ forClass(node.getClass()).prettyPrint(node, printer);
+ }
+
+ public static String genericPrettyPrint(Node node) {
+ SourcePrinter sourcePrinter = new SourcePrinter(" ", EOL);
+ forClass(node.getClass()).prettyPrint(node, sourcePrinter);
+ return sourcePrinter.getSource();
+ }
+
+ public static CsmElement forClass(Class<? extends Node> nodeClazz) {
+ initializationError.ifPresent(s -> {
+ throw new IllegalStateException(s);
+ });
+ if (!concreteSyntaxModelByClass.containsKey(nodeClazz)) {
+ throw new UnsupportedOperationException(nodeClazz.getSimpleName());
+ }
+ return concreteSyntaxModelByClass.get(nodeClazz);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java
new file mode 100644
index 000000000..2e190c942
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/DotPrinter.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer;
+
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.toList;
+
+import java.util.List;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.metamodel.NodeMetaModel;
+import com.github.javaparser.metamodel.PropertyMetaModel;
+
+/**
+ * Outputs a Graphviz diagram of the AST.
+ */
+public class DotPrinter {
+
+ private int nodeCount;
+ private final boolean outputNodeType;
+
+ public DotPrinter(boolean outputNodeType) {
+ this.outputNodeType = outputNodeType;
+ }
+
+ public String output(Node node) {
+ nodeCount = 0;
+ StringBuilder output = new StringBuilder();
+ output.append("digraph {");
+ output(node, null, "root", output);
+ output.append(System.lineSeparator() + "}");
+ return output.toString();
+ }
+
+ public void output(Node node, String parentNodeName, String name, StringBuilder builder) {
+ assertNotNull(node);
+ NodeMetaModel metaModel = node.getMetaModel();
+ List<PropertyMetaModel> allPropertyMetaModels = metaModel.getAllPropertyMetaModels();
+ List<PropertyMetaModel> attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute)
+ .filter(PropertyMetaModel::isSingular).collect(toList());
+ List<PropertyMetaModel> subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode)
+ .filter(PropertyMetaModel::isSingular).collect(toList());
+ List<PropertyMetaModel> subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList)
+ .collect(toList());
+
+ String ndName = nextNodeName();
+ if (outputNodeType)
+ builder.append(System.lineSeparator() + ndName + " [label=\"" + name + " (" + metaModel.getTypeName()
+ + ")\"];");
+ else
+ builder.append(System.lineSeparator() + ndName + " [label=\"" + name + "\"];");
+
+ if (parentNodeName != null)
+ builder.append(System.lineSeparator() + parentNodeName + " -> " + ndName + ";");
+
+ for (PropertyMetaModel a : attributes) {
+ String attrName = nextNodeName();
+ builder.append(System.lineSeparator() + attrName + " [label=\"" + a.getName() + "='"
+ + a.getValue(node).toString() + "'\"];");
+ builder.append(System.lineSeparator() + ndName + " -> " + attrName + ";");
+
+ }
+
+ for (PropertyMetaModel sn : subNodes) {
+ Node nd = (Node) sn.getValue(node);
+ if (nd != null)
+ output(nd, ndName, sn.getName(), builder);
+ }
+
+ for (PropertyMetaModel sl : subLists) {
+ NodeList<? extends Node> nl = (NodeList<? extends Node>) sl.getValue(node);
+ if (nl != null && nl.isNonEmpty()) {
+ String ndLstName = nextNodeName();
+ builder.append(System.lineSeparator() + ndLstName + " [label=\"" + sl.getName() + "\"];");
+ builder.append(System.lineSeparator() + ndName + " -> " + ndLstName + ";");
+ String slName = sl.getName().substring(0, sl.getName().length() - 1);
+ for (Node nd : nl)
+ output(nd, ndLstName, slName, builder);
+ }
+ }
+ }
+
+ private String nextNodeName() {
+ return "n" + (nodeCount++);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/JsonPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/JsonPrinter.java
new file mode 100644
index 000000000..237051265
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/JsonPrinter.java
@@ -0,0 +1,74 @@
+package com.github.javaparser.printer;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.metamodel.NodeMetaModel;
+import com.github.javaparser.metamodel.PropertyMetaModel;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Outputs a JSON file containing the AST meant for inspecting it.
+ */
+public class JsonPrinter {
+ private final boolean outputNodeType;
+
+ public JsonPrinter(boolean outputNodeType) {
+ this.outputNodeType = outputNodeType;
+ }
+
+ public String output(Node node) {
+ return output(node, null, 0);
+ }
+
+ public String output(Node node, String name, int level) {
+ assertNotNull(node);
+ NodeMetaModel metaModel = node.getMetaModel();
+ List<PropertyMetaModel> allPropertyMetaModels = metaModel.getAllPropertyMetaModels();
+ List<PropertyMetaModel> attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList());
+ List<PropertyMetaModel> subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList());
+ List<PropertyMetaModel> subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList());
+
+ final List<String> content = new ArrayList<>();
+
+ if (outputNodeType) {
+ content.add(q("type") + ":" + q(metaModel.getTypeName()));
+ }
+
+ for (PropertyMetaModel attributeMetaModel : attributes) {
+ content.add(q(attributeMetaModel.getName()) + ":" + q(attributeMetaModel.getValue(node).toString()));
+ }
+
+ for (PropertyMetaModel subNodeMetaModel : subNodes) {
+ Node value = (Node) subNodeMetaModel.getValue(node);
+ if (value != null) {
+ content.add(output(value, subNodeMetaModel.getName(), level + 1));
+ }
+ }
+
+ for (PropertyMetaModel subListMetaModel : subLists) {
+ NodeList<? extends Node> subList = (NodeList<? extends Node>) subListMetaModel.getValue(node);
+ if (subList != null && !subList.isEmpty()) {
+ final List<String> listContent = new ArrayList<>();
+ for (Node subListNode : subList) {
+ listContent.add(output(subListNode, null, level + 1));
+ }
+ content.add(listContent.stream().collect(Collectors.joining(",", q(subListMetaModel.getName()) + ":[", "]")));
+ }
+ }
+
+ if (name == null) {
+ return content.stream().collect(Collectors.joining(",", "{", "}"));
+ }
+ return content.stream().collect(Collectors.joining(",", q(name) + ":{", "}"));
+ }
+
+ private static String q(String value) {
+ return "\"" + value.replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "\\r") + "\"";
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java
new file mode 100644
index 000000000..8a1d6b510
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrintVisitor.java
@@ -0,0 +1,1609 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer;
+
+import com.github.javaparser.Position;
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.nodeTypes.NodeWithTypeArguments;
+import com.github.javaparser.ast.nodeTypes.NodeWithVariables;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import com.github.javaparser.ast.visitor.Visitable;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE;
+import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition;
+import static com.github.javaparser.utils.Utils.isNullOrEmpty;
+import static com.github.javaparser.utils.Utils.normalizeEolInTextBlock;
+import static com.github.javaparser.utils.Utils.trimTrailingSpaces;
+
+/**
+ * Outputs the AST as formatted Java source code.
+ *
+ * @author Julio Vilmar Gesser
+ */
+public class PrettyPrintVisitor implements VoidVisitor<Void> {
+ protected final PrettyPrinterConfiguration configuration;
+ protected final SourcePrinter printer;
+ private Deque<Position> methodChainPositions = new LinkedList<>();
+
+ public PrettyPrintVisitor(PrettyPrinterConfiguration prettyPrinterConfiguration) {
+ configuration = prettyPrinterConfiguration;
+ printer = new SourcePrinter(configuration.getIndent(), configuration.getEndOfLineCharacter());
+ pushMethodChainPosition(printer.getCursor()); // initialize a default position for methodChainPositions, it is expected by method #resetMethodChainPosition()
+ }
+
+ public String getSource() {
+ return printer.getSource();
+ }
+
+ public void resetMethodChainPosition(Position position) {
+ this.methodChainPositions.pop();
+ this.methodChainPositions.push(position);
+ }
+
+ public void pushMethodChainPosition(Position position) {
+ this.methodChainPositions.push(position);
+ }
+
+ public Position peekMethodChainPosition() {
+ return this.methodChainPositions.peek();
+ }
+
+ public Position popMethodChainPosition() {
+ return this.methodChainPositions.pop();
+ }
+
+ private void printModifiers(final EnumSet<Modifier> modifiers) {
+ if (modifiers.size() > 0) {
+ printer.print(modifiers.stream().map(Modifier::asString).collect(Collectors.joining(" ")) + " ");
+ }
+ }
+
+ private void printMembers(final NodeList<BodyDeclaration<?>> members, final Void arg) {
+ for (final BodyDeclaration<?> member : members) {
+ printer.println();
+ member.accept(this, arg);
+ printer.println();
+ }
+ }
+
+ private void printMemberAnnotations(final NodeList<AnnotationExpr> annotations, final Void arg) {
+ if (annotations.isEmpty()) {
+ return;
+ }
+ for (final AnnotationExpr a : annotations) {
+ a.accept(this, arg);
+ printer.println();
+ }
+ }
+
+ private void printAnnotations(final NodeList<AnnotationExpr> annotations, boolean prefixWithASpace,
+ final Void arg) {
+ if (annotations.isEmpty()) {
+ return;
+ }
+ if (prefixWithASpace) {
+ printer.print(" ");
+ }
+ for (AnnotationExpr annotation : annotations) {
+ annotation.accept(this, arg);
+ printer.print(" ");
+ }
+ }
+
+ private void printTypeArgs(final NodeWithTypeArguments<?> nodeWithTypeArguments, final Void arg) {
+ NodeList<Type> typeArguments = nodeWithTypeArguments.getTypeArguments().orElse(null);
+ if (!isNullOrEmpty(typeArguments)) {
+ printer.print("<");
+ for (final Iterator<Type> i = typeArguments.iterator(); i.hasNext(); ) {
+ final Type t = i.next();
+ t.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ printer.print(">");
+ }
+ }
+
+ private void printTypeParameters(final NodeList<TypeParameter> args, final Void arg) {
+ if (!isNullOrEmpty(args)) {
+ printer.print("<");
+ for (final Iterator<TypeParameter> i = args.iterator(); i.hasNext(); ) {
+ final TypeParameter t = i.next();
+ t.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ printer.print(">");
+ }
+ }
+
+ private void printArguments(final NodeList<Expression> args, final Void arg) {
+ printer.print("(");
+ Position cursorRef = printer.getCursor();
+ if (!isNullOrEmpty(args)) {
+ for (final Iterator<Expression> i = args.iterator(); i.hasNext(); ) {
+ final Expression e = i.next();
+ e.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(",");
+ if (configuration.isColumnAlignParameters()) {
+ printer.wrapToColumn(cursorRef.column);
+ } else {
+ printer.print(" ");
+ }
+ }
+ }
+ }
+ printer.print(")");
+ }
+
+ private void printPrePostFixOptionalList(final NodeList<? extends Visitable> args, final Void arg, String prefix, String separator, String postfix) {
+ if (!args.isEmpty()) {
+ printer.print(prefix);
+ for (final Iterator<? extends Visitable> i = args.iterator(); i.hasNext(); ) {
+ final Visitable v = i.next();
+ v.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(separator);
+ }
+ }
+ printer.print(postfix);
+ }
+ }
+
+ private void printPrePostFixRequiredList(final NodeList<? extends Visitable> args, final Void arg, String prefix, String separator, String postfix) {
+ printer.print(prefix);
+ if (!args.isEmpty()) {
+ for (final Iterator<? extends Visitable> i = args.iterator(); i.hasNext(); ) {
+ final Visitable v = i.next();
+ v.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(separator);
+ }
+ }
+ }
+ printer.print(postfix);
+ }
+
+ private void printComment(final Optional<Comment> comment, final Void arg) {
+ comment.ifPresent(c -> c.accept(this, arg));
+ }
+
+ @Override
+ public void visit(final CompilationUnit n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getParsed() == UNPARSABLE) {
+ printer.println("???");
+ return;
+ }
+
+ if (n.getPackageDeclaration().isPresent()) {
+ n.getPackageDeclaration().get().accept(this, arg);
+ }
+
+ n.getImports().accept(this, arg);
+ if (!n.getImports().isEmpty()) {
+ printer.println();
+ }
+
+ for (final Iterator<TypeDeclaration<?>> i = n.getTypes().iterator(); i.hasNext(); ) {
+ i.next().accept(this, arg);
+ printer.println();
+ if (i.hasNext()) {
+ printer.println();
+ }
+ }
+
+ n.getModule().ifPresent(m -> m.accept(this, arg));
+
+ printOrphanCommentsEnding(n);
+ }
+
+ @Override
+ public void visit(final PackageDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), false, arg);
+ printer.print("package ");
+ n.getName().accept(this, arg);
+ printer.println(";");
+ printer.println();
+
+ printOrphanCommentsEnding(n);
+ }
+
+ @Override
+ public void visit(final NameExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getName().accept(this, arg);
+
+ printOrphanCommentsEnding(n);
+ }
+
+ @Override
+ public void visit(final Name n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getQualifier().isPresent()) {
+ n.getQualifier().get().accept(this, arg);
+ printer.print(".");
+ }
+ printAnnotations(n.getAnnotations(), false, arg);
+ printer.print(n.getIdentifier());
+
+ printOrphanCommentsEnding(n);
+ }
+
+ @Override
+ public void visit(SimpleName n, Void arg) {
+ printer.print(n.getIdentifier());
+ }
+
+ @Override
+ public void visit(final ClassOrInterfaceDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printMemberAnnotations(n.getAnnotations(), arg);
+ printModifiers(n.getModifiers());
+
+ if (n.isInterface()) {
+ printer.print("interface ");
+ } else {
+ printer.print("class ");
+ }
+
+ n.getName().accept(this, arg);
+
+ printTypeParameters(n.getTypeParameters(), arg);
+
+ if (!n.getExtendedTypes().isEmpty()) {
+ printer.print(" extends ");
+ for (final Iterator<ClassOrInterfaceType> i = n.getExtendedTypes().iterator(); i.hasNext(); ) {
+ final ClassOrInterfaceType c = i.next();
+ c.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+
+ if (!n.getImplementedTypes().isEmpty()) {
+ printer.print(" implements ");
+ for (final Iterator<ClassOrInterfaceType> i = n.getImplementedTypes().iterator(); i.hasNext(); ) {
+ final ClassOrInterfaceType c = i.next();
+ c.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+
+ printer.println(" {");
+ printer.indent();
+ if (!isNullOrEmpty(n.getMembers())) {
+ printMembers(n.getMembers(), arg);
+ }
+
+ printOrphanCommentsEnding(n);
+
+ printer.unindent();
+ printer.print("}");
+ }
+
+ @Override
+ public void visit(final JavadocComment n, final Void arg) {
+ if (configuration.isPrintComments() && configuration.isPrintJavadoc()) {
+ printer.println("/**");
+ final String commentContent = normalizeEolInTextBlock(n.getContent(), configuration.getEndOfLineCharacter());
+ String[] lines = commentContent.split("\\R");
+ boolean skippingLeadingEmptyLines = true;
+ boolean prependEmptyLine = false;
+ for (String line : lines) {
+ final String trimmedLine = line.trim();
+ if (trimmedLine.startsWith("*")) {
+ line = trimmedLine.substring(1);
+ }
+ line = trimTrailingSpaces(line);
+ if (line.isEmpty()) {
+ if (!skippingLeadingEmptyLines) {
+ prependEmptyLine = true;
+ }
+ } else {
+ skippingLeadingEmptyLines = false;
+ if (prependEmptyLine) {
+ printer.println(" *");
+ prependEmptyLine = false;
+ }
+ printer.println(" *" + line);
+ }
+ }
+ printer.println(" */");
+ }
+ }
+
+ @Override
+ public void visit(final ClassOrInterfaceType n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getScope().isPresent()) {
+ n.getScope().get().accept(this, arg);
+ printer.print(".");
+ }
+ for (AnnotationExpr ae : n.getAnnotations()) {
+ ae.accept(this, arg);
+ printer.print(" ");
+ }
+
+ n.getName().accept(this, arg);
+
+ if (n.isUsingDiamondOperator()) {
+ printer.print("<>");
+ } else {
+ printTypeArgs(n, arg);
+ }
+ }
+
+ @Override
+ public void visit(final TypeParameter n, final Void arg) {
+ printComment(n.getComment(), arg);
+ for (AnnotationExpr ann : n.getAnnotations()) {
+ ann.accept(this, arg);
+ printer.print(" ");
+ }
+ n.getName().accept(this, arg);
+ if (!isNullOrEmpty(n.getTypeBound())) {
+ printer.print(" extends ");
+ for (final Iterator<ClassOrInterfaceType> i = n.getTypeBound().iterator(); i.hasNext(); ) {
+ final ClassOrInterfaceType c = i.next();
+ c.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(" & ");
+ }
+ }
+ }
+ }
+
+ @Override
+ public void visit(final PrimitiveType n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), true, arg);
+ printer.print(n.getType().asString());
+ }
+
+ @Override
+ public void visit(final ArrayType n, final Void arg) {
+ final List<ArrayType> arrayTypeBuffer = new LinkedList<>();
+ Type type = n;
+ while (type instanceof ArrayType) {
+ final ArrayType arrayType = (ArrayType) type;
+ arrayTypeBuffer.add(arrayType);
+ type = arrayType.getComponentType();
+ }
+
+ type.accept(this, arg);
+ for (ArrayType arrayType : arrayTypeBuffer) {
+ printAnnotations(arrayType.getAnnotations(), true, arg);
+ printer.print("[]");
+ }
+ }
+
+ @Override
+ public void visit(final ArrayCreationLevel n, final Void arg) {
+ printAnnotations(n.getAnnotations(), true, arg);
+ printer.print("[");
+ if (n.getDimension().isPresent()) {
+ n.getDimension().get().accept(this, arg);
+ }
+ printer.print("]");
+ }
+
+ @Override
+ public void visit(final IntersectionType n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), false, arg);
+ boolean isFirst = true;
+ for (ReferenceType element : n.getElements()) {
+ if (isFirst) {
+ isFirst = false;
+ } else {
+ printer.print(" & ");
+ }
+ element.accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(final UnionType n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), true, arg);
+ boolean isFirst = true;
+ for (ReferenceType element : n.getElements()) {
+ if (isFirst) {
+ isFirst = false;
+ } else {
+ printer.print(" | ");
+ }
+ element.accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(final WildcardType n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), false, arg);
+ printer.print("?");
+ if (n.getExtendedType().isPresent()) {
+ printer.print(" extends ");
+ n.getExtendedType().get().accept(this, arg);
+ }
+ if (n.getSuperType().isPresent()) {
+ printer.print(" super ");
+ n.getSuperType().get().accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(final UnknownType n, final Void arg) {
+ // Nothing to print
+ }
+
+ @Override
+ public void visit(final FieldDeclaration n, final Void arg) {
+ printOrphanCommentsBeforeThisChildNode(n);
+
+ printComment(n.getComment(), arg);
+ printMemberAnnotations(n.getAnnotations(), arg);
+ printModifiers(n.getModifiers());
+ if (!n.getVariables().isEmpty()) {
+ Optional<Type> maximumCommonType = n.getMaximumCommonType();
+ maximumCommonType.ifPresent(t -> t.accept(this, arg));
+ if (!maximumCommonType.isPresent()) {
+ printer.print("???");
+ }
+ }
+
+ printer.print(" ");
+ for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext(); ) {
+ final VariableDeclarator var = i.next();
+ var.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final VariableDeclarator n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getName().accept(this, arg);
+
+ n.getAncestorOfType(NodeWithVariables.class).ifPresent(ancestor -> {
+ ((NodeWithVariables<?>) ancestor).getMaximumCommonType().ifPresent(commonType -> {
+
+ final Type type = n.getType();
+
+ ArrayType arrayType = null;
+
+ for (int i = commonType.getArrayLevel(); i < type.getArrayLevel(); i++) {
+ if (arrayType == null) {
+ arrayType = (ArrayType) type;
+ } else {
+ arrayType = (ArrayType) arrayType.getComponentType();
+ }
+ printAnnotations(arrayType.getAnnotations(), true, arg);
+ printer.print("[]");
+ }
+ });
+ });
+
+ if (n.getInitializer().isPresent()) {
+ printer.print(" = ");
+ n.getInitializer().get().accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(final ArrayInitializerExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("{");
+ if (!isNullOrEmpty(n.getValues())) {
+ printer.print(" ");
+ for (final Iterator<Expression> i = n.getValues().iterator(); i.hasNext(); ) {
+ final Expression expr = i.next();
+ expr.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ printer.print(" ");
+ }
+ printOrphanCommentsEnding(n);
+ printer.print("}");
+ }
+
+ @Override
+ public void visit(final VoidType n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), false, arg);
+ printer.print("void");
+ }
+
+ @Override
+ public void visit(final VarType n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), false, arg);
+ printer.print("var");
+ }
+
+ @Override
+ public void visit(final ArrayAccessExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getName().accept(this, arg);
+ printer.print("[");
+ n.getIndex().accept(this, arg);
+ printer.print("]");
+ }
+
+ @Override
+ public void visit(final ArrayCreationExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("new ");
+ n.getElementType().accept(this, arg);
+ for (ArrayCreationLevel level : n.getLevels()) {
+ level.accept(this, arg);
+ }
+ if (n.getInitializer().isPresent()) {
+ printer.print(" ");
+ n.getInitializer().get().accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(final AssignExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getTarget().accept(this, arg);
+ printer.print(" ");
+ printer.print(n.getOperator().asString());
+ printer.print(" ");
+ n.getValue().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final BinaryExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getLeft().accept(this, arg);
+ printer.print(" ");
+ printer.print(n.getOperator().asString());
+ printer.print(" ");
+ n.getRight().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final CastExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("(");
+ n.getType().accept(this, arg);
+ printer.print(") ");
+ n.getExpression().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final ClassExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getType().accept(this, arg);
+ printer.print(".class");
+ }
+
+ @Override
+ public void visit(final ConditionalExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getCondition().accept(this, arg);
+ printer.print(" ? ");
+ n.getThenExpr().accept(this, arg);
+ printer.print(" : ");
+ n.getElseExpr().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final EnclosedExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("(");
+ n.getInner().accept(this, arg);
+ printer.print(")");
+ }
+
+ @Override
+ public void visit(final FieldAccessExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getScope().accept(this, arg);
+ printer.print(".");
+ n.getName().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final InstanceOfExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getExpression().accept(this, arg);
+ printer.print(" instanceof ");
+ n.getType().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final CharLiteralExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("'");
+ printer.print(n.getValue());
+ printer.print("'");
+ }
+
+ @Override
+ public void visit(final DoubleLiteralExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print(n.getValue());
+ }
+
+ @Override
+ public void visit(final IntegerLiteralExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print(n.getValue());
+ }
+
+ @Override
+ public void visit(final LongLiteralExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print(n.getValue());
+ }
+
+ @Override
+ public void visit(final StringLiteralExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("\"");
+ printer.print(n.getValue());
+ printer.print("\"");
+ }
+
+ @Override
+ public void visit(final BooleanLiteralExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print(String.valueOf(n.getValue()));
+ }
+
+ @Override
+ public void visit(final NullLiteralExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("null");
+ }
+
+ @Override
+ public void visit(final ThisExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getClassExpr().isPresent()) {
+ n.getClassExpr().get().accept(this, arg);
+ printer.print(".");
+ }
+ printer.print("this");
+ }
+
+ @Override
+ public void visit(final SuperExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getClassExpr().isPresent()) {
+ n.getClassExpr().get().accept(this, arg);
+ printer.print(".");
+ }
+ printer.print("super");
+ }
+
+ @Override
+ public void visit(final MethodCallExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getScope().isPresent()) {
+ n.getScope().get().accept(this, arg);
+ if (configuration.isColumnAlignFirstMethodChain()) {
+ if (!(n.getScope().get() instanceof MethodCallExpr) || (!((MethodCallExpr) n.getScope().get()).getScope().isPresent())) {
+ resetMethodChainPosition(printer.getCursor());
+ } else {
+ printer.wrapToColumn(peekMethodChainPosition().column);
+ }
+ }
+ printer.print(".");
+ }
+ printTypeArgs(n, arg);
+ n.getName().accept(this, arg);
+ pushMethodChainPosition(printer.getCursor());
+ printArguments(n.getArguments(), arg);
+ popMethodChainPosition();
+ }
+
+ @Override
+ public void visit(final ObjectCreationExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getScope().isPresent()) {
+ n.getScope().get().accept(this, arg);
+ printer.print(".");
+ }
+
+ printer.print("new ");
+
+ printTypeArgs(n, arg);
+ if (!isNullOrEmpty(n.getTypeArguments().orElse(null))) {
+ printer.print(" ");
+ }
+
+ n.getType().accept(this, arg);
+
+ printArguments(n.getArguments(), arg);
+
+ if (n.getAnonymousClassBody().isPresent()) {
+ printer.println(" {");
+ printer.indent();
+ printMembers(n.getAnonymousClassBody().get(), arg);
+ printer.unindent();
+ printer.print("}");
+ }
+ }
+
+ @Override
+ public void visit(final UnaryExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getOperator().isPrefix()) {
+ printer.print(n.getOperator().asString());
+ }
+
+ n.getExpression().accept(this, arg);
+
+ if (n.getOperator().isPostfix()) {
+ printer.print(n.getOperator().asString());
+ }
+ }
+
+ @Override
+ public void visit(final ConstructorDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printMemberAnnotations(n.getAnnotations(), arg);
+ printModifiers(n.getModifiers());
+
+ printTypeParameters(n.getTypeParameters(), arg);
+ if (n.isGeneric()) {
+ printer.print(" ");
+ }
+ n.getName().accept(this, arg);
+
+ printer.print("(");
+ if (!n.getParameters().isEmpty()) {
+ for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) {
+ final Parameter p = i.next();
+ p.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+ printer.print(")");
+
+ if (!isNullOrEmpty(n.getThrownExceptions())) {
+ printer.print(" throws ");
+ for (final Iterator<ReferenceType> i = n.getThrownExceptions().iterator(); i.hasNext(); ) {
+ final ReferenceType name = i.next();
+ name.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+ printer.print(" ");
+ n.getBody().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final MethodDeclaration n, final Void arg) {
+ printOrphanCommentsBeforeThisChildNode(n);
+
+ printComment(n.getComment(), arg);
+ printMemberAnnotations(n.getAnnotations(), arg);
+ printModifiers(n.getModifiers());
+ printTypeParameters(n.getTypeParameters(), arg);
+ if (!isNullOrEmpty(n.getTypeParameters())) {
+ printer.print(" ");
+ }
+
+ n.getType().accept(this, arg);
+ printer.print(" ");
+ n.getName().accept(this, arg);
+
+ printer.print("(");
+ n.getReceiverParameter().ifPresent(rp -> {
+ rp.accept(this, arg);
+ printer.print(", ");
+ });
+ if (!isNullOrEmpty(n.getParameters())) {
+ for (final Iterator<Parameter> i = n.getParameters().iterator(); i.hasNext(); ) {
+ final Parameter p = i.next();
+ p.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+ printer.print(")");
+
+ if (!isNullOrEmpty(n.getThrownExceptions())) {
+ printer.print(" throws ");
+ for (final Iterator<ReferenceType> i = n.getThrownExceptions().iterator(); i.hasNext(); ) {
+ final ReferenceType name = i.next();
+ name.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+ if (!n.getBody().isPresent()) {
+ printer.print(";");
+ } else {
+ printer.print(" ");
+ n.getBody().get().accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(final Parameter n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), false, arg);
+ printModifiers(n.getModifiers());
+ n.getType().accept(this, arg);
+ if (n.isVarArgs()) {
+ printAnnotations(n.getVarArgsAnnotations(), false, arg);
+ printer.print("...");
+ }
+ if (!(n.getType() instanceof UnknownType)) {
+ printer.print(" ");
+ }
+ n.getName().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final ReceiverParameter n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), false, arg);
+ n.getType().accept(this, arg);
+ printer.print(" ");
+ n.getName().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final ExplicitConstructorInvocationStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.isThis()) {
+ printTypeArgs(n, arg);
+ printer.print("this");
+ } else {
+ if (n.getExpression().isPresent()) {
+ n.getExpression().get().accept(this, arg);
+ printer.print(".");
+ }
+ printTypeArgs(n, arg);
+ printer.print("super");
+ }
+ printArguments(n.getArguments(), arg);
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final VariableDeclarationExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printAnnotations(n.getAnnotations(), false, arg);
+ printModifiers(n.getModifiers());
+
+ if (!n.getVariables().isEmpty()) {
+ n.getMaximumCommonType().ifPresent(t -> t.accept(this, arg));
+ }
+ printer.print(" ");
+
+ for (final Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext(); ) {
+ final VariableDeclarator v = i.next();
+ v.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+
+ @Override
+ public void visit(final LocalClassDeclarationStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getClassDeclaration().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final AssertStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("assert ");
+ n.getCheck().accept(this, arg);
+ if (n.getMessage().isPresent()) {
+ printer.print(" : ");
+ n.getMessage().get().accept(this, arg);
+ }
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final BlockStmt n, final Void arg) {
+ printOrphanCommentsBeforeThisChildNode(n);
+ printComment(n.getComment(), arg);
+ printer.println("{");
+ if (n.getStatements() != null) {
+ printer.indent();
+ for (final Statement s : n.getStatements()) {
+ s.accept(this, arg);
+ printer.println();
+ }
+ printer.unindent();
+ }
+ printOrphanCommentsEnding(n);
+ printer.print("}");
+ }
+
+ @Override
+ public void visit(final LabeledStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getLabel().accept(this, arg);
+ printer.print(": ");
+ n.getStatement().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final EmptyStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final ExpressionStmt n, final Void arg) {
+ printOrphanCommentsBeforeThisChildNode(n);
+ printComment(n.getComment(), arg);
+ n.getExpression().accept(this, arg);
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final SwitchStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("switch(");
+ n.getSelector().accept(this, arg);
+ printer.println(") {");
+ if (n.getEntries() != null) {
+ printer.indent();
+ for (final SwitchEntryStmt e : n.getEntries()) {
+ e.accept(this, arg);
+ }
+ printer.unindent();
+ }
+ printer.print("}");
+ }
+
+ @Override
+ public void visit(final SwitchEntryStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getLabel().isPresent()) {
+ printer.print("case ");
+ n.getLabel().get().accept(this, arg);
+ printer.print(":");
+ } else {
+ printer.print("default:");
+ }
+ printer.println();
+ printer.indent();
+ if (n.getStatements() != null) {
+ for (final Statement s : n.getStatements()) {
+ s.accept(this, arg);
+ printer.println();
+ }
+ }
+ printer.unindent();
+ }
+
+ @Override
+ public void visit(final BreakStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("break");
+ n.getLabel().ifPresent(l -> printer.print(" ").print(l.getIdentifier()));
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final ReturnStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("return");
+ if (n.getExpression().isPresent()) {
+ printer.print(" ");
+ n.getExpression().get().accept(this, arg);
+ }
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final EnumDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printMemberAnnotations(n.getAnnotations(), arg);
+ printModifiers(n.getModifiers());
+
+ printer.print("enum ");
+ n.getName().accept(this, arg);
+
+ if (!n.getImplementedTypes().isEmpty()) {
+ printer.print(" implements ");
+ for (final Iterator<ClassOrInterfaceType> i = n.getImplementedTypes().iterator(); i.hasNext(); ) {
+ final ClassOrInterfaceType c = i.next();
+ c.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+
+ printer.println(" {");
+ printer.indent();
+ if (n.getEntries().isNonEmpty()) {
+ final boolean alignVertically =
+ // Either we hit the constant amount limit in the configurations, or...
+ n.getEntries().size() > configuration.getMaxEnumConstantsToAlignHorizontally() ||
+ // any of the constants has a comment.
+ n.getEntries().stream().anyMatch(e -> e.getComment().isPresent());
+ printer.println();
+ for (final Iterator<EnumConstantDeclaration> i = n.getEntries().iterator(); i.hasNext(); ) {
+ final EnumConstantDeclaration e = i.next();
+ e.accept(this, arg);
+ if (i.hasNext()) {
+ if (alignVertically) {
+ printer.println(",");
+ } else {
+ printer.print(", ");
+ }
+ }
+ }
+ }
+ if (!n.getMembers().isEmpty()) {
+ printer.println(";");
+ printMembers(n.getMembers(), arg);
+ } else {
+ if (!n.getEntries().isEmpty()) {
+ printer.println();
+ }
+ }
+ printer.unindent();
+ printer.print("}");
+ }
+
+ @Override
+ public void visit(final EnumConstantDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printMemberAnnotations(n.getAnnotations(), arg);
+ n.getName().accept(this, arg);
+
+ if (!n.getArguments().isEmpty()) {
+ printArguments(n.getArguments(), arg);
+ }
+
+ if (!n.getClassBody().isEmpty()) {
+ printer.println(" {");
+ printer.indent();
+ printMembers(n.getClassBody(), arg);
+ printer.unindent();
+ printer.println("}");
+ }
+ }
+
+ @Override
+ public void visit(final InitializerDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.isStatic()) {
+ printer.print("static ");
+ }
+ n.getBody().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final IfStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("if (");
+ n.getCondition().accept(this, arg);
+ final boolean thenBlock = n.getThenStmt() instanceof BlockStmt;
+ if (thenBlock) // block statement should start on the same line
+ printer.print(") ");
+ else {
+ printer.println(")");
+ printer.indent();
+ }
+ n.getThenStmt().accept(this, arg);
+ if (!thenBlock)
+ printer.unindent();
+ if (n.getElseStmt().isPresent()) {
+ if (thenBlock)
+ printer.print(" ");
+ else
+ printer.println();
+ final boolean elseIf = n.getElseStmt().orElse(null) instanceof IfStmt;
+ final boolean elseBlock = n.getElseStmt().orElse(null) instanceof BlockStmt;
+ if (elseIf || elseBlock) // put chained if and start of block statement on a same level
+ printer.print("else ");
+ else {
+ printer.println("else");
+ printer.indent();
+ }
+ if (n.getElseStmt().isPresent())
+ n.getElseStmt().get().accept(this, arg);
+ if (!(elseIf || elseBlock))
+ printer.unindent();
+ }
+ }
+
+ @Override
+ public void visit(final WhileStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("while (");
+ n.getCondition().accept(this, arg);
+ printer.print(") ");
+ n.getBody().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final ContinueStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("continue");
+ n.getLabel().ifPresent(l -> printer.print(" ").print(l.getIdentifier()));
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final DoStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("do ");
+ n.getBody().accept(this, arg);
+ printer.print(" while (");
+ n.getCondition().accept(this, arg);
+ printer.print(");");
+ }
+
+ @Override
+ public void visit(final ForeachStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("for (");
+ n.getVariable().accept(this, arg);
+ printer.print(" : ");
+ n.getIterable().accept(this, arg);
+ printer.print(") ");
+ n.getBody().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final ForStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("for (");
+ if (n.getInitialization() != null) {
+ for (final Iterator<Expression> i = n.getInitialization().iterator(); i.hasNext(); ) {
+ final Expression e = i.next();
+ e.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+ printer.print("; ");
+ if (n.getCompare().isPresent()) {
+ n.getCompare().get().accept(this, arg);
+ }
+ printer.print("; ");
+ if (n.getUpdate() != null) {
+ for (final Iterator<Expression> i = n.getUpdate().iterator(); i.hasNext(); ) {
+ final Expression e = i.next();
+ e.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+ printer.print(") ");
+ n.getBody().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final ThrowStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("throw ");
+ n.getExpression().accept(this, arg);
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final SynchronizedStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("synchronized (");
+ n.getExpression().accept(this, arg);
+ printer.print(") ");
+ n.getBody().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final TryStmt n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("try ");
+ if (!n.getResources().isEmpty()) {
+ printer.print("(");
+ Iterator<Expression> resources = n.getResources().iterator();
+ boolean first = true;
+ while (resources.hasNext()) {
+ resources.next().accept(this, arg);
+ if (resources.hasNext()) {
+ printer.print(";");
+ printer.println();
+ if (first) {
+ printer.indent();
+ }
+ }
+ first = false;
+ }
+ if (n.getResources().size() > 1) {
+ printer.unindent();
+ }
+ printer.print(") ");
+ }
+ n.getTryBlock().accept(this, arg);
+ for (final CatchClause c : n.getCatchClauses()) {
+ c.accept(this, arg);
+ }
+ if (n.getFinallyBlock().isPresent()) {
+ printer.print(" finally ");
+ n.getFinallyBlock().get().accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(final CatchClause n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print(" catch (");
+ n.getParameter().accept(this, arg);
+ printer.print(") ");
+ n.getBody().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final AnnotationDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printMemberAnnotations(n.getAnnotations(), arg);
+ printModifiers(n.getModifiers());
+
+ printer.print("@interface ");
+ n.getName().accept(this, arg);
+ printer.println(" {");
+ printer.indent();
+ if (n.getMembers() != null) {
+ printMembers(n.getMembers(), arg);
+ }
+ printer.unindent();
+ printer.print("}");
+ }
+
+ @Override
+ public void visit(final AnnotationMemberDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printMemberAnnotations(n.getAnnotations(), arg);
+ printModifiers(n.getModifiers());
+
+ n.getType().accept(this, arg);
+ printer.print(" ");
+ n.getName().accept(this, arg);
+ printer.print("()");
+ if (n.getDefaultValue().isPresent()) {
+ printer.print(" default ");
+ n.getDefaultValue().get().accept(this, arg);
+ }
+ printer.print(";");
+ }
+
+ @Override
+ public void visit(final MarkerAnnotationExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("@");
+ n.getName().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final SingleMemberAnnotationExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("@");
+ n.getName().accept(this, arg);
+ printer.print("(");
+ n.getMemberValue().accept(this, arg);
+ printer.print(")");
+ }
+
+ @Override
+ public void visit(final NormalAnnotationExpr n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("@");
+ n.getName().accept(this, arg);
+ printer.print("(");
+ if (n.getPairs() != null) {
+ for (final Iterator<MemberValuePair> i = n.getPairs().iterator(); i.hasNext(); ) {
+ final MemberValuePair m = i.next();
+ m.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ }
+ printer.print(")");
+ }
+
+ @Override
+ public void visit(final MemberValuePair n, final Void arg) {
+ printComment(n.getComment(), arg);
+ n.getName().accept(this, arg);
+ printer.print(" = ");
+ n.getValue().accept(this, arg);
+ }
+
+ @Override
+ public void visit(final LineComment n, final Void arg) {
+ if (configuration.isIgnoreComments()) {
+ return;
+ }
+ printer
+ .print("// ")
+ .println(normalizeEolInTextBlock(n.getContent(), "").trim());
+ }
+
+ @Override
+ public void visit(final BlockComment n, final Void arg) {
+ if (configuration.isIgnoreComments()) {
+ return;
+ }
+ final String commentContent = normalizeEolInTextBlock(n.getContent(), configuration.getEndOfLineCharacter());
+ String[] lines = commentContent.split("\\R", -1); // as BlockComment should not be formatted, -1 to preserve any trailing empty line if present
+ printer.print("/*");
+ for (int i = 0; i < (lines.length - 1); i++) {
+ printer.print(lines[i]);
+ printer.print(configuration.getEndOfLineCharacter()); // Avoids introducing indentation in blockcomments. ie: do not use println() as it would trigger indentation at the next print call.
+ }
+ printer.print(lines[lines.length - 1]); // last line is not followed by a newline, and simply terminated with `*/`
+ printer.println("*/");
+ }
+
+ @Override
+ public void visit(LambdaExpr n, Void arg) {
+ printComment(n.getComment(), arg);
+
+ final NodeList<Parameter> parameters = n.getParameters();
+ final boolean printPar = n.isEnclosingParameters();
+
+ if (printPar) {
+ printer.print("(");
+ }
+ for (Iterator<Parameter> i = parameters.iterator(); i.hasNext(); ) {
+ Parameter p = i.next();
+ p.accept(this, arg);
+ if (i.hasNext()) {
+ printer.print(", ");
+ }
+ }
+ if (printPar) {
+ printer.print(")");
+ }
+
+ printer.print(" -> ");
+ final Statement body = n.getBody();
+ if (body instanceof ExpressionStmt) {
+ // Print the expression directly
+ ((ExpressionStmt) body).getExpression().accept(this, arg);
+ } else {
+ body.accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(MethodReferenceExpr n, Void arg) {
+ printComment(n.getComment(), arg);
+ Expression scope = n.getScope();
+ String identifier = n.getIdentifier();
+ if (scope != null) {
+ n.getScope().accept(this, arg);
+ }
+
+ printer.print("::");
+ printTypeArgs(n, arg);
+ if (identifier != null) {
+ printer.print(identifier);
+ }
+ }
+
+ @Override
+ public void visit(TypeExpr n, Void arg) {
+ printComment(n.getComment(), arg);
+ if (n.getType() != null) {
+ n.getType().accept(this, arg);
+ }
+ }
+
+ @Override
+ public void visit(NodeList n, Void arg) {
+ if (configuration.isOrderImports() && n.size() > 0 && n.get(0) instanceof ImportDeclaration) {
+ //noinspection unchecked
+ NodeList<ImportDeclaration> modifiableList = new NodeList<>(n);
+ modifiableList.sort((left, right) -> {
+ int sort = Integer.compare(left.isStatic() ? 0 : 1, right.isStatic() ? 0 : 1);
+ if (sort == 0) {
+ sort = left.getNameAsString().compareTo(right.getNameAsString());
+ }
+ return sort;
+ });
+ for (Object node : modifiableList) {
+ ((Node) node).accept(this, arg);
+ }
+ } else {
+ for (Object node : n) {
+ ((Node) node).accept(this, arg);
+ }
+ }
+ }
+
+ @Override
+ public void visit(final ImportDeclaration n, final Void arg) {
+ printComment(n.getComment(), arg);
+ printer.print("import ");
+ if (n.isStatic()) {
+ printer.print("static ");
+ }
+ n.getName().accept(this, arg);
+ if (n.isAsterisk()) {
+ printer.print(".*");
+ }
+ printer.println(";");
+
+ printOrphanCommentsEnding(n);
+ }
+
+
+ @Override
+ public void visit(ModuleDeclaration n, Void arg) {
+ printAnnotations(n.getAnnotations(), false, arg);
+ printer.println();
+ if (n.isOpen()) {
+ printer.print("open ");
+ }
+ printer.print("module ");
+ n.getName().accept(this, arg);
+ printer.println(" {").indent();
+ n.getModuleStmts().accept(this, arg);
+ printer.unindent().println("}");
+ }
+
+ @Override
+ public void visit(ModuleRequiresStmt n, Void arg) {
+ printer.print("requires ");
+ printModifiers(n.getModifiers());
+ n.getName().accept(this, arg);
+ printer.println(";");
+ }
+
+ @Override
+ public void visit(ModuleExportsStmt n, Void arg) {
+ printer.print("exports ");
+ n.getName().accept(this, arg);
+ printPrePostFixOptionalList(n.getModuleNames(), arg, " to ", ", ", "");
+ printer.println(";");
+ }
+
+ @Override
+ public void visit(ModuleProvidesStmt n, Void arg) {
+ printer.print("provides ");
+ n.getType().accept(this, arg);
+ printPrePostFixRequiredList(n.getWithTypes(), arg, " with ", ", ", "");
+ printer.println(";");
+ }
+
+ @Override
+ public void visit(ModuleUsesStmt n, Void arg) {
+ printer.print("uses ");
+ n.getType().accept(this, arg);
+ printer.println(";");
+ }
+
+ @Override
+ public void visit(ModuleOpensStmt n, Void arg) {
+ printer.print("opens ");
+ n.getName().accept(this, arg);
+ printPrePostFixOptionalList(n.getModuleNames(), arg, " to ", ", ", "");
+ printer.println(";");
+ }
+
+ @Override
+ public void visit(UnparsableStmt n, Void arg) {
+ printer.print("???;");
+ }
+
+ private void printOrphanCommentsBeforeThisChildNode(final Node node) {
+ if (configuration.isIgnoreComments()) return;
+ if (node instanceof Comment) return;
+
+ Node parent = node.getParentNode().orElse(null);
+ if (parent == null) return;
+ List<Node> everything = new LinkedList<>();
+ everything.addAll(parent.getChildNodes());
+ sortByBeginPosition(everything);
+ int positionOfTheChild = -1;
+ for (int i = 0; i < everything.size(); i++) {
+ if (everything.get(i) == node) positionOfTheChild = i;
+ }
+ if (positionOfTheChild == -1) {
+ throw new AssertionError("I am not a child of my parent.");
+ }
+ int positionOfPreviousChild = -1;
+ for (int i = positionOfTheChild - 1; i >= 0 && positionOfPreviousChild == -1; i--) {
+ if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i;
+ }
+ for (int i = positionOfPreviousChild + 1; i < positionOfTheChild; i++) {
+ Node nodeToPrint = everything.get(i);
+ if (!(nodeToPrint instanceof Comment))
+ throw new RuntimeException(
+ "Expected comment, instead " + nodeToPrint.getClass() + ". Position of previous child: "
+ + positionOfPreviousChild + ", position of child " + positionOfTheChild);
+ nodeToPrint.accept(this, null);
+ }
+ }
+
+ private void printOrphanCommentsEnding(final Node node) {
+ if (configuration.isIgnoreComments()) return;
+
+ List<Node> everything = new LinkedList<>();
+ everything.addAll(node.getChildNodes());
+ sortByBeginPosition(everything);
+ if (everything.isEmpty()) {
+ return;
+ }
+
+ int commentsAtEnd = 0;
+ boolean findingComments = true;
+ while (findingComments && commentsAtEnd < everything.size()) {
+ Node last = everything.get(everything.size() - 1 - commentsAtEnd);
+ findingComments = (last instanceof Comment);
+ if (findingComments) {
+ commentsAtEnd++;
+ }
+ }
+ for (int i = 0; i < commentsAtEnd; i++) {
+ everything.get(everything.size() - commentsAtEnd + i).accept(this, null);
+ }
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java
new file mode 100644
index 000000000..510457c4d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinter.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer;
+
+import com.github.javaparser.ast.Node;
+
+/**
+ * Pretty printer for AST nodes.
+ */
+public class PrettyPrinter {
+ private final PrettyPrinterConfiguration configuration;
+
+ public PrettyPrinter() {
+ this(new PrettyPrinterConfiguration());
+ }
+
+ public PrettyPrinter(PrettyPrinterConfiguration configuration) {
+ this.configuration = configuration;
+ }
+
+ public String print(Node node) {
+ final PrettyPrintVisitor visitor = configuration.getVisitorFactory().apply(configuration);
+ node.accept(visitor, null);
+ return visitor.getSource();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinterConfiguration.java b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinterConfiguration.java
new file mode 100644
index 000000000..1c650d2ec
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/PrettyPrinterConfiguration.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer;
+
+import java.util.function.Function;
+
+import static com.github.javaparser.utils.Utils.EOL;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * Configuration options for the {@link PrettyPrinter}.
+ */
+public class PrettyPrinterConfiguration {
+ public static final int DEFAULT_MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY = 5;
+
+ private boolean orderImports = false;
+ private boolean printComments = true;
+ private boolean printJavadoc = true;
+ private boolean columnAlignParameters = false;
+ private boolean columnAlignFirstMethodChain = false;
+ private String indent = " ";
+ private String endOfLineCharacter = EOL;
+ private Function<PrettyPrinterConfiguration, PrettyPrintVisitor> visitorFactory = PrettyPrintVisitor::new;
+ private int maxEnumConstantsToAlignHorizontally = DEFAULT_MAX_ENUM_CONSTANTS_TO_ALIGN_HORIZONTALLY;
+
+ public String getIndent() {
+ return indent;
+ }
+
+ /**
+ * Set the string to use for indenting. For example: "\t", " ", "".
+ */
+ public PrettyPrinterConfiguration setIndent(String indent) {
+ this.indent = assertNotNull(indent);
+ return this;
+ }
+
+ public boolean isOrderImports() {
+ return orderImports;
+ }
+
+ /**
+ * @deprecated this is always on.
+ */
+ @Deprecated
+ public boolean isNormalizeEolInComment() {
+ return true;
+ }
+
+ /**
+ * @deprecated this is always on.
+ */
+ @Deprecated
+ public PrettyPrinterConfiguration setNormalizeEolInComment(boolean normalizeEolInComment) {
+ return this;
+ }
+
+ public boolean isPrintComments() {
+ return printComments;
+ }
+
+ public boolean isIgnoreComments() {
+ return !printComments;
+ }
+
+ public boolean isPrintJavadoc() {
+ return printJavadoc;
+ }
+
+ public boolean isColumnAlignParameters() {
+ return columnAlignParameters;
+ }
+
+ public boolean isColumnAlignFirstMethodChain() {
+ return columnAlignFirstMethodChain;
+ }
+
+ /**
+ * When true, all comments will be printed, unless printJavadoc is false, then only line and block comments will be
+ * printed.
+ */
+ public PrettyPrinterConfiguration setPrintComments(boolean printComments) {
+ this.printComments = printComments;
+ return this;
+ }
+
+ /**
+ * When true, Javadoc will be printed.
+ */
+ public PrettyPrinterConfiguration setPrintJavadoc(boolean printJavadoc) {
+ this.printJavadoc = printJavadoc;
+ return this;
+ }
+
+ public PrettyPrinterConfiguration setColumnAlignParameters(boolean columnAlignParameters) {
+ this.columnAlignParameters = columnAlignParameters;
+ return this;
+ }
+
+ public PrettyPrinterConfiguration setColumnAlignFirstMethodChain(boolean columnAlignFirstMethodChain) {
+ this.columnAlignFirstMethodChain = columnAlignFirstMethodChain;
+ return this;
+ }
+
+ public Function<PrettyPrinterConfiguration, PrettyPrintVisitor> getVisitorFactory() {
+ return visitorFactory;
+ }
+
+ /**
+ * Set the factory that creates the PrettyPrintVisitor. By changing this you can make the PrettyPrinter use a custom
+ * PrettyPrinterVisitor.
+ */
+ public PrettyPrinterConfiguration setVisitorFactory(Function<PrettyPrinterConfiguration, PrettyPrintVisitor> visitorFactory) {
+ this.visitorFactory = assertNotNull(visitorFactory);
+ return this;
+ }
+
+ public String getEndOfLineCharacter() {
+ return endOfLineCharacter;
+ }
+
+ /**
+ * Set the character to append when a line should end. Example values: "\n", "\r\n", "".
+ */
+ public PrettyPrinterConfiguration setEndOfLineCharacter(String endOfLineCharacter) {
+ this.endOfLineCharacter = assertNotNull(endOfLineCharacter);
+ return this;
+ }
+
+ /**
+ * When true, orders imports by alphabetically.
+ */
+ public PrettyPrinterConfiguration setOrderImports(boolean orderImports) {
+ this.orderImports = orderImports;
+ return this;
+ }
+
+ public int getMaxEnumConstantsToAlignHorizontally() {
+ return maxEnumConstantsToAlignHorizontally;
+ }
+
+ /**
+ * By default enum constants get aligned like this:
+ * <pre>
+ * enum X {
+ * A, B, C, D
+ * }
+ * </pre>
+ * until the amount of constants passes this value (5 by default).
+ * Then they get aligned like this:
+ * <pre>
+ * enum X {
+ * A,
+ * B,
+ * C,
+ * D,
+ * E,
+ * F,
+ * G
+ * }
+ * </pre>
+ * Set it to a large number to always align horizontally.
+ * Set it to 1 or less to always align vertically.
+ */
+ public PrettyPrinterConfiguration setMaxEnumConstantsToAlignHorizontally(int maxEnumConstantsToAlignHorizontally) {
+ this.maxEnumConstantsToAlignHorizontally = maxEnumConstantsToAlignHorizontally;
+ return this;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/Printable.java b/javaparser-core/src/main/java/com/github/javaparser/printer/Printable.java
new file mode 100644
index 000000000..390baa76b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/Printable.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser.printer;
+
+/**
+ * Something that has a printable form. I.e., it can be converted to a user-facing String.
+ */
+public interface Printable {
+ String asString();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java
new file mode 100644
index 000000000..a53d90775
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/SourcePrinter.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer;
+
+import com.github.javaparser.Position;
+import com.github.javaparser.utils.Utils;
+
+public class SourcePrinter {
+
+ private final String indentation;
+ private final int indentationLength;
+ private final String endOfLineCharacter;
+ private int level = 0;
+ private boolean indented = false;
+ private final StringBuilder buf = new StringBuilder();
+ private Position cursor = new Position(1, 0);
+
+ SourcePrinter(final String indentation, final String endOfLineCharacter) {
+ this.indentation = indentation;
+ this.indentationLength = indentation.length();
+ this.endOfLineCharacter = endOfLineCharacter;
+ }
+
+ public SourcePrinter indent() {
+ level++;
+ return this;
+ }
+
+ public SourcePrinter unindent() {
+ level--;
+ return this;
+ }
+
+ private void makeIndent() {
+ for (int i = 0; i < level; i++) {
+ buf.append(indentation);
+ cursor = Position.pos(cursor.line, cursor.column + indentationLength);
+ }
+ }
+
+ /**
+ * Append the source string passed as argument to the buffer.
+ * If this is being appended at the beginning of a line, performs indentation first.
+ * <p>
+ * The source line to be printed should not contain newline/carriage-return characters;
+ * use {@link #println(String)} to automatically append a newline at the end of the source string.
+ * If the source line passed as argument contains newline/carriage-return characters would
+ * impredictably affect a correct computation of the current {@link #getCursor()} position.
+ *
+ * @see SourcePrinter#println(String)
+ * @param arg source line to be printed (should not contain newline/carriage-return characters)
+ * @return this instance, for nesting calls to method as fluent interface
+ */
+ public SourcePrinter print(final String arg) {
+ if (!indented) {
+ makeIndent();
+ indented = true;
+ }
+ buf.append(arg);
+ cursor = Position.pos(cursor.line, cursor.column + arg.length());
+ return this;
+ }
+
+ /**
+ * Append the source string passed as argument to the buffer, then append a newline.
+ * If this is being appended at the beginning of a line, performs indentation first.
+ * <p>
+ * The source line to be printed should not contain newline/carriage-return characters.
+ * If the source line passed as argument contains newline/carriage-return characters would
+ * impredictably affect a correct computation of the current {@link #getCursor()} position.
+ *
+ * @param arg source line to be printed (should not contain newline/carriage-return characters)
+ * @return this instance, for nesting calls to method as fluent interface
+ */
+ public SourcePrinter println(final String arg) {
+ print(arg);
+ println();
+ return this;
+ }
+
+ /**
+ * Append a newline to the buffer.
+ *
+ * @return this instance, for nesting calls to method as fluent interface
+ */
+ public SourcePrinter println() {
+ buf.append(endOfLineCharacter);
+ cursor = Position.pos(cursor.line + 1, 0);
+ indented = false;
+ return this;
+ }
+
+ /**
+ * Return the current cursor position (line, column) in the source printer buffer.
+ * <p>
+ * Please notice in order to guarantee a correct computation of the cursor position,
+ * this printer expect the contracts of the methods {@link #print(String)} and {@link #println(String)}
+ * has been respected through all method calls, meaning the source string passed as argument to those method
+ * calls did not contain newline/carriage-return characters.
+ *
+ * @return the current cursor position (line, column).
+ */
+ public Position getCursor() {
+ return cursor;
+ }
+
+ /**
+ * Performs a new line and indent, then prints enough space characters until aligned to the specified column.
+ * @param column the column to align to
+ */
+ public void wrapToColumn(int column) {
+ println();
+ if (!indented) {
+ makeIndent();
+ indented = true;
+ }
+ while ( cursor.column < column ) {
+ print(" ");
+ }
+ }
+
+ public String getSource() {
+ return buf.toString();
+ }
+
+ @Override
+ public String toString() {
+ return getSource();
+ }
+
+ public String normalizeEolInTextBlock(String content) {
+ return Utils.normalizeEolInTextBlock(content, endOfLineCharacter);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java
new file mode 100644
index 000000000..ea69c9e7b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/XmlPrinter.java
@@ -0,0 +1,77 @@
+package com.github.javaparser.printer;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.metamodel.NodeMetaModel;
+import com.github.javaparser.metamodel.PropertyMetaModel;
+
+import java.util.List;
+
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.toList;
+
+/**
+ * Outputs an XML file containing the AST meant for inspecting it.
+ */
+public class XmlPrinter {
+ private final boolean outputNodeType;
+
+ public XmlPrinter(boolean outputNodeType) {
+ this.outputNodeType = outputNodeType;
+ }
+
+ public String output(Node node) {
+ StringBuilder output = new StringBuilder();
+ output(node, "root", 0, output);
+ return output.toString();
+ }
+
+ public void output(Node node, String name, int level, StringBuilder builder) {
+ assertNotNull(node);
+ NodeMetaModel metaModel = node.getMetaModel();
+ List<PropertyMetaModel> allPropertyMetaModels = metaModel.getAllPropertyMetaModels();
+ List<PropertyMetaModel> attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute).filter(PropertyMetaModel::isSingular).collect(toList());
+ List<PropertyMetaModel> subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode).filter(PropertyMetaModel::isSingular).collect(toList());
+ List<PropertyMetaModel> subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList).collect(toList());
+
+ builder.append("<").append(name);
+ if (outputNodeType) {
+ builder.append(attribute("type", metaModel.getTypeName()));
+ }
+
+ for (PropertyMetaModel attributeMetaModel : attributes) {
+ builder.append(attribute(attributeMetaModel.getName(), attributeMetaModel.getValue(node).toString()));
+ }
+ builder.append(">");
+
+ for (PropertyMetaModel subNodeMetaModel : subNodes) {
+ Node value = (Node) subNodeMetaModel.getValue(node);
+ if (value != null) {
+ output(value, subNodeMetaModel.getName(), level + 1, builder);
+ }
+ }
+
+ for (PropertyMetaModel subListMetaModel : subLists) {
+ NodeList<? extends Node> subList = (NodeList<? extends Node>) subListMetaModel.getValue(node);
+ if (subList != null && !subList.isEmpty()) {
+ String listName = subListMetaModel.getName();
+ builder.append("<").append(listName).append(">");
+ String singular = listName.substring(0, listName.length() - 1);
+ for (Node subListNode : subList) {
+ output(subListNode, singular, level + 1, builder);
+ }
+ builder.append(close(listName));
+ }
+ }
+ builder.append(close(name));
+ }
+
+ private static String close(String name) {
+ return "</" + name + ">";
+ }
+
+ private static String attribute(String name, String value) {
+ return " " + name + "='" + value + "'";
+ }
+}
+
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java
new file mode 100644
index 000000000..1e418f5f0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/YamlPrinter.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer;
+
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.util.stream.Collectors.toList;
+
+import java.util.List;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.metamodel.NodeMetaModel;
+import com.github.javaparser.metamodel.PropertyMetaModel;
+
+/**
+ * Outputs a YAML file containing the AST meant for inspecting it.
+ */
+public class YamlPrinter {
+
+ private static final int NUM_SPACES_FOR_INDENT = 4;
+ private final boolean outputNodeType;
+
+ public YamlPrinter(boolean outputNodeType) {
+ this.outputNodeType = outputNodeType;
+ }
+
+ public String output(Node node) {
+ StringBuilder output = new StringBuilder();
+ output.append("---");
+ output(node, "root", 0, output);
+ output.append(System.lineSeparator() + "...");
+ return output.toString();
+ }
+
+ public void output(Node node, String name, int level, StringBuilder builder) {
+ assertNotNull(node);
+ NodeMetaModel metaModel = node.getMetaModel();
+ List<PropertyMetaModel> allPropertyMetaModels = metaModel.getAllPropertyMetaModels();
+ List<PropertyMetaModel> attributes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isAttribute)
+ .filter(PropertyMetaModel::isSingular).collect(toList());
+ List<PropertyMetaModel> subNodes = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNode)
+ .filter(PropertyMetaModel::isSingular).collect(toList());
+ List<PropertyMetaModel> subLists = allPropertyMetaModels.stream().filter(PropertyMetaModel::isNodeList)
+ .collect(toList());
+
+ if (outputNodeType)
+ builder.append(System.lineSeparator() + indent(level) + name + "(Type=" + metaModel.getTypeName() + "): ");
+ else
+ builder.append(System.lineSeparator() + indent(level) + name + ": ");
+
+ level++;
+ for (PropertyMetaModel a : attributes) {
+ builder.append(System.lineSeparator() + indent(level) + a.getName() + ": \""
+ + a.getValue(node).toString() + "\"");
+ }
+
+ for (PropertyMetaModel sn : subNodes) {
+ Node nd = (Node) sn.getValue(node);
+ if (nd != null)
+ output(nd, sn.getName(), level, builder);
+ }
+
+ for (PropertyMetaModel sl : subLists) {
+ NodeList<? extends Node> nl = (NodeList<? extends Node>) sl.getValue(node);
+ if (nl != null && nl.isNonEmpty()) {
+ builder.append(System.lineSeparator() + indent(level) + sl.getName() + ": ");
+ String slName = sl.getName();
+ slName = slName.endsWith("s") ? slName.substring(0, sl.getName().length() - 1) : slName;
+ for (Node nd : nl)
+ output(nd, "- " + slName, level + 1, builder);
+ }
+ }
+ }
+
+ private String indent(int level) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < level; i++)
+ for (int j = 0; j < NUM_SPACES_FOR_INDENT; j++)
+ sb.append(" ");
+ return sb.toString();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java
new file mode 100644
index 000000000..b44672de2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmAttribute.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.GeneratedJavaParserConstants;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.IntegerLiteralExpr;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.SourcePrinter;
+
+public class CsmAttribute implements CsmElement {
+ public ObservableProperty getProperty() {
+ return property;
+ }
+
+ private final ObservableProperty property;
+
+ public CsmAttribute(ObservableProperty property) {
+ this.property = property;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ Object value = property.getRawValue(node);
+ printer.print(PrintingHelper.printToString(value));
+ }
+
+ /**
+ * Obtain the token type corresponding to the specific value of the attribute.
+ * For example, to the attribute "Operator" different token could correspond like PLUS or MINUS.
+ */
+ public int getTokenType(Node node, String text) {
+ switch (property) {
+ case IDENTIFIER:
+ return GeneratedJavaParserConstants.IDENTIFIER;
+ case TYPE:
+ String expectedImage = "\"" + text.toLowerCase() + "\"";
+ for (int i=0;i<GeneratedJavaParserConstants.tokenImage.length;i++) {
+ if (GeneratedJavaParserConstants.tokenImage[i].equals(expectedImage)) {
+ return i;
+ }
+ }
+ throw new RuntimeException("Attribute 'type' does not corresponding to any expected value. Text: " + text);
+ case OPERATOR:
+ try {
+ return (Integer)(GeneratedJavaParserConstants.class.getDeclaredField(text).get(null));
+ } catch (IllegalAccessException|NoSuchFieldException e) {
+ throw new RuntimeException("Attribute 'operator' does not corresponding to any expected value. Text: " + text, e);
+ }
+ case VALUE:
+ if (node instanceof IntegerLiteralExpr) {
+ return GeneratedJavaParserConstants.INTEGER_LITERAL;
+ }
+ case NAME:
+ return GeneratedJavaParserConstants.IDENTIFIER;
+ }
+ throw new UnsupportedOperationException("getTokenType does not know how to handle property "
+ + property + " with text: " + text);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmChar.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmChar.java
new file mode 100644
index 000000000..2f22899d5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmChar.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.SourcePrinter;
+
+public class CsmChar implements CsmElement {
+ private final ObservableProperty property;
+
+ public CsmChar(ObservableProperty property) {
+ this.property = property;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ printer.print("'");
+ printer.print(property.getValueAsStringAttribute(node));
+ printer.print("'");
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmComment.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmComment.java
new file mode 100644
index 000000000..8e684c4c5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmComment.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+import com.github.javaparser.printer.SourcePrinter;
+
+public class CsmComment implements CsmElement {
+
+ static void process(Comment comment, SourcePrinter printer) {
+ String content = printer.normalizeEolInTextBlock(comment.getContent());
+ if (comment instanceof BlockComment) {
+ printer.print("/*");
+ printer.print(content);
+ printer.println("*/");
+ } else if (comment instanceof JavadocComment) {
+ printer.print("/**");
+ printer.print(content);
+ printer.println("*/");
+ } else if (comment instanceof LineComment) {
+ printer.print("//");
+ printer.print(content);
+ printer.println();
+ } else {
+ throw new UnsupportedOperationException(comment.getClass().getSimpleName());
+ }
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ node.getComment().ifPresent(c -> process(c, printer));
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java
new file mode 100644
index 000000000..a2ca7cdd1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmConditional.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.SourcePrinter;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class CsmConditional implements CsmElement {
+ private final Condition condition;
+ private final List<ObservableProperty> properties;
+ private final CsmElement thenElement;
+ private final CsmElement elseElement;
+
+ public Condition getCondition() {
+ return condition;
+ }
+
+ public ObservableProperty getProperty() {
+ if (properties.size() > 1) {
+ throw new IllegalStateException();
+ }
+ return properties.get(0);
+ }
+
+ public CsmElement getThenElement() {
+ return thenElement;
+ }
+
+ public CsmElement getElseElement() {
+ return elseElement;
+ }
+
+ public enum Condition {
+ IS_EMPTY,
+ IS_NOT_EMPTY,
+ IS_PRESENT,
+ FLAG;
+
+ boolean evaluate(Node node, ObservableProperty property){
+ if (this == IS_PRESENT) {
+ return !property.isNullOrNotPresent(node);
+ }
+ if (this == FLAG) {
+ return property.getValueAsBooleanAttribute(node);
+ }
+ if (this == IS_EMPTY) {
+ NodeList value = property.getValueAsMultipleReference(node);
+ return value == null || value.isEmpty();
+ }
+ if (this == IS_NOT_EMPTY) {
+ NodeList value = property.getValueAsMultipleReference(node);
+ return value != null && !value.isEmpty();
+ }
+ throw new UnsupportedOperationException(name());
+ }
+ }
+
+ public CsmConditional(ObservableProperty property, Condition condition, CsmElement thenElement, CsmElement elseElement) {
+ this.properties = Arrays.asList(property);
+ this.condition = condition;
+ this.thenElement = thenElement;
+ this.elseElement = elseElement;
+ }
+
+ public CsmConditional(List<ObservableProperty> properties, Condition condition, CsmElement thenElement, CsmElement elseElement) {
+ if (properties.size() < 1) {
+ throw new IllegalArgumentException();
+ }
+ this.properties = properties;
+ this.condition = condition;
+ this.thenElement = thenElement;
+ this.elseElement = elseElement;
+ }
+
+ public CsmConditional(ObservableProperty property, Condition condition, CsmElement thenElement) {
+ this(property, condition, thenElement, new CsmNone());
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ boolean test = false;
+ for (ObservableProperty prop : properties) {
+ test = test || condition.evaluate(node, prop);
+ }
+ if (test) {
+ thenElement.prettyPrint(node, printer);
+ } else {
+ elseElement.prettyPrint(node, printer);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java
new file mode 100644
index 000000000..61566d1f0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmElement.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.GeneratedJavaParserConstants;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.SourcePrinter;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static com.github.javaparser.TokenTypes.*;
+import static com.github.javaparser.utils.Utils.EOL;
+
+public interface CsmElement {
+
+ void prettyPrint(Node node, SourcePrinter printer);
+
+ static CsmElement child(ObservableProperty property) {
+ return new CsmSingleReference(property);
+ }
+
+ static CsmElement attribute(ObservableProperty property) {
+ return new CsmAttribute(property);
+ }
+
+ static CsmElement sequence(CsmElement... elements) {
+ return new CsmSequence(Arrays.asList(elements));
+ }
+
+ static CsmElement string(int tokenType, String content) {
+ return new CsmToken(tokenType, content);
+ }
+
+ static CsmElement string(int tokenType) {
+ return new CsmToken(tokenType);
+ }
+
+ static CsmElement stringToken(ObservableProperty property) {
+ return new CsmString(property);
+ }
+
+ static CsmElement charToken(ObservableProperty property) {
+ return new CsmChar(property);
+ }
+
+ static CsmElement token(int tokenType) {
+ return new CsmToken(tokenType);
+ }
+
+ static CsmElement token(int tokenType, CsmToken.TokenContentCalculator tokenContentCalculator) {
+ return new CsmToken(tokenType, tokenContentCalculator);
+ }
+
+ static CsmElement conditional(ObservableProperty property, CsmConditional.Condition condition, CsmElement thenElement) {
+ return new CsmConditional(property, condition, thenElement);
+ }
+
+ static CsmElement conditional(ObservableProperty property, CsmConditional.Condition condition, CsmElement thenElement, CsmElement elseElement) {
+ return new CsmConditional(property, condition, thenElement, elseElement);
+ }
+
+ static CsmElement conditional(List<ObservableProperty> properties, CsmConditional.Condition condition, CsmElement thenElement, CsmElement elseElement) {
+ return new CsmConditional(properties, condition, thenElement, elseElement);
+ }
+
+ static CsmElement space() {
+ return new CsmToken(spaceTokenKind(), " ");
+ }
+
+ static CsmElement semicolon() {
+ return new CsmToken(GeneratedJavaParserConstants.SEMICOLON);
+ }
+
+ static CsmElement comment() { return new CsmComment(); }
+
+ static CsmElement newline() {
+ return new CsmToken(eolTokenKind(), EOL);
+ }
+
+ static CsmElement none() {
+ return new CsmNone();
+ }
+
+ static CsmElement comma() {
+ return new CsmToken(GeneratedJavaParserConstants.COMMA);
+ }
+
+ static CsmElement list(ObservableProperty property) {
+ return new CsmList(property);
+ }
+
+ static CsmElement list(ObservableProperty property, CsmElement separator) {
+ return new CsmList(property, CsmElement.none(), separator, new CsmNone(), new CsmNone());
+ }
+
+ static CsmElement list(ObservableProperty property, CsmElement separator, CsmElement preceeding, CsmElement following) {
+ return new CsmList(property, none(), separator, preceeding, following);
+ }
+
+ static CsmElement list(ObservableProperty property, CsmElement separatorPre, CsmElement separatorPost, CsmElement preceeding, CsmElement following) {
+ return new CsmList(property, separatorPre, separatorPost, preceeding, following);
+ }
+
+ static CsmElement orphanCommentsEnding() {
+ return new CsmOrphanCommentsEnding();
+ }
+
+ static CsmElement orphanCommentsBeforeThis() {
+ // FIXME
+ return new CsmNone();
+ }
+
+ static CsmElement indent() {
+ return new CsmIndent();
+ }
+
+ static CsmElement unindent() {
+ return new CsmUnindent();
+ }
+
+ static CsmElement block(CsmElement content) {
+ return sequence(token(GeneratedJavaParserConstants.LBRACE), indent(), content, unindent(), token(GeneratedJavaParserConstants.RBRACE));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java
new file mode 100644
index 000000000..69be97f62
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmIndent.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.printer.SourcePrinter;
+
+public class CsmIndent implements CsmElement {
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ printer.indent();
+ }
+
+ @Override
+ public int hashCode() {
+ return 1;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof CsmIndent;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java
new file mode 100644
index 000000000..30fae7ed4
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmList.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.ConcreteSyntaxModel;
+import com.github.javaparser.printer.SourcePrinter;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+public class CsmList implements CsmElement {
+ private final ObservableProperty property;
+ private final CsmElement separatorPost;
+ private final CsmElement separatorPre;
+ private final CsmElement preceeding;
+ private final CsmElement following;
+
+ public ObservableProperty getProperty() {
+ return property;
+ }
+
+ public CsmElement getSeparatorPost() {
+ return separatorPost;
+ }
+
+ public CsmElement getSeparatorPre() {
+ return separatorPre;
+ }
+
+ public CsmElement getPreceeding() {
+ return preceeding;
+ }
+
+ public CsmElement getFollowing() {
+ return following;
+ }
+
+ public CsmList(ObservableProperty property, CsmElement separator) {
+ this(property, new CsmNone(), separator, new CsmNone(), new CsmNone());
+ }
+
+ public CsmList(ObservableProperty property) {
+ this(property, new CsmNone(), new CsmNone(), new CsmNone(), new CsmNone());
+ }
+
+ public CsmList(ObservableProperty property, CsmElement separatorPre, CsmElement separatorPost, CsmElement preceeding, CsmElement following) {
+ this.property = property;
+ this.separatorPre = separatorPre;
+ this.separatorPost = separatorPost;
+ this.preceeding = preceeding;
+ this.following = following;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ if (property.isAboutNodes()) {
+ NodeList nodeList = property.getValueAsMultipleReference(node);
+ if (nodeList == null) {
+ return;
+ }
+ if (!nodeList.isEmpty() && preceeding != null) {
+ preceeding.prettyPrint(node, printer);
+ }
+ for (int i = 0; i < nodeList.size(); i++) {
+ if (separatorPre != null && i != 0) {
+ separatorPre.prettyPrint(node, printer);
+ }
+ ConcreteSyntaxModel.genericPrettyPrint(nodeList.get(i), printer);
+ if (separatorPost != null && i != (nodeList.size() - 1)) {
+ separatorPost.prettyPrint(node, printer);
+ }
+ }
+ if (!nodeList.isEmpty() && following != null) {
+ following.prettyPrint(node, printer);
+ }
+ } else {
+ Collection<?> values = property.getValueAsCollection(node);
+ if (values == null) {
+ return;
+ }
+ if (!values.isEmpty() && preceeding != null) {
+ preceeding.prettyPrint(node, printer);
+ }
+ for (Iterator it = values.iterator(); it.hasNext(); ) {
+ if (separatorPre != null && it.hasNext()) {
+ separatorPre.prettyPrint(node, printer);
+ }
+ printer.print(PrintingHelper.printToString(it.next()));
+ if (separatorPost != null && it.hasNext()) {
+ separatorPost.prettyPrint(node, printer);
+ }
+ }
+ if (!values.isEmpty() && following != null) {
+ following.prettyPrint(node, printer);
+ }
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java
new file mode 100644
index 000000000..9ce54617d
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmMix.java
@@ -0,0 +1,54 @@
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.printer.SourcePrinter;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+/**
+ * A group of elements that could be in any order.
+ */
+public class CsmMix implements CsmElement {
+ private List<CsmElement> elements;
+
+ public CsmMix(List<CsmElement> elements) {
+ if (elements == null) {
+ throw new NullPointerException();
+ }
+ if (elements.stream().anyMatch(Objects::isNull)) {
+ throw new IllegalArgumentException("Null element in the mix");
+ }
+ this.elements = elements;
+ }
+
+ public List<CsmElement> getElements() {
+ return elements;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ elements.forEach(e -> e.prettyPrint(node, printer));
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ CsmMix csmMix = (CsmMix) o;
+
+ return elements != null ? elements.equals(csmMix.elements) : csmMix.elements == null;
+ }
+
+ @Override
+ public int hashCode() {
+ return elements != null ? elements.hashCode() : 0;
+ }
+
+ @Override
+ public String toString() {
+ return "CsmMix[" + String.join(", ", elements.stream().map(e -> elements.toString()).collect(Collectors.toList())) + "]";
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java
new file mode 100644
index 000000000..372bf8fdf
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmNone.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.printer.SourcePrinter;
+
+public class CsmNone implements CsmElement {
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java
new file mode 100644
index 000000000..dc04e16ea
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmOrphanCommentsEnding.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.printer.SourcePrinter;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static com.github.javaparser.utils.PositionUtils.sortByBeginPosition;
+
+public class CsmOrphanCommentsEnding implements CsmElement {
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ List<Node> everything = new LinkedList<>();
+ everything.addAll(node.getChildNodes());
+ sortByBeginPosition(everything);
+ if (everything.isEmpty()) {
+ return;
+ }
+
+ int commentsAtEnd = 0;
+ boolean findingComments = true;
+ while (findingComments && commentsAtEnd < everything.size()) {
+ Node last = everything.get(everything.size() - 1 - commentsAtEnd);
+ findingComments = (last instanceof Comment);
+ if (findingComments) {
+ commentsAtEnd++;
+ }
+ }
+ for (int i = 0; i < commentsAtEnd; i++) {
+ Comment c = (Comment)everything.get(everything.size() - commentsAtEnd + i);
+ CsmComment.process(c, printer);
+ }
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java
new file mode 100644
index 000000000..fcfd9ad1f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSequence.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.printer.SourcePrinter;
+
+import java.util.List;
+import java.util.Objects;
+
+public class CsmSequence implements CsmElement {
+ private List<CsmElement> elements;
+
+ public CsmSequence(List<CsmElement> elements) {
+ if (elements == null) {
+ throw new NullPointerException();
+ }
+ if (elements.stream().anyMatch(Objects::isNull)) {
+ throw new IllegalArgumentException("Null element in the sequence");
+ }
+ this.elements = elements;
+ }
+
+ public List<CsmElement> getElements() {
+ return elements;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ elements.forEach(e -> e.prettyPrint(node, printer));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java
new file mode 100644
index 000000000..36211a1ed
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmSingleReference.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.ConcreteSyntaxModel;
+import com.github.javaparser.printer.SourcePrinter;
+
+public class CsmSingleReference implements CsmElement {
+ private final ObservableProperty property;
+
+ public ObservableProperty getProperty() {
+ return property;
+ }
+
+ public CsmSingleReference(ObservableProperty property) {
+ this.property = property;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ Node child = property.getValueAsSingleReference(node);
+ if (child != null) {
+ ConcreteSyntaxModel.genericPrettyPrint(child, printer);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java
new file mode 100644
index 000000000..2fa0178d1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmString.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.SourcePrinter;
+
+public class CsmString implements CsmElement {
+ private final ObservableProperty property;
+
+ public CsmString(ObservableProperty property) {
+ this.property = property;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ printer.print("\"");
+ printer.print(property.getValueAsStringAttribute(node));
+ printer.print("\"");
+ }
+
+ @Override
+ public String toString() {
+ return String.format("CsmString(property:%s)", property);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java
new file mode 100644
index 000000000..d0745f7d0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmToken.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.GeneratedJavaParserConstants;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.printer.SourcePrinter;
+import com.github.javaparser.TokenTypes;
+import com.github.javaparser.utils.Utils;
+
+import static com.github.javaparser.TokenTypes.isEndOfLineToken;
+import static com.github.javaparser.TokenTypes.isSpaceOrTab;
+
+public class CsmToken implements CsmElement {
+ private final int tokenType;
+ private String content;
+ private TokenContentCalculator tokenContentCalculator;
+
+ public interface TokenContentCalculator {
+ String calculate(Node node);
+ }
+
+ public int getTokenType() {
+ return tokenType;
+ }
+
+ public String getContent(Node node) {
+ if (tokenContentCalculator != null) {
+ return tokenContentCalculator.calculate(node);
+ }
+ return content;
+ }
+
+ public CsmToken(int tokenType) {
+ this.tokenType = tokenType;
+ this.content = GeneratedJavaParserConstants.tokenImage[tokenType];
+ if (content.startsWith("\"")) {
+ content = content.substring(1, content.length() - 1);
+ }
+ if (isEndOfLineToken(tokenType)) {
+ content = Utils.EOL;
+ } else if (isSpaceOrTab(tokenType)) {
+ content = " ";
+ }
+ }
+
+ public CsmToken(int tokenType, String content) {
+ this.tokenType = tokenType;
+ this.content = content;
+ }
+
+ public CsmToken(int tokenType, TokenContentCalculator tokenContentCalculator) {
+ this.tokenType = tokenType;
+ this.tokenContentCalculator = tokenContentCalculator;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ if (isEndOfLineToken(tokenType)) {
+ printer.println();
+ } else {
+ printer.print(getContent(node));
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "token(" + content + ")";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ CsmToken csmToken = (CsmToken) o;
+
+ if (tokenType != csmToken.tokenType) return false;
+ if (content != null ? !content.equals(csmToken.content) : csmToken.content != null) return false;
+ return tokenContentCalculator != null ? tokenContentCalculator.equals(csmToken.tokenContentCalculator) : csmToken.tokenContentCalculator == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = tokenType;
+ result = 31 * result + (content != null ? content.hashCode() : 0);
+ result = 31 * result + (tokenContentCalculator != null ? tokenContentCalculator.hashCode() : 0);
+ return result;
+ }
+
+ public boolean isWhiteSpace() {
+ return TokenTypes.isWhitespace(tokenType);
+ }
+
+ public boolean isNewLine() {
+ return TokenTypes.isEndOfLineToken(tokenType);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java
new file mode 100644
index 000000000..bc4a00121
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/CsmUnindent.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.printer.SourcePrinter;
+
+public class CsmUnindent implements CsmElement {
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ printer.unindent();
+ }
+
+ @Override
+ public int hashCode() {
+ return 2;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return obj instanceof CsmUnindent;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java
new file mode 100644
index 000000000..626b0b842
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/concretesyntaxmodel/PrintingHelper.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.concretesyntaxmodel;
+
+import com.github.javaparser.printer.Printable;
+
+class PrintingHelper {
+
+ static String printToString(Object value) {
+ if (value instanceof Printable) {
+ return ((Printable)value).asString();
+ }
+ if (value instanceof Enum) {
+ return ((Enum) value).name().toLowerCase();
+ } else {
+ if (value != null) {
+ return value.toString();
+ }
+ }
+ return "";
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java
new file mode 100644
index 000000000..ad890c489
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.comments.Comment;
+
+/**
+ * Represent the position of a child node in the NodeText of its parent.
+ */
+class ChildTextElement extends TextElement {
+ private final Node child;
+
+ ChildTextElement(Node child) {
+ this.child = child;
+ }
+
+ String expand() {
+ return LexicalPreservingPrinter.print(child);
+ }
+
+ Node getChild() {
+ return child;
+ }
+
+ @Override
+ boolean isToken(int tokenKind) {
+ return false;
+ }
+
+ @Override
+ boolean isNode(Node node) {
+ return node == child;
+ }
+
+ NodeText getNodeTextForWrappedNode() {
+ return LexicalPreservingPrinter.getOrCreateNodeText(child);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ChildTextElement that = (ChildTextElement) o;
+
+ return child.equals(that.child);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return child.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "ChildTextElement{" + child + '}';
+ }
+
+ @Override
+ public boolean isWhiteSpace() {
+ return false;
+ }
+
+ @Override
+ public boolean isSpaceOrTab() {
+ return false;
+ }
+
+ @Override
+ public boolean isNewline() {
+ return false;
+ }
+
+ @Override
+ public boolean isComment() {
+ return child instanceof Comment;
+ }
+
+ @Override
+ public boolean isChildOfClass(Class<? extends Node> nodeClass) {
+ return nodeClass.isInstance(child);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java
new file mode 100644
index 000000000..610f91609
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/Difference.java
@@ -0,0 +1,885 @@
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.GeneratedJavaParserConstants;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.type.PrimitiveType;
+import com.github.javaparser.TokenTypes;
+import com.github.javaparser.printer.concretesyntaxmodel.*;
+import com.github.javaparser.printer.lexicalpreservation.LexicalDifferenceCalculator.CsmChild;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.GeneratedJavaParserConstants.*;
+
+/**
+ * A Difference should give me a sequence of elements I should find (to indicate the context) followed by a list of elements
+ * to remove or to add and follow by another sequence of elements.
+ *
+ * I should later be able to apply such difference to a nodeText.
+ */
+public class Difference {
+
+ private static final int STANDARD_INDENTATION_SIZE = 4;
+
+ private final List<DifferenceElement> elements;
+
+ private Difference(List<DifferenceElement> elements) {
+ this.elements = elements;
+ }
+
+ interface DifferenceElement {
+ static DifferenceElement added(CsmElement element) {
+ return new Added(element);
+ }
+
+ static DifferenceElement removed(CsmElement element) {
+ return new Removed(element);
+ }
+
+ static DifferenceElement kept(CsmElement element) {
+ return new Kept(element);
+ }
+
+ /**
+ * Return the CsmElement considered in this DifferenceElement.
+ */
+ CsmElement getElement();
+
+ boolean isAdded();
+ }
+
+ private static class Added implements DifferenceElement {
+ final CsmElement element;
+
+ public Added(CsmElement element) {
+ this.element = element;
+ }
+
+ @Override
+ public String toString() {
+ return "Added{" + element + '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Added added = (Added) o;
+
+ return element.equals(added.element);
+ }
+
+ @Override
+ public int hashCode() {
+ return element.hashCode();
+ }
+
+ @Override
+ public CsmElement getElement() {
+ return element;
+ }
+
+ @Override
+ public boolean isAdded() {
+ return true;
+ }
+ }
+
+ /**
+ * Elements in a CsmMix have been reshuffled. It could also mean that
+ * some new elements have been added or removed to the mix.
+ */
+ private static class Reshuffled implements DifferenceElement {
+ final CsmMix previousOrder;
+ final CsmMix element;
+
+ public Reshuffled(CsmMix previousOrder, CsmMix element) {
+ this.previousOrder = previousOrder;
+ this.element = element;
+ }
+
+ @Override
+ public String toString() {
+ return "Reshuffled{" + element + ", previous="+ previousOrder+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Reshuffled that = (Reshuffled) o;
+
+ if (!previousOrder.equals(that.previousOrder)) return false;
+ return element.equals(that.element);
+ }
+
+ @Override
+ public int hashCode() {
+ int result = previousOrder.hashCode();
+ result = 31 * result + element.hashCode();
+ return result;
+ }
+
+ @Override
+ public CsmMix getElement() {
+ return element;
+ }
+
+ @Override
+ public boolean isAdded() {
+ return false;
+ }
+ }
+
+ private static class Kept implements DifferenceElement {
+ final CsmElement element;
+
+ public Kept(CsmElement element) {
+ this.element = element;
+ }
+
+ @Override
+ public String toString() {
+ return "Kept{" + element + '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Kept kept = (Kept) o;
+
+ return element.equals(kept.element);
+ }
+
+ @Override
+ public int hashCode() {
+ return element.hashCode();
+ }
+
+ @Override
+ public CsmElement getElement() {
+ return element;
+ }
+
+ @Override
+ public boolean isAdded() {
+ return false;
+ }
+ }
+
+ private static class Removed implements DifferenceElement {
+ final CsmElement element;
+
+ public Removed(CsmElement element) {
+ this.element = element;
+ }
+
+ @Override
+ public String toString() {
+ return "Removed{" + element + '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Removed removed = (Removed) o;
+
+ return element.equals(removed.element);
+ }
+
+ @Override
+ public int hashCode() {
+ return element.hashCode();
+ }
+
+ @Override
+ public CsmElement getElement() {
+ return element;
+ }
+
+ @Override
+ public boolean isAdded() {
+ return false;
+ }
+ }
+
+ private static boolean matching(CsmElement a, CsmElement b) {
+ if (a instanceof CsmChild) {
+ if (b instanceof CsmChild) {
+ CsmChild childA = (CsmChild) a;
+ CsmChild childB = (CsmChild) b;
+ return childA.getChild().equals(childB.getChild());
+ } else if (b instanceof CsmToken) {
+ return false;
+ } else if (b instanceof CsmIndent) {
+ return false;
+ } else if (b instanceof CsmUnindent) {
+ return false;
+ } else {
+ throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName());
+ }
+ } else if (a instanceof CsmToken) {
+ if (b instanceof CsmToken) {
+ CsmToken childA = (CsmToken)a;
+ CsmToken childB = (CsmToken)b;
+ return childA.getTokenType() == childB.getTokenType();
+ } else if (b instanceof CsmChild) {
+ return false;
+ } else if (b instanceof CsmIndent) {
+ return false;
+ } else if (b instanceof CsmUnindent) {
+ return false;
+ } else {
+ throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName());
+ }
+ } else if (a instanceof CsmIndent) {
+ return b instanceof CsmIndent;
+ } else if (a instanceof CsmUnindent) {
+ return b instanceof CsmUnindent;
+ }
+ throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName());
+ }
+
+ private static boolean replacement(CsmElement a, CsmElement b) {
+ if (a instanceof CsmIndent || b instanceof CsmIndent || a instanceof CsmUnindent || b instanceof CsmUnindent) {
+ return false;
+ }
+ if (a instanceof CsmChild) {
+ if (b instanceof CsmChild) {
+ CsmChild childA = (CsmChild) a;
+ CsmChild childB = (CsmChild) b;
+ return childA.getChild().getClass().equals(childB.getChild().getClass());
+ } else if (b instanceof CsmToken) {
+ return false;
+ } else {
+ throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName());
+ }
+ } else if (a instanceof CsmToken) {
+ if (b instanceof CsmToken) {
+ CsmToken childA = (CsmToken)a;
+ CsmToken childB = (CsmToken)b;
+ return childA.getTokenType() == childB.getTokenType();
+ } else if (b instanceof CsmChild) {
+ return false;
+ }
+ }
+ throw new UnsupportedOperationException(a.getClass().getSimpleName()+ " "+b.getClass().getSimpleName());
+ }
+
+ /**
+ * Find the positions of all the given children.
+ */
+ private static Map<Node, Integer> findChildrenPositions(LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel) {
+ Map<Node, Integer> positions = new HashMap<>();
+ for (int i=0;i<calculatedSyntaxModel.elements.size();i++) {
+ CsmElement element = calculatedSyntaxModel.elements.get(i);
+ if (element instanceof CsmChild) {
+ positions.put(((CsmChild)element).getChild(), i);
+ }
+ }
+ return positions;
+ }
+
+ /**
+ * Calculate the Difference between two CalculatedSyntaxModel elements, determining which elements were kept,
+ * which were added and which were removed.
+ */
+ static Difference calculate(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) {
+ // For performance reasons we use the positions of matching children
+ // to guide the calculation of the difference
+ //
+ // Suppose we have:
+ // qwerty[A]uiop
+ // qwer[A]uiop
+ //
+ // with [A] being a child and lowercase letters being tokens
+ //
+ // We would calculate the Difference between "qwerty" and "qwer" then we know the A is kep, and then we
+ // would calculate the difference between "uiop" and "uiop"
+
+ Map<Node, Integer> childrenInOriginal = findChildrenPositions(original);
+ Map<Node, Integer> childrenInAfter = findChildrenPositions(after);
+
+ List<Node> commonChildren = new LinkedList<>(childrenInOriginal.keySet());
+ commonChildren.retainAll(childrenInAfter.keySet());
+ commonChildren.sort(Comparator.comparingInt(childrenInOriginal::get));
+
+ List<DifferenceElement> elements = new LinkedList<>();
+
+ int originalIndex = 0;
+ int afterIndex = 0;
+ int commonChildrenIndex = 0;
+ while (commonChildrenIndex < commonChildren.size()) {
+ Node child = commonChildren.get(commonChildrenIndex++);
+ int posOfNextChildInOriginal = childrenInOriginal.get(child);
+ int posOfNextChildInAfter = childrenInAfter.get(child);
+ if (originalIndex < posOfNextChildInOriginal || afterIndex < posOfNextChildInAfter) {
+ elements.addAll(calculateImpl(original.sub(originalIndex, posOfNextChildInOriginal), after.sub(afterIndex, posOfNextChildInAfter)).elements);
+ }
+ elements.add(new Kept(new CsmChild(child)));
+ originalIndex = posOfNextChildInOriginal + 1;
+ afterIndex = posOfNextChildInAfter + 1;
+ }
+
+ if (originalIndex < original.elements.size() || afterIndex < after.elements.size()) {
+ elements.addAll(calculateImpl(original.sub(originalIndex, original.elements.size()), after.sub(afterIndex, after.elements.size())).elements);
+ }
+ return new Difference(elements);
+ }
+
+ private static Difference calculateImpl(LexicalDifferenceCalculator.CalculatedSyntaxModel original, LexicalDifferenceCalculator.CalculatedSyntaxModel after) {
+ List<DifferenceElement> elements = new LinkedList<>();
+
+ int originalIndex = 0;
+ int afterIndex = 0;
+
+ // We move through the two CalculatedSyntaxModel, moving both forward when we have a match
+ // and moving just one side forward when we have an element kept or removed
+
+ do {
+ if (originalIndex < original.elements.size() && afterIndex >= after.elements.size()) {
+ elements.add(new Removed(original.elements.get(originalIndex)));
+ originalIndex++;
+ } else if (originalIndex >= original.elements.size() && afterIndex < after.elements.size()) {
+ elements.add(new Added(after.elements.get(afterIndex)));
+ afterIndex++;
+ } else {
+ CsmElement nextOriginal = original.elements.get(originalIndex);
+ CsmElement nextAfter = after.elements.get(afterIndex);
+
+ if ((nextOriginal instanceof CsmMix) && (nextAfter instanceof CsmMix)) {
+ if (((CsmMix) nextAfter).getElements().equals(((CsmMix) nextOriginal).getElements())) {
+ // No reason to deal with a reshuffled, we are just going to keep everything as it is
+ ((CsmMix) nextAfter).getElements().forEach(el -> elements.add(new Kept(el)));
+ } else {
+ elements.add(new Reshuffled((CsmMix)nextOriginal, (CsmMix)nextAfter));
+ }
+ originalIndex++;
+ afterIndex++;
+ } else if (matching(nextOriginal, nextAfter)) {
+ elements.add(new Kept(nextOriginal));
+ originalIndex++;
+ afterIndex++;
+ } else if (replacement(nextOriginal, nextAfter)) {
+ elements.add(new Removed(nextOriginal));
+ elements.add(new Added(nextAfter));
+ originalIndex++;
+ afterIndex++;
+ } else {
+ // We can try to remove the element or add it and look which one leads to the lower difference
+ Difference adding = calculate(original.from(originalIndex), after.from(afterIndex + 1));
+ Difference removing = null;
+ if (adding.cost() > 0) {
+ removing = calculate(original.from(originalIndex + 1), after.from(afterIndex));
+ }
+
+ if (removing == null || removing.cost() > adding.cost()) {
+ elements.add(new Added(nextAfter));
+ afterIndex++;
+ } else {
+ elements.add(new Removed(nextOriginal));
+ originalIndex++;
+ }
+ }
+ }
+ } while (originalIndex < original.elements.size() || afterIndex < after.elements.size());
+
+ return new Difference(elements);
+ }
+
+ private TextElement toTextElement(CsmElement csmElement) {
+ if (csmElement instanceof CsmChild) {
+ return new ChildTextElement(((CsmChild) csmElement).getChild());
+ } else if (csmElement instanceof CsmToken) {
+ return new TokenTextElement(((CsmToken) csmElement).getTokenType(), ((CsmToken) csmElement).getContent(null));
+ } else {
+ throw new UnsupportedOperationException(csmElement.getClass().getSimpleName());
+ }
+ }
+
+ private List<TextElement> processIndentation(List<TokenTextElement> indentation, List<TextElement> prevElements) {
+ List<TextElement> res = new LinkedList<>();
+ res.addAll(indentation);
+ boolean afterNl = false;
+ for (TextElement e : prevElements) {
+ if (e.isNewline() || e.isToken(SINGLE_LINE_COMMENT)) {
+ res.clear();
+ afterNl = true;
+ } else {
+ if (afterNl && e instanceof TokenTextElement && TokenTypes.isWhitespace(((TokenTextElement)e).getTokenKind())) {
+ res.add(e);
+ } else {
+ afterNl = false;
+ }
+ }
+ }
+ return res;
+ }
+
+ private List<TextElement> indentationBlock() {
+ List<TextElement> res = new LinkedList<>();
+ res.add(new TokenTextElement(SPACE));
+ res.add(new TokenTextElement(SPACE));
+ res.add(new TokenTextElement(SPACE));
+ res.add(new TokenTextElement(SPACE));
+ return res;
+ }
+
+ private int considerCleaningTheLine(NodeText nodeText, int nodeTextIndex) {
+ while (nodeTextIndex >=1 && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace() && !nodeText.getElements().get(nodeTextIndex - 1).isNewline()) {
+ nodeText.removeElement(nodeTextIndex - 1);
+ nodeTextIndex--;
+ }
+ return nodeTextIndex;
+ }
+
+ private boolean isAfterLBrace(NodeText nodeText, int nodeTextIndex) {
+ if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isToken(LBRACE)) {
+ return true;
+ }
+ if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace() && !nodeText.getElements().get(nodeTextIndex - 1).isNewline()) {
+ return isAfterLBrace(nodeText, nodeTextIndex - 1);
+ }
+ return false;
+ }
+
+ /**
+ * If we are at the beginning of a line, with just spaces or tabs before us we should force the space to be
+ * the same as the indentation.
+ */
+ private int considerEnforcingIndentation(NodeText nodeText, int nodeTextIndex) {
+ boolean hasOnlyWsBefore = true;
+ for (int i=nodeTextIndex; i >= 0 && hasOnlyWsBefore && i < nodeText.getElements().size(); i--) {
+ if (nodeText.getElements().get(i).isNewline()) {
+ break;
+ }
+ if (!nodeText.getElements().get(i).isSpaceOrTab()) {
+ hasOnlyWsBefore = false;
+ }
+ }
+ if (hasOnlyWsBefore) {
+ for (int i=nodeTextIndex; i >= 0 && i < nodeText.getElements().size(); i--) {
+ if (nodeText.getElements().get(i).isNewline()) {
+ break;
+ }
+ nodeText.removeElement(i);
+ }
+ }
+ return nodeTextIndex;
+ }
+
+ /**
+ * Node that we have calculate the Difference we can apply to a concrete NodeText, modifying it according
+ * to the difference (adding and removing the elements provided).
+ */
+ void apply(NodeText nodeText, Node node) {
+ if (nodeText == null) {
+ throw new NullPointerException();
+ }
+ boolean addedIndentation = false;
+ List<TokenTextElement> indentation = LexicalPreservingPrinter.findIndentation(node);
+ int diffIndex = 0;
+ int nodeTextIndex = 0;
+ do {
+ if (diffIndex < this.elements.size() && nodeTextIndex >= nodeText.getElements().size()) {
+ DifferenceElement diffEl = elements.get(diffIndex);
+ if (diffEl instanceof Kept) {
+ Kept kept = (Kept) diffEl;
+ if (kept.element instanceof CsmToken) {
+ CsmToken csmToken = (CsmToken) kept.element;
+ if (TokenTypes.isWhitespaceOrComment(csmToken.getTokenType())) {
+ diffIndex++;
+ } else {
+ throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: "
+ + nodeText + ". Difference: " + this);
+ }
+ } else {
+ throw new IllegalStateException("Cannot keep element because we reached the end of nodetext: "
+ + nodeText + ". Difference: " + this);
+ }
+ } else if (diffEl instanceof Added) {
+ nodeText.addElement(nodeTextIndex, toTextElement(((Added) diffEl).element));
+ nodeTextIndex++;
+ diffIndex++;
+ } else {
+ throw new UnsupportedOperationException(diffEl.getClass().getSimpleName());
+ }
+ } else if (diffIndex >= this.elements.size() && nodeTextIndex < nodeText.getElements().size()) {
+ TextElement nodeTextEl = nodeText.getElements().get(nodeTextIndex);
+ if (nodeTextEl.isWhiteSpaceOrComment()) {
+ nodeTextIndex++;
+ } else {
+ throw new UnsupportedOperationException("NodeText: " + nodeText + ". Difference: "
+ + this + " " + nodeTextEl);
+ }
+ } else {
+ DifferenceElement diffEl = elements.get(diffIndex);
+ TextElement nodeTextEl = nodeText.getElements().get(nodeTextIndex);
+ if (diffEl instanceof Added) {
+ CsmElement addedElement = ((Added) diffEl).element;
+ if (addedElement instanceof CsmIndent) {
+ for (int i=0;i<STANDARD_INDENTATION_SIZE;i++){
+ indentation.add(new TokenTextElement(GeneratedJavaParserConstants.SPACE));
+ }
+ addedIndentation = true;
+ diffIndex++;
+ continue;
+ }
+ if (addedElement instanceof CsmUnindent) {
+ for (int i=0;i<STANDARD_INDENTATION_SIZE && !indentation.isEmpty();i++){
+ indentation.remove(indentation.size() - 1);
+ }
+ addedIndentation = false;
+ diffIndex++;
+ continue;
+ }
+ TextElement textElement = toTextElement(addedElement);
+ boolean used = false;
+ if (nodeTextIndex > 0 && nodeText.getElements().get(nodeTextIndex - 1).isNewline()) {
+ for (TextElement e : processIndentation(indentation, nodeText.getElements().subList(0, nodeTextIndex - 1))) {
+ nodeText.addElement(nodeTextIndex++, e);
+ }
+ } else if (isAfterLBrace(nodeText, nodeTextIndex) && !isAReplacement(diffIndex)) {
+ if (textElement.isNewline()) {
+ used = true;
+ }
+ nodeText.addElement(nodeTextIndex++, new TokenTextElement(TokenTypes.eolTokenKind()));
+ // This remove the space in "{ }" when adding a new line
+ while (nodeText.getElements().get(nodeTextIndex).isSpaceOrTab()) {
+ nodeText.getElements().remove(nodeTextIndex);
+ }
+ for (TextElement e : processIndentation(indentation, nodeText.getElements().subList(0, nodeTextIndex - 1))) {
+ nodeText.addElement(nodeTextIndex++, e);
+ }
+ // Indentation is painful...
+ // Sometimes we want to force indentation: this is the case when indentation was expected but
+ // was actually not there. For example if we have "{ }" we would expect indentation but it is
+ // not there, so when adding new elements we force it. However if the indentation has been
+ // inserted by us in this transformation we do not want to insert it again
+ if (!addedIndentation) {
+ for (TextElement e : indentationBlock()) {
+ nodeText.addElement(nodeTextIndex++, e);
+ }
+ }
+ }
+ if (!used) {
+ nodeText.addElement(nodeTextIndex, textElement);
+ nodeTextIndex++;
+ }
+ if (textElement.isNewline()) {
+ boolean followedByUnindent = (diffIndex + 1) < elements.size()
+ && elements.get(diffIndex + 1).isAdded()
+ && elements.get(diffIndex + 1).getElement() instanceof CsmUnindent;
+ nodeTextIndex = adjustIndentation(indentation, nodeText, nodeTextIndex, followedByUnindent/* && !addedIndentation*/);
+ }
+ diffIndex++;
+ } else if (diffEl instanceof Kept) {
+ Kept kept = (Kept)diffEl;
+ if (nodeTextEl.isComment()) {
+ nodeTextIndex++;
+ } else if ((kept.element instanceof CsmChild) && nodeTextEl instanceof ChildTextElement) {
+ diffIndex++;
+ nodeTextIndex++;
+ } else if ((kept.element instanceof CsmChild) && nodeTextEl instanceof TokenTextElement) {
+ if (nodeTextEl.isWhiteSpaceOrComment()) {
+ nodeTextIndex++;
+ } else {
+ if (kept.element instanceof CsmChild) {
+ CsmChild keptChild = (CsmChild)kept.element;
+ if (keptChild.getChild() instanceof PrimitiveType) {
+ nodeTextIndex++;
+ diffIndex++;
+ } else {
+ throw new UnsupportedOperationException("kept " + kept.element + " vs " + nodeTextEl);
+ }
+ } else {
+ throw new UnsupportedOperationException("kept " + kept.element + " vs " + nodeTextEl);
+ }
+ }
+ } else if ((kept.element instanceof CsmToken) && nodeTextEl instanceof TokenTextElement) {
+ CsmToken csmToken = (CsmToken) kept.element;
+ TokenTextElement nodeTextToken = (TokenTextElement) nodeTextEl;
+ if (csmToken.getTokenType() == nodeTextToken.getTokenKind()) {
+ nodeTextIndex++;
+ diffIndex++;
+ } else if (TokenTypes.isWhitespaceOrComment(csmToken.getTokenType())) {
+ diffIndex++;
+ } else if (nodeTextToken.isWhiteSpaceOrComment()) {
+ nodeTextIndex++;
+ } else {
+ throw new UnsupportedOperationException("Csm token " + csmToken + " NodeText TOKEN " + nodeTextToken);
+ }
+ } else if ((kept.element instanceof CsmToken) && ((CsmToken) kept.element).isWhiteSpace()) {
+ diffIndex++;
+ } else if (kept.element instanceof CsmIndent) {
+ // Nothing to do
+ diffIndex++;
+ } else if (kept.element instanceof CsmUnindent) {
+ // Nothing to do, beside considering indentation
+ diffIndex++;
+ for (int i = 0; i < STANDARD_INDENTATION_SIZE && nodeTextIndex >= 1 && nodeText.getTextElement(nodeTextIndex - 1).isSpaceOrTab(); i++) {
+ nodeText.removeElement(--nodeTextIndex);
+ }
+ } else {
+ throw new UnsupportedOperationException("kept " + kept.element + " vs " + nodeTextEl);
+ }
+ } else if (diffEl instanceof Removed) {
+ Removed removed = (Removed)diffEl;
+ if ((removed.element instanceof CsmChild) && nodeTextEl instanceof ChildTextElement) {
+ ChildTextElement actualChild = (ChildTextElement)nodeTextEl;
+ if (actualChild.isComment()) {
+ CsmChild csmChild = (CsmChild)removed.element;
+ // We expected to remove a proper node but we found a comment in between.
+ // If the comment is associated to the node we want to remove we remove it as well, otherwise we keep it
+ Comment comment = (Comment)actualChild.getChild();
+ if (!comment.isOrphan() && comment.getCommentedNode().isPresent() && comment.getCommentedNode().get().equals(csmChild.getChild())) {
+ nodeText.removeElement(nodeTextIndex);
+ } else {
+ nodeTextIndex++;
+ }
+ } else {
+ nodeText.removeElement(nodeTextIndex);
+ if (nodeTextIndex < nodeText.getElements().size() && nodeText.getElements().get(nodeTextIndex).isNewline()) {
+ nodeTextIndex = considerCleaningTheLine(nodeText, nodeTextIndex);
+ } else {
+ if (diffIndex + 1 >= this.getElements().size() || !(this.getElements().get(diffIndex + 1) instanceof Added)) {
+ nodeTextIndex = considerEnforcingIndentation(nodeText, nodeTextIndex);
+ }
+ // If in front we have one space and before also we had space let's drop one space
+ if (nodeText.getElements().size() > nodeTextIndex && nodeTextIndex > 0) {
+ if (nodeText.getElements().get(nodeTextIndex).isWhiteSpace()
+ && nodeText.getElements().get(nodeTextIndex - 1).isWhiteSpace()) {
+ // However we do not want to do that when we are about to adding or removing elements
+ if ((diffIndex + 1) == this.elements.size() || (elements.get(diffIndex + 1) instanceof Kept)) {
+ nodeText.getElements().remove(nodeTextIndex--);
+ }
+ }
+ }
+ }
+ diffIndex++;
+ }
+ } else if ((removed.element instanceof CsmToken) && nodeTextEl instanceof TokenTextElement
+ && ((CsmToken)removed.element).getTokenType() == ((TokenTextElement)nodeTextEl).getTokenKind()) {
+ nodeText.removeElement(nodeTextIndex);
+ diffIndex++;
+ } else if (nodeTextEl instanceof TokenTextElement
+ && nodeTextEl.isWhiteSpaceOrComment()) {
+ nodeTextIndex++;
+ } else if (removed.element instanceof CsmChild
+ && ((CsmChild)removed.element).getChild() instanceof PrimitiveType) {
+ if (isPrimitiveType(nodeTextEl)) {
+ nodeText.removeElement(nodeTextIndex);
+ diffIndex++;
+ } else {
+ throw new UnsupportedOperationException("removed " + removed.element + " vs " + nodeTextEl);
+ }
+ } else if (removed.element instanceof CsmToken && ((CsmToken)removed.element).isWhiteSpace()) {
+ diffIndex++;
+ } else if (nodeTextEl.isWhiteSpace()) {
+ nodeTextIndex++;
+ } else {
+ throw new UnsupportedOperationException("removed " + removed.element + " vs " + nodeTextEl);
+ }
+ } else if (diffEl instanceof Reshuffled) {
+
+ // First, let's see how many tokens we need to attribute to the previous version of the of the CsmMix
+ Reshuffled reshuffled = (Reshuffled)diffEl;
+ CsmMix elementsFromPreviousOrder = reshuffled.previousOrder;
+ CsmMix elementsFromNextOrder = reshuffled.element;
+
+ // This contains indexes from elementsFromNextOrder to indexes from elementsFromPreviousOrder
+ Map<Integer, Integer> correspondanceBetweenNextOrderAndPreviousOrder = new HashMap<>();
+ for (int ni=0;ni<elementsFromNextOrder.getElements().size();ni++) {
+ boolean found = false;
+ CsmElement ne = elementsFromNextOrder.getElements().get(ni);
+ for (int pi=0;pi<elementsFromPreviousOrder.getElements().size() && !found;pi++) {
+ CsmElement pe = elementsFromPreviousOrder.getElements().get(pi);
+ if (!correspondanceBetweenNextOrderAndPreviousOrder.values().contains(pi)
+ && matching(ne, pe)) {
+ found = true;
+ correspondanceBetweenNextOrderAndPreviousOrder.put(ni, pi);
+ }
+ }
+ }
+
+ // We now find out which Node Text elements corresponds to the elements in the original CSM
+ final int startNodeTextIndex = nodeTextIndex;
+ final Set<Integer> usedIndexes = new HashSet<>();
+ List<Integer> nodeTextIndexOfPreviousElements = elementsFromPreviousOrder.getElements().stream()
+ .map(it -> findIndexOfCorrespondingNodeTextElement(it, nodeText, startNodeTextIndex, usedIndexes, node))
+ .collect(Collectors.toList());
+ Map<Integer, Integer> nodeTextIndexToPreviousCSMIndex = new HashMap<>();
+ for (int i=0;i<nodeTextIndexOfPreviousElements.size();i++) {
+ int value = nodeTextIndexOfPreviousElements.get(i);
+ if (value != -1) {
+ nodeTextIndexToPreviousCSMIndex.put(value, i);
+ }
+ }
+ int lastNodeTextIndex = nodeTextIndexOfPreviousElements.stream().max(Integer::compareTo).orElse(-1);
+
+ // Elements to be added at the end
+ List<CsmElement> elementsToBeAddedAtTheEnd = new LinkedList<>();
+ Map<Integer, List<CsmElement>> elementsToAddBeforeGivenOriginalCSMElement = new HashMap<>();
+ for (int ni=0;ni<elementsFromNextOrder.getElements().size();ni++) {
+ // If it has a mapping, then it is kept
+ if (!correspondanceBetweenNextOrderAndPreviousOrder.containsKey(ni)) {
+ // Ok, it is something new. Where to put it? Let's see what is the first following
+ // element that has a mapping
+ int originalCsmIndex = -1;
+ for (int nj=ni + 1;nj<elementsFromNextOrder.getElements().size() && originalCsmIndex==-1;nj++) {
+ if (correspondanceBetweenNextOrderAndPreviousOrder.containsKey(nj)) {
+ originalCsmIndex = correspondanceBetweenNextOrderAndPreviousOrder.get(nj);
+ if (!elementsToAddBeforeGivenOriginalCSMElement.containsKey(originalCsmIndex)){
+ elementsToAddBeforeGivenOriginalCSMElement.put(originalCsmIndex, new LinkedList<>());
+ }
+ elementsToAddBeforeGivenOriginalCSMElement.get(originalCsmIndex).add(elementsFromNextOrder.getElements().get(ni));
+ }
+ }
+ // it does not preceed anything, so it goes at the end
+ if (originalCsmIndex == -1) {
+ elementsToBeAddedAtTheEnd.add(elementsFromNextOrder.getElements().get(ni));
+ }
+ }
+ }
+
+ // We go over the original node text elements, in the order they appear in the NodeText.
+ // Considering an original node text element (ONE)
+ // * we verify if it corresponds to a CSM element. If it does not we just move on, otherwise
+ // we find the correspond OCE (Original CSM Element)
+ // * we first add new elements that are marked to be added before OCE
+ // * if OCE is marked to be present also in the "after" CSM we add a kept element,
+ // otherwise we add a removed element
+
+ this.getElements().remove(diffIndex);
+ int diffElIterator = diffIndex;
+ if (lastNodeTextIndex != -1) {
+ for (int ntIndex = startNodeTextIndex; ntIndex<=lastNodeTextIndex; ntIndex++) {
+
+ if (nodeTextIndexToPreviousCSMIndex.containsKey(ntIndex)) {
+ int indexOfOriginalCSMElement = nodeTextIndexToPreviousCSMIndex.get(ntIndex);
+ if (elementsToAddBeforeGivenOriginalCSMElement.containsKey(indexOfOriginalCSMElement)) {
+ for (CsmElement elementToAdd : elementsToAddBeforeGivenOriginalCSMElement.get(indexOfOriginalCSMElement)) {
+ elements.add(diffElIterator++, new Added(elementToAdd));
+ }
+ }
+
+ CsmElement originalCSMElement = elementsFromPreviousOrder.getElements().get(indexOfOriginalCSMElement);
+ boolean toBeKept = correspondanceBetweenNextOrderAndPreviousOrder.containsValue(indexOfOriginalCSMElement);
+ if (toBeKept) {
+ elements.add(diffElIterator++, new Kept(originalCSMElement));
+ } else {
+ elements.add(diffElIterator++, new Removed(originalCSMElement));
+ }
+ }
+ // else we have a simple node text element, without associated csm element, just keep ignore it
+ }
+ }
+
+ // Finally we look for the remaining new elements that were not yet added and
+ // add all of them
+ for (CsmElement elementToAdd : elementsToBeAddedAtTheEnd) {
+ elements.add(diffElIterator++, new Added(elementToAdd));
+ }
+ } else {
+ throw new UnsupportedOperationException("" + diffEl + " vs " + nodeTextEl);
+ }
+ }
+ } while (diffIndex < this.elements.size() || nodeTextIndex < nodeText.getElements().size());
+ }
+
+ private int findIndexOfCorrespondingNodeTextElement(CsmElement csmElement, NodeText nodeText, int startIndex, Set<Integer> usedIndexes, Node node) {
+ for (int i=startIndex;i<nodeText.getElements().size();i++){
+ if (!usedIndexes.contains(i)) {
+ TextElement textElement = nodeText.getTextElement(i);
+ if (csmElement instanceof CsmToken) {
+ CsmToken csmToken = (CsmToken)csmElement;
+ if (textElement instanceof TokenTextElement) {
+ TokenTextElement tokenTextElement = (TokenTextElement)textElement;
+ if (tokenTextElement.getTokenKind() == csmToken.getTokenType() && tokenTextElement.getText().equals(csmToken.getContent(node))) {
+ usedIndexes.add(i);
+ return i;
+ }
+ }
+ } else if (csmElement instanceof CsmChild) {
+ CsmChild csmChild = (CsmChild)csmElement;
+ if (textElement instanceof ChildTextElement) {
+ ChildTextElement childTextElement = (ChildTextElement)textElement;
+ if (childTextElement.getChild() == csmChild.getChild()) {
+ usedIndexes.add(i);
+ return i;
+ }
+ }
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+ }
+ return -1;
+ }
+
+ private int adjustIndentation(List<TokenTextElement> indentation, NodeText nodeText, int nodeTextIndex, boolean followedByUnindent) {
+ List<TextElement> indentationAdj = processIndentation(indentation, nodeText.getElements().subList(0, nodeTextIndex - 1));
+ if (nodeTextIndex < nodeText.getElements().size() && nodeText.getElements().get(nodeTextIndex).isToken(RBRACE)) {
+ indentationAdj = indentationAdj.subList(0, indentationAdj.size() - Math.min(STANDARD_INDENTATION_SIZE, indentationAdj.size()));
+ } else if (followedByUnindent) {
+ indentationAdj = indentationAdj.subList(0, Math.max(0, indentationAdj.size() - STANDARD_INDENTATION_SIZE));
+ }
+ for (TextElement e : indentationAdj) {
+ if ((nodeTextIndex<nodeText.getElements().size()) && nodeText.getElements().get(nodeTextIndex).isSpaceOrTab()) {
+ nodeTextIndex++;
+ } else {
+ nodeText.getElements().add(nodeTextIndex++, e);
+ }
+ }
+ return nodeTextIndex;
+ }
+
+ private boolean isAReplacement(int diffIndex) {
+ return (diffIndex > 0) && getElements().get(diffIndex) instanceof Added && getElements().get(diffIndex - 1) instanceof Removed;
+ }
+
+ private boolean isPrimitiveType(TextElement textElement) {
+ if (textElement instanceof TokenTextElement) {
+ TokenTextElement tokenTextElement = (TokenTextElement)textElement;
+ int tokenKind = tokenTextElement.getTokenKind();
+ return tokenKind == BYTE
+ || tokenKind == CHAR
+ || tokenKind == SHORT
+ || tokenKind == INT
+ || tokenKind == LONG
+ || tokenKind == FLOAT
+ || tokenKind == DOUBLE;
+ } else {
+ return false;
+ }
+ }
+
+ private long cost() {
+ return elements.stream().filter(e -> !(e instanceof Kept)).count();
+ }
+
+ @Override
+ public String toString() {
+ return "Difference{" + elements + '}';
+ }
+
+ public List<DifferenceElement> getElements() {
+ return elements;
+ }
+
+ /**
+ * Remove from the difference all the elements related to indentation.
+ * This is mainly intended for test purposes.
+ */
+ void removeIndentationElements() {
+ elements.removeIf(el -> el.getElement() instanceof CsmIndent || el.getElement() instanceof CsmUnindent);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java
new file mode 100644
index 000000000..9263dfd8a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalDifferenceCalculator.java
@@ -0,0 +1,332 @@
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.GeneratedJavaParserConstants;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.StringLiteralExpr;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.ConcreteSyntaxModel;
+import com.github.javaparser.printer.Printable;
+import com.github.javaparser.printer.SourcePrinter;
+import com.github.javaparser.printer.concretesyntaxmodel.*;
+import com.github.javaparser.printer.lexicalpreservation.changes.*;
+
+import java.util.*;
+
+class LexicalDifferenceCalculator {
+
+ /**
+ * The ConcreteSyntaxModel represents the general format. This model is a calculated version of the ConcreteSyntaxModel,
+ * with no condition, no lists, just tokens and node children.
+ */
+ static class CalculatedSyntaxModel {
+ final List<CsmElement> elements;
+
+ CalculatedSyntaxModel(List<CsmElement> elements) {
+ this.elements = elements;
+ }
+
+ public CalculatedSyntaxModel from(int index) {
+ List<CsmElement> newList = new LinkedList<>();
+ newList.addAll(elements.subList(index, elements.size()));
+ return new CalculatedSyntaxModel(newList);
+ }
+
+ @Override
+ public String toString() {
+ return "CalculatedSyntaxModel{" +
+ "elements=" + elements +
+ '}';
+ }
+
+ CalculatedSyntaxModel sub(int start, int end) {
+ return new CalculatedSyntaxModel(elements.subList(start, end));
+ }
+
+ void removeIndentationElements() {
+ elements.removeIf(el -> el instanceof CsmIndent || el instanceof CsmUnindent);
+ }
+ }
+
+ static class CsmChild implements CsmElement {
+ private final Node child;
+
+ public Node getChild() {
+ return child;
+ }
+
+ CsmChild(Node child) {
+ this.child = child;
+ }
+
+ @Override
+ public void prettyPrint(Node node, SourcePrinter printer) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String toString() {
+ return "child(" + child.getClass().getSimpleName()+")";
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ CsmChild csmChild = (CsmChild) o;
+
+ return child.equals(csmChild.child);
+ }
+
+ @Override
+ public int hashCode() {
+ return child.hashCode();
+ }
+ }
+
+ Difference calculateListRemovalDifference(ObservableProperty observableProperty, NodeList nodeList, int index) {
+ Node container = nodeList.getParentNodeForChildren();
+ CsmElement element = ConcreteSyntaxModel.forClass(container.getClass());
+ CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container);
+ CalculatedSyntaxModel after = calculatedSyntaxModelAfterListRemoval(element, observableProperty, nodeList, index);
+ return Difference.calculate(original, after);
+ }
+
+ Difference calculateListAdditionDifference(ObservableProperty observableProperty, NodeList nodeList, int index, Node nodeAdded) {
+ Node container = nodeList.getParentNodeForChildren();
+ CsmElement element = ConcreteSyntaxModel.forClass(container.getClass());
+ CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container);
+ CalculatedSyntaxModel after = calculatedSyntaxModelAfterListAddition(element, observableProperty, nodeList, index, nodeAdded);
+ return Difference.calculate(original, after);
+ }
+
+ Difference calculateListReplacementDifference(ObservableProperty observableProperty, NodeList nodeList, int index, Node newValue) {
+ Node container = nodeList.getParentNodeForChildren();
+ CsmElement element = ConcreteSyntaxModel.forClass(container.getClass());
+ CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, container);
+ CalculatedSyntaxModel after = calculatedSyntaxModelAfterListReplacement(element, observableProperty, nodeList, index, newValue);
+ return Difference.calculate(original, after);
+ }
+
+ public void calculatePropertyChange(NodeText nodeText, Node observedNode, ObservableProperty property, Object oldValue, Object newValue) {
+ if (nodeText == null) {
+ throw new NullPointerException();
+ }
+ CsmElement element = ConcreteSyntaxModel.forClass(observedNode.getClass());
+ CalculatedSyntaxModel original = calculatedSyntaxModelForNode(element, observedNode);
+ CalculatedSyntaxModel after = calculatedSyntaxModelAfterPropertyChange(element, observedNode, property, oldValue, newValue);
+ Difference difference = Difference.calculate(original, after);
+ difference.apply(nodeText, observedNode);
+ }
+
+ // Visible for testing
+ CalculatedSyntaxModel calculatedSyntaxModelForNode(CsmElement csm, Node node) {
+ List<CsmElement> elements = new LinkedList<>();
+ calculatedSyntaxModelForNode(csm, node, elements, new NoChange());
+ return new CalculatedSyntaxModel(elements);
+ }
+
+ CalculatedSyntaxModel calculatedSyntaxModelForNode(Node node) {
+ return calculatedSyntaxModelForNode(ConcreteSyntaxModel.forClass(node.getClass()), node);
+ }
+
+ private void calculatedSyntaxModelForNode(CsmElement csm, Node node, List<CsmElement> elements, Change change) {
+ if (csm instanceof CsmSequence) {
+ CsmSequence csmSequence = (CsmSequence) csm;
+ csmSequence.getElements().forEach(e -> calculatedSyntaxModelForNode(e, node, elements, change));
+ } else if (csm instanceof CsmComment) {
+ // nothing to do
+ } else if (csm instanceof CsmSingleReference) {
+ CsmSingleReference csmSingleReference = (CsmSingleReference)csm;
+ Node child;
+ if (change instanceof PropertyChange && ((PropertyChange)change).getProperty() == csmSingleReference.getProperty()) {
+ child = (Node)((PropertyChange)change).getNewValue();
+ } else {
+ child = csmSingleReference.getProperty().getValueAsSingleReference(node);
+ }
+ if (child != null) {
+ elements.add(new CsmChild(child));
+ }
+ } else if (csm instanceof CsmNone) {
+ // nothing to do
+ } else if (csm instanceof CsmToken) {
+ elements.add(csm);
+ } else if (csm instanceof CsmOrphanCommentsEnding) {
+ // nothing to do
+ } else if (csm instanceof CsmList) {
+ CsmList csmList = (CsmList) csm;
+ if (csmList.getProperty().isAboutNodes()) {
+ Object rawValue = change.getValue(csmList.getProperty(), node);
+ NodeList nodeList;
+ if (rawValue instanceof Optional) {
+ Optional optional = (Optional)rawValue;
+ if (optional.isPresent()) {
+ if (!(optional.get() instanceof NodeList)) {
+ throw new IllegalStateException("Expected NodeList, found " + optional.get().getClass().getCanonicalName());
+ }
+ nodeList = (NodeList) optional.get();
+ } else {
+ nodeList = new NodeList();
+ }
+ } else {
+ if (!(rawValue instanceof NodeList)) {
+ throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName());
+ }
+ nodeList = (NodeList) rawValue;
+ }
+ if (!nodeList.isEmpty()) {
+ calculatedSyntaxModelForNode(csmList.getPreceeding(), node, elements, change);
+ for (int i = 0; i < nodeList.size(); i++) {
+ if (i != 0) {
+ calculatedSyntaxModelForNode(csmList.getSeparatorPre(), node, elements, change);
+ }
+ elements.add(new CsmChild(nodeList.get(i)));
+ if (i != (nodeList.size() - 1)) {
+ calculatedSyntaxModelForNode(csmList.getSeparatorPost(), node, elements, change);
+ }
+
+ }
+ calculatedSyntaxModelForNode(csmList.getFollowing(), node, elements, change);
+ }
+ } else {
+ Collection collection = (Collection) change.getValue(csmList.getProperty(), node);
+ if (!collection.isEmpty()) {
+ calculatedSyntaxModelForNode(csmList.getPreceeding(), node, elements, change);
+
+ boolean first = true;
+ for (Iterator it = collection.iterator(); it.hasNext(); ) {
+ if (!first) {
+ calculatedSyntaxModelForNode(csmList.getSeparatorPre(), node, elements, change);
+ }
+ Object value = it.next();
+ if (value instanceof Modifier) {
+ Modifier modifier = (Modifier)value;
+ elements.add(new CsmToken(toToken(modifier)));
+ } else {
+ throw new UnsupportedOperationException(it.next().getClass().getSimpleName());
+ }
+ if (it.hasNext()) {
+ calculatedSyntaxModelForNode(csmList.getSeparatorPost(), node, elements, change);
+ }
+ first = false;
+ }
+ calculatedSyntaxModelForNode(csmList.getFollowing(), node, elements, change);
+ }
+ }
+ } else if (csm instanceof CsmConditional) {
+ CsmConditional csmConditional = (CsmConditional) csm;
+ boolean satisfied = change.evaluate(csmConditional, node);
+ if (satisfied) {
+ calculatedSyntaxModelForNode(csmConditional.getThenElement(), node, elements, change);
+ } else {
+ calculatedSyntaxModelForNode(csmConditional.getElseElement(), node, elements, change);
+ }
+ } else if (csm instanceof CsmIndent) {
+ elements.add(csm);
+ } else if (csm instanceof CsmUnindent) {
+ elements.add(csm);
+ } else if (csm instanceof CsmAttribute) {
+ CsmAttribute csmAttribute = (CsmAttribute) csm;
+ Object value = change.getValue(csmAttribute.getProperty(), node);
+ String text = value.toString();
+ if (value instanceof Printable) {
+ text = ((Printable) value).asString();
+ }
+ elements.add(new CsmToken(csmAttribute.getTokenType(node, value.toString()), text));
+ } else if ((csm instanceof CsmString) && (node instanceof StringLiteralExpr)) {
+ elements.add(new CsmToken(GeneratedJavaParserConstants.STRING_LITERAL,
+ "\"" + ((StringLiteralExpr) node).getValue() + "\""));
+ } else if (csm instanceof CsmMix) {
+ CsmMix csmMix = (CsmMix)csm;
+ List<CsmElement> mixElements = new LinkedList<>();
+ csmMix.getElements().forEach(e -> calculatedSyntaxModelForNode(e, node, mixElements, change));
+ elements.add(new CsmMix(mixElements));
+ } else {
+ throw new UnsupportedOperationException(csm.getClass().getSimpleName()+ " " + csm);
+ }
+ }
+
+ private int toToken(Modifier modifier) {
+ switch (modifier) {
+ case PUBLIC:
+ return GeneratedJavaParserConstants.PUBLIC;
+ case PRIVATE:
+ return GeneratedJavaParserConstants.PRIVATE;
+ case PROTECTED:
+ return GeneratedJavaParserConstants.PROTECTED;
+ case STATIC:
+ return GeneratedJavaParserConstants.STATIC;
+ case FINAL:
+ return GeneratedJavaParserConstants.FINAL;
+ case ABSTRACT:
+ return GeneratedJavaParserConstants.ABSTRACT;
+ default:
+ throw new UnsupportedOperationException(modifier.name());
+ }
+ }
+
+ ///
+ /// Methods that calculate CalculatedSyntaxModel
+ ///
+
+ // Visible for testing
+ CalculatedSyntaxModel calculatedSyntaxModelAfterPropertyChange(Node node, ObservableProperty property, Object oldValue, Object newValue) {
+ return calculatedSyntaxModelAfterPropertyChange(ConcreteSyntaxModel.forClass(node.getClass()), node, property, oldValue, newValue);
+ }
+
+ // Visible for testing
+ CalculatedSyntaxModel calculatedSyntaxModelAfterPropertyChange(CsmElement csm, Node node, ObservableProperty property, Object oldValue, Object newValue) {
+ List<CsmElement> elements = new LinkedList<>();
+ calculatedSyntaxModelForNode(csm, node, elements, new PropertyChange(property, oldValue, newValue));
+ return new CalculatedSyntaxModel(elements);
+ }
+
+ // Visible for testing
+ CalculatedSyntaxModel calculatedSyntaxModelAfterListRemoval(CsmElement csm, ObservableProperty observableProperty, NodeList nodeList, int index) {
+ List<CsmElement> elements = new LinkedList<>();
+ Node container = nodeList.getParentNodeForChildren();
+ calculatedSyntaxModelForNode(csm, container, elements, new ListRemovalChange(observableProperty, index));
+ return new CalculatedSyntaxModel(elements);
+ }
+
+ // Visible for testing
+ CalculatedSyntaxModel calculatedSyntaxModelAfterListAddition(CsmElement csm, ObservableProperty observableProperty, NodeList nodeList, int index, Node nodeAdded) {
+ List<CsmElement> elements = new LinkedList<>();
+ Node container = nodeList.getParentNodeForChildren();
+ calculatedSyntaxModelForNode(csm, container, elements, new ListAdditionChange(observableProperty, index, nodeAdded));
+ return new CalculatedSyntaxModel(elements);
+ }
+
+ // Visible for testing
+ CalculatedSyntaxModel calculatedSyntaxModelAfterListAddition(Node container, ObservableProperty observableProperty, int index, Node nodeAdded) {
+ CsmElement csm = ConcreteSyntaxModel.forClass(container.getClass());
+ Object rawValue = observableProperty.getRawValue(container);
+ if (!(rawValue instanceof NodeList)) {
+ throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName());
+ }
+ NodeList nodeList = (NodeList)rawValue;
+ return calculatedSyntaxModelAfterListAddition(csm, observableProperty, nodeList, index, nodeAdded);
+ }
+
+ // Visible for testing
+ CalculatedSyntaxModel calculatedSyntaxModelAfterListRemoval(Node container, ObservableProperty observableProperty, int index) {
+ CsmElement csm = ConcreteSyntaxModel.forClass(container.getClass());
+ Object rawValue = observableProperty.getRawValue(container);
+ if (!(rawValue instanceof NodeList)) {
+ throw new IllegalStateException("Expected NodeList, found " + rawValue.getClass().getCanonicalName());
+ }
+ NodeList nodeList = (NodeList)rawValue;
+ return calculatedSyntaxModelAfterListRemoval(csm, observableProperty, nodeList, index);
+ }
+
+ // Visible for testing
+ private CalculatedSyntaxModel calculatedSyntaxModelAfterListReplacement(CsmElement csm, ObservableProperty observableProperty, NodeList nodeList, int index, Node newValue) {
+ List<CsmElement> elements = new LinkedList<>();
+ Node container = nodeList.getParentNodeForChildren();
+ calculatedSyntaxModelForNode(csm, container, elements, new ListReplacementChange(observableProperty, index, newValue));
+ return new CalculatedSyntaxModel(elements);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java
new file mode 100644
index 000000000..ef647fbf0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/LexicalPreservingPrinter.java
@@ -0,0 +1,507 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.*;
+import com.github.javaparser.ast.DataKey;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.VariableDeclarator;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.nodeTypes.NodeWithVariables;
+import com.github.javaparser.ast.observer.AstObserver;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.ast.observer.PropagatingAstObserver;
+import com.github.javaparser.ast.type.PrimitiveType;
+import com.github.javaparser.ast.visitor.TreeVisitor;
+import com.github.javaparser.printer.ConcreteSyntaxModel;
+import com.github.javaparser.printer.concretesyntaxmodel.CsmElement;
+import com.github.javaparser.printer.concretesyntaxmodel.CsmMix;
+import com.github.javaparser.printer.concretesyntaxmodel.CsmToken;
+import com.github.javaparser.utils.Pair;
+import com.github.javaparser.utils.Utils;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.GeneratedJavaParserConstants.*;
+import static com.github.javaparser.TokenTypes.eolTokenKind;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static com.github.javaparser.utils.Utils.decapitalize;
+import static java.util.Comparator.*;
+
+/**
+ * A Lexical Preserving Printer is used to capture all the lexical information while parsing, update them when
+ * operating on the AST and then used them to reproduce the source code
+ * in its original formatting including the AST changes.
+ */
+public class LexicalPreservingPrinter {
+
+ /**
+ * The nodetext for a node is stored in the node's data field. This is the key to set and retrieve it.
+ */
+ public static final DataKey<NodeText> NODE_TEXT_DATA = new DataKey<NodeText>() {
+ };
+
+ //
+ // Factory methods
+ //
+
+ /**
+ * Parse the code and setup the LexicalPreservingPrinter.
+ *
+ * @deprecated use setup(Node) and the static methods on this class.
+ */
+ public static <N extends Node> Pair<ParseResult<N>, LexicalPreservingPrinter> setup(ParseStart<N> parseStart,
+ Provider provider) {
+ ParseResult<N> parseResult = new JavaParser().parse(parseStart, provider);
+ if (!parseResult.isSuccessful()) {
+ throw new RuntimeException("Parsing failed, unable to setup the lexical preservation printer: "
+ + parseResult.getProblems());
+ }
+ LexicalPreservingPrinter lexicalPreservingPrinter = new LexicalPreservingPrinter(parseResult.getResult().get());
+ return new Pair<>(parseResult, lexicalPreservingPrinter);
+ }
+
+ /**
+ * Prepares the node so it can be used in the print methods.
+ * The correct order is:
+ * <ol>
+ * <li>Parse some code</li>
+ * <li>Call this setup method on the result</li>
+ * <li>Make changes to the AST as desired</li>
+ * <li>Use one of the print methods on this class to print out the original source code with your changes added</li>
+ * </ol>
+ *
+ * @return the node passed as a parameter for your convenience.
+ */
+ public static <N extends Node> N setup(N node) {
+ assertNotNull(node);
+
+ node.getTokenRange().ifPresent(r -> {
+ storeInitialText(node);
+
+ // Setup observer
+ AstObserver observer = createObserver();
+
+ node.registerForSubtree(observer);
+ });
+ return node;
+ }
+
+ //
+ // Constructor and setup
+ //
+
+ /**
+ * @deprecated use setup(Node) to prepare a node for lexical preservation,
+ * then use the static methods on this class to print it.
+ */
+ @Deprecated
+ public LexicalPreservingPrinter(Node node) {
+ setup(node);
+ }
+
+ private static AstObserver createObserver() {
+ return new PropagatingAstObserver() {
+ @Override
+ public void concretePropertyChange(Node observedNode, ObservableProperty property, Object oldValue, Object newValue) {
+ // Not really a change, ignoring
+ if ((oldValue != null && oldValue.equals(newValue)) || (oldValue == null && newValue == null)) {
+ return;
+ }
+ if (property == ObservableProperty.RANGE || property == ObservableProperty.COMMENTED_NODE) {
+ return;
+ }
+ if (property == ObservableProperty.COMMENT) {
+ if (!observedNode.getParentNode().isPresent()) {
+ throw new IllegalStateException();
+ }
+ NodeText nodeText = getOrCreateNodeText(observedNode.getParentNode().get());
+ if (oldValue == null) {
+ // Find the position of the comment node and put in front of it the comment and a newline
+ int index = nodeText.findChild(observedNode);
+ nodeText.addChild(index, (Comment) newValue);
+ nodeText.addToken(index + 1, eolTokenKind(), Utils.EOL);
+ } else if (newValue == null) {
+ if (oldValue instanceof JavadocComment) {
+ JavadocComment javadocComment = (JavadocComment) oldValue;
+ List<TokenTextElement> matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(JAVADOC_COMMENT)
+ && ((TokenTextElement) e).getText().equals("/**" + javadocComment.getContent() + "*/")).map(e -> (TokenTextElement) e).collect(Collectors.toList());
+ if (matchingTokens.size() != 1) {
+ throw new IllegalStateException();
+ }
+ int index = nodeText.findElement(matchingTokens.get(0));
+ nodeText.removeElement(index);
+ if (nodeText.getElements().get(index).isNewline()) {
+ nodeText.removeElement(index);
+ }
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ } else {
+ if (oldValue instanceof JavadocComment) {
+ JavadocComment oldJavadocComment = (JavadocComment) oldValue;
+ List<TokenTextElement> matchingTokens = nodeText.getElements().stream().filter(e -> e.isToken(JAVADOC_COMMENT)
+ && ((TokenTextElement) e).getText().equals("/**" + oldJavadocComment.getContent() + "*/")).map(e -> (TokenTextElement) e).collect(Collectors.toList());
+ if (matchingTokens.size() != 1) {
+ throw new IllegalStateException();
+ }
+ JavadocComment newJavadocComment = (JavadocComment) newValue;
+ nodeText.replace(matchingTokens.get(0), new TokenTextElement(JAVADOC_COMMENT, "/**" + newJavadocComment.getContent() + "*/"));
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+ }
+ NodeText nodeText = getOrCreateNodeText(observedNode);
+
+ if (nodeText == null) {
+ throw new NullPointerException(observedNode.getClass().getSimpleName());
+ }
+
+ new LexicalDifferenceCalculator().calculatePropertyChange(nodeText, observedNode, property, oldValue, newValue);
+ }
+
+ @Override
+ public void concreteListChange(NodeList changedList, ListChangeType type, int index, Node nodeAddedOrRemoved) {
+ NodeText nodeText = getOrCreateNodeText(changedList.getParentNodeForChildren());
+ if (type == ListChangeType.REMOVAL) {
+ new LexicalDifferenceCalculator().calculateListRemovalDifference(findNodeListName(changedList), changedList, index).apply(nodeText, changedList.getParentNodeForChildren());
+ } else if (type == ListChangeType.ADDITION) {
+ new LexicalDifferenceCalculator().calculateListAdditionDifference(findNodeListName(changedList), changedList, index, nodeAddedOrRemoved).apply(nodeText, changedList.getParentNodeForChildren());
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ @Override
+ public void concreteListReplacement(NodeList changedList, int index, Node oldValue, Node newValue) {
+ NodeText nodeText = getOrCreateNodeText(changedList.getParentNodeForChildren());
+ new LexicalDifferenceCalculator().calculateListReplacementDifference(findNodeListName(changedList), changedList, index, newValue).apply(nodeText, changedList.getParentNodeForChildren());
+ }
+ };
+ }
+
+ private static void storeInitialText(Node root) {
+ Map<Node, List<JavaToken>> tokensByNode = new IdentityHashMap<>();
+
+ // We go over tokens and find to which nodes they belong. Note that we do not traverse the tokens as they were
+ // on a list but as they were organized in a tree. At each time we select only the branch corresponding to the
+ // range of interest and ignore all other branches
+ for (JavaToken token : root.getTokenRange().get()) {
+ Range tokenRange = token.getRange().orElseThrow(() -> new RuntimeException("Token without range: " + token));
+ Node owner = findNodeForToken(root, tokenRange);
+ if (owner == null) {
+ throw new RuntimeException("Token without node owning it: " + token);
+ }
+ if (!tokensByNode.containsKey(owner)) {
+ tokensByNode.put(owner, new LinkedList<>());
+ }
+ tokensByNode.get(owner).add(token);
+ }
+
+ // Now that we know the tokens we use them to create the initial NodeText for each node
+ new TreeVisitor() {
+ @Override
+ public void process(Node node) {
+ if (!PhantomNodeLogic.isPhantomNode(node)) {
+ LexicalPreservingPrinter.storeInitialTextForOneNode(node, tokensByNode.get(node));
+ }
+ }
+ }.visitBreadthFirst(root);
+ }
+
+ private static Node findNodeForToken(Node node, Range tokenRange) {
+ if (PhantomNodeLogic.isPhantomNode(node)) {
+ return null;
+ }
+ if (node.getRange().get().contains(tokenRange)) {
+ for (Node child : node.getChildNodes()) {
+ Node found = findNodeForToken(child, tokenRange);
+ if (found != null) {
+ return found;
+ }
+ }
+ return node;
+ } else {
+ return null;
+ }
+ }
+
+ private static void storeInitialTextForOneNode(Node node, List<JavaToken> nodeTokens) {
+ if (nodeTokens == null) {
+ nodeTokens = Collections.emptyList();
+ }
+ List<Pair<Range, TextElement>> elements = new LinkedList<>();
+ for (Node child : node.getChildNodes()) {
+ if (!PhantomNodeLogic.isPhantomNode(child)) {
+ if (!child.getRange().isPresent()) {
+ throw new RuntimeException("Range not present on node " + child);
+ }
+ elements.add(new Pair<>(child.getRange().get(), new ChildTextElement(child)));
+ }
+ }
+ for (JavaToken token : nodeTokens) {
+ elements.add(new Pair<>(token.getRange().get(), new TokenTextElement(token)));
+ }
+ elements.sort(comparing(e -> e.a.begin));
+ node.setData(NODE_TEXT_DATA, new NodeText(elements.stream().map(p -> p.b).collect(Collectors.toList())));
+ }
+
+ //
+ // Iterators
+ //
+
+ private static Iterator<TokenTextElement> tokensPreceeding(final Node node) {
+ if (!node.getParentNode().isPresent()) {
+ return new TextElementIteratorsFactory.EmptyIterator<>();
+ }
+ // There is the awfully painful case of the fake types involved in variable declarators and
+ // fields or variable declaration that are, of course, an exception...
+
+ NodeText parentNodeText = getOrCreateNodeText(node.getParentNode().get());
+ int index = parentNodeText.tryToFindChild(node);
+ if (index == NodeText.NOT_FOUND) {
+ if (node.getParentNode().get() instanceof VariableDeclarator) {
+ return tokensPreceeding(node.getParentNode().get());
+ } else {
+ throw new IllegalArgumentException(
+ String.format("I could not find child '%s' in parent '%s'. parentNodeText: %s",
+ node, node.getParentNode().get(), parentNodeText));
+ }
+ }
+
+ return new TextElementIteratorsFactory.CascadingIterator<>(
+ TextElementIteratorsFactory.partialReverseIterator(parentNodeText, index - 1),
+ () -> tokensPreceeding(node.getParentNode().get()));
+ }
+
+ //
+ // Printing methods
+ //
+
+ /**
+ * Print a Node into a String, preserving the lexical information.
+ */
+ public static String print(Node node) {
+ StringWriter writer = new StringWriter();
+ try {
+ print(node, writer);
+ } catch (IOException e) {
+ throw new RuntimeException("Unexpected IOException on a StringWriter", e);
+ }
+ return writer.toString();
+ }
+
+ /**
+ * Print a Node into a Writer, preserving the lexical information.
+ */
+ public static void print(Node node, Writer writer) throws IOException {
+ if (!node.containsData(NODE_TEXT_DATA)) {
+ getOrCreateNodeText(node);
+ }
+ final NodeText text = node.getData(NODE_TEXT_DATA);
+ writer.append(text.expand());
+ }
+
+ //
+ // Methods to handle transformations
+ //
+
+ private static void prettyPrintingTextNode(Node node, NodeText nodeText) {
+ if (node instanceof PrimitiveType) {
+ PrimitiveType primitiveType = (PrimitiveType) node;
+ switch (primitiveType.getType()) {
+ case BOOLEAN:
+ nodeText.addToken(BOOLEAN, node.toString());
+ break;
+ case CHAR:
+ nodeText.addToken(CHAR, node.toString());
+ break;
+ case BYTE:
+ nodeText.addToken(BYTE, node.toString());
+ break;
+ case SHORT:
+ nodeText.addToken(SHORT, node.toString());
+ break;
+ case INT:
+ nodeText.addToken(INT, node.toString());
+ break;
+ case LONG:
+ nodeText.addToken(LONG, node.toString());
+ break;
+ case FLOAT:
+ nodeText.addToken(FLOAT, node.toString());
+ break;
+ case DOUBLE:
+ nodeText.addToken(DOUBLE, node.toString());
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+ return;
+ }
+ if (node instanceof JavadocComment) {
+ nodeText.addToken(JAVADOC_COMMENT, "/**" + ((JavadocComment) node).getContent() + "*/");
+ return;
+ }
+
+ interpret(node, ConcreteSyntaxModel.forClass(node.getClass()), nodeText);
+ }
+
+ private static NodeText interpret(Node node, CsmElement csm, NodeText nodeText) {
+ LexicalDifferenceCalculator.CalculatedSyntaxModel calculatedSyntaxModel = new LexicalDifferenceCalculator().calculatedSyntaxModelForNode(csm, node);
+
+ List<TokenTextElement> indentation = findIndentation(node);
+
+ boolean pendingIndentation = false;
+ for (CsmElement element : calculatedSyntaxModel.elements) {
+ if (pendingIndentation && !(element instanceof CsmToken && ((CsmToken) element).isNewLine())) {
+ indentation.forEach(nodeText::addElement);
+ }
+ pendingIndentation = false;
+ if (element instanceof LexicalDifferenceCalculator.CsmChild) {
+ nodeText.addChild(((LexicalDifferenceCalculator.CsmChild) element).getChild());
+ } else if (element instanceof CsmToken) {
+ CsmToken csmToken = (CsmToken) element;
+ nodeText.addToken(csmToken.getTokenType(), csmToken.getContent(node));
+ if (csmToken.isNewLine()) {
+ pendingIndentation = true;
+ }
+ } else if (element instanceof CsmMix) {
+ CsmMix csmMix = (CsmMix) element;
+ csmMix.getElements().forEach(e -> interpret(node, e, nodeText));
+ } else {
+ throw new UnsupportedOperationException(element.getClass().getSimpleName());
+ }
+ }
+ // Array brackets are a pain... we do not have a way to represent them explicitly in the AST
+ // so they have to be handled in a special way
+ if (node instanceof VariableDeclarator) {
+ VariableDeclarator variableDeclarator = (VariableDeclarator) node;
+ variableDeclarator.getParentNode().ifPresent(parent ->
+ ((NodeWithVariables<?>) parent).getMaximumCommonType().ifPresent(mct -> {
+ int extraArrayLevels = variableDeclarator.getType().getArrayLevel() - mct.getArrayLevel();
+ for (int i = 0; i < extraArrayLevels; i++) {
+ nodeText.addElement(new TokenTextElement(LBRACKET));
+ nodeText.addElement(new TokenTextElement(RBRACKET));
+ }
+ })
+ );
+ }
+ return nodeText;
+ }
+
+ // Visible for testing
+ static NodeText getOrCreateNodeText(Node node) {
+ if (!node.containsData(NODE_TEXT_DATA)) {
+ NodeText nodeText = new NodeText();
+ node.setData(NODE_TEXT_DATA, nodeText);
+ prettyPrintingTextNode(node, nodeText);
+ }
+ return node.getData(NODE_TEXT_DATA);
+ }
+
+ // Visible for testing
+ static List<TokenTextElement> findIndentation(Node node) {
+ List<TokenTextElement> followingNewlines = new LinkedList<>();
+ Iterator<TokenTextElement> it = tokensPreceeding(node);
+ while (it.hasNext()) {
+ TokenTextElement tte = it.next();
+ if (tte.getTokenKind() == SINGLE_LINE_COMMENT
+ || tte.isNewline()) {
+ break;
+ } else {
+ followingNewlines.add(tte);
+ }
+ }
+ Collections.reverse(followingNewlines);
+ for (int i = 0; i < followingNewlines.size(); i++) {
+ if (!followingNewlines.get(i).isSpaceOrTab()) {
+ return followingNewlines.subList(0, i);
+ }
+ }
+ return followingNewlines;
+ }
+
+ //
+ // Helper methods
+ //
+
+ private static boolean isReturningOptionalNodeList(Method m) {
+ if (!m.getReturnType().getCanonicalName().equals(Optional.class.getCanonicalName())) {
+ return false;
+ }
+ if (!(m.getGenericReturnType() instanceof ParameterizedType)) {
+ return false;
+ }
+ ParameterizedType parameterizedType = (ParameterizedType) m.getGenericReturnType();
+ java.lang.reflect.Type optionalArgument = parameterizedType.getActualTypeArguments()[0];
+ return (optionalArgument.getTypeName().startsWith(NodeList.class.getCanonicalName()));
+ }
+
+ private static ObservableProperty findNodeListName(NodeList nodeList) {
+ Node parent = nodeList.getParentNodeForChildren();
+ for (Method m : parent.getClass().getMethods()) {
+ if (m.getParameterCount() == 0 && m.getReturnType().getCanonicalName().equals(NodeList.class.getCanonicalName())) {
+ try {
+ Object raw = m.invoke(parent);
+ if (!(raw instanceof NodeList)) {
+ throw new IllegalStateException("Expected NodeList, found " + raw.getClass().getCanonicalName());
+ }
+ NodeList result = (NodeList) raw;
+ if (result == nodeList) {
+ String name = m.getName();
+ if (name.startsWith("get")) {
+ name = name.substring("get".length());
+ }
+ return ObservableProperty.fromCamelCaseName(decapitalize(name));
+ }
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ } else if (m.getParameterCount() == 0 && isReturningOptionalNodeList(m)) {
+ try {
+ Optional<NodeList<?>> raw = (Optional<NodeList<?>>) m.invoke(parent);
+ if (raw.isPresent() && raw.get() == nodeList) {
+ String name = m.getName();
+ if (name.startsWith("get")) {
+ name = name.substring("get".length());
+ }
+ return ObservableProperty.fromCamelCaseName(decapitalize(name));
+ }
+ } catch (IllegalAccessException | InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ throw new IllegalArgumentException("Cannot find list name of NodeList of size " + nodeList.size());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java
new file mode 100644
index 000000000..1be264e88
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/NodeText.java
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.ast.Node;
+
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * This contains the lexical information for a single node.
+ * It is basically a list of tokens and children.
+ */
+class NodeText {
+ private final List<TextElement> elements;
+
+ public static final int NOT_FOUND = -1;
+
+ enum Option {
+ REMOVE_SPACE_IMMEDIATELY_AFTER,
+ EXCLUDE_START,
+ EXCLUDE_END
+ }
+
+ //
+ // Constructors
+ //
+
+ NodeText(List<TextElement> elements) {
+ this.elements = elements;
+ }
+
+ /**
+ * Initialize with an empty list of elements.
+ */
+ NodeText() {
+ this(new LinkedList<>());
+ }
+
+ //
+ // Adding elements
+ //
+
+ /**
+ * Add an element at the end.
+ */
+ void addElement(TextElement nodeTextElement) {
+ this.elements.add(nodeTextElement);
+ }
+
+ /**
+ * Add an element at the given position.
+ */
+ void addElement(int index, TextElement nodeTextElement) {
+ this.elements.add(index, nodeTextElement);
+ }
+
+ void addChild(Node child) {
+ addElement(new ChildTextElement(child));
+ }
+
+ void addChild(int index, Node child) {
+ addElement(index, new ChildTextElement(child));
+ }
+
+ void addToken(int tokenKind, String text) {
+ elements.add(new TokenTextElement(tokenKind, text));
+ }
+
+ void addToken(int index, int tokenKind, String text) {
+ elements.add(index, new TokenTextElement(tokenKind, text));
+ }
+
+ //
+ // Finding elements
+ //
+
+ int findElement(TextElementMatcher matcher) {
+ return findElement(matcher, 0);
+ }
+
+ int findElement(TextElementMatcher matcher, int from) {
+ int res = tryToFindElement(matcher, from);
+ if (res == NOT_FOUND) {
+ throw new IllegalArgumentException(
+ String.format("I could not find child '%s' from position %d. Elements: %s",
+ matcher, from, elements));
+ } else {
+ return res;
+ }
+ }
+
+ int tryToFindElement(TextElementMatcher matcher, int from) {
+ for (int i=from; i<elements.size(); i++) {
+ TextElement element = elements.get(i);
+ if (matcher.match(element)) {
+ return i;
+ }
+ }
+ return NOT_FOUND;
+ }
+
+ int findChild(Node child) {
+ return findChild(child, 0);
+ }
+
+ int findChild(Node child, int from) {
+ return findElement(TextElementMatchers.byNode(child), from);
+ }
+
+ int tryToFindChild(Node child) {
+ return tryToFindChild(child, 0);
+ }
+
+ int tryToFindChild(Node child, int from) {
+ return tryToFindElement(TextElementMatchers.byNode(child), from);
+ }
+
+ //
+ // Removing single elements
+ //
+
+ void remove(TextElementMatcher matcher) {
+ elements.removeIf(matcher::match);
+ }
+
+ public void remove(TextElementMatcher matcher, boolean potentiallyFollowingWhitespace) {
+ int i=0;
+ for (TextElement e : elements) {
+ if (matcher.match(e)) {
+ elements.remove(e);
+ if (potentiallyFollowingWhitespace) {
+ if (i < elements.size()) {
+ if (elements.get(i).isWhiteSpace()) {
+ elements.remove(i);
+ }
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+ return;
+ }
+ }
+ throw new IllegalArgumentException();
+ }
+
+ //
+ // Removing sequences
+ //
+
+ void removeElement(int index) {
+ elements.remove(index);
+ }
+
+ //
+ // Replacing elements
+ //
+
+ void replace(TextElementMatcher position, TextElement newElement) {
+ int index = findElement(position, 0);
+ elements.remove(index);
+ elements.add(index, newElement);
+ }
+
+ //
+ // Other methods
+ //
+
+ /**
+ * Generate the corresponding string.
+ */
+ String expand() {
+ StringBuffer sb = new StringBuffer();
+
+ elements.forEach(e -> sb.append(e.expand()));
+ return sb.toString();
+ }
+
+ // Visible for testing
+ int numberOfElements() {
+ return elements.size();
+ }
+
+ // Visible for testing
+ TextElement getTextElement(int index) {
+ return elements.get(index);
+ }
+
+ // Visible for testing
+ List<TextElement> getElements() {
+ return elements;
+ }
+
+ @Override
+ public String toString() {
+ return "NodeText{" + elements + '}';
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java
new file mode 100644
index 000000000..d17f76835
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/PhantomNodeLogic.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.AstObserver;
+import com.github.javaparser.ast.observer.AstObserverAdapter;
+import com.github.javaparser.ast.type.UnknownType;
+
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+import static java.util.Collections.synchronizedMap;
+
+/**
+ * We want to recognize and ignore "phantom" nodes, like the fake type of variable in FieldDeclaration
+ */
+class PhantomNodeLogic {
+
+ private static final int LEVELS_TO_EXPLORE = 3;
+
+ private static final Map<Node, Boolean> isPhantomNodeCache = synchronizedMap(new IdentityHashMap<>());
+
+ private static final AstObserver cacheCleaner = new AstObserverAdapter() {
+ @Override
+ public void parentChange(Node observedNode, Node previousParent, Node newParent) {
+ isPhantomNodeCache.remove(observedNode);
+ }
+ };
+
+ static boolean isPhantomNode(Node node) {
+ if (isPhantomNodeCache.containsKey(node)) {
+ return isPhantomNodeCache.get(node);
+ } else {
+ if (node instanceof UnknownType) {
+ return true;
+ }
+ boolean res = (node.getParentNode().isPresent() &&
+ !node.getParentNode().get().getRange().get().contains(node.getRange().get())
+ || inPhantomNode(node, LEVELS_TO_EXPLORE));
+ isPhantomNodeCache.put(node, res);
+ node.register(cacheCleaner);
+ return res;
+ }
+ }
+
+ /**
+ * A node contained in a phantom node is also a phantom node. We limit how many levels up we check just for performance reasons.
+ */
+ private static boolean inPhantomNode(Node node, int levels) {
+ return node.getParentNode().isPresent() &&
+ (isPhantomNode(node.getParentNode().get())
+ || inPhantomNode(node.getParentNode().get(), levels - 1));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java
new file mode 100644
index 000000000..987b8f228
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElement.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.GeneratedJavaParserConstants;
+import com.github.javaparser.ast.Node;
+
+public abstract class TextElement implements TextElementMatcher {
+
+ abstract String expand();
+
+ abstract boolean isToken(int tokenKind);
+
+ final boolean isCommentToken() {
+ return isToken(GeneratedJavaParserConstants.JAVADOC_COMMENT)
+ || isToken(GeneratedJavaParserConstants.SINGLE_LINE_COMMENT)
+ || isToken(GeneratedJavaParserConstants.MULTI_LINE_COMMENT);
+ }
+
+ @Override
+ public boolean match(TextElement textElement) {
+ return this.equals(textElement);
+ }
+
+ abstract boolean isNode(Node node);
+
+ public abstract boolean isWhiteSpace();
+
+ public abstract boolean isSpaceOrTab();
+
+ public abstract boolean isNewline();
+
+ public abstract boolean isComment();
+
+ public final boolean isWhiteSpaceOrComment() {
+ return isWhiteSpace() || isComment();
+ }
+
+ /**
+ * Is this TextElement representing a child of the given class?
+ */
+ public abstract boolean isChildOfClass(Class<? extends Node> nodeClass);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java
new file mode 100644
index 000000000..b2e29b41b
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementIteratorsFactory.java
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+class TextElementIteratorsFactory {
+
+ static class CascadingIterator<E> implements Iterator<E> {
+ interface Provider<E> {
+ Iterator<E> provide();
+ }
+
+ private final Provider<E> nextProvider;
+ private Iterator<E> current;
+ private Iterator<E> next;
+ private boolean lastReturnedFromCurrent = false;
+ private boolean lastReturnedFromNext = false;
+
+ public CascadingIterator(Iterator<E> current, Provider<E> nextProvider) {
+ this.nextProvider = nextProvider;
+ this.current = current;
+ }
+
+
+ @Override
+ public boolean hasNext() {
+ if (current.hasNext()) {
+ return true;
+ }
+ if (next == null) {
+ next = nextProvider.provide();
+ }
+ return next.hasNext();
+ }
+
+ @Override
+ public E next() {
+ if (current.hasNext()) {
+ lastReturnedFromCurrent = true;
+ lastReturnedFromNext = false;
+ return current.next();
+ }
+ if (next == null) {
+ next = nextProvider.provide();
+ }
+ lastReturnedFromCurrent = false;
+ lastReturnedFromNext = true;
+ return next.next();
+ }
+
+ @Override
+ public void remove() {
+ if (lastReturnedFromCurrent) {
+ current.remove();
+ return;
+ }
+ if (lastReturnedFromNext) {
+ next.remove();
+ return;
+ }
+ throw new IllegalArgumentException();
+ }
+ }
+
+ static class EmptyIterator<E> implements Iterator<E> {
+ @Override
+ public boolean hasNext() {
+ return false;
+ }
+
+ @Override
+ public E next() {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ private static class SingleElementIterator<E> implements Iterator<E> {
+ private final E element;
+ private boolean returned;
+
+ SingleElementIterator(E element) {
+ this.element = element;
+ }
+
+ @Override
+ public boolean hasNext() {
+ return !returned;
+ }
+
+ @Override
+ public E next() {
+ returned = true;
+ return element;
+ }
+
+ @Override
+ public void remove() {
+
+ }
+ }
+
+ static class ComposedIterator<E> implements Iterator<E> {
+ private final List<Iterator<E>> elements;
+ private int currIndex;
+
+ ComposedIterator(List<Iterator<E>> elements) {
+ this.elements = elements;
+ currIndex = 0;
+ }
+
+ @Override
+ public boolean hasNext() {
+ if (currIndex >= elements.size()) {
+ return false;
+ }
+ if (elements.get(currIndex).hasNext()){
+ return true;
+ }
+ currIndex++;
+ return hasNext();
+ }
+
+ @Override
+ public E next() {
+ if (!hasNext()) {
+ throw new IllegalArgumentException();
+ }
+ return elements.get(currIndex).next();
+ }
+
+ @Override
+ public void remove() {
+ elements.get(currIndex).remove();
+ }
+ }
+
+ private static Iterator<TokenTextElement> reverseIterator(NodeText nodeText, int index) {
+ TextElement textElement = nodeText.getTextElement(index);
+ if (textElement instanceof TokenTextElement) {
+ return new SingleElementIterator<TokenTextElement>((TokenTextElement)textElement) {
+ @Override
+ public void remove() {
+ nodeText.removeElement(index);
+ }
+ };
+ } else if (textElement instanceof ChildTextElement) {
+ ChildTextElement childTextElement = (ChildTextElement)textElement;
+ NodeText textForChild = childTextElement.getNodeTextForWrappedNode();
+ return reverseIterator(textForChild);
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public static Iterator<TokenTextElement> reverseIterator(NodeText nodeText) {
+ return partialReverseIterator(nodeText, nodeText.numberOfElements() - 1);
+ }
+
+ public static Iterator<TokenTextElement> partialReverseIterator(NodeText nodeText, int fromIndex) {
+ List<Iterator<TokenTextElement>> elements = new LinkedList<>();
+ for (int i=fromIndex;i>=0;i--) {
+ elements.add(reverseIterator(nodeText, i));
+ }
+ return new ComposedIterator<>(elements);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java
new file mode 100644
index 000000000..e52200849
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatcher.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+public interface TextElementMatcher {
+
+ boolean match(TextElement textElement);
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java
new file mode 100644
index 000000000..f3e95b754
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TextElementMatchers.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.ast.Node;
+
+class TextElementMatchers {
+
+ static TextElementMatcher byTokenType(int tokenType) {
+ return textElement -> textElement.isToken(tokenType);
+ }
+
+ static TextElementMatcher byNode(final Node node) {
+ return new TextElementMatcher() {
+ @Override
+ public boolean match(TextElement textElement) {
+ return textElement.isNode(node);
+ }
+
+ @Override
+ public String toString() {
+ return "match node " + node;
+ }
+ };
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java
new file mode 100644
index 000000000..e57b214ab
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.printer.lexicalpreservation;
+
+import com.github.javaparser.JavaToken;
+import com.github.javaparser.TokenTypes;
+import com.github.javaparser.ast.Node;
+
+class TokenTextElement extends TextElement {
+ private final JavaToken token;
+
+ TokenTextElement(JavaToken token) {
+ this.token = token;
+ }
+
+ TokenTextElement(int tokenKind, String text) {
+ this(new JavaToken(tokenKind, text));
+ }
+
+ TokenTextElement(int tokenKind) {
+ this(new JavaToken(tokenKind));
+ }
+
+ @Override
+ String expand() {
+ return token.getText();
+ }
+
+ // Visible for testing
+ String getText() {
+ return token.getText();
+ }
+
+ public int getTokenKind() {
+ return token.getKind();
+ }
+
+ public JavaToken getToken() {
+ return token;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ TokenTextElement that = (TokenTextElement) o;
+
+ return token.equals(that.token);
+ }
+
+ @Override
+ public int hashCode() {
+ return token.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return token.toString();
+ }
+
+ @Override
+ boolean isToken(int tokenKind) {
+ return token.getKind() == tokenKind;
+ }
+
+ @Override
+ boolean isNode(Node node) {
+ return false;
+ }
+
+ @Override
+ public boolean isWhiteSpace() {
+ return token.getCategory().isWhitespace();
+ }
+
+ @Override
+ public boolean isSpaceOrTab() {
+ return token.getCategory().isWhitespaceButNotEndOfLine();
+ }
+
+ @Override
+ public boolean isComment() {
+ return token.getCategory().isComment();
+ }
+
+ @Override
+ public boolean isNewline() {
+ return token.getCategory().isEndOfLine();
+ }
+
+ @Override
+ public boolean isChildOfClass(Class<? extends Node> nodeClass) {
+ return false;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java
new file mode 100644
index 000000000..23fe09dce
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/Change.java
@@ -0,0 +1,29 @@
+package com.github.javaparser.printer.lexicalpreservation.changes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.printer.concretesyntaxmodel.CsmConditional;
+import com.github.javaparser.utils.Utils;
+
+/**
+ * This represent a change happened to a specific Node.
+ */
+public interface Change {
+
+ default boolean evaluate(CsmConditional csmConditional, Node node) {
+ switch (csmConditional.getCondition()) {
+ case FLAG:
+ return (Boolean) getValue(csmConditional.getProperty(), node);
+ case IS_NOT_EMPTY:
+ return !Utils.valueIsNullOrEmpty(getValue(csmConditional.getProperty(), node));
+ case IS_EMPTY:
+ return Utils.valueIsNullOrEmpty(getValue(csmConditional.getProperty(), node));
+ case IS_PRESENT:
+ return !Utils.valueIsNullOrEmpty(getValue(csmConditional.getProperty(), node));
+ default:
+ throw new UnsupportedOperationException("" + csmConditional.getProperty() + " " + csmConditional.getCondition());
+ }
+ }
+
+ Object getValue(ObservableProperty property, Node node);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java
new file mode 100644
index 000000000..ab15cc52f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListAdditionChange.java
@@ -0,0 +1,37 @@
+package com.github.javaparser.printer.lexicalpreservation.changes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.observer.ObservableProperty;
+
+/**
+ * The Addition of an element to a list.
+ */
+public class ListAdditionChange implements Change {
+ private final ObservableProperty observableProperty;
+ private final int index;
+ private final Node nodeAdded;
+
+ public ListAdditionChange(ObservableProperty observableProperty, int index, Node nodeAdded) {
+ this.observableProperty = observableProperty;
+ this.index = index;
+ this.nodeAdded = nodeAdded;
+ }
+
+ @Override
+ public Object getValue(ObservableProperty property, Node node) {
+ if (property == observableProperty) {
+ NodeList<Node> nodeList = new NodeList<>();
+ Object currentRawValue = new NoChange().getValue(property, node);
+ if (!(currentRawValue instanceof NodeList)){
+ throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName());
+ }
+ NodeList<?> currentNodeList = (NodeList<?>)(currentRawValue);
+ nodeList.addAll(currentNodeList);
+ nodeList.add(index, nodeAdded);
+ return nodeList;
+ } else {
+ return new NoChange().getValue(property, node);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java
new file mode 100644
index 000000000..c99efd265
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListRemovalChange.java
@@ -0,0 +1,35 @@
+package com.github.javaparser.printer.lexicalpreservation.changes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.observer.ObservableProperty;
+
+/**
+ * The removal of an element in a list.
+ */
+public class ListRemovalChange implements Change {
+ private final ObservableProperty observableProperty;
+ private final int index;
+
+ public ListRemovalChange(ObservableProperty observableProperty, int index) {
+ this.observableProperty = observableProperty;
+ this.index = index;
+ }
+
+ @Override
+ public Object getValue(ObservableProperty property, Node node) {
+ if (property == observableProperty) {
+ NodeList<Node> nodeList = new NodeList<>();
+ Object currentRawValue = new NoChange().getValue(property, node);
+ if (!(currentRawValue instanceof NodeList)){
+ throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName());
+ }
+ NodeList<?> currentNodeList = (NodeList<?>)currentRawValue;
+ nodeList.addAll(currentNodeList);
+ nodeList.remove(index);
+ return nodeList;
+ } else {
+ return new NoChange().getValue(property, node);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java
new file mode 100644
index 000000000..ccb0eada5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/ListReplacementChange.java
@@ -0,0 +1,44 @@
+package com.github.javaparser.printer.lexicalpreservation.changes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.observer.ObservableProperty;
+import com.github.javaparser.utils.Pair;
+
+import java.util.Optional;
+
+/**
+ * The replacement of an element in a list.
+ */
+public class ListReplacementChange implements Change {
+ private final ObservableProperty observableProperty;
+ private final int index;
+ private final Node newValue;
+
+ public ListReplacementChange(ObservableProperty observableProperty, int index, Node newValue) {
+ this.observableProperty = observableProperty;
+ this.index = index;
+ this.newValue = newValue;
+ }
+
+ @Override
+ public Object getValue(ObservableProperty property, Node node) {
+ if (property == observableProperty) {
+ NodeList nodeList = new NodeList();
+ Object currentRawValue = new NoChange().getValue(property, node);
+ if (currentRawValue instanceof Optional) {
+ Optional optional = (Optional)currentRawValue;
+ currentRawValue = optional.orElseGet(null);
+ }
+ if (!(currentRawValue instanceof NodeList)){
+ throw new IllegalStateException("Expected NodeList, found " + currentRawValue.getClass().getCanonicalName());
+ }
+ NodeList currentNodeList = (NodeList)currentRawValue;
+ nodeList.addAll(currentNodeList);
+ nodeList.set(index, newValue);
+ return nodeList;
+ } else {
+ return new NoChange().getValue(property, node);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java
new file mode 100644
index 000000000..6b29e3eb5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/NoChange.java
@@ -0,0 +1,15 @@
+package com.github.javaparser.printer.lexicalpreservation.changes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+
+/**
+ * No change. The Node is not mutated.
+ */
+public class NoChange implements Change {
+
+ @Override
+ public Object getValue(ObservableProperty property, Node node) {
+ return property.getRawValue(node);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java
new file mode 100644
index 000000000..37b3a6f93
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/printer/lexicalpreservation/changes/PropertyChange.java
@@ -0,0 +1,40 @@
+package com.github.javaparser.printer.lexicalpreservation.changes;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.observer.ObservableProperty;
+
+/**
+ * The change in value of a property.
+ */
+public class PropertyChange implements Change {
+ private final ObservableProperty property;
+ private final Object oldValue;
+ private final Object newValue;
+
+ public ObservableProperty getProperty() {
+ return property;
+ }
+
+ public Object getOldValue() {
+ return oldValue;
+ }
+
+ public Object getNewValue() {
+ return newValue;
+ }
+
+ public PropertyChange(ObservableProperty property, Object oldValue, Object newValue) {
+ this.property = property;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ @Override
+ public Object getValue(ObservableProperty property, Node node) {
+ if (property == this.property) {
+ return newValue;
+ } else {
+ return property.getRawValue(node);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java
new file mode 100644
index 000000000..76632c5ab
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodAmbiguityException.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution;
+
+/**
+ * It is not possible to decide how to resolve a method invocation.
+ *
+ * @author Federico Tomassetti
+ */
+public class MethodAmbiguityException extends RuntimeException {
+
+ /**
+ * Create an instance from a description of the reason why there is ambiguity in this particular case.
+ */
+ public MethodAmbiguityException(String description) {
+ super(description);
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java
new file mode 100644
index 000000000..ec3a06bbe
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/MethodUsage.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution;
+
+import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+import com.github.javaparser.resolution.types.ResolvedType;
+import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap;
+import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized;
+
+
+import java.util.*;
+
+/**
+ * This is basically a MethodDeclaration with some TypeParameters defined.
+ * The defined TypeParameters can comes from the Method itself or from the surrounding types.
+ *
+ * @author Federico Tomassetti
+ */
+public class MethodUsage implements ResolvedTypeParametrized {
+ private ResolvedMethodDeclaration declaration;
+ private List<ResolvedType> paramTypes = new ArrayList<>();
+ private List<ResolvedType> exceptionTypes = new ArrayList<>();
+ private ResolvedType returnType;
+ private ResolvedTypeParametersMap typeParametersMap;
+
+ public MethodUsage(ResolvedMethodDeclaration declaration) {
+ this.typeParametersMap = ResolvedTypeParametersMap.empty();
+ this.declaration = declaration;
+ for (int i = 0; i < declaration.getNumberOfParams(); i++) {
+ paramTypes.add(declaration.getParam(i).getType());
+ }
+ for (int i = 0; i < declaration.getNumberOfSpecifiedExceptions(); i++) {
+ exceptionTypes.add(declaration.getSpecifiedException(i));
+ }
+ returnType = declaration.getReturnType();
+ }
+
+ public MethodUsage(ResolvedMethodDeclaration declaration,
+ List<ResolvedType> paramTypes, ResolvedType returnType) {
+ this(declaration, paramTypes, returnType, declaration.getSpecifiedExceptions(),
+ ResolvedTypeParametersMap.empty());
+ }
+
+ public MethodUsage(ResolvedMethodDeclaration declaration, List<ResolvedType> paramTypes, ResolvedType returnType,
+ List<ResolvedType> exceptionTypes) {
+ this(declaration, paramTypes, returnType, exceptionTypes, ResolvedTypeParametersMap.empty());
+ }
+
+ private MethodUsage(ResolvedMethodDeclaration declaration, List<ResolvedType> paramTypes, ResolvedType returnType,
+ List<ResolvedType> exceptionTypes, ResolvedTypeParametersMap typeParametersMap) {
+ this.declaration = declaration;
+ this.paramTypes = paramTypes;
+ this.returnType = returnType;
+ this.exceptionTypes = exceptionTypes;
+ this.typeParametersMap = typeParametersMap;
+ }
+
+ @Override
+ public String toString() {
+ return "MethodUsage{" +
+ "declaration=" + declaration +
+ ", paramTypes=" + paramTypes +
+ '}';
+ }
+
+ public ResolvedMethodDeclaration getDeclaration() {
+ return declaration;
+ }
+
+ public String getName() {
+ return declaration.getName();
+ }
+
+ public ResolvedReferenceTypeDeclaration declaringType() {
+ return declaration.declaringType();
+ }
+
+ public ResolvedType returnType() {
+ return returnType;
+ }
+
+ public List<ResolvedType> getParamTypes() {
+ return paramTypes;
+ }
+
+ public MethodUsage replaceParamType(int i, ResolvedType replaced) {
+ if (i < 0 || i >= getNoParams()) {
+ throw new IllegalArgumentException();
+ }
+ if (paramTypes.get(i) == replaced) {
+ return this;
+ }
+ List<ResolvedType> newParams = new LinkedList<>(paramTypes);
+ newParams.set(i, replaced);
+ return new MethodUsage(declaration, newParams, returnType, exceptionTypes, typeParametersMap);
+ }
+
+ public MethodUsage replaceExceptionType(int i, ResolvedType replaced) {
+ if (i < 0 || i >= exceptionTypes.size()) {
+ throw new IllegalArgumentException();
+ }
+ if (exceptionTypes.get(i) == replaced) {
+ return this;
+ }
+ List<ResolvedType> newTypes = new LinkedList<>(exceptionTypes);
+ newTypes.set(i, replaced);
+ return new MethodUsage(declaration, paramTypes, returnType, newTypes, typeParametersMap);
+ }
+
+ public MethodUsage replaceReturnType(ResolvedType returnType) {
+ if (returnType == this.returnType) {
+ return this;
+ } else {
+ return new MethodUsage(declaration, paramTypes, returnType, exceptionTypes, typeParametersMap);
+ }
+ }
+
+ /**
+ * Return the number of formal arguments accepted by this method.
+ */
+ public int getNoParams() {
+ return paramTypes.size();
+ }
+
+ /**
+ * Return the type of the formal argument at the given position.
+ */
+ public ResolvedType getParamType(int i) {
+ return paramTypes.get(i);
+ }
+
+ public MethodUsage replaceTypeParameter(ResolvedTypeParameterDeclaration typeParameter, ResolvedType type) {
+ if (type == null) {
+ throw new IllegalArgumentException();
+ }
+
+ // TODO if the method declaration has a type param with that name ignore this call
+ MethodUsage res = new MethodUsage(declaration, paramTypes, returnType, exceptionTypes,
+ typeParametersMap.toBuilder().setValue(typeParameter, type).build());
+
+ Map<ResolvedTypeParameterDeclaration, ResolvedType> inferredTypes = new HashMap<>();
+ for (int i = 0; i < paramTypes.size(); i++) {
+ ResolvedType originalParamType = paramTypes.get(i);
+ ResolvedType newParamType = originalParamType.replaceTypeVariables(typeParameter, type, inferredTypes);
+ res = res.replaceParamType(i, newParamType);
+ }
+ for (int i = 0; i < exceptionTypes.size(); i++) {
+ ResolvedType originalType = exceptionTypes.get(i);
+ ResolvedType newType = originalType.replaceTypeVariables(typeParameter, type, inferredTypes);
+ res = res.replaceExceptionType(i, newType);
+ }
+ ResolvedType oldReturnType = res.returnType;
+ ResolvedType newReturnType = oldReturnType.replaceTypeVariables(typeParameter, type, inferredTypes);
+ res = res.replaceReturnType(newReturnType);
+ return res;
+ }
+
+ @Override
+ public ResolvedTypeParametersMap typeParametersMap() {
+ return typeParametersMap;
+ }
+
+ public String getQualifiedSignature() {
+ // TODO use the type parameters
+ return this.getDeclaration().getQualifiedSignature();
+ }
+
+ public List<ResolvedType> exceptionTypes() {
+ return exceptionTypes;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java
new file mode 100644
index 000000000..2b12a1bb8
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/Resolvable.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution;
+
+public interface Resolvable<T> {
+ T resolve();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java
new file mode 100644
index 000000000..67f8a00ce
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/SymbolResolver.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.expr.Expression;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.resolution.types.ResolvedType;
+
+public interface SymbolResolver {
+ /**
+ * For a reference it would find the corresponding
+ * declaration.
+ */
+ <T> T resolveDeclaration(Node node, Class<T> resultClass);
+
+ /**
+ * For types it would find the corresponding resolved types.
+ */
+ <T> T toResolvedType(Type javaparserType, Class<T> resultClass);
+
+ ResolvedType calculateType(Expression expression);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java
new file mode 100644
index 000000000..b915096d0
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/UnsolvedSymbolException.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution;
+
+/**
+ * This exception is thrown when a symbol cannot be resolved.
+ *
+ * @author Federico Tomassetti
+ */
+public class UnsolvedSymbolException extends RuntimeException {
+
+ private String context;
+ private String name;
+
+ public UnsolvedSymbolException(String name, String context) {
+ super("Unsolved symbol in " + context + " : " + name);
+ this.context = context;
+ this.name = name;
+ }
+
+ public UnsolvedSymbolException(String name) {
+ super("Unsolved symbol : " + name);
+ this.context = "unknown";
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return "UnsolvedSymbolException{" +
+ "context='" + context + '\'' +
+ ", name='" + name + '\''+
+ '}';
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java
new file mode 100644
index 000000000..5d7e5bb55
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/HasAccessSpecifier.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import com.github.javaparser.ast.AccessSpecifier;
+
+/**
+ * Anything which can have an AccessSpecifier.
+ *
+ * @author Federico Tomassetti
+ */
+public interface HasAccessSpecifier {
+
+ /**
+ * The access specifier of this element.
+ */
+ AccessSpecifier accessSpecifier();
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java
new file mode 100644
index 000000000..c3124f25e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationDeclaration.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import java.util.List;
+
+/**
+ * @author Federico Tomassetti
+ */
+public interface ResolvedAnnotationDeclaration extends ResolvedReferenceTypeDeclaration {
+
+ List<ResolvedAnnotationMemberDeclaration> getAnnotationMembers();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java
new file mode 100644
index 000000000..0e6f856c4
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedAnnotationMemberDeclaration.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import com.github.javaparser.ast.expr.Expression;
+
+/**
+ * @author Federico Tomassetti
+ */
+public interface ResolvedAnnotationMemberDeclaration extends ResolvedValueDeclaration {
+
+ Expression getDefaultValue();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java
new file mode 100644
index 000000000..08a8d75a2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedClassDeclaration.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import com.github.javaparser.resolution.types.ResolvedReferenceType;
+
+import java.util.List;
+
+/**
+ * Declaration of a Class (not an interface or an enum).
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedClassDeclaration extends ResolvedReferenceTypeDeclaration,
+ ResolvedTypeParametrizable, HasAccessSpecifier {
+
+ /**
+ * This method should always return true.
+ */
+ @Override
+ default boolean isClass() {
+ return true;
+ }
+
+ /**
+ * This is a ReferenceTypeUsage because it could contain type typeParametersValues.
+ * For example: class A extends B<Integer, String>.
+ * <p>
+ * Note that only the Object class should not have a superclass and therefore
+ * return null.
+ */
+ ResolvedReferenceType getSuperClass();
+
+ /**
+ * Return all the interfaces implemented directly by this class.
+ * It does not include the interfaces implemented by superclasses or extended
+ * by the interfaces implemented.
+ */
+ List<ResolvedReferenceType> getInterfaces();
+
+ /**
+ * Get all superclasses, with all the type typeParametersValues expressed as functions of the type
+ * typeParametersValues of this declaration.
+ */
+ List<ResolvedReferenceType> getAllSuperClasses();
+
+ /**
+ * Return all the interfaces implemented by this class, either directly or indirectly, including the interfaces
+ * extended by interfaces it implements.
+ * <p>
+ * Get all interfaces, with all the type typeParametersValues expressed as functions of the type
+ * typeParametersValues of this declaration.
+ */
+ List<ResolvedReferenceType> getAllInterfaces();
+
+ ///
+ /// Constructors
+ ///
+
+ /**
+ * List of constructors available for the class.
+ * This list should also include the default constructor.
+ */
+ List<ResolvedConstructorDeclaration> getConstructors();
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java
new file mode 100644
index 000000000..07f486c5a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedConstructorDeclaration.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+/**
+ * A declaration of a constructor.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedConstructorDeclaration extends ResolvedMethodLikeDeclaration {
+
+ /**
+ * A constructor can be declared in a class or an enum.
+ */
+ @Override
+ ResolvedReferenceTypeDeclaration declaringType();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java
new file mode 100644
index 000000000..86bee80aa
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedDeclaration.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+/**
+ * A generic declaration.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedDeclaration {
+
+ /**
+ * Anonymous classes do not have a name, for example.
+ */
+ default boolean hasName() {
+ return true;
+ }
+
+ /**
+ * Should return the name or throw a RuntimeException if the name is not available.
+ */
+ String getName();
+
+ /**
+ * Does this declaration represents a class field?
+ */
+ default boolean isField() {
+ return false;
+ }
+
+ /**
+ * Does this declaration represents a method parameter?
+ */
+ default boolean isParameter() {
+ return false;
+ }
+
+ /**
+ * Does this declaration represents a type?
+ */
+ default boolean isType() {
+ return false;
+ }
+
+ /**
+ * Does this declaration represents a method?
+ */
+ default boolean isMethod() {
+ return false;
+ }
+
+ /**
+ * Return this as a FieldDeclaration or throw an UnsupportedOperationException
+ */
+ default ResolvedFieldDeclaration asField() {
+ throw new UnsupportedOperationException(String.format("%s is not a FieldDeclaration", this));
+ }
+
+ /**
+ * Return this as a ParameterDeclaration or throw an UnsupportedOperationException
+ */
+ default ResolvedParameterDeclaration asParameter() {
+ throw new UnsupportedOperationException(String.format("%s is not a ParameterDeclaration", this));
+ }
+
+ /**
+ * Return this as a TypeDeclaration or throw an UnsupportedOperationException
+ */
+ default ResolvedTypeDeclaration asType() {
+ throw new UnsupportedOperationException(String.format("%s is not a TypeDeclaration", this));
+ }
+
+ /**
+ * Return this as a MethodDeclaration or throw an UnsupportedOperationException
+ */
+ default ResolvedMethodDeclaration asMethod() {
+ throw new UnsupportedOperationException(String.format("%s is not a MethodDeclaration", this));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java
new file mode 100644
index 000000000..aeb0dedb1
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumConstantDeclaration.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+/**
+ * @author Federico Tomassetti
+ */
+public interface ResolvedEnumConstantDeclaration extends ResolvedValueDeclaration {
+
+ String getName();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java
new file mode 100644
index 000000000..e31a4fb9c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedEnumDeclaration.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import java.util.List;
+
+/**
+ * Declaration of an Enum.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedEnumDeclaration extends ResolvedReferenceTypeDeclaration,
+ HasAccessSpecifier {
+
+ @Override
+ default boolean isEnum() {
+ return true;
+ }
+
+ @Override
+ default ResolvedEnumDeclaration asEnum() {
+ return this;
+ }
+
+ List<ResolvedEnumConstantDeclaration> getEnumConstants();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java
new file mode 100644
index 000000000..194c892c5
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedFieldDeclaration.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+/**
+ * Declaration of a field.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedFieldDeclaration extends ResolvedValueDeclaration, HasAccessSpecifier {
+
+ /**
+ * Is the field static?
+ */
+ boolean isStatic();
+
+ @Override
+ default boolean isField() {
+ return true;
+ }
+
+ @Override
+ default ResolvedFieldDeclaration asField() {
+ return this;
+ }
+
+ /**
+ * The type on which this field has been declared
+ */
+ ResolvedTypeDeclaration declaringType();
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java
new file mode 100644
index 000000000..5ef53b2ce
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedInterfaceDeclaration.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import com.github.javaparser.resolution.types.ResolvedReferenceType;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An interface declaration.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedInterfaceDeclaration extends ResolvedReferenceTypeDeclaration,
+ ResolvedTypeParametrizable, HasAccessSpecifier {
+
+ @Override
+ default boolean isInterface() {
+ return true;
+ }
+
+ /**
+ * Return the list of interfaces extended directly by this one.
+ */
+ List<ResolvedReferenceType> getInterfacesExtended();
+
+ /**
+ * Return the list of interfaces extended directly or indirectly by this one.
+ */
+ default List<ResolvedReferenceType> getAllInterfacesExtended() {
+ List<ResolvedReferenceType> interfaces = new ArrayList<>();
+ for (ResolvedReferenceType interfaceDeclaration : getInterfacesExtended()) {
+ interfaces.add(interfaceDeclaration);
+ interfaces.addAll(interfaceDeclaration.getAllInterfacesAncestors());
+ }
+ return interfaces;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java
new file mode 100644
index 000000000..9f2f64ce3
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodDeclaration.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import com.github.javaparser.resolution.types.ResolvedType;
+
+/**
+ * A declaration of a method (either in an interface, a class, an enum or an annotation).
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedMethodDeclaration extends ResolvedMethodLikeDeclaration {
+
+ /**
+ * The type of the value returned by the current method. This method can also be invoked
+ * for methods returning void.
+ */
+ ResolvedType getReturnType();
+
+ /**
+ * Is the method abstract? All interface methods not marked as default are abstract.
+ */
+ boolean isAbstract();
+
+ /**
+ * Is this a default method?
+ */
+ boolean isDefaultMethod();
+
+ /*
+ * Is this method static?
+ */
+ boolean isStatic();
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java
new file mode 100644
index 000000000..97f35f595
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedMethodLikeDeclaration.java
@@ -0,0 +1,159 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import com.github.javaparser.resolution.types.ResolvedType;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * This is a common interface for MethodDeclaration and ConstructorDeclaration.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedMethodLikeDeclaration extends ResolvedDeclaration,
+ ResolvedTypeParametrizable, HasAccessSpecifier {
+ /**
+ * The package name of the declaring type.
+ */
+ default String getPackageName() {
+ return declaringType().getPackageName();
+ }
+
+ /**
+ * The class(es) wrapping the declaring type.
+ */
+ default String getClassName() {
+ return declaringType().getClassName();
+ }
+
+ /**
+ * The qualified name of the method composed by the qualfied name of the declaring type
+ * followed by a dot and the name of the method.
+ */
+ default String getQualifiedName() {
+ return declaringType().getQualifiedName() + "." + this.getName();
+ }
+
+ /**
+ * The signature of the method.
+ */
+ default String getSignature() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(getName());
+ sb.append("(");
+ for (int i = 0; i < getNumberOfParams(); i++) {
+ if (i != 0) {
+ sb.append(", ");
+ }
+ sb.append(getParam(i).describeType());
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+ /**
+ * The qualified signature of the method. It is composed by the qualified name of the declaring type
+ * followed by the signature of the method.
+ */
+ default String getQualifiedSignature() {
+ return declaringType().getId() + "." + this.getSignature();
+ }
+
+ /**
+ * The type in which the method is declared.
+ */
+ ResolvedReferenceTypeDeclaration declaringType();
+
+ /**
+ * Number of params.
+ */
+ int getNumberOfParams();
+
+ /**
+ * Get the ParameterDeclaration at the corresponding position or throw IllegalArgumentException.
+ */
+ ResolvedParameterDeclaration getParam(int i);
+
+ /**
+ * Utility method to get the last ParameterDeclaration. It throws UnsupportedOperationException if the method
+ * has no parameters.
+ * The last parameter can be variadic and sometimes it needs to be handled in a special way.
+ */
+ default ResolvedParameterDeclaration getLastParam() {
+ if (getNumberOfParams() == 0) {
+ throw new UnsupportedOperationException("This method has no typeParametersValues, therefore it has no a last parameter");
+ }
+ return getParam(getNumberOfParams() - 1);
+ }
+
+ /**
+ * Has the method or construcor a variadic parameter?
+ * Note that when a method has a variadic parameter it should have an array type.
+ */
+ default boolean hasVariadicParameter() {
+ if (getNumberOfParams() == 0) {
+ return false;
+ } else {
+ return getParam(getNumberOfParams() - 1).isVariadic();
+ }
+ }
+
+ @Override
+ default Optional<ResolvedTypeParameterDeclaration> findTypeParameter(String name) {
+ for (ResolvedTypeParameterDeclaration tp : this.getTypeParameters()) {
+ if (tp.getName().equals(name)) {
+ return Optional.of(tp);
+ }
+ }
+ return declaringType().findTypeParameter(name);
+ }
+
+ /**
+ * Number of exceptions listed in the throws clause.
+ */
+ int getNumberOfSpecifiedExceptions();
+
+ /**
+ * Type of the corresponding entry in the throws clause.
+ *
+ * @throws IllegalArgumentException if the index is negative or it is equal or greater than the value returned by
+ * getNumberOfSpecifiedExceptions
+ * @throws UnsupportedOperationException for those types of methods of constructor that do not declare exceptions
+ */
+ ResolvedType getSpecifiedException(int index);
+
+ default List<ResolvedType> getSpecifiedExceptions() {
+ if (getNumberOfSpecifiedExceptions() == 0) {
+ return Collections.emptyList();
+ } else {
+ List<ResolvedType> exceptions = new LinkedList<>();
+ for (int i=0;i<getNumberOfSpecifiedExceptions();i++) {
+ exceptions.add(getSpecifiedException(i));
+ }
+ return exceptions;
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedParameterDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedParameterDeclaration.java
new file mode 100644
index 000000000..668652271
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedParameterDeclaration.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+/**
+ * Declaration of a parameter.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedParameterDeclaration extends ResolvedValueDeclaration {
+
+ @Override
+ default boolean isParameter() {
+ return true;
+ }
+
+ @Override
+ default ResolvedParameterDeclaration asParameter() {
+ return this;
+ }
+
+ /**
+ * Is this parameter declared as variadic?
+ */
+ boolean isVariadic();
+
+ /**
+ * Describe the type of the parameter. In practice add three dots to the type name
+ * is the parameter is variadic.
+ */
+ default String describeType() {
+ if (isVariadic()) {
+ return getType().asArrayType().getComponentType().describe() + "...";
+ } else {
+ return getType().describe();
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java
new file mode 100644
index 000000000..b39521067
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedReferenceTypeDeclaration.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import com.github.javaparser.ast.AccessSpecifier;
+import com.github.javaparser.resolution.MethodUsage;
+import com.github.javaparser.resolution.UnsolvedSymbolException;
+import com.github.javaparser.resolution.types.ResolvedReferenceType;
+import com.github.javaparser.resolution.types.ResolvedType;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * @author Federico Tomassetti
+ */
+public interface ResolvedReferenceTypeDeclaration extends ResolvedTypeDeclaration,
+ ResolvedTypeParametrizable {
+
+ @Override
+ default ResolvedReferenceTypeDeclaration asReferenceType() {
+ return this;
+ }
+
+ ///
+ /// Ancestors
+ ///
+
+ /**
+ * The list of all the direct ancestors of the current declaration.
+ * Note that the ancestor can be parametrized types with values specified. For example:
+ * <p>
+ * class A implements Comparable&lt;String&gt; {}
+ * <p>
+ * In this case the ancestor is Comparable&lt;String&gt;
+ */
+ List<ResolvedReferenceType> getAncestors();
+
+ /**
+ * The list of all the ancestors of the current declaration, direct and indirect.
+ * This list does not contains duplicates with the exacting same type parameters.
+ */
+ default List<ResolvedReferenceType> getAllAncestors() {
+ List<ResolvedReferenceType> ancestors = new ArrayList<>();
+ // We want to avoid infinite recursion in case of Object having Object as ancestor
+ if (!(Object.class.getCanonicalName().equals(getQualifiedName()))) {
+ for (ResolvedReferenceType ancestor : getAncestors()) {
+ ancestors.add(ancestor);
+ for (ResolvedReferenceType inheritedAncestor : ancestor.getAllAncestors()) {
+ if (!ancestors.contains(inheritedAncestor)) {
+ ancestors.add(inheritedAncestor);
+ }
+ }
+ }
+ }
+ return ancestors;
+ }
+
+ ///
+ /// Fields
+ ///
+
+ /**
+ * Note that the type of the field should be expressed using the type variables of this particular type.
+ * Consider for example:
+ * <p>
+ * class Foo<E> { E field; }
+ * <p>
+ * class Bar extends Foo<String> { }
+ * <p>
+ * When calling getField("field") on Foo I should get a FieldDeclaration with type E, while calling it on
+ * Bar I should get a FieldDeclaration with type String.
+ */
+ default ResolvedFieldDeclaration getField(String name) {
+ Optional<ResolvedFieldDeclaration> field = this.getAllFields().stream().filter(f -> f.getName().equals(name)).findFirst();
+ if (field.isPresent()) {
+ return field.get();
+ } else {
+ throw new UnsolvedSymbolException("Field not found: " + name);
+ }
+ }
+
+ /**
+ * Consider only field or inherited field which is not private.
+ */
+ default ResolvedFieldDeclaration getVisibleField(String name) {
+ Optional<ResolvedFieldDeclaration> field = getVisibleFields().stream().filter(f -> f.getName().equals(name)).findFirst();
+ if (field.isPresent()) {
+ return field.get();
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ /**
+ * Has this type a field with the given name?
+ */
+ default boolean hasField(String name) {
+ return this.getAllFields().stream().filter(f -> f.getName().equals(name)).findFirst().isPresent();
+ }
+
+ /**
+ * Either a declared field or inherited field which is not private.
+ */
+ default boolean hasVisibleField(String name) {
+ return getVisibleFields().stream().filter(f -> f.getName().equals(name)).findFirst().isPresent();
+ }
+
+ /**
+ * Return a list of all fields, either declared in this declaration or inherited.
+ */
+ List<ResolvedFieldDeclaration> getAllFields();
+
+ /**
+ * Return a list of all fields declared and the inherited ones which are not private.
+ */
+ default List<ResolvedFieldDeclaration> getVisibleFields() {
+ return getAllFields().stream()
+ .filter(f -> f.declaringType().equals(this) || f.accessSpecifier() != AccessSpecifier.PRIVATE)
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Return a list of all the non static fields, either declared or inherited.
+ */
+ default List<ResolvedFieldDeclaration> getAllNonStaticFields() {
+ return getAllFields().stream().filter(it -> !it.isStatic()).collect(Collectors.toList());
+ }
+
+ /**
+ * Return a list of all the static fields, either declared or inherited.
+ */
+ default List<ResolvedFieldDeclaration> getAllStaticFields() {
+ return getAllFields().stream().filter(it -> it.isStatic()).collect(Collectors.toList());
+ }
+
+ /**
+ * Return a list of all the fields declared in this type.
+ */
+ default List<ResolvedFieldDeclaration> getDeclaredFields() {
+ return getAllFields().stream().filter(it -> it.declaringType().getQualifiedName().equals(getQualifiedName())).collect(Collectors.toList());
+ }
+
+ ///
+ /// Methods
+ ///
+
+ /**
+ * Return a list of all the methods declared in this type declaration.
+ */
+ Set<ResolvedMethodDeclaration> getDeclaredMethods();
+
+ /**
+ * Return a list of all the methods declared of this type declaration, either declared or inherited.
+ * Note that it should not include overridden methods.
+ */
+ Set<MethodUsage> getAllMethods();
+
+ ///
+ /// Assignability
+ ///
+
+ /**
+ * Can we assign instances of the given type to variables having the type defined
+ * by this declaration?
+ */
+ boolean isAssignableBy(ResolvedType type);
+
+ /**
+ * Can we assign instances of the type defined by this declaration to variables having the type defined
+ * by the given type?
+ */
+ default boolean canBeAssignedTo(ResolvedReferenceTypeDeclaration other) {
+ return other.isAssignableBy(this);
+ }
+
+ /**
+ * Can we assign instances of the given type to variables having the type defined
+ * by this declaration?
+ */
+ boolean isAssignableBy(ResolvedReferenceTypeDeclaration other);
+
+ ///
+ /// Annotations
+ ///
+
+ /**
+ * Has the type at least one annotation declared having the specified qualified name?
+ */
+ boolean hasDirectlyAnnotation(String qualifiedName);
+
+ /**
+ * Has the type at least one annotation declared or inherited having the specified qualified name?
+ */
+ default boolean hasAnnotation(String qualifiedName) {
+ if (hasDirectlyAnnotation(qualifiedName)) {
+ return true;
+ }
+ return getAllAncestors().stream().anyMatch(it -> it.asReferenceType().getTypeDeclaration().hasDirectlyAnnotation(qualifiedName));
+ }
+
+ /**
+ * This means that the type has a functional method. Conceptually, a functional interface has exactly one abstract method.
+ * Typically these classes has the FunctionInterface annotation but this is not mandatory.
+ */
+ boolean isFunctionalInterface();
+
+ ///
+ /// Type parameters
+ ///
+
+ @Override
+ default Optional<ResolvedTypeParameterDeclaration> findTypeParameter(String name) {
+ for (ResolvedTypeParameterDeclaration tp : this.getTypeParameters()) {
+ if (tp.getName().equals(name)) {
+ return Optional.of(tp);
+ }
+ }
+ if (this.containerType().isPresent()) {
+ return this.containerType().get().findTypeParameter(name);
+ }
+ return Optional.empty();
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java
new file mode 100644
index 000000000..0b715fe29
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeDeclaration.java
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import com.github.javaparser.resolution.UnsolvedSymbolException;
+
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * A declaration of a type. It could be a primitive type, an enum, a class, an interface
+ * or a type variable.
+ * It cannot be an annotation or an array.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedTypeDeclaration extends ResolvedDeclaration {
+
+ ///
+ /// Containment
+ ///
+
+ /**
+ * Get the list of types defined inside the current type.
+ */
+ default Set<ResolvedReferenceTypeDeclaration> internalTypes() {
+ throw new UnsupportedOperationException("InternalTypes not available for " + this.getClass().getCanonicalName());
+ }
+
+ /**
+ * Returns a type declaration for the internal type based on name.
+ * (Does not include internal types inside internal types).
+ */
+ default ResolvedReferenceTypeDeclaration getInternalType(String name) {
+ Optional<ResolvedReferenceTypeDeclaration> type =
+ this.internalTypes().stream().filter(f -> f.getName().equals(name)).findFirst();
+ return type.orElseThrow(() ->
+ new UnsolvedSymbolException("Internal type not found: " + name));
+ }
+
+ /**
+ * Does this type contain an internal type with the given name?
+ * (Does not include internal types inside internal types).
+ */
+ default boolean hasInternalType(String name) {
+ return this.internalTypes().stream().anyMatch(f -> f.getName().equals(name));
+ }
+
+ /**
+ * Get the ReferenceTypeDeclaration enclosing this declaration.
+ *
+ * @return
+ */
+ Optional<ResolvedReferenceTypeDeclaration> containerType();
+
+ ///
+ /// Misc
+ ///
+
+ /**
+ * Is this the declaration of a class?
+ * Note that an Enum is not considered a Class in this case.
+ */
+ default boolean isClass() {
+ return false;
+ }
+
+ /**
+ * Is this the declaration of an interface?
+ */
+ default boolean isInterface() {
+ return false;
+ }
+
+ /**
+ * Is this the declaration of an enum?
+ */
+ default boolean isEnum() {
+ return false;
+ }
+
+ /**
+ * Is this the declaration of a type parameter?
+ */
+ default boolean isTypeParameter() {
+ return false;
+ }
+
+ @Override
+ default boolean isType() {
+ return true;
+ }
+
+ /**
+ * Is this type declaration corresponding to an anonymous class?
+ *
+ * This is an example of anonymous class:
+ * <pre>
+ * HelloWorld frenchGreeting = new HelloWorld() {
+ * String name = "tout le monde";
+ *
+ * public void greet() {
+ * greetSomeone("tout le monde");
+ * }
+ *
+ * public void greetSomeone(String someone) {
+ * name = someone;
+ * System.out.println("Salut " + name);
+ * }
+ * };
+ * </pre>
+ */
+ default boolean isAnonymousClass() {
+ return false;
+ }
+
+ @Override
+ default ResolvedTypeDeclaration asType() {
+ return this;
+ }
+
+ /**
+ * Return this as a ClassDeclaration or throw UnsupportedOperationException.
+ */
+ default ResolvedClassDeclaration asClass() {
+ throw new UnsupportedOperationException(String.format("%s is not a class", this));
+ }
+
+ /**
+ * Return this as a InterfaceDeclaration or throw UnsupportedOperationException.
+ */
+ default ResolvedInterfaceDeclaration asInterface() {
+ throw new UnsupportedOperationException(String.format("%s is not an interface", this));
+ }
+
+ /**
+ * Return this as a EnumDeclaration or throw UnsupportedOperationException.
+ */
+ default ResolvedEnumDeclaration asEnum() {
+ throw new UnsupportedOperationException(String.format("%s is not an enum", this));
+ }
+
+ /**
+ * Return this as a TypeParameterDeclaration or throw UnsupportedOperationException.
+ */
+ default ResolvedTypeParameterDeclaration asTypeParameter() {
+ throw new UnsupportedOperationException(String.format("%s is not a type parameter", this));
+ }
+
+ default ResolvedReferenceTypeDeclaration asReferenceType() {
+ throw new UnsupportedOperationException(String.format("%s is not a reference type", this));
+ }
+
+ /**
+ * The package name of the type.
+ */
+ String getPackageName();
+
+ /**
+ * The class(es) wrapping this type.
+ */
+ String getClassName();
+
+ /**
+ * The fully qualified name of the type declared.
+ */
+ String getQualifiedName();
+
+ /**
+ * The ID corresponds most of the type to the qualified name. It differs only for local
+ * classes which do not have a qualified name but have an ID.
+ */
+ default String getId() {
+ String qname = getQualifiedName();
+ if (qname == null) {
+ return String.format("<localClass>:%s", getName());
+ }
+ return qname;
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java
new file mode 100644
index 000000000..14326db1f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParameterDeclaration.java
@@ -0,0 +1,305 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+
+import com.github.javaparser.resolution.types.ResolvedType;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Declaration of a type parameter.
+ * For example:
+ * <p>
+ * class A&lt;E extends String&gt;{}
+ * </p>
+ * <p>
+ * In this case <b>E</b> would be a type parameter.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedTypeParameterDeclaration extends ResolvedTypeDeclaration {
+
+ /**
+ * Instantiate a TypeParameter defined on a Type with the given data.
+ */
+ static ResolvedTypeParameterDeclaration onType(final String name, String classQName, List<Bound> bounds) {
+ return new ResolvedTypeParameterDeclaration() {
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public boolean declaredOnType() {
+ return true;
+ }
+
+ @Override
+ public boolean declaredOnMethod() {
+ return false;
+ }
+
+ @Override
+ public boolean declaredOnConstructor() {
+ return false;
+ }
+
+ @Override
+ public String getContainerQualifiedName() {
+ return classQName;
+ }
+
+ @Override
+ public String getContainerId() {
+ return classQName;
+ }
+
+ @Override
+ public ResolvedTypeParametrizable getContainer() {
+ return null;
+ }
+
+ @Override
+ public List<Bound> getBounds() {
+ return bounds;
+ }
+
+ @Override
+ public String toString() {
+ return "TypeParameter onType " + name;
+ }
+
+ @Override
+ public Optional<ResolvedReferenceTypeDeclaration> containerType() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ /**
+ * Name of the type parameter.
+ */
+ String getName();
+
+ /**
+ * Is the type parameter been defined on a type?
+ */
+ default boolean declaredOnType() {
+ return (getContainer() instanceof ResolvedReferenceTypeDeclaration);
+ }
+
+ /**
+ * Is the type parameter been defined on a method?
+ */
+ default boolean declaredOnMethod() {
+ return (getContainer() instanceof ResolvedMethodDeclaration);
+ }
+
+ /**
+ * Is the type parameter been defined on a constructor?
+ */
+ default boolean declaredOnConstructor() {
+ return (getContainer() instanceof ResolvedConstructorDeclaration);
+ }
+
+ /**
+ * The package name of the type bound(s).
+ * This is unsupported because there is no package for a Type Parameter, only for its container.
+ */
+ default String getPackageName() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * The class(es) wrapping the type bound(s).
+ * This is unsupported because there is no class for a Type Parameter, only for its container.
+ */
+ default String getClassName() {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * The qualified name of the Type Parameter.
+ * It is composed by the qualified name of the container followed by a dot and the name of the Type Parameter.
+ * The qualified name of a method is its qualified signature.
+ */
+ default String getQualifiedName() {
+ return String.format("%s.%s", getContainerId(), getName());
+ }
+
+ /**
+ * The qualified name of the container.
+ */
+ String getContainerQualifiedName();
+
+ /**
+ * The ID of the container. See TypeContainer.getId
+ */
+ String getContainerId();
+
+ /**
+ * The TypeParametrizable of the container. Can be either a ReferenceTypeDeclaration or a MethodLikeDeclaration
+ */
+ ResolvedTypeParametrizable getContainer();
+
+ /**
+ * The bounds specified for the type parameter.
+ * For example:
+ * "extends A" or "super B"
+ */
+ List<Bound> getBounds();
+
+ /**
+ * Has the type parameter a lower bound?
+ */
+ default boolean hasLowerBound() {
+ for (Bound b : getBounds()) {
+ if (b.isExtends()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Has the type parameter an upper bound?
+ */
+ default boolean hasUpperBound() {
+ for (Bound b : getBounds()) {
+ if (b.isSuper()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get the type used as lower bound.
+ *
+ * @throws IllegalStateException if there is no lower bound
+ */
+ default ResolvedType getLowerBound() {
+ for (Bound b : getBounds()) {
+ if (b.isExtends()) {
+ return b.getType();
+ }
+ }
+ throw new IllegalStateException();
+ }
+
+ /**
+ * Get the type used as upper bound.
+ *
+ * @throws IllegalStateException if there is no upper bound
+ */
+ default ResolvedType getUpperBound() {
+ for (Bound b : getBounds()) {
+ if (b.isSuper()) {
+ return b.getType();
+ }
+ }
+ throw new IllegalStateException();
+ }
+
+ /**
+ * A Bound on a Type Parameter.
+ */
+ class Bound {
+ private boolean extendsBound;
+ private ResolvedType type;
+
+ private Bound(boolean extendsBound, ResolvedType type) {
+ this.extendsBound = extendsBound;
+ this.type = type;
+ }
+
+ /**
+ * Create an extends bound with the given type:
+ * <p>
+ * extends "given type"
+ * </p>
+ */
+ public static Bound extendsBound(ResolvedType type) {
+ return new Bound(true, type);
+ }
+
+ /**
+ * Create a super bound with the given type:
+ * <p>
+ * super "given type"
+ * </p>
+ */
+ public static Bound superBound(ResolvedType type) {
+ return new Bound(false, type);
+ }
+
+ /**
+ * Get the type used in the Bound.
+ */
+ public ResolvedType getType() {
+ return type;
+ }
+
+ /**
+ * Is this an extends bound?
+ */
+ public boolean isExtends() {
+ return extendsBound;
+ }
+
+ /**
+ * Is this a super bound?
+ */
+ public boolean isSuper() {
+ return !isExtends();
+ }
+
+ @Override
+ public String toString() {
+ return "Bound{" +
+ "extendsBound=" + extendsBound +
+ ", type=" + type +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Bound bound = (Bound) o;
+
+ if (extendsBound != bound.extendsBound) return false;
+ return type != null ? type.equals(bound.type) : bound.type == null;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = (extendsBound ? 1 : 0);
+ result = 31 * result + (type != null ? type.hashCode() : 0);
+ return result;
+ }
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java
new file mode 100644
index 000000000..3d6b92e7a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedTypeParametrizable.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * An entity which has type parameter.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedTypeParametrizable {
+
+ /**
+ * The list of type parameters defined on this element.
+ */
+ List<ResolvedTypeParameterDeclaration> getTypeParameters();
+
+ /**
+ * Find the closest TypeParameterDeclaration with the given name.
+ * It first look on this element itself and then on the containers.
+ */
+ Optional<ResolvedTypeParameterDeclaration> findTypeParameter(String name);
+
+ default boolean isGeneric() {
+ return !getTypeParameters().isEmpty();
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java
new file mode 100644
index 000000000..ee6230ad8
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/declarations/ResolvedValueDeclaration.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.declarations;
+
+
+import com.github.javaparser.resolution.types.ResolvedType;
+
+/**
+ * Declaration of a value.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedValueDeclaration extends ResolvedDeclaration {
+
+ /**
+ * Type of the declaration.
+ */
+ ResolvedType getType();
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java
new file mode 100644
index 000000000..bc422f75f
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedArrayType.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+
+import java.util.Map;
+
+/**
+ * Array Type.
+ *
+ * @author Federico Tomassetti
+ */
+public class ResolvedArrayType implements ResolvedType {
+
+ private ResolvedType baseType;
+
+ public ResolvedArrayType(ResolvedType baseType) {
+ this.baseType = baseType;
+ }
+
+ ///
+ /// Object methods
+ ///
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ResolvedArrayType that = (ResolvedArrayType) o;
+
+ if (!baseType.equals(that.baseType)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return baseType.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "ResolvedArrayType{" + baseType + "}";
+ }
+
+ ///
+ /// Type methods
+ ///
+
+ @Override
+ public ResolvedArrayType asArrayType() {
+ return this;
+ }
+
+ @Override
+ public boolean isArray() {
+ return true;
+ }
+
+ @Override
+ public String describe() {
+ return baseType.describe() + "[]";
+ }
+
+ public ResolvedType getComponentType() {
+ return baseType;
+ }
+
+ @Override
+ public boolean isAssignableBy(ResolvedType other) {
+ if (other.isArray()) {
+ if (baseType.isPrimitive() && other.asArrayType().getComponentType().isPrimitive()) {
+ return baseType.equals(other.asArrayType().getComponentType());
+ }
+ return baseType.isAssignableBy(other.asArrayType().getComponentType());
+ } else if (other.isNull()) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, Map<ResolvedTypeParameterDeclaration, ResolvedType> inferredTypes) {
+ ResolvedType baseTypeReplaced = baseType.replaceTypeVariables(tpToReplace, replaced, inferredTypes);
+ if (baseTypeReplaced == baseType) {
+ return this;
+ } else {
+ return new ResolvedArrayType(baseTypeReplaced);
+ }
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java
new file mode 100644
index 000000000..e308feace
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedIntersectionType.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * An intersection type is defined in java as list of types separates by ampersands.
+ *
+ * @author Federico Tomassetti
+ */
+public class ResolvedIntersectionType implements ResolvedType {
+ private List<ResolvedType> elements;
+
+ public ResolvedIntersectionType(Collection<ResolvedType> elements) {
+ if (elements.size() < 2) {
+ throw new IllegalArgumentException("An intersection type should have at least two elements. This has " + elements.size());
+ }
+ this.elements = new LinkedList<>(elements);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ResolvedIntersectionType that = (ResolvedIntersectionType) o;
+
+ return new HashSet<>(elements).equals(new HashSet<>(that.elements));
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashSet<>(elements).hashCode();
+ }
+
+ @Override
+ public String describe() {
+ return String.join(" & ", elements.stream().map(ResolvedType::describe).collect(Collectors.toList()));
+ }
+
+ @Override
+ public boolean isAssignableBy(ResolvedType other) {
+ return elements.stream().allMatch(e -> e.isAssignableBy(other));
+ }
+
+ @Override
+ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced, Map<ResolvedTypeParameterDeclaration, ResolvedType> inferredTypes) {
+ List<ResolvedType> elementsReplaced = elements.stream()
+ .map(e -> e.replaceTypeVariables(tp, replaced, inferredTypes))
+ .collect(Collectors.toList());
+ if (elementsReplaced.equals(elements)) {
+ return this;
+ } else {
+ return new ResolvedIntersectionType(elementsReplaced);
+ }
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java
new file mode 100644
index 000000000..e43d434d8
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedLambdaConstraintType.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+public class ResolvedLambdaConstraintType implements ResolvedType {
+ private ResolvedType bound;
+
+ private ResolvedLambdaConstraintType(ResolvedType bound) {
+ this.bound = bound;
+ }
+
+ @Override
+ public String describe() {
+ return "? super " + bound.describe();
+ }
+
+ public ResolvedType getBound() {
+ return bound;
+ }
+
+ @Override
+ public boolean isConstraint() {
+ return true;
+ }
+
+ @Override
+ public ResolvedLambdaConstraintType asConstraintType() {
+ return this;
+ }
+
+ public static ResolvedLambdaConstraintType bound(ResolvedType bound){
+ return new ResolvedLambdaConstraintType(bound);
+ }
+
+ @Override
+ public boolean isAssignableBy(ResolvedType other) {
+ return bound.isAssignableBy(other);
+ }
+
+ @Override
+ public String toString() {
+ return "LambdaConstraintType{" +
+ "bound=" + bound +
+ '}';
+ }
+} \ No newline at end of file
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java
new file mode 100644
index 000000000..4a7e29258
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedPrimitiveType.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Federico Tomassetti
+ */
+public enum ResolvedPrimitiveType implements ResolvedType {
+
+
+ BYTE("byte", Byte.class.getCanonicalName(), Collections.emptyList()),
+ SHORT("short", Short.class.getCanonicalName(), Collections.singletonList(BYTE)),
+ CHAR("char", Character.class.getCanonicalName(), Collections.emptyList()),
+ INT("int", Integer.class.getCanonicalName(), Arrays.asList(BYTE, SHORT, CHAR)),
+ LONG("long", Long.class.getCanonicalName(), Arrays.asList(BYTE, SHORT, INT, CHAR)),
+ BOOLEAN("boolean", Boolean.class.getCanonicalName(), Collections.emptyList()),
+ FLOAT("float", Float.class.getCanonicalName(), Arrays.asList(LONG, INT, SHORT, BYTE, CHAR)),
+ DOUBLE("double", Double.class.getCanonicalName(), Arrays.asList(FLOAT, LONG, INT, SHORT, BYTE, CHAR));
+
+ ///
+ /// Fields
+ ///
+
+ private String name;
+ private String boxTypeQName;
+ private List<ResolvedPrimitiveType> promotionTypes;
+
+ private ResolvedPrimitiveType(String name, String boxTypeQName, List<ResolvedPrimitiveType> promotionTypes) {
+ this.name = name;
+ this.boxTypeQName = boxTypeQName;
+ this.promotionTypes = promotionTypes;
+ }
+
+ public static ResolvedType byName(String name) {
+ name = name.toLowerCase();
+ for (ResolvedPrimitiveType ptu : values()) {
+ if (ptu.describe().equals(name)) {
+ return ptu;
+ }
+ }
+ throw new IllegalArgumentException("Name " + name);
+ }
+
+ @Override
+ public String toString() {
+ return "PrimitiveTypeUsage{" +
+ "name='" + name + '\'' +
+ '}';
+ }
+
+ public ResolvedPrimitiveType asPrimitive() {
+ return this;
+ }
+
+ @Override
+ public boolean isArray() {
+ return false;
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return true;
+ }
+
+ @Override
+ public boolean isReferenceType() {
+ return false;
+ }
+
+ @Override
+ public String describe() {
+ return name;
+ }
+
+ @Override
+ public boolean isTypeVariable() {
+ return false;
+ }
+
+ @Override
+ public boolean isAssignableBy(ResolvedType other) {
+ if (other.isPrimitive()) {
+ return this == other || promotionTypes.contains(other);
+ } else if (other.isReferenceType()) {
+ if (other.asReferenceType().getQualifiedName().equals(boxTypeQName)) {
+ return true;
+ }
+ for (ResolvedPrimitiveType promotion : promotionTypes) {
+ if (other.asReferenceType().getQualifiedName().equals(promotion.boxTypeQName)) {
+ return true;
+ }
+ }
+ return false;
+ } else if (other.isConstraint()){
+ return this.isAssignableBy(other.asConstraintType().getBound());
+ } else {
+ return false;
+ }
+ }
+
+ public String getBoxTypeQName() {
+ return boxTypeQName;
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java
new file mode 100644
index 000000000..4fecaf6ec
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedReferenceType.java
@@ -0,0 +1,451 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+import com.github.javaparser.resolution.MethodUsage;
+import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParameterValueProvider;
+import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap;
+import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametrized;
+import com.github.javaparser.utils.Pair;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * A ReferenceType like a class, an interface or an enum. Note that this type can contain also the values
+ * specified for the type parameters.
+ *
+ * @author Federico Tomassetti
+ */
+public abstract class ResolvedReferenceType implements ResolvedType,
+ ResolvedTypeParametrized, ResolvedTypeParameterValueProvider {
+
+ //
+ // Fields
+ //
+
+ protected ResolvedReferenceTypeDeclaration typeDeclaration;
+ protected ResolvedTypeParametersMap typeParametersMap;
+
+ //
+ // Constructors
+ //
+
+ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration) {
+ this(typeDeclaration, deriveParams(typeDeclaration));
+ }
+
+ public ResolvedReferenceType(ResolvedReferenceTypeDeclaration typeDeclaration, List<ResolvedType> typeArguments) {
+ if (typeDeclaration.isTypeParameter()) {
+ throw new IllegalArgumentException("You should use only Classes, Interfaces and enums");
+ }
+ if (typeArguments.size() > 0 && typeArguments.size() != typeDeclaration.getTypeParameters().size()) {
+ throw new IllegalArgumentException(String.format(
+ "expected either zero type arguments or has many as defined in the declaration (%d). Found %d",
+ typeDeclaration.getTypeParameters().size(), typeArguments.size()));
+ }
+ ResolvedTypeParametersMap.Builder typeParametersMapBuilder = new ResolvedTypeParametersMap.Builder();
+ for (int i = 0; i < typeArguments.size(); i++) {
+ typeParametersMapBuilder.setValue(typeDeclaration.getTypeParameters().get(i), typeArguments.get(i));
+ }
+ this.typeParametersMap = typeParametersMapBuilder.build();
+ this.typeDeclaration = typeDeclaration;
+ }
+
+ //
+ // Public Object methods
+ //
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ResolvedReferenceType that = (ResolvedReferenceType) o;
+
+ if (!typeDeclaration.equals(that.typeDeclaration)) return false;
+ if (!typeParametersMap.equals(that.typeParametersMap)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = typeDeclaration.hashCode();
+ result = 31 * result + typeParametersMap.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "ReferenceType{" + getQualifiedName() +
+ ", typeParametersMap=" + typeParametersMap +
+ '}';
+ }
+
+ ///
+ /// Relation with other types
+ ///
+
+ @Override
+ public final boolean isReferenceType() {
+ return true;
+ }
+
+ ///
+ /// Downcasting
+ ///
+
+ @Override
+ public ResolvedReferenceType asReferenceType() {
+ return this;
+ }
+
+ ///
+ /// Naming
+ ///
+
+ @Override
+ public String describe() {
+ StringBuilder sb = new StringBuilder();
+ if (hasName()) {
+ sb.append(typeDeclaration.getQualifiedName());
+ } else {
+ sb.append("<anonymous class>");
+ }
+ if (!typeParametersMap().isEmpty()) {
+ sb.append("<");
+ sb.append(String.join(", ", typeDeclaration.getTypeParameters().stream()
+ .map(tp -> typeParametersMap().getValue(tp).describe())
+ .collect(Collectors.toList())));
+ sb.append(">");
+ }
+ return sb.toString();
+ }
+
+ ///
+ /// TypeParameters
+ ///
+
+ /**
+ * Execute a transformation on all the type parameters of this element.
+ */
+ public abstract ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer);
+
+ @Override
+ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced,
+ Map<ResolvedTypeParameterDeclaration, ResolvedType> inferredTypes) {
+ if (replaced == null) {
+ throw new IllegalArgumentException();
+ }
+
+ ResolvedReferenceType result = this;
+ int i = 0;
+ for (ResolvedType tp : this.typeParametersValues()) {
+ ResolvedType transformedTp = tp.replaceTypeVariables(tpToReplace, replaced, inferredTypes);
+ // Identity comparison on purpose
+ if (tp.isTypeVariable() && tp.asTypeVariable().describe().equals(tpToReplace.getName())) {
+ inferredTypes.put(tp.asTypeParameter(), replaced);
+ }
+ // FIXME
+ if (true) {
+ List<ResolvedType> typeParametersCorrected = result.asReferenceType().typeParametersValues();
+ typeParametersCorrected.set(i, transformedTp);
+ result = create(typeDeclaration, typeParametersCorrected);
+ }
+ i++;
+ }
+
+ List<ResolvedType> values = result.typeParametersValues();
+ // FIXME
+ if(values.contains(tpToReplace)){
+ int index = values.indexOf(tpToReplace);
+ values.set(index, replaced);
+ return create(result.getTypeDeclaration(), values);
+ }
+
+ return result;
+ }
+
+ ///
+ /// Assignability
+ ///
+
+ /**
+ * This method checks if ThisType t = new OtherType() would compile.
+ */
+ @Override
+ public abstract boolean isAssignableBy(ResolvedType other);
+
+ ///
+ /// Ancestors
+ ///
+
+ /**
+ * Return all ancestors, that means all superclasses and interfaces.
+ * This list should always include Object (unless this is a reference to Object).
+ * The type typeParametersValues should be expressed in terms of this type typeParametersValues.
+ * <p>
+ * For example, given:
+ * <p>
+ * class Foo&lt;A, B&gt; {}
+ * class Bar&lt;C&gt; extends Foo&lt;C, String&gt; {}
+ * <p>
+ * a call to getAllAncestors on a reference to Bar having type parameter Boolean should include
+ * Foo&lt;Boolean, String&gt;.
+ */
+ public abstract List<ResolvedReferenceType> getAllAncestors();
+
+ public final List<ResolvedReferenceType> getAllInterfacesAncestors() {
+ return getAllAncestors().stream()
+ .filter(it -> it.getTypeDeclaration().isInterface())
+ .collect(Collectors.toList());
+ }
+
+ public final List<ResolvedReferenceType> getAllClassesAncestors() {
+ return getAllAncestors().stream()
+ .filter(it -> it.getTypeDeclaration().isClass())
+ .collect(Collectors.toList());
+ }
+
+ ///
+ /// Type parameters
+ ///
+
+ /**
+ * Get the type associated with the type parameter with the given name.
+ * It returns Optional.empty unless the type declaration declares a type parameter with the given name.
+ */
+ public Optional<ResolvedType> getGenericParameterByName(String name) {
+ for (ResolvedTypeParameterDeclaration tp : typeDeclaration.getTypeParameters()) {
+ if (tp.getName().equals(name)) {
+ return Optional.of(this.typeParametersMap().getValue(tp));
+ }
+ }
+ return Optional.empty();
+ }
+
+ /**
+ * Get the values for all type parameters declared on this type.
+ * The list can be empty for raw types.
+ */
+ public List<ResolvedType> typeParametersValues() {
+ return this.typeParametersMap.isEmpty() ? Collections.emptyList() : typeDeclaration.getTypeParameters().stream().map(tp -> typeParametersMap.getValue(tp)).collect(Collectors.toList());
+ }
+
+ /**
+ * Get the values for all type parameters declared on this type.
+ * In case of raw types the values correspond to TypeVariables.
+ */
+ public List<Pair<ResolvedTypeParameterDeclaration, ResolvedType>> getTypeParametersMap() {
+ List<Pair<ResolvedTypeParameterDeclaration, ResolvedType>> typeParametersMap = new ArrayList<>();
+ if (!isRawType()) {
+ for (int i = 0; i < typeDeclaration.getTypeParameters().size(); i++) {
+ typeParametersMap.add(new Pair<>(typeDeclaration.getTypeParameters().get(0), typeParametersValues().get(i)));
+ }
+ }
+ return typeParametersMap;
+ }
+
+ @Override
+ public ResolvedTypeParametersMap typeParametersMap() {
+ return typeParametersMap;
+ }
+
+ ///
+ /// Other methods introduced by ReferenceType
+ ///
+
+ /**
+ * Corresponding TypeDeclaration
+ */
+ public final ResolvedReferenceTypeDeclaration getTypeDeclaration() {
+ return typeDeclaration;
+ }
+
+ /**
+ * The type of the field could be different from the one in the corresponding FieldDeclaration because
+ * type variables would be solved.
+ */
+ public Optional<ResolvedType> getFieldType(String name) {
+ if (!typeDeclaration.hasField(name)) {
+ return Optional.empty();
+ }
+ ResolvedType type = typeDeclaration.getField(name).getType();
+ type = useThisTypeParametersOnTheGivenType(type);
+ return Optional.of(type);
+ }
+
+ /**
+ * Has the TypeDeclaration a name? Anonymous classes do not have one.
+ */
+ public boolean hasName() {
+ return typeDeclaration.hasName();
+ }
+
+ /**
+ * Qualified name of the declaration.
+ */
+ public String getQualifiedName() {
+ return typeDeclaration.getQualifiedName();
+ }
+
+ /**
+ * Id of the declaration. It corresponds to the qualified name, unless for local classes.
+ */
+ public String getId() {
+ return typeDeclaration.getId();
+ }
+
+ /**
+ * Methods declared on this type.
+ */
+ public abstract Set<MethodUsage> getDeclaredMethods();
+
+ public boolean isRawType() {
+ if (!typeDeclaration.getTypeParameters().isEmpty()) {
+ if (typeParametersMap().isEmpty()) {
+ return true;
+ }
+ for (String name : typeParametersMap().getNames()) {
+ Optional<ResolvedType> value = typeParametersMap().getValueBySignature(name);
+ if (value.isPresent() && value.get().isTypeVariable() && value.get().asTypeVariable().qualifiedName().equals(name)) {
+ // nothing to do
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public Optional<ResolvedType> typeParamValue(ResolvedTypeParameterDeclaration typeParameterDeclaration) {
+ if (typeParameterDeclaration.declaredOnMethod()) {
+ throw new IllegalArgumentException();
+ }
+ String typeId = this.getTypeDeclaration().getId();
+ if (typeId.equals(typeParameterDeclaration.getContainerId())) {
+ return Optional.of(this.typeParametersMap().getValue(typeParameterDeclaration));
+ }
+ for (ResolvedReferenceType ancestor : this.getAllAncestors()) {
+ if (ancestor.getId().equals(typeParameterDeclaration.getContainerId())) {
+ return Optional.of(ancestor.typeParametersMap().getValue(typeParameterDeclaration));
+ }
+ }
+ return Optional.empty();
+ }
+
+ public abstract ResolvedType toRawType();
+
+ //
+ // Protected methods
+ //
+
+ protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, List<ResolvedType> typeParameters);
+
+ protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, ResolvedTypeParametersMap typeParametersMap) {
+ return create(typeDeclaration, typeDeclaration.getTypeParameters().stream()
+ .map(typeParametersMap::getValue)
+ .collect(Collectors.toList()));
+ }
+
+ protected abstract ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration);
+
+ protected boolean isCorrespondingBoxingType(String typeName) {
+ switch (typeName) {
+ case "boolean":
+ return getQualifiedName().equals(Boolean.class.getCanonicalName());
+ case "char":
+ return getQualifiedName().equals(Character.class.getCanonicalName());
+ case "byte":
+ return getQualifiedName().equals(Byte.class.getCanonicalName());
+ case "short":
+ return getQualifiedName().equals(Short.class.getCanonicalName());
+ case "int":
+ return getQualifiedName().equals(Integer.class.getCanonicalName());
+ case "long":
+ return getQualifiedName().equals(Long.class.getCanonicalName());
+ case "float":
+ return getQualifiedName().equals(Float.class.getCanonicalName());
+ case "double":
+ return getQualifiedName().equals(Double.class.getCanonicalName());
+ default:
+ throw new UnsupportedOperationException(typeName);
+ }
+ }
+
+ protected boolean compareConsideringTypeParameters(ResolvedReferenceType other) {
+ if (other.equals(this)) {
+ return true;
+ }
+ if (this.getQualifiedName().equals(other.getQualifiedName())) {
+ if (this.isRawType() || other.isRawType()) {
+ return true;
+ }
+ if (this.typeParametersValues().size() != other.typeParametersValues().size()) {
+ throw new IllegalStateException();
+ }
+ for (int i = 0; i < typeParametersValues().size(); i++) {
+ ResolvedType thisParam = typeParametersValues().get(i);
+ ResolvedType otherParam = other.typeParametersValues().get(i);
+ if (!thisParam.equals(otherParam)) {
+ if (thisParam instanceof ResolvedWildcard) {
+ ResolvedWildcard thisParamAsWildcard = (ResolvedWildcard) thisParam;
+ if (thisParamAsWildcard.isSuper() && otherParam.isAssignableBy(thisParamAsWildcard.getBoundedType())) {
+ // ok
+ } else if (thisParamAsWildcard.isExtends() && thisParamAsWildcard.getBoundedType().isAssignableBy(otherParam)) {
+ // ok
+ } else if (!thisParamAsWildcard.isBounded()) {
+ // ok
+ } else {
+ return false;
+ }
+ } else {
+ if (thisParam instanceof ResolvedTypeVariable && otherParam instanceof ResolvedTypeVariable) {
+ List<ResolvedType> thisBounds = thisParam.asTypeVariable().asTypeParameter().getBounds().stream().map(bound -> bound.getType()).collect(Collectors.toList());
+ List<ResolvedType> otherBounds = otherParam.asTypeVariable().asTypeParameter().getBounds().stream().map(bound -> bound.getType()).collect(Collectors.toList());
+ if (thisBounds.size() == otherBounds.size() && otherBounds.containsAll(thisBounds)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ //
+ // Private methods
+ //
+
+ private static List<ResolvedType> deriveParams(ResolvedReferenceTypeDeclaration typeDeclaration) {
+ return typeDeclaration.getTypeParameters().stream().map((tp) -> new ResolvedTypeVariable(tp)).collect(Collectors.toList());
+ }
+
+ public abstract ResolvedReferenceType deriveTypeParameters(ResolvedTypeParametersMap typeParametersMap);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java
new file mode 100644
index 000000000..d787b597a
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedType.java
@@ -0,0 +1,192 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A resolved type. It could be a primitive type or a reference type (enum, class, interface). In the later case it
+ * could take type typeParametersValues (other TypeUsages). It could also be a TypeVariable, like in:
+ * <p>
+ * class A&lt;Bgt; { }
+ * <p>
+ * where B is a TypeVariable. It could also be Wildcard Type, possibly with constraints.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedType {
+
+ ///
+ /// Relation with other types
+ ///
+
+ /**
+ * Does this type represent an array?
+ */
+ default boolean isArray() {
+ return false;
+ }
+
+ default int arrayLevel() {
+ if (isArray()) {
+ return 1 + this.asArrayType().getComponentType().arrayLevel();
+ } else {
+ return 0;
+ }
+ }
+
+ /**
+ * Is this a primitive type?
+ */
+ default boolean isPrimitive() {
+ return false;
+ }
+
+ /**
+ * Is this the null type?
+ */
+ default boolean isNull() {
+ return false;
+ }
+
+ /**
+ * Is this a union type (as the ones used in multi catch clauses)?
+ */
+ default boolean isUnionType() {
+ return false;
+ }
+
+ /**
+ * Is this a non primitive value?
+ */
+ default boolean isReference() {
+ return isReferenceType() || isArray() || isTypeVariable() || isNull() || isWildcard() || isUnionType();
+ }
+
+ /**
+ * Is this a lambda constraint type?
+ */
+ default boolean isConstraint() { return false; }
+
+ /**
+ * Can this be seen as a ReferenceTypeUsage?
+ * In other words: is this a reference to a class, an interface or an enum?
+ */
+ default boolean isReferenceType() {
+ return false;
+ }
+
+ default boolean isVoid() {
+ return false;
+ }
+
+ default boolean isTypeVariable() {
+ return false;
+ }
+
+ default boolean isWildcard() {
+ return false;
+ }
+
+ ///
+ /// Downcasting
+ ///
+
+ default ResolvedArrayType asArrayType() {
+ throw new UnsupportedOperationException(String.format("%s is not an Array", this));
+ }
+
+ default ResolvedReferenceType asReferenceType() {
+ throw new UnsupportedOperationException(String.format("%s is not a Reference Type", this));
+ }
+
+ default ResolvedTypeParameterDeclaration asTypeParameter() {
+ throw new UnsupportedOperationException(String.format("%s is not a Type parameter", this));
+ }
+
+ default ResolvedTypeVariable asTypeVariable() {
+ throw new UnsupportedOperationException(String.format("%s is not a Type variable", this));
+ }
+
+ default ResolvedPrimitiveType asPrimitive() {
+ throw new UnsupportedOperationException(String.format("%s is not a Primitive type", this));
+ }
+
+ default ResolvedWildcard asWildcard() {
+ throw new UnsupportedOperationException(String.format("%s is not a Wildcard", this));
+ }
+
+ default ResolvedLambdaConstraintType asConstraintType() {
+ throw new UnsupportedOperationException(String.format("%s is not a constraint type", this));
+ }
+
+ default ResolvedUnionType asUnionType() {
+ throw new UnsupportedOperationException(String.format("%s is not a union type", this));
+ }
+
+ ///
+ /// Naming
+ ///
+
+ String describe();
+
+ ///
+ /// TypeParameters
+ ///
+
+ /**
+ * Replace all variables referring to the given TypeParameter with the given value.
+ * By replacing these values I could also infer some type equivalence.
+ * Those would be collected in the given map.
+ */
+ default ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced, Map<ResolvedTypeParameterDeclaration, ResolvedType> inferredTypes) {
+ return this;
+ }
+
+ /**
+ * This is like ({@link #replaceTypeVariables(ResolvedTypeParameterDeclaration, ResolvedType, Map)} but ignores the inferred values.
+ */
+ default ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced) {
+ return replaceTypeVariables(tp, replaced, new HashMap<>());
+ }
+
+ /**
+ * Does this type mention at all, directly or indirectly, the given type parameters?
+ */
+ default boolean mention(List<ResolvedTypeParameterDeclaration> typeParameters) {
+ throw new UnsupportedOperationException(this.getClass().getCanonicalName());
+ }
+
+ ///
+ /// Assignability
+ ///
+
+ /**
+ * This method checks if ThisType t = new OtherType() would compile.
+ */
+ boolean isAssignableBy(ResolvedType other);
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java
new file mode 100644
index 000000000..a5eaebe7e
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+/**
+ * @author Federico Tomassetti
+ */
+@FunctionalInterface
+public interface ResolvedTypeTransformer {
+ ResolvedType transform(ResolvedType type);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java
new file mode 100644
index 000000000..5e91057b9
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeVariable.java
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * From JLS 4.4: A type variable is introduced by the declaration of a type parameter of a generic class,
+ * interface, method, or constructor (§8.1.2, §9.1.2, §8.4.4, §8.8.4).
+ *
+ * @author Federico Tomassetti
+ */
+public class ResolvedTypeVariable implements ResolvedType {
+
+ private ResolvedTypeParameterDeclaration typeParameter;
+
+ public ResolvedTypeVariable(ResolvedTypeParameterDeclaration typeParameter) {
+ this.typeParameter = typeParameter;
+ }
+
+ @Override
+ public String toString() {
+ return "TypeVariable {" + typeParameter.getQualifiedName() + "}";
+ }
+
+ public String qualifiedName() {
+ return this.typeParameter.getQualifiedName();
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ResolvedTypeVariable that = (ResolvedTypeVariable) o;
+
+ if (!typeParameter.getName().equals(that.typeParameter.getName())) return false;
+ if (typeParameter.declaredOnType() != that.typeParameter.declaredOnType()) return false;
+ if (typeParameter.declaredOnMethod() != that.typeParameter.declaredOnMethod()) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return typeParameter.hashCode();
+ }
+
+ @Override
+ public boolean isArray() {
+ return false;
+ }
+
+ @Override
+ public boolean isPrimitive() {
+ return false;
+ }
+
+ @Override
+ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToBeReplaced, ResolvedType replaced, Map<ResolvedTypeParameterDeclaration, ResolvedType> inferredTypes) {
+ if(tpToBeReplaced.getName().equals(this.typeParameter.getName())){
+ inferredTypes.put(this.asTypeParameter(), replaced);
+ return replaced;
+ } else {
+ return this;
+ }
+ }
+
+ @Override
+ public boolean isReferenceType() {
+ return false;
+ }
+
+ @Override
+ public String describe() {
+ return typeParameter.getName();
+ }
+
+ @Override
+ public ResolvedTypeParameterDeclaration asTypeParameter() {
+ return typeParameter;
+ }
+
+ @Override
+ public ResolvedTypeVariable asTypeVariable() {
+ return this;
+ }
+
+ @Override
+ public boolean isTypeVariable() {
+ return true;
+ }
+
+ @Override
+ public boolean isAssignableBy(ResolvedType other) {
+ if (other.isTypeVariable()) {
+ return describe().equals(other.describe());
+ } else {
+ return true;
+ }
+ }
+
+ @Override
+ public boolean mention(List<ResolvedTypeParameterDeclaration> typeParameters) {
+ return typeParameters.contains(typeParameter);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java
new file mode 100644
index 000000000..bd5361ac9
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedUnionType.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * A union type is defined in java as list of types separates by pipes.
+ *
+ * @author Federico Tomassetti
+ */
+public class ResolvedUnionType implements ResolvedType {
+ private List<ResolvedType> elements;
+
+ public ResolvedUnionType(List<ResolvedType> elements) {
+ if (elements.size() < 2) {
+ throw new IllegalArgumentException("An union type should have at least two elements. This has " + elements.size());
+ }
+ this.elements = new LinkedList<>(elements);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ ResolvedUnionType that = (ResolvedUnionType) o;
+
+ return new HashSet<>(elements).equals(new HashSet<>(that.elements));
+ }
+
+ @Override
+ public int hashCode() {
+ return new HashSet<>(elements).hashCode();
+ }
+
+ @Override
+ public String describe() {
+ return String.join(" | ", elements.stream().map(ResolvedType::describe).collect(Collectors.toList()));
+ }
+
+ @Override
+ public boolean isAssignableBy(ResolvedType other) {
+ return elements.stream().allMatch(e -> e.isAssignableBy(other));
+ }
+
+ @Override
+ public boolean isUnionType() {
+ return true;
+ }
+
+ @Override
+ public ResolvedUnionType asUnionType() {
+ return this;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java
new file mode 100644
index 000000000..b8f219453
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedVoidType.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+/**
+ * The special type void.
+ *
+ * @author Federico Tomassetti
+ */
+public class ResolvedVoidType implements ResolvedType {
+ public static final ResolvedType INSTANCE = new ResolvedVoidType();
+
+ private ResolvedVoidType() {
+ }
+
+ @Override
+ public String describe() {
+ return "void";
+ }
+
+ @Override
+ public boolean isAssignableBy(ResolvedType other) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public boolean isVoid() {
+ return true;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java
new file mode 100644
index 000000000..51fd099e4
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/ResolvedWildcard.java
@@ -0,0 +1,183 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types;
+
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A wildcard can be:
+ * - unbounded (?)
+ * - have a lower bound (? super Number)
+ * - have an upper bound (? extends Number)
+ * It is not possible to have both a lower and an upper bound at the same time.
+ *
+ * @author Federico Tomassetti
+ */
+public class ResolvedWildcard implements ResolvedType {
+
+ public static ResolvedWildcard UNBOUNDED = new ResolvedWildcard(null, null);
+
+ private BoundType type;
+ private ResolvedType boundedType;
+
+ private ResolvedWildcard(BoundType type, ResolvedType boundedType) {
+ if (type == null && boundedType != null) {
+ throw new IllegalArgumentException();
+ }
+ if (type != null && boundedType == null) {
+ throw new IllegalArgumentException();
+ }
+ this.type = type;
+ this.boundedType = boundedType;
+ }
+
+ public static ResolvedWildcard superBound(ResolvedType type) {
+ return new ResolvedWildcard(BoundType.SUPER, type);
+ }
+
+ public static ResolvedWildcard extendsBound(ResolvedType type) {
+ return new ResolvedWildcard(BoundType.EXTENDS, type);
+ }
+
+ @Override
+ public String toString() {
+ return "WildcardUsage{" +
+ "type=" + type +
+ ", boundedType=" + boundedType +
+ '}';
+ }
+
+ public boolean isWildcard() {
+ return true;
+ }
+
+ public ResolvedWildcard asWildcard() {
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ResolvedWildcard)) return false;
+
+ ResolvedWildcard that = (ResolvedWildcard) o;
+
+ if (boundedType != null ? !boundedType.equals(that.boundedType) : that.boundedType != null) return false;
+ if (type != that.type) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = type != null ? type.hashCode() : 0;
+ result = 31 * result + (boundedType != null ? boundedType.hashCode() : 0);
+ return result;
+ }
+
+ @Override
+ public String describe() {
+ if (type == null) {
+ return "?";
+ } else if (type == BoundType.SUPER) {
+ return "? super " + boundedType.describe();
+ } else if (type == BoundType.EXTENDS) {
+ return "? extends " + boundedType.describe();
+ } else {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public boolean isSuper() {
+ return type == BoundType.SUPER;
+ }
+
+ public boolean isExtends() {
+ return type == BoundType.EXTENDS;
+ }
+
+ public boolean isBounded() {
+ return isSuper() || isExtends();
+ }
+
+ public ResolvedType getBoundedType() {
+ if (boundedType == null) {
+ throw new IllegalStateException();
+ }
+ return boundedType;
+ }
+
+ @Override
+ public boolean isAssignableBy(ResolvedType other) {
+ if (boundedType == null) {
+ //return other.isReferenceType() && other.asReferenceType().getQualifiedName().equals(Object.class.getCanonicalName());
+ return false;
+ } else if (type == BoundType.SUPER) {
+ return boundedType.isAssignableBy(other);
+ } else if (type == BoundType.EXTENDS) {
+ return false;
+ } else {
+ throw new RuntimeException();
+ }
+ }
+
+ @Override
+ public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tpToReplace, ResolvedType replaced, Map<ResolvedTypeParameterDeclaration, ResolvedType> inferredTypes) {
+ if (replaced == null) {
+ throw new IllegalArgumentException();
+ }
+ if (boundedType == null) {
+ return this;
+ }
+ ResolvedType boundedTypeReplaced = boundedType.replaceTypeVariables(tpToReplace, replaced, inferredTypes);
+ if (boundedTypeReplaced == null) {
+ throw new RuntimeException();
+ }
+ if (boundedTypeReplaced != boundedType) {
+ return new ResolvedWildcard(type, boundedTypeReplaced);
+ } else {
+ return this;
+ }
+ }
+
+ @Override
+ public boolean mention(List<ResolvedTypeParameterDeclaration> typeParameters) {
+ return boundedType != null && boundedType.mention(typeParameters);
+ }
+
+ public boolean isUpperBounded() {
+ return isSuper();
+ }
+
+ public boolean isLowerBounded() {
+ return isExtends();
+ }
+
+ public enum BoundType {
+ SUPER,
+ EXTENDS
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java
new file mode 100644
index 000000000..c310fb5f7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types.parametrization;
+
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+import com.github.javaparser.resolution.types.ResolvedType;
+import com.github.javaparser.resolution.types.ResolvedWildcard;
+
+import java.util.Optional;
+
+/**
+ * @author Federico Tomassetti
+ */
+public interface ResolvedTypeParameterValueProvider {
+
+ /**
+ * Calculate the value for the given type parameter.
+ * It could be inherited.
+ */
+ Optional<ResolvedType> typeParamValue(ResolvedTypeParameterDeclaration typeParameterDeclaration);
+
+ /**
+ * Replace the type typeParametersValues present in the given type with the ones for which this type
+ * has a value.
+ */
+ default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) {
+ if (type.isTypeVariable()) {
+ ResolvedTypeParameterDeclaration typeParameter = type.asTypeParameter();
+ if (typeParameter.declaredOnType()) {
+ Optional<ResolvedType> typeParam = typeParamValue(typeParameter);
+ if (typeParam.isPresent()) {
+ type = typeParam.get();
+ }
+ }
+ }
+
+ if (type.isWildcard() && type.asWildcard().isBounded()) {
+ if (type.asWildcard().isExtends()) {
+ return ResolvedWildcard.extendsBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType()));
+ } else {
+ return ResolvedWildcard.superBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType()));
+ }
+ }
+
+ if (type.isReferenceType()) {
+ type = type.asReferenceType().transformTypeParameters(this::useThisTypeParametersOnTheGivenType);
+ }
+
+ return type;
+ }
+
+ Optional<ResolvedType> getGenericParameterByName(String name);
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java
new file mode 100644
index 000000000..b1cb16dae
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametersMap.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types.parametrization;
+
+import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
+import com.github.javaparser.resolution.types.ResolvedType;
+import com.github.javaparser.resolution.types.ResolvedTypeVariable;
+
+import java.util.*;
+
+/**
+ * A map of values associated to TypeParameters.
+ *
+ * @author Federico Tomassetti
+ */
+public class ResolvedTypeParametersMap {
+
+ public static class Builder {
+ private Map<String, ResolvedType> nameToValue;
+ private Map<String, ResolvedTypeParameterDeclaration> nameToDeclaration;
+
+ public Builder() {
+ nameToValue = new HashMap<>();
+ nameToDeclaration = new HashMap<>();
+ }
+
+ private Builder(Map<String, ResolvedType> nameToValue,
+ Map<String, ResolvedTypeParameterDeclaration> nameToDeclaration) {
+ this.nameToValue = new HashMap<>();
+ this.nameToValue.putAll(nameToValue);
+ this.nameToDeclaration = new HashMap<>();
+ this.nameToDeclaration.putAll(nameToDeclaration);
+ }
+
+ public ResolvedTypeParametersMap build() {
+ return new ResolvedTypeParametersMap(nameToValue, nameToDeclaration);
+ }
+
+ public Builder setValue(ResolvedTypeParameterDeclaration typeParameter,
+ ResolvedType value) {
+ // TODO: we shouldn't just silently overwrite existing types!
+ String qualifiedName = typeParameter.getQualifiedName();
+ nameToValue.put(qualifiedName, value);
+ nameToDeclaration.put(qualifiedName, typeParameter);
+ return this;
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ResolvedTypeParametersMap)) return false;
+
+ ResolvedTypeParametersMap that = (ResolvedTypeParametersMap) o;
+
+ return nameToValue.equals(that.nameToValue) && nameToDeclaration.equals(that.nameToDeclaration);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return nameToValue.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "TypeParametersMap{" +
+ "nameToValue=" + nameToValue +
+ '}';
+ }
+
+ private Map<String, ResolvedType> nameToValue;
+ private Map<String, ResolvedTypeParameterDeclaration> nameToDeclaration;
+
+ public static ResolvedTypeParametersMap empty() {
+ return new Builder().build();
+ }
+
+ private ResolvedTypeParametersMap(Map<String, ResolvedType> nameToValue,
+ Map<String, ResolvedTypeParameterDeclaration> nameToDeclaration) {
+ this.nameToValue = new HashMap<>();
+ this.nameToValue.putAll(nameToValue);
+ this.nameToDeclaration = new HashMap<>();
+ this.nameToDeclaration.putAll(nameToDeclaration);
+ }
+
+ public ResolvedType getValue(ResolvedTypeParameterDeclaration typeParameter) {
+ String qualifiedName = typeParameter.getQualifiedName();
+ if (nameToValue.containsKey(qualifiedName)) {
+ return nameToValue.get(qualifiedName);
+ } else {
+ return new ResolvedTypeVariable(typeParameter);
+ }
+ }
+
+ public Optional<ResolvedType> getValueBySignature(String signature) {
+ if (nameToValue.containsKey(signature)) {
+ return Optional.of(nameToValue.get(signature));
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ public List<String> getNames(){
+ return new ArrayList<>(nameToValue.keySet());
+ }
+
+ public List<ResolvedType> getTypes(){
+ return new ArrayList<>(nameToValue.values());
+ }
+
+ public Builder toBuilder() {
+ return new Builder(nameToValue, nameToDeclaration);
+ }
+
+ public boolean isEmpty() {
+ return nameToValue.isEmpty();
+ }
+
+ public ResolvedType replaceAll(ResolvedType type) {
+ Map<ResolvedTypeParameterDeclaration, ResolvedType> inferredTypes = new HashMap<>();
+ for (ResolvedTypeParameterDeclaration typeParameterDeclaration : this.nameToDeclaration.values()) {
+ type = type.replaceTypeVariables(typeParameterDeclaration, getValue(typeParameterDeclaration), inferredTypes);
+ }
+ return type;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java
new file mode 100644
index 000000000..91a792ab7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/resolution/types/parametrization/ResolvedTypeParametrized.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.resolution.types.parametrization;
+
+/**
+ * Something which can have values for TypeParameters.
+ *
+ * @author Federico Tomassetti
+ */
+public interface ResolvedTypeParametrized {
+ ResolvedTypeParametersMap typeParametersMap();
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java
new file mode 100644
index 000000000..b0bdf0538
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/ClassUtils.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ClassUtils {
+ /**
+ * Maps primitive {@code Class}es to their corresponding wrapper {@code Class}.
+ */
+ private static final Map<Class<?>, Class<?>> primitiveWrapperMap = new HashMap<>();
+
+ static {
+ primitiveWrapperMap.put(Boolean.TYPE, Boolean.class);
+ primitiveWrapperMap.put(Byte.TYPE, Byte.class);
+ primitiveWrapperMap.put(Character.TYPE, Character.class);
+ primitiveWrapperMap.put(Short.TYPE, Short.class);
+ primitiveWrapperMap.put(Integer.TYPE, Integer.class);
+ primitiveWrapperMap.put(Long.TYPE, Long.class);
+ primitiveWrapperMap.put(Double.TYPE, Double.class);
+ primitiveWrapperMap.put(Float.TYPE, Float.class);
+ primitiveWrapperMap.put(Void.TYPE, Void.TYPE);
+ }
+
+ /**
+ * Maps wrapper {@code Class}es to their corresponding primitive types.
+ */
+ private static final Map<Class<?>, Class<?>> wrapperPrimitiveMap = new HashMap<>();
+
+ static {
+ for (final Class<?> primitiveClass : primitiveWrapperMap.keySet()) {
+ final Class<?> wrapperClass = primitiveWrapperMap.get(primitiveClass);
+ if (!primitiveClass.equals(wrapperClass)) {
+ wrapperPrimitiveMap.put(wrapperClass, primitiveClass);
+ }
+ }
+ }
+
+ /**
+ * Returns whether the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte},
+ * {@link Character},
+ * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
+ *
+ * @param type The class to query or null.
+ * @return true if the given {@code type} is a primitive or primitive wrapper ({@link Boolean}, {@link Byte}, {@link
+ * Character}, {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
+ */
+ public static boolean isPrimitiveOrWrapper(final Class<?> type) {
+ if (type == null) {
+ return false;
+ }
+ return type.isPrimitive() || isPrimitiveWrapper(type);
+ }
+
+ /**
+ * Returns whether the given {@code type} is a primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character},
+ * {@link Short},
+ * {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
+ *
+ * @param type The class to query or null.
+ * @return true if the given {@code type} is a primitive wrapper ({@link Boolean}, {@link Byte}, {@link Character},
+ * {@link Short}, {@link Integer}, {@link Long}, {@link Double}, {@link Float}).
+ * @since 3.1
+ */
+ public static boolean isPrimitiveWrapper(final Class<?> type) {
+ return wrapperPrimitiveMap.containsKey(type);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java
new file mode 100644
index 000000000..098920b16
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/CodeGenerationUtils.java
@@ -0,0 +1,137 @@
+package com.github.javaparser.utils;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import static com.github.javaparser.utils.Utils.capitalize;
+import static com.github.javaparser.utils.Utils.decapitalize;
+
+public final class CodeGenerationUtils {
+ private CodeGenerationUtils() {
+ }
+
+ public static String getterName(Class<?> type, String name) {
+ if (name.startsWith("is")) {
+ return name;
+ } else if (type.equals(Boolean.class)) {
+ return "is" + capitalize(name);
+ }
+ return "get" + capitalize(name);
+ }
+
+ public static String getterToPropertyName(String getterName) {
+ if (getterName.startsWith("is")) {
+ return decapitalize(getterName.substring("is".length()));
+ } else if (getterName.startsWith("get")) {
+ return decapitalize(getterName.substring("get".length()));
+ } else if (getterName.startsWith("has")) {
+ return decapitalize(getterName.substring("has".length()));
+ }
+ throw new IllegalArgumentException("Unexpected getterName '" + getterName + "'");
+ }
+
+ public static String setterName(String fieldName) {
+ if (fieldName.startsWith("is")) {
+ return "set" + fieldName.substring(2);
+ }
+ return "set" + capitalize(fieldName);
+ }
+
+ public static String optionalOf(String text, boolean isOptional) {
+ if (isOptional) {
+ return f("Optional.of(%s)", text);
+ } else {
+ return "Optional.empty()";
+ }
+ }
+
+ /**
+ * A shortcut to String.format.
+ */
+ public static String f(String format, Object... params) {
+ return String.format(format, params);
+ }
+
+ /**
+ * Calculates the path to a file in a package.
+ *
+ * @param root the root directory in which the package resides
+ * @param pkg the package in which the file resides, like "com.laamella.parser"
+ * @param file the filename of the file in the package.
+ */
+ public static Path fileInPackageAbsolutePath(String root, String pkg, String file) {
+ pkg = packageToPath(pkg);
+ return Paths.get(root, pkg, file).normalize();
+ }
+
+ public static Path fileInPackageAbsolutePath(Path root, String pkg, String file) {
+ return fileInPackageAbsolutePath(root.toString(), pkg, file);
+ }
+
+ /**
+ * Turns a package and a file into a relative path. "com.laamella" and "Simple.java" will become
+ * "com/laamella/Simple.java"
+ */
+ public static Path fileInPackageRelativePath(String pkg, String file) {
+ pkg = packageToPath(pkg);
+ return Paths.get(pkg, file).normalize();
+ }
+
+ /**
+ * Converts a package name like "com.laamella.parser" to a path like "com/laamella/parser"
+ */
+ public static String packageToPath(String pkg) {
+ return pkg.replace(".", File.separator);
+ }
+
+ /**
+ * Calculates the path of a package.
+ *
+ * @param root the root directory in which the package resides
+ * @param pkg the package, like "com.laamella.parser"
+ */
+ public static Path packageAbsolutePath(String root, String pkg) {
+ pkg = packageToPath(pkg);
+ return Paths.get(root, pkg).normalize();
+ }
+
+ public static Path packageAbsolutePath(Path root, String pkg) {
+ return packageAbsolutePath(root.toString(), pkg);
+ }
+
+ /**
+ * @return the root directory of the classloader for class c.
+ */
+ public static Path classLoaderRoot(Class<?> c) {
+ try {
+ return Paths.get(c.getProtectionDomain().getCodeSource().getLocation().toURI());
+ } catch (URISyntaxException e) {
+ throw new AssertionError("Bug in JavaParser, please report.", e);
+ }
+ }
+
+ /**
+ * Useful for locating source code in your Maven project. Finds the classpath for class c, then backs up out of
+ * "target/(test-)classes", giving the directory containing the pom.xml.
+ */
+ public static Path mavenModuleRoot(Class<?> c) {
+ return classLoaderRoot(c).resolve(Paths.get("..", "..")).normalize();
+ }
+
+ /**
+ * Shortens path "full" by cutting "difference" off the end of it.
+ */
+ public static Path subtractPaths(Path full, Path difference) {
+ while (difference != null) {
+ if (difference.getFileName().equals(full.getFileName())) {
+ difference = difference.getParent();
+ full = full.getParent();
+ } else {
+ throw new RuntimeException(f("'%s' could not be subtracted from '%s'", difference, full));
+ }
+ }
+ return full;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java
new file mode 100644
index 000000000..12a9cdc85
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Log.java
@@ -0,0 +1,122 @@
+package com.github.javaparser.utils;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+
+/**
+ * To avoid dependencies on logging frameworks, we have invented yet another logging framework :-)
+ */
+public class Log {
+ /**
+ * This adapter logs to standard out and standard error.
+ */
+ public static class StandardOutStandardErrorAdapter implements Adapter {
+ @Override
+ public void info(String message) {
+ System.out.println(message);
+ }
+
+ @Override
+ public void trace(String message) {
+ System.out.println(message);
+ }
+
+ @Override
+ public void error(Throwable throwable, String message) {
+ if (message == null) {
+ System.err.println(throwable.getMessage());
+ printStackTrace(throwable);
+ } else if (throwable == null) {
+ System.err.println(message);
+ } else {
+ System.err.println(message + ":" + throwable.getMessage());
+ printStackTrace(throwable);
+ }
+ }
+
+ private void printStackTrace(Throwable throwable) {
+ try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) {
+ throwable.printStackTrace(pw);
+ trace(sw.toString());
+ } catch (IOException e) {
+ throw new AssertionError("Error in logging library");
+ }
+ }
+ }
+
+ /**
+ * This adapter logs nothing.
+ */
+ public static class SilentAdapter implements Adapter {
+ @Override
+ public void info(String message) {
+ }
+
+ @Override
+ public void trace(String message) {
+ }
+
+ @Override
+ public void error(Throwable throwable, String f) {
+ }
+ }
+
+ public interface Adapter {
+
+ void info(String message);
+
+ void trace(String message);
+
+ /**
+ * Both can be null.
+ */
+ void error(Throwable throwable, String f);
+ }
+
+ private static Adapter CURRENT_ADAPTER = new SilentAdapter();
+
+ /**
+ * Change how logging is handled. You can set your own implementation that forwards to your logging library.
+ */
+ public static void setAdapter(Adapter adapter) {
+ CURRENT_ADAPTER = adapter;
+ }
+
+ /**
+ * For logging information that may help solving a problem.
+ */
+ public static void trace(String format, Object... args) {
+ CURRENT_ADAPTER.trace(f(format, args));
+ }
+
+ /**
+ * For logging things that are nice to see scrolling by.
+ */
+ public static void info(String format, Object... args) {
+ CURRENT_ADAPTER.info(f(format, args));
+ }
+
+ /**
+ * For drawing attention to an error.
+ */
+ public static void error(Throwable throwable) {
+ CURRENT_ADAPTER.error(throwable, null);
+ }
+
+ /**
+ * For drawing attention to an error that you don't have an exception for.
+ */
+ public static void error(Throwable throwable, String format, Object... args) {
+ CURRENT_ADAPTER.error(throwable, f(format, args));
+ }
+
+ /**
+ * For drawing attention to an error that you don't have an exception for.
+ */
+ public static void error(String format, Object... args) {
+ CURRENT_ADAPTER.error(null, f(format, args));
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java
new file mode 100644
index 000000000..6f84a7ba2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Pair.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.utils;
+
+import static com.github.javaparser.utils.CodeGenerationUtils.f;
+
+/**
+ * Simply a pair of objects.
+ *
+ * @param <A> type of object a.
+ * @param <B> type of object b.
+ */
+public class Pair<A, B> {
+ public final A a;
+ public final B b;
+
+ public Pair(A a, B b) {
+ this.a = a;
+ this.b = b;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Pair<?, ?> pair = (Pair<?, ?>) o;
+
+ if (a != null ? !a.equals(pair.a) : pair.a != null) return false;
+ if (b != null ? !b.equals(pair.b) : pair.b != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = a != null ? a.hashCode() : 0;
+ return 31 * result + (b != null ? b.hashCode() : 0);
+ }
+
+ @Override
+ public String toString() {
+ return f("<%s, %s>", a, b);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java
new file mode 100644
index 000000000..6852b29c2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/PositionUtils.java
@@ -0,0 +1,153 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.utils;
+
+import com.github.javaparser.Position;
+import com.github.javaparser.Range;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
+import com.github.javaparser.ast.body.FieldDeclaration;
+import com.github.javaparser.ast.body.MethodDeclaration;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+import com.github.javaparser.ast.nodeTypes.NodeWithAnnotations;
+import com.github.javaparser.ast.nodeTypes.NodeWithType;
+import com.github.javaparser.ast.type.Type;
+
+import java.util.List;
+
+import static java.lang.Integer.signum;
+
+public final class PositionUtils {
+
+ private PositionUtils() {
+ // prevent instantiation
+ }
+
+ public static <T extends Node> void sortByBeginPosition(List<T> nodes) {
+ sortByBeginPosition(nodes, false);
+ }
+
+ public static <T extends Node> void sortByBeginPosition(NodeList<T> nodes) {
+ sortByBeginPosition(nodes, false);
+ }
+
+ public static <T extends Node> void sortByBeginPosition(List<T> nodes, final boolean ignoringAnnotations) {
+ nodes.sort((o1, o2) -> PositionUtils.compare(o1, o2, ignoringAnnotations));
+ }
+
+ public static boolean areInOrder(Node a, Node b) {
+ return areInOrder(a, b, false);
+ }
+
+ public static boolean areInOrder(Node a, Node b, boolean ignoringAnnotations) {
+ return compare(a, b, ignoringAnnotations) <= 0;
+ }
+
+ private static int compare(Node a, Node b, boolean ignoringAnnotations) {
+ if(a.getRange().isPresent() && !b.getRange().isPresent()) {
+ return -1;
+ }
+ if(!a.getRange().isPresent() && b.getRange().isPresent()) {
+ return 1;
+ }
+ if (!a.getRange().isPresent() && !b.getRange().isPresent()) {
+ return 0;
+ }
+ if (ignoringAnnotations) {
+ int signLine = signum(beginLineWithoutConsideringAnnotation(a) - beginLineWithoutConsideringAnnotation(b));
+ if (signLine == 0) {
+ return signum(beginColumnWithoutConsideringAnnotation(a) - beginColumnWithoutConsideringAnnotation(b));
+ } else {
+ return signLine;
+ }
+ }
+
+ Position aBegin = a.getBegin().get();
+ Position bBegin = b.getBegin().get();
+
+ int signLine = signum(aBegin.line - bBegin.line);
+ if (signLine == 0) {
+ return signum(aBegin.column - bBegin.column);
+ } else {
+ return signLine;
+ }
+ }
+
+ public static AnnotationExpr getLastAnnotation(Node node) {
+ if (node instanceof NodeWithAnnotations) {
+ NodeList<AnnotationExpr> annotations = NodeList.nodeList(((NodeWithAnnotations<?>) node).getAnnotations());
+ if (annotations.isEmpty()) {
+ return null;
+ }
+ sortByBeginPosition(annotations);
+ return annotations.get(annotations.size() - 1);
+ } else {
+ return null;
+ }
+ }
+
+ private static int beginLineWithoutConsideringAnnotation(Node node) {
+ return beginNodeWithoutConsideringAnnotations(node).getRange().get().begin.line;
+ }
+
+
+ private static int beginColumnWithoutConsideringAnnotation(Node node) {
+ return beginNodeWithoutConsideringAnnotations(node).getRange().get().begin.column;
+ }
+
+ private static Node beginNodeWithoutConsideringAnnotations(Node node) {
+ if (node instanceof MethodDeclaration || node instanceof FieldDeclaration) {
+ NodeWithType<?, Type> casted = (NodeWithType<?, Type>) node;
+ return casted.getType();
+ } else if (node instanceof ClassOrInterfaceDeclaration) {
+ ClassOrInterfaceDeclaration casted = (ClassOrInterfaceDeclaration) node;
+ return casted.getName();
+ } else {
+ return node;
+ }
+ }
+
+ public static boolean nodeContains(Node container, Node contained, boolean ignoringAnnotations) {
+ final Range containedRange = contained.getRange().get();
+ final Range containerRange = container.getRange().get();
+ if (!ignoringAnnotations || PositionUtils.getLastAnnotation(container) == null) {
+ return container.containsWithin(contained);
+ }
+ if (!container.containsWithin(contained)) {
+ return false;
+ }
+ // if the node is contained, but it comes immediately after the annotations,
+ // let's not consider it contained
+ if (container instanceof NodeWithAnnotations) {
+ int bl = beginLineWithoutConsideringAnnotation(container);
+ int bc = beginColumnWithoutConsideringAnnotation(container);
+ if (bl > containedRange.begin.line) return false;
+ if (bl == containedRange.begin.line && bc > containedRange.begin.column) return false;
+ if (containerRange.end.line < containedRange.end.line) return false;
+ // TODO < or <= ?
+ return !(containerRange.end.line == containedRange.end.line && containerRange.end.column < containedRange.end.column);
+ }
+ return true;
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java
new file mode 100644
index 000000000..3cef7237c
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SeparatedItemStringBuilder.java
@@ -0,0 +1,45 @@
+package com.github.javaparser.utils;
+
+/**
+ * Builds a string containing a list of items with a prefix, a postfix, and a separator.
+ * <br/>Example: (1,2,3) which has prefix "(", separator ",", postfix ")" and the items 1 through 3.
+ * <p/>Java 8 offers the very nice Collectors.joining(String, String, String) which does the same thing.
+ */
+public class SeparatedItemStringBuilder {
+ private final String separator;
+ private final String postfix;
+ private boolean hasItems = false;
+ private StringBuilder builder;
+
+ public SeparatedItemStringBuilder(String prefix, String separator, String postfix) {
+ builder = new StringBuilder(prefix);
+ this.separator = separator;
+ this.postfix = postfix;
+
+ }
+
+ /**
+ * Add one item. Either pass a string, or a format for String.format and corresponding arguments.
+ */
+ public SeparatedItemStringBuilder append(CharSequence format, Object... args) {
+ if (hasItems) {
+ builder.append(separator);
+ }
+ builder.append(String.format(format.toString(), args));
+ hasItems = true;
+ return this;
+ }
+
+ public boolean hasItems() {
+ return hasItems;
+ }
+
+ /**
+ * Convert the builder into its final string representation.
+ */
+ @Override
+ public String toString() {
+ // This order of toStringing avoids debuggers from making a mess.
+ return builder.toString() + postfix;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java
new file mode 100644
index 000000000..02a90ffec
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceRoot.java
@@ -0,0 +1,577 @@
+package com.github.javaparser.utils;
+
+import com.github.javaparser.JavaParser;
+import com.github.javaparser.ParseProblemException;
+import com.github.javaparser.ParseResult;
+import com.github.javaparser.ParserConfiguration;
+import com.github.javaparser.ast.CompilationUnit;
+import com.github.javaparser.printer.PrettyPrinter;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.RecursiveAction;
+import java.util.function.Function;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
+import static com.github.javaparser.Providers.provider;
+import static com.github.javaparser.utils.CodeGenerationUtils.fileInPackageRelativePath;
+import static com.github.javaparser.utils.CodeGenerationUtils.packageAbsolutePath;
+import static com.github.javaparser.utils.SourceRoot.Callback.Result.SAVE;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+import static java.nio.file.FileVisitResult.CONTINUE;
+import static java.nio.file.FileVisitResult.SKIP_SUBTREE;
+
+/**
+ * A collection of Java source files located in one directory and its subdirectories on the file system. Files can be
+ * parsed and written back one by one or all together. <b>Note that</b> the internal cache used is thread-safe.
+ * <ul>
+ * <li>methods called "tryToParse..." will return their result inside a "ParseResult", which supports parse successes and failures.</li>
+ * <li>methods called "parse..." will return "CompilationUnit"s. If a file fails to parse, an exception is thrown.</li>
+ * <li>methods ending in "...Parallelized" will speed up parsing by using multiple threads.</li>
+ * </ul>
+ */
+public class SourceRoot {
+ @FunctionalInterface
+ public interface Callback {
+ enum Result {
+ SAVE, DONT_SAVE
+ }
+
+ /**
+ * @param localPath the path to the file that was parsed, relative to the source root path.
+ * @param absolutePath the absolute path to the file that was parsed.
+ * @param result the result of of parsing the file.
+ */
+ Result process(Path localPath, Path absolutePath, ParseResult<CompilationUnit> result);
+ }
+
+ private final Path root;
+ private final Map<Path, ParseResult<CompilationUnit>> cache = new ConcurrentHashMap<>();
+ private ParserConfiguration parserConfiguration = new ParserConfiguration();
+ private Function<CompilationUnit, String> printer = new PrettyPrinter()::print;
+ private static final Pattern JAVA_IDENTIFIER = Pattern.compile("\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*");
+
+ public SourceRoot(Path root) {
+ assertNotNull(root);
+ if (!Files.isDirectory(root)) {
+ throw new IllegalArgumentException("Only directories are allowed as root path!");
+ }
+ this.root = root.normalize();
+ Log.info("New source root at \"%s\"", this.root);
+ }
+
+ public SourceRoot(Path root, ParserConfiguration parserConfiguration) {
+ this(root);
+ setParserConfiguration(parserConfiguration);
+ }
+
+ /**
+ * Tries to parse a .java files under the source root and returns the ParseResult. It keeps track of the parsed file
+ * so you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you
+ * don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you
+ * might want to use the parse method with a callback.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ * @deprecated pass ParserConfiguration instead of JavaParser
+ */
+ @Deprecated
+ public ParseResult<CompilationUnit> tryToParse(String startPackage, String filename, JavaParser javaParser)
+ throws IOException {
+ return tryToParse(startPackage, filename, javaParser.getParserConfiguration());
+ }
+
+ /**
+ * Tries to parse a .java files under the source root and returns the ParseResult. It keeps track of the parsed file
+ * so you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you
+ * don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you
+ * might want to use the parse method with a callback.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ */
+ public ParseResult<CompilationUnit> tryToParse(String startPackage, String filename, ParserConfiguration configuration) throws IOException {
+ assertNotNull(startPackage);
+ assertNotNull(filename);
+ final Path relativePath = fileInPackageRelativePath(startPackage, filename);
+ if (cache.containsKey(relativePath)) {
+ Log.trace("Retrieving cached %s", relativePath);
+ return cache.get(relativePath);
+ }
+ final Path path = root.resolve(relativePath);
+ Log.trace("Parsing %s", path);
+ final ParseResult<CompilationUnit> result = new JavaParser(configuration)
+ .parse(COMPILATION_UNIT, provider(path));
+ result.getResult().ifPresent(cu -> cu.setStorage(path));
+ cache.put(relativePath, result);
+ return result;
+ }
+
+ /**
+ * Tries to parse a .java files under the source root and returns the ParseResult. It keeps track of the parsed file
+ * so you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you
+ * don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you
+ * might want to use the parse method with a callback.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ */
+ public ParseResult<CompilationUnit> tryToParse(String startPackage, String filename) throws IOException {
+ return tryToParse(startPackage, filename, parserConfiguration);
+ }
+
+ /**
+ * Tries to parse all .java files in a package recursively, and returns all files ever parsed with this source root.
+ * It keeps track of all parsed files so you can write them out with a single saveAll() call. Note that the cache
+ * grows with every file parsed, so if you don't need saveAll(), or you don't ask SourceRoot to parse files multiple
+ * times (where the cache is useful) you might want to use the parse method with a callback.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ */
+ public List<ParseResult<CompilationUnit>> tryToParse(String startPackage) throws IOException {
+ assertNotNull(startPackage);
+ logPackage(startPackage);
+ final Path path = packageAbsolutePath(root, startPackage);
+ Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ if (!attrs.isDirectory() && file.toString().endsWith(".java")) {
+ Path relative = root.relativize(file.getParent());
+ tryToParse(relative.toString(), file.getFileName().toString());
+ }
+ return CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
+ return isSensibleDirectoryToEnter(dir) ? CONTINUE : SKIP_SUBTREE;
+ }
+ });
+ return getCache();
+ }
+
+ private static boolean isSensibleDirectoryToEnter(Path dir) throws IOException {
+ final String dirToEnter = dir.getFileName().toString();
+ final boolean directoryIsAValidJavaIdentifier = JAVA_IDENTIFIER.matcher(dirToEnter).matches();
+ if (Files.isHidden(dir) || !directoryIsAValidJavaIdentifier) {
+ Log.trace("Not processing directory \"%s\"", dirToEnter);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Tries to parse all .java files under the source root recursively, and returns all files ever parsed with this
+ * source root. It keeps track of all parsed files so you can write them out with a single saveAll() call. Note that
+ * the cache grows with every file parsed, so if you don't need saveAll(), or you don't ask SourceRoot to parse
+ * files multiple times (where the cache is useful) you might want to use the parse method with a callback.
+ */
+ public List<ParseResult<CompilationUnit>> tryToParse() throws IOException {
+ return tryToParse("");
+ }
+
+ /**
+ * Tries to parse all .java files in a package recursively using multiple threads, and returns all files ever parsed
+ * with this source root. A new thread is forked each time a new directory is visited and is responsible for parsing
+ * all .java files in that directory. <b>Note that</b> to ensure thread safety, a new parser instance is created for
+ * every file with the internal parser's (i.e. {@link #setJavaParser}) configuration. It keeps track of all parsed
+ * files so you can write them out with a single saveAll() call. Note that the cache grows with every file parsed,
+ * so if you don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is
+ * useful) you might want to use the parse method with a callback.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ */
+ public List<ParseResult<CompilationUnit>> tryToParseParallelized(String startPackage) {
+ assertNotNull(startPackage);
+ logPackage(startPackage);
+ final Path path = packageAbsolutePath(root, startPackage);
+ ParallelParse parse = new ParallelParse(path, (file, attrs) -> {
+ if (!attrs.isDirectory() && file.toString().endsWith(".java")) {
+ Path relative = root.relativize(file.getParent());
+ try {
+ tryToParse(
+ relative.toString(),
+ file.getFileName().toString(),
+ parserConfiguration);
+ } catch (IOException e) {
+ Log.error(e);
+ }
+ }
+ return CONTINUE;
+ });
+ ForkJoinPool pool = new ForkJoinPool();
+ pool.invoke(parse);
+ return getCache();
+ }
+
+ /**
+ * Tries to parse all .java files under the source root recursively using multiple threads, and returns all files
+ * ever parsed with this source root. A new thread is forked each time a new directory is visited and is responsible
+ * for parsing all .java files in that directory. <b>Note that</b> to ensure thread safety, a new parser instance is
+ * created for every file with the internal parser's (i.e. {@link #setJavaParser}) configuration. It keeps track of
+ * all parsed files so you can write them out with a single saveAll() call. Note that the cache grows with every
+ * file parsed, so if you don't need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the
+ * cache is useful) you might want to use the parse method with a callback.
+ */
+ public List<ParseResult<CompilationUnit>> tryToParseParallelized() throws IOException {
+ return tryToParseParallelized("");
+ }
+
+ /**
+ * Parses a .java files under the source root and returns its CompilationUnit. It keeps track of the parsed file so
+ * you can write it out with the saveAll() call. Note that the cache grows with every file parsed, so if you don't
+ * need saveAll(), or you don't ask SourceRoot to parse files multiple times (where the cache is useful) you might
+ * want to use the parse method with a callback.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ * @throws ParseProblemException when something went wrong.
+ */
+ public CompilationUnit parse(String startPackage, String filename) {
+ assertNotNull(startPackage);
+ assertNotNull(filename);
+ try {
+ final ParseResult<CompilationUnit> result = tryToParse(startPackage, filename);
+ if (result.isSuccessful()) {
+ return result.getResult().get();
+ }
+ throw new ParseProblemException(result.getProblems());
+ } catch (IOException e) {
+ throw new ParseProblemException(e);
+ }
+ }
+
+ /**
+ * Tries to parse all .java files in a package recursively and passes them one by one to the callback. In comparison
+ * to the other parse methods, this is much more memory efficient, but saveAll() won't work.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ * @deprecated pass ParserConfiguration instead of JavaParser
+ */
+ @Deprecated
+ public SourceRoot parse(String startPackage, JavaParser javaParser, Callback callback) throws IOException {
+ return parse(startPackage, javaParser.getParserConfiguration(), callback);
+ }
+
+ /**
+ * Tries to parse all .java files in a package recursively and passes them one by one to the callback. In comparison
+ * to the other parse methods, this is much more memory efficient, but saveAll() won't work.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ */
+ public SourceRoot parse(String startPackage, ParserConfiguration configuration, Callback callback) throws IOException {
+ assertNotNull(startPackage);
+ assertNotNull(configuration);
+ assertNotNull(callback);
+ logPackage(startPackage);
+ final JavaParser javaParser = new JavaParser(configuration);
+ final Path path = packageAbsolutePath(root, startPackage);
+ Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path absolutePath, BasicFileAttributes attrs) throws IOException {
+ if (!attrs.isDirectory() && absolutePath.toString().endsWith(".java")) {
+ Path localPath = root.relativize(absolutePath);
+ Log.trace("Parsing %s", localPath);
+ final ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT,
+ provider(absolutePath));
+ result.getResult().ifPresent(cu -> cu.setStorage(absolutePath));
+ if (callback.process(localPath, absolutePath, result) == SAVE) {
+ if (result.getResult().isPresent()) {
+ save(result.getResult().get(), path);
+ }
+ }
+ }
+ return CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
+ return isSensibleDirectoryToEnter(dir) ? CONTINUE : SKIP_SUBTREE;
+ }
+ });
+ return this;
+ }
+
+ private void logPackage(String startPackage) {
+ if (startPackage.isEmpty()) {
+ return;
+ }
+ Log.info("Parsing package \"%s\"", startPackage);
+ }
+
+ /**
+ * Tries to parse all .java files in a package recursively using multiple threads, and passes them one by one to the
+ * callback. A new thread is forked each time a new directory is visited and is responsible for parsing all .java
+ * files in that directory. <b>Note that</b> the provided {@link Callback} code must be made thread-safe. <b>Note
+ * that</b> to ensure thread safety, a new parser instance is created for every file with the provided {@link
+ * ParserConfiguration}. In comparison to the other parse methods, this is much more memory efficient, but saveAll()
+ * won't work.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ */
+ public SourceRoot parseParallelized(String startPackage, ParserConfiguration configuration, Callback callback) {
+ assertNotNull(startPackage);
+ assertNotNull(configuration);
+ assertNotNull(callback);
+ logPackage(startPackage);
+ final Path path = packageAbsolutePath(root, startPackage);
+ ParallelParse parse = new ParallelParse(path, (file, attrs) -> {
+ if (!attrs.isDirectory() && file.toString().endsWith(".java")) {
+ Path localPath = root.relativize(file);
+ Log.trace("Parsing %s", localPath);
+ try {
+ ParseResult<CompilationUnit> result = new JavaParser(configuration)
+ .parse(COMPILATION_UNIT, provider(file));
+ result.getResult().ifPresent(cu -> cu.setStorage(file));
+ if (callback.process(localPath, file, result) == SAVE) {
+ if (result.getResult().isPresent()) {
+ save(result.getResult().get(), path);
+ }
+ }
+ } catch (IOException e) {
+ Log.error(e);
+ }
+ }
+ return CONTINUE;
+ });
+ ForkJoinPool pool = new ForkJoinPool();
+ pool.invoke(parse);
+ return this;
+ }
+
+ /**
+ * Tries to parse all .java files in a package recursively using multiple threads, and passes them one by one to the
+ * callback. A new thread is forked each time a new directory is visited and is responsible for parsing all .java
+ * files in that directory. <b>Note that</b> the provided {@link Callback} code must be made thread-safe. <b>Note
+ * that</b> to ensure thread safety, a new parser instance is created for every file. In comparison to the other
+ * parse methods, this is much more memory efficient, but saveAll() won't work.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ */
+ public SourceRoot parseParallelized(String startPackage, Callback callback) throws IOException {
+ return parseParallelized(startPackage, new ParserConfiguration(), callback);
+ }
+
+ /**
+ * Tries to parse all .java files recursively using multiple threads, and passes them one by one to the callback. A
+ * new thread is forked each time a new directory is visited and is responsible for parsing all .java files in that
+ * directory. <b>Note that</b> the provided {@link Callback} code must be made thread-safe. <b>Note that</b> to
+ * ensure thread safety, a new parser instance is created for every file. In comparison to the other parse methods,
+ * this is much more memory efficient, but saveAll() won't work.
+ */
+ public SourceRoot parseParallelized(Callback callback) throws IOException {
+ return parseParallelized("", new ParserConfiguration(), callback);
+ }
+
+ /**
+ * Add a newly created Java file to the cache of this source root. It will be saved when saveAll is called.
+ *
+ * @param startPackage files in this package and deeper are parsed. Pass "" to parse all files.
+ */
+ public SourceRoot add(String startPackage, String filename, CompilationUnit compilationUnit) {
+ assertNotNull(startPackage);
+ assertNotNull(filename);
+ assertNotNull(compilationUnit);
+ Log.trace("Adding new file %s.%s", startPackage, filename);
+ final Path path = fileInPackageRelativePath(startPackage, filename);
+ final ParseResult<CompilationUnit> parseResult = new ParseResult<>(
+ compilationUnit,
+ new ArrayList<>(),
+ null,
+ null);
+ cache.put(path, parseResult);
+ return this;
+ }
+
+ /**
+ * Add a newly created Java file to the cache of this source root. It will be saved when saveAll is called. It needs
+ * to have its path set.
+ */
+ public SourceRoot add(CompilationUnit compilationUnit) {
+ assertNotNull(compilationUnit);
+ if (compilationUnit.getStorage().isPresent()) {
+ final Path path = compilationUnit.getStorage().get().getPath();
+ Log.trace("Adding new file %s", path);
+ final ParseResult<CompilationUnit> parseResult = new ParseResult<>(
+ compilationUnit,
+ new ArrayList<>(),
+ null,
+ null);
+ cache.put(path, parseResult);
+ } else {
+ throw new AssertionError("Files added with this method should have their path set.");
+ }
+ return this;
+ }
+
+ /**
+ * Save the given compilation unit to the given path.
+ */
+ private SourceRoot save(CompilationUnit cu, Path path) {
+ assertNotNull(cu);
+ assertNotNull(path);
+ cu.setStorage(path);
+ cu.getStorage().get().save(printer);
+ return this;
+ }
+
+ /**
+ * Save all previously parsed files back to a new path.
+ */
+ public SourceRoot saveAll(Path root) {
+ assertNotNull(root);
+ Log.info("Saving all files (%s) to %s", cache.size(), root);
+ for (Map.Entry<Path, ParseResult<CompilationUnit>> cu : cache.entrySet()) {
+ final Path path = root.resolve(cu.getKey());
+ if (cu.getValue().getResult().isPresent()) {
+ Log.trace("Saving %s", path);
+ save(cu.getValue().getResult().get(), path);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Save all previously parsed files back to where they were found.
+ */
+ public SourceRoot saveAll() {
+ return saveAll(root);
+ }
+
+ /**
+ * The Java files that have been parsed by this source root object, or have been added manually.
+ */
+ public List<ParseResult<CompilationUnit>> getCache() {
+ return new ArrayList<>(cache.values());
+ }
+
+ /**
+ * The CompilationUnits of the Java files that have been parsed succesfully by this source root object, or have been
+ * added manually.
+ */
+ public List<CompilationUnit> getCompilationUnits() {
+ return cache.values().stream()
+ .filter(ParseResult::isSuccessful)
+ .map(p -> p.getResult().get())
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * The path that was passed in the constructor.
+ */
+ public Path getRoot() {
+ return root;
+ }
+
+ /**
+ * @deprecated store ParserConfiguration now
+ */
+ @Deprecated
+ public JavaParser getJavaParser() {
+ return new JavaParser(parserConfiguration);
+ }
+
+ /**
+ * Set the parser that is used for parsing by default.
+ *
+ * @deprecated store ParserConfiguration now
+ */
+ @Deprecated
+ public SourceRoot setJavaParser(JavaParser javaParser) {
+ assertNotNull(javaParser);
+ this.parserConfiguration = javaParser.getParserConfiguration();
+ return this;
+ }
+
+ public ParserConfiguration getParserConfiguration() {
+ return parserConfiguration;
+ }
+
+ /**
+ * Set the parser configuration that is used for parsing when no configuration is passed to a method.
+ */
+ public SourceRoot setParserConfiguration(ParserConfiguration parserConfiguration) {
+ assertNotNull(parserConfiguration);
+ this.parserConfiguration = parserConfiguration;
+ return this;
+ }
+
+ /**
+ * Set the printing function that transforms compilation units into a string to save.
+ */
+ public SourceRoot setPrinter(Function<CompilationUnit, String> printer) {
+ assertNotNull(printer);
+ this.printer = printer;
+ return this;
+ }
+
+ /**
+ * Get the printing function.
+ */
+ public Function<CompilationUnit, String> getPrinter() {
+ return printer;
+ }
+
+ /**
+ * Executes a recursive file tree walk using threads. A new thread is invoked for each new directory discovered
+ * during the walk. For each file visited, the user-provided {@link VisitFileCallback} is called with the current
+ * path and file attributes. Any shared resources accessed in a {@link VisitFileCallback} should be made
+ * thread-safe.
+ */
+ private static class ParallelParse extends RecursiveAction {
+
+ private static final long serialVersionUID = 1L;
+ private final Path path;
+ private final VisitFileCallback callback;
+
+ ParallelParse(Path path, VisitFileCallback callback) {
+ this.path = path;
+ this.callback = callback;
+ }
+
+ @Override
+ protected void compute() {
+ final List<ParallelParse> walks = new ArrayList<>();
+ try {
+ Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
+ if (!SourceRoot.isSensibleDirectoryToEnter(dir)) {
+ return SKIP_SUBTREE;
+ }
+ if (!dir.equals(ParallelParse.this.path)) {
+ ParallelParse w = new ParallelParse(dir, callback);
+ w.fork();
+ walks.add(w);
+ return SKIP_SUBTREE;
+ } else {
+ return CONTINUE;
+ }
+ }
+
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
+ return callback.process(file, attrs);
+ }
+ });
+ } catch (IOException e) {
+ Log.error(e);
+ }
+
+ for (ParallelParse w : walks) {
+ w.join();
+ }
+ }
+
+ interface VisitFileCallback {
+ FileVisitResult process(Path file, BasicFileAttributes attrs);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java
new file mode 100644
index 000000000..ffb64f4a4
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/SourceZip.java
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.utils;
+
+import com.github.javaparser.JavaParser;
+import com.github.javaparser.ParseResult;
+import com.github.javaparser.ParserConfiguration;
+import com.github.javaparser.ast.CompilationUnit;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import static com.github.javaparser.ParseStart.COMPILATION_UNIT;
+import static com.github.javaparser.Providers.provider;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * A collection of Java source files and its sub-directories located in a ZIP or JAR file on the file system.
+ * Files can be parsed with a callback.
+ *
+ */
+public class SourceZip {
+
+ private final Path zipPath;
+ private ParserConfiguration parserConfiguration;
+
+ /**
+ * Create a new ZIP parser. An instance of {@link JavaParser} with the default {@link ParserConfiguration} will be
+ * used to parse the ZIP.
+ *
+ * @param zipPath The absolute path of ZIP file to parse.
+ */
+ public SourceZip(Path zipPath) {
+ this(zipPath, new ParserConfiguration());
+ }
+
+ /**
+ * Create a new ZIP parser. An instance of {@link JavaParser} with the given configuration will be used to parse
+ * the ZIP.
+ *
+ * @param zipPath The absolute path of ZIP file to parse.
+ * @param configuration The configuration to initiate the default parser with.
+ */
+ public SourceZip(Path zipPath, ParserConfiguration configuration) {
+ assertNotNull(zipPath);
+ assertNotNull(configuration);
+ this.zipPath = zipPath.normalize();
+ this.parserConfiguration = configuration;
+ Log.info("New source zip at \"%s\"", this.zipPath);
+ }
+
+ /**
+ * Tries to parse all '.java' files in the ZIP located at this <i>SourceZip</i>'s path and returns the parse
+ * results in a list.
+ *
+ * @return A list of path-compilation unit pairs.
+ *
+ * @throws IOException If an error occurs while trying to parse the given source.
+ */
+ public List<Pair<Path, ParseResult<CompilationUnit>>> parse() throws IOException {
+ Log.info("Parsing zip at \"%s\"", zipPath);
+ List<Pair<Path, ParseResult<CompilationUnit>>> results = new ArrayList<>();
+ parse((path, result) -> results.add(new Pair<>(path, result)));
+ return results;
+ }
+
+ /**
+ * Tries to parse all '.java' files in the ZIP located at this <i>SourceZip</i>'s path and returns the parse
+ * results in a list.
+ *
+ * @return A list of path-compilation unit pairs.
+ *
+ * @throws IOException If an error occurs while trying to parse the given source.
+ */
+ public SourceZip parse(Callback callback) throws IOException {
+ Log.info("Parsing zip at \"%s\"", zipPath);
+ JavaParser javaParser = new JavaParser(parserConfiguration);
+ try (ZipFile zipFile = new ZipFile(zipPath.toFile())) {
+ for (ZipEntry entry : Collections.list(zipFile.entries())) {
+ if (!entry.isDirectory() && entry.getName().endsWith(".java")) {
+ Log.info("Parsing zip entry \"%s\"", entry.getName());
+ final ParseResult<CompilationUnit> result = javaParser.parse(COMPILATION_UNIT,
+ provider(zipFile.getInputStream(entry)));
+ callback.process(Paths.get(entry.getName()), result);
+ }
+ }
+ }
+ return this;
+ }
+
+ /**
+ * An interface to define a callback for each file that's parsed.
+ */
+ @FunctionalInterface
+ public interface Callback {
+
+ /**
+ * Process the given parse result.
+ *
+ * @param relativeZipEntryPath The relative path of the entry in the ZIP file that was parsed.
+ * @param result The parse result of file located at <i>absolutePath</i>.
+ */
+ void process(Path relativeZipEntryPath, ParseResult<CompilationUnit> result);
+ }
+
+ /**
+ * Get the path of the ZIP file to be parsed.
+ *
+ * @return The absolute path of this ZIP file.
+ */
+ public Path getZipPath() {
+ return zipPath;
+ }
+
+ /**
+ * @deprecated store ParserConfiguration now
+ */
+ @Deprecated
+ public JavaParser getJavaParser() {
+ return new JavaParser(parserConfiguration);
+ }
+
+ /**
+ * Set the parser that is used for parsing by default.
+ *
+ * @deprecated store ParserConfiguration now
+ */
+ @Deprecated
+ public SourceZip setJavaParser(JavaParser javaParser) {
+ assertNotNull(javaParser);
+ this.parserConfiguration = javaParser.getParserConfiguration();
+ return this;
+ }
+
+ public ParserConfiguration getParserConfiguration() {
+ return parserConfiguration;
+ }
+
+ public SourceZip setParserConfiguration(ParserConfiguration parserConfiguration) {
+ assertNotNull(parserConfiguration);
+ this.parserConfiguration = parserConfiguration;
+ return this;
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java
new file mode 100644
index 000000000..a9732b906
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/StringEscapeUtils.java
@@ -0,0 +1,435 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.github.javaparser.utils;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.HashSet;
+
+/**
+ * Adapted from apache commons-lang3 project.
+ * <p>
+ * Unescapes escaped chars in strings.
+ */
+public class StringEscapeUtils {
+
+ private StringEscapeUtils() {
+ }
+
+ /**
+ * <p>Escapes the characters in a {@code String} using Java String rules.</p>
+ * <p>
+ * <p>Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.) </p>
+ * <p>
+ * <p>So a tab becomes the characters {@code '\\'} and
+ * {@code 't'}.</p>
+ * <p>
+ * <p>The only difference between Java strings and JavaScript strings
+ * is that in JavaScript, a single quote and forward-slash (/) are escaped.</p>
+ * <p>
+ * <p>Example:</p>
+ * <pre>
+ * input string: He didn't say, "Stop!"
+ * output string: He didn't say, \"Stop!\"
+ * </pre>
+ *
+ * @param input String to escape values in, may be null
+ * @return String with escaped values, {@code null} if null string input
+ */
+ public static String escapeJava(final String input) {
+ return ESCAPE_JAVA.translate(input);
+ }
+
+ /**
+ * <p>Unescapes any Java literals found in the {@code String}.
+ * For example, it will turn a sequence of {@code '\'} and
+ * {@code 'n'} into a newline character, unless the {@code '\'}
+ * is preceded by another {@code '\'}.</p>
+ *
+ * @param input the {@code String} to unescape, may be null
+ * @return a new unescaped {@code String}, {@code null} if null string input
+ */
+ public static String unescapeJava(final String input) {
+ return UNESCAPE_JAVA.translate(input);
+ }
+
+ private static final String[][] JAVA_CTRL_CHARS_UNESCAPE = {
+ {"\\b", "\b"},
+ {"\\n", "\n"},
+ {"\\t", "\t"},
+ {"\\f", "\f"},
+ {"\\r", "\r"}
+ };
+
+ private static final String[][] JAVA_CTRL_CHARS_ESCAPE = {
+ {"\b", "\\b"},
+ {"\n", "\\n"},
+ {"\t", "\\t"},
+ {"\f", "\\f"},
+ {"\r", "\\r"}
+ };
+
+ private static final CharSequenceTranslator ESCAPE_JAVA =
+ new AggregateTranslator(
+ new LookupTranslator(
+ new String[][]{
+ {"\"", "\\\""},
+ {"\\", "\\\\"},
+ }),
+ new LookupTranslator(JAVA_CTRL_CHARS_ESCAPE.clone())
+ );
+
+ private static final CharSequenceTranslator UNESCAPE_JAVA =
+ new AggregateTranslator(
+ new OctalUnescaper(),
+ new UnicodeUnescaper(),
+ new LookupTranslator(JAVA_CTRL_CHARS_UNESCAPE.clone()),
+ new LookupTranslator(
+ new String[][]{
+ {"\\\\", "\\"},
+ {"\\\"", "\""},
+ {"\\'", "'"},
+ {"\\", ""}
+ })
+ );
+
+ /**
+ * Adapted from apache commons-lang3 project.
+ * <p>
+ * An API for translating text.
+ * Its core use is to escape and unescape text. Because escaping and unescaping
+ * is completely contextual, the API does not present two separate signatures.
+ *
+ * @since 3.0
+ */
+ private static abstract class CharSequenceTranslator {
+
+ /**
+ * Translate a set of codepoints, represented by an int index into a CharSequence,
+ * into another set of codepoints. The number of codepoints consumed must be returned,
+ * and the only IOExceptions thrown must be from interacting with the Writer so that
+ * the top level API may reliably ignore StringWriter IOExceptions.
+ *
+ * @param input CharSequence that is being translated
+ * @param index int representing the current point of translation
+ * @param out Writer to translate the text to
+ * @return int count of codepoints consumed
+ * @throws IOException if and only if the Writer produces an IOException
+ */
+ public abstract int translate(CharSequence input, int index, Writer out) throws IOException;
+
+ /**
+ * Helper for non-Writer usage.
+ *
+ * @param input CharSequence to be translated
+ * @return String output of translation
+ */
+ public final String translate(final CharSequence input) {
+ if (input == null) {
+ return null;
+ }
+ try {
+ final StringWriter writer = new StringWriter(input.length() * 2);
+ translate(input, writer);
+ return writer.toString();
+ } catch (final IOException ioe) {
+ // this should never ever happen while writing to a StringWriter
+ throw new RuntimeException(ioe);
+ }
+ }
+
+ /**
+ * Translate an input onto a Writer. This is intentionally final as its algorithm is
+ * tightly coupled with the abstract method of this class.
+ *
+ * @param input CharSequence that is being translated
+ * @param out Writer to translate the text to
+ * @throws IOException if and only if the Writer produces an IOException
+ */
+ public final void translate(final CharSequence input, final Writer out) throws IOException {
+ if (out == null) {
+ throw new IllegalArgumentException("The Writer must not be null");
+ }
+ if (input == null) {
+ return;
+ }
+ int pos = 0;
+ final int len = input.length();
+ while (pos < len) {
+ final int consumed = translate(input, pos, out);
+ if (consumed == 0) {
+ // inlined implementation of Character.toChars(Character.codePointAt(input, pos))
+ // avoids allocating temp char arrays and duplicate checks
+ char c1 = input.charAt(pos);
+ out.write(c1);
+ pos++;
+ if (Character.isHighSurrogate(c1) && pos < len) {
+ char c2 = input.charAt(pos);
+ if (Character.isLowSurrogate(c2)) {
+ out.write(c2);
+ pos++;
+ }
+ }
+ continue;
+ }
+ // contract with translators is that they have to understand codepoints
+ // and they just took care of a surrogate pair
+ for (int pt = 0; pt < consumed; pt++) {
+ pos += Character.charCount(Character.codePointAt(input, pos));
+ }
+ }
+ }
+
+ /**
+ * Helper method to create a merger of this translator with another set of
+ * translators. Useful in customizing the standard functionality.
+ *
+ * @param translators CharSequenceTranslator array of translators to merge with this one
+ * @return CharSequenceTranslator merging this translator with the others
+ */
+ public final CharSequenceTranslator with(final CharSequenceTranslator... translators) {
+ final CharSequenceTranslator[] newArray = new CharSequenceTranslator[translators.length + 1];
+ newArray[0] = this;
+ System.arraycopy(translators, 0, newArray, 1, translators.length);
+ return new AggregateTranslator(newArray);
+ }
+
+ }
+
+ /**
+ * Adapted from apache commons-lang3 project.
+ * <p>
+ * Translates a value using a lookup table.
+ *
+ * @since 3.0
+ */
+ private static class LookupTranslator extends CharSequenceTranslator {
+
+ private final HashMap<String, String> lookupMap;
+ private final HashSet<Character> prefixSet;
+ private final int shortest;
+ private final int longest;
+
+ /**
+ * Define the lookup table to be used in translation
+ * <p>
+ * Note that, as of Lang 3.1, the key to the lookup table is converted to a
+ * java.lang.String. This is because we need the key to support hashCode and
+ * equals(Object), allowing it to be the key for a HashMap. See LANG-882.
+ *
+ * @param lookup CharSequence[][] table of size [*][2]
+ */
+ public LookupTranslator(final CharSequence[]... lookup) {
+ lookupMap = new HashMap<>();
+ prefixSet = new HashSet<>();
+ int _shortest = Integer.MAX_VALUE;
+ int _longest = 0;
+ if (lookup != null) {
+ for (final CharSequence[] seq : lookup) {
+ this.lookupMap.put(seq[0].toString(), seq[1].toString());
+ this.prefixSet.add(seq[0].charAt(0));
+ final int sz = seq[0].length();
+ if (sz < _shortest) {
+ _shortest = sz;
+ }
+ if (sz > _longest) {
+ _longest = sz;
+ }
+ }
+ }
+ shortest = _shortest;
+ longest = _longest;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
+ // check if translation exists for the input at position index
+ if (prefixSet.contains(input.charAt(index))) {
+ int max = longest;
+ if (index + longest > input.length()) {
+ max = input.length() - index;
+ }
+ // implement greedy algorithm by trying maximum match first
+ for (int i = max; i >= shortest; i--) {
+ final CharSequence subSeq = input.subSequence(index, index + i);
+ final String result = lookupMap.get(subSeq.toString());
+
+ if (result != null) {
+ out.write(result);
+ return i;
+ }
+ }
+ }
+ return 0;
+ }
+ }
+
+ /**
+ * Adapted from apache commons-lang3 project.
+ * <p>
+ * Executes a sequence of translators one after the other. Execution ends whenever
+ * the first translator consumes codepoints from the input.
+ *
+ * @since 3.0
+ */
+ private static class AggregateTranslator extends CharSequenceTranslator {
+
+ private final CharSequenceTranslator[] translators;
+
+ /**
+ * Specify the translators to be used at creation time.
+ *
+ * @param translators CharSequenceTranslator array to aggregate
+ */
+ public AggregateTranslator(final CharSequenceTranslator... translators) {
+ this.translators = translators == null ? null : translators.clone();
+ }
+
+ /**
+ * The first translator to consume codepoints from the input is the 'winner'.
+ * Execution stops with the number of consumed codepoints being returned.
+ * {@inheritDoc}
+ */
+ @Override
+ public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
+ for (final CharSequenceTranslator translator : translators) {
+ final int consumed = translator.translate(input, index, out);
+ if (consumed != 0) {
+ return consumed;
+ }
+ }
+ return 0;
+ }
+
+ }
+
+ /**
+ * Adapted from apache commons-lang3 project.
+ * <p>
+ * Translate escaped octal Strings back to their octal values.
+ * <p>
+ * For example, "\45" should go back to being the specific value (a %).
+ * <p>
+ * Note that this currently only supports the viable range of octal for Java; namely
+ * 1 to 377. This is because parsing Java is the main use case.
+ *
+ * @since 3.0
+ */
+ private static class OctalUnescaper extends CharSequenceTranslator {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
+ final int remaining = input.length() - index - 1; // how many characters left, ignoring the first \
+ final StringBuilder builder = new StringBuilder();
+ if (input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index + 1))) {
+ final int next = index + 1;
+ final int next2 = index + 2;
+ final int next3 = index + 3;
+
+ // we know this is good as we checked it in the if block above
+ builder.append(input.charAt(next));
+
+ if (remaining > 1 && isOctalDigit(input.charAt(next2))) {
+ builder.append(input.charAt(next2));
+ if (remaining > 2 && isZeroToThree(input.charAt(next)) && isOctalDigit(input.charAt(next3))) {
+ builder.append(input.charAt(next3));
+ }
+ }
+
+ out.write(Integer.parseInt(builder.toString(), 8));
+ return 1 + builder.length();
+ }
+ return 0;
+ }
+
+ /**
+ * Checks if the given char is an octal digit. Octal digits are the character representations of the digits 0 to
+ * 7.
+ *
+ * @param ch the char to check
+ * @return true if the given char is the character representation of one of the digits from 0 to 7
+ */
+ private boolean isOctalDigit(final char ch) {
+ return ch >= '0' && ch <= '7';
+ }
+
+ /**
+ * Checks if the given char is the character representation of one of the digit from 0 to 3.
+ *
+ * @param ch the char to check
+ * @return true if the given char is the character representation of one of the digits from 0 to 3
+ */
+ private boolean isZeroToThree(final char ch) {
+ return ch >= '0' && ch <= '3';
+ }
+ }
+
+ /**
+ * Adapted from apache commons-lang3 project.
+ * <p>
+ * Translates escaped Unicode values of the form \\u+\d\d\d\d back to
+ * Unicode. It supports multiple 'u' characters and will work with or
+ * without the +.
+ *
+ * @since 3.0
+ */
+ private static class UnicodeUnescaper extends CharSequenceTranslator {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int translate(final CharSequence input, final int index, final Writer out) throws IOException {
+ if (input.charAt(index) == '\\' && index + 1 < input.length() && input.charAt(index + 1) == 'u') {
+ // consume optional additional 'u' chars
+ int i = 2;
+ while (index + i < input.length() && input.charAt(index + i) == 'u') {
+ i++;
+ }
+
+ if (index + i < input.length() && input.charAt(index + i) == '+') {
+ i++;
+ }
+
+ if (index + i + 4 <= input.length()) {
+ // Get 4 hex digits
+ final CharSequence unicode = input.subSequence(index + i, index + i + 4);
+
+ try {
+ final int value = Integer.parseInt(unicode.toString(), 16);
+ out.write((char) value);
+ } catch (final NumberFormatException nfe) {
+ throw new IllegalArgumentException("Unable to parse unicode value: " + unicode, nfe);
+ }
+ return i + 4;
+ }
+ throw new IllegalArgumentException("Less than 4 hex digits in unicode value: '" + input.subSequence(index, input.length())
+ + "' due to end of CharSequence");
+ }
+ return 0;
+ }
+ }
+
+} \ No newline at end of file
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java
new file mode 100644
index 000000000..2db00e522
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/Utils.java
@@ -0,0 +1,253 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.utils;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.util.*;
+import java.util.function.Predicate;
+import java.util.function.Function;
+
+import static java.util.Arrays.*;
+
+/**
+ * Any kind of utility.
+ *
+ * @author Federico Tomassetti
+ */
+public class Utils {
+ public static final String EOL = System.getProperty("line.separator");
+
+ public static final Predicate<String> STRING_NOT_EMPTY = s -> !s.isEmpty();
+
+ /**
+ * @deprecated This is no longer in use by JavaParser, please write your own replacement.
+ */
+ public static <T> List<T> ensureNotNull(List<T> list) {
+ return list == null ? new ArrayList<>() : list;
+ }
+
+ public static <E> boolean isNullOrEmpty(Collection<E> collection) {
+ return collection == null || collection.isEmpty();
+ }
+
+ public static <T> T assertNotNull(T o) {
+ if (o == null) {
+ throw new AssertionError("A reference was unexpectedly null.");
+ }
+ return o;
+ }
+
+ public static String assertNonEmpty(String string) {
+ if (string == null || string.isEmpty()) {
+ throw new AssertionError("A string was unexpectedly empty.");
+ }
+ return string;
+ }
+
+ /**
+ * @return string with ASCII characters 10 and 13 replaced by the text "\n" and "\r".
+ */
+ public static String escapeEndOfLines(String string) {
+ StringBuilder escapedString = new StringBuilder();
+ for (char c : string.toCharArray()) {
+ switch (c) {
+ case '\n':
+ escapedString.append("\\n");
+ break;
+ case '\r':
+ escapedString.append("\\r");
+ break;
+ default:
+ escapedString.append(c);
+ }
+ }
+ return escapedString.toString();
+ }
+
+ public static String readerToString(Reader reader) throws IOException {
+ final StringBuilder result = new StringBuilder();
+ final char[] buffer = new char[8 * 1024];
+ int numChars;
+
+ while ((numChars = reader.read(buffer, 0, buffer.length)) > 0) {
+ result.append(buffer, 0, numChars);
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Puts varargs in a mutable list.
+ * This does not have the disadvantage of Arrays#asList that it has a static size.
+ *
+ * @deprecated This is no longer in use by JavaParser, please write your own replacement.
+ */
+ @Deprecated
+ public static <T> List<T> arrayToList(T[] array) {
+ List<T> list = new LinkedList<>();
+ Collections.addAll(list, array);
+ return list;
+ }
+
+ /**
+ * @deprecated use screamingToCamelCase
+ */
+ public static String toCamelCase(String original) {
+ return screamingToCamelCase(original);
+ }
+
+ /**
+ * Transform a string to the camel case conversion.
+ * <p>
+ * For example "ABC_DEF" becomes "abcDef"
+ */
+ public static String screamingToCamelCase(String original) {
+ StringBuilder sb = new StringBuilder();
+ String[] parts = original.toLowerCase().split("_");
+ for (int i = 0; i < parts.length; i++) {
+ sb.append(i == 0 ? parts[i] : capitalize(parts[i]));
+ }
+ return sb.toString();
+ }
+
+
+ /**
+ * @param input "aCamelCaseString"
+ * @return "A_CAMEL_CASE_STRING"
+ */
+ public static String camelCaseToScreaming(String input) {
+ if (input.isEmpty()) {
+ return "";
+ }
+ StringBuilder scream = new StringBuilder(input.substring(0, 1).toUpperCase());
+ for (char c : input.substring(1).toCharArray()) {
+ if (Character.isUpperCase(c)) {
+ scream.append("_");
+ }
+ scream.append(Character.toUpperCase(c));
+ }
+ return scream.toString();
+ }
+
+ /**
+ * Return the next word of the string, in other words it stops when a space is encountered.
+ */
+ public static String nextWord(String string) {
+ int index = 0;
+ while (index < string.length() && !Character.isWhitespace(string.charAt(index))) {
+ index++;
+ }
+ return string.substring(0, index);
+ }
+
+ /**
+ * Make an indent by appending indentLevel tab characters to the builder.
+ */
+ public static StringBuilder indent(StringBuilder builder, int indentLevel) {
+ for (int i = 0; i < indentLevel; i++) {
+ builder.append("\t");
+ }
+ return builder;
+ }
+
+ /**
+ * Capitalizes the first character in the string.
+ */
+ public static String capitalize(String s) {
+ return stringTransformer(s, "capitalize", String::toUpperCase);
+ }
+
+ /**
+ * Lower-cases the first character in the string.
+ */
+ public static String decapitalize(String s) {
+ return stringTransformer(s, "decapitalize", String::toLowerCase);
+ }
+
+ private static String stringTransformer(String s, String operationDescription, Function<String, String> transformation) {
+ if (s.isEmpty()) {
+ throw new IllegalArgumentException(String.format("You cannot %s an empty string", operationDescription));
+ }
+ return transformation.apply(s.substring(0, 1)) +
+ s.substring(1);
+ }
+
+ /**
+ * @return true if the value is null, an empty Optional, or an empty String.
+ */
+ public static boolean valueIsNullOrEmpty(Object value) {
+ if (value == null) {
+ return true;
+ }
+ if (value instanceof Optional) {
+ if (((Optional) value).isPresent()) {
+ value = ((Optional) value).get();
+ } else {
+ return true;
+ }
+ }
+ if (value instanceof Collection) {
+ if (((Collection) value).isEmpty()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @return a set of the items.
+ */
+ public static <T> Set<T> set(T... items) {
+ return new HashSet<>(asList(items));
+ }
+
+ /**
+ * @return content with all kinds of EOL characters replaced by endOfLineCharacter
+ */
+ public static String normalizeEolInTextBlock(String content, String endOfLineCharacter) {
+ return content
+ .replaceAll("\\R", endOfLineCharacter);
+ }
+
+ /**
+ * @return the filename with the last "." and everything following it removed.
+ */
+ public static String removeFileExtension(String filename) {
+ int extensionIndex = filename.lastIndexOf(".");
+ if (extensionIndex == -1)
+ return filename;
+
+ return filename.substring(0, extensionIndex);
+ }
+
+ /**
+ * Like {@link String#trim()}, but only the trailing spaces.
+ */
+ public static String trimTrailingSpaces(String line) {
+ while (line.length() > 0 && line.charAt(line.length() - 1) <= 0x20) {
+ line = line.substring(0, line.length() - 1);
+ }
+ return line;
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java
new file mode 100644
index 000000000..ea21787c2
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorList.java
@@ -0,0 +1,303 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.stream.Collectors;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.Visitable;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+
+/**
+ * A list that overrides the equals and hashcode calculation of the added nodes
+ * by using another equals and hashcode visitor for those methods.
+ */
+public class VisitorList<N extends Node> implements List<N> {
+
+ protected List<EqualsHashcodeOverridingFacade> innerList;
+ protected final GenericVisitor<Integer, Void> hashcodeVisitor;
+ protected final GenericVisitor<Boolean, Visitable> equalsVisitor;
+
+ /**
+ * Pass the visitors to use for equals and hashcode.
+ */
+ public VisitorList(GenericVisitor<Integer, Void> hashcodeVisitor,
+ GenericVisitor<Boolean, Visitable> equalsVisitor) {
+ this.hashcodeVisitor = hashcodeVisitor;
+ this.equalsVisitor = equalsVisitor;
+ innerList = new ArrayList<>();
+ }
+
+ @Override
+ public boolean add(N elem) {
+ return innerList.add(new EqualsHashcodeOverridingFacade(elem));
+ }
+
+ @Override
+ public void add(int index, N elem) {
+ innerList.add(index, new EqualsHashcodeOverridingFacade(elem));
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends N> col) {
+ boolean modified = false;
+ for (N elem : col)
+ if (add(elem))
+ modified = true;
+ return modified;
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends N> col) {
+ if (col.isEmpty())
+ return false;
+ for (N elem : col) {
+ if (index == size())
+ add(elem);
+ else
+ add(index, elem);
+ index++;
+ }
+ return true;
+ }
+
+ @Override
+ public void clear() {
+ innerList.clear();
+ }
+
+ @Override
+ public boolean contains(Object elem) {
+ return innerList.contains(new EqualsHashcodeOverridingFacade((N) elem));
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> col) {
+ for (Object elem : col)
+ if (!contains(elem))
+ return false;
+ return true;
+ }
+
+ @Override
+ public N get(int index) {
+ return innerList.get(index).overridden;
+ }
+
+ @Override
+ public int indexOf(Object elem) {
+ return innerList.indexOf(new EqualsHashcodeOverridingFacade((N) elem));
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return innerList.isEmpty();
+ }
+
+ @Override
+ public Iterator<N> iterator() {
+ return new Iterator<N>() {
+ final Iterator<EqualsHashcodeOverridingFacade> itr = innerList.iterator();
+
+ @Override
+ public boolean hasNext() {
+ return itr.hasNext();
+ }
+
+ @Override
+ public N next() {
+ return itr.next().overridden;
+ }
+
+ @Override
+ public void remove() {
+ itr.remove();
+ }
+ };
+ }
+
+ @Override
+ public int lastIndexOf(Object elem) {
+ return innerList.lastIndexOf(new EqualsHashcodeOverridingFacade((N) elem));
+ }
+
+ @Override
+ public ListIterator<N> listIterator() {
+ return listIterator(0);
+ }
+
+ @Override
+ public ListIterator<N> listIterator(int index) {
+ return new ListIterator<N>() {
+ final ListIterator<EqualsHashcodeOverridingFacade> itr = innerList.listIterator(index);
+
+ @Override
+ public boolean hasNext() {
+ return itr.hasNext();
+ }
+
+ @Override
+ public N next() {
+ return itr.next().overridden;
+ }
+
+ @Override
+ public void remove() {
+ itr.remove();
+ }
+
+ @Override
+ public void add(N elem) {
+ itr.add(new EqualsHashcodeOverridingFacade((N) elem));
+ }
+
+ @Override
+ public boolean hasPrevious() {
+ return itr.hasPrevious();
+ }
+
+ @Override
+ public int nextIndex() {
+ return itr.nextIndex();
+ }
+
+ @Override
+ public N previous() {
+ return itr.previous().overridden;
+ }
+
+ @Override
+ public int previousIndex() {
+ return itr.previousIndex();
+ }
+
+ @Override
+ public void set(N elem) {
+ itr.set(new EqualsHashcodeOverridingFacade((N) elem));
+ }
+ };
+ }
+
+ @Override
+ public boolean remove(Object elem) {
+ return innerList.remove(new EqualsHashcodeOverridingFacade((N) elem));
+ }
+
+ @Override
+ public N remove(int index) {
+ return innerList.remove(index).overridden;
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> col) {
+ boolean modified = false;
+ for (Object elem : col)
+ if (remove(elem))
+ modified = true;
+ return modified;
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> col) {
+ int oldSize = size();
+ clear();
+ addAll((Collection<? extends N>) col);
+ return size() != oldSize;
+ }
+
+ @Override
+ public N set(int index, N elem) {
+ return innerList.set(index, new EqualsHashcodeOverridingFacade((N) elem)).overridden;
+ }
+
+ @Override
+ public int size() {
+ return innerList.size();
+ }
+
+ @Override
+ public List<N> subList(int fromIndex, int toIndex) {
+ return new VisitorList<N>(hashcodeVisitor, equalsVisitor) {
+ {
+ this.innerList = VisitorList.this.innerList.subList(fromIndex, toIndex);
+ }
+ };
+ }
+
+ @Override
+ public Object[] toArray() {
+ return innerList.stream().map(facade -> facade.overridden).collect(Collectors.toList()).toArray();
+ }
+
+ @Override
+ public <T> T[] toArray(T[] arr) {
+ return innerList.stream().map(facade -> facade.overridden).collect(Collectors.toList()).toArray(arr);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("[");
+ if (size() == 0)
+ return sb.append("]").toString();
+ for (EqualsHashcodeOverridingFacade facade : innerList) {
+ sb.append(facade.overridden.toString() + ", ");
+ }
+ return sb.replace(sb.length() - 2, sb.length(), "]").toString();
+ }
+
+ private class EqualsHashcodeOverridingFacade implements Visitable {
+ private final N overridden;
+
+ EqualsHashcodeOverridingFacade(N overridden) {
+ this.overridden = overridden;
+ }
+
+ @Override
+ public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public <A> void accept(VoidVisitor<A> v, A arg) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public final int hashCode() {
+ return overridden.accept(hashcodeVisitor, null);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null || !(obj instanceof VisitorList.EqualsHashcodeOverridingFacade)) {
+ return false;
+ }
+ return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden);
+ }
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java
new file mode 100644
index 000000000..ab21b9178
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorMap.java
@@ -0,0 +1,125 @@
+package com.github.javaparser.utils;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.Visitable;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * A map that overrides the equals and hashcode calculation of the added nodes
+ * by using another equals and hashcode visitor for those methods.
+ */
+public class VisitorMap<N extends Node, V> implements Map<N, V> {
+ private final Map<EqualsHashcodeOverridingFacade, V> innerMap = new HashMap<>();
+ private final GenericVisitor<Integer, Void> hashcodeVisitor;
+ private final GenericVisitor<Boolean, Visitable> equalsVisitor;
+
+ /**
+ * Pass the visitors to use for equals and hashcode.
+ */
+ public VisitorMap(GenericVisitor<Integer, Void> hashcodeVisitor, GenericVisitor<Boolean, Visitable> equalsVisitor) {
+ this.hashcodeVisitor = hashcodeVisitor;
+ this.equalsVisitor = equalsVisitor;
+ }
+
+ @Override
+ public int size() {
+ return innerMap.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return innerMap.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(Object key) {
+ return innerMap.containsKey(new EqualsHashcodeOverridingFacade((N) key));
+ }
+
+ @Override
+ public boolean containsValue(Object value) {
+ return innerMap.containsValue(value);
+ }
+
+ @Override
+ public V get(Object key) {
+ return innerMap.get(new EqualsHashcodeOverridingFacade((N) key));
+ }
+
+ @Override
+ public V put(N key, V value) {
+ return innerMap.put(new EqualsHashcodeOverridingFacade(key), value);
+ }
+
+ private class EqualsHashcodeOverridingFacade implements Visitable {
+ private final N overridden;
+
+ EqualsHashcodeOverridingFacade(N overridden) {
+ this.overridden = overridden;
+ }
+
+ @Override
+ public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public <A> void accept(VoidVisitor<A> v, A arg) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public final int hashCode() {
+ return overridden.accept(hashcodeVisitor, null);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null || !(obj instanceof VisitorMap.EqualsHashcodeOverridingFacade)) {
+ return false;
+ }
+ return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden);
+ }
+ }
+
+ @Override
+ public V remove(Object key) {
+ return innerMap.remove(new EqualsHashcodeOverridingFacade((N) key));
+ }
+
+ @Override
+ public void putAll(Map<? extends N, ? extends V> m) {
+ m.forEach(this::put);
+ }
+
+ @Override
+ public void clear() {
+ innerMap.clear();
+ }
+
+ @Override
+ public Set<N> keySet() {
+ return innerMap.keySet().stream()
+ .map(k -> k.overridden)
+ .collect(Collectors.toSet());
+ }
+
+ @Override
+ public Collection<V> values() {
+ return innerMap.values();
+ }
+
+ @Override
+ public Set<Entry<N, V>> entrySet() {
+ return innerMap.entrySet().stream()
+ .map(e -> new HashMap.SimpleEntry<>(e.getKey().overridden, e.getValue()))
+ .collect(Collectors.toSet());
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java
new file mode 100644
index 000000000..70fc358c7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/utils/VisitorSet.java
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+package com.github.javaparser.utils;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.visitor.GenericVisitor;
+import com.github.javaparser.ast.visitor.Visitable;
+import com.github.javaparser.ast.visitor.VoidVisitor;
+
+/**
+ * A set that overrides the equals and hashcode calculation of the added nodes
+ * by using another equals and hashcode visitor for those methods.
+ */
+public class VisitorSet<N extends Node> implements Set<N> {
+
+ private final Set<EqualsHashcodeOverridingFacade> innerSet = new HashSet<>();
+ private final GenericVisitor<Integer, Void> hashcodeVisitor;
+ private final GenericVisitor<Boolean, Visitable> equalsVisitor;
+
+ /**
+ * Pass the visitors to use for equals and hashcode.
+ */
+ public VisitorSet(GenericVisitor<Integer, Void> hashcodeVisitor, GenericVisitor<Boolean, Visitable> equalsVisitor) {
+ this.hashcodeVisitor = hashcodeVisitor;
+ this.equalsVisitor = equalsVisitor;
+ }
+
+ @Override
+ public boolean add(N elem) {
+ return innerSet.add(new EqualsHashcodeOverridingFacade(elem));
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends N> col) {
+ boolean modified = false;
+ for (N elem : col)
+ if (add(elem))
+ modified = true;
+ return modified;
+ }
+
+ @Override
+ public void clear() {
+ innerSet.clear();
+ }
+
+ @Override
+ public boolean contains(Object elem) {
+ return innerSet.contains(new EqualsHashcodeOverridingFacade((N) elem));
+ }
+
+ @Override
+ public boolean containsAll(Collection<?> col) {
+ for (Object elem : col)
+ if (!contains(elem))
+ return false;
+ return true;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return innerSet.isEmpty();
+ }
+
+ @Override
+ public Iterator<N> iterator() {
+ return new Iterator<N>() {
+ final Iterator<EqualsHashcodeOverridingFacade> itr = innerSet.iterator();
+
+ @Override
+ public boolean hasNext() {
+ return itr.hasNext();
+ }
+
+ @Override
+ public N next() {
+ return itr.next().overridden;
+ }
+
+ @Override
+ public void remove() {
+ itr.remove();
+ }
+ };
+ }
+
+ @Override
+ public boolean remove(Object elem) {
+ return innerSet.remove(new EqualsHashcodeOverridingFacade((N) elem));
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> col) {
+ boolean modified = false;
+ for (Object elem : col)
+ if (remove(elem))
+ modified = true;
+ return modified;
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> col) {
+ int oldSize = size();
+ clear();
+ addAll((Collection<? extends N>) col);
+ return size() != oldSize;
+ }
+
+ @Override
+ public int size() {
+ return innerSet.size();
+ }
+
+ @Override
+ public Object[] toArray() {
+ return innerSet.stream().map(facade -> facade.overridden).collect(Collectors.toList()).toArray();
+ }
+
+ @Override
+ public <T> T[] toArray(T[] arr) {
+ return innerSet.stream().map(facade -> facade.overridden).collect(Collectors.toList()).toArray(arr);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("[");
+ if (size() == 0)
+ return sb.append("]").toString();
+ for (EqualsHashcodeOverridingFacade facade : innerSet) {
+ sb.append(facade.overridden.toString() + ",");
+ }
+ return sb.replace(sb.length() - 2, sb.length(), "]").toString();
+ }
+
+ private class EqualsHashcodeOverridingFacade implements Visitable {
+ private final N overridden;
+
+ EqualsHashcodeOverridingFacade(N overridden) {
+ this.overridden = overridden;
+ }
+
+ @Override
+ public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public <A> void accept(VoidVisitor<A> v, A arg) {
+ throw new AssertionError();
+ }
+
+ @Override
+ public final int hashCode() {
+ return overridden.accept(hashcodeVisitor, null);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == null || !(obj instanceof VisitorSet.EqualsHashcodeOverridingFacade)) {
+ return false;
+ }
+ return overridden.accept(equalsVisitor, ((EqualsHashcodeOverridingFacade) obj).overridden);
+ }
+ }
+
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/version/Java10PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/version/Java10PostProcessor.java
new file mode 100644
index 000000000..7130870e7
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/version/Java10PostProcessor.java
@@ -0,0 +1,24 @@
+package com.github.javaparser.version;
+
+import com.github.javaparser.ast.type.ClassOrInterfaceType;
+import com.github.javaparser.ast.type.VarType;
+
+import static com.github.javaparser.ParseResult.PostProcessor;
+
+/**
+ * Processes the generic AST into a Java 10 AST and validates it.
+ */
+public class Java10PostProcessor extends PostProcessors {
+ protected final PostProcessor varNodeCreator = (result, configuration) ->
+ result.getResult().ifPresent(node -> {
+ node.findAll(ClassOrInterfaceType.class).forEach(n -> {
+ if (n.getNameAsString().equals("var")) {
+ n.replace(new VarType(n.getTokenRange().orElse(null)));
+ }
+ });
+ });
+
+ public Java10PostProcessor() {
+ add(varNodeCreator);
+ }
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/version/Java11PostProcessor.java b/javaparser-core/src/main/java/com/github/javaparser/version/Java11PostProcessor.java
new file mode 100644
index 000000000..004967edd
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/version/Java11PostProcessor.java
@@ -0,0 +1,7 @@
+package com.github.javaparser.version;
+
+/**
+ * Processes the generic AST into a Java 10 AST and validates it.
+ */
+public class Java11PostProcessor extends Java10PostProcessor {
+}
diff --git a/javaparser-core/src/main/java/com/github/javaparser/version/PostProcessors.java b/javaparser-core/src/main/java/com/github/javaparser/version/PostProcessors.java
new file mode 100644
index 000000000..4220de341
--- /dev/null
+++ b/javaparser-core/src/main/java/com/github/javaparser/version/PostProcessors.java
@@ -0,0 +1,49 @@
+package com.github.javaparser.version;
+
+import com.github.javaparser.ParseResult;
+import com.github.javaparser.ParserConfiguration;
+import com.github.javaparser.ast.Node;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static com.github.javaparser.ParseResult.PostProcessor;
+
+/**
+ * A post processor that will call a collection of post processors.
+ */
+public class PostProcessors implements PostProcessor {
+ private final List<PostProcessor> postProcessors = new ArrayList<>();
+
+ public PostProcessors(PostProcessor... postProcessors) {
+ this.postProcessors.addAll(Arrays.asList(postProcessors));
+ }
+
+ public List<PostProcessor> getPostProcessors() {
+ return postProcessors;
+ }
+
+ public PostProcessors remove(PostProcessor postProcessor) {
+ if (!postProcessors.remove(postProcessor)) {
+ throw new AssertionError("Trying to remove a post processor that isn't there.");
+ }
+ return this;
+ }
+
+ public PostProcessors replace(PostProcessor oldProcessor, PostProcessor newProcessor) {
+ remove(oldProcessor);
+ add(newProcessor);
+ return this;
+ }
+
+ public PostProcessors add(PostProcessor newProcessor) {
+ postProcessors.add(newProcessor);
+ return this;
+ }
+
+ @Override
+ public void process(ParseResult<? extends Node> result, ParserConfiguration configuration) {
+ postProcessors.forEach(pp -> pp.process(result, configuration));
+ }
+}
diff --git a/javaparser-core/src/main/javacc-support/com/github/javaparser/GeneratedJavaParserBase.java b/javaparser-core/src/main/javacc-support/com/github/javaparser/GeneratedJavaParserBase.java
new file mode 100644
index 000000000..ef0b7efd4
--- /dev/null
+++ b/javaparser-core/src/main/javacc-support/com/github/javaparser/GeneratedJavaParserBase.java
@@ -0,0 +1,369 @@
+package com.github.javaparser;
+
+import com.github.javaparser.ast.ArrayCreationLevel;
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.body.Parameter;
+import com.github.javaparser.ast.comments.CommentsCollection;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.stmt.Statement;
+import com.github.javaparser.ast.type.ArrayType;
+import com.github.javaparser.ast.type.Type;
+import com.github.javaparser.ast.type.UnknownType;
+import com.github.javaparser.utils.Pair;
+
+import java.util.*;
+
+import static com.github.javaparser.GeneratedJavaParserConstants.EOF;
+import static com.github.javaparser.ast.type.ArrayType.unwrapArrayTypes;
+import static com.github.javaparser.ast.type.ArrayType.wrapInArrayTypes;
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * Base class for {@link GeneratedJavaParser}
+ */
+abstract class GeneratedJavaParserBase {
+ //// Interface with the generated code
+ abstract GeneratedJavaParserTokenManager getTokenSource();
+
+ abstract void ReInit(Provider provider);
+
+ /* Returns the JavaParser specific token type of the last matched token */
+ abstract JavaToken token();
+
+ abstract Token getNextToken();
+
+ ////
+
+ /* The problems encountered while parsing */
+ List<Problem> problems = new ArrayList<>();
+ /* Configuration flag whether we store tokens and tokenranges */
+ boolean storeTokens;
+
+ /* Resets the parser for reuse, gaining a little performance */
+ void reset(Provider provider) {
+ ReInit(provider);
+ problems = new ArrayList<>();
+ getTokenSource().reset();
+ }
+
+ /**
+ * Return the list of JavaParser specific tokens that have been encountered while parsing code using this parser.
+ *
+ * @return a list of tokens
+ */
+ public List<JavaToken> getTokens() {
+ return getTokenSource().getTokens();
+ }
+
+ /* The collection of comments encountered */
+ CommentsCollection getCommentsCollection() {
+ return getTokenSource().getCommentsCollection();
+ }
+
+ /* Reports a problem to the user */
+ void addProblem(String message) {
+ // TODO tokenRange only takes the final token. Need all the tokens.
+ problems.add(new Problem(message, tokenRange(), null));
+ }
+
+ /* Returns a tokenRange that spans the last matched token */
+ TokenRange tokenRange() {
+ if (storeTokens) {
+ return new TokenRange(token(), token());
+ }
+ return null;
+ }
+
+ /**
+ * Return a TokenRange spanning from begin to end
+ */
+ TokenRange range(JavaToken begin, JavaToken end) {
+ if (storeTokens) {
+ return new TokenRange(begin, end);
+ }
+ return null;
+ }
+
+ /**
+ * Return a TokenRange spanning from begin to end
+ */
+ TokenRange range(Node begin, JavaToken end) {
+ if (storeTokens) {
+ return new TokenRange(begin.getTokenRange().get().getBegin(), end);
+ }
+ return null;
+ }
+
+ /**
+ * Return a TokenRange spanning from begin to end
+ */
+ TokenRange range(JavaToken begin, Node end) {
+ if (storeTokens) {
+ return new TokenRange(begin, end.getTokenRange().get().getEnd());
+ }
+ return null;
+ }
+
+ /**
+ * Return a TokenRange spanning from begin to end
+ */
+ TokenRange range(Node begin, Node end) {
+ if (storeTokens) {
+ return new TokenRange(begin.getTokenRange().get().getBegin(), end.getTokenRange().get().getEnd());
+ }
+ return null;
+ }
+
+ /**
+ * @return secondChoice if firstChoice is JavaToken.UNKNOWN, otherwise firstChoice
+ */
+ JavaToken orIfInvalid(JavaToken firstChoice, JavaToken secondChoice) {
+ if (storeTokens) {
+ assertNotNull(firstChoice);
+ assertNotNull(secondChoice);
+ if (firstChoice.valid() || secondChoice.invalid()) {
+ return firstChoice;
+ }
+ return secondChoice;
+ }
+ return null;
+ }
+
+ /**
+ * @return the begin-token secondChoice if firstChoice is JavaToken.UNKNOWN, otherwise firstChoice
+ */
+ JavaToken orIfInvalid(JavaToken firstChoice, Node secondChoice) {
+ if (storeTokens) {
+ return orIfInvalid(firstChoice, secondChoice.getTokenRange().get().getBegin());
+ }
+ return null;
+ }
+
+ /**
+ * Get the token that starts the NodeList l
+ */
+ JavaToken nodeListBegin(NodeList<?> l) {
+ if (!storeTokens || l.isEmpty()) {
+ return JavaToken.INVALID;
+ }
+ return l.get(0).getTokenRange().get().getBegin();
+ }
+
+ /* Sets the kind of the last matched token to newKind */
+ void setTokenKind(int newKind) {
+ token().setKind(newKind);
+ }
+
+ /* Makes the parser keep a list of tokens */
+ void setStoreTokens(boolean storeTokens) {
+ this.storeTokens = storeTokens;
+ getTokenSource().setStoreTokens(storeTokens);
+ }
+
+ /* Called from within a catch block to skip forward to a known token,
+ and report the occurred exception as a problem. */
+ TokenRange recover(int recoveryTokenType, ParseException p) {
+ JavaToken begin = null;
+ if (p.currentToken != null) {
+ begin = token();
+ }
+ Token t;
+ do {
+ t = getNextToken();
+ } while (t.kind != recoveryTokenType && t.kind != EOF);
+
+ JavaToken end = token();
+
+ TokenRange tokenRange = null;
+ if (begin != null && end != null) {
+ tokenRange = range(begin, end);
+ }
+
+ problems.add(new Problem(makeMessageForParseException(p), tokenRange, p));
+ return tokenRange;
+ }
+
+ /**
+ * Quickly create a new NodeList
+ */
+ <T extends Node> NodeList<T> emptyList() {
+ return new NodeList<>();
+ }
+
+ /**
+ * Add obj to list and return it. Create a new list if list is null
+ */
+ <T extends Node> NodeList<T> add(NodeList<T> list, T obj) {
+ if (list == null) {
+ list = new NodeList<>();
+ }
+ list.add(obj);
+ return list;
+ }
+
+ /**
+ * Add obj to list only when list is not null
+ */
+ <T extends Node> NodeList<T> addWhenNotNull(NodeList<T> list, T obj) {
+ if (obj == null) {
+ return list;
+ }
+ return add(list, obj);
+ }
+
+ /**
+ * Add obj to list at position pos
+ */
+ <T extends Node> NodeList<T> prepend(NodeList<T> list, T obj) {
+ if (list == null) {
+ list = new NodeList<>();
+ }
+ list.addFirst(obj);
+ return list;
+ }
+
+ /**
+ * Add obj to list
+ */
+ <T> List<T> add(List<T> list, T obj) {
+ if (list == null) {
+ list = new LinkedList<>();
+ }
+ list.add(obj);
+ return list;
+ }
+
+ /**
+ * Add modifier mod to modifiers
+ */
+ void addModifier(EnumSet<Modifier> modifiers, Modifier mod) {
+ if (modifiers.contains(mod)) {
+ addProblem("Duplicated modifier");
+ }
+ modifiers.add(mod);
+ }
+
+ /**
+ * Propagate expansion of the range on the right to the parent. This is necessary when the right border of the child
+ * is determining the right border of the parent (i.e., the child is the last element of the parent). In this case
+ * when we "enlarge" the child we should enlarge also the parent.
+ */
+ private void propagateRangeGrowthOnRight(Node node, Node endNode) {
+ if (storeTokens) {
+ node.getParentNode().ifPresent(nodeParent -> {
+ boolean isChildOnTheRightBorderOfParent = node.getTokenRange().get().getEnd().equals(nodeParent.getTokenRange().get().getEnd());
+ if (isChildOnTheRightBorderOfParent) {
+ propagateRangeGrowthOnRight(nodeParent, endNode);
+ }
+ });
+ node.setTokenRange(range(node, endNode));
+ }
+ }
+
+ /**
+ * Workaround for rather complex ambiguity that lambda's create
+ */
+ Expression generateLambda(Expression ret, Statement lambdaBody) {
+ if (ret instanceof EnclosedExpr) {
+ Expression inner = ((EnclosedExpr) ret).getInner();
+ SimpleName id = ((NameExpr) inner).getName();
+ NodeList<Parameter> params = add(new NodeList<>(), new Parameter(ret.getTokenRange().orElse(null), EnumSet.noneOf(Modifier.class), new NodeList<>(), new UnknownType(), false, new NodeList<>(), id));
+ ret = new LambdaExpr(range(ret, lambdaBody), params, lambdaBody, true);
+ } else if (ret instanceof NameExpr) {
+ SimpleName id = ((NameExpr) ret).getName();
+ NodeList<Parameter> params = add(new NodeList<>(), new Parameter(ret.getTokenRange().orElse(null), EnumSet.noneOf(Modifier.class), new NodeList<>(), new UnknownType(), false, new NodeList<>(), id));
+ ret = new LambdaExpr(range(ret, lambdaBody), params, lambdaBody, false);
+ } else if (ret instanceof LambdaExpr) {
+ ((LambdaExpr) ret).setBody(lambdaBody);
+ propagateRangeGrowthOnRight(ret, lambdaBody);
+ } else if (ret instanceof CastExpr) {
+ CastExpr castExpr = (CastExpr) ret;
+ Expression inner = generateLambda(castExpr.getExpression(), lambdaBody);
+ castExpr.setExpression(inner);
+ } else {
+ addProblem("Failed to parse lambda expression! Please create an issue at https://github.com/javaparser/javaparser/issues");
+ }
+ return ret;
+ }
+
+ /**
+ * Throws together an ArrayCreationExpr from a lot of pieces
+ */
+ ArrayCreationExpr juggleArrayCreation(TokenRange range, List<TokenRange> levelRanges, Type type, NodeList<Expression> dimensions, List<NodeList<AnnotationExpr>> arrayAnnotations, ArrayInitializerExpr arrayInitializerExpr) {
+ NodeList<ArrayCreationLevel> levels = new NodeList<>();
+
+ for (int i = 0; i < arrayAnnotations.size(); i++) {
+ levels.add(new ArrayCreationLevel(levelRanges.get(i), dimensions.get(i), arrayAnnotations.get(i)));
+ }
+ return new ArrayCreationExpr(range, type, levels, arrayInitializerExpr);
+ }
+
+ /**
+ * Throws together a Type, taking care of all the array brackets
+ */
+ Type juggleArrayType(Type partialType, List<ArrayType.ArrayBracketPair> additionalBrackets) {
+ Pair<Type, List<ArrayType.ArrayBracketPair>> partialParts = unwrapArrayTypes(partialType);
+ Type elementType = partialParts.a;
+ List<ArrayType.ArrayBracketPair> leftMostBrackets = partialParts.b;
+ return wrapInArrayTypes(elementType, leftMostBrackets, additionalBrackets).clone();
+ }
+
+ /**
+ * This is the code from ParseException.initialise, modified to be more horizontal.
+ */
+ private String makeMessageForParseException(ParseException exception) {
+ final StringBuilder sb = new StringBuilder("Parse error. Found ");
+ final StringBuilder expected = new StringBuilder();
+
+ int maxExpectedTokenSequenceLength = 0;
+ TreeSet<String> sortedOptions = new TreeSet<>();
+ for (int i = 0; i < exception.expectedTokenSequences.length; i++) {
+ if (maxExpectedTokenSequenceLength < exception.expectedTokenSequences[i].length) {
+ maxExpectedTokenSequenceLength = exception.expectedTokenSequences[i].length;
+ }
+ for (int j = 0; j < exception.expectedTokenSequences[i].length; j++) {
+ sortedOptions.add(exception.tokenImage[exception.expectedTokenSequences[i][j]]);
+ }
+ }
+
+ for (String option : sortedOptions) {
+ expected.append(" ").append(option);
+ }
+
+ sb.append("");
+
+ Token token = exception.currentToken.next;
+ for (int i = 0; i < maxExpectedTokenSequenceLength; i++) {
+ String tokenText = token.image;
+ String escapedTokenText = ParseException.add_escapes(tokenText);
+ if (i != 0) {
+ sb.append(" ");
+ }
+ if (token.kind == 0) {
+ sb.append(exception.tokenImage[0]);
+ break;
+ }
+ escapedTokenText = "\"" + escapedTokenText + "\"";
+ String image = exception.tokenImage[token.kind];
+ if (image.equals(escapedTokenText)) {
+ sb.append(image);
+ } else {
+ sb.append(" ")
+ .append(escapedTokenText)
+ .append(" ")
+ .append(image);
+ }
+ token = token.next;
+ }
+
+ if (exception.expectedTokenSequences.length != 0) {
+ int numExpectedTokens = exception.expectedTokenSequences.length;
+ sb.append(", expected")
+ .append(numExpectedTokens == 1 ? "" : " one of ")
+ .append(expected.toString());
+ }
+ return sb.toString();
+ }
+}
diff --git a/javaparser-core/src/main/javacc-support/com/github/javaparser/GeneratedJavaParserTokenManagerBase.java b/javaparser-core/src/main/javacc-support/com/github/javaparser/GeneratedJavaParserTokenManagerBase.java
new file mode 100644
index 000000000..da4331edf
--- /dev/null
+++ b/javaparser-core/src/main/javacc-support/com/github/javaparser/GeneratedJavaParserTokenManagerBase.java
@@ -0,0 +1,46 @@
+package com.github.javaparser;
+
+import com.github.javaparser.ast.comments.BlockComment;
+import com.github.javaparser.ast.comments.Comment;
+import com.github.javaparser.ast.comments.JavadocComment;
+import com.github.javaparser.ast.comments.LineComment;
+
+import static com.github.javaparser.GeneratedJavaParserConstants.*;
+import static com.github.javaparser.Position.pos;
+
+/**
+ * Base class for {@link com.github.javaparser.GeneratedJavaParserTokenManager}
+ */
+abstract class GeneratedJavaParserTokenManagerBase {
+ /**
+ * Create a TokenRange that spans exactly one token
+ */
+ private static TokenRange tokenRange(Token token) {
+ JavaToken javaToken = token.javaToken;
+ return new TokenRange(javaToken, javaToken);
+ }
+
+ /**
+ * Since comments are completely captured in a single token, including their delimiters, deconstruct them here so we
+ * can turn them into nodes later on.
+ */
+ static Comment createCommentFromToken(Token token) {
+ String commentText = token.image;
+ if (token.kind == JAVADOC_COMMENT) {
+ return new JavadocComment(tokenRange(token), commentText.substring(3, commentText.length() - 2));
+ } else if (token.kind == MULTI_LINE_COMMENT) {
+ return new BlockComment(tokenRange(token), commentText.substring(2, commentText.length() - 2));
+ } else if (token.kind == SINGLE_LINE_COMMENT) {
+ // line comments have their end of line character(s) included, and we don't want that.
+ Range range = new Range(pos(token.beginLine, token.beginColumn), pos(token.endLine, token.endColumn));
+ while (commentText.endsWith("\r") || commentText.endsWith("\n")) {
+ commentText = commentText.substring(0, commentText.length() - 1);
+ }
+ range = range.withEnd(pos(range.begin.line, range.begin.column + commentText.length()));
+ LineComment comment = new LineComment(tokenRange(token), commentText.substring(2));
+ comment.setRange(range);
+ return comment;
+ }
+ throw new AssertionError("Unexpectedly got passed a non-comment token.");
+ }
+}
diff --git a/javaparser-core/src/main/javacc-support/com/github/javaparser/ModifierHolder.java b/javaparser-core/src/main/javacc-support/com/github/javaparser/ModifierHolder.java
new file mode 100644
index 000000000..46d2e8f62
--- /dev/null
+++ b/javaparser-core/src/main/javacc-support/com/github/javaparser/ModifierHolder.java
@@ -0,0 +1,24 @@
+package com.github.javaparser;
+
+import com.github.javaparser.ast.Modifier;
+import com.github.javaparser.ast.NodeList;
+import com.github.javaparser.ast.expr.AnnotationExpr;
+
+import java.util.EnumSet;
+
+import static com.github.javaparser.utils.Utils.assertNotNull;
+
+/**
+ * Helper class for {@link GeneratedJavaParser}
+ */
+class ModifierHolder {
+ final EnumSet<Modifier> modifiers;
+ final NodeList<AnnotationExpr> annotations;
+ final JavaToken begin;
+
+ ModifierHolder(JavaToken begin, EnumSet<Modifier> modifiers, NodeList<AnnotationExpr> annotations) {
+ this.begin = begin;
+ this.modifiers = assertNotNull(modifiers);
+ this.annotations = annotations;
+ }
+}
diff --git a/javaparser-core/src/main/javacc-support/com/github/javaparser/RangedList.java b/javaparser-core/src/main/javacc-support/com/github/javaparser/RangedList.java
new file mode 100644
index 000000000..328ec50fb
--- /dev/null
+++ b/javaparser-core/src/main/javacc-support/com/github/javaparser/RangedList.java
@@ -0,0 +1,33 @@
+package com.github.javaparser;
+
+import com.github.javaparser.ast.Node;
+import com.github.javaparser.ast.NodeList;
+
+/**
+ * Helper class for {@link GeneratedJavaParser}
+ */
+class RangedList<T extends Node> {
+ /* A ranged list MUST be set to a begin and end,
+ or these temporary values will leak out */
+ TokenRange range = new TokenRange(JavaToken.INVALID, JavaToken.INVALID);
+ NodeList<T> list;
+
+ RangedList(NodeList<T> list) {
+ this.list = list;
+ }
+
+ void beginAt(JavaToken begin) {
+ range = range.withBegin(begin);
+ }
+
+ void endAt(JavaToken end) {
+ range = range.withEnd(end);
+ }
+
+ void add(T t) {
+ if (list == null) {
+ list = new NodeList<>();
+ }
+ list.add(t);
+ }
+}
diff --git a/javaparser-core/src/main/javacc-support/com/github/javaparser/TokenBase.java b/javaparser-core/src/main/javacc-support/com/github/javaparser/TokenBase.java
new file mode 100644
index 000000000..c52663c46
--- /dev/null
+++ b/javaparser-core/src/main/javacc-support/com/github/javaparser/TokenBase.java
@@ -0,0 +1,18 @@
+package com.github.javaparser;
+
+import static com.github.javaparser.GeneratedJavaParserConstants.GT;
+
+/**
+ * Base class for the generated {@link Token}
+ */
+abstract class TokenBase {
+ /**
+ * For tracking the >> >>> ambiguity.
+ */
+ int realKind = GT;
+
+ /**
+ * This is the link to the token that JavaParser presents to the user
+ */
+ JavaToken javaToken = null;
+}
diff --git a/javaparser-core/src/main/javacc/java.jj b/javaparser-core/src/main/javacc/java.jj
new file mode 100644
index 000000000..c68822878
--- /dev/null
+++ b/javaparser-core/src/main/javacc/java.jj
@@ -0,0 +1,2795 @@
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+
+options {
+ STATIC=false;
+ COMMON_TOKEN_ACTION=true;
+ JDK_VERSION = "1.8";
+ TOKEN_EXTENDS ="TokenBase";
+ JAVA_TEMPLATE_TYPE = "modern";
+}
+
+PARSER_BEGIN(GeneratedJavaParser)
+/*
+ * Copyright (C) 2007-2010 Júlio Vilmar Gesser.
+ * Copyright (C) 2011, 2013-2016 The JavaParser Team.
+ *
+ * This file is part of JavaParser.
+ *
+ * JavaParser can be used either under the terms of
+ * a) the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * b) the terms of the Apache License
+ *
+ * You should have received a copy of both licenses in LICENCE.LGPL and
+ * LICENCE.APACHE. Please refer to those files for details.
+ *
+ * JavaParser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ */
+package com.github.javaparser;
+import java.io.*;
+import java.util.*;
+import com.github.javaparser.ast.*;
+import com.github.javaparser.ast.body.*;
+import com.github.javaparser.ast.comments.*;
+import com.github.javaparser.ast.modules.*;
+import com.github.javaparser.ast.expr.*;
+import com.github.javaparser.ast.stmt.*;
+import com.github.javaparser.ast.type.*;
+import com.github.javaparser.utils.*;
+import javax.annotation.Generated;
+import static com.github.javaparser.JavaToken.INVALID;
+import static com.github.javaparser.ast.Node.Parsedness.UNPARSABLE;
+import static com.github.javaparser.utils.Utils.*;
+import static com.github.javaparser.ast.NodeList.*;
+import static com.github.javaparser.GeneratedJavaParser.*;
+import static com.github.javaparser.Range.*;
+import static com.github.javaparser.Position.*;
+import static com.github.javaparser.ast.type.ArrayType.*;
+import static com.github.javaparser.GeneratedJavaParserTokenManagerBase.*;
+
+@Generated("JavaCC")
+final class GeneratedJavaParser extends GeneratedJavaParserBase {
+ /* Returns the JavaParser specific token type of the last matched token */
+ JavaToken token() {
+ return token.javaToken;
+ }
+
+ /* Changes the amount by which the horizontal position is increased when a tab character is encountered.
+ One by default.*/
+ void setTabSize(int size) {
+ jj_input_stream.setTabSize(size);
+ }
+
+ @Override
+ GeneratedJavaParserTokenManager getTokenSource() {
+ return token_source;
+ }
+}
+
+PARSER_END(GeneratedJavaParser)
+
+/* WHITE SPACE */
+
+SPECIAL_TOKEN :
+{
+ <SPACE: [" ", "\t", "\f", "\u0085", "\u00A0", "\u1680", "\u180e", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004", "\u2005",
+ "\u2006", "\u2007", "\u2008", "\u2009", "\u200a", "\u200b", "\u200c", "\u200d", "\u2028", "\u2029", "\u202f", "\u205f", "\u2060", "\u3000", "\ufeff"]>
+| <WINDOWS_EOL : "\r\n">
+| <UNIX_EOL: "\n">
+| <OLD_MAC_EOL: "\r">
+}
+
+TOKEN_MGR_DECLS :
+{
+ private List<JavaToken> tokens = new ArrayList<JavaToken>();
+ private CommentsCollection commentsCollection = new CommentsCollection();
+ private JavaToken homeToken;
+ private Stack<Token> tokenWorkStack = new Stack<Token>();
+ private boolean storeTokens;
+
+ void reset() {
+ tokens = new ArrayList<JavaToken>();
+ commentsCollection = new CommentsCollection();
+ homeToken = null;
+ }
+
+ List<JavaToken> getTokens() {
+ if(storeTokens) {
+ return tokens;
+ }
+ return null;
+ }
+
+ CommentsCollection getCommentsCollection() {
+ return commentsCollection;
+ }
+
+ /* Get the very first token in the file */
+ JavaToken getHomeToken() {
+ return homeToken;
+ }
+
+ /* Makes the parser keep a list of tokens */
+ public void setStoreTokens(boolean storeTokens) {
+ this.storeTokens = storeTokens;
+ }
+
+ private void CommonTokenAction(Token token) {
+ // Use an intermediary stack to avoid recursion, see issue 1003
+ do {
+ tokenWorkStack.push(token);
+ token = token.specialToken;
+ } while (token != null);
+
+ // The stack is now filled with tokens in left-to-right order. Process them.
+ while(!tokenWorkStack.empty()) {
+ token = tokenWorkStack.pop();
+ token.javaToken = new JavaToken(token, tokens);
+
+ if(storeTokens) {
+ tokens.add(token.javaToken);
+ }
+
+ if (homeToken == null) {
+ homeToken = token.javaToken;
+ }
+
+ if(TokenTypes.isComment(token.kind)) {
+ Comment comment = createCommentFromToken(token);
+ commentsCollection.addComment(comment);
+ }
+ }
+ }
+}
+
+/* COMMENTS */
+
+SPECIAL_TOKEN :
+{
+ <SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")? >
+}
+
+MORE :
+{
+ <ENTER_JAVADOC_COMMENT: "/**" ~["/"]> { input_stream.backup(1); } : IN_JAVADOC_COMMENT
+|
+ <ENTER_MULTILINE_COMMENT: "/*"> : IN_MULTI_LINE_COMMENT
+}
+
+<IN_JAVADOC_COMMENT>
+SPECIAL_TOKEN :
+{
+ <JAVADOC_COMMENT: "*/" > : DEFAULT
+}
+
+<IN_MULTI_LINE_COMMENT>
+SPECIAL_TOKEN :
+{
+ <MULTI_LINE_COMMENT: "*/" > : DEFAULT
+}
+
+<IN_JAVADOC_COMMENT, IN_MULTI_LINE_COMMENT>
+MORE :
+{
+ <COMMENT_CONTENT: ~[] >
+}
+
+/* RESERVED WORDS AND LITERALS */
+
+TOKEN :
+{
+ < ABSTRACT: "abstract" >
+| < ASSERT: "assert" >
+| < BOOLEAN: "boolean" >
+| < BREAK: "break" >
+| < BYTE: "byte" >
+| < CASE: "case" >
+| < CATCH: "catch" >
+| < CHAR: "char" >
+| < CLASS: "class" >
+| < CONST: "const" >
+| < CONTINUE: "continue" >
+| < _DEFAULT: "default" >
+| < DO: "do" >
+| < DOUBLE: "double" >
+| < ELSE: "else" >
+| < ENUM: "enum" >
+| < EXTENDS: "extends" >
+| < FALSE: "false" >
+| < FINAL: "final" >
+| < FINALLY: "finally" >
+| < FLOAT: "float" >
+| < FOR: "for" >
+| < GOTO: "goto" >
+| < IF: "if" >
+| < IMPLEMENTS: "implements" >
+| < IMPORT: "import" >
+| < INSTANCEOF: "instanceof" >
+| < INT: "int" >
+| < INTERFACE: "interface" >
+| < LONG: "long" >
+| < NATIVE: "native" >
+| < NEW: "new" >
+| < NULL: "null" >
+| < PACKAGE: "package">
+| < PRIVATE: "private" >
+| < PROTECTED: "protected" >
+| < PUBLIC: "public" >
+| < RETURN: "return" >
+| < SHORT: "short" >
+| < STATIC: "static" >
+| < STRICTFP: "strictfp" >
+| < SUPER: "super" >
+| < SWITCH: "switch" >
+| < SYNCHRONIZED: "synchronized" >
+| < THIS: "this" >
+| < THROW: "throw" >
+| < THROWS: "throws" >
+| < TRANSIENT: "transient" >
+| < TRUE: "true" >
+| < TRY: "try" >
+| < VOID: "void" >
+| < VOLATILE: "volatile" >
+| < WHILE: "while" >
+| < REQUIRES: "requires" >
+| < TO: "to" >
+| < WITH: "with" >
+| < OPEN: "open" >
+| < OPENS: "opens" >
+| < USES: "uses" >
+| < MODULE: "module" >
+| < EXPORTS: "exports" >
+| < PROVIDES: "provides" >
+| < TRANSITIVE: "transitive" >
+}
+
+/* LITERALS */
+
+TOKEN :
+{
+ < LONG_LITERAL:
+ <DECIMAL_LITERAL> (["l","L"])
+ | <HEX_LITERAL> (["l","L"])
+ | <OCTAL_LITERAL> (["l","L"])
+ | <BINARY_LITERAL> (["l","L"])
+ >
+|
+ < INTEGER_LITERAL:
+ <DECIMAL_LITERAL>
+ | <HEX_LITERAL>
+ | <OCTAL_LITERAL>
+ | <BINARY_LITERAL>
+ >
+|
+ < #DECIMAL_LITERAL: ["0"-"9"]((["0"-"9","_"])*["0"-"9"])? >
+|
+ < #HEX_LITERAL: "0" ["x","X"] <HEX_DIGITS> >
+|
+ < #OCTAL_LITERAL: "0" ["0"-"7"]((["0"-"7","_"])*["0"-"7"])? >
+|
+ < #BINARY_LITERAL: "0" ["b","B"] ["0","1"]((["0","1","_"])*["0","1"])? >
+|
+ < FLOATING_POINT_LITERAL:
+ <DECIMAL_FLOATING_POINT_LITERAL>
+ | <HEXADECIMAL_FLOATING_POINT_LITERAL>
+ >
+|
+ < #DECIMAL_FLOATING_POINT_LITERAL:
+ <DECIMAL_LITERAL> "." (<DECIMAL_LITERAL>)? (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
+ | "." <DECIMAL_LITERAL> (<DECIMAL_EXPONENT>)? (["f","F","d","D"])?
+ | <DECIMAL_LITERAL> <DECIMAL_EXPONENT> (["f","F","d","D"])?
+ | <DECIMAL_LITERAL> (<DECIMAL_EXPONENT>)? ["f","F","d","D"]
+ >
+|
+ < #DECIMAL_EXPONENT: ["e","E"] (["+","-"])? (<DECIMAL_LITERAL>)+ >
+|
+ < #HEXADECIMAL_FLOATING_POINT_LITERAL:
+ <HEX_LITERAL> (".")? <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
+ | "0" ["x","X"] (<HEX_DIGITS>)? "." <HEX_DIGITS> <HEXADECIMAL_EXPONENT> (["f","F","d","D"])?
+ >
+|
+ < #HEXADECIMAL_EXPONENT: ["p","P"] (["+","-"])? <DECIMAL_LITERAL> >
+|
+ < #HEX_DIGITS: ["0"-"9","a"-"f","A"-"F"]((["0"-"9","a"-"f","A"-"F","_"])*["0"-"9","a"-"f","A"-"F"])? >
+|
+ < #UNICODE_ESCAPE:
+ "\\u"
+ ["0"-"9","A"-"F","a"-"f"]
+ ["0"-"9","A"-"F","a"-"f"]
+ ["0"-"9","A"-"F","a"-"f"]
+ ["0"-"9","A"-"F","a"-"f"] >
+|
+ < CHARACTER_LITERAL:
+ "'"
+ ( (~["'","\\","\n","\r"])
+ | ("\\"
+ ( ["n","t","b","r","f","\\","'","\""]
+ | ["0"-"7"] ( ["0"-"7"] )?
+ | ["0"-"3"] ["0"-"7"] ["0"-"7"]
+ )
+ )
+ | <UNICODE_ESCAPE>
+ )
+ "'"
+ >
+|
+ < STRING_LITERAL:
+ "\""
+ ( (~["\"","\\","\n","\r"])
+ | ("\\"
+ ( ["n","t","b","r","f","\\","'","\""]
+ | ["0"-"7"] ( ["0"-"7"] )?
+ | ["0"-"3"] ["0"-"7"] ["0"-"7"]
+ )
+ )
+ | ("\\u"
+ ["0"-"9","A"-"F","a"-"f"]
+ ["0"-"9","A"-"F","a"-"f"]
+ ["0"-"9","A"-"F","a"-"f"]
+ ["0"-"9","A"-"F","a"-"f"]
+ )
+ )*
+ "\""
+ >
+}
+
+/* IDENTIFIERS */
+
+TOKEN :
+{
+ < IDENTIFIER: <LETTER> (<PART_LETTER>)* >
+|
+ < #LETTER: [
+ "\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00a2"-"\u00a5", "\u00aa", "\u00b5",
+ "\u00ba", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u02c1", "\u02c6"-"\u02d1", "\u02e0"-"\u02e4",
+ "\u02ec", "\u02ee", "\u0370"-"\u0374", "\u0376"-"\u0377", "\u037a"-"\u037d", "\u0386", "\u0388"-"\u038a",
+ "\u038c", "\u038e"-"\u03a1", "\u03a3"-"\u03f5", "\u03f7"-"\u0481", "\u048a"-"\u0527", "\u0531"-"\u0556",
+ "\u0559", "\u0561"-"\u0587", "\u058f", "\u05d0"-"\u05ea", "\u05f0"-"\u05f2", "\u060b", "\u0620"-"\u064a",
+ "\u066e"-"\u066f", "\u0671"-"\u06d3", "\u06d5", "\u06e5"-"\u06e6", "\u06ee"-"\u06ef", "\u06fa"-"\u06fc",
+ "\u06ff", "\u0710", "\u0712"-"\u072f", "\u074d"-"\u07a5", "\u07b1", "\u07ca"-"\u07ea", "\u07f4"-"\u07f5",
+ "\u07fa", "\u0800"-"\u0815", "\u081a", "\u0824", "\u0828", "\u0840"-"\u0858", "\u08a0", "\u08a2"-"\u08ac",
+ "\u0904"-"\u0939", "\u093d", "\u0950", "\u0958"-"\u0961", "\u0971"-"\u0977", "\u0979"-"\u097f",
+ "\u0985"-"\u098c", "\u098f"-"\u0990", "\u0993"-"\u09a8", "\u09aa"-"\u09b0", "\u09b2", "\u09b6"-"\u09b9",
+ "\u09bd", "\u09ce", "\u09dc"-"\u09dd", "\u09df"-"\u09e1", "\u09f0"-"\u09f3", "\u09fb", "\u0a05"-"\u0a0a",
+ "\u0a0f"-"\u0a10", "\u0a13"-"\u0a28", "\u0a2a"-"\u0a30", "\u0a32"-"\u0a33", "\u0a35"-"\u0a36",
+ "\u0a38"-"\u0a39", "\u0a59"-"\u0a5c", "\u0a5e", "\u0a72"-"\u0a74", "\u0a85"-"\u0a8d", "\u0a8f"-"\u0a91",
+ "\u0a93"-"\u0aa8", "\u0aaa"-"\u0ab0", "\u0ab2"-"\u0ab3", "\u0ab5"-"\u0ab9", "\u0abd", "\u0ad0",
+ "\u0ae0"-"\u0ae1", "\u0af1", "\u0b05"-"\u0b0c", "\u0b0f"-"\u0b10", "\u0b13"-"\u0b28", "\u0b2a"-"\u0b30",
+ "\u0b32"-"\u0b33", "\u0b35"-"\u0b39", "\u0b3d", "\u0b5c"-"\u0b5d", "\u0b5f"-"\u0b61", "\u0b71",
+ "\u0b83", "\u0b85"-"\u0b8a", "\u0b8e"-"\u0b90", "\u0b92"-"\u0b95", "\u0b99"-"\u0b9a", "\u0b9c",
+ "\u0b9e"-"\u0b9f", "\u0ba3"-"\u0ba4", "\u0ba8"-"\u0baa", "\u0bae"-"\u0bb9", "\u0bd0", "\u0bf9",
+ "\u0c05"-"\u0c0c", "\u0c0e"-"\u0c10", "\u0c12"-"\u0c28", "\u0c2a"-"\u0c33", "\u0c35"-"\u0c39",
+ "\u0c3d", "\u0c58"-"\u0c59", "\u0c60"-"\u0c61", "\u0c85"-"\u0c8c", "\u0c8e"-"\u0c90", "\u0c92"-"\u0ca8",
+ "\u0caa"-"\u0cb3", "\u0cb5"-"\u0cb9", "\u0cbd", "\u0cde", "\u0ce0"-"\u0ce1", "\u0cf1"-"\u0cf2",
+ "\u0d05"-"\u0d0c", "\u0d0e"-"\u0d10", "\u0d12"-"\u0d3a", "\u0d3d", "\u0d4e", "\u0d60"-"\u0d61",
+ "\u0d7a"-"\u0d7f", "\u0d85"-"\u0d96", "\u0d9a"-"\u0db1", "\u0db3"-"\u0dbb", "\u0dbd", "\u0dc0"-"\u0dc6",
+ "\u0e01"-"\u0e30", "\u0e32"-"\u0e33", "\u0e3f"-"\u0e46", "\u0e81"-"\u0e82", "\u0e84", "\u0e87"-"\u0e88",
+ "\u0e8a", "\u0e8d", "\u0e94"-"\u0e97", "\u0e99"-"\u0e9f", "\u0ea1"-"\u0ea3", "\u0ea5", "\u0ea7",
+ "\u0eaa"-"\u0eab", "\u0ead"-"\u0eb0", "\u0eb2"-"\u0eb3", "\u0ebd", "\u0ec0"-"\u0ec4", "\u0ec6",
+ "\u0edc"-"\u0edf", "\u0f00", "\u0f40"-"\u0f47", "\u0f49"-"\u0f6c", "\u0f88"-"\u0f8c", "\u1000"-"\u102a",
+ "\u103f", "\u1050"-"\u1055", "\u105a"-"\u105d", "\u1061", "\u1065"-"\u1066", "\u106e"-"\u1070",
+ "\u1075"-"\u1081", "\u108e", "\u10a0"-"\u10c5", "\u10c7", "\u10cd", "\u10d0"-"\u10fa", "\u10fc"-"\u1248",
+ "\u124a"-"\u124d", "\u1250"-"\u1256", "\u1258", "\u125a"-"\u125d", "\u1260"-"\u1288", "\u128a"-"\u128d",
+ "\u1290"-"\u12b0", "\u12b2"-"\u12b5", "\u12b8"-"\u12be", "\u12c0", "\u12c2"-"\u12c5", "\u12c8"-"\u12d6",
+ "\u12d8"-"\u1310", "\u1312"-"\u1315", "\u1318"-"\u135a", "\u1380"-"\u138f", "\u13a0"-"\u13f4",
+ "\u1401"-"\u166c", "\u166f"-"\u167f", "\u1681"-"\u169a", "\u16a0"-"\u16ea", "\u16ee"-"\u16f0",
+ "\u1700"-"\u170c", "\u170e"-"\u1711", "\u1720"-"\u1731", "\u1740"-"\u1751", "\u1760"-"\u176c",
+ "\u176e"-"\u1770", "\u1780"-"\u17b3", "\u17d7", "\u17db"-"\u17dc", "\u1820"-"\u1877", "\u1880"-"\u18a8",
+ "\u18aa", "\u18b0"-"\u18f5", "\u1900"-"\u191c", "\u1950"-"\u196d", "\u1970"-"\u1974", "\u1980"-"\u19ab",
+ "\u19c1"-"\u19c7", "\u1a00"-"\u1a16", "\u1a20"-"\u1a54", "\u1aa7", "\u1b05"-"\u1b33", "\u1b45"-"\u1b4b",
+ "\u1b83"-"\u1ba0", "\u1bae"-"\u1baf", "\u1bba"-"\u1be5", "\u1c00"-"\u1c23", "\u1c4d"-"\u1c4f",
+ "\u1c5a"-"\u1c7d", "\u1ce9"-"\u1cec", "\u1cee"-"\u1cf1", "\u1cf5"-"\u1cf6", "\u1d00"-"\u1dbf",
+ "\u1e00"-"\u1f15", "\u1f18"-"\u1f1d", "\u1f20"-"\u1f45", "\u1f48"-"\u1f4d", "\u1f50"-"\u1f57",
+ "\u1f59", "\u1f5b", "\u1f5d", "\u1f5f"-"\u1f7d", "\u1f80"-"\u1fb4", "\u1fb6"-"\u1fbc", "\u1fbe",
+ "\u1fc2"-"\u1fc4", "\u1fc6"-"\u1fcc", "\u1fd0"-"\u1fd3", "\u1fd6"-"\u1fdb", "\u1fe0"-"\u1fec",
+ "\u1ff2"-"\u1ff4", "\u1ff6"-"\u1ffc", "\u203f"-"\u2040", "\u2054", "\u2071", "\u207f", "\u2090"-"\u209c",
+ "\u20a0"-"\u20ba", "\u2102", "\u2107", "\u210a"-"\u2113", "\u2115", "\u2119"-"\u211d", "\u2124",
+ "\u2126", "\u2128", "\u212a"-"\u212d", "\u212f"-"\u2139", "\u213c"-"\u213f", "\u2145"-"\u2149",
+ "\u214e", "\u2160"-"\u2188", "\u2c00"-"\u2c2e", "\u2c30"-"\u2c5e", "\u2c60"-"\u2ce4", "\u2ceb"-"\u2cee",
+ "\u2cf2"-"\u2cf3", "\u2d00"-"\u2d25", "\u2d27", "\u2d2d", "\u2d30"-"\u2d67", "\u2d6f", "\u2d80"-"\u2d96",
+ "\u2da0"-"\u2da6", "\u2da8"-"\u2dae", "\u2db0"-"\u2db6", "\u2db8"-"\u2dbe", "\u2dc0"-"\u2dc6",
+ "\u2dc8"-"\u2dce", "\u2dd0"-"\u2dd6", "\u2dd8"-"\u2dde", "\u2e2f", "\u3005"-"\u3007", "\u3021"-"\u3029",
+ "\u3031"-"\u3035", "\u3038"-"\u303c", "\u3041"-"\u3096", "\u309d"-"\u309f", "\u30a1"-"\u30fa",
+ "\u30fc"-"\u30ff", "\u3105"-"\u312d", "\u3131"-"\u318e", "\u31a0"-"\u31ba", "\u31f0"-"\u31ff",
+ "\u3400"-"\u4db5", "\u4e00"-"\u9fcc", "\ua000"-"\ua48c", "\ua4d0"-"\ua4fd", "\ua500"-"\ua60c",
+ "\ua610"-"\ua61f", "\ua62a"-"\ua62b", "\ua640"-"\ua66e", "\ua67f"-"\ua697", "\ua6a0"-"\ua6ef",
+ "\ua717"-"\ua71f", "\ua722"-"\ua788", "\ua78b"-"\ua78e", "\ua790"-"\ua793", "\ua7a0"-"\ua7aa",
+ "\ua7f8"-"\ua801", "\ua803"-"\ua805", "\ua807"-"\ua80a", "\ua80c"-"\ua822", "\ua838", "\ua840"-"\ua873",
+ "\ua882"-"\ua8b3", "\ua8f2"-"\ua8f7", "\ua8fb", "\ua90a"-"\ua925", "\ua930"-"\ua946", "\ua960"-"\ua97c",
+ "\ua984"-"\ua9b2", "\ua9cf", "\uaa00"-"\uaa28", "\uaa40"-"\uaa42", "\uaa44"-"\uaa4b", "\uaa60"-"\uaa76",
+ "\uaa7a", "\uaa80"-"\uaaaf", "\uaab1", "\uaab5"-"\uaab6", "\uaab9"-"\uaabd", "\uaac0", "\uaac2",
+ "\uaadb"-"\uaadd", "\uaae0"-"\uaaea", "\uaaf2"-"\uaaf4", "\uab01"-"\uab06", "\uab09"-"\uab0e",
+ "\uab11"-"\uab16", "\uab20"-"\uab26", "\uab28"-"\uab2e", "\uabc0"-"\uabe2", "\uac00"-"\ud7a3",
+ "\ud7b0"-"\ud7c6", "\ud7cb"-"\ud7fb", "\ud800"-"\udfff", "\uf900"-"\ufa6d", "\ufa70"-"\ufad9",
+ "\ufb00"-"\ufb06", "\ufb13"-"\ufb17", "\ufb1d", "\ufb1f"-"\ufb28", "\ufb2a"-"\ufb36", "\ufb38"-"\ufb3c",
+ "\ufb3e", "\ufb40"-"\ufb41", "\ufb43"-"\ufb44", "\ufb46"-"\ufbb1", "\ufbd3"-"\ufd3d", "\ufd50"-"\ufd8f",
+ "\ufd92"-"\ufdc7", "\ufdf0"-"\ufdfc", "\ufe33"-"\ufe34", "\ufe4d"-"\ufe4f", "\ufe69", "\ufe70"-"\ufe74",
+ "\ufe76"-"\ufefc", "\uff04", "\uff21"-"\uff3a", "\uff3f", "\uff41"-"\uff5a", "\uff66"-"\uffbe",
+ "\uffc2"-"\uffc7", "\uffca"-"\uffcf", "\uffd2"-"\uffd7", "\uffda"-"\uffdc", "\uffe0"-"\uffe1",
+ "\uffe5"-"\uffe6" ]
+ | <UNICODE_ESCAPE>
+ >
+|
+ < #PART_LETTER: [
+ "\u0000"-"\u0008", "\u000e"-"\u001b", "\u0024", "\u0030"-"\u0039", "\u0041"-"\u005a", "\u005f",
+ "\u0061"-"\u007a", "\u007f"-"\u009f", "\u00a2"-"\u00a5", "\u00aa", "\u00ad", "\u00b5", "\u00ba",
+ "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u02c1", "\u02c6"-"\u02d1", "\u02e0"-"\u02e4",
+ "\u02ec", "\u02ee", "\u0300"-"\u0374", "\u0376"-"\u0377", "\u037a"-"\u037d", "\u0386", "\u0388"-"\u038a",
+ "\u038c", "\u038e"-"\u03a1", "\u03a3"-"\u03f5", "\u03f7"-"\u0481", "\u0483"-"\u0487", "\u048a"-"\u0527",
+ "\u0531"-"\u0556", "\u0559", "\u0561"-"\u0587", "\u058f", "\u0591"-"\u05bd", "\u05bf", "\u05c1"-"\u05c2",
+ "\u05c4"-"\u05c5", "\u05c7", "\u05d0"-"\u05ea", "\u05f0"-"\u05f2", "\u0600"-"\u0604", "\u060b",
+ "\u0610"-"\u061a", "\u0620"-"\u0669", "\u066e"-"\u06d3", "\u06d5"-"\u06dd", "\u06df"-"\u06e8",
+ "\u06ea"-"\u06fc", "\u06ff", "\u070f"-"\u074a", "\u074d"-"\u07b1", "\u07c0"-"\u07f5", "\u07fa",
+ "\u0800"-"\u082d", "\u0840"-"\u085b", "\u08a0", "\u08a2"-"\u08ac", "\u08e4"-"\u08fe", "\u0900"-"\u0963",
+ "\u0966"-"\u096f", "\u0971"-"\u0977", "\u0979"-"\u097f", "\u0981"-"\u0983", "\u0985"-"\u098c",
+ "\u098f"-"\u0990", "\u0993"-"\u09a8", "\u09aa"-"\u09b0", "\u09b2", "\u09b6"-"\u09b9", "\u09bc"-"\u09c4",
+ "\u09c7"-"\u09c8", "\u09cb"-"\u09ce", "\u09d7", "\u09dc"-"\u09dd", "\u09df"-"\u09e3", "\u09e6"-"\u09f3",
+ "\u09fb", "\u0a01"-"\u0a03", "\u0a05"-"\u0a0a", "\u0a0f"-"\u0a10", "\u0a13"-"\u0a28", "\u0a2a"-"\u0a30",
+ "\u0a32"-"\u0a33", "\u0a35"-"\u0a36", "\u0a38"-"\u0a39", "\u0a3c", "\u0a3e"-"\u0a42", "\u0a47"-"\u0a48",
+ "\u0a4b"-"\u0a4d", "\u0a51", "\u0a59"-"\u0a5c", "\u0a5e", "\u0a66"-"\u0a75", "\u0a81"-"\u0a83",
+ "\u0a85"-"\u0a8d", "\u0a8f"-"\u0a91", "\u0a93"-"\u0aa8", "\u0aaa"-"\u0ab0", "\u0ab2"-"\u0ab3",
+ "\u0ab5"-"\u0ab9", "\u0abc"-"\u0ac5", "\u0ac7"-"\u0ac9", "\u0acb"-"\u0acd", "\u0ad0", "\u0ae0"-"\u0ae3",
+ "\u0ae6"-"\u0aef", "\u0af1", "\u0b01"-"\u0b03", "\u0b05"-"\u0b0c", "\u0b0f"-"\u0b10", "\u0b13"-"\u0b28",
+ "\u0b2a"-"\u0b30", "\u0b32"-"\u0b33", "\u0b35"-"\u0b39", "\u0b3c"-"\u0b44", "\u0b47"-"\u0b48",
+ "\u0b4b"-"\u0b4d", "\u0b56"-"\u0b57", "\u0b5c"-"\u0b5d", "\u0b5f"-"\u0b63", "\u0b66"-"\u0b6f",
+ "\u0b71", "\u0b82"-"\u0b83", "\u0b85"-"\u0b8a", "\u0b8e"-"\u0b90", "\u0b92"-"\u0b95", "\u0b99"-"\u0b9a",
+ "\u0b9c", "\u0b9e"-"\u0b9f", "\u0ba3"-"\u0ba4", "\u0ba8"-"\u0baa", "\u0bae"-"\u0bb9", "\u0bbe"-"\u0bc2",
+ "\u0bc6"-"\u0bc8", "\u0bca"-"\u0bcd", "\u0bd0", "\u0bd7", "\u0be6"-"\u0bef", "\u0bf9", "\u0c01"-"\u0c03",
+ "\u0c05"-"\u0c0c", "\u0c0e"-"\u0c10", "\u0c12"-"\u0c28", "\u0c2a"-"\u0c33", "\u0c35"-"\u0c39",
+ "\u0c3d"-"\u0c44", "\u0c46"-"\u0c48", "\u0c4a"-"\u0c4d", "\u0c55"-"\u0c56", "\u0c58"-"\u0c59",
+ "\u0c60"-"\u0c63", "\u0c66"-"\u0c6f", "\u0c82"-"\u0c83", "\u0c85"-"\u0c8c", "\u0c8e"-"\u0c90",
+ "\u0c92"-"\u0ca8", "\u0caa"-"\u0cb3", "\u0cb5"-"\u0cb9", "\u0cbc"-"\u0cc4", "\u0cc6"-"\u0cc8",
+ "\u0cca"-"\u0ccd", "\u0cd5"-"\u0cd6", "\u0cde", "\u0ce0"-"\u0ce3", "\u0ce6"-"\u0cef", "\u0cf1"-"\u0cf2",
+ "\u0d02"-"\u0d03", "\u0d05"-"\u0d0c", "\u0d0e"-"\u0d10", "\u0d12"-"\u0d3a", "\u0d3d"-"\u0d44",
+ "\u0d46"-"\u0d48", "\u0d4a"-"\u0d4e", "\u0d57", "\u0d60"-"\u0d63", "\u0d66"-"\u0d6f", "\u0d7a"-"\u0d7f",
+ "\u0d82"-"\u0d83", "\u0d85"-"\u0d96", "\u0d9a"-"\u0db1", "\u0db3"-"\u0dbb", "\u0dbd", "\u0dc0"-"\u0dc6",
+ "\u0dca", "\u0dcf"-"\u0dd4", "\u0dd6", "\u0dd8"-"\u0ddf", "\u0df2"-"\u0df3", "\u0e01"-"\u0e3a",
+ "\u0e3f"-"\u0e4e", "\u0e50"-"\u0e59", "\u0e81"-"\u0e82", "\u0e84", "\u0e87"-"\u0e88", "\u0e8a",
+ "\u0e8d", "\u0e94"-"\u0e97", "\u0e99"-"\u0e9f", "\u0ea1"-"\u0ea3", "\u0ea5", "\u0ea7", "\u0eaa"-"\u0eab",
+ "\u0ead"-"\u0eb9", "\u0ebb"-"\u0ebd", "\u0ec0"-"\u0ec4", "\u0ec6", "\u0ec8"-"\u0ecd", "\u0ed0"-"\u0ed9",
+ "\u0edc"-"\u0edf", "\u0f00", "\u0f18"-"\u0f19", "\u0f20"-"\u0f29", "\u0f35", "\u0f37", "\u0f39",
+ "\u0f3e"-"\u0f47", "\u0f49"-"\u0f6c", "\u0f71"-"\u0f84", "\u0f86"-"\u0f97", "\u0f99"-"\u0fbc",
+ "\u0fc6", "\u1000"-"\u1049", "\u1050"-"\u109d", "\u10a0"-"\u10c5", "\u10c7", "\u10cd", "\u10d0"-"\u10fa",
+ "\u10fc"-"\u1248", "\u124a"-"\u124d", "\u1250"-"\u1256", "\u1258", "\u125a"-"\u125d", "\u1260"-"\u1288",
+ "\u128a"-"\u128d", "\u1290"-"\u12b0", "\u12b2"-"\u12b5", "\u12b8"-"\u12be", "\u12c0", "\u12c2"-"\u12c5",
+ "\u12c8"-"\u12d6", "\u12d8"-"\u1310", "\u1312"-"\u1315", "\u1318"-"\u135a", "\u135d"-"\u135f",
+ "\u1380"-"\u138f", "\u13a0"-"\u13f4", "\u1401"-"\u166c", "\u166f"-"\u167f", "\u1681"-"\u169a",
+ "\u16a0"-"\u16ea", "\u16ee"-"\u16f0", "\u1700"-"\u170c", "\u170e"-"\u1714", "\u1720"-"\u1734",
+ "\u1740"-"\u1753", "\u1760"-"\u176c", "\u176e"-"\u1770", "\u1772"-"\u1773", "\u1780"-"\u17d3",
+ "\u17d7", "\u17db"-"\u17dd", "\u17e0"-"\u17e9", "\u180b"-"\u180d", "\u1810"-"\u1819", "\u1820"-"\u1877",
+ "\u1880"-"\u18aa", "\u18b0"-"\u18f5", "\u1900"-"\u191c", "\u1920"-"\u192b", "\u1930"-"\u193b",
+ "\u1946"-"\u196d", "\u1970"-"\u1974", "\u1980"-"\u19ab", "\u19b0"-"\u19c9", "\u19d0"-"\u19d9",
+ "\u1a00"-"\u1a1b", "\u1a20"-"\u1a5e", "\u1a60"-"\u1a7c", "\u1a7f"-"\u1a89", "\u1a90"-"\u1a99",
+ "\u1aa7", "\u1b00"-"\u1b4b", "\u1b50"-"\u1b59", "\u1b6b"-"\u1b73", "\u1b80"-"\u1bf3", "\u1c00"-"\u1c37",
+ "\u1c40"-"\u1c49", "\u1c4d"-"\u1c7d", "\u1cd0"-"\u1cd2", "\u1cd4"-"\u1cf6", "\u1d00"-"\u1de6",
+ "\u1dfc"-"\u1f15", "\u1f18"-"\u1f1d", "\u1f20"-"\u1f45", "\u1f48"-"\u1f4d", "\u1f50"-"\u1f57",
+ "\u1f59", "\u1f5b", "\u1f5d", "\u1f5f"-"\u1f7d", "\u1f80"-"\u1fb4", "\u1fb6"-"\u1fbc", "\u1fbe",
+ "\u1fc2"-"\u1fc4", "\u1fc6"-"\u1fcc", "\u1fd0"-"\u1fd3", "\u1fd6"-"\u1fdb", "\u1fe0"-"\u1fec",
+ "\u1ff2"-"\u1ff4", "\u1ff6"-"\u1ffc", "\u200b"-"\u200f", "\u202a"-"\u202e", "\u203f"-"\u2040",
+ "\u2054", "\u2060"-"\u2064", "\u206a"-"\u206f", "\u2071", "\u207f", "\u2090"-"\u209c", "\u20a0"-"\u20ba",
+ "\u20d0"-"\u20dc", "\u20e1", "\u20e5"-"\u20f0", "\u2102", "\u2107", "\u210a"-"\u2113", "\u2115",
+ "\u2119"-"\u211d", "\u2124", "\u2126", "\u2128", "\u212a"-"\u212d", "\u212f"-"\u2139", "\u213c"-"\u213f",
+ "\u2145"-"\u2149", "\u214e", "\u2160"-"\u2188", "\u2c00"-"\u2c2e", "\u2c30"-"\u2c5e", "\u2c60"-"\u2ce4",
+ "\u2ceb"-"\u2cf3", "\u2d00"-"\u2d25", "\u2d27", "\u2d2d", "\u2d30"-"\u2d67", "\u2d6f", "\u2d7f"-"\u2d96",
+ "\u2da0"-"\u2da6", "\u2da8"-"\u2dae", "\u2db0"-"\u2db6", "\u2db8"-"\u2dbe", "\u2dc0"-"\u2dc6",
+ "\u2dc8"-"\u2dce", "\u2dd0"-"\u2dd6", "\u2dd8"-"\u2dde", "\u2de0"-"\u2dff", "\u2e2f", "\u3005"-"\u3007",
+ "\u3021"-"\u302f", "\u3031"-"\u3035", "\u3038"-"\u303c", "\u3041"-"\u3096", "\u3099"-"\u309a",
+ "\u309d"-"\u309f", "\u30a1"-"\u30fa", "\u30fc"-"\u30ff", "\u3105"-"\u312d", "\u3131"-"\u318e",
+ "\u31a0"-"\u31ba", "\u31f0"-"\u31ff", "\u3400"-"\u4db5", "\u4e00"-"\u9fcc", "\ua000"-"\ua48c",
+ "\ua4d0"-"\ua4fd", "\ua500"-"\ua60c", "\ua610"-"\ua62b", "\ua640"-"\ua66f", "\ua674"-"\ua67d",
+ "\ua67f"-"\ua697", "\ua69f"-"\ua6f1", "\ua717"-"\ua71f", "\ua722"-"\ua788", "\ua78b"-"\ua78e",
+ "\ua790"-"\ua793", "\ua7a0"-"\ua7aa", "\ua7f8"-"\ua827", "\ua838", "\ua840"-"\ua873", "\ua880"-"\ua8c4",
+ "\ua8d0"-"\ua8d9", "\ua8e0"-"\ua8f7", "\ua8fb", "\ua900"-"\ua92d", "\ua930"-"\ua953", "\ua960"-"\ua97c",
+ "\ua980"-"\ua9c0", "\ua9cf"-"\ua9d9", "\uaa00"-"\uaa36", "\uaa40"-"\uaa4d", "\uaa50"-"\uaa59",
+ "\uaa60"-"\uaa76", "\uaa7a"-"\uaa7b", "\uaa80"-"\uaac2", "\uaadb"-"\uaadd", "\uaae0"-"\uaaef",
+ "\uaaf2"-"\uaaf6", "\uab01"-"\uab06", "\uab09"-"\uab0e", "\uab11"-"\uab16", "\uab20"-"\uab26",
+ "\uab28"-"\uab2e", "\uabc0"-"\uabea", "\uabec"-"\uabed", "\uabf0"-"\uabf9", "\uac00"-"\ud7a3",
+ "\ud7b0"-"\ud7c6", "\ud7cb"-"\ud7fb", "\ud800"-"\udfff", "\uf900"-"\ufa6d", "\ufa70"-"\ufad9",
+ "\ufb00"-"\ufb06", "\ufb13"-"\ufb17", "\ufb1d"-"\ufb28", "\ufb2a"-"\ufb36", "\ufb38"-"\ufb3c",
+ "\ufb3e", "\ufb40"-"\ufb41", "\ufb43"-"\ufb44", "\ufb46"-"\ufbb1", "\ufbd3"-"\ufd3d", "\ufd50"-"\ufd8f",
+ "\ufd92"-"\ufdc7", "\ufdf0"-"\ufdfc", "\ufe00"-"\ufe0f", "\ufe20"-"\ufe26", "\ufe33"-"\ufe34",
+ "\ufe4d"-"\ufe4f", "\ufe69", "\ufe70"-"\ufe74", "\ufe76"-"\ufefc", "\ufeff", "\uff04", "\uff10"-"\uff19",
+ "\uff21"-"\uff3a", "\uff3f", "\uff41"-"\uff5a", "\uff66"-"\uffbe", "\uffc2"-"\uffc7", "\uffca"-"\uffcf",
+ "\uffd2"-"\uffd7", "\uffda"-"\uffdc", "\uffe0"-"\uffe1", "\uffe5"-"\uffe6", "\ufff9"-"\ufffb" ]
+ | <UNICODE_ESCAPE>
+ >
+}
+
+/* SEPARATORS */
+
+TOKEN :
+{
+ < LPAREN: "(" >
+| < RPAREN: ")" >
+| < LBRACE: "{" >
+| < RBRACE: "}" >
+| < LBRACKET: "[" >
+| < RBRACKET: "]" >
+| < SEMICOLON: ";" >
+| < COMMA: "," >
+| < DOT: "." >
+| < AT: "@" >
+}
+
+/* OPERATORS */
+
+TOKEN :
+{
+ < ASSIGN: "=" >
+| < LT: "<" >
+| < BANG: "!" >
+| < TILDE: "~" >
+| < HOOK: "?" >
+| < COLON: ":" >
+| < EQ: "==" >
+| < LE: "<=" >
+| < GE: ">=" >
+| < NE: "!=" >
+| < SC_OR: "||" >
+| < SC_AND: "&&" >
+| < INCR: "++" >
+| < DECR: "--" >
+| < PLUS: "+" >
+| < MINUS: "-" >
+| < STAR: "*" >
+| < SLASH: "/" >
+| < BIT_AND: "&" >
+| < BIT_OR: "|" >
+| < XOR: "^" >
+| < REM: "%" >
+| < LSHIFT: "<<" >
+| < PLUSASSIGN: "+=" >
+| < MINUSASSIGN: "-=" >
+| < STARASSIGN: "*=" >
+| < SLASHASSIGN: "/=" >
+| < ANDASSIGN: "&=" >
+| < ORASSIGN: "|=" >
+| < XORASSIGN: "^=" >
+| < REMASSIGN: "%=" >
+| < LSHIFTASSIGN: "<<=" >
+| < RSIGNEDSHIFTASSIGN: ">>=" >
+| < RUNSIGNEDSHIFTASSIGN: ">>>=" >
+| < ELLIPSIS: "..." >
+| < ARROW: "->" >
+| < DOUBLECOLON: "::" >
+}
+
+/* >'s need special attention due to generics syntax. */
+TOKEN :
+{
+ < RUNSIGNEDSHIFT: ">>>" >
+ {
+ matchedToken.kind = GT;
+ matchedToken.realKind = RUNSIGNEDSHIFT;
+ input_stream.backup(2);
+ }
+| < RSIGNEDSHIFT: ">>" >
+ {
+ matchedToken.kind = GT;
+ matchedToken.realKind = RSIGNEDSHIFT;
+ input_stream.backup(1);
+ }
+| < GT: ">" >
+}
+
+TOKEN: { <CTRL_Z: "\u001A" /** ctrl+z char **/> }
+
+/*****************************************
+ * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
+ *****************************************/
+
+/*
+ * Program structuring syntax follows.
+ */
+
+CompilationUnit CompilationUnit():
+{
+ PackageDeclaration pakage = null;
+ NodeList<ImportDeclaration> imports = emptyList();
+ ImportDeclaration in = null;
+ NodeList<TypeDeclaration<?>> types = emptyList();
+ ModifierHolder modifier;
+ TypeDeclaration tn = null;
+ ModuleDeclaration module = null;
+}
+{
+ try {
+ ( LOOKAHEAD(2)";" )*
+ [ LOOKAHEAD(PackageDeclaration()) pakage = PackageDeclaration() ]
+ (
+ in = ImportDeclaration() { imports = add(imports, in); }
+ |
+ (
+ modifier = Modifiers()
+ (
+ tn = ClassOrInterfaceDeclaration(modifier) { types = add(types, tn); }
+ |
+ tn = EnumDeclaration(modifier) { types = add(types, tn); }
+ |
+ tn = AnnotationTypeDeclaration(modifier) { types = add(types, tn); }
+ |
+ module = ModuleDeclaration(modifier)
+ |
+ ";"
+ )
+ )
+ )*
+ (<EOF> | <CTRL_Z>)
+ { return new CompilationUnit(range(token_source.getHomeToken(), token()), pakage, imports, types, module); }
+ } catch (ParseException e) {
+ recover(EOF, e);
+ final CompilationUnit compilationUnit = new CompilationUnit(range(token_source.getHomeToken(), token()), null, new NodeList<ImportDeclaration>(), new NodeList<TypeDeclaration<?>>(), null);
+ compilationUnit.setParsed(UNPARSABLE);
+ return compilationUnit;
+ }
+}
+
+PackageDeclaration PackageDeclaration():
+{
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+ Name name;
+ JavaToken begin;
+}
+{
+ annotations = Annotations()
+ "package" {begin = token();} name = Name() ";"
+ { return new PackageDeclaration(range(begin, token()), annotations, name); }
+}
+
+
+ImportDeclaration ImportDeclaration():
+{
+ Name name;
+ boolean isStatic = false;
+ boolean isAsterisk = false;
+ JavaToken begin;
+}
+{
+ "import" {begin = token();}
+ [ "static" { isStatic = true; } ]
+ name = Name()
+ [ "." "*" { isAsterisk = true; } ] ";"
+ { return new ImportDeclaration(range(begin, token()), name, isStatic, isAsterisk); }
+}
+
+/*
+ * Modifiers. We match all modifiers in a single rule to reduce the chances of
+ * syntax errors for simple modifier mistakes. It will also enable us to give
+ * better error messages.
+ */
+
+ModifierHolder Modifiers():
+{
+ JavaToken begin = INVALID;
+ EnumSet<Modifier> modifiers = EnumSet.noneOf(Modifier.class);
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+ AnnotationExpr ann;
+}
+{
+ (
+ LOOKAHEAD(2)
+ (
+ "public" { addModifier(modifiers, Modifier.PUBLIC); begin = orIfInvalid(begin, token()); }
+ |
+ "static" { addModifier(modifiers, Modifier.STATIC); begin = orIfInvalid(begin, token()); }
+ |
+ "protected" { addModifier(modifiers, Modifier.PROTECTED); begin = orIfInvalid(begin, token()); }
+ |
+ "private" { addModifier(modifiers, Modifier.PRIVATE); begin = orIfInvalid(begin, token()); }
+ |
+ "final" { addModifier(modifiers, Modifier.FINAL); begin = orIfInvalid(begin, token()); }
+ |
+ "abstract" { addModifier(modifiers, Modifier.ABSTRACT); begin = orIfInvalid(begin, token()); }
+ |
+ "synchronized" { addModifier(modifiers, Modifier.SYNCHRONIZED); begin = orIfInvalid(begin, token()); }
+ |
+ "native" { addModifier(modifiers, Modifier.NATIVE); begin = orIfInvalid(begin, token()); }
+ |
+ "transient" { addModifier(modifiers, Modifier.TRANSIENT); begin = orIfInvalid(begin, token()); }
+ |
+ "volatile" { addModifier(modifiers, Modifier.VOLATILE); begin = orIfInvalid(begin, token()); }
+ |
+ "strictfp" { addModifier(modifiers, Modifier.STRICTFP); begin = orIfInvalid(begin, token()); }
+ |
+ "transitive" { addModifier(modifiers, Modifier.TRANSITIVE); begin = orIfInvalid(begin, token()); }
+ |
+ "default" { addModifier(modifiers, Modifier.DEFAULT); begin = orIfInvalid(begin, token()); }
+ |
+ ann = Annotation() { annotations = add(annotations, ann); begin = orIfInvalid(begin, ann); }
+ )
+ )*
+
+ {
+ return new ModifierHolder(begin, modifiers, annotations);
+ }
+}
+
+/*
+ * Declaration syntax follows.
+ */
+
+ClassOrInterfaceDeclaration ClassOrInterfaceDeclaration(ModifierHolder modifier):
+{
+ boolean isInterface = false;
+ SimpleName name;
+ RangedList<TypeParameter> typePar = new RangedList<TypeParameter>(emptyList());
+ NodeList<ClassOrInterfaceType> extList = emptyList();
+ NodeList<ClassOrInterfaceType> impList = emptyList();
+ NodeList<BodyDeclaration<?>> members = emptyList();
+ JavaToken begin = modifier.begin;
+}
+{
+ ( "class" | "interface" { isInterface = true; } ) { begin = orIfInvalid(begin, token()); }
+ name = SimpleName()
+ [ typePar = TypeParameters() ]
+ [ extList = ExtendsList() ]
+ [ impList = ImplementsList() ]
+ members = ClassOrInterfaceBody()
+
+ { return new ClassOrInterfaceDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, isInterface, name, typePar.list, extList, impList, members); }
+}
+
+NodeList<ClassOrInterfaceType> ExtendsList():
+{
+ boolean extendsMoreThanOne = false;
+ NodeList<ClassOrInterfaceType> ret = new NodeList<ClassOrInterfaceType>();
+ ClassOrInterfaceType cit;
+}
+{
+ "extends" cit = AnnotatedClassOrInterfaceType() { ret.add(cit); }
+ ( "," cit = AnnotatedClassOrInterfaceType() { ret.add(cit); extendsMoreThanOne = true; } )*
+ { return ret; }
+}
+
+NodeList<ClassOrInterfaceType> ImplementsList():
+{
+ NodeList<ClassOrInterfaceType> ret = new NodeList<ClassOrInterfaceType>();
+ ClassOrInterfaceType cit;
+}
+{
+ "implements" cit = AnnotatedClassOrInterfaceType() { ret.add(cit); }
+ ( "," cit = AnnotatedClassOrInterfaceType() { ret.add(cit); } )*
+ { return ret; }
+}
+
+EnumDeclaration EnumDeclaration(ModifierHolder modifier):
+{
+ SimpleName name;
+ NodeList<ClassOrInterfaceType> impList = emptyList();
+ EnumConstantDeclaration entry;
+ NodeList<EnumConstantDeclaration> entries = emptyList();
+ BodyDeclaration<?> member;
+ NodeList<BodyDeclaration<?>> members = emptyList();
+ JavaToken begin = modifier.begin;
+}
+{
+ "enum" { begin = orIfInvalid(begin, token()); }
+ name = SimpleName()
+ [ impList = ImplementsList() ]
+ "{"
+ [
+ entry = EnumConstantDeclaration() { entries.add(entry); } ( LOOKAHEAD(2) "," entry = EnumConstantDeclaration() { entries.add(entry); } )*
+ ]
+ [ "," ]
+ [
+ ";" (
+ member = ClassOrInterfaceBodyDeclaration() { members = add(members, member); }
+ |
+ ";"
+ )*
+ ]
+ "}"
+
+ { return new EnumDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, name, impList, entries, members); }
+}
+
+
+EnumConstantDeclaration EnumConstantDeclaration():
+{
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+ AnnotationExpr ann;
+ SimpleName name;
+ NodeList<Expression> args = emptyList();
+ NodeList<BodyDeclaration<?>> classBody = emptyList();
+ JavaToken begin = INVALID;
+}
+{
+ { }
+ ( ann = Annotation() { annotations = add(annotations, ann); begin = orIfInvalid(begin, ann); } )*
+ name = SimpleName() { begin = orIfInvalid(begin, token()); }
+ [ args = Arguments() ] [ classBody = ClassOrInterfaceBody() ]
+ {
+ return new EnumConstantDeclaration(range(begin, token()), annotations, name, args, classBody);
+ }
+}
+
+/**
+ * If the list inside the returned RangedList is null, there are no brackets.
+ * If it is empty, there are brackets, but nothing is in them <>.
+ * The normal case is that it contains TypeParameters, like <A, B, C>.
+ */
+RangedList<TypeParameter> TypeParameters():
+{
+ RangedList<TypeParameter> ret = new RangedList<TypeParameter>(new NodeList<TypeParameter>());
+ TypeParameter tp;
+ NodeList<AnnotationExpr> annotations;
+}
+{
+ "<" { ret.beginAt(token()); }
+ annotations = Annotations()
+ tp = TypeParameter(annotations) { ret.add(tp); annotations = null; }
+ ( ","
+ annotations = Annotations() tp = TypeParameter(annotations) { ret.add(tp); annotations = null; } )*
+ ">" { ret.endAt(token()); }
+ { return ret; }
+}
+
+TypeParameter TypeParameter(NodeList<AnnotationExpr> annotations):
+{
+ SimpleName name;
+ NodeList<ClassOrInterfaceType> typeBound = emptyList();
+ JavaToken begin;
+}
+{
+ name = SimpleName() { begin=token(); } [ typeBound = TypeBound() ]
+ { return new TypeParameter(range(begin, token()), name, typeBound, annotations); }
+}
+
+NodeList<ClassOrInterfaceType> TypeBound():
+{
+ NodeList<ClassOrInterfaceType> ret = emptyList();
+ ClassOrInterfaceType cit;
+}
+{
+ "extends" cit = AnnotatedClassOrInterfaceType() { ret.add(cit); }
+ ( "&" cit = AnnotatedClassOrInterfaceType() { ret.add(cit); } )*
+ { return ret; }
+}
+
+NodeList<BodyDeclaration<?>> ClassOrInterfaceBody():
+{
+ NodeList<BodyDeclaration<?>> ret = emptyList();
+ BodyDeclaration member;
+}
+{
+ "{" (
+ member = ClassOrInterfaceBodyDeclaration() { ret.add(member); }
+ |
+ ";"
+ )* "}"
+ { return ret; }
+}
+
+BodyDeclaration<?> ClassOrInterfaceBodyDeclaration():
+{
+ ModifierHolder modifier;
+ BodyDeclaration<?> ret;
+}
+{
+ (
+ LOOKAHEAD(2)
+ ret = InitializerDeclaration()
+ |
+ // Just get all the modifiers out of the way. If you want to do
+ // more checks, pass the modifiers down to the member
+ modifier = Modifiers()
+ (
+ ret = ClassOrInterfaceDeclaration(modifier)
+ | LOOKAHEAD("enum")
+ ret = EnumDeclaration(modifier)
+ | LOOKAHEAD("@" "interface")
+ ret = AnnotationTypeDeclaration(modifier)
+ | LOOKAHEAD( [ TypeParameters() ] Identifier() "(" )
+ ret = ConstructorDeclaration(modifier)
+ | LOOKAHEAD( Type() Identifier() ( ArrayBracketPair() )* ( "," | "=" | ";" ) )
+ ret = FieldDeclaration(modifier)
+ |
+ ret = MethodDeclaration(modifier)
+ )
+ )
+ { return ret; }
+}
+
+FieldDeclaration FieldDeclaration(ModifierHolder modifier):
+{
+ Type partialType;
+ NodeList<VariableDeclarator> variables = new NodeList<VariableDeclarator>();
+ VariableDeclarator val;
+}
+{
+ // Modifiers are already matched in the caller
+ partialType = Type(emptyList()) val = VariableDeclarator(partialType) { variables.add(val); }
+ ( "," val = VariableDeclarator(partialType) { variables.add(val); } )* ";"
+ {
+ JavaToken begin = orIfInvalid(modifier.begin, partialType);
+ return new FieldDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, variables);
+ }
+}
+
+VariableDeclarator VariableDeclarator(Type partialType):
+{
+ Pair<SimpleName, List<ArrayBracketPair>> id;
+ Expression init = null;
+}
+{
+ id = VariableDeclaratorId() [ "=" init = VariableInitializer() ]
+ { return new VariableDeclarator(range(id.a, token()), juggleArrayType(partialType, id.b), id.a, init); }
+}
+
+Pair<SimpleName, List<ArrayBracketPair>> VariableDeclaratorId():
+{
+ SimpleName name;
+ JavaToken begin;
+ ArrayBracketPair arrayBracketPair;
+ List<ArrayBracketPair> arrayBracketPairs = new ArrayList(0);
+}
+{
+ name = SimpleName() { begin=token();} ( arrayBracketPair = ArrayBracketPair(Origin.NAME) { arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); } )*
+ {
+ if(storeTokens) {
+ name.setTokenRange(name.getTokenRange().get().withEnd(token()));
+ }
+ return new Pair(name, arrayBracketPairs);
+ }
+}
+
+Expression VariableInitializer():
+{
+ Expression ret;
+}
+{
+ (
+ ret = ArrayInitializer()
+ |
+ ret = Expression()
+ )
+ { return ret;}
+}
+
+ArrayInitializerExpr ArrayInitializer():
+{
+ NodeList<Expression> values = emptyList();
+ Expression val;
+ JavaToken begin;
+}
+{
+ "{" {begin=token();} [ val = VariableInitializer() { values = add(values, val); } ( LOOKAHEAD(2) "," val = VariableInitializer() { values = add(values, val); } )* ] [ "," ] "}"
+ { return new ArrayInitializerExpr(range(begin, token()), values); }
+}
+
+MethodDeclaration MethodDeclaration(ModifierHolder modifier):
+{
+ RangedList<TypeParameter> typeParameters = new RangedList<TypeParameter>(emptyList());
+ Type type;
+ SimpleName name;
+ Pair<NodeList<Parameter>, ReceiverParameter> parameters = new Pair<NodeList<Parameter>, ReceiverParameter>(emptyList(), null);
+ ArrayBracketPair arrayBracketPair;
+ List<ArrayBracketPair> arrayBracketPairs = new ArrayList(0);
+ NodeList<ReferenceType> throws_ = emptyList();
+ BlockStmt body = null;
+ NodeList<AnnotationExpr> annotations;
+ JavaToken begin = modifier.begin;
+ ReferenceType throwType;
+}
+{
+ // Modifiers already matched in the caller!
+ [ typeParameters = TypeParameters() { begin = orIfInvalid(begin, typeParameters.range.getBegin()); } ]
+ annotations = Annotations() { modifier.annotations.addAll(annotations); begin = orIfInvalid(begin, nodeListBegin(annotations)); }
+ type = ResultType(emptyList()) { begin = orIfInvalid(begin, type); }
+ name = SimpleName() parameters = Parameters() ( arrayBracketPair = ArrayBracketPair(Origin.NAME) { arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); } )*
+ [ "throws" throwType = AnnotatedReferenceType() { throws_ = add(throws_, throwType); }
+ ("," throwType = AnnotatedReferenceType() { throws_ = add(throws_, throwType); } )* ]
+ ( body = Block() | ";" )
+ {
+ type = juggleArrayType(type, arrayBracketPairs);
+ return new MethodDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, typeParameters.list, type, name, parameters.a, throws_, body, parameters.b);
+ }
+}
+
+ReferenceType AnnotatedReferenceType():
+{
+ NodeList<AnnotationExpr> annotations;
+ ReferenceType type;
+}
+{
+ annotations = Annotations()
+ type = ReferenceType(annotations)
+ { return type; }
+}
+
+Type AnnotatedType():
+{
+ NodeList<AnnotationExpr> annotations;
+ Type type;
+}
+{
+ annotations = Annotations()
+ type = Type(annotations)
+ { return type; }
+}
+
+Pair<NodeList<Parameter>, ReceiverParameter> Parameters():
+{
+ NodeList<Parameter> ret = emptyList();
+ Parameter par;
+ ReceiverParameter rp = null;
+}
+{
+ "("
+ [
+ ( LOOKAHEAD(ReceiverParameter())
+ rp = ReceiverParameter()
+ |
+ par = Parameter() { ret = add(ret, par); }
+ )
+ ( "," par = Parameter() { ret = add(ret, par); } )*
+ ]
+ ")"
+ { return new Pair(ret, rp); }
+}
+
+NodeList<Parameter> LambdaParameters():
+{
+ NodeList<Parameter> ret = null;
+ Parameter par;
+}
+{
+ par = Parameter() { ret = add(ret, par); } ( "," par = Parameter() { ret = add(ret, par); } )*
+ { return ret; }
+}
+
+NodeList<Parameter> InferredLambdaParameters():
+{
+ NodeList<Parameter> ret = null;
+ Pair<SimpleName, List<ArrayBracketPair>> id;
+}
+{
+ id = VariableDeclaratorId() { ret = add(ret, new Parameter(range(id.a, id.a), EnumSet.noneOf(Modifier.class), emptyList(), new UnknownType(), false, emptyList(), id.a));}
+ (
+ "," id = VariableDeclaratorId() { ret = add(ret, new Parameter(range(id.a, id.a), EnumSet.noneOf(Modifier.class), emptyList(), new UnknownType(), false, emptyList(), id.a)); }
+ )*
+ { return ret; }
+}
+
+Parameter Parameter():
+{
+ ModifierHolder modifier;
+ Type partialType;
+ boolean isVarArg = false;
+ Pair<SimpleName, List<ArrayBracketPair>> id;
+ NodeList<AnnotationExpr> varArgAnnotations = emptyList();
+}
+{
+ modifier = Modifiers() partialType = Type(emptyList()) [ varArgAnnotations = Annotations() "..." { isVarArg = true;} ]
+ id = VariableDeclaratorId()
+ {
+ JavaToken begin = orIfInvalid(modifier.begin, partialType);
+ return new Parameter(range(begin, token()), modifier.modifiers, modifier.annotations, juggleArrayType(partialType, id.b), isVarArg, varArgAnnotations, id.a);
+ }
+}
+
+ReceiverParameter ReceiverParameter():
+{
+ Type partialType;
+ Name id;
+ NodeList<AnnotationExpr> annotations = emptyList();
+}
+{
+ annotations = Annotations()
+ partialType = Type(emptyList())
+ id = ReceiverParameterId()
+ {
+ return new ReceiverParameter(range(partialType, token()), annotations, partialType, id);
+ }
+}
+
+Name ReceiverParameterId():
+{
+ Name ret = null;
+ NodeList<AnnotationExpr> annotations;
+}
+{
+ [ LOOKAHEAD(Name()) ret = Name() "."] annotations=Annotations() "this"
+ { return new Name(tokenRange(), ret, token.image, annotations); }
+}
+
+ConstructorDeclaration ConstructorDeclaration(ModifierHolder modifier):
+{
+ RangedList<TypeParameter> typeParameters = new RangedList<TypeParameter>(emptyList());
+ SimpleName name;
+ Pair<NodeList<Parameter>, ReceiverParameter> parameters = new Pair<NodeList<Parameter>, ReceiverParameter>(emptyList(), null);
+ NodeList<ReferenceType> throws_ = emptyList();
+ ExplicitConstructorInvocationStmt exConsInv = null;
+ NodeList<Statement> stmts = emptyList();
+ JavaToken begin = modifier.begin;
+ JavaToken blockBegin = INVALID;
+ ReferenceType throwType;
+}
+{
+ [ typeParameters = TypeParameters() { begin = orIfInvalid(begin, typeParameters.range.getBegin()); } ]
+ // Modifiers matched in the caller
+ name = SimpleName() { begin = orIfInvalid(begin, typeParameters.range.getBegin()); begin = orIfInvalid(begin, token()); } parameters = Parameters() [ "throws" throwType = AnnotatedReferenceType() { throws_ = add(throws_, throwType); }
+ ("," throwType = AnnotatedReferenceType() { throws_ = add(throws_, throwType); })* ]
+ "{" { blockBegin=token(); }
+ [ LOOKAHEAD(ExplicitConstructorInvocation()) exConsInv = ExplicitConstructorInvocation() ]
+ stmts = Statements()
+ "}"
+
+ {
+ if (exConsInv != null) {
+ stmts = prepend(stmts, exConsInv);
+ }
+ return new ConstructorDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, typeParameters.list, name, parameters.a, throws_, new BlockStmt(range(blockBegin, token()), stmts), parameters.b);
+ }
+}
+
+ExplicitConstructorInvocationStmt ExplicitConstructorInvocation():
+{
+ boolean isThis = false;
+ NodeList<Expression> args;
+ Expression expr = null;
+ RangedList<Type> typeArgs = new RangedList<Type>(null);
+ JavaToken begin = INVALID;
+}
+{
+ (
+ LOOKAHEAD([ TypeArguments() ] <THIS> "(")
+ [ typeArgs = TypeArguments() { begin=typeArgs.range.getBegin(); } ]
+ <THIS> { begin = orIfInvalid(begin, token()); isThis = true; }
+ args = Arguments() ";"
+ |
+ [
+ LOOKAHEAD( PrimaryExpressionWithoutSuperSuffix() "." )
+ expr = PrimaryExpressionWithoutSuperSuffix() "."
+ { begin = orIfInvalid(begin, expr); }
+ ]
+ [ typeArgs = TypeArguments() { begin = orIfInvalid(begin, typeArgs.range.getBegin()); } ]
+ <SUPER> {begin = orIfInvalid(begin, token());}
+ args = Arguments() ";"
+ )
+ { return new ExplicitConstructorInvocationStmt(range(begin, token()),typeArgs.list, isThis, expr, args); }
+}
+
+NodeList<Statement> Statements():
+{
+ NodeList<Statement> ret = emptyList();
+ Statement stmt;
+}
+{
+ ( LOOKAHEAD(2) stmt = BlockStatement() { ret = add(ret, stmt); } )*
+ { return ret; }
+}
+
+InitializerDeclaration InitializerDeclaration():
+{
+ BlockStmt body;
+ JavaToken begin = INVALID;
+ boolean isStatic = false;
+}
+{
+ [ "static" { isStatic = true; begin=token();} ]
+ body = Block() {begin = orIfInvalid(begin, body);}
+ { return new InitializerDeclaration(range(begin, token()), isStatic, body); }
+}
+
+
+/*
+ * Type, name and expression syntax follows.
+ */
+
+Type Type(NodeList<AnnotationExpr> annotations):
+{
+ Type ret;
+}
+{
+ (
+ LOOKAHEAD(2) ret = ReferenceType(annotations)
+ |
+ ret = PrimitiveType(annotations )
+ )
+ { return ret; }
+}
+
+ReferenceType ReferenceType(NodeList<AnnotationExpr> annotations):
+{
+ Type type;
+ ArrayBracketPair arrayBracketPair;
+ List<ArrayBracketPair> arrayBracketPairs = new ArrayList(0);
+}
+{
+ (
+ type = PrimitiveType(annotations) ( LOOKAHEAD(Annotations() "[") arrayBracketPair = ArrayBracketPair(Origin.TYPE) { arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); } )+
+ |
+ type = ClassOrInterfaceType(annotations) ( LOOKAHEAD(Annotations() "[") arrayBracketPair = ArrayBracketPair(Origin.TYPE) { arrayBracketPairs=add(arrayBracketPairs, arrayBracketPair); } )*
+ )
+ { return (ReferenceType)wrapInArrayTypes(type, arrayBracketPairs); }
+}
+
+ArrayBracketPair ArrayBracketPair(Origin origin):
+{
+ NodeList<AnnotationExpr> annotations;
+ JavaToken begin = INVALID;
+}
+{
+ annotations = Annotations()
+ "[" { begin = orIfInvalid(begin, token()); } "]"
+ { return new ArrayBracketPair(range(begin, token()), origin, annotations); }
+}
+
+IntersectionType IntersectionType(NodeList<AnnotationExpr> annotations):
+{
+ JavaToken begin = INVALID;
+ ReferenceType elementType;
+ NodeList<ReferenceType> elements = emptyList();
+}
+{
+ elementType = ReferenceType(annotations) { begin = orIfInvalid(begin, elementType); elements = add(elements, elementType); }
+ "&" (elementType = AnnotatedReferenceType() { elements = add(elements, elementType); } )+
+ { return new IntersectionType(range(begin, token()), elements); }
+}
+
+ClassOrInterfaceType AnnotatedClassOrInterfaceType():
+{
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+ ClassOrInterfaceType cit;
+}
+{
+ annotations = Annotations()
+ cit = ClassOrInterfaceType(annotations)
+ { return cit; }
+}
+
+ClassOrInterfaceType ClassOrInterfaceType(NodeList<AnnotationExpr> firstAnnotations):
+{
+ ClassOrInterfaceType ret;
+ SimpleName name;
+ RangedList<Type> typeArgs = new RangedList<Type>(null);
+ JavaToken begin;
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+}
+{
+ name = SimpleName() {begin=token();}
+ [ LOOKAHEAD(2) typeArgs = TypeArguments() ]
+ {
+ ret = new ClassOrInterfaceType(range(begin, token()), null, name, typeArgs.list, firstAnnotations);
+ typeArgs = new RangedList<Type>(null);
+ }
+ (
+ LOOKAHEAD(2) "." annotations = Annotations() name = SimpleName()
+ [ LOOKAHEAD(2) typeArgs = TypeArguments() ]
+ {
+ ret = new ClassOrInterfaceType(range(begin, token()), ret, name, typeArgs.list, annotations);
+ typeArgs = new RangedList<Type>(null);
+ }
+ )*
+ { return ret; }
+}
+
+RangedList<Type> TypeArguments():
+{
+ RangedList<Type> ret = new RangedList<Type>(new NodeList<Type>());
+ Type type;
+}
+{
+ (
+ "<" { ret.beginAt(token()); }
+ (type = TypeArgument() { ret.add(type); } ( "," type = TypeArgument() { ret.add(type); } )*)?
+ ">" { ret.endAt(token()); }
+ )
+ { return ret; }
+}
+
+Type TypeArgument():
+{
+ Type ret;
+ NodeList<AnnotationExpr> annotations;
+}
+{
+ annotations = Annotations()
+ (
+ ret = Type(annotations)
+ |
+ ret = Wildcard(annotations)
+ )
+ { return ret; }
+}
+
+WildcardType Wildcard(NodeList<AnnotationExpr> firstAnnotations):
+{
+ ReferenceType ext = null;
+ ReferenceType sup = null;
+ JavaToken begin;
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+}
+{
+ "?" {begin=token();}
+ [
+ "extends" annotations = Annotations() ext = ReferenceType(annotations)
+ |
+ "super" annotations = Annotations() sup = ReferenceType(annotations)
+ ]
+ {
+ return new WildcardType(range(begin, token()), ext, sup, firstAnnotations);
+ }
+}
+
+PrimitiveType PrimitiveType(NodeList<AnnotationExpr> annotations):
+{
+ PrimitiveType ret;
+}
+{
+(
+ "boolean" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.BOOLEAN, annotations); }
+|
+ "char" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.CHAR, annotations); }
+|
+ "byte" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.BYTE, annotations); }
+|
+ "short" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.SHORT, annotations); }
+|
+ "int" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.INT, annotations); }
+|
+ "long" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.LONG, annotations); }
+|
+ "float" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.FLOAT, annotations); }
+|
+ "double" { ret = new PrimitiveType(tokenRange(), PrimitiveType.Primitive.DOUBLE, annotations); }
+)
+{ return ret; }
+}
+
+Type ResultType(NodeList<AnnotationExpr> annotations):
+{
+ Type ret;
+}
+{
+ (
+ "void" { ret = new VoidType(tokenRange()); }
+ |
+ ret = Type(annotations)
+ )
+ { return ret; }
+}
+
+Name Name():
+/*
+ * A lookahead is required below since "Name" can be followed
+ * by a ".*" when used in the context of an "ImportDeclaration".
+ */
+{
+ Name ret;
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+}
+{
+ annotations=Annotations() Identifier() { ret = new Name(tokenRange(), null, token.image, annotations); }
+ ( LOOKAHEAD("." Annotations() Identifier())
+ "." annotations=Annotations() Identifier() { ret = new Name(range(ret, token()), ret, token.image, annotations); } )*
+ { return ret; }
+}
+
+SimpleName SimpleName():
+{
+ SimpleName ret;
+}
+{
+ Identifier() { ret = new SimpleName(tokenRange(), token.image); }
+ { return ret; }
+}
+
+
+String Identifier():
+{
+ String ret;
+}
+{
+ // Make sure the module info keywords don't interfere with normal Java parsing by matching them as normal identifiers.
+ (<MODULE> | <REQUIRES> | <TO> | <WITH> | <OPEN> | <OPENS> | <USES> | <EXPORTS> | <PROVIDES> | <TRANSITIVE> |
+ // Make sure older Java versions parse
+ <ENUM> | <STRICTFP> |
+ // An actual plain old identifier
+ <IDENTIFIER>) { ret = token.image; setTokenKind(IDENTIFIER);}
+ { return ret; }
+}
+
+/*
+ * Expression syntax follows.
+ */
+
+Expression Expression():
+/*
+ * This expansion has been written this way instead of:
+ * Assignment() | ConditionalExpression()
+ * for performance reasons.
+ * However, it is a weakening of the grammar for it allows the LHS of
+ * assignments to be any conditional expression whereas it can only be
+ * a primary expression. This is caught by a validation after parsing.
+ */
+{
+ Expression ret;
+ AssignExpr.Operator op;
+ Expression value;
+ Statement lambdaBody = null;
+ RangedList<Type> typeArgs = new RangedList<Type>(null);
+}
+{
+ ret = ConditionalExpression()
+ [
+ ( LOOKAHEAD(2)
+ op = AssignmentOperator() value = Expression() { ret = new AssignExpr(range(ret, token()), ret, value, op); }
+ |
+ "->" lambdaBody = LambdaBody()
+ {
+ if (ret instanceof CastExpr) {
+ ret = generateLambda(ret, lambdaBody);
+ } else if (ret instanceof ConditionalExpr) {
+ ConditionalExpr ce = (ConditionalExpr) ret;
+ if(ce.getElseExpr() != null) {
+ ce.setElseExpr(generateLambda(ce.getElseExpr(), lambdaBody));
+ }
+ } else {
+ ret = generateLambda(ret, lambdaBody);
+ }
+ }
+ |
+ "::" [typeArgs = TypeArguments() ] (Identifier() | "new") { ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image); }
+ )
+ ]
+
+ { return ret; }
+}
+
+AssignExpr.Operator AssignmentOperator():
+{
+ AssignExpr.Operator ret;
+}
+{
+ (
+ "=" { ret = AssignExpr.Operator.ASSIGN; }
+ | "*=" { ret = AssignExpr.Operator.MULTIPLY; }
+ | "/=" { ret = AssignExpr.Operator.DIVIDE; }
+ | "%=" { ret = AssignExpr.Operator.REMAINDER; }
+ | "+=" { ret = AssignExpr.Operator.PLUS; }
+ | "-=" { ret = AssignExpr.Operator.MINUS; }
+ | "<<=" { ret = AssignExpr.Operator.LEFT_SHIFT; }
+ | ">>=" { ret = AssignExpr.Operator.SIGNED_RIGHT_SHIFT; }
+ | ">>>=" { ret = AssignExpr.Operator.UNSIGNED_RIGHT_SHIFT; }
+ | "&=" { ret = AssignExpr.Operator.BINARY_AND; }
+ | "^=" { ret = AssignExpr.Operator.XOR; }
+ | "|=" { ret = AssignExpr.Operator.BINARY_OR; }
+ )
+ { return ret; }
+}
+
+Expression ConditionalExpression():
+{
+ Expression ret;
+ Expression left;
+ Expression right;
+}
+{
+ ret = ConditionalOrExpression()
+ [ "?" left = Expression() ":" right = ConditionalExpression() { ret = new ConditionalExpr(range(ret, token()), ret, left, right); } ]
+ { return ret; }
+}
+
+Expression ConditionalOrExpression():
+{
+ Expression ret;
+ Expression right;
+}
+{
+ ret = ConditionalAndExpression() ( "||" right = ConditionalAndExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.OR); } )*
+ { return ret; }
+}
+
+Expression ConditionalAndExpression():
+{
+ Expression ret;
+ Expression right;
+}
+{
+ ret = InclusiveOrExpression() ( "&&" right = InclusiveOrExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.AND); } )*
+ { return ret; }
+}
+
+Expression InclusiveOrExpression():
+{
+ Expression ret;
+ Expression right;
+}
+{
+ ret = ExclusiveOrExpression() ( "|" right = ExclusiveOrExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.BINARY_OR); } )*
+ { return ret; }
+}
+
+Expression ExclusiveOrExpression():
+{
+ Expression ret;
+ Expression right;
+}
+{
+ ret = AndExpression() ( "^" right = AndExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.XOR); } )*
+ { return ret; }
+}
+
+Expression AndExpression():
+{
+ Expression ret;
+ Expression right;
+}
+{
+ ret = EqualityExpression() ( "&" right = EqualityExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, BinaryExpr.Operator.BINARY_AND); } )*
+ { return ret; }
+}
+
+Expression EqualityExpression():
+{
+ Expression ret;
+ Expression right;
+ BinaryExpr.Operator op;
+}
+{
+ ret = InstanceOfExpression()
+ (
+ ( "==" { op = BinaryExpr.Operator.EQUALS; } |
+ "!=" { op = BinaryExpr.Operator.NOT_EQUALS; }
+ ) right = InstanceOfExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); }
+ )*
+ { return ret; }
+}
+
+Expression InstanceOfExpression():
+{
+ Expression ret;
+ ReferenceType type;
+ NodeList<AnnotationExpr> annotations;
+}
+{
+ ret = RelationalExpression() [ "instanceof" type = AnnotatedReferenceType() {
+ ret = new InstanceOfExpr(range(ret, token()), ret, type);
+ } ]
+ { return ret; }
+}
+
+Expression RelationalExpression():
+{
+ Expression ret;
+ Expression right;
+ BinaryExpr.Operator op;
+}
+{
+ ret = ShiftExpression()
+ (
+ ( "<" { op = BinaryExpr.Operator.LESS; } |
+ ">" { op = BinaryExpr.Operator.GREATER; } |
+ "<=" { op = BinaryExpr.Operator.LESS_EQUALS; } |
+ ">=" { op = BinaryExpr.Operator.GREATER_EQUALS; }
+ ) right = ShiftExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); }
+ )*
+ { return ret; }
+}
+
+Expression ShiftExpression():
+{
+ Expression ret;
+ Expression right;
+ BinaryExpr.Operator op;
+}
+{
+ ret = AdditiveExpression()
+ (
+ ( "<<" { op = BinaryExpr.Operator.LEFT_SHIFT; } |
+ RSIGNEDSHIFT() { op = BinaryExpr.Operator.SIGNED_RIGHT_SHIFT; } |
+ RUNSIGNEDSHIFT() { op = BinaryExpr.Operator.UNSIGNED_RIGHT_SHIFT; }
+ ) right = AdditiveExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); }
+ )*
+ { return ret; }
+}
+
+Expression AdditiveExpression():
+{
+ Expression ret;
+ Expression right;
+ BinaryExpr.Operator op;
+}
+{
+ ret = MultiplicativeExpression()
+ (
+ ( "+" { op = BinaryExpr.Operator.PLUS; } |
+ "-" { op = BinaryExpr.Operator.MINUS; }
+ ) right = MultiplicativeExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); }
+ )*
+ { return ret; }
+}
+
+Expression MultiplicativeExpression():
+{
+ Expression ret;
+ Expression right;
+ BinaryExpr.Operator op;
+}
+{
+ ret = UnaryExpression()
+ (
+ ( "*" { op = BinaryExpr.Operator.MULTIPLY; } |
+ "/" { op = BinaryExpr.Operator.DIVIDE; } |
+ "%" { op = BinaryExpr.Operator.REMAINDER; }
+ ) right = UnaryExpression() { ret = new BinaryExpr(range(ret, token()), ret, right, op); }
+ )*
+ { return ret; }
+}
+
+Expression UnaryExpression():
+{
+ Expression ret;
+ UnaryExpr.Operator op;
+ JavaToken begin = INVALID;
+}
+{
+ (
+ ret = PreIncrementExpression()
+ |
+ ret = PreDecrementExpression()
+ |
+ ( "+" { op = UnaryExpr.Operator.PLUS; begin=token();} |
+ "-" { op = UnaryExpr.Operator.MINUS; begin=token();}
+ ) ret = UnaryExpression()
+ {
+ ret = new UnaryExpr(range(begin, token()), ret, op);
+ }
+ |
+ ret = UnaryExpressionNotPlusMinus()
+ )
+ { return ret; }
+}
+
+Expression PreIncrementExpression():
+{
+ Expression ret;
+ JavaToken begin = INVALID;
+}
+{
+ "++" {begin=token();} ret = UnaryExpression() { ret = new UnaryExpr(range(begin, token()), ret, UnaryExpr.Operator.PREFIX_INCREMENT); }
+ { return ret; }
+}
+
+Expression PreDecrementExpression():
+{
+ Expression ret;
+ JavaToken begin;
+}
+{
+ "--" {begin=token();} ret = UnaryExpression() { ret = new UnaryExpr(range(begin, token()), ret, UnaryExpr.Operator.PREFIX_DECREMENT); }
+ { return ret; }
+}
+
+Expression UnaryExpressionNotPlusMinus():
+{
+ Expression ret;
+ UnaryExpr.Operator op;
+ JavaToken begin = INVALID;
+}
+{
+ (
+ ( "~" { op = UnaryExpr.Operator.BITWISE_COMPLEMENT; begin=token(); } |
+ "!" { op = UnaryExpr.Operator.LOGICAL_COMPLEMENT; begin=token(); }
+ ) ret = UnaryExpression() { ret = new UnaryExpr(range(begin, token()), ret, op); }
+ |
+ LOOKAHEAD( CastExpression() )
+ ret = CastExpression()
+ |
+ ret = PostfixExpression()
+ )
+ { return ret; }
+}
+
+Expression PostfixExpression():
+{
+ Expression ret;
+ UnaryExpr.Operator op;
+}
+{
+ ret = PrimaryExpression()
+ [
+ LOOKAHEAD(2)
+ ( "++" { op = UnaryExpr.Operator.POSTFIX_INCREMENT; } |
+ "--" { op = UnaryExpr.Operator.POSTFIX_DECREMENT; }
+ ) { ret = new UnaryExpr(range(ret, token()), ret, op); }
+ ]
+ { return ret; }
+}
+
+Expression CastExpression():
+{
+ Expression ret;
+ ReferenceType referenceType;
+ PrimitiveType primitiveType;
+ JavaToken begin = INVALID;
+ NodeList<AnnotationExpr> annotations;
+ NodeList<ReferenceType> typesOfMultiCast = emptyList();
+}
+{
+ "(" {begin=token();}
+ annotations = Annotations()
+ (
+ LOOKAHEAD(2)
+ primitiveType = PrimitiveType(annotations) ")" ret = UnaryExpression() { ret = new CastExpr(range(begin, token()), primitiveType, ret); }
+ |
+ referenceType = ReferenceType(annotations) { typesOfMultiCast = add(typesOfMultiCast, referenceType); }
+ ( "&" referenceType = AnnotatedReferenceType() {
+ typesOfMultiCast = add(typesOfMultiCast, referenceType);
+ }
+ )*
+ ")" ret = UnaryExpressionNotPlusMinus() {
+ if (typesOfMultiCast.size() > 1) {
+ ret = new CastExpr(range(begin, token()), new IntersectionType(range(typesOfMultiCast.get(0), typesOfMultiCast.get(typesOfMultiCast.size() -1)), typesOfMultiCast), ret);
+ } else {
+ ret = new CastExpr(range(begin, token()), referenceType, ret);
+ }
+ }
+ )
+ { return ret; }
+}
+
+
+
+Expression PrimaryExpression():
+{
+ Expression ret;
+}
+{
+ ret = PrimaryPrefix() ( LOOKAHEAD(2) ret = PrimarySuffix(ret) )*
+ { return ret; }
+}
+
+Expression PrimaryExpressionWithoutSuperSuffix():
+{
+ Expression ret;
+}
+{
+ ret = PrimaryPrefix() ( LOOKAHEAD( PrimarySuffixWithoutSuper(null) ) ret = PrimarySuffixWithoutSuper(ret) )*
+ { return ret; }
+}
+
+Expression PrimaryPrefix():
+{
+ Expression ret = null;
+ SimpleName name;
+ RangedList<Type> typeArgs = new RangedList<Type>(null);
+ NodeList<Expression> args = emptyList();
+ NodeList<Parameter> params = emptyList();
+ boolean hasArgs = false;
+ boolean isLambda = false;
+ Type type;
+ JavaToken begin;
+ Parameter p = null;
+ SimpleName id = null;
+}
+{
+ (
+ ret = Literal()
+ |
+ <THIS> { ret = new ThisExpr(tokenRange(), null); }
+ |
+ <SUPER> { ret = new SuperExpr(tokenRange(), null); }
+ (
+ "."
+ [ typeArgs = TypeArguments() ]
+ name = SimpleName()
+ [ args = Arguments() {hasArgs=true;} ]
+ {
+ if (hasArgs) {
+ ret = new MethodCallExpr(range(ret, token()), ret, typeArgs.list, name, args);
+ } else {
+ ret = new FieldAccessExpr(range(ret, token()), ret, emptyList(), name);
+ }
+ }
+ |
+ "::" [typeArgs = TypeArguments() ] (Identifier() | "new")
+ {
+ ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image);
+ }
+ )
+ |
+ "(" {begin=token();}
+ (
+ ")" { ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); }
+ | LOOKAHEAD(Parameter())
+ params = LambdaParameters() ")" { ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); }
+ | LOOKAHEAD(VariableDeclaratorId() ",")
+ params = InferredLambdaParameters() ")" { ret = new LambdaExpr(range(begin, token()), params, new BlockStmt(), true); }
+ |
+ // This could still be a lambda expression, but this is handled after matching -> elsewhere
+ ret = Expression() ")" { ret = new EnclosedExpr(range(begin, token()), ret); }
+ )
+ |
+ ret = AllocationExpression(null)
+ |
+ LOOKAHEAD( ResultType() "." "class" )
+ type = ResultType(emptyList()) "." "class" { ret = new ClassExpr(range(type, token()), type); }
+
+ | LOOKAHEAD (AnnotatedType() "::" )
+ type = AnnotatedType() "::" [typeArgs = TypeArguments() ] (Identifier() | "new")
+ {
+ ret = new TypeExpr(range(type, type), type);
+ ret = new MethodReferenceExpr(range(ret, token()), ret, typeArgs.list, token.image);
+ }
+
+ |
+ name = SimpleName() { begin=token(); }
+ [ args = Arguments() { hasArgs=true; } ]
+ {
+ if (hasArgs) {
+ ret = new MethodCallExpr(range(begin, token()), null, null, name, args);
+ } else {
+ ret = new NameExpr(name);
+ }
+ }
+ )
+ { return ret; }
+}
+
+Expression PrimarySuffix(Expression scope):
+{
+ Expression ret;
+}
+{
+ (
+ LOOKAHEAD(2)
+ ret = PrimarySuffixWithoutSuper(scope)
+ |
+ "." "super" { ret = new SuperExpr(range(scope, token()), scope); }
+ )
+ { return ret; }
+}
+
+Expression PrimarySuffixWithoutSuper(Expression scope):
+{
+ Expression ret;
+ RangedList<Type> typeArgs = new RangedList<Type>(null);
+ NodeList<Expression> args = emptyList();
+ boolean hasArgs = false;
+ SimpleName name;
+}
+{
+ (
+ "."
+ (
+ "this" { ret = new ThisExpr(range(scope, token()), scope); }
+ |
+ ret = AllocationExpression(scope)
+ |
+ LOOKAHEAD( [ TypeArguments() ] Identifier() )
+ [ typeArgs = TypeArguments() ]
+ name = SimpleName()
+ [ args = Arguments() {hasArgs=true;} ]
+ {
+ if (hasArgs) {
+ ret = new MethodCallExpr(range(scope, token()), scope, typeArgs.list, name, args);
+ } else {
+ ret = new FieldAccessExpr(range(scope, token()), scope, typeArgs.list, name);
+ }
+ }
+ )
+ |
+ "["ret = Expression() "]" { ret = new ArrayAccessExpr(range(scope, token()), scope, ret); }
+ )
+ { return ret; }
+}
+
+Expression Literal():
+{
+ Expression ret;
+}
+{
+ (
+ <INTEGER_LITERAL> {
+ ret = new IntegerLiteralExpr(tokenRange(), token.image);
+ }
+ |
+ <LONG_LITERAL> {
+ ret = new LongLiteralExpr(tokenRange(), token.image);
+ }
+ |
+ <FLOATING_POINT_LITERAL> {
+ ret = new DoubleLiteralExpr(tokenRange(), token.image);
+ }
+ |
+ <CHARACTER_LITERAL> {
+ ret = new CharLiteralExpr(tokenRange(), token.image.substring(1, token.image.length()-1));
+ }
+ |
+ <STRING_LITERAL> {
+ ret = new StringLiteralExpr(tokenRange(), token.image.substring(1, token.image.length()-1));
+ }
+ |
+ ret = BooleanLiteral()
+ |
+ ret = NullLiteral()
+ )
+ { return ret; }
+}
+
+Expression BooleanLiteral():
+{
+ Expression ret;
+}
+{
+ (
+ "true" { ret = new BooleanLiteralExpr(tokenRange(), true); }
+ |
+ "false" { ret = new BooleanLiteralExpr(tokenRange(), false); }
+ )
+ { return ret; }
+}
+
+Expression NullLiteral():
+{}
+{
+ "null"
+ { return new NullLiteralExpr(tokenRange()); }
+}
+
+NodeList<Expression> Arguments():
+{
+ NodeList<Expression> ret = emptyList();
+}
+{
+ "(" [ ret = ArgumentList() ] ")"
+ { return ret; }
+}
+
+NodeList<Expression> ArgumentList():
+{
+ NodeList<Expression> ret = emptyList();
+ Expression expr;
+}
+{
+ expr = Expression() { ret.add(expr); } ( "," expr = Expression() { ret.add(expr); } )*
+ { return ret; }
+}
+
+Expression AllocationExpression(Expression scope):
+{
+ Expression ret;
+ Type type;
+ RangedList<Type> typeArgs = new RangedList<Type>(null);
+ NodeList<BodyDeclaration<?>> anonymousBody = null;
+ NodeList<Expression> args;
+ JavaToken begin = INVALID;
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+}
+{
+ "new" { if(scope==null) {begin=token();} else {begin = orIfInvalid(begin, scope);} }
+
+ annotations = Annotations()
+ (
+ type = PrimitiveType(annotations)
+ ret = ArrayCreation(begin, type)
+ |
+ [ typeArgs = TypeArguments() ]
+ type = AnnotatedClassOrInterfaceType()
+ (
+ ret = ArrayCreation(begin, type)
+ |
+ args = Arguments() [ LOOKAHEAD(2) anonymousBody = ClassOrInterfaceBody() ]
+ { ret = new ObjectCreationExpr(range(begin, token()), scope, (ClassOrInterfaceType) type, typeArgs.list, args, anonymousBody); }
+ )
+ )
+ { return ret; }
+}
+
+ArrayCreationExpr ArrayCreation(JavaToken begin, Type type):
+{
+ Expression expr = null;
+ ArrayInitializerExpr arrayInitializerExpr = null;
+ NodeList<Expression> inits = emptyList();
+ List<NodeList<AnnotationExpr>> accum = new ArrayList<NodeList<AnnotationExpr>>();
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+ JavaToken arrayCreationLevelStart = INVALID;
+ List<TokenRange> levelRanges = new ArrayList<TokenRange>();
+}
+{
+ ( LOOKAHEAD(2)
+ annotations = Annotations()
+ "[" { arrayCreationLevelStart = annotations.isEmpty() ? token() : orIfInvalid(arrayCreationLevelStart, annotations.get(0)); }
+ (expr = Expression())? { accum = add(accum, annotations); inits = add(inits, expr); annotations=null; expr=null; }
+ "]" { levelRanges.add(range(arrayCreationLevelStart, token())); }
+ )+
+ (arrayInitializerExpr = ArrayInitializer())?
+ {
+ return juggleArrayCreation(range(begin, token()), levelRanges, type, inits, accum, arrayInitializerExpr);
+ }
+}
+
+/*
+ * Statement syntax follows.
+ */
+
+Statement Statement():
+{
+ Statement ret;
+}
+{
+ try {
+ ( LOOKAHEAD(2)
+ ret = LabeledStatement()
+ |
+ ret = AssertStatement()
+ |
+ ret = Block()
+ |
+ ret = EmptyStatement()
+ |
+ ret = StatementExpression()
+ |
+ ret = SwitchStatement()
+ |
+ ret = IfStatement()
+ |
+ ret = WhileStatement()
+ |
+ ret = DoStatement()
+ |
+ ret = ForStatement()
+ |
+ ret = BreakStatement()
+ |
+ ret = ContinueStatement()
+ |
+ ret = ReturnStatement()
+ |
+ ret = ThrowStatement()
+ |
+ ret = SynchronizedStatement()
+ |
+ ret = TryStatement()
+ )
+ { return ret; }
+ } catch (ParseException e) {
+ TokenRange errorRange = recover(SEMICOLON, e);
+ return new UnparsableStmt(errorRange);
+ }
+}
+
+AssertStmt AssertStatement():
+{
+ Expression check;
+ Expression msg = null;
+ JavaToken begin;
+}
+{
+ "assert" {begin=token();} check = Expression() [ ":" msg = Expression() ] ";"
+ { return new AssertStmt(range(begin, token()), check, msg); }
+}
+
+LabeledStmt LabeledStatement():
+{
+ SimpleName label;
+ Statement stmt;
+ JavaToken begin;
+}
+{
+ label = SimpleName() {begin=token();} ":" stmt = Statement()
+ { return new LabeledStmt(range(begin, token()), label, stmt); }
+}
+
+BlockStmt Block():
+{
+ NodeList<Statement> stmts = emptyList();
+ JavaToken begin;
+}
+{
+ "{" {begin=token();}
+ try {
+ stmts = Statements()
+ "}"
+ { return new BlockStmt(range(begin, token()), stmts); }
+ } catch (ParseException e) {
+ recover(RBRACE, e);
+ BlockStmt block = new BlockStmt(range(begin, token()), new NodeList<Statement>());
+ block.setParsed(UNPARSABLE);
+ return block;
+ }
+}
+
+/*
+ * Classes inside body statements can only be abstract or final. The semantic must check it.
+ */
+Statement BlockStatement():
+{
+ Statement ret;
+ Expression expr;
+ ClassOrInterfaceDeclaration typeDecl;
+ ModifierHolder modifier;
+}
+{
+ try {
+ ( LOOKAHEAD( Modifiers() ("class" | "interface") )
+ modifier = Modifiers()
+ typeDecl = ClassOrInterfaceDeclaration(modifier) { ret = new LocalClassDeclarationStmt(range(typeDecl, token()), typeDecl); }
+ | LOOKAHEAD(VariableDeclarationExpression() )
+ expr = VariableDeclarationExpression() ";"
+ { ret = new ExpressionStmt(range(expr, token()), expr); }
+ |
+ ret = Statement()
+ )
+ { return ret; }
+ } catch (ParseException e) {
+ TokenRange errorRange = recover(SEMICOLON, e);
+ return new UnparsableStmt(errorRange);
+ }
+}
+
+VariableDeclarationExpr VariableDeclarationExpression():
+{
+ ModifierHolder modifier;
+ Type partialType;
+ NodeList<VariableDeclarator> variables = new NodeList<VariableDeclarator>();
+ VariableDeclarator var;
+}
+{
+ modifier = Modifiers() partialType = Type(emptyList()) var = VariableDeclarator(partialType) { variables.add(var); } ( "," var = VariableDeclarator(partialType) { variables.add(var); } )*
+ {
+ JavaToken begin=orIfInvalid(modifier.begin, partialType);
+ return new VariableDeclarationExpr(range(begin, token()), modifier.modifiers, modifier.annotations, variables);
+ }
+}
+
+EmptyStmt EmptyStatement():
+{}
+{
+ ";"
+ { return new EmptyStmt(tokenRange()); }
+}
+
+Statement LambdaBody():
+{
+ Expression expr;
+ Statement n = null;
+}
+{
+ (
+ expr = Expression() { n = new ExpressionStmt(range(expr, token()), expr); }
+ |
+ n = Block()
+ )
+ { return n; }
+}
+
+ExpressionStmt StatementExpression():
+/*
+ * The last expansion of this production accepts more than the legal
+ * Java expansions for StatementExpression. This expansion does not
+ * use PostfixExpression for performance reasons.
+ */
+{
+ Expression expr;
+ AssignExpr.Operator op;
+ Expression value;
+ RangedList<Type> typeArgs = new RangedList<Type>(null);
+ Statement lambdaBody;
+}
+{
+ ( LOOKAHEAD(2)
+ expr = PreIncrementExpression()
+ |
+ expr = PreDecrementExpression()
+ |
+ expr = PrimaryExpression()
+ [
+ "++" { expr = new UnaryExpr(range(expr, token()), expr, UnaryExpr.Operator.POSTFIX_INCREMENT); }
+ |
+ "--" { expr = new UnaryExpr(range(expr, token()), expr, UnaryExpr.Operator.POSTFIX_DECREMENT); }
+ |
+ op = AssignmentOperator() value = Expression() { expr = new AssignExpr(range(expr, token()), expr, value, op); }
+ ]
+ )
+ ";"
+ { return new ExpressionStmt(range(expr, token()), expr); }
+}
+
+SwitchStmt SwitchStatement():
+{
+ Expression selector;
+ SwitchEntryStmt entry;
+ NodeList<SwitchEntryStmt> entries = emptyList();
+ JavaToken begin;
+}
+{
+ "switch" {begin=token();} "(" selector = Expression() ")" "{"
+ ( entry = SwitchEntry() { entries = add(entries, entry); } )*
+ "}"
+
+ { return new SwitchStmt(range(begin, token()), selector, entries); }
+}
+
+SwitchEntryStmt SwitchEntry():
+{
+ Expression label = null;
+ NodeList<Statement> stmts;
+ JavaToken begin;
+}
+{
+ (
+ "case" {begin=token();} label = Expression()
+ |
+ "default" {begin=token();}
+ )
+ ":" stmts = Statements()
+
+ { return new SwitchEntryStmt(range(begin, token()),label, stmts); }
+}
+
+IfStmt IfStatement():
+/*
+ * The disambiguating algorithm of JavaCC automatically binds dangling
+ * else's to the innermost if statement. The LOOKAHEAD specification
+ * is to tell JavaCC that we know what we are doing.
+ */
+{
+ Expression condition;
+ Statement thenStmt;
+ Statement elseStmt = null;
+ JavaToken begin;
+}
+{
+ "if" {begin=token();} "(" condition = Expression() ")" {} thenStmt = Statement() [ LOOKAHEAD(1) "else" {} elseStmt = Statement() ]
+ {
+ return new IfStmt(range(begin, token()), condition, thenStmt, elseStmt);
+ }
+}
+
+WhileStmt WhileStatement():
+{
+ Expression condition;
+ Statement body;
+ JavaToken begin;
+}
+{
+ "while" {begin=token();} "(" condition = Expression() ")" body = Statement()
+ { return new WhileStmt(range(begin, token()),condition, body); }
+}
+
+DoStmt DoStatement():
+{
+ Expression condition;
+ Statement body;
+ JavaToken begin;
+}
+{
+ "do" {begin=token();} body = Statement() "while" "(" condition = Expression() ")" ";"
+ { return new DoStmt(range(begin, token()),body, condition); }
+}
+
+Statement ForStatement():
+{
+ VariableDeclarationExpr varExpr = null;
+ Expression expr = null;
+ NodeList<Expression> init = emptyList();
+ NodeList<Expression> update = emptyList();
+ Statement body;
+ JavaToken begin;
+}
+{
+ "for" {begin=token();} "("
+
+ (
+ LOOKAHEAD(VariableDeclarationExpression() ":")
+ varExpr = VariableDeclarationExpression() ":" expr = Expression()
+ |
+ [ init = ForInit() ] ";" [ expr = Expression() ] ";" [ update = ForUpdate() ]
+ )
+
+ ")" body = Statement()
+
+ {
+ if (varExpr != null) {
+ return new ForeachStmt(range(begin, token()),varExpr, expr, body);
+ }
+ return new ForStmt(range(begin, token()),init, expr, update, body);
+ }
+}
+
+NodeList<Expression> ForInit():
+{
+ NodeList<Expression> ret;
+ Expression expr;
+}
+{
+ (
+ LOOKAHEAD( Modifiers() Type() Identifier() )
+ expr = VariableDeclarationExpression() { ret = new NodeList<Expression>(); ret.add(expr); }
+ |
+ ret = ExpressionList()
+ )
+ { return ret; }
+}
+
+NodeList<Expression> ExpressionList():
+{
+ NodeList<Expression> ret = new NodeList<Expression>();
+ Expression expr;
+}
+{
+ expr = Expression() { ret.add(expr); } ( "," expr = Expression() { ret.add(expr); } )*
+
+ { return ret; }
+}
+
+NodeList<Expression> ForUpdate():
+{
+ NodeList<Expression> ret;
+}
+{
+ ret = ExpressionList()
+
+ { return ret; }
+}
+
+BreakStmt BreakStatement():
+{
+ SimpleName label = null;
+ JavaToken begin;
+}
+{
+ "break" {begin=token();} [ label = SimpleName() ] ";"
+ { return new BreakStmt(range(begin, token()), label); }
+}
+
+ContinueStmt ContinueStatement():
+{
+ SimpleName label = null;
+ JavaToken begin;
+}
+{
+ "continue" {begin=token();} [ label = SimpleName() ] ";"
+ { return new ContinueStmt(range(begin, token()), label); }
+}
+
+ReturnStmt ReturnStatement():
+{
+ Expression expr = null;
+ JavaToken begin;
+}
+{
+ "return" {begin=token();} [ expr = Expression() ] ";"
+ { return new ReturnStmt(range(begin, token()),expr); }
+}
+
+ThrowStmt ThrowStatement():
+{
+ Expression expr;
+ JavaToken begin;
+}
+{
+ "throw" {begin=token();} expr = Expression() ";"
+ { return new ThrowStmt(range(begin, token()),expr); }
+}
+
+SynchronizedStmt SynchronizedStatement():
+{
+ Expression expr;
+ BlockStmt body;
+ JavaToken begin;
+}
+{
+ "synchronized" {begin=token();} "(" expr = Expression() ")" body = Block()
+ { return new SynchronizedStmt(range(begin, token()),expr, body); }
+}
+
+TryStmt TryStatement():
+{
+ NodeList<Expression> resources = emptyList();
+ BlockStmt tryBlock;
+ BlockStmt finallyBlock = null;
+ NodeList<CatchClause> catchs = emptyList();
+ BlockStmt catchBlock;
+ ModifierHolder exceptModifier;
+ ReferenceType exceptionType;
+ NodeList<ReferenceType> exceptionTypes = emptyList();
+ Pair<SimpleName, List<ArrayBracketPair>> exceptId;
+ JavaToken begin;
+ JavaToken catchBegin;
+ JavaToken typesBegin;
+ JavaToken paramEnd;
+ Type type;
+}
+{
+ "try" {begin=token();}
+ (resources = ResourceSpecification())?
+ tryBlock = Block()
+ (
+ LOOKAHEAD(2)
+ (
+ "catch" {catchBegin=token();}
+ "(" { typesBegin=token(); }
+ exceptModifier = Modifiers() exceptionType = ReferenceType(emptyList()) { exceptionTypes.add(exceptionType); }
+ ( "|" exceptionType = AnnotatedReferenceType() { exceptionTypes.add(exceptionType); } )*
+ exceptId = VariableDeclaratorId() { paramEnd = token(); }
+ ")"
+
+ catchBlock = Block()
+ {
+ if (exceptionTypes.size() > 1) {
+ type = new UnionType(range(exceptionTypes.get(0), exceptionTypes.get(exceptionTypes.size() - 1)), exceptionTypes);
+ } else {
+ type = (Type)exceptionTypes.get(0);
+ }
+ Parameter catchType = new Parameter(range(type, paramEnd), exceptModifier.modifiers, exceptModifier.annotations, type, false, emptyList(), exceptId.a);
+ catchs = add(catchs, new CatchClause(range(catchBegin, token()), catchType, catchBlock));
+ exceptionTypes = emptyList(); }
+ )*
+ [ "finally" finallyBlock = Block() ]
+ |
+ "finally" finallyBlock = Block()
+ )
+ { return new TryStmt(range(begin, token()), resources, tryBlock, catchs, finallyBlock); }
+}
+
+
+NodeList<Expression> ResourceSpecification() :
+{
+ NodeList<Expression> variables;
+}
+{
+ "("
+ variables = Resources()
+ (LOOKAHEAD(2) ";")?
+ ")"
+ { return variables; }
+}
+
+
+NodeList<Expression> Resources() :
+{
+ NodeList<Expression> expressions = new NodeList<Expression>();
+ Expression expr;
+}
+{
+ expr = Resource() {expressions.add(expr);} (LOOKAHEAD(2) ";" expr = Resource() {expressions.add(expr);})*
+ { return expressions; }
+}
+
+Expression Resource() :
+{
+ Expression expr;
+}
+{
+ ( LOOKAHEAD( Modifiers() partialType = Type() VariableDeclarator(partialType))
+ /*this is a bit more lenient than we need to be, eg allowing access modifiers like private*/
+ expr = VariableDeclarationExpression()
+ |
+ expr = PrimaryExpression()
+ )
+ { return expr; }
+}
+
+
+/* We use productions to match >>>, >> and > so that we can keep the
+ * type declaration syntax with generics clean
+ */
+
+void RUNSIGNEDSHIFT():
+{}
+{
+ ( LOOKAHEAD({ getToken(1).kind == GT &&
+ getToken(1).realKind == RUNSIGNEDSHIFT} )
+ ">" ">" ">"
+ )
+}
+
+void RSIGNEDSHIFT():
+{}
+{
+ ( LOOKAHEAD({ getToken(1).kind == GT &&
+ getToken(1).realKind == RSIGNEDSHIFT} )
+ ">" ">"
+ )
+}
+
+/* Annotation syntax follows. */
+
+NodeList<AnnotationExpr> Annotations():
+{
+ NodeList<AnnotationExpr> annotations = new NodeList<AnnotationExpr>();
+ AnnotationExpr annotation;
+}
+{
+ (LOOKAHEAD("@") annotation = Annotation() {annotations = add(annotations, annotation);} )*
+ { return annotations; }
+}
+
+AnnotationExpr Annotation():
+{
+ AnnotationExpr ret;
+ Name name;
+ NodeList<MemberValuePair> pairs = emptyList();
+ JavaToken begin;
+ Expression memberVal;
+}
+{
+ "@" { begin=token(); } name = Name()
+ (
+ LOOKAHEAD( "(" ( Identifier() "=" | ")" ))
+ "(" [ pairs = MemberValuePairs() ] ")"
+ { ret = new NormalAnnotationExpr(range(begin, token()), name, pairs); }
+ |
+ LOOKAHEAD( "(" )
+ "(" memberVal = MemberValue() ")"
+ { ret = new SingleMemberAnnotationExpr(range(begin, token()), name, memberVal); }
+ |
+ { ret = new MarkerAnnotationExpr(range(begin, token()), name); }
+ )
+ { return ret; }
+}
+
+NodeList<MemberValuePair> MemberValuePairs():
+{
+ NodeList<MemberValuePair> ret = new NodeList<MemberValuePair>();
+ MemberValuePair pair;
+}
+{
+ pair = MemberValuePair() { ret.add(pair); } ( "," pair = MemberValuePair() { ret.add(pair); } )*
+ { return ret; }
+}
+
+MemberValuePair MemberValuePair():
+{
+ SimpleName name;
+ Expression value;
+ JavaToken begin;
+}
+{
+ name = SimpleName() { begin=token();} "=" value = MemberValue()
+ { return new MemberValuePair(range(begin, token()),name, value); }
+}
+
+Expression MemberValue():
+{
+ Expression ret;
+}
+{
+ ( LOOKAHEAD("@")
+ ret = Annotation()
+ |
+ ret = MemberValueArrayInitializer()
+ |
+ ret = ConditionalExpression()
+ )
+ { return ret; }
+}
+
+Expression MemberValueArrayInitializer():
+{
+ NodeList<Expression> ret = emptyList();
+ Expression member;
+ JavaToken begin;
+}
+{
+ "{" {begin=token();}
+ ( member = MemberValue() { ret.add(member); } ( LOOKAHEAD(2) "," member = MemberValue() { ret.add(member); } )* )? [ "," ]
+ "}"
+ { return new ArrayInitializerExpr(range(begin, token()),ret); }
+}
+
+
+/* Annotation Types. */
+
+AnnotationDeclaration AnnotationTypeDeclaration(ModifierHolder modifier):
+{
+ SimpleName name;
+ NodeList<BodyDeclaration<?>> members = emptyList();
+ JavaToken begin = modifier.begin;
+}
+{
+ "@" { begin=orIfInvalid(begin, token()); }
+ "interface" name = SimpleName() members = AnnotationTypeBody()
+ {
+ return new AnnotationDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, name, members);
+ }
+}
+
+NodeList<BodyDeclaration<?>> AnnotationTypeBody():
+{
+ NodeList<BodyDeclaration<?>> ret = emptyList();
+ BodyDeclaration member;
+}
+{
+ "{" (
+ member = AnnotationBodyDeclaration() { ret = addWhenNotNull(ret, member); }
+ |
+ ";"
+ )* "}"
+ { return ret; }
+}
+
+BodyDeclaration<?> AnnotationBodyDeclaration():
+{
+ ModifierHolder modifier;
+ BodyDeclaration ret;
+}
+{
+ (
+ modifier = Modifiers()
+ (
+ LOOKAHEAD(Type() Identifier() "(")
+ ret = AnnotationTypeMemberDeclaration(modifier)
+ |
+ ret = ClassOrInterfaceDeclaration(modifier)
+ | LOOKAHEAD("enum")
+ ret = EnumDeclaration(modifier)
+ |
+ ret = AnnotationTypeDeclaration(modifier)
+ |
+ ret = FieldDeclaration(modifier)
+ )
+ )
+ { return ret; }
+}
+
+AnnotationMemberDeclaration AnnotationTypeMemberDeclaration(ModifierHolder modifier):
+{
+ Type type;
+ SimpleName name;
+ Expression defaultVal = null;
+}
+{
+ type = Type(emptyList()) name = SimpleName() "(" ")" [ defaultVal = DefaultValue() ] ";"
+
+ {
+ JavaToken begin = orIfInvalid(modifier.begin, type);
+ return new AnnotationMemberDeclaration(range(begin, token()), modifier.modifiers, modifier.annotations, type, name, defaultVal);
+ }
+}
+
+Expression DefaultValue():
+{
+ Expression ret;
+}
+{
+ "default" ret = MemberValue()
+ { return ret; }
+}
+
+/* Module syntax follows */
+
+
+ModuleStmt ModuleStmt():
+{
+ ModifierHolder modifiers;
+ Name name;
+ Name tmpName;
+ NodeList<Name> names=emptyList();
+ Type type;
+ Type tmpType;
+ NodeList<Type> types=emptyList();
+ JavaToken begin;
+ ModuleStmt stmt=new ModuleRequiresStmt();
+ JavaToken transitiveExceptionalToken;
+}
+{
+ (
+ // This is a hack for the edge case "requires transitive;" which is supposed to mean "require the module named 'transitive'"
+ LOOKAHEAD(<REQUIRES> <TRANSITIVE> ";")
+ <REQUIRES> {begin=token();} <TRANSITIVE> {transitiveExceptionalToken=token(); setTokenKind(IDENTIFIER);} ";" {stmt=new ModuleRequiresStmt(range(begin, token()), EnumSet.noneOf(Modifier.class), new Name(range(transitiveExceptionalToken, transitiveExceptionalToken), null, transitiveExceptionalToken.getText(), new NodeList<AnnotationExpr>()));}
+ |
+ <REQUIRES> {begin=token();} modifiers=Modifiers() name=Name() ";" {stmt=new ModuleRequiresStmt(range(begin, token()), modifiers.modifiers, name);}
+ |
+ <EXPORTS> {begin=token();} name=Name() [<TO> tmpName=Name() {names.add(tmpName);} ("," tmpName=Name(){names.add(tmpName);} )* ] ";" {stmt=new ModuleExportsStmt(range(begin, token()), name, names);}
+ |
+ <OPENS> {begin=token();} name=Name() [<TO> tmpName=Name() {names.add(tmpName);} ("," tmpName=Name(){names.add(tmpName);} )* ] ";" {stmt=new ModuleOpensStmt(range(begin, token()), name, names);}
+ |
+ <USES> { begin=token();} type=Type(emptyList()) ";" {stmt=new ModuleUsesStmt(range(begin, token()), type);}
+ |
+ <PROVIDES> { begin=token();} type=Type(emptyList()) <WITH> tmpType=Type(emptyList()) {types.add(tmpType);} ("," tmpType=Type(emptyList()) {types.add(tmpType);} )* ";" {stmt=new ModuleProvidesStmt(range(begin, token()), type, types);}
+ )
+ { return stmt; }
+}
+
+ModuleDeclaration ModuleDeclaration(ModifierHolder modifier):
+{
+ NodeList<ModuleStmt> statements = new NodeList<ModuleStmt>();
+ boolean open=false;
+ ModuleStmt st;
+ Name name;
+ JavaToken begin = modifier.begin;
+}
+{
+ [ <OPEN> {open=true; begin = orIfInvalid(begin, token());} ]
+ <MODULE> { begin = orIfInvalid(begin, token()); }
+ name = Name() "{"
+ ( st = ModuleStmt() { statements = add(statements, st); } )*
+ "}"
+ { return new ModuleDeclaration(range(begin, token()), modifier.annotations, name, open, statements); }
+}
+
+/* Rules for matching partial inputs.
+These rules are needed to properly terminate them -
+if we simply use the usual rules, they will ignore everything in the provider
+after they matched their desired input, which will lead to unexpected behaviour
+*/
+
+
+BlockStmt BlockParseStart():
+{ BlockStmt ret; }
+{ ret = Block() <EOF> { return ret; } }
+
+Statement BlockStatementParseStart():
+{ Statement ret; }
+{ (LOOKAHEAD(3) ret = BlockStatement()|ret = ExplicitConstructorInvocation()) <EOF> { return ret; } }
+
+ImportDeclaration ImportDeclarationParseStart():
+{ ImportDeclaration ret; }
+{ ret = ImportDeclaration() <EOF> { return ret; } }
+
+Expression ExpressionParseStart():
+{ Expression ret; }
+{ ret = Expression() <EOF> { return ret; } }
+
+AnnotationExpr AnnotationParseStart():
+{ AnnotationExpr ret; }
+{ ret = Annotation() <EOF> { return ret; } }
+
+BodyDeclaration<?> AnnotationBodyDeclarationParseStart():
+{ BodyDeclaration<?> ret; }
+{ ret = AnnotationBodyDeclaration() <EOF> { return ret; } }
+
+BodyDeclaration<?> ClassOrInterfaceBodyDeclarationParseStart():
+{ BodyDeclaration<?> ret; }
+{ ret = ClassOrInterfaceBodyDeclaration() <EOF> { return ret; } }
+
+ClassOrInterfaceType ClassOrInterfaceTypeParseStart():
+{ ClassOrInterfaceType ret; }
+{ ret = AnnotatedClassOrInterfaceType() <EOF> { return ret; } }
+
+Type ResultTypeParseStart():
+{ NodeList<AnnotationExpr> annotations; Type ret; }
+{ annotations = Annotations() ret = ResultType(annotations) <EOF> { return ret; } }
+
+VariableDeclarationExpr VariableDeclarationExpressionParseStart():
+{ VariableDeclarationExpr ret; }
+{ ret = VariableDeclarationExpression() <EOF> { return ret; } }
+
+ExplicitConstructorInvocationStmt ExplicitConstructorInvocationParseStart():
+{ ExplicitConstructorInvocationStmt ret; }
+{ ret = ExplicitConstructorInvocation() <EOF> { return ret; } }
+
+Name NameParseStart():
+{ Name ret; }
+{ ret = Name() <EOF> { return ret; } }
+
+SimpleName SimpleNameParseStart():
+{ SimpleName ret; }
+{ ret = SimpleName() <EOF> { return ret; } }
+
+Parameter ParameterParseStart():
+{ Parameter ret; }
+{ ret = Parameter() <EOF> { return ret; } }
+
+PackageDeclaration PackageDeclarationParseStart():
+{ PackageDeclaration ret; }
+{ ret = PackageDeclaration() <EOF> { return ret; } }