Bug 329998 - [content assist] override method proposal in anonymous class inserts bad stub
Summary: [content assist] override method proposal in anonymous class inserts bad stub
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M4   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-11 09:33 EST by Markus Keller CLA
Modified: 2010-12-07 05:22 EST (History)
4 users (show)

See Also:


Attachments
Proposed fix + regression test (4.36 KB, patch)
2010-11-15 13:04 EST, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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