Class CodeVisitor
java.lang.Object
io.github.mmm.code.api.object.CodeVisitor
- Direct Known Subclasses:
CodeImportGeneratorVisitor
Generic visitor to traverse the code AST (abstract syntax tree). Allows to recursively visit
CodeElements,
CodeNodes, and other related code elements. To visit simply create your own
sub-class and call according visit method (e.g. visitFile(CodeFile) on it. You implementation may be
stateful and collect data in fields of your implementation. To avoid performance issues some recursive traversals are
not enabled by default. You may therefore override methods like isVisitDocs(), isVisitProperties(),
isVisitComments() to activate deeper and more greedy recursion. Also you may override other methods like
isVisitFields(), etc. if recursion is not needed in your case.- Since:
- 1.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoVisitBlock(CodeBlock block) protected voiddoVisitElement(CodeElement element) protected voiddoVisitExpression(CodeExpression expression) protected voiddoVisitOperation(CodeOperation operation) protected voidprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected voidvisitAnnotation(CodeAnnotation annotation) protected voidvisitArrayInstatiation(CodeArrayInstatiation expression) protected voidvisitArrayType(CodeArrayType type) protected voidvisitAssignment(CodeAssignment statement) protected voidvisitBlockFor(CodeBlockFor block) protected voidvisitBlockIf(CodeBlockIf block) protected voidprotected voidvisitBody(CodeBlockBody body) protected voidvisitCastExpression(CodeCastExpression expression) protected voidvisitComment(CodeComment comment) protected voidprotected voidvisitCondition(CodeCondition condition) protected voidvisitConstant(CodeConstant constant) protected voidvisitConstructor(CodeConstructor constructor) protected voidprotected voidvisitExpression(CodeExpression expression) protected voidvisitExpressionCondition(CodeExpressionCondition expression) protected voidvisitField(CodeField field) voidprotected voidvisitForEachExpreesion(CodeForEachExpression expression) protected voidvisitForExpression(CodeForExpression expression) protected voidvisitForLoopExpression(CodeForLoopExpression expression) protected voidprotected voidvisitImport(CodeImport importStatement) protected voidprotected voidvisitLocalVariable(CodeLocalVariable variable) protected voidvisitMethod(CodeMethod method) protected voidvisitOperationInvocation(CodeOperationInvocation expression) protected voidvisitOperatorExpression(CodeOperatorExpression expression) voidvisitPackage(CodePackage pkg) protected voidvisitParameter(CodeParameter parameter) protected voidprotected voidvisitProperty(CodeProperty property) protected voidvisitReturns(CodeReturn returns) protected voidvisitReturnStatement(CodeReturnStatement statement) protected voidvisitStatement(CodeStatement statement) protected voidvisitSuperType(CodeGenericType superType) protected voidvisitTernaryExpression(CodeTernaryExpression expression) voidvisitTypeDeclaration(CodeType type) This method is called to visit a type declaration and will recursively traverse the givenCodeTypeextensively.protected voidvisitTypeReference(CodeType type) This method will be called for everyCodeTypevisited from code as reference.protected voidprotected void
-
Constructor Details
-
CodeVisitor
public CodeVisitor()
-
-
Method Details
-
visitPackage
- Parameters:
pkg- theCodePackageto visit.
-
visitFile
-
isVisitImports
protected boolean isVisitImports()- Returns:
truetovisit import statements,falseotherwise (ignore imports).
-
visitImport
- Parameters:
importStatement- theCodeImportto visit.- See Also:
-
visitImportItem
- Parameters:
item- theCodeImportItemto visit.
-
isVisitComments
protected boolean isVisitComments()- Returns:
truetovisit comments,falseotherwise (ignore comments).
-
visitComment
- Parameters:
comment- theCodeCommentto visit.- See Also:
-
isVisitDocs
protected boolean isVisitDocs()- Returns:
truetovisit documentation,falseotherwise (ignore doc).
-
visitDoc
-
isVisitAnnotations
protected boolean isVisitAnnotations()- Returns:
truetovisit annotations,falseotherwise (ignore annotations).
-
visitAnnotation
- Parameters:
annotation- theCodeAnnotationto visit.- See Also:
-
visitTypeDeclaration
This method is called to visit a type declaration and will recursively traverse the givenCodeTypeextensively. However, furtherCodeTypereferenced from traversed children will be visited viavisitTypeReference(CodeType)to avoid infinity loops as types can have cyclic references and visitors may also not expect such behavior.- Parameters:
type- theCodeTypeto visit.- See Also:
-
visitTypeReference
-
isVisitSuperTypes
protected boolean isVisitSuperTypes()- Returns:
truetovisit super-types,falseotherwise (ignore super-types).
-
visitSuperType
- Parameters:
superType- thesuper-typeto visit.
-
isVisitFields
protected boolean isVisitFields()- Returns:
truetovisit fields,falseotherwise (ignore fields).
-
visitField
-
isVisitConstructors
protected boolean isVisitConstructors()- Returns:
truetovisit constructors,falseotherwise (ignore constructors).
-
visitConstructor
- Parameters:
constructor- theCodeConstructorto visit.- See Also:
-
isVisitMethods
protected boolean isVisitMethods()- Returns:
truetovisit methods,falseotherwise (ignore methods).
-
visitMethod
- Parameters:
method- theCodeMethodto visit.- See Also:
-
visitReturns
- Parameters:
returns- theCodeReturnto visit.- See Also:
-
doVisitOperation
- Parameters:
operation- theCodeOperationto visit.- See Also:
-
isVisitProperties
protected boolean isVisitProperties()- Returns:
truetovisit properties,falseotherwise (ignore properties).
-
visitProperty
- Parameters:
property- theCodePropertyto visit.- See Also:
-
isVisitParameters
protected boolean isVisitParameters()- Returns:
truetovisit parameters,falseotherwise (ignore parameters).
-
visitParameter
- Parameters:
parameter- theCodeParameterto visit.- See Also:
-
isVisitBodies
protected boolean isVisitBodies()- Returns:
truetovisit bodies(implementations),falseotherwise (ignore bodies).
-
visitBody
- Parameters:
body- theCodeBlockBodyto visit.- See Also:
-
isVisitBlocks
protected boolean isVisitBlocks()- Returns:
truetovisit blocks(implementations),falseotherwise (ignore blocks).
-
doVisitBlock
-
isVisitStatements
protected boolean isVisitStatements()- Returns:
truetovisit statements,falseotherwise (ignore statements).
-
visitStatement
- Parameters:
statement- theCodeStatementto visit.
-
visitBlockStatement
- Parameters:
block- theCodeBlockStatementto visit.
-
visitBlockIf
- Parameters:
block- theCodeBlockIfto visit.- See Also:
-
visitBlockFor
- Parameters:
block- theCodeBlockForto visit.- See Also:
-
visitReturnStatement
- Parameters:
statement- theCodeReturnStatementto visit.
-
visitAssignment
- Parameters:
statement- theCodeAssignmentto visit.- See Also:
-
isVisitVariables
protected boolean isVisitVariables()- Returns:
truetovisit variables,falseotherwise (ignore variables).
-
visitLocalVariable
- Parameters:
variable- theCodeLocalVariableto visit.- See Also:
-
isVisitExpressions
protected boolean isVisitExpressions()- Returns:
truetovisit expressions,falseotherwise (ignore expressions).
-
visitCondition
- Parameters:
condition- theCodeConditionto visit.- See Also:
-
doVisitExpression
- Parameters:
expression- theCodeExpressionto visit.- See Also:
-
visitExpression
- Parameters:
expression- theCodeExpressionto visit.- See Also:
-
visitArrayInstatiation
- Parameters:
expression- theCodeArrayInstatiationto visit.- See Also:
-
visitOperationInvocation
- Parameters:
expression- theCodeOperationInvocationto visit.- See Also:
-
visitTernaryExpression
- Parameters:
expression- theCodeTernaryExpressionto visit.- See Also:
-
visitExpressionCondition
- Parameters:
expression- theCodeExpressionConditionto visit.- See Also:
-
visitOperatorExpression
- Parameters:
expression- theCodeOperatorExpressionto visit.- See Also:
-
visitCastExpression
- Parameters:
expression- theCodeCastExpressionto visit.- See Also:
-
visitConstant
- Parameters:
constant- theCodeConstantto visit.- See Also:
-
visitForExpression
- Parameters:
expression- theCodeForExpressionto visit.- See Also:
-
visitForEachExpreesion
- Parameters:
expression- theCodeForEachExpressionto visit.- See Also:
-
visitForLoopExpression
- Parameters:
expression- theCodeForLoopExpressionto visit.- See Also:
-
doVisitElement
- Parameters:
element- theCodeElementto visit.
-
visitGenericType
- Parameters:
type- theCodeGenericTypeto visit.
-
visitComposedType
- Parameters:
type- theCodeComposedTypeto visit.
-
visitParameterizedType
- Parameters:
type- theCodeParameterizedTypeto visit.
-
visitArrayType
- Parameters:
type- theCodeArrayTypeto visit.
-
doVisitTypePlaceholder
- Parameters:
type- theCodeTypePlaceholderto visit.
-
visitTypeVariable
- Parameters:
type- theCodeTypeVariableto visit.
-
visitTypeWildcard
- Parameters:
type- theCodeTypeWildcardto visit.
-