Bug 102650 - [ast rewrite] Removing all TYPE_PARAMETERS_PROPERTY values in a derived type gives incompilable code
Summary: [ast rewrite] Removing all TYPE_PARAMETERS_PROPERTY values in a derived type ...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Martin Aeschlimann CLA Friend
QA Contact:
URL:
Whiteboard:
Keywords:
: 108209 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-07-04 09:59 EDT by Alexander Pavlov CLA Friend
Modified: 2005-10-19 11:48 EDT (History)
4 users (show)

See Also:


Attachments
patch for jdt.core (5.82 KB, patch)
2005-07-11 11:02 EDT, Martin Aeschlimann CLA Friend
no flags Details | Diff
patch for jdt.core.tests.model (5.33 KB, patch)
2005-07-11 11:04 EDT, Martin Aeschlimann CLA Friend
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Pavlov CLA Friend 2005-07-04 09:59:56 EDT
(RC3)

Consider a class:
public class B<T> extends A {}

We create an ASTRewrite and getListRewrite (lrw) for a node corresponding to 
the type B and the TypeDeclaration.TYPE_PARAMETERS_PROPERTY. Then we remove all 
the nodes from the list:
List list = lrw.getOriginalList();
for (Iterator it = list.iterator(); it.hasNext(); ) {
	lrw.remove((ASTNode)it.next(), null);
}

and then we apply changes (rewrite the AST). The following code results:
public class Bextends A {}

which is wrong. The only thing I found out is that rewriteAst() generates two 
consecutive DeleteEdits of length two. Everything is OK if there is 
no "extends" clause.
Comment 1 Dirk Baeumer CLA Friend 2005-07-04 10:32:46 EDT
Martin, can you please investigate. May be a candidate for 3.1.1 ?
Comment 2 Martin Aeschlimann CLA Friend 2005-07-11 11:02:20 EDT
Created attachment 24541 [details]
patch for jdt.core
Comment 3 Martin Aeschlimann CLA Friend 2005-07-11 11:04:41 EDT
Created attachment 24542 [details]
patch for jdt.core.tests.model
Comment 4 Martin Aeschlimann CLA Friend 2005-07-11 11:27:54 EDT
Philippe, can you please decide if you want this in 3.1.1?

The rewriter in 3.1 can create non-compilable code when all type parameters or
arguments are removed. It currently always starts removing from the opening
bracket ('<') and removes until the token after the closing bracket ('>'). The
following examples fail:

class A<T>extends X -> class Aextends X
class A<T> extends X -> class Aextends X
public<T>void foo -> publicvoid foo
public<T> void foo -> publicvoid foo
new<T>MyClass() -> newMyClass()

The fix makes sure that for these 3 cases at least a space is added when the
opening bracket is right after the last token.

Test cases have been added for the problematic scenarios.


Comment 5 Philipe Mulet CLA Friend 2005-07-11 11:52:56 EDT
I would fix it for 3.1.1 as the symptoms look bad.
David - pls review the change
Comment 6 David Audel CLA Friend 2005-07-12 06:51:05 EDT
Martin's patch seems very good.
Comment 7 Martin Aeschlimann CLA Friend 2005-07-12 11:42:09 EDT
released in 3.1.1 and 3.2 streams > 20050712
Comment 8 Markus Keller CLA Friend 2005-08-09 13:05:44 EDT
Verified in M20050804-1200 and I20050808-2000.
Comment 9 Martin Aeschlimann CLA Friend 2005-10-19 11:48:40 EDT
*** Bug 108209 has been marked as a duplicate of this bug. ***