Community
Participate
Working Groups
Looking at the documentation of these two classes, I think the comment stating that a local variable expression can only be found in the inits of a for statement is misleading. If you have the following code: int i, j = 4, k; It could be seen as an expression statement that contains a variable declaration expression that contains 3 fragments. It could also be seen as a variable declaration statement that contains 3 fragments. The parser should not be constraint to build such a node. This would require some clarifications whether the two lines are part of the specification or it simply provides extra information. The specifications of the ForStatement forInits is wrong. It should be: * ForInit: * Expression {<b>,</b> Expression } Where the first Expression could be a variable declaration expression.
I've clarified the specs as follows: ForStatement - When variables are declared in the initializer of a for statement such as "<code>for (int a=1, b=2;;);</code>", they should be represented as a single <code>VariableDeclarationExpression</code> with two fragments, rather than being split up into a pair of expressions. VariableDeclarationExpression - This type of node can be used as the initializer of a <code>ForStatement</code>, or wrapped in an <code>ExpressionStatement</code> to form the equivalent of a <code>VariableDeclarationStatement</code>. VariableDeclarationStatement - This type of node is a convenience of sorts. An equivalent way to represent the same statement is to use a <code>VariableDeclarationExpression</code> wrapped in an <code>ExpressionStatement</code>. None of these clarification are API changes. In general, in numerous cases there is more than one way that a Java language fragment can be mapped to an AST tree. Clients learn to live with this ambiguity and not rely on the exact shape. Making use of ASTVisitor is a good way to do that. Build notes updated.
Verified for 3.1 M2 with build I200409230010.