| Summary: | ITypeBinding.isAssignable(ITypeBinding) does not work if types came from different universe | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Theodora Yeung <tyeung> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | aalves, jgarms, markus.kell.r, thanson |
| Version: | 3.1.1 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
(sorry hit the commit key too early by mistake)
public ITypeBinding getTypeBinding(final String bindingKey){
final ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setResolveBindings(true);
parser.setProject(<java project>);
parser.createASTs(new ICompilationUnit[]{}, new String[]{bindingKey}, <some
non-null requestor>, null);
}
public boolean isAssignableTest(){
final String collectionKey =
BindingKey.createTypeBindingKey("java.util.Collection");
final ITypeBinding type0 = getTypeBinding(collectionKey);
final ITypeBinding type1 = getTypeBinding(collectionKey);
return type0.isAssignmentCompatible(type1);
}
The call to isAssignableTest() will always return false even though the type theoretically is the same type (both being java.util.Collection). The problem here being type0 and type1 came from two completely different type binding universe and == comparison as well .equals() will always return false.
This presents a huge problem to user since the binding universe is an implementation detail that is not exposed and not documented in the API. To a user, this just looks like a bug.
|
public ITypeBinding getTypeBinding(final String bindingKey){ final ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setResolveBindings(true); parser.setProject(<java project>); parser.createASTs(new ICompilationUnit[]{}, new String[]{bindingKey}, <some non-null requestor>, null); } public boolean isAssignableTest(){ final String collectionKey = BindingKey.createTypeBindingKey("java.util.Collection"); final ITypeBinding type0 = getTypeBinding(collectionKey); final ITypeBinding type1 = getTypeBinding(collectionKey); System.err.println("t0 assignable to t1 ? " + type0.isAssignmentCompatible(type1)); System.err.println("t1 assignable to t2 ? " + type1.isAssignmentCompatible(type0)); }