Community
Participate
Working Groups
Build ID: I20070503-1400 Steps To Reproduce: 1. For code: List/**/getUsers(); or even List /**/getUsers(); but not for List/**/ getUsers(); 2. When I use following code: serviceRoot.recordModifications(); methodDeclaration.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID)); and later: // prepare text edits MultiTextEdit edits = (MultiTextEdit) serviceRoot.rewrite(document, serviceUnit.getJavaProject().getOptions(true)); // prepare new source code edits.apply(document); newSource = document.get(); 3. Result source: voidtheMethodName() i.e. all whitespaces and comments removed and produce invalid source. More information: Hm... Why AJDT? It should be in JDT.
I have two fixes: 1) one that keeps the existing comment between the old return type and the new one. 2) one that removes the existing comment and only make sure a space is inserted. Markus, any preference ?
I prefer a solution that is consistent with the API specs and with how this is handled in other places. ASTRewrite says it uses a default TargetSourceRangeComputer, so the comments should be removed in both cases. Here's a test case I used. It also shows the same problem in method argument lists and field declarations. Apply Quick Fixes to see what the ASTRewrite does. I think we'll need to set a NoCommentSourceRangeComputer in some of the quick fixes to avoid losing comments. package xy; import java.util.List; @SuppressWarnings("rawtypes") public class Try { List/*important*/getUsers2() { return; } List /*important*/getUsers() { return fField; } String/**/fField; void foo(List/**/l) { foo(""); foo(/**/q); } }
Since ASTReweitre(In reply to comment #2) > I prefer a solution that is consistent with the API specs and with how this is > handled in other places. ASTRewrite says it uses a default > TargetSourceRangeComputer, so the comments should be removed in both cases. Yes, I checked the doc later on and indeed it is specified to use the extended range. So comments should be removed in both cases. I'll fix it that way. I'll also check the two other cases you mentioned.
Created attachment 162312 [details] Proposed fix + regression tests
Released for 3.6M7. Regression tests added in: org.eclipse.jdt.core.tests.rewrite.modifying.ASTRewritingModifyingReplaceTest#test0007 org.eclipse.jdt.core.tests.rewrite.modifying.ASTRewritingModifyingReplaceTest#test0008 org.eclipse.jdt.core.tests.rewrite.modifying.ASTRewritingModifyingReplaceTest#test0009 org.eclipse.jdt.core.tests.rewrite.modifying.ASTRewritingModifyingReplaceTest#test0010 org.eclipse.jdt.core.tests.rewrite.modifying.ASTRewritingModifyingReplaceTest#test0011 org.eclipse.jdt.core.tests.rewrite.modifying.ASTRewritingModifyingReplaceTest#test0012 org.eclipse.jdt.core.tests.rewrite.modifying.ASTRewritingModifyingReplaceTest#test0013 This fixes the initial issue with method return type, but also the field type and method arguments issues reported by Markus.
Verified for 3.6M7 using I20100425-2000.