Klasse NodeFinder

java.lang.Object
org.aspectj.org.eclipse.jdt.core.dom.NodeFinder

public final class NodeFinder extends Object
For a given selection range, finds the covered node and the covering node.
Seit:
3.5
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
    NodeFinder(ASTNode root, int start, int length)
    Instantiate a new node finder using the given root node, the given start and the given length.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    If the AST contains nodes whose range is equal to the selection, returns the innermost of those nodes.
    Returns the innermost node that fully contains the selection.
    static ASTNode
    perform(ASTNode root, int start, int length)
    Maps a selection to an ASTNode, where the selection is defined using a start and a length.
    static ASTNode
    perform(ASTNode root, int start, int length, ITypeRoot source)
    Maps a selection to an ASTNode, where the selection is given by a start and a length.
    static ASTNode
    Maps a selection to an ASTNode, where the selection is defined using a source range.

    Von Klasse geerbte Methoden java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Konstruktordetails

    • NodeFinder

      public NodeFinder(ASTNode root, int start, int length)
      Instantiate a new node finder using the given root node, the given start and the given length.
      Parameter:
      root - the given root node
      start - the given start
      length - the given length
  • Methodendetails

    • perform

      public static ASTNode perform(ASTNode root, int start, int length)
      Maps a selection to an ASTNode, where the selection is defined using a start and a length. The result node is determined as follows:
      • First, tries to find a node whose range is the exactly the given selection. If multiple matching nodes are found, the innermost is returned.
      • If no such node exists, then the last node in a preorder traversal of the AST is returned, where the node range fully contains the selection. If the length is zero, then ties between adjacent nodes are broken by choosing the right side.
      Parameter:
      root - the root node from which the search starts
      start - the start of the selection
      length - the length of the selection
      Gibt zurück:
      the innermost node that exactly matches the selection, or the first node that contains the selection
    • perform

      public static ASTNode perform(ASTNode root, ISourceRange range)
      Maps a selection to an ASTNode, where the selection is defined using a source range. Calls perform(root, range.getOffset(), range.getLength()).
      Parameter:
      root - the root node from which the search starts
      range - the selection range
      Gibt zurück:
      the innermost node that exactly matches the selection, or the first node that contains the selection
      Siehe auch:
    • perform

      public static ASTNode perform(ASTNode root, int start, int length, ITypeRoot source) throws JavaModelException
      Maps a selection to an ASTNode, where the selection is given by a start and a length. The result node is determined as follows:
      • If getCoveredNode() doesn't find a node, returns null.
      • Otherwise, iff the selection only contains the covered node and optionally some whitespace or comments on either side of the node, returns the node.
      • Otherwise, returns the covering node.
      Parameter:
      root - the root node from which the search starts
      start - the start of the selection
      length - the length of the selection
      source - the source of the compilation unit
      Gibt zurück:
      the result node
      Löst aus:
      JavaModelException - if an error occurs in the Java model
    • getCoveredNode

      public ASTNode getCoveredNode()
      If the AST contains nodes whose range is equal to the selection, returns the innermost of those nodes. Otherwise, returns the first node in a preorder traversal of the AST, where the complete node range is covered by the selection.

      Example: For a SimpleType whose name is a SimpleName and a selection that equals both nodes' range, the covered node is the SimpleName. But if the selection is expanded to include a whitespace before or after the SimpleType, then the covered node is the SimpleType.

      Gibt zurück:
      the covered node, or null if the selection is empty or too short to cover an entire node
    • getCoveringNode

      public ASTNode getCoveringNode()
      Returns the innermost node that fully contains the selection. A node also contains the zero-length selection on either end.

      If more than one node covers the selection, the returned node is the last covering node found in a preorder traversal of the AST. This implies that for a zero-length selection between two adjacent sibling nodes, the node on the right is returned.

      Gibt zurück:
      the covering node