Bug 137847 - getSourceRange() don't work on constructors of some binary inner classes
Summary: getSourceRange() don't work on constructors of some binary inner classes
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-20 17:53 EDT by Andrey Loskutov CLA
Modified: 2009-04-07 11:45 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Loskutov CLA 2006-04-20 17:53:08 EDT
This is a followup of the bug 119249 comment 6.
Seen with the RC1, Build id: I20060413-1718, JDK 1.5

I'm trying to get source range for explicit constructors of inner classes from
binary types, like the one from HasMap$Entry class in JDK 1.5.

If I call IClassFile.getElementAt(offset) on HashMap with the source offset of the HashMap.Entry constructor, then I get the Entry as BinaryType, but not the constructor itself. If I call IClassFile.getElementAt(offset) on HasMap$Entry with the same offset, then I get null because org.eclipse.jdt.internal.core.SourceMapper could not find the appropriate source range for binary method (Entry constructor) in getSourceRange().

Summary:
- IClassFile.getElementAt(constructor_offset) returns the enclosing type instead of binary method
- SourceMapper.getSourceRange() for some binary constr. returns UNKNOWN_RANGE so that:
- - IClassFile.getElementAt(constructor_offset) returns null
- - ISourceReference.getSourceRange() returns null for binary constr.

Please notice, that in this case the binary constructor *has* the appropriated source code, so it *should* have source range.

To reproduce the bug:
1) open HashMap *class file* from JDK 1.5 (the source should be attached to the jdk). 
2) The navigation in Java editor will *not* work if you select the Entry(int h, K k, V v, Entry<K,V> n) constructor in the outline. 
3) Create breakpoint at 
org.eclipse.jdt.internal.ui.javaeditor.JavaEditor:
protected void setSelection(ISourceReference reference, boolean moveCursor)
In RC1 on the line 1995 is the call to the reference.getSourceRange().

The "reference" variable looks in debugger as:
Entry(int, K, V, java.util.HashMap.Entry<K,V>) [in Entry [in HashMap$Entry.class [in java.util [in F:\java\jdk1.5.0\jre\lib\rt.jar [in Test]]]]]

The source range returned at line 1995 is null.

This is NOT the error in JavaEditor, because I've got similar problem in the completely different code which is not related to JavaEditor.

Same behavoir for HashIterator() constructor in HashMap.
This bug seems to be similar to the bug 119249.

The difference is probably that HashMap.Entry is a *static* class, and HashMap.HashIterator an abstract class.
Comment 1 Andrey Loskutov CLA 2006-04-29 11:36:15 EDT
In 3.2RC2 still the same error.
I have also realized, that the "Show source of selected element only" button on the Java editor toolbar doesn't work too - in 3.1, if cursor is inside of HashMap.Entry constructor, the code of constructor only could be shown in editor, in 3.2 the whole inner class wil be shown (because source range for constructor is "unknown").
Comment 2 Jerome Lanneluc CLA 2006-05-03 07:29:47 EDT
Will consider post 3.2
Comment 3 Andrey Loskutov CLA 2008-06-14 14:56:39 EDT
Seems to be fixed in 3.3-3.4. Verified with 3.4 RC3
Comment 4 Jerome Lanneluc CLA 2008-06-16 07:30:43 EDT
Changing resolution to WORKSFORME since no action was taken to fix this particular bug.