8000 feat: A visitor looking for a node by its position in an AST by jlerbsc · Pull Request #4258 · javaparser/javaparser · GitHub
[go: up one dir, main page]

Skip to content

Conversation

jlerbsc
Copy link
Collaborator
@jlerbsc jlerbsc commented Dec 14, 2023

Fixes #4254 .

The visitor is initialized with a range-based function that is evaluated on each node of the AST until a node matches the function.
The visitor uses a depth-first search. Below is an example of code to implement this search

NodeFinderVisitor finder = new NodeFinderVisitor(NodeFinderVisitor.fConveringNode);
CompilationUnit cu = parse(
			"class X {\n" +
			"  Boolean f;\n" +
			"}");
cu.accept(finder, range(2, 11));
finder.getSelectedNode();

@jlerbsc jlerbsc merged commit 0e909fe into javaparser:master Dec 14, 2023
@jlerbsc jlerbsc added this to the next release milestone Dec 14, 2023
@jlerbsc jlerbsc added the PR: Added A PR that introduces new behaviour (e.g. functionality, tests) label Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: Added A PR that introduces new behaviour (e.g. functionality, tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get node by offset in file

1 participant

0