### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.84 diff -u -r1.84 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 7 Sep 2006 12:59:41 -0000 1.84 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 14 Sep 2006 16:52:50 -0000 @@ -55,7 +55,6 @@ } } class TypeReferencesCollector extends JavaSearchResultCollector { - protected IJavaElement getElement(SearchMatch searchMatch) { IJavaElement element = super.getElement(searchMatch); IJavaElement localElement = null; @@ -6896,4 +6895,67 @@ "b156177.B156177_I", requestor); } + +/** + * Bug 156491: [1.5][search] interfaces and annotations could be found with only one requets of searchAllTypeName + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=156491" + */ +public void testBug156491() throws CoreException { + resultCollector.showRule = true; + workingCopies = new ICompilationUnit[5]; + workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/pack/I.java", + "package pack;\n" + + "public interface I {}\n" + ); + workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/pack/X.java", + "package pack;\n" + + "public class X {\n" + + " public String toString() {\n" + + " return \"X\";\n" + + " }\n" + + "}\n" + ); + workingCopies[2] = getWorkingCopy("/JavaSearchBugs/src/pack/Sub.java", + "package pack;\n" + + "public class Sub extends X {}\n" + ); + workingCopies[3] = getWorkingCopy("/JavaSearchBugs/src/pack/Y.java", + "package pack;\n" + + "public class Y {\n" + + " public String toString() {\n" + + " return \"Y\";\n" + + " }\n" + + "}\n" + ); + workingCopies[4] = getWorkingCopy("/JavaSearchBugs/src/pack/Test.java", + "package pack;\n" + + "public class Test {\n" + + " void noMatch(Y y) {\n" + + " y.toString();\n" + + " toString();\n" + + " }\n" + + " void validMatches(X x) {\n" + + " x.toString();\n" + + " }\n" + + " void polymorphicSuper(Object o) {\n" + + " o.toString();\n" + + " }\n" + + " void polymorphicPotential(I i) {\n" + + " i.toString();\n" + + " }\n" + + " void polymorphicSub(Sub s) {\n" + + " s.toString();\n" + + " }\n" + + "}\n" + ); + IMethod method = workingCopies[1].getType("X").getMethod("toString", new String[0]); + this.resultCollector.showPolymorphic = 2; + search(method, REFERENCES); + assertSearchResults( + "src/pack/Test.java void pack.Test.validMatches(X) [toString()] EXACT_MATCH\n" + + "src/pack/Test.java void pack.Test.polymorphicSuper(Object) [toString()] EXACT_MATCH POLYMORPHIC\n" + + "src/pack/Test.java void pack.Test.polymorphicPotential(I) [toString()] POTENTIAL_MATCH POLYMORPHIC\n" + + "src/pack/Test.java void pack.Test.polymorphicSub(Sub) [toString()] EXACT_MATCH POLYMORPHIC" + ); +} } \ No newline at end of file Index: src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java,v retrieving revision 1.17 diff -u -r1.17 AbstractJavaSearchTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java 29 Mar 2006 04:03:07 -0000 1.17 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java 14 Sep 2006 16:52:46 -0000 @@ -55,12 +55,15 @@ public boolean showPotential = true; public boolean showProject; public boolean showSynthetic; + public int showPolymorphic = 0; public int count = 0; public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException { count++; this.match = searchMatch; writeLine(); - writeLineToResult(); + if (line != null) { + writeLineToResult(); + } } protected void writeLineToResult() { if (match.getAccuracy() == SearchMatch.A_ACCURATE || showPotential) { @@ -211,6 +214,22 @@ } } } + if (match instanceof MethodReferenceMatch) { + MethodReferenceMatch methRef = (MethodReferenceMatch) match; + if (methRef.isPolymorphic()) { + if (match.getAccuracy() == SearchMatch.A_ACCURATE) { + if (this.showPolymorphic > 0) { + line.append(" POLYMORPHIC"); + } + } else { + if (this.showPolymorphic <= 1) { + line = null; // do not show potential polymorphic matches + } else { + line.append(" POLYMORPHIC"); + } + } + } + } } catch (JavaModelException e) { results.append("\n"); results.append(e.toString()); #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/search/matching/MatchingNodeSet.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchingNodeSet.java,v retrieving revision 1.34 diff -u -r1.34 MatchingNodeSet.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchingNodeSet.java 10 May 2006 18:03:43 -0000 1.34 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchingNodeSet.java 14 Sep 2006 16:52:56 -0000 @@ -54,18 +54,32 @@ } public int addMatch(ASTNode node, int matchLevel) { - switch (matchLevel & PatternLocator.NODE_SET_MASK) { + int maskedLevel = matchLevel & PatternLocator.MATCH_LEVEL_MASK; + switch (maskedLevel) { case PatternLocator.INACCURATE_MATCH: - addTrustedMatch(node, POTENTIAL_MATCH); + if (matchLevel != maskedLevel) { + addTrustedMatch(node, new Integer(SearchMatch.A_INACCURATE+(matchLevel & PatternLocator.FLAVORS_MASK))); + } else { + addTrustedMatch(node, POTENTIAL_MATCH); + } break; case PatternLocator.POSSIBLE_MATCH: addPossibleMatch(node); break; case PatternLocator.ERASURE_MATCH: - addTrustedMatch(node, ERASURE_MATCH); + if (matchLevel != maskedLevel) { + addTrustedMatch(node, new Integer(SearchPattern.R_ERASURE_MATCH+(matchLevel & PatternLocator.FLAVORS_MASK))); + } else { + addTrustedMatch(node, ERASURE_MATCH); + } break; case PatternLocator.ACCURATE_MATCH: - addTrustedMatch(node, EXACT_MATCH); + if (matchLevel != maskedLevel) { + addTrustedMatch(node, new Integer(SearchMatch.A_ACCURATE+(matchLevel & PatternLocator.FLAVORS_MASK))); + } else { + addTrustedMatch(node, EXACT_MATCH); + } + break; } return matchLevel; } Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java,v retrieving revision 1.279 diff -u -r1.279 MatchLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 7 Sep 2006 07:27:16 -0000 1.279 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java 14 Sep 2006 16:52:55 -0000 @@ -1401,7 +1401,8 @@ boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0; if (enclosingBinding != null) enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); - return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, insideDocComment, participant, resource); + boolean isPolymorphic = (accuracy & PatternLocator.POLYMORPHIC_FLAVOR) != 0; + return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isPolymorphic, insideDocComment, participant, resource); } public SearchMatch newPackageReferenceMatch( @@ -1641,15 +1642,27 @@ : "\tAccuracy: POTENTIAL_MATCH"); //$NON-NLS-1$ System.out.print("\tRule: "); //$NON-NLS-1$ if (match.isExact()) { - System.out.println("EXACT"); //$NON-NLS-1$ + System.out.print("EXACT"); //$NON-NLS-1$ } else if (match.isEquivalent()) { - System.out.println("EQUIVALENT"); //$NON-NLS-1$ + System.out.print("EQUIVALENT"); //$NON-NLS-1$ } else if (match.isErasure()) { - System.out.println("ERASURE"); //$NON-NLS-1$ + System.out.print("ERASURE"); //$NON-NLS-1$ } else { - System.out.println("INVALID RULE"); //$NON-NLS-1$ + System.out.print("INVALID RULE"); //$NON-NLS-1$ } - System.out.println("\tRaw: "+match.isRaw()); //$NON-NLS-1$ + if (match instanceof MethodReferenceMatch) { + MethodReferenceMatch methodReferenceMatch = (MethodReferenceMatch) match; + if (methodReferenceMatch.isPolymorphic()) { + System.out.print("+POLYMORPHIC"); //$NON-NLS-1$ + } + if (methodReferenceMatch.isImplicit()) { + System.out.print("+IMPLICIT"); //$NON-NLS-1$ + } + if (methodReferenceMatch.isSynthetic()) { + System.out.print("+SYNTHETIC"); //$NON-NLS-1$ + } + } + System.out.println("\n\tRaw: "+match.isRaw()); //$NON-NLS-1$ } this.requestor.acceptSearchMatch(match); if (BasicSearchEngine.VERBOSE) Index: search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java,v retrieving revision 1.59 diff -u -r1.59 PatternLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java 3 Aug 2006 17:23:54 -0000 1.59 +++ search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java 14 Sep 2006 16:52:56 -0000 @@ -41,13 +41,14 @@ // Possible rule match flavors // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79866 -protected static final int POSSIBLE_FULL_MATCH = POSSIBLE_MATCH | (SearchPattern.R_FULL_MATCH<<16); -protected static final int POSSIBLE_PREFIX_MATCH = POSSIBLE_MATCH | (SearchPattern.R_PREFIX_MATCH<<16); -protected static final int POSSIBLE_PATTERN_MATCH = POSSIBLE_MATCH | (SearchPattern.R_PATTERN_MATCH<<16); -protected static final int POSSIBLE_REGEXP_MATCH = POSSIBLE_MATCH | (SearchPattern.R_REGEXP_MATCH<<16); -protected static final int POSSIBLE_CAMELCASE_MATCH = POSSIBLE_MATCH | (SearchPattern.R_CAMELCASE_MATCH<<16); -protected static final int NODE_SET_MASK = 0xFF; -protected static final int POSSIBLE_MATCH_MASK = ~NODE_SET_MASK; +protected static final int EXACT_FLAVOR = 0x0010; +protected static final int PREFIX_FLAVOR = 0x0020; +protected static final int PATTERN_FLAVOR = 0x0040; +protected static final int REGEXP_FLAVOR = 0x0080; +protected static final int CAMELCASE_FLAVOR = 0x0100; +protected static final int POLYMORPHIC_FLAVOR = 0x0200; +protected static final int MATCH_LEVEL_MASK = 0x0F; +protected static final int FLAVORS_MASK = ~MATCH_LEVEL_MASK; /* match container */ public static final int COMPILATION_UNIT_CONTAINER = 1; @@ -251,10 +252,16 @@ * @param name * @return Possible values are: *
true
if this search matches a constructor
+ * false
otherwise
+ * @param synthetic true
if this search matches a synthetic element
+ * false
otherwise
+ * @param polymorphic true
if this search matches a polymorphic element
+ * false
otherwise
+ * @param insideDocComment true
if this search match is inside a doc
+ * comment, and false
otherwise
+ * @param participant the search participant that created the match
+ * @param resource the resource of the element
+ * @since 3.3
+ */
+ public MethodReferenceMatch(IJavaElement enclosingElement, int accuracy, int offset, int length, boolean constructor, boolean synthetic, boolean polymorphic, boolean insideDocComment, SearchParticipant participant, IResource resource) {
+ this(enclosingElement, accuracy, offset, length, constructor, synthetic, insideDocComment, participant, resource);
+ this.polymorphic = polymorphic;
+ }
+
+ /**
* Returns whether the reference is on a constructor.
*
* @return Returns whether the reference is on a constructor or not.
@@ -87,4 +112,16 @@
public final boolean isSynthetic() {
return this.synthetic;
}
+
+ /**
+ * Returns whether the reference is on a polymorphic method or not.
+ * Note that this field is only used for method reference. This happens when the reference
+ * is not implemented on the declaring class pattern but only on one of its superclass or subclass.
+ *
+ * @return true
if the reference is a polymorphic method or not,
+ * false
otherwise
+ */
+ public boolean isPolymorphic() {
+ return this.polymorphic;
+ }
}
Index: search/org/eclipse/jdt/core/search/SearchMatch.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchMatch.java,v
retrieving revision 1.28
diff -u -r1.28 SearchMatch.java
--- search/org/eclipse/jdt/core/search/SearchMatch.java 10 May 2006 18:03:46 -0000 1.28
+++ search/org/eclipse/jdt/core/search/SearchMatch.java 14 Sep 2006 16:52:54 -0000
@@ -57,9 +57,10 @@
private boolean insideDocComment = false;
// store the rule used while reporting the match
- private int rule = SearchPattern.R_FULL_MATCH |
+ private final static int ALL_GENERIC_FLAVORS = SearchPattern.R_FULL_MATCH |
SearchPattern.R_EQUIVALENT_MATCH |
SearchPattern.R_ERASURE_MATCH;
+ private int rule = ALL_GENERIC_FLAVORS;
// store other necessary information
private boolean raw = false;
@@ -91,7 +92,11 @@
this.length = length;
this.accuracy = accuracy & A_INACCURATE;
if (accuracy > A_INACCURATE) {
- this.rule = accuracy & ~A_INACCURATE; // accuracy may have also some rule information
+ int genericFlavors = accuracy & ALL_GENERIC_FLAVORS;
+ if (genericFlavors > 0) {
+ this.rule &= ~ALL_GENERIC_FLAVORS; // reset generic flavors
+ }
+ this.rule |= accuracy & ~A_INACCURATE; // accuracy may have also some rule information
}
this.participant = participant;
this.resource = resource;
Index: buildnotes_jdt-core.html
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/buildnotes_jdt-core.html,v
retrieving revision 1.5406
diff -u -r1.5406 buildnotes_jdt-core.html
--- buildnotes_jdt-core.html 14 Sep 2006 03:04:29 -0000 1.5406
+++ buildnotes_jdt-core.html 14 Sep 2006 16:52:54 -0000
@@ -52,10 +52,33 @@
(cvs).
isPolymorphic()
getters to MethodReferenceMatch.
+SearchRequestor
) accepts this kind of match,
+it knows if a method reference match is a polymorphic method (ie. implemented in a superclass or a subclass) or not.
++public class X { + public String toString() {} +} +public class Test { + void foo(Object o) { + o.toString(); + } +} ++Searching for reference to
X.toString()
method will get a polymorphic MethodReferenceMatch
+as the reference is the Object.toString() method (found in a superclass of X)...
+