Bug 33172 - Code assist shows repeated method names with inner classes
Summary: Code assist shows repeated method names with inner classes
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-25 18:33 EST by Alex Blewitt CLA
Modified: 2004-06-30 10:35 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Blewitt CLA 2003-02-25 18:33:16 EST
I discovered an odd behaviour in a nested class:

public class OuterPanel extends JPanel {
  public class InnerPanel extends JPanel {
    public InnerPanel() {
      setLayo <- code assist here
    }
  }
}

This brings up two setLayout() methods, though both provide the same identical
piece of code. I verified this with other JPanel methods (setSize, setLocation)
and they all appeared to be duplicated.

On reflection, I think it was showing me both the inner and outer classes' 
methods. [I tested this theory out with a third nested inner class, and indeed
in that inner class, it showed three methods, so this seems to be the right idea]

However, it doesn't matter which one I pick since they all expand to 
setLayout(mgr) in the code itself.

My thoughts are:

A) This behaviour should display one method if all it's going to do is insert
   the same piece of code, or
B) The methods showing calls to the outer class should be distinguished somehow
   in the method code assist area (such as setLayout(LayoutManager) -
   OuterPanel) and the code should generate the appropriate OuterPanel.setLayout
   call

In this particular case, I wanted the internal method call, but there may be
situations where a commonly-used name (like getName()) is desired to be called
on the outer class whereas instead it will pick up the inner class' implementation.

Eclipse 2.1RC1 Windows 2000/Mac OS X.2.4
Comment 1 Philipe Mulet CLA 2003-02-27 05:26:58 EST
Our intent is to provide all methods, and provide adequate qualification in 
case of conflict (if you mean the enclosing method).

Need to investigate.
Comment 2 David Audel CLA 2003-02-27 09:08:31 EST
If i do code completion with your test case, there is two proposals. This 
proposals seems to be the same in the popup window. If i select the first 
proposal, the inserted text is "setLayout()", but if i select the other 
proposal, the inserted text is "OuterPanel.this.setLayout()".

Alex - Do you see the same behavior ?
Comment 3 Alex Blewitt CLA 2003-02-27 09:20:54 EST
Both of the proposals return the same 'setLayout(mgr)' regardless of which 
one I select, on both Windows 2000 and Mac OS X.2.4 using Eclipse 2.1RC1
(200302211557)

It's possible that this has been fixed by another patch elsewhere (for example,
it might be an underlying issue in the SWT List that can't tell which of two
identical entries are selected).

However, IMHO it would still be useful for the drop-down list to distinguish
between the two, possibly by changing the '- Component' to '- OuterPanel' or '- Component (OuterPanel)'
Comment 4 Philipe Mulet CLA 2003-02-27 09:46:55 EST
Alex - there are 2 things to consider:
1- what you see in the completion popup,
2- what gets inserted in the editor after picking one completion

We know that (1) is confusing, this is a known JDT/UI limitation (they should 
disambiguate the presented information, but currently don't).

However, on (2) we think we insert the various prefixes corresponding to what 
you select, on your exact test case. Can you confirm this ? 

There is no patch elsewhere that we know about which would alter this behavior.
Comment 5 Alex Blewitt CLA 2003-02-27 09:52:48 EST
To clarify: the behaviour described in the bug is the behaviour I see. I retested
it and put comment #3 to clarify this.

So, to be completely unambiguous, I have never seen the OuterPanel.this.setLayout() in 2.1RC1, regardless of which of the two 
proposals I choose.

Have you tested this against 2.1RC1 or a more recent build? If it is more recent,
then perhaps you could test against a fresh install of 2.1RC1 to see if this
is an issue with 2.1RC1, or whether it's an install issue on my machine(s).

FWIW One of them is an upgraded workspace from previous 2.1M builds, the other
(Windows) is a fresh install of 2.1RC1.
Comment 6 David Audel CLA 2003-02-27 11:51:38 EST
If you have never seen "OuterPanel.this.setLayout()", there is bug.
But i cannot reproduce it with 2.1M4, 2.1M5, 2.1RC1 , the latest integration 
build (I20030227)and and with a fresh workspace.

What is your exact test case? The test case  seems to be incomplete (import is 
missing). I tried to reproduce the problem with the following code.

import javax.swing.JPanel;
public class OuterPanel extends JPanel {
  public class InnerPanel extends JPanel {
    public InnerPanel() {
      setLayo<- code assist here
    }
  }
}
Comment 7 Alex Blewitt CLA 2003-02-27 12:20:53 EST
I tried this on my M5 install with a clean workspace, and it worked correctly.
It may be something that is just screwed up with my preferences in the more
recent builds.

I'd suggest filing this as RESOLVED/WORKSFORME and when RC2 comes out I'll zap
my workspace and verify this.
Comment 8 David Audel CLA 2003-03-18 10:20:52 EST
I can reproduce the symptom with another test case but i don't think that is 
the same bug.

import javax.swing.JPanel;
public class X {
  void foo(){
    new JPanel(){
      class InnerPanel extends JPanel {
        public InnerPanel() {
          setLayout(<- code assist here
        }
      }
    };
  }
}
Comment 9 David Audel CLA 2003-03-18 10:38:31 EST
I filled a new bug report for this new test case (bug 35220).
Comment 10 David Audel CLA 2004-05-10 05:53:38 EDT
Could not reproduce in I20040506

Closed.