Community
Participate
Working Groups
Consider following code in the Java text editor: if (param.getValue().equals("")) //$NON-NLS-1$ throw new ValidationException( Messages.ErrorMessage); Consider following save actions enabled: - Convert control statement bodies to block except for single return or throw statement - Remove unused imports - Add missing '@Override' annotations - Add missing '@Deprecated' annotations - Remove unnecessary '$NON-NLS$' tags - Remove trailing white spaces on all lines - Correct indentation When indentation is corrected, the $NON-NLS-1$ is also removed, producing following code produced non externalizes string error: if (param.getValue().equals("")) throw new ValidationException( Messages.ErrorMessage); However, this happens only if the "Convert control statement bodies to block" is set to "except for single return or throw statement". Eclipse SDK Version: 3.4.0 Build id: I20080617-2000 Eclipse Java Development Tools Version: 3.4.0.v20080603-2000-7o7tEAXEFpPqqoXxgaBhhhq Build id: I20080617-2000
Simpler test case: 1. have an if-statement that has a comment on the same line, e.g.: if (true) // this is a test 2. run clean up with only 'Convert control statement bodies to block' ==> comment lost
This is a bug in org.eclipse.jdt.core.dom.rewrite.ASTRewrite.set(ASTNode, StructuralPropertyDescriptor, Object, TextEditGroup). I understand that the general problem of handling/loosing comments is very hard to solve in the ASTRewrite but I guess it should not be to hard to handle this concrete problem (i.e. EndOfLineComment after if).
*** Bug 153264 has been marked as a duplicate of this bug. ***
This bug has been reported several times now. Martin always refused to fix it but I think we should try to do something at least for this special case if possible.
Even easier to reproduce with quick fixes that add/remove blocks: if (true) // quick fix change to block System.out.println(-42); if (true) { // quick fix change to statement System.out.println(42); } CompilationUnit#getExtended*(ASTNode) should probably include these comments (map them to the statement on the next line). Bug 153264 is a similar problem (but not exactly the same).
>Bug 153264 is a similar problem (but not exactly the same). Right, bug 153264 contains more (complex) samples/dups of comment problems. Please don't defer this one just because there are too many cases. We should try to at least solve the scenario where the EndOfLine comment is on the same line as the if and the else (if): if (xxx) // comment ... else if (xxx) // comment else // comment e.g. if (xxx) // comment ... ==> if (xxx) // comment { ... } or (maybe?) better: if (xxx) { // comment ... } But we need to be careful that this doesn't become: if (xxx) { // comment ... } if such formatter prefs are used.
*** Bug 378139 has been marked as a duplicate of this bug. ***
*** Bug 385478 has been marked as a duplicate of this bug. ***
*** Bug 261207 has been marked as a duplicate of this bug. ***
*** Bug 429079 has been marked as a duplicate of this bug. ***
*** Bug 453692 has been marked as a duplicate of this bug. ***
The best solution for such problems is usually to call ASTRewrite#setTargetSourceRangeComputer(TargetSourceRangeComputer) and set a NoCommentSourceRangeComputer or a properly configured TightSourceRangeComputer.
*** Bug 491720 has been marked as a duplicate of this bug. ***
*** Bug 501860 has been marked as a duplicate of this bug. ***
*** Bug 535440 has been marked as a duplicate of this bug. ***
Still in 4.11... Just hit it on mass-cleanup of PDE code...
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.