Community
Participate
Working Groups
For each code snippet below - Move X to new file (problem is independent creating an instance variable) - The comment gets deleted. Its neither in new file nor the old file. - There can be some empty lines between the comment and class X, the comment will still be deleted However if the comment is a javadoc (begins with /**) then its moved to new file. Marking as major as there is loss of data and the user may not realize it right away. Also I do not see any junits which test these (comments) cases. 1) package p; class A { /* * A very important comment. */ class X { } } 2) package p; class A { /* * A very important comment. */ class X { } } 3) package p; class A { // A very important comment. class X { } } 4) package p; class A { class X { } // A very important comment. } 5) package p; class A { class X { } /* A very important comment.*/ } 6) package p; class A { class X { } /** A very important comment.*/ } Things that work fine - Javadoc comment before Class X Empty lines between Class X and the comment when comment occurs after the class 1) package p; class A { /** * A very important comment. */ class X { } } 2) package p; class A { class X { } // A very important comment. } 3) package p; class A { class X { } /* A very important comment.*/ } 4) package p; class A { class X { } /** A very important comment.*/ }
I don't think that's new (same problem in old refactoring). Raksha, can you please have a look? Maybe we should set a NoCommentSourceRangeComputer or another source range computer to the AST rewrite.
Yes the problem exists in 3.5 as well. Also the problem is with Secondary types as well. For instance, moving X in the following also deletes the comment. package p; class A { } /* * A very important comment. */ class X { }
Probably not for 3.6, waiting on decision in bug 306524.
Created attachment 172314 [details] Fix for the new CU Markus, how about using a source range computer even for computing the new source range for the moved CU? This takes the extended range of the declaration node into account rather than just the simple range which helps in copying the comments which belong to the extended range of the node along with the declaration to the new CU. Since deleting the comments from the old CU which belong to the new CU in ASTRewriteAnalyzer is also done using the same source range computer, there wont be any inconsistencies. I tried this approach: ASTNodes.getNodeSource(declaration, true, false), but that returns null in this case ASTNode root= node.getRoot(); if (root instanceof CompilationUnit) { CompilationUnit astRoot= (CompilationUnit) root; ITypeRoot typeRoot= astRoot.getTypeRoot(); since the java type root of the astRoot is null.
(In reply to comment #4) +1, makes sense.
Created attachment 175427 [details] Fix + tests Added some tests and adjusted some for the changes in JDT-Core(bug 306524) and UI.
(In reply to comment #6) > Created an attachment (id=175427) [details] [diff] > Fix + tests Committed to HEAD after Ayush committed the fix for bug 306524.
Verified in I20100802-1800.