MCPcopy
hub / github.com/Col-E/Recaf / getNodeAt

Method getNodeAt

src/main/java/me/coley/recaf/parse/source/SourceCode.java:150–165  ·  view source on GitHub ↗

Returns the AST node at the given position. The child-most node may not be returned if the parent is better suited for contextual purposes. @param line Cursor line. @param column Cursor column. @return JavaParser AST node at the given position in the source code.

(int line, int column)

Source from the content-addressed store, hash-verified

148 * @return JavaParser AST node at the given position in the source code.
149 */
150 public Node getNodeAt(int line, int column) {
151 return getNodeAt(line, column, unit.findRootNode(), node -> {
152 // We want to know more about this type, don't resolve down to the lowest AST
153 // type... the parent has more data and is essentially just a wrapper around SimpleName.
154 if (node instanceof SimpleName)
155 return false;
156 // Verify the node range can be accessed
157 if (!node.getBegin().isPresent() || !node.getEnd().isPresent())
158 return false;
159 // Same as above, we want to return the node with actual context.
160 if (node instanceof NameExpr)
161 return false;
162 // Should be fine
163 return true;
164 });
165 }
166
167 private Node getNodeAt(int line, int column, Node root, Predicate<Node> filter) {
168 if (!filter.test(root))

Callers 5

testNodeAtPosMethod · 0.95
testClassResolveMethod · 0.95
testFieldResolveMethod · 0.95
testMethodResolveMethod · 0.95
getVerboseNodeAtMethod · 0.95

Calls 2

testMethod · 0.80
getMethod · 0.45

Tested by 4

testNodeAtPosMethod · 0.76
testClassResolveMethod · 0.76
testFieldResolveMethod · 0.76
testMethodResolveMethod · 0.76