Bug 21916 - VariableDeclarationExpression
Summary: VariableDeclarationExpression
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 2.0.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-25 14:00 EDT by Timothy Halloran CLA
Modified: 2002-09-20 09:32 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Halloran CLA 2002-07-25 14:00:35 EDT
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
Comment 1 Olivier Thomann CLA 2002-07-26 15:06:51 EDT
I will investigate.
Comment 2 Olivier Thomann CLA 2002-07-26 15:17:25 EDT
I think the for statement should be:
{ SingleVariableDeclaration | VariableDeclarationExpression }

There is clearly something wrong with the initializers of the for statement.
Comment 3 Olivier Thomann CLA 2002-07-26 15:35:48 EDT
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.
Comment 4 Olivier Thomann CLA 2002-07-31 10:26:00 EDT
Set target milestone.
Comment 5 Olivier Thomann CLA 2002-07-31 13:03:03 EDT
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.
Comment 6 Olivier Thomann CLA 2002-07-31 14:19:39 EDT
Fixed and released in 2.0.1 stream.
Comment 7 Jim des Rivieres CLA 2002-08-06 15:52:57 EDT
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."
Comment 8 Jerome Lanneluc CLA 2002-08-19 10:11:44 EDT
Changed Javadoc comment in 2.0.1 and 2.1 streams.
Comment 9 Jerome Lanneluc CLA 2002-08-19 11:01:45 EDT
Verified by adding regression test ASTConverterTest.test0357()
Comment 10 Jerome Lanneluc CLA 2002-08-19 11:11:27 EDT
Test is test0362 in 2.1 stream.
Comment 11 David Audel CLA 2002-08-20 12:19:49 EDT
Verified.
Comment 12 David Audel CLA 2002-09-20 09:32:35 EDT
Verified in 2.1 M1