Package spoon.reflect.visitor
Class EarlyTerminatingScanner<T>
java.lang.Object
spoon.reflect.visitor.CtScanner
spoon.reflect.visitor.EarlyTerminatingScanner<T>
- Type Parameters:
T
- the type of the result produced by this scanner.
- All Implemented Interfaces:
CtVisitor
- Direct Known Subclasses:
ImportCleaner.ImportCleanerScanner
,LexicalScopeScanner
,MatchingScanner
Extends
It is possible to register an implementation of
CtScanner
, to support early termination of scanning process and scan listeners.
It is useful when your algorithm is searching for a specific node only.
In this case, you can call terminate()
, which ensures that no more AST nodes are visited,
It is possible to register an implementation of
CtScannerListener
,
whose CtScannerListener.enter(CtElement)
/CtScannerListener.exit(CtElement)
methods are called before/after each AST node is visited.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
doScan(CtRole role, CtElement element, ScanningMode mode)
This method is called ONLY when the listener decides that the current element and children should be visited.protected boolean
boolean
protected void
Called for each scanned element.void
Generically scans a meta-model element.void
Generically scans an object that can be an element, a reference, or a collection of those.void
scan(CtRole role, Collection<? extends CtElement> elements)
Generically scans a collection of meta-model elements.void
Generically scans a Map of meta-model elements.void
Generically scans a meta-model element.setListener(CtScannerListener listener)
protected void
setVisitCompilationUnitContent(boolean visitCompilationUnitContent)
protected void
void
visitCtCompilationUnit(CtCompilationUnit compilationUnit)
Visits a compilation unitMethods inherited from class spoon.reflect.visitor.CtScanner
enter, exit, scan, scan, visitCtAnnotation, visitCtAnnotationFieldAccess, visitCtAnnotationMethod, visitCtAnnotationType, visitCtAnonymousExecutable, visitCtArrayRead, visitCtArrayTypeReference, visitCtArrayWrite, visitCtAssert, visitCtAssignment, visitCtBinaryOperator, visitCtBlock, visitCtBreak, visitCtCase, visitCtCatch, visitCtCatchVariable, visitCtCatchVariableReference, visitCtClass, visitCtCodeSnippetExpression, visitCtCodeSnippetStatement, visitCtComment, visitCtConditional, visitCtConstructor, visitCtConstructorCall, visitCtContinue, visitCtDo, visitCtEnum, visitCtEnumValue, visitCtExecutableReference, visitCtExecutableReferenceExpression, visitCtField, visitCtFieldRead, visitCtFieldReference, visitCtFieldWrite, visitCtFor, visitCtForEach, visitCtIf, visitCtImport, visitCtInterface, visitCtIntersectionTypeReference, visitCtInvocation, visitCtJavaDoc, visitCtJavaDocTag, visitCtLambda, visitCtLiteral, visitCtLocalVariable, visitCtLocalVariableReference, visitCtMethod, visitCtModule, visitCtModuleReference, visitCtModuleRequirement, visitCtNewArray, visitCtNewClass, visitCtOperatorAssignment, visitCtPackage, visitCtPackageDeclaration, visitCtPackageExport, visitCtPackageReference, visitCtParameter, visitCtParameterReference, visitCtProvidedService, visitCtRecord, visitCtRecordComponent, visitCtReturn, visitCtStatementList, visitCtSuperAccess, visitCtSwitch, visitCtSwitchExpression, visitCtSynchronized, visitCtTextBlock, visitCtThisAccess, visitCtThrow, visitCtTry, visitCtTryWithResource, visitCtTypeAccess, visitCtTypeMemberWildcardImportReference, visitCtTypeParameter, visitCtTypeParameterReference, visitCtTypePattern, visitCtTypeReference, visitCtUnaryOperator, visitCtUnboundVariableReference, visitCtUsedService, visitCtVariableRead, visitCtVariableWrite, visitCtWhile, visitCtWildcardReference, visitCtYieldStatement
-
Field Details
-
scannedRole
-
-
Constructor Details
-
EarlyTerminatingScanner
public EarlyTerminatingScanner()
-
-
Method Details
-
terminate
protected void terminate() -
isTerminated
protected boolean isTerminated() -
setResult
-
getResult
- Returns:
- the result of scanning - the value, which was stored by a previous call of
setResult(Object)
-
getListener
- Returns:
- null or the implementation of
CtScannerListener
, which is registered to listen for enter/exit of nodes during scanning of the AST
-
setListener
- Parameters:
listener
- the implementation ofCtScannerListener
, which will be called back when entering/exiting odes during scanning.- Returns:
- this to support fluent API
-
scan
Description copied from class:CtScanner
Generically scans a collection of meta-model elements. -
scan
Description copied from class:CtScanner
Generically scans a Map of meta-model elements. -
scan
Description copied from class:CtScanner
Generically scans a meta-model element. -
scan
Description copied from class:CtScanner
Generically scans a meta-model element. -
doScan
This method is called ONLY when the listener decides that the current element and children should be visited. Subclasses can override it to react accordingly. -
visitCtCompilationUnit
Description copied from interface:CtVisitor
Visits a compilation unit- Specified by:
visitCtCompilationUnit
in interfaceCtVisitor
- Overrides:
visitCtCompilationUnit
in classCtScanner
-
onElement
Called for each scanned element. The call of this method is influenced byScanningMode
defined byCtScannerListener
- Parameters:
role
- a role of `element` in parentelement
- a scanned element
-
scan
Description copied from class:CtScanner
Generically scans an object that can be an element, a reference, or a collection of those.- Overrides:
scan
in classCtScanner
- Parameters:
role
- Role of the object in its parento
- ACtElement
, or aMap
orCollection
of elements
-
isVisitCompilationUnitContent
public boolean isVisitCompilationUnitContent()- Returns:
- true if types and modules are visited. false if only their references are visited. false is default
-
setVisitCompilationUnitContent
public EarlyTerminatingScanner<T> setVisitCompilationUnitContent(boolean visitCompilationUnitContent)- Parameters:
visitCompilationUnitContent
- use true if types and modules have to be visited. false if only their references have to be visited. false is default
-