javaparser / javaparser

Java 1-21 Parser and Abstract Syntax Tree for Java with advanced analysis functionalities.
https://javaparser.org
Other
5.44k stars 1.16k forks source link

VariableDeclarator character range does not match range of children #4520

Open kjy5 opened 3 months ago

kjy5 commented 3 months ago

When parsing the line

private int one = 1;

I get

Why does VariableDeclarator start at 29 if it's child, PrimitiveType starts at 25? Is this expected behavior?

Thank you!

jlerbsc commented 3 months ago

It's hard to answer for the project designers, but I think it's because the variable declaration is a special expression. For example, you could write "int one = 1, two = 2;". In this case you have 2 variable declarations "one = 1", "two = 2" each with the type of the variable among its attributes.