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)
| 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)) |