Community
Participate
Working Groups
When the initializer list from a "for" loop is examined and it contains a VariableDeclarationExpression, it always only should contain one. Currently it contains a VariableDeclarationExpression for each variable declared (and not a VariableDeclarationExpression containing a VariableDeclarationFragment for each declaration), see below: DEBUG (ParseAdapter.java:567) - ForStatement : for (int i=0;int j=0;int k=0;; i++j++k++; i<10) {System.out.println("L");} DEBUG (ParseAdapter.java:545) - Initializer : int i=0; DEBUG (ParseAdapter.java:545) - Initializer : int j=0; DEBUG (ParseAdapter.java:545) - Initializer : int k=0; The top is outputing the ForStatement (via toString()) and the bottom three are the VariableDeclarationExpressions (via toString()). The original source code for the for loop was: for (int i=0, j=0, k=0; i<10 ; i++,j++,k++) { System.out.println("L"); } From the Eclipse JavaDoc: VariableDeclarationExpression: { Modifier } Type VariableDeclarationFragment { , VariableDeclarationFragment } Hence, for my example "for" loop above, I would expect a single VariableDeclarationExpression with 3 VariableDeclarationFragments. This appears broke, either the code (my guess) or the JavaDoc. Please advise. Take Care, Tim Halloran Carnegie Mellon University
I will investigate.
I think the for statement should be: { SingleVariableDeclaration | VariableDeclarationExpression } There is clearly something wrong with the initializers of the for statement.
Sorry I was wrong. For inits of the for statement should be: { VariableDeclarationExpression | { Expression {, Expression }} This means that several local declarations (in the compiler's ast world) have to be converted to one VariableDeclarationExpression and not multiple VariableDeclaration Expression.
Set target milestone.
Fixed and released in 2.1 stream. Now the local declarations are converted to a single VariableDeclarationExpression, which contains multiple fragments. This is more consistent with the Java grammar. Thanks for the report.
Fixed and released in 2.0.1 stream.
The Javadoc comment for ForStatement.initializer says: "The list should consist of either a list of so called statement expressions (JLS2, 14.8), or a list of variable declaration expressions all with the same type. Otherwise, the for statement would have no Java source equivalent." It should be revised as well: "The list should consist of either a list of so called statement expressions (JLS2, 14.8), or a single <code>VariableDeclarationExpression</code>. Otherwise, the for statement would have no Java source equivalent."
Changed Javadoc comment in 2.0.1 and 2.1 streams.
Verified by adding regression test ASTConverterTest.test0357()
Test is test0362 in 2.1 stream.
Verified.
Verified in 2.1 M1