Community
Participate
Working Groups
This is a fully reproducible bug. 1. Reference some jar in your project. 2. Attach its source. 3. Browse to an Inner class. 4. Place your cursor inside the innner class constructor. Now if the following code snippet is run, it returns null if the file is a .class file, however it returns an IMethod if the same is inside a .java file. private IMember getMethodAtCursor() { IJavaElement element = getSelectedJavaElement(); if (element != null) { try { if (element instanceof ICompilationUnit) { element = ((ICompilationUnit) element).getElementAt(currentSelection.getOffset()); } else if (element instanceof IClassFile) { //NOTE: this line will set element to null element = ((IClassFile) element).getElementAt(currentSelection.getOffset()); } if (element instanceof IMethod || element instanceof IInitializer) return (IMember) element; } catch (JavaModelException e) { return null; } } return null; }
An even easier way to reproduce this bug is to open a .class file (with source of course), and open the outline view. When you place your cursor inside the constructor of the inner class, the outline view doesnt sync and highlight the method inside the view, however it does so for every other method in the inner class. My personal gut feeling says that its cause the inner class constructors take a hidden parameter to the 'this' pointer of the outerclass and that is messing with the signature that the text editor is passing which does not include the hidden parameter.
At a quick check I couldn't reproduce. Using Eclipse 3.6.0 I opened class HashMap from the JRE and navigated to some of its inner classes like Entry. In this scenario everything works as expected. So you probably have either a different Eclipse version or a different inner class.
could be some compiler specific thing in the class file. try using a 1.5 compiled class file.
If it's fully reproducible on your machine we need to know what exact Eclipse version you have and which example classes from which jar you used. Could you please provide these details? Thanks.
i am using eclipse 3.6.0. did you try reproducing on 1.5 compiled class?
(In reply to comment #5) > i am using eclipse 3.6.0. > did you try reproducing on 1.5 compiled class? Prashant, please attach a test case that is showing the problem. Thanks.
here ya go - 1. download berkeley db je 4.103 2. reference it and attach the src in eclipse. 3. navigate to the constructor of Store.InternalPrimaryIndex you can see the problem manifest itself there.
(In reply to comment #7) > here ya go - > > 1. download berkeley db je 4.103 > 2. reference it and attach the src in eclipse. > 3. navigate to the constructor of Store.InternalPrimaryIndex > > you can see the problem manifest itself there. OK, that get's us going. Here's a minimal test class: public class Container { private class Inner<S> { Inner(String st/*, Class<S> s*/) { super(); } } } - export as jar in the file system, - import into other project as external jar and attach source. Using the class as above everything works fine, however, when uncommenting the second ctor arg (and repeating the jar-steps) the outline indeed no longer synchronizes with the editor, likely indicating a missing java element.
Thanks for the test case. I'll investigate.
*** Bug 322880 has been marked as a duplicate of this bug. ***
The problem occurs only when the constructor has a generic signature. I believe the problem comes from the fact that the generic signature doesn't contain the enclosing instance.
Created attachment 178060 [details] Proposed fix Stephan, could you please test it with your test case ? Thanks. I still need to add a regression test for it.
Created attachment 178149 [details] Proposed fix + regression test Same patch with a regression test.
Released for 3.7M2. Regression test added in: org.eclipse.jdt.core.tests.model.AttachSourceTests#testConstructorAccess
(In reply to comment #12) > Created an attachment (id=178060) [details] > Proposed fix > > Stephan, could you please test it with your test case ? > Thanks. > I still need to add a regression test for it. Sorry for the delay (I was away from the internet for some days). I just picked up build N20100903-2000 and tried the scenarios from comment 8 and everything works as desired. Good job :) Obviously the missing JavaElement was indeed the issue and your test and fix are sufficient.
Verified in I20100914-0100.