Bug 309966 - IType#getKey() does not work for unresolved local ITypes
Summary: IType#getKey() does not work for unresolved local ITypes
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 minor (vote)
Target Milestone: 3.6 M7   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-21 10:07 EDT by Markus Keller CLA
Modified: 2010-04-26 14:00 EDT (History)
3 users (show)

See Also:


Attachments
Proposed fix (1.65 KB, patch)
2010-04-22 19:35 EDT, Olivier Thomann CLA
no flags Details | Diff
Complement (3.18 KB, patch)
2010-04-23 09:11 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2010-04-21 10:07:41 EDT
HEAD, follow-up to bug 301113 comment 2:

package x.y.z;

public class Test {
  public void method() {
    class LocalClazz {
      public String speak() {
        return "hello"; //set bp here
      }
    }
  }
}

The key I get from IType.getKey() is: Lx/y/z/Test$LocalClazz;
(The IType is coming from ITypeRoot.getElementAt(..)).

From bug 301113 comment 3:
IType#getKey() does not specify that it doesn't work for unresolved local ITypes (with IType#isResolved() == false).

Debug has a workaround (i.e. can live without a fix for 3.6).
Comment 1 Olivier Thomann CLA 2010-04-22 14:47:12 EDT
The problem is that the key is different between a resolved type and an unresolved type.
When the type is resolved, its key comes from the corresponding binding. When the type is not resolved, its key is computed and the way it is computed returns a different value for local types.
Comment 2 Olivier Thomann CLA 2010-04-22 15:02:09 EDT
Using:
CompilationUnit unit = SharedASTProvider.getAST(type.getTypeRoot(),
SharedASTProvider.WAIT_YES, null);
ASTNode node = unit.findDeclaringNode(type.getKey());
is wrong as type.getKey() is not a binding key. It is only a java element key when the element is not resolved.
Would not a org.eclipse.jdt.core.dom.NodeFinder be used to retrieve the corresponding ASTNode?
Comment 3 Markus Keller CLA 2010-04-22 15:13:11 EDT
(In reply to comment #2)
> [..] is wrong as type.getKey() is not a binding key. It is only a
> java element key when the element is not resolved.

That is not spec'd in IType#getKey(), which is why I've opened this bug. We can also close this by saying that the method only returns a binding key if the type is resolved.

> Would not a org.eclipse.jdt.core.dom.NodeFinder be used to retrieve the
> corresponding ASTNode?

No, we don't want to find the corresponding node, but the *declaring* node.
Comment 4 Markus Keller CLA 2010-04-22 15:18:46 EDT
(In reply to comment #3)
> > Would not a org.eclipse.jdt.core.dom.NodeFinder be used to retrieve the
> > corresponding ASTNode?
> 
> No, we don't want to find the corresponding node, but the *declaring* node.

Sorry, for bug 301113, that would definitely be a better solution with even better performance, since IType#getNameRange() shouldn't be too expensive and we can use the shared AST again.
Comment 5 Olivier Thomann CLA 2010-04-22 15:21:42 EDT
(In reply to comment #4)
> Sorry, for bug 301113, that would definitely be a better solution with even
> better performance, since IType#getNameRange() shouldn't be too expensive and
> we can use the shared AST again.
Exactly what I had in mind :-). I'll try to provide a patch for this.
Comment 6 Olivier Thomann CLA 2010-04-22 19:35:53 EDT
Created attachment 165863 [details]
Proposed fix
Comment 7 Olivier Thomann CLA 2010-04-22 19:36:15 EDT
Released for 3.6M7.
Comment 8 Markus Keller CLA 2010-04-23 06:02:03 EDT
I guess we have the same problem in IField and IMethod, so the Javadoc should also be adjusted there.
Comment 9 Olivier Thomann CLA 2010-04-23 09:11:53 EDT
Created attachment 165905 [details]
Complement
Comment 10 Olivier Thomann CLA 2010-04-23 09:12:14 EDT
Released for 3.6M7.
Comment 11 Ayushman Jain CLA 2010-04-26 13:53:48 EDT
Verified for 3.6M7 through code inspection
Comment 12 Jay Arthanareeswaran CLA 2010-04-26 14:00:09 EDT
Verified.