Bug 100636 - [model] Can't find overriden methods of protected nonstatic inner class.
Summary: [model] Can't find overriden methods of protected nonstatic inner class.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-17 14:29 EDT by Brian Miller CLA
Modified: 2005-09-26 10:16 EDT (History)
1 user (show)

See Also:


Attachments
Fix partially fixing the problem (2.62 KB, patch)
2005-06-21 14:09 EDT, Frederic Fusier CLA
no flags Details | Diff
Improved patch (2.07 KB, patch)
2005-06-22 06:09 EDT, Jerome Lanneluc CLA
no flags Details | Diff
Another approach (4.62 KB, patch)
2005-06-22 08:53 EDT, Jerome Lanneluc CLA
no flags Details | Diff
Merged patches from comment 15 and comment 16 (5.67 KB, patch)
2005-08-19 06:56 EDT, Jerome Lanneluc CLA
no flags Details | Diff
Regression test (2.42 KB, patch)
2005-08-19 06:57 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Miller CLA 2005-06-17 14:29:56 EDT
I'm using 3.1RC2.  There are two symptoms of this bug, written in CAPITAL 
LETTERS in steps 4 & 6 below.

Steps:

1) Open type javax.swing.DefaultCellEditor.

2) Switch to the Java Browsing perspective.

3) In the Members tab, hilite EditorDelegate and press F4 (Open Type 
Hierarchy).

4) In the lower pane of the Hierarchy tab, rightclick on setValue(Object) and 
pick Declarations>>Hierarchy.  WRONGLY NONE ARE FOUND.

5) In the upper pane of the Hierarchy tab, doubleclick on any one of 
EditorDelegate's subclasses.  The subclass's source is scrolled into view in 
the source text editor.

6) In the left margin of the source text editor, click on any of the green 
triangles appearing at any of the subclass's methods.  THE SOURCE TEXT EDITOR 
FAILS TO SCROLL TO THE SUPERTYPE'S DECLARATION OF THAT METHOD.
Comment 1 Brian Miller CLA 2005-06-17 14:54:02 EDT
Steps for another symptom:

Repeat steps 1-2 above.

3) In the Members tab, rightclick on EditorDelegate's constructor and pick 
References>>Hierarchy.  WRONGLY NONE ARE FOUND.
Comment 2 Dirk Baeumer CLA 2005-06-20 05:26:12 EDT
This are two distinct issues. I opened bug 100776 for the search for declaration
issue. 

Moving to Text for the navigation issue (suspect that getJavaElement returns null).

Comment 3 Dani Megert CLA 2005-06-20 08:21:26 EDT
we get the wrong element for the correct method binding when calling
IMethodBinding..getJavaElement()
Comment 4 Frederic Fusier CLA 2005-06-20 08:28:29 EDT
I suspect that search match element handle is not correctly created...
Comment 5 Frederic Fusier CLA 2005-06-21 07:06:59 EDT
In fact this is not a search problem as it is not involved while clicking on
override indicator.
In fact, this problem does not seem to come from JDT/Core binding.

I've set a breakpoint in OverrideIndicatorManager.open() method at line 106.
Now I try to click on override indicator of setValue(Object) method in one of
DefaultCellEditor constructor => definingMethod.exist() returns false.
I think that's why Dany assign this bug to JDT/Core...

However, now try a different scenario:
1) select the setValue(Object) method
2) click on F3 to open editor on anonymous class
3) in this new editor click on override indicator
=> at my breakpoint, definingMethod.exist() now returns true!

methodBinding (result of resolveBinding() on methodDeclaration node), is the
same in both scenarios but definingMethodBinding is different => it looks like
problem comes from findMethodDefininition(IMethodBinding,boolean) which does not
compute correctly method binding from JDT/Core binding key

So, put back to JDT/Text component for comment and further investigation
Comment 6 Dani Megert CLA 2005-06-21 07:52:19 EDT
Not sure what the second scenario should prove.
definingMethodBinding.getJavaElement() should *not* return the method in the
anonymous class but the EditorDelegate.setValue(Object).

I will have to debug this with Martin to see whether/why we compute the wrong
method binding.
Comment 7 Frederic Fusier CLA 2005-06-21 08:45:03 EDT
Sorry to have returned this bug a little bit too rapidly...
You're right, in my second scenario the element exist but was not correct!
I've verified that in first scenario Binding.findMethodDefinition returns
correct binding:
Ljavax/swing/DefaultCellEditor$EditorDelegate;.setValue(Ljava/lang/Object;)V
but getJavaElement() fails to return a valid java element.

Put back in JDT/Core land...
Comment 8 Frederic Fusier CLA 2005-06-21 08:53:10 EDT
Problem is located in TypeBinding.getUnresolvedJavaElement(TypeBinding)
In this case, typeBinding argument is a MemberTypeBinding:
Member type : EditorDelegate (id=NoId)
protected class javax.swing.DefaultCellEditor$EditorDelegate
	extends java.lang.Object
	implements : java.awt.event.ActionListener, java.awt.event.ItemListener,
java.io.Serializable
	enclosing type : javax.swing.DefaultCellEditor
...
but fileName computed in this method does not reflect it:
[=, b, 1, 0, 0, 7, 7, 6, /, D, :, \, /, a, \, /, J, D, K, s, \, /, s, u, n, \,
/, 1, ., 5, ., 0, \, /, j, r, e, \, /, l, i, b, \, /, r, t, ., j, a, r, |, j, a,
v, a, x, /, s, w, i, n, g, /, D, e, f, a, u, l, t, C, e, l, l, E, d, i, t, o, r,
., c, l, a, s, s]

then classFile is:
DefaultCellEditor.class [in javax.swing [in D:\a\JDKs\sun\1.5.0\jre\lib\rt.jar
[in b100776]]]
  class DefaultCellEditor

and this method returns enclosing type binding instead of member type one...
Comment 9 Martin Aeschlimann CLA 2005-06-21 08:56:44 EDT
You can also see problem when looking at the method binding in the AST view:

- open the AST view on DefaultCellEditor
    line 90, ('setValue'), expand method binding
or
    line 278 ('setValue')

java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.Signature.getParameterCount(Signature.java:981)
	at org.eclipse.jdt.core.Signature.getParameterTypes(Signature.java:1155)
	at org.eclipse.jdt.core.Signature.getParameterTypes(Signature.java:1194)
	at org.eclipse.jdt.ui.JavaElementLabels.getMethodLabel(JavaElementLabels.java:490)
	at org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(JavaElementLabels.java:386)
	at org.eclipse.jdt.ui.JavaElementLabels.getElementLabel(JavaElementLabels.java:363)
	at org.eclipse.jdt.astview.views.JavaElement.getLabel(JavaElement.java:55)
	at
org.eclipse.jdt.astview.views.ASTViewLabelProvider.getText(ASTViewLabelProvider.java:66)
	at
org.eclipse.jface.viewers.StructuredViewer.buildLabel(StructuredViewer.java:1877)
	at org.eclipse.jface.viewers.TreeViewer.doUpdateItem(TreeViewer.java:231)
	at
org.eclipse.jface.viewers.AbstractTreeViewer$UpdateItemSafeRunnable.run(AbstractTreeViewer.java:85)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044)
	at org.eclipse.core.runtime.Platform.run(Platform.java:783)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:44)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:148)
	at
org.eclipse.jface.viewers.AbstractTreeViewer.doUpdateItem(AbstractTreeViewer.java:621)
	at
org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:434)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044)
	at org.eclipse.core.runtime.Platform.run(Platform.java:783)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:44)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:148)
	at
org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:1763)
	at
org.eclipse.jface.viewers.AbstractTreeViewer.createTreeItem(AbstractTreeViewer.java:535)
	at org.eclipse.jface.viewers.AbstractTreeViewer$1.run(AbstractTreeViewer.java:514)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:69)
	at
org.eclipse.jface.viewers.AbstractTreeViewer.createChildren(AbstractTreeViewer.java:494)
	at
org.eclipse.jface.viewers.AbstractTreeViewer.handleTreeExpand(AbstractTreeViewer.java:948)
	at
org.eclipse.jface.viewers.AbstractTreeViewer$4.treeExpanded(AbstractTreeViewer.java:959)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:179)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
...
Comment 10 Frederic Fusier CLA 2005-06-21 14:01:35 EDT
comment 9 issue seems to be related to bug 100549...
=> set this bug as depending on it
Comment 11 Frederic Fusier CLA 2005-06-21 14:09:42 EDT
Created attachment 23650 [details]
Fix partially fixing the problem

This fix partially fixes the problem as now overriden indicator works but only
in top level class editor (ie. DefaultCellEditor.class).
It still fails in second scenario (ie. in DefaultCellEditor$1.class editor)

I've also added a change in SourceTypeBinding.computeUniquekey(boolean) method
to try to fix bug 100549 issue but I'm not really sure it is the correct thing
to do...
Comment 12 Frederic Fusier CLA 2005-06-21 14:10:22 EDT
Hope this patch may help a little bit...
Comment 13 Jerome Lanneluc CLA 2005-06-22 04:58:20 EDT
In fact, bug 100549 has nothing to do with this one.
Removing dependency.
Comment 14 Jerome Lanneluc CLA 2005-06-22 05:00:07 EDT
Really removing dependency
Comment 15 Jerome Lanneluc CLA 2005-06-22 06:09:34 EDT
Created attachment 23714 [details]
Improved patch

This patch takes a different approach: it uses the binding's constant pool name
to get the class file name.
Comment 16 Jerome Lanneluc CLA 2005-06-22 08:53:21 EDT
Created attachment 23723 [details]
Another approach

In this approach, we ensure that the class file name is always the toplevel
type class file name.
The patch still needs to handle the case of anonymous and local types (see
TODO)
Comment 17 Jerome Lanneluc CLA 2005-06-22 08:54:15 EDT
Anyway, the bug existed in 3.0. So this is not a regression.
This is a good candidate for 3.1.1
Comment 18 Jerome Lanneluc CLA 2005-08-19 06:56:43 EDT
Created attachment 26288 [details]
Merged patches from comment 15 and comment 16
Comment 19 Jerome Lanneluc CLA 2005-08-19 06:57:05 EDT
Created attachment 26289 [details]
Regression test
Comment 20 Philipe Mulet CLA 2005-09-01 06:40:09 EDT
+1 for 3.1.1
Comment 21 Jerome Lanneluc CLA 2005-09-02 06:35:17 EDT
Released fix (slightly modified to handle default binary packages) and
regression tests
ASTModelBridgeTests#testBinaryMemberTypeFromAnonymousClassFile1() and
testBinaryMemberTypeFromAnonymousClassFile2() in both HEAD and R3_1_maintenance
branch.
Comment 22 David Audel CLA 2005-09-21 07:48:37 EDT
Verified in I20050920-0010 for 3.2M2
Comment 23 Olivier Thomann CLA 2005-09-26 10:16:14 EDT
Verified for 3.1.1 using M20050923-1430.