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

Collapse All | Expand All

(-)search/org/eclipse/jdt/core/search/SearchPattern.java (-4 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 2222-2236 Link Here
2222
		case IJavaSearchConstants.DECLARATIONS : // cannot search for explicit member types
2222
		case IJavaSearchConstants.DECLARATIONS : // cannot search for explicit member types
2223
			return new QualifiedTypeDeclarationPattern(qualificationChars, typeChars, indexSuffix, matchRule);
2223
			return new QualifiedTypeDeclarationPattern(qualificationChars, typeChars, indexSuffix, matchRule);
2224
		case IJavaSearchConstants.REFERENCES :
2224
		case IJavaSearchConstants.REFERENCES :
2225
			return new TypeReferencePattern(qualificationChars, typeChars, typeSignature, matchRule);
2225
			return new TypeReferencePattern(qualificationChars, typeChars, typeSignature, indexSuffix, matchRule);
2226
		case IJavaSearchConstants.IMPLEMENTORS :
2226
		case IJavaSearchConstants.IMPLEMENTORS :
2227
			return new SuperTypeReferencePattern(qualificationChars, typeChars, SuperTypeReferencePattern.ONLY_SUPER_INTERFACES, indexSuffix, matchRule);
2227
			return new SuperTypeReferencePattern(qualificationChars, typeChars, SuperTypeReferencePattern.ONLY_SUPER_INTERFACES, indexSuffix, matchRule);
2228
		case IJavaSearchConstants.ALL_OCCURRENCES :
2228
		case IJavaSearchConstants.ALL_OCCURRENCES :
2229
			return new OrPattern(
2229
			return new OrPattern(
2230
				new QualifiedTypeDeclarationPattern(qualificationChars, typeChars, indexSuffix, matchRule),// cannot search for explicit member types
2230
				new QualifiedTypeDeclarationPattern(qualificationChars, typeChars, indexSuffix, matchRule),// cannot search for explicit member types
2231
				new TypeReferencePattern(qualificationChars, typeChars, typeSignature, matchRule));
2231
				new TypeReferencePattern(qualificationChars, typeChars, typeSignature, indexSuffix, matchRule));
2232
		default:
2232
		default:
2233
			return new TypeReferencePattern(qualificationChars, typeChars, typeSignature, limitTo, matchRule);
2233
			return new TypeReferencePattern(qualificationChars, typeChars, typeSignature, limitTo, indexSuffix, matchRule);
2234
	}
2234
	}
2235
}
2235
}
2236
/**
2236
/**
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeReferenceLocator.java (-7 / +45 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 687-698 Link Here
687
 * This is just an helper to avoid call of method with all parameters...
687
 * This is just an helper to avoid call of method with all parameters...
688
 */
688
 */
689
protected int resolveLevelForType(TypeBinding typeBinding) {
689
protected int resolveLevelForType(TypeBinding typeBinding) {
690
	return resolveLevelForType(
690
	boolean valid = typeBinding.isValidBinding();
691
			this.pattern.simpleName,
691
	if (typeBinding.isValidBinding()) {
692
			this.pattern.qualification,
692
		switch (this.pattern.typeSuffix) {
693
			this.pattern.getTypeArguments(),
693
			case CLASS_SUFFIX:
694
			0,
694
				if (!typeBinding.isClass()) return IMPOSSIBLE_MATCH;
695
			typeBinding);
695
				break;
696
			case CLASS_AND_INTERFACE_SUFFIX:
697
				if (!(typeBinding.isClass() || (typeBinding.isInterface() && !typeBinding.isAnnotationType()))) return IMPOSSIBLE_MATCH;
698
				break;
699
			case CLASS_AND_ENUM_SUFFIX:
700
				if (!(typeBinding.isClass() || typeBinding.isEnum())) return IMPOSSIBLE_MATCH;
701
				break;
702
			case INTERFACE_SUFFIX:
703
				if (!typeBinding.isInterface() || typeBinding.isAnnotationType()) return IMPOSSIBLE_MATCH;
704
				break;
705
			case INTERFACE_AND_ANNOTATION_SUFFIX:
706
				if (!(typeBinding.isInterface() || typeBinding.isAnnotationType())) return IMPOSSIBLE_MATCH;
707
				break;
708
			case ENUM_SUFFIX:
709
				if (!typeBinding.isEnum()) return IMPOSSIBLE_MATCH;
710
				break;
711
			case ANNOTATION_TYPE_SUFFIX:
712
				if (!typeBinding.isAnnotationType()) return IMPOSSIBLE_MATCH;
713
				break;
714
			case TYPE_SUFFIX : // nothing
715
		}
716
	}
717
	int level = resolveLevelForType( this.pattern.simpleName,
718
						this.pattern.qualification,
719
						this.pattern.getTypeArguments(),
720
						0,
721
						typeBinding);
722
	if (valid || level <= INACCURATE_MATCH) return level;
723
	
724
	switch (this.pattern.typeSuffix) {
725
		case CLASS_SUFFIX:
726
		case CLASS_AND_ENUM_SUFFIX:
727
		case CLASS_AND_INTERFACE_SUFFIX:
728
		case TYPE_SUFFIX:
729
			return level;
730
		default:
731
			return INACCURATE_MATCH;
732
	}
733
	
696
}
734
}
697
/**
735
/**
698
 * Returns whether the given type binding or one of its enclosing types
736
 * Returns whether the given type binding or one of its enclosing types
(-)search/org/eclipse/jdt/internal/core/search/matching/TypeReferencePattern.java (-4 / +12 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 32-37 Link Here
32
		CATEGORIES = { REF, ANNOTATION_REF },
32
		CATEGORIES = { REF, ANNOTATION_REF },
33
		CATEGORIES_ANNOT_REF = { ANNOTATION_REF };
33
		CATEGORIES_ANNOT_REF = { ANNOTATION_REF };
34
	private char[][] categories;
34
	private char[][] categories;
35
	char typeSuffix = TYPE_SUFFIX;
35
36
36
	public TypeReferencePattern(char[] qualification, char[] simpleName, int matchRule) {
37
	public TypeReferencePattern(char[] qualification, char[] simpleName, int matchRule) {
37
		this(matchRule);
38
		this(matchRule);
Lines 58-71 Link Here
58
	 * Instantiate a type reference pattern with additional information for generics search
59
	 * Instantiate a type reference pattern with additional information for generics search
59
	 */
60
	 */
60
	public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, int matchRule) {
61
	public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, int matchRule) {
61
		this(qualification, simpleName, typeSignature, 0, matchRule);
62
		this(qualification, simpleName, typeSignature, 0, TYPE_SUFFIX, matchRule);
63
	}
64
	/*
65
	 * Instantiate a type reference pattern with additional information for generics search and search elements nature
66
	 */
67
	public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, char typeSuffix, int matchRule) {
68
		this(qualification, simpleName, typeSignature, 0, typeSuffix, matchRule);
62
	}
69
	}
63
70
64
	/*
71
	/*
65
	 * Instanciate a type reference pattern with additional information for generics search and fine grain information
72
	 * Instanciate a type reference pattern with additional information for generics search, search elements nature and fine grain information
66
	 */
73
	 */
67
	public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, int limitTo, int matchRule) {
74
	public TypeReferencePattern(char[] qualification, char[] simpleName, String typeSignature, int limitTo, char typeSuffix, int matchRule) {
68
		this(qualification, simpleName,matchRule);
75
		this(qualification, simpleName,matchRule);
76
		this.typeSuffix = typeSuffix;
69
		if (typeSignature != null) {
77
		if (typeSignature != null) {
70
			// store type signatures and arguments
78
			// store type signatures and arguments
71
			this.typeSignatures = Util.splitTypeLevelsSignature(typeSignature);
79
			this.typeSignatures = Util.splitTypeLevelsSignature(typeSignature);
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+114 lines)
Lines 11566-11569 Link Here
11566
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11566
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11567
	}
11567
	}
11568
}
11568
}
11569
11570
/**
11571
 * @bug 306223:  [search] Searching for annotation references report all type references
11572
 * @test Ensures the following - 
11573
 * 		 1. Search for annotation references does not report type references
11574
 * 		 2. Search for annotation references even report a non-annotation references to an annotation type
11575
 *		 3. Search for annotation references report an unknown reference as POTENTIAL_MATCH
11576
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=306223"
11577
 */
11578
public void testBug306223a() throws CoreException {
11579
	this.workingCopies = new ICompilationUnit[2];
11580
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11581
			"import b306223.MyAnnot;\n"+
11582
			"@MyAnnot\n" + 
11583
			"public class TestAnnot {\n" +
11584
				"MyAnnot annon;\n" +
11585
				"Zork x;\n" +
11586
			    "String test;\n" +
11587
			    "void foo(String str) {\n" +
11588
			        "this.test = str;\n" +
11589
			    "}\n" +
11590
			"}\n"		
11591
		);
11592
	this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java",
11593
			"@interface MyAnnot {}\n");
11594
	SearchPattern pattern = SearchPattern.createPattern(
11595
			"*",
11596
			ANNOTATION_TYPE,
11597
			REFERENCES,
11598
			EXACT_RULE);
11599
	new SearchEngine(this.workingCopies).search(pattern,
11600
	new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11601
	getJavaSearchWorkingCopiesScope(),
11602
	this.resultCollector,
11603
	null);
11604
	assertSearchResults(
11605
			"src/b306223/Test.java [b306223.MyAnnot] EXACT_MATCH\n" + 
11606
			"src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH\n" + 
11607
			"src/b306223/Test.java b306223.TestAnnot.annon [MyAnnot] EXACT_MATCH\n" + 
11608
			"src/b306223/Test.java b306223.TestAnnot.x [Zork] POTENTIAL_MATCH"
11609
	);
11610
}
11611
/**
11612
 * This ensures that using ANNOTATION_TYPE_REFERENCE as fine grain constant reports only 
11613
 * annotations and not any other references to an annotation type
11614
 */
11615
public void testBug306223b() throws CoreException {
11616
	this.workingCopies = new ICompilationUnit[2];
11617
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11618
			"import b306223.MyAnnot;\n"+
11619
			"@MyAnnot\n" + 
11620
			"public class TestAnnot {\n" +
11621
				"MyAnnot annon;\n" +
11622
			    "String test;\n" +
11623
			    "void foo(String str) {\n" +
11624
			        "this.test = str;\n" +
11625
			    "}\n" +
11626
			"}\n"		
11627
		);
11628
	this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java",
11629
			"@interface MyAnnot {}\n");
11630
	SearchPattern pattern = SearchPattern.createPattern(
11631
			"*",
11632
			ANNOTATION_TYPE,
11633
			REFERENCES|ANNOTATION_TYPE_REFERENCE,
11634
			EXACT_RULE);
11635
	new SearchEngine(this.workingCopies).search(pattern,
11636
	new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11637
	getJavaSearchWorkingCopiesScope(),
11638
	this.resultCollector,
11639
	null);
11640
	assertSearchResults(
11641
			"src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH"
11642
	);
11643
}
11644
/**
11645
 * This ensures that search for enum references does not report type references.
11646
 */
11647
public void testBug306223c() throws CoreException {
11648
	this.workingCopies = new ICompilationUnit[1];
11649
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223b/Test.java",
11650
			"public class TestEnum {\n" +
11651
			"	String foo(MyEnum e) {\n" +
11652
			"		switch (e) {\n"+
11653
			"			case ONE:\n" +
11654
			"				return \"1\";\n" +
11655
			"			case TWO:\n" +
11656
			"				return \"2\";\n" +
11657
			"			default:\n" +
11658
			"				return \"-1\";\n" +
11659
			"			}\n" +
11660
			"		}\n" +
11661
			"	}\n" +
11662
11663
			"enum MyEnum {\n" +
11664
			"	ONE, TWO\n" +
11665
			"}\n"
11666
	);
11667
11668
	SearchPattern pattern = SearchPattern.createPattern(
11669
			"*",
11670
			ENUM,
11671
			REFERENCES,
11672
			EXACT_RULE);
11673
	new SearchEngine(this.workingCopies).search(pattern,
11674
	new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11675
	getJavaSearchWorkingCopiesScope(),
11676
	this.resultCollector,
11677
	null);
11678
	assertSearchResults(
11679
			"src/b306223b/Test.java String b306223b.TestEnum.foo(MyEnum) [MyEnum] EXACT_MATCH"
11680
	);
11681
}
11682
11569
}
11683
}

Return to bug 306223