Community
Participate
Working Groups
Build I20040824: Searching method declaration references does not work with classes having type parameters. Stack trace: java.lang.ClassCastException: org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding at org.eclipse.jdt.internal.core.search.matching.MethodLocator.reportDeclaration (MethodLocator.java:192) at org.eclipse.jdt.internal.core.search.matching.MethodLocator.matchReportReferenc e(MethodLocator.java:154) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching (MatchLocator.java:1408) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching (MatchLocator.java:1643) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.reportMatching (MatchLocator.java:1498) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.process (MatchLocator.java:1162) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches (MatchLocator.java:766) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches (MatchLocator.java:805) at org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches (MatchLocator.java:921) at org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches (JavaSearchParticipant.java:94) at org.eclipse.jdt.core.search.SearchEngine.searchDeclarations (SearchEngine.java:1066) at org.eclipse.jdt.core.search.SearchEngine.searchDeclarationsOfSentMessages (SearchEngine.java:1300) at org.eclipse.jdt.internal.corext.refactoring.structure.ReferenceFinderUtil.getMe thodReferencesIn(ReferenceFinderUtil.java:112) at org.eclipse.jdt.internal.corext.refactoring.structure.ReferenceFinderUtil.getMe thodReferencesIn(ReferenceFinderUtil.java:104) at org.eclipse.jdt.internal.corext.refactoring.structure.ReferenceFinderUtil.getMe thodsReferencedIn(ReferenceFinderUtil.java:95) aso.
I tried some cases & they worked fine for me. Do you have a testcase that fails?
The problem only occurs with the new 1.5 implementation of the push down/pull up refactoring which has not been released yet. I was hoping that the error could be understood based on the stack trace. After some investigation, I am now able to give some more information: The problem occurs if parameterized type bindings occur. Consider a generic class A<T> with a method "public void bar(){}" and a class B<R> which extends A and has a method "public void foo(){super.bar()}" Calling org.eclipse.jdt.internal.corext.refactoring.structure.ReferenceFinderUtil.getMe thodsReferencedIn(IJavaElement[],IProgressMonitor) with a java element array containing the java element corresponding to B#foo yields the class cast exception in MethodLocator, line 192 (see stack trace) Variable "declaringClass" is a parameterized type binding which does not extend source type bindings. Therefore the exception.
But when you construct your case, you can find references to the method foo() without any problems... so the problem is likely in the way the refactoring code is calling the SearchEngine. I'll look into protecting ourselves against this, but you should look into how you call the SearchEngine.
I can duplicate this now with the existing 'push down' code... I'll look into it further.
Fixed. We now protect the 3 places where he expect SourceTypeBindings. If a Parameterized or Raw type shows up, we'll extract the SourceTypeBinding.
Verified in I200409240100.