tree-sitter-java
tree-sitter-java copied to clipboard
field_access takes precedence over class_literal
Problem description
The class literal pattern, e.g. String.class gets interpreted as a field access.
For the following snippet:
class C { Class x = String.class; }
Expected parse tree output (optional)
(program (class_declaration name: (identifier) body: (class_body (field_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier)
value: (class_literal (_unannotated_type)))))))
Actual parse tree output (optional)
(program (class_declaration name: (identifier) body: (class_body (field_declaration type: (type_identifier) declarator (variable_declarator name: (identifier)
value: (field_access object: (identifier) field: (identifier)))))))
Same problem here: https://github.com/returntocorp/semgrep/issues/6002
I don't know if this used to work. @danzat can you bisect to a point where it stopped working? Or it never worked?
Looks like it has never worked.
I have a fix that sets dynamic precedence to field_access and class_literal, how do you prefer to apply it? PR? Should I post the diff here?
Also, are there any formatting guidelines to the grammar.js file?
PR sounds great to me. I think if there's some formatting issues, the commit hooks would complain.
https://github.com/tree-sitter/tree-sitter-java/pull/125