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

Bug 355926

Summary: [content assist] Code completion adds wrong method proposal if superclass method contains generic varargs argument
Product: [Eclipse Project] JDT Reporter: Andre Bargull <andrebargull+eclipse>
Component: TextAssignee: Deepak Azad <deepakazad>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, deepakazad, samrat.dhillon
Version: 3.8   
Target Milestone: 3.8 M6   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
Proposing a patch for this bug none

Description Andre Bargull CLA 2011-08-26 05:11:14 EDT
Build Identifier: M20110825-0847

When overriding a method from a superclass which has got a generic varargs argument, code completion adds a wrong method declaration. 

Expected:
- the following method declaration should be added
 @Override
 void method(Z<?>... zs) {
   // TODO Auto-generated method stub
   super.method(zs);
 }

Actual:
- "transient" modifier is added
- varargs argument is changed to array
- outer class name ("Testcase") is added
- the complete method declaration looks like follows
 transient void method(Testcase.Z<?>[] zs) {};

Environment:
- Eclipse 3.7.1 (M20110825-0847)
- JDK 7

---
class Testcase {
    static interface Z<T> {}

    static class A {
        void method(Z<?>... zs) {}
    }

    static class B extends A {
        // - type here `method` and then use code completion (ctrl + space)
    }
}
---

Reproducible: Always
Comment 1 Ayushman Jain CLA 2011-08-26 05:25:43 EDT
Seems broken since pre-3.7 times. Will investigate
Comment 2 Samrat Dhillon CLA 2012-02-28 12:19:57 EST
Created attachment 211750 [details]
Proposing a patch for this bug

This proposed fix is to preserve argument type. Eclipse is dropping everything that comes after '<' while comparing arguments. 

extension/org/eclipse/jdt/internal/corext/dom/Bindings.java isEqualMethod is dropping stuff that comes after <> for argument comparison. It makes sense to drop the generic arguments but eclipse should preserve stuff that comes after generic arguments; such as an array. 

e.g. while comparing arguments Z<?>[] and Z, if everything after < is dropped Z<?>[] and Z will become equal which is not true.
Comment 3 Ayushman Jain CLA 2012-02-28 12:48:36 EST
Deepak, can you please take a look at the above patch(which is against JDT/Text) and see if it solves the problem? If so, we can move it to JDT text for a review. Thanks!
Comment 4 Deepak Azad CLA 2012-02-29 01:59:19 EST
(In reply to comment #2)
> Created attachment 211750 [details] [diff]
> Proposing a patch for this bug

Looks reasonable. I will take a look. (Have to make sure that other clients are not adversely affected)
Comment 5 Deepak Azad CLA 2012-03-03 05:29:25 EST
(In reply to comment #2)
> Created attachment 211750 [details] [diff]
> Proposing a patch for this bug
Thanks for the patch, Samrat! 

I tweaked the patch a bit and added a few tests.

http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=944192f9c11b3675c106e773bfaafdb80fc6851b