### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/core/search/SearchPattern.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/core/search/SearchPattern.java,v retrieving revision 1.82 diff -u -r1.82 SearchPattern.java --- search/org/eclipse/jdt/core/search/SearchPattern.java 25 Sep 2009 16:54:10 -0000 1.82 +++ search/org/eclipse/jdt/core/search/SearchPattern.java 29 Mar 2010 06:06:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -2222,15 +2222,15 @@ case IJavaSearchConstants.DECLARATIONS : // cannot search for explicit member types return new QualifiedTypeDeclarationPattern(qualificationChars, typeChars, indexSuffix, matchRule); case IJavaSearchConstants.REFERENCES : - return new TypeReferencePattern(qualificationChars, typeChars, typeSignature, matchRule); + return new TypeReferencePattern(qualificationChars, typeChars, typeSignature, indexSuffix, matchRule); case IJavaSearchConstants.IMPLEMENTORS : return new SuperTypeReferencePattern(qualificationChars, typeChars, SuperTypeReferencePattern.ONLY_SUPER_INTERFACES, indexSuffix, matchRule); case IJavaSearchConstants.ALL_OCCURRENCES : return new OrPattern( new QualifiedTypeDeclarationPattern(qualificationChars, typeChars, indexSuffix, matchRule),// cannot search for explicit member types - new TypeReferencePattern(qualificationChars, typeChars, typeSignature, matchRule)); + new TypeReferencePattern(qualificationChars, typeChars, typeSignature, indexSuffix, matchRule)); default: - return new TypeReferencePattern(qualificationChars, typeChars, typeSignature, limitTo, matchRule); + return new TypeReferencePattern(qualificationChars, typeChars, typeSignature, limitTo, indexSuffix, matchRule); } } /** Index: search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java,v retrieving revision 1.68 diff -u -r1.68 TypeReferenceLocator.java --- search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java 28 Apr 2009 16:53:03 -0000 1.68 +++ search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java 29 Mar 2010 06:06:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -687,6 +687,30 @@ * This is just an helper to avoid call of method with all parameters... */ protected int resolveLevelForType(TypeBinding typeBinding) { + switch (this.pattern.typeSuffix) { + case CLASS_SUFFIX: + if (!typeBinding.isClass()) return IMPOSSIBLE_MATCH; + break; + case CLASS_AND_INTERFACE_SUFFIX: + if (!(typeBinding.isClass() || (typeBinding.isInterface() && !typeBinding.isAnnotationType()))) return IMPOSSIBLE_MATCH; + break; + case CLASS_AND_ENUM_SUFFIX: + if (!(typeBinding.isClass() || typeBinding.isEnum())) return IMPOSSIBLE_MATCH; + break; + case INTERFACE_SUFFIX: + if (!typeBinding.isInterface() || typeBinding.isAnnotationType()) return IMPOSSIBLE_MATCH; + break; + case INTERFACE_AND_ANNOTATION_SUFFIX: + if (!(typeBinding.isInterface() || typeBinding.isAnnotationType())) return IMPOSSIBLE_MATCH; + break; + case ENUM_SUFFIX: + if (!typeBinding.isEnum()) return IMPOSSIBLE_MATCH; + break; + case ANNOTATION_TYPE_SUFFIX: + if (!typeBinding.isAnnotationType()) return IMPOSSIBLE_MATCH; + break; + case TYPE_SUFFIX : // nothing + } return resolveLevelForType( this.pattern.simpleName, this.pattern.qualification, Index: search/org/eclipse/jdt/internal/core/search/matching/TypeReferencePattern.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/TypeReferencePattern.java,v retrieving revision 1.85 diff -u -r1.85 TypeReferencePattern.java --- search/org/eclipse/jdt/internal/core/search/matching/TypeReferencePattern.java 7 Mar 2009 01:08:09 -0000 1.85 +++ search/org/eclipse/jdt/internal/core/search/matching/TypeReferencePattern.java 29 Mar 2010 06:06:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -32,6 +32,7 @@ CATEGORIES = { REF, ANNOTATION_REF }, CATEGORIES_ANNOT_REF = { ANNOTATION_REF }; private char[][] categories; + char typeSuffix = TYPE_SUFFIX; public TypeReferencePattern(char[] qualification, char[] simpleName, int matchRule) { this(matchRule); @@ -58,14 +59,21 @@ * Instantiate a type reference pattern with additional information for generics search */ public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, int matchRule) { - this(qualification, simpleName, typeSignature, 0, matchRule); + this(qualification, simpleName, typeSignature, 0, TYPE_SUFFIX, matchRule); + } + /* + * Instantiate a type reference pattern with additional information for generics search and search elements nature + */ + public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, char typeSuffix, int matchRule) { + this(qualification, simpleName, typeSignature, 0, typeSuffix, matchRule); } /* - * Instanciate a type reference pattern with additional information for generics search and fine grain information + * Instanciate a type reference pattern with additional information for generics search, search elements nature and fine grain information */ - public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, int limitTo, int matchRule) { + public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, int limitTo, char typeSuffix, int matchRule) { this(qualification, simpleName,matchRule); + this.typeSuffix = typeSuffix; if (typeSignature != null) { // store type signatures and arguments this.typeSignatures = Util.splitTypeLevelsSignature(typeSignature); #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.193 diff -u -r1.193 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 25 Mar 2010 14:34:16 -0000 1.193 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 29 Mar 2010 06:06:58 -0000 @@ -11566,4 +11566,113 @@ removeClasspathEntry(JAVA_PROJECT, new Path(libPath)); } } + +/** + * @bug 306223: [search] Searching for annotation references report all type references + * @test Ensure that search for annotation references does not report type references. + * It also ensures that a reference to annotation type is also reported. + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=306223" + */ +public void testBug306223a() throws CoreException { + this.workingCopies = new ICompilationUnit[2]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java", + "import b306223.MyAnnot;\n"+ + "@MyAnnot\n" + + "public class TestAnnot {\n" + + "MyAnnot annon;\n" + + "String test;\n" + + "void foo(String str) {\n" + + "this.test = str;\n" + + "}\n" + + "}\n" + ); + this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java", + "@interface MyAnnot {}\n"); + SearchPattern pattern = SearchPattern.createPattern( + "*", + ANNOTATION_TYPE, + REFERENCES, + EXACT_RULE); + new SearchEngine(this.workingCopies).search(pattern, + new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, + getJavaSearchWorkingCopiesScope(), + this.resultCollector, + null); + assertSearchResults( + "src/b306223/Test.java [b306223.MyAnnot] EXACT_MATCH\n" + + "src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH\n" + + "src/b306223/Test.java b306223.TestAnnot.annon [MyAnnot] EXACT_MATCH" + ); +} +/** + * This ensures that using ANNOTATION_TYPE_REFERENCE as fine grain constant reports only + * annotations and not any other references to an annotation type + */ +public void testBug306223b() throws CoreException { + this.workingCopies = new ICompilationUnit[2]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java", + "import b306223.MyAnnot;\n"+ + "@MyAnnot\n" + + "public class TestAnnot {\n" + + "MyAnnot annon;\n" + + "String test;\n" + + "void foo(String str) {\n" + + "this.test = str;\n" + + "}\n" + + "}\n" + ); + this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java", + "@interface MyAnnot {}\n"); + SearchPattern pattern = SearchPattern.createPattern( + "*", + ANNOTATION_TYPE, + REFERENCES|ANNOTATION_TYPE_REFERENCE, + EXACT_RULE); + new SearchEngine(this.workingCopies).search(pattern, + new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, + getJavaSearchWorkingCopiesScope(), + this.resultCollector, + null); + assertSearchResults( + "src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH" + ); +} +/** + * This ensures that search for enum references does not report type references. + */ +public void testBug306223c() throws CoreException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223b/Test.java", + "public class TestEnum {\n" + + " String foo(MyEnum e) {\n" + + " switch (e) {\n"+ + " case ONE:\n" + + " return \"1\";\n" + + " case TWO:\n" + + " return \"2\";\n" + + " default:\n" + + " return \"-1\";\n" + + " }\n" + + " }\n" + + " }\n" + + + "enum MyEnum {\n" + + " ONE, TWO\n" + + "}\n" + ); + + SearchPattern pattern = SearchPattern.createPattern( + "*", + ENUM, + REFERENCES, + EXACT_RULE); + new SearchEngine(this.workingCopies).search(pattern, + new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()}, + getJavaSearchWorkingCopiesScope(), + this.resultCollector, + null); + assertSearchResults( + "src/b306223b/Test.java String b306223b.TestEnum.foo(MyEnum) [MyEnum] EXACT_MATCH" + ); +} } \ No newline at end of file