Class ImportCleaner

java.lang.Object
spoon.processing.AbstractProcessor<CtElement>
spoon.reflect.visitor.ImportCleaner
All Implemented Interfaces:
FactoryAccessor, Processor<CtElement>

public class ImportCleaner extends AbstractProcessor<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
  • Field Details

  • Constructor Details

    • ImportCleaner

      public ImportCleaner()
  • Method Details

    • createScanner

      protected ImportCleaner.ImportCleanerScanner createScanner()
      creates the scanner that will be used to visit the model
    • getScannerContextInformation

      protected ImportCleaner.Context 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

      public ImportCleaner setCanAddImports(boolean canAddImports)
      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

      public ImportCleaner setCanRemoveImports(boolean canRemoveImports)
      Parameters:
      canRemoveImports - true if this processor is allowed to remove imports
    • getImportComparator

      public Comparator<CtImport> getImportComparator()
    • setImportComparator

      public ImportCleaner setImportComparator(Comparator<CtImport> importComparator)
    • process

      public void process(CtElement el)
      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 method Processor.isToBeProcessed(CtElement) returns true for a given scanned element. In order to manually scan the meta-model, one can define the Processor.process() method instead.
      Parameters:
      el - the element that is currently being scanned
    • process

      protected static void process(CtScanner scanner, CtCompilationUnit cu)
    • createScannerListener

      protected CtScannerListener createScannerListener()
    • onEnter

      protected void onEnter(ImportCleaner.Context context, CtRole role, CtElement element)
    • getParentIfType

      protected static <T extends CtElement> T getParentIfType(CtElement element, Class<T> type)
      Returns:
      parent of `element`, but only if it's type is `type`