Bug 329998

Summary: [content assist] override method proposal in anonymous class inserts bad stub
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, jarthana, Olivier_Thomann, remy.suen
Version: 3.7   
Target Milestone: 3.7 M4   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Proposed fix + regression test none

Description Markus Keller CLA 2010-11-11 09:33:04 EST
HEAD

Have this example:

public class Try {
    Object field;

    void foo() {
        field= new Object() {
            hash
        };
    }

    void bar() {
        Object var= new Object() {
            hash
        };
    }
}

Content assist after the first "hash" inserts:

            public int hashCode() {};

Expected: Same as proposal at second "hash" (formatted, calls super method).

See also bug 317497, bug 246343 for similar problems.
Comment 1 Dani Megert CLA 2010-11-15 08:52:02 EST
This looks like a bug in JDT Core's NodeFinder: in the first case it returns the ExpressionStatement but in the second/correct one, it correctly returns the AnonymousClassDeclaration node. Also, if I remove "hash", do code assist and then select 'hashCode', it also works fine.
Comment 2 Olivier Thomann CLA 2010-11-15 12:34:25 EST
The problem comes from the positions (start/length) of the assignment node are wrong. They don't include the anonymous type declaration.
This is easily visible using the ASTView and double-clicking on the assignment node. Only "field= new Object()" is selected.
This is related to the syntax error recovery. Positions are fine if the code doesn't contain syntax errors.
Investigating.
Comment 3 Olivier Thomann CLA 2010-11-15 13:04:34 EST
Created attachment 183147 [details]
Proposed fix + regression test
Comment 4 Olivier Thomann CLA 2010-11-15 14:22:31 EST
Released for 3.7M4.
Comment 5 Jay Arthanareeswaran CLA 2010-12-07 05:22:54 EST
Verified for 3.7M4 using build I20101206-1800