View | Details | Raw Unified | Return to bug 157814 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-7 / +7 lines)
Lines 28-33 Link Here
28
import org.eclipse.jdt.internal.core.SourceMethod;
28
import org.eclipse.jdt.internal.core.SourceMethod;
29
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
29
import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants;
30
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
30
import org.eclipse.jdt.internal.core.search.matching.MatchLocator;
31
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
31
import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern;
32
import org.eclipse.jdt.internal.core.search.matching.TypeDeclarationPattern;
32
33
33
/**
34
/**
Lines 7085-7109 Link Here
7085
		"	void validMatches(X x) {\n" + 
7086
		"	void validMatches(X x) {\n" + 
7086
		"		x.toString();\n" + 
7087
		"		x.toString();\n" + 
7087
		"	}\n" + 
7088
		"	}\n" + 
7088
		"	void polymorphicSuper(Object o) {\n" + 
7089
		"	void overriddenSuper(Object o) {\n" + 
7089
		"		o.toString();\n" + 
7090
		"		o.toString();\n" + 
7090
		"	}\n" + 
7091
		"	}\n" + 
7091
		"	void polymorphicPotential(I i) {\n" + 
7092
		"	void overriddenPotential(I i) {\n" + 
7092
		"		i.toString();\n" + 
7093
		"		i.toString();\n" + 
7093
		"	}\n" + 
7094
		"	}\n" + 
7094
		"	void polymorphicSub(Sub s) {\n" + 
7095
		"	void overriddenSub(Sub s) {\n" + 
7095
		"		s.toString();\n" + 
7096
		"		s.toString();\n" + 
7096
		"	}\n" + 
7097
		"	}\n" + 
7097
		"}\n"
7098
		"}\n"
7098
	);
7099
	);
7099
	IMethod method = workingCopies[1].getType("X").getMethod("toString", new String[0]);
7100
	IMethod method = workingCopies[1].getType("X").getMethod("toString", new String[0]);
7100
	this.resultCollector.showPolymorphic = 2;
7101
	this.resultCollector.showFlavors = PatternLocator.OVERRIDDEN_FLAVOR;
7101
	search(method, REFERENCES);
7102
	search(method, REFERENCES);
7102
	assertSearchResults(
7103
	assertSearchResults(
7103
		"src/pack/Test.java void pack.Test.validMatches(X) [toString()] EXACT_MATCH\n" + 
7104
		"src/pack/Test.java void pack.Test.validMatches(X) [toString()] EXACT_MATCH\n" + 
7104
		"src/pack/Test.java void pack.Test.polymorphicSuper(Object) [toString()] EXACT_MATCH POLYMORPHIC\n" + 
7105
		"src/pack/Test.java void pack.Test.overriddenSuper(Object) [toString()] EXACT_MATCH OVERRIDDEN\n" + 
7105
		"src/pack/Test.java void pack.Test.polymorphicPotential(I) [toString()] POTENTIAL_MATCH POLYMORPHIC\n" + 
7106
		"src/pack/Test.java void pack.Test.overriddenSub(Sub) [toString()] EXACT_MATCH"
7106
		"src/pack/Test.java void pack.Test.polymorphicSub(Sub) [toString()] EXACT_MATCH POLYMORPHIC"
7107
	);
7107
	);
7108
}
7108
}
7109
7109
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java (-14 / +10 lines)
Lines 25-30 Link Here
25
//import org.eclipse.jdt.internal.core.ResolvedSourceMethod;
25
//import org.eclipse.jdt.internal.core.ResolvedSourceMethod;
26
//import org.eclipse.jdt.internal.core.ResolvedSourceType;
26
//import org.eclipse.jdt.internal.core.ResolvedSourceType;
27
import org.eclipse.jdt.internal.core.SourceRefElement;
27
import org.eclipse.jdt.internal.core.SourceRefElement;
28
import org.eclipse.jdt.internal.core.search.matching.PatternLocator;
28
29
29
/**
30
/**
30
 * Abstract class for Java Search tests.
31
 * Abstract class for Java Search tests.
Lines 55-61 Link Here
55
		public boolean showPotential = true;
56
		public boolean showPotential = true;
56
		public boolean showProject;
57
		public boolean showProject;
57
		public boolean showSynthetic;
58
		public boolean showSynthetic;
58
		public int showPolymorphic = 0;
59
		public int showFlavors = 0;
59
		public int count = 0;
60
		public int count = 0;
60
		public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException {
61
		public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException {
61
			count++;
62
			count++;
Lines 214-232 Link Here
214
						}
215
						}
215
					}
216
					}
216
				}
217
				}
217
				if (match instanceof MethodReferenceMatch) {
218
				if (this.showFlavors > 0) {
218
					MethodReferenceMatch methRef = (MethodReferenceMatch) match;
219
					if (match instanceof MethodReferenceMatch) {
219
					if (methRef.isPolymorphic()) {
220
						MethodReferenceMatch methRef = (MethodReferenceMatch) match;
220
						if (match.getAccuracy() == SearchMatch.A_ACCURATE) {
221
						if (methRef.isOverridden() && showOverridden()) {
221
							if (this.showPolymorphic > 0) {
222
							line.append(" OVERRIDDEN");
222
								line.append(" POLYMORPHIC");
223
							}
224
						} else {
225
							if (this.showPolymorphic <= 1) {
226
								line = null; // do not show potential polymorphic matches
227
							} else {
228
								line.append(" POLYMORPHIC");
229
							}
230
						}
223
						}
231
					}
224
					}
232
				}
225
				}
Lines 235-240 Link Here
235
				results.append(e.toString());
228
				results.append(e.toString());
236
			}
229
			}
237
		}
230
		}
231
		private boolean showOverridden() {
232
			return (this.showFlavors & PatternLocator.OVERRIDDEN_FLAVOR) != 0;
233
		}
238
		protected void append(IField field) throws JavaModelException {
234
		protected void append(IField field) throws JavaModelException {
239
			append(field.getDeclaringType());
235
			append(field.getDeclaringType());
240
			line.append(".");
236
			line.append(".");
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-4 / +4 lines)
Lines 1401-1408 Link Here
1401
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1401
	boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0;
1402
	if (enclosingBinding != null)
1402
	if (enclosingBinding != null)
1403
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
1403
		enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding);
1404
	boolean isPolymorphic = (accuracy & PatternLocator.POLYMORPHIC_FLAVOR) != 0;
1404
	boolean isOverridden = (accuracy & PatternLocator.OVERRIDDEN_FLAVOR) != 0;
1405
	return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isPolymorphic, insideDocComment, participant, resource);
1405
	return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource);
1406
}
1406
}
1407
1407
1408
public SearchMatch newPackageReferenceMatch(
1408
public SearchMatch newPackageReferenceMatch(
Lines 1652-1659 Link Here
1652
		}
1652
		}
1653
		if (match instanceof MethodReferenceMatch) {
1653
		if (match instanceof MethodReferenceMatch) {
1654
			MethodReferenceMatch methodReferenceMatch = (MethodReferenceMatch) match;
1654
			MethodReferenceMatch methodReferenceMatch = (MethodReferenceMatch) match;
1655
			if (methodReferenceMatch.isPolymorphic()) {
1655
			if (methodReferenceMatch.isOverridden()) {
1656
				System.out.print("+POLYMORPHIC"); //$NON-NLS-1$
1656
				System.out.print("+OVERRIDDEN"); //$NON-NLS-1$
1657
			}
1657
			}
1658
			if (methodReferenceMatch.isImplicit()) {
1658
			if (methodReferenceMatch.isImplicit()) {
1659
				System.out.print("+IMPLICIT"); //$NON-NLS-1$
1659
				System.out.print("+IMPLICIT"); //$NON-NLS-1$
(-)search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java (-8 / +9 lines)
Lines 41-54 Link Here
41
41
42
// Possible rule match flavors
42
// Possible rule match flavors
43
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79866
43
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79866
44
protected static final int EXACT_FLAVOR = 0x0010;
44
public static final int EXACT_FLAVOR = 0x0010;
45
protected static final int PREFIX_FLAVOR = 0x0020;
45
public static final int PREFIX_FLAVOR = 0x0020;
46
protected static final int PATTERN_FLAVOR = 0x0040;
46
public static final int PATTERN_FLAVOR = 0x0040;
47
protected static final int REGEXP_FLAVOR = 0x0080;
47
public static final int REGEXP_FLAVOR = 0x0080;
48
protected static final int CAMELCASE_FLAVOR = 0x0100;
48
public static final int CAMELCASE_FLAVOR = 0x0100;
49
protected static final int POLYMORPHIC_FLAVOR = 0x0200;
49
public static final int OVERRIDDEN_FLAVOR = 0x0200;
50
protected static final int MATCH_LEVEL_MASK = 0x0F;
50
public static final int SUB_TYPE_FLAVOR = 0x0400;
51
protected static final int FLAVORS_MASK = ~MATCH_LEVEL_MASK;
51
public static final int MATCH_LEVEL_MASK = 0x0F;
52
public static final int FLAVORS_MASK = ~MATCH_LEVEL_MASK;
52
53
53
/* match container */
54
/* match container */
54
public static final int COMPILATION_UNIT_CONTAINER = 1;
55
public static final int COMPILATION_UNIT_CONTAINER = 1;
(-)search/org/eclipse/jdt/internal/core/search/matching/MethodLocator.java (-3 / +6 lines)
Lines 640-653 Link Here
640
				for (int i = 0, max = this.allSuperDeclaringTypeNames.length; i < max; i++) {
640
				for (int i = 0, max = this.allSuperDeclaringTypeNames.length; i < max; i++) {
641
					if (CharOperation.equals(this.allSuperDeclaringTypeNames[i], compoundName)) {
641
					if (CharOperation.equals(this.allSuperDeclaringTypeNames[i], compoundName)) {
642
						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
643
							| OVERRIDDEN_FLAVOR; // this is an overridden method => add flavor to returned level
644
					}
644
					}
645
				}
645
				}
646
				/* Do not return interfaces potential matches
647
				 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=157814#c8"
646
				if (methodReceiverType.isInterface()) {
648
				if (methodReceiverType.isInterface()) {
647
					// all methods interface with same name and parameters are potential matches
649
					// all methods interface with same name and parameters are potential matches
648
					// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
650
					// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491
649
					return INACCURATE_MATCH | POLYMORPHIC_FLAVOR;
651
					return INACCURATE_MATCH | POLYMORPHIC_FLAVOR;
650
				}
652
				}
653
				*/
651
			}
654
			}
652
		}
655
		}
653
		if ((declaringLevel & FLAVORS_MASK) != 0) {
656
		if ((declaringLevel & FLAVORS_MASK) != 0) {
Lines 675-681 Link Here
675
	// matches superclass
678
	// matches superclass
676
	if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
679
	if (!type.isInterface() && !CharOperation.equals(type.compoundName, TypeConstants.JAVA_LANG_OBJECT)) {
677
		level = resolveLevelAsSubtype(qualifiedPattern, type.superclass());
680
		level = resolveLevelAsSubtype(qualifiedPattern, type.superclass());
678
		if (level != IMPOSSIBLE_MATCH) return level | POLYMORPHIC_FLAVOR; // this is a polymorphic method => add flavor to returned level
681
		if (level != IMPOSSIBLE_MATCH) return level | SUB_TYPE_FLAVOR; // add flavor to returned level
679
	}
682
	}
680
683
681
	// matches interfaces
684
	// matches interfaces
Lines 683-689 Link Here
683
	if (interfaces == null) return INACCURATE_MATCH;
686
	if (interfaces == null) return INACCURATE_MATCH;
684
	for (int i = 0; i < interfaces.length; i++) {
687
	for (int i = 0; i < interfaces.length; i++) {
685
		level = resolveLevelAsSubtype(qualifiedPattern, interfaces[i]);
688
		level = resolveLevelAsSubtype(qualifiedPattern, interfaces[i]);
686
		if (level != IMPOSSIBLE_MATCH) return level | POLYMORPHIC_FLAVOR; // this is a polymorphic method => add flavor to returned level
689
		if (level != IMPOSSIBLE_MATCH) return level | SUB_TYPE_FLAVOR; // add flavor to returned level
687
	}
690
	}
688
	return IMPOSSIBLE_MATCH;
691
	return IMPOSSIBLE_MATCH;
689
}
692
}
(-)buildnotes_jdt-core.html (-1 / +3 lines)
Lines 68-74 Link Here
68
</ul>
68
</ul>
69
69
70
<h3>Problem Reports Fixed</h3>
70
<h3>Problem Reports Fixed</h3>
71
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=148380">148380</a>
71
<a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=157814">157814</a>
72
[search] polymorphic matches in supertype hierarchy should be marked as potential
73
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=148380">148380</a>
72
[search] get IType from TypeNameRequestor result
74
[search] get IType from TypeNameRequestor result
73
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160025">160025</a>
75
<br><a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=160025">160025</a>
74
CharOperation fails with AIOOBE when replaced array contains the same chars
76
CharOperation fails with AIOOBE when replaced array contains the same chars
(-)search/org/eclipse/jdt/core/search/MethodReferenceMatch.java (-11 / +12 lines)
Lines 25-31 Link Here
25
public class MethodReferenceMatch extends SearchMatch {
25
public class MethodReferenceMatch extends SearchMatch {
26
	private boolean constructor;
26
	private boolean constructor;
27
	private boolean synthetic;
27
	private boolean synthetic;
28
	private boolean polymorphic;
28
	private boolean overridden;
29
29
30
	/**
30
	/**
31
	 * Creates a new method reference match.
31
	 * Creates a new method reference match.
Lines 78-84 Link Here
78
	 * <code>false</code> otherwise
78
	 * <code>false</code> otherwise
79
	 * @param synthetic <code>true</code> if this search matches a synthetic element
79
	 * @param synthetic <code>true</code> if this search matches a synthetic element
80
	 * <code>false</code> otherwise
80
	 * <code>false</code> otherwise
81
	 * @param polymorphic <code>true</code> if this search matches a polymorphic element
81
	 * @param overridden <code>true</code> if this search matches a polymorphic element
82
	 * <code>false</code> otherwise
82
	 * <code>false</code> otherwise
83
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
83
	 * @param insideDocComment <code>true</code> if this search match is inside a doc
84
	 * comment, and <code>false</code> otherwise
84
	 * comment, and <code>false</code> otherwise
Lines 86-94 Link Here
86
	 * @param resource the resource of the element
86
	 * @param resource the resource of the element
87
	 * @since 3.3
87
	 * @since 3.3
88
	 */
88
	 */
89
	public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean polymorphic, boolean insideDocComment, SearchParticipant participant, IResource resource) {
89
	public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean overridden, boolean insideDocComment, SearchParticipant participant, IResource resource) {
90
		this(enclosingElement, accuracy, offset, length, constructor, synthetic, insideDocComment, participant, resource);
90
		this(enclosingElement, accuracy, offset, length, constructor, synthetic, insideDocComment, participant, resource);
91
		this.polymorphic = polymorphic;
91
		this.overridden = overridden;
92
	}
92
	}
93
93
94
	/**
94
	/**
Lines 114-127 Link Here
114
	}
114
	}
115
115
116
	/**
116
	/**
117
	 * Returns whether the reference is on a polymorphic method or not.
117
	 * Returns whether the reference is on a method that is overridden by the
118
	 * Note that this field is only used for method reference. This happens when the reference
118
	 * search target or not. If <code>true</code>, the method called at run-time
119
	 * is not implemented on the declaring class pattern but only on one of its super or sub type.
119
	 * may or may not be the search target, depending on the run-time type
120
	 * of the receiver object.
120
	 * 
121
	 * 
121
	 * @return <code>true</code> if the reference is a polymorphic method or not,
122
	 * @return <code>true</code> if the reference is on a method that is
122
	 * <code>false </code> otherwise
123
	 * overridden by the search target, <code>false </code> otherwise
123
	 */
124
	 */
124
	public boolean isPolymorphic() {
125
	public boolean isOverridden() {
125
		return this.polymorphic;
126
		return this.overridden;
126
	}
127
	}
127
}
128
}

Return to bug 157814