Bug 73933 - Clarifications of the DOM/AST API for VariableDeclarationExpression and VariableDeclarationStatement
Summary: Clarifications of the DOM/AST API for VariableDeclarationExpression and Varia...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1 M2   Edit
Assignee: Jim des Rivieres CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-14 17:21 EDT by Olivier Thomann CLA
Modified: 2004-09-23 11:32 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Thomann CLA 2004-09-14 17:21:08 EDT
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.
Comment 1 Jim des Rivieres CLA 2004-09-16 15:41:23 EDT
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.
Comment 2 Frederic Fusier CLA 2004-09-23 11:32:32 EDT
Verified for 3.1 M2 with build I200409230010.