Bug 95727 - ITypeBinding#getJavaElement() returns a ResolvedSourceField for an anonymous class
Summary: ITypeBinding#getJavaElement() returns a ResolvedSourceField for an anonymous ...
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 RC1   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-18 07:12 EDT by Markus Keller CLA
Modified: 2005-05-27 07:40 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2005-05-18 07:12:26 EDT
HEAD

- create an AST for org.eclipse.jdt.internal.core.search.matching.MatchLocator
- resolve the type binding for the anonymous type inside
    #createAndPattern(SearchPattern, SearchPattern)

=> ITypeBinding#getJavaElement() on that anonymous type returns:
ResolvedSourceField:
org.eclipse.jdt.internal.core.search.matching.MatchLocator.createAndPattern(...).new
AndPattern() {...}.current : SearchPattern

=> Expected: the IType for the anonymous class, not an IField inside the type.

Consequently, getJavaElement() on e.g. the variable binding for field 'current'
throws a java.lang.ClassCastException:
org/eclipse/jdt/internal/core/ResolvedSourceField incompatible with
org/eclipse/jdt/core/IType
	at
org.eclipse.jdt.core.dom.VariableBinding.getUnresolvedJavaElement(VariableBinding.java:139)
	at
org.eclipse.jdt.core.dom.VariableBinding.getJavaElement(VariableBinding.java:128)

This bug is a problem for the Infer Type Arguments refactoring.
Comment 1 Dirk Baeumer CLA 2005-05-18 08:41:20 EDT
Philippe, can you please have a look. The bug is blocking Markus in Infer Type
Argument fixing...
Comment 2 Jerome Lanneluc CLA 2005-05-20 08:04:49 EDT
Reduced the test case to:
public class X {
	void foo() {
		new Y(0/*c*/) {
			Object field;
		};
	}
}
class Y {
	Y(int i) {
	}
}

Note that if you remove /*c*/, you get a ResolvedSourceType for the anonymous.
Comment 3 Jerome Lanneluc CLA 2005-05-20 08:53:56 EDT
Changed Parser#consumeAnonymousClassBody() to flush comments (as this is already
done for type headers.
Added regression test ASTModelBridgeTests#testAnonymous2()
Comment 4 David Audel CLA 2005-05-27 07:40:22 EDT
Verified in i20050527-0010