Bug 95839 - [ast rewrite] problems with single line comments
Summary: [ast rewrite] problems with single line comments
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.2 RC2   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 103340 114418 128818 134439 137873 (view as bug list)
Depends on: 113108
Blocks:
  Show dependency tree
 
Reported: 2005-05-18 16:14 EDT by Adam Kiezun CLA
Modified: 2006-04-27 22:46 EDT (History)
8 users (show)

See Also:


Attachments
proposed fix for RC2 (30.10 KB, patch)
2006-04-27 11:26 EDT, Martin Aeschlimann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adam Kiezun CLA 2005-05-18 16:14:56 EDT
3.1M7

public class Foo //implements List
{
	private Object x;
	void set(T1 x){
		this.x= x;
	}
}

quick fix the compile error by selecting "add type parameter"
you get:
public class Foo //implements List<T1>
{
	private Object x;
	void set(T1 x){
		this.x= x;
	}
}
(fyi: quick fixing again adds another <T1> :) )
Comment 1 Adam Kiezun CLA 2005-05-24 11:00:29 EDT
btw this only happens in this one comment+line break constellation, as far as I
can tell
Comment 2 Martin Aeschlimann CLA 2005-06-01 09:42:17 EDT
has to wait for 3.2, too risky to turn screws in the ast rewriter now
Comment 3 Martin Aeschlimann CLA 2005-07-12 06:10:27 EDT
*** Bug 103340 has been marked as a duplicate of this bug. ***
Comment 4 Martin Aeschlimann CLA 2005-10-19 13:06:42 EDT
API requested in bug 113108 would give me the possibility to find out that the
last comment is a line comment. So I could decide either to not map the comment
to the name, or go to the next line when inserting.
Comment 5 Martin Aeschlimann CLA 2005-11-04 10:36:23 EST
*** Bug 114418 has been marked as a duplicate of this bug. ***
Comment 6 Jim des Rivieres CLA 2005-11-14 00:08:27 EST
Martin,  Before adding AST API, I'd like to understand a bit more about why 
the quick fix is making this mistake. The source range of an end-of-line 
comment includes the line end delimiter. Presumably, the comment in the 
example is either considered a trailing comment of the "Foo" SimpleName node 
(comment included in extended source range of SimpleName node), or an interior 
comment of the class declaration (comment not included in extended source 
range of SimpleName node). In the first case, the type parameter node should 
end up being inserted after the extended source range of the name, which would 
place it on the following line:

public class Foo //implements List
<T1>{

In the second case, the type parameter node should end up being inserted after 
the extended source range of the name, which would place it before the comment:

public class Foo<T1> //implements List
{

How do you explain the observed behavior, which is neither of the above? 
Comment 7 Martin Aeschlimann CLA 2005-11-14 10:12:49 EST
The new line delimiter is currently not contained in single line comments.
That's a long discussed issue, which I didn't dare to challange (again).


Comment 8 Martin Aeschlimann CLA 2006-03-07 12:26:17 EST
*** Bug 128818 has been marked as a duplicate of this bug. ***
Comment 9 Martin Aeschlimann CLA 2006-04-05 10:33:56 EDT
*** Bug 134439 has been marked as a duplicate of this bug. ***
Comment 10 Martin Aeschlimann CLA 2006-04-23 15:55:33 EDT
*** Bug 137873 has been marked as a duplicate of this bug. ***
Comment 11 Martin Aeschlimann CLA 2006-04-26 14:37:02 EDT
*** Bug 128422 has been marked as a duplicate of this bug. ***
Comment 12 Martin Aeschlimann CLA 2006-04-27 11:26:43 EDT
Created attachment 39676 [details]
proposed fix for RC2

Fixes the problem by detecting insertions after line comments and inserting a new line delimiter.
Does not care about formatting: Result is mostly strangly formatted, but code isn't corrupted anymore.
Doesn't yes fix insertion after copied nodes with new line comments (bug 128422).
But all other duplicates are fixed and covered in the tests.

David, can you review?
Comment 13 David Audel CLA 2006-04-27 12:01:12 EDT
This patch looks good and work as described in comment 12.
Comment 14 Philipe Mulet CLA 2006-04-27 12:25:29 EDT
+1 for 3.2RC2
Comment 15 Olivier Thomann CLA 2006-04-27 12:43:11 EDT
Fixed and released in HEAD.
Comment 16 Olivier Thomann CLA 2006-04-27 22:46:28 EDT
Verified with I20060427-1600 for RC2.