Bug 203579

Summary: [dom] Length of VariableDeclarationFragment is not the same inside a 'for' initialisation
Product: [Eclipse Project] JDT Reporter: David Audel <david_audel>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jerome_lanneluc, Olivier_Thomann
Version: 3.3   
Target Milestone: 3.4 M3   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 199668    
Attachments:
Description Flags
Proposed fix
none
Regression test
none
New fix none

Description David Audel CLA 2007-09-17 07:30:44 EDT
build I20070917-0010

1) create X.java
public class X {
	void foo() {
		int   a  /*a*/,   b  /*b*/;
		for (int  i  /*i*/,  j  /*j*/;;) {
		}
	}
}

2) build a DOM AST (with ASTView).
The end of 'a' is after '/*a*/'.
The end of 'b' is after '/*a*/'.
The end of 'i' is after 'int  i' and not after '/*i*/'.
The end of 'j' is after ',  j' and not after '/*j*/'.

The end of the fragment should be the same in each case.
Comment 1 Olivier Thomann CLA 2007-09-17 08:36:50 EDT
Do we want to include the trailing comment inside the positions ?
I would say no. The comment could be included in the extended range though.
David, any thought ?
Comment 2 David Audel CLA 2007-09-17 09:00:21 EDT
My explanation wasn't clear. The problem isn't related to trailing comments. The problem is the same without comments.

public class X {
        void foo() {
                int   a  ,   b  ;
                for (int  i  ,  j  ;;) {
                }
        }
}

Inside a 'for' statement the end of the fragment is at the end of the variable name and inside a locale variable the end is just before the next comma or semicolon.
The problem is in the same area as bug 199668.
Comment 3 Olivier Thomann CLA 2007-09-17 09:09:21 EDT
The positions should be consistent in both cases. No whitespaces should be included in the position range.
Comment 4 Olivier Thomann CLA 2007-09-19 13:26:17 EDT
Created attachment 78775 [details]
Proposed fix
Comment 5 Olivier Thomann CLA 2007-09-19 13:27:51 EDT
Created attachment 78776 [details]
Regression test
Comment 6 Olivier Thomann CLA 2007-09-20 14:44:56 EDT
Created attachment 78882 [details]
New fix
Comment 7 Olivier Thomann CLA 2007-09-20 14:45:43 EDT
Released in HEAD.
Regression test added in org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2#test0686
Comment 8 Jerome Lanneluc CLA 2007-10-29 07:39:18 EDT
Verified for 3.4M3 using I20071029-0800