Skip to content

Conversation

lightless233
Copy link

Addresses #204.

Right now, modifiers like public or static are just anonymous keywords in the AST. This makes it a pain to write queries for them without matching on text.

This PR makes them actual nodes, similar to how tree-sitter-typescript handles it.

Changes:

  1. New (visibility) node:

    • public, protected, private are now grouped under this node.
    • Makes it easy to find declarations with specific visibility.
    ; e.g., find public methods
    (method_declaration (modifiers (visibility) @v) (#eq? @v "public"))
  2. New (modifier) node:

    • static, final, abstract, etc., now all produce a (modifier) node.
    • This provides a single node type for all these other keywords.
    ; e.g., find static fields
    (field_declaration (modifiers (modifier) @m) (#eq? @m "static"))

Resulting AST:

For public static class..., the AST is now much cleaner:

- (modifiers (KEYWORD) (KEYWORD))
+ (modifiers
+   (visibility)
+   (modifier)
+ )

Closes #204.

@wetneb
Copy link

wetneb commented Jul 28, 2025

Not a maintainer, but thank you for your PR! I have integrated it in this fork (alongside other unreviewed PRs) and the change turned out to be very helpful in Mergiraf.

Since you seem to be using this grammar from Rust, maybe you're interested in switching to the fork (tree-sitter-java-orchard on crates.io).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No visibility node
2 participants