Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 507922

Summary: Code cleanup deletes comments
Product: [Eclipse Project] JDT Reporter: Klaus Christiansen <klaus.edwin.christiansen>
Component: TextAssignee: JDT-Text-Inbox <jdt-text-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: gautier.desaintmartinlacaze, loskutov
Version: 4.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug
Attachments:
Description Flags
The code cleanup settings I used. none

Description Klaus Christiansen CLA 2016-11-22 01:50:23 EST
Created attachment 265503 [details]
The code cleanup settings I used.

Java Code cleanup sometimes removes comments.
It seams that comments on the same line as an IF (maybe other block statements to?) is removed during code cleanup.
Other times the result is just poorly formatted.

Before:
@Override
public String getTypeName() {
    if (type == null) // No type means that we are the type.
        return NameUtils.upperCaseFirstChar(NameUtils.setVariableCase(getName()));
    return type.getTypeName();
}

After:
@Override
public String getTypeName() {
    if (type == null) {
        return NameUtils.upperCaseFirstChar(NameUtils.setVariableCase(getName()));
    }
    return type.getTypeName();
}



This is an example of poorly formatted code cleanup.
Before:
public void addImport(String imp) {
    if (imp.contains("FormGroup2"))
        System.err.println("addToImport ");
    String imppac = imp.substring(0, imp.lastIndexOf("."));
    if (imppac.equals(getPackageName()))
        return; // No need to add classes in same package
    if (getImports().get(imppac + ".*") != null)
        return; // Whole package already imported

    imports.put(imp, imp);
}

After:
public void addImport(String imp) {
    if (imp.contains("FormGroup2")) {
        System.err.println("addToImport ");
    }
    String imppac = imp.substring(0, imp.lastIndexOf("."));
    if (imppac.equals(getPackageName()))
     {
        return; // No need to add classes in same package
    }
    if (getImports().get(imppac + ".*") != null)
     {
        return; // Whole package already imported
    }
   
    imports.put(imp, imp);
}

Another example of poorly formatted code cleanup.

before:
protected void define(FunctionSymbol sym, boolean doSetScope) {
    if (doSetScope)
        sym.scope = this; // track the scope in each symbol
...
}

After:
protected void define(FunctionSymbol sym, boolean doSetScope) {
    if (doSetScope)
     {
        sym.scope = this; // track the scope in each symbol
    }
...
}
Comment 1 Eclipse Genie CLA 2020-03-15 13:26:38 EDT
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.