Package spoon.reflect.visitor
Class ImportCleaner
- All Implemented Interfaces:
FactoryAccessor
,Processor<CtElement>
Updates list of import statements of compilation unit following
CtElement.isImplicit()
.
Can be configured to add or remove imports using setCanAddImports(boolean)
and setCanRemoveImports(boolean)
.
This does not force some references to be implicit, and doesn't fix the wrong implicit which causes conflicts: this fixing done by ImportConflictDetector
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
a set of imports for a given compilation unitclass
A scanner that initializes context for a compilation unit. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected ImportCleaner.ImportCleanerScanner
creates the scanner that will be used to visit the modelprotected CtScannerListener
protected static <T extends CtElement>
TgetParentIfType(CtElement element, Class<T> type)
protected ImportCleaner.Context
extract the required information from the scanner to take a decisionprotected void
handleTargetedExpression(CtTargetedExpression<?,?> targetedExpression, ImportCleaner.Context context)
what do we do a target expression (print target or not) ?protected void
handleTypeReference(CtTypeReference<?> reference, ImportCleaner.Context context, CtRole role)
what do we do a type reference?boolean
boolean
protected void
onEnter(ImportCleaner.Context context, CtRole role, CtElement element)
void
A callback method called by the meta-model scanner to perform a dedicated job on the currently scanned element.protected static void
process(CtScanner scanner, CtCompilationUnit cu)
setCanAddImports(boolean canAddImports)
setCanRemoveImports(boolean canRemoveImports)
setImportComparator(Comparator<CtImport> importComparator)
Methods inherited from class spoon.processing.AbstractProcessor
addProcessedElementType, clearProcessedElementType, getEnvironment, getFactory, getProcessedElementTypes, getTraversalStrategy, init, initProperties, interrupt, isToBeProcessed, loadProperties, process, processingDone, removeProcessedElementType, setFactory
-
Field Details
-
scanner
-
IGNORED_ROLES_WHEN_IMPLICIT
-
-
Constructor Details
-
ImportCleaner
public ImportCleaner()
-
-
Method Details
-
createScanner
creates the scanner that will be used to visit the model -
getScannerContextInformation
extract the required information from the scanner to take a decision -
handleTargetedExpression
protected void handleTargetedExpression(CtTargetedExpression<?,?> targetedExpression, ImportCleaner.Context context)what do we do a target expression (print target or not) ? -
handleTypeReference
protected void handleTypeReference(CtTypeReference<?> reference, ImportCleaner.Context context, CtRole role)what do we do a type reference? -
isCanAddImports
public boolean isCanAddImports()- Returns:
- true if this processor is allowed to add new imports
-
setCanAddImports
- Parameters:
canAddImports
- true if this processor is allowed to add new imports
-
isCanRemoveImports
public boolean isCanRemoveImports()- Returns:
- true if this processor is allowed to remove imports
-
setCanRemoveImports
- Parameters:
canRemoveImports
- true if this processor is allowed to remove imports
-
getImportComparator
-
setImportComparator
-
process
Description copied from interface:Processor
A callback method called by the meta-model scanner to perform a dedicated job on the currently scanned element. The way Spoon calls this method depends on the processed element types (Processor.getProcessedElementTypes()
), the traversal strategy (Processor.getTraversalStrategy()
), and the used processing manager (Environment.getManager()
. Also, this method is called only if the methodProcessor.isToBeProcessed(CtElement)
returns true for a given scanned element. In order to manually scan the meta-model, one can define theProcessor.process()
method instead.- Parameters:
el
- the element that is currently being scanned
-
process
-
createScannerListener
-
onEnter
-
getParentIfType
- Returns:
- parent of `element`, but only if it's type is `type`
-