Lines 22-27
Link Here
|
22 |
import org.eclipse.jdt.internal.compiler.lookup.*; |
22 |
import org.eclipse.jdt.internal.compiler.lookup.*; |
23 |
import org.eclipse.jdt.internal.compiler.util.SimpleSet; |
23 |
import org.eclipse.jdt.internal.compiler.util.SimpleSet; |
24 |
import org.eclipse.jdt.internal.core.JavaElement; |
24 |
import org.eclipse.jdt.internal.core.JavaElement; |
|
|
25 |
import org.eclipse.jdt.internal.core.search.BasicSearchEngine; |
25 |
|
26 |
|
26 |
public class MethodLocator extends PatternLocator { |
27 |
public class MethodLocator extends PatternLocator { |
27 |
|
28 |
|
Lines 47-52
Link Here
|
47 |
this.methodDeclarationsWithInvalidParam = new HashMap(); |
48 |
this.methodDeclarationsWithInvalidParam = new HashMap(); |
48 |
} |
49 |
} |
49 |
public void initializePolymorphicSearch(MatchLocator locator) { |
50 |
public void initializePolymorphicSearch(MatchLocator locator) { |
|
|
51 |
long start = 0; |
52 |
if (BasicSearchEngine.VERBOSE) { |
53 |
start = System.currentTimeMillis(); |
54 |
} |
50 |
try { |
55 |
try { |
51 |
this.allSuperDeclaringTypeNames = |
56 |
this.allSuperDeclaringTypeNames = |
52 |
new SuperTypeNamesCollector( |
57 |
new SuperTypeNamesCollector( |
Lines 59-64
Link Here
|
59 |
} catch (JavaModelException e) { |
64 |
} catch (JavaModelException e) { |
60 |
// inaccurate matches will be found |
65 |
// inaccurate matches will be found |
61 |
} |
66 |
} |
|
|
67 |
if (BasicSearchEngine.VERBOSE) { |
68 |
System.out.println("Time to initialize polymorphic search: "+(System.currentTimeMillis()-start)); //$NON-NLS-1$ |
69 |
} |
62 |
} |
70 |
} |
63 |
/* |
71 |
/* |
64 |
* Return whether a type name is in pattern all super declaring types names. |
72 |
* Return whether a type name is in pattern all super declaring types names. |
Lines 621-638
Link Here
|
621 |
if (qualifiedPattern == null) return methodLevel; // since any declaring class will do |
629 |
if (qualifiedPattern == null) return methodLevel; // since any declaring class will do |
622 |
|
630 |
|
623 |
int declaringLevel; |
631 |
int declaringLevel; |
624 |
if (isVirtualInvoke(method, messageSend) && !(messageSend.actualReceiverType instanceof ArrayBinding)) { |
632 |
if (isVirtualInvoke(method, messageSend) && (messageSend.actualReceiverType instanceof ReferenceBinding)) { |
625 |
declaringLevel = resolveLevelAsSubtype(qualifiedPattern, method.declaringClass); |
633 |
ReferenceBinding methodReceiverType = (ReferenceBinding) messageSend.actualReceiverType; |
|
|
634 |
declaringLevel = resolveLevelAsSubtype(qualifiedPattern, methodReceiverType); |
626 |
if (declaringLevel == IMPOSSIBLE_MATCH) { |
635 |
if (declaringLevel == IMPOSSIBLE_MATCH) { |
627 |
if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) { |
636 |
if (method.declaringClass == null || this.allSuperDeclaringTypeNames == null) { |
628 |
declaringLevel = INACCURATE_MATCH; |
637 |
declaringLevel = INACCURATE_MATCH; |
629 |
} else { |
638 |
} else { |
630 |
char[][] compoundName = method.declaringClass.compoundName; |
639 |
char[][] compoundName = methodReceiverType.compoundName; |
631 |
for (int i = 0, max = this.allSuperDeclaringTypeNames.length; i < max; i++) |
640 |
for (int i = 0, max = this.allSuperDeclaringTypeNames.length; i < max; i++) { |
632 |
if (CharOperation.equals(this.allSuperDeclaringTypeNames[i], compoundName)) |
641 |
if (CharOperation.equals(this.allSuperDeclaringTypeNames[i], compoundName)) { |
633 |
return methodLevel; // since this is an ACCURATE_MATCH so return the possibly weaker match |
642 |
return methodLevel // since this is an ACCURATE_MATCH so return the possibly weaker match |
|
|
643 |
| POLYMORPHIC_FLAVOR; // this is a polymorphic method => add flavor to returned level |
644 |
} |
645 |
} |
646 |
if (methodReceiverType.isInterface()) { |
647 |
// all methods interface with same name and parameters are potential matches |
648 |
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491 |
649 |
return INACCURATE_MATCH | POLYMORPHIC_FLAVOR; |
650 |
} |
634 |
} |
651 |
} |
635 |
} |
652 |
} |
|
|
653 |
if ((declaringLevel & FLAVORS_MASK) != 0) { |
654 |
// level got some flavors => return it |
655 |
return declaringLevel; |
656 |
} |
636 |
} else { |
657 |
} else { |
637 |
declaringLevel = resolveLevelForType(qualifiedPattern, method.declaringClass); |
658 |
declaringLevel = resolveLevelForType(qualifiedPattern, method.declaringClass); |
638 |
} |
659 |
} |
Lines 654-660
Link Here
|
654 |
// matches superclass |
675 |
// matches superclass |
655 |
if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { |
676 |
if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) { |
656 |
level = resolveLevelAsSubtype(qualifiedPattern, type.superclass()); |
677 |
level = resolveLevelAsSubtype(qualifiedPattern, type.superclass()); |
657 |
if (level != IMPOSSIBLE_MATCH) return level; |
678 |
if (level != IMPOSSIBLE_MATCH) return level | POLYMORPHIC_FLAVOR; // this is a polymorphic method => add flavor to returned level |
658 |
} |
679 |
} |
659 |
|
680 |
|
660 |
// matches interfaces |
681 |
// matches interfaces |
Lines 662-668
Link Here
|
662 |
if (interfaces == null) return INACCURATE_MATCH; |
683 |
if (interfaces == null) return INACCURATE_MATCH; |
663 |
for (int i = 0; i < interfaces.length; i++) { |
684 |
for (int i = 0; i < interfaces.length; i++) { |
664 |
level = resolveLevelAsSubtype(qualifiedPattern, interfaces[i]); |
685 |
level = resolveLevelAsSubtype(qualifiedPattern, interfaces[i]); |
665 |
if (level != IMPOSSIBLE_MATCH) return level; |
686 |
if (level != IMPOSSIBLE_MATCH) return level | POLYMORPHIC_FLAVOR; // this is a polymorphic method => add flavor to returned level |
666 |
} |
687 |
} |
667 |
return IMPOSSIBLE_MATCH; |
688 |
return IMPOSSIBLE_MATCH; |
668 |
} |
689 |
} |