### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/search/matching/AndLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/AndLocator.java,v retrieving revision 1.4 diff -u -r1.4 AndLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/AndLocator.java 24 Jun 2008 15:23:48 -0000 1.4 +++ search/org/eclipse/jdt/internal/core/search/matching/AndLocator.java 3 Sep 2010 11:27:51 -0000 @@ -255,4 +255,13 @@ } return level; } +/* (non-Javadoc) + * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#setFlavors(int) + */ +void setFlavors(int flavors) { + for (int i = 0, length = this.patternLocators.length; i < length; i++) { + this.patternLocators[i].setFlavors(flavors); + } +} + } Index: search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java,v retrieving revision 1.87 diff -u -r1.87 MatchLocatorParser.java --- search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java 11 May 2010 18:47:10 -0000 1.87 +++ search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java 3 Sep 2010 11:27:51 -0000 @@ -256,11 +256,13 @@ } protected void consumeClassHeaderExtends() { + this.patternLocator.setFlavors(PatternLocator.SUPERTYPE_REF_FLAVOR); super.consumeClassHeaderExtends(); if ((this.patternFineGrain & IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE) != 0) { TypeDeclaration typeDeclaration = (TypeDeclaration) this.astStack[this.astPtr]; this.patternLocator.match(typeDeclaration.superclass, this.nodeSet); } + this.patternLocator.setFlavors(PatternLocator.NO_FLAVOR); } protected void consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() { @@ -283,6 +285,12 @@ } } +protected void consumeEnterAnonymousClassBody(boolean qualified) { + this.patternLocator.setFlavors(PatternLocator.SUPERTYPE_REF_FLAVOR); + super.consumeEnterAnonymousClassBody(qualified); + this.patternLocator.setFlavors(PatternLocator.NO_FLAVOR); +} + protected void consumeEnterVariable() { boolean isLocalDeclaration = this.nestedMethod[this.nestedType] != 0; super.consumeEnterVariable(); @@ -337,11 +345,13 @@ } } protected void consumeInterfaceType() { + this.patternLocator.setFlavors(PatternLocator.SUPERTYPE_REF_FLAVOR); super.consumeInterfaceType(); if ((this.patternFineGrain & IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE) != 0) { TypeReference typeReference = (TypeReference) this.astStack[this.astPtr]; this.patternLocator.match(typeReference, this.nodeSet); } + this.patternLocator.setFlavors(PatternLocator.NO_FLAVOR); } protected void consumeLocalVariableDeclaration() { Index: search/org/eclipse/jdt/internal/core/search/matching/OrLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/OrLocator.java,v retrieving revision 1.23 diff -u -r1.23 OrLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/OrLocator.java 24 Jun 2008 15:23:48 -0000 1.23 +++ search/org/eclipse/jdt/internal/core/search/matching/OrLocator.java 3 Sep 2010 11:27:51 -0000 @@ -307,4 +307,13 @@ } return level; } +/* (non-Javadoc) + * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#setFlavors(int) + */ +void setFlavors(int flavors) { + for (int i = 0, length = this.patternLocators.length; i < length; i++) { + this.patternLocators[i].setFlavors(flavors); + } +} + } 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.78 diff -u -r1.78 PatternLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java 20 May 2010 14:12:00 -0000 1.78 +++ search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java 3 Sep 2010 11:27:51 -0000 @@ -39,7 +39,9 @@ public static final int ERASURE_MATCH = 4; // Possible rule match flavors +int flavors = 0; // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79866 +public static final int NO_FLAVOR = 0x0000; public static final int EXACT_FLAVOR = 0x0010; public static final int PREFIX_FLAVOR = 0x0020; public static final int PATTERN_FLAVOR = 0x0040; @@ -48,6 +50,7 @@ public static final int SUPER_INVOCATION_FLAVOR = 0x0200; public static final int SUB_INVOCATION_FLAVOR = 0x0400; public static final int OVERRIDDEN_METHOD_FLAVOR = 0x0800; +public static final int SUPERTYPE_REF_FLAVOR = 0x1000; public static final int MATCH_LEVEL_MASK = 0x0F; public static final int FLAVORS_MASK = ~MATCH_LEVEL_MASK; @@ -436,6 +439,17 @@ // need to do instance of checks to find out exact type of ASTNode return IMPOSSIBLE_MATCH; } +/** + * Set the flavors for which the locator has to be focused on. + * If not set, the locator will accept all matches with or without flavors. + * When set, the locator will only accept match having the corresponding flavors. + * + * @param flavors Bits mask specifying the flavors to be accepted or + * 0 to ignore the flavors while accepting matches. + */ +void setFlavors(int flavors) { + this.flavors = flavors; +} /* * Update pattern locator match for parameterized top level types. * Set match raw flag and recurse to enclosing types if any... Index: search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java,v retrieving revision 1.18 diff -u -r1.18 SuperTypeReferenceLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java 18 Sep 2008 15:24:57 -0000 1.18 +++ search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java 3 Sep 2010 11:27:51 -0000 @@ -34,6 +34,7 @@ //public int match(Reference node, MatchingNodeSet nodeSet) - SKIP IT //public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT public int match(TypeReference node, MatchingNodeSet nodeSet) { + if (this.flavors != SUPERTYPE_REF_FLAVOR) return IMPOSSIBLE_MATCH; if (this.pattern.superSimpleName == null) return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); #P org.eclipse.jdt.core.tests.model 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.40 diff -u -r1.40 AbstractJavaSearchTests.java --- src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java 25 Nov 2009 12:26:50 -0000 1.40 +++ src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java 3 Sep 2010 11:27:53 -0000 @@ -42,10 +42,10 @@ public static List JAVA_SEARCH_SUITES = null; protected static IJavaProject JAVA_PROJECT; protected static boolean COPY_DIRS = true; - protected static int EXACT_RULE = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; - protected static int EQUIVALENT_RULE = EXACT_RULE | SearchPattern.R_EQUIVALENT_MATCH; - protected static int ERASURE_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH; - protected static int RAW_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH | SearchPattern.R_EQUIVALENT_MATCH; + protected final static int EXACT_RULE = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; + protected final static int EQUIVALENT_RULE = EXACT_RULE | SearchPattern.R_EQUIVALENT_MATCH; + protected final static int ERASURE_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH; + protected final static int RAW_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH | SearchPattern.R_EQUIVALENT_MATCH; // ICompilationUnit[] workingCopies; // boolean discard; 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.205 diff -u -r1.205 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 2 Sep 2010 09:00:25 -0000 1.205 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 3 Sep 2010 11:27:54 -0000 @@ -12073,6 +12073,246 @@ } /** + * @bug 322979: [search] use of IJavaSearchConstants.IMPLEMENTORS yields surprising results + * @test search of implementors does no longer report matches in type arguments + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=322979" + */ +public void testBug322979a() throws CoreException { + try + { + IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); + createFile("/P/Test.java", + "public class Test extends Object implements Comparable{\n"+ + "public int compareTo(Object o) {\n"+ + "return 0;\n"+ + "}\n"+ + "}\n"); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + this.resultCollector.showAccuracy(true); + this.resultCollector.showSelection(); + search("Object", TYPE, IMPLEMENTORS, scope); + assertSearchResults( + "Test.java Test [public class Test extends !|Object|! implements Comparable{] EXACT_MATCH" + ); + } finally { + deleteProject("P"); + } +} + +public void testBug322979b() throws CoreException { + try + { + IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); + createFile("/P/Test.java", + "public class Test extends java.lang.Object implements Comparable{\n"+ + "public int compareTo(Object o) {\n"+ + "return 0;\n"+ + "}\n"+ + "}\n"); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + IType type = getClassFile("P", getExternalJCLPathString("1.5"), "java.lang", "Object.class").getType(); + this.resultCollector.showAccuracy(true); + this.resultCollector.showSelection(); + search(type, IMPLEMENTORS, scope); + assertSearchResults( + "Test.java Test [public class Test extends !|java.lang.Object|! implements Comparable{] EXACT_MATCH" + ); + } finally { + deleteProject("P"); + } +} + +public void testBug322979c() throws CoreException { + try + { + IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); + createFile("/P/Test.java", + "public class Test extends Object implements I01a, I01b, I01c {\n" + + "}\n" + + "interface I01a {}\n" + + "interface I01b {}\n" + + "interface I01c {}\n" + ); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + this.resultCollector.showSelection(); + search("java.lang.Object", TYPE, IMPLEMENTORS, scope); + assertSearchResults( + "Test.java Test [public class Test extends !|Object|! implements I01a, I01b, I01c {] EXACT_MATCH" + ); + } finally { + deleteProject("P"); + } +} + +public void testBug322979d() throws CoreException { + try + { + IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); + createFile("/P/Test.java", + "public class Test extends Object implements I01<\n" + + " I02<\n" + + " I03>,\n" + + " I03, I02>>\n" + + " >,\n" + + " I01>> {\n" + + "}\n" + + "interface I01 {}\n" + + "interface I02 {}\n" + + "interface I03 {}\n" + ); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + this.resultCollector.showSelection(); + search("Object", TYPE, IMPLEMENTORS, scope); + assertSearchResults( + "Test.java Test [public class Test extends !|Object|! implements I01<] EXACT_MATCH" + ); + } finally { + deleteProject("P"); + } +} + +public void testBug322979e() throws CoreException { + try + { + IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); + createFile("/P/Test.java", + "public class Test extends Object implements I01<\n" + + " I02<\n" + + " I03>,\n" + + " I03, I02>>\n" + + " >,\n" + + " I01>> {\n" + + "}\n" + + "interface I01 {}\n" + + "interface I02 {}\n" + + "interface I03 {}\n" + ); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + this.resultCollector.showSelection(); + search("Object", TYPE, REFERENCES, scope); + assertSearchResults( + "Test.java Test [public class Test extends !|Object|! implements I01<] EXACT_MATCH\n" + + "Test.java Test [ I03>,] EXACT_MATCH\n" + + "Test.java Test [ I02>,] EXACT_MATCH\n" + + "Test.java Test [ I03, I02>>] EXACT_MATCH\n" + + "Test.java Test [ I03, I02>>] EXACT_MATCH\n" + + "Test.java Test [ I03, I02>>] EXACT_MATCH\n" + + "Test.java Test [ I03, I02>>] EXACT_MATCH\n" + + "Test.java Test [ I01>> {] EXACT_MATCH\n" + + ""+ getExternalJCLPathString("1.5") + " java.lang.Object java.lang.Object.clone() EXACT_MATCH\n" + + ""+ getExternalJCLPathString("1.5") + " boolean java.lang.Object.equals(java.lang.Object) EXACT_MATCH\n" + + ""+ getExternalJCLPathString("1.5") + " java.lang.Class java.lang.Object.getClass() EXACT_MATCH" + ); + } finally { + deleteProject("P"); + } +} + +public void testBug322979f() throws CoreException { + try + { + IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); + createFile("/P/Test.java", + "public class Test extends Object implements I01<\n" + + " I02<\n" + + " I03>,\n" + + " I03, I02>>\n" + + " >,\n" + + " I01>> {\n" + + "}\n" + + "interface I01 {}\n" + + "interface I02 {}\n" + + "interface I03 {}\n" + ); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + this.resultCollector.showSelection(); + search("Object", TYPE, REFERENCES | SUPERTYPE_TYPE_REFERENCE, scope); + assertSearchResults( + "Test.java Test [public class Test extends !|Object|! implements I01<] EXACT_MATCH" + ); + } finally { + deleteProject("P"); + } +} + +public void testBug322979g() throws CoreException { + try + { + IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); + createFile("/P/Test.java", + "public class Test extends Object implements I.B>.C.B.C>>> {\n" + + "}\n" + + "interface I {\n" + + "}\n" + + "class A {\n" + + " class B {\n" + + " class C {}\n" + + " }\n" + + "}\n" + ); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + this.resultCollector.showSelection(); + search("Object", TYPE, IMPLEMENTORS, scope); + assertSearchResults( + "Test.java Test [public class Test extends !|Object|! implements I.B>.C.B.C>>> {] EXACT_MATCH" + ); + } finally { + deleteProject("P"); + } +} +public void testBug322979h() throws CoreException { + try + { + IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5"); + createFile("/P/Test.java", + "public class Test extends Object implements I1, I2{\n"+ + "}\n"+ + "Interface I1 {}\n"+ + "Interface I2 {}\n"); + waitUntilIndexesReady(); + int mask = IJavaSearchScope.SOURCES ; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + this.resultCollector.showAccuracy(true); + this.resultCollector.showSelection(); + SearchPattern leftPattern = SearchPattern.createPattern( + "Object", + TYPE, + IMPLEMENTORS, + EXACT_RULE); + SearchPattern rightPattern = SearchPattern.createPattern( + "String", + TYPE, + REFERENCES, + EXACT_RULE); + search(SearchPattern.createOrPattern(leftPattern, rightPattern), scope, this.resultCollector); + assertSearchResults( + "Test.java Test [public class Test extends !|Object|! implements I1, I2{] EXACT_MATCH\n" + + "Test.java Test [public class Test extends Object implements I1, I2{] EXACT_MATCH" + ); + } finally { + deleteProject("P"); + } +} + +/** * @bug 324109: [search] Java search shows incorrect results as accurate matches * @test search of method declaration off missing types should report potential matches and not accurate. * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324109"