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

public class EarlyTerminatingScanner<T> extends CtScanner
Extends 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 Details

    • scannedRole

      protected CtRole scannedRole
  • Constructor Details

    • EarlyTerminatingScanner

      public EarlyTerminatingScanner()
  • Method Details

    • terminate

      protected void terminate()
    • isTerminated

      protected boolean isTerminated()
    • setResult

      protected void setResult(T result)
    • getResult

      public T getResult()
      Returns:
      the result of scanning - the value, which was stored by a previous call of setResult(Object)
    • getListener

      public CtScannerListener getListener()
      Returns:
      null or the implementation of CtScannerListener, which is registered to listen for enter/exit of nodes during scanning of the AST
    • setListener

      public EarlyTerminatingScanner<T> setListener(CtScannerListener listener)
      Parameters:
      listener - the implementation of CtScannerListener, which will be called back when entering/exiting odes during scanning.
      Returns:
      this to support fluent API
    • scan

      public void scan(CtRole role, Collection<? extends CtElement> elements)
      Description copied from class: CtScanner
      Generically scans a collection of meta-model elements.
      Overrides:
      scan in class CtScanner
      Parameters:
      role - Role of the collection in the parent element
      elements - A collection of elements to scan (generally sibling elements)
    • scan

      public void scan(CtRole role, Map<String,​? extends CtElement> elements)
      Description copied from class: CtScanner
      Generically scans a Map of meta-model elements.
      Overrides:
      scan in class CtScanner
      Parameters:
      role - Role of the map in the parent element
      elements - A map of elements to scan (generally sibling elements)
    • scan

      public void scan(CtRole role, CtElement element)
      Description copied from class: CtScanner
      Generically scans a meta-model element.
      Overrides:
      scan in class CtScanner
      Parameters:
      role - Role of the element in its parent
      element - An element to scan
    • scan

      public void scan(CtElement element)
      Description copied from class: CtScanner
      Generically scans a meta-model element.
      Overrides:
      scan in class CtScanner
      Parameters:
      element - An element to scan
    • doScan

      protected 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. Subclasses can override it to react accordingly.
    • visitCtCompilationUnit

      public void visitCtCompilationUnit(CtCompilationUnit compilationUnit)
      Description copied from interface: CtVisitor
      Visits a compilation unit
      Specified by:
      visitCtCompilationUnit in interface CtVisitor
      Overrides:
      visitCtCompilationUnit in class CtScanner
    • onElement

      protected void onElement(CtRole role, CtElement element)
      Called for each scanned element. The call of this method is influenced by ScanningMode defined by CtScannerListener
      Parameters:
      role - a role of `element` in parent
      element - a scanned element
    • scan

      public void scan(CtRole role, Object o)
      Description copied from class: CtScanner
      Generically scans an object that can be an element, a reference, or a collection of those.
      Overrides:
      scan in class CtScanner
      Parameters:
      role - Role of the object in its parent
      o - A CtElement, or a Map or Collection 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