Class ImportConflictDetector

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

public class ImportConflictDetector extends AbstractProcessor<CtElement>
Detects conflicts needed to be required be a fully-qualified name. 1) Example: conflict of field name with an variable name and fixes it by making field target explicit.
 class A {
  int xxx;
  void m(String xxx) {
    this.xxx //the target `this.` must be explicit, otherwise parameter `String xxx` hides it
  }
 }
2) Example: conflict of package name with an variable name and fixes it by making field target implicit.
 class A {
  int com;
  void m() {
    com.package.Type.doSomething(); //the package `com` is in conflict with field `com`. Must be imported
  }
 }
and fixes them by call of CtElement.setImplicit(boolean) and CtTypeReference.setSimplyQualified(boolean)
  • Field Details

  • Constructor Details

    • ImportConflictDetector

      public ImportConflictDetector()
  • Method Details

    • createScanner

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

      protected LexicalScope getScannerContextInformation()
      extract the required information from the scanner to take a decision
    • handleTargetedExpression

      protected void handleTargetedExpression(CtTargetedExpression<?,​?> targetedExpression, LexicalScope nameScope)
      what do we do a target expression (print target or not) ?
    • handleTypeReference

      protected void handleTypeReference(CtTypeReference<?> ref, LexicalScope nameScope, CtRole role)
      what do we do a type reference?
    • process

      public void process(CtElement el)
      Description copied from interface: Processor
      A callback method upcalled by the meta-model scanner to perform a dedicated job on the currently scanned element. The way Spoon upcalls 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 upcalled 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(LexicalScope 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`