public final class NodeFinder extends Object
Constructor and Description |
---|
NodeFinder(ASTNode root,
int start,
int length)
Instantiate a new node finder using the given root node, the given start and the given length.
|
Modifier and Type | Method and Description |
---|---|
ASTNode |
getCoveredNode()
If the AST contains nodes whose range is equal to the selection, returns the innermost of those nodes.
|
ASTNode |
getCoveringNode()
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 |
perform(ASTNode root,
ISourceRange range)
Maps a selection to an ASTNode, where the selection is defined using a source range.
|
public NodeFinder(ASTNode root, int start, int length)
root
- the given root nodestart
- the given startlength
- the given lengthpublic static ASTNode perform(ASTNode root, int start, int length)
root
- the root node from which the search startsstart
- the start of the selectionlength
- the length of the selectionpublic static ASTNode perform(ASTNode root, ISourceRange range)
perform(root, range.getOffset(), range.getLength())
.root
- the root node from which the search startsrange
- the selection rangeperform(ASTNode, int, int)
public static ASTNode perform(ASTNode root, int start, int length, ITypeRoot source) throws JavaModelException
getCoveredNode()
doesn't find a node, returns null
.covering
node.root
- the root node from which the search startsstart
- the start of the selectionlength
- the length of the selectionsource
- the source of the compilation unitJavaModelException
- if an error occurs in the Java modelpublic ASTNode getCoveredNode()
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
.
null
if the selection is empty or too short to cover an entire nodepublic ASTNode getCoveringNode()
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.
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.