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 / +34 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
	if (typeBinding == null || !typeBinding.isValidBinding()) {
691
			this.pattern.simpleName,
691
		if (this.pattern.typeSuffix != TYPE_SUFFIX) return INACCURATE_MATCH;
692
			this.pattern.qualification,
692
	} else {
693
			this.pattern.getTypeArguments(),
693
		switch (this.pattern.typeSuffix) {
694
			0,
694
			case CLASS_SUFFIX:
695
			typeBinding);
695
				if (!typeBinding.isClass()) return IMPOSSIBLE_MATCH;
696
				break;
697
			case CLASS_AND_INTERFACE_SUFFIX:
698
				if (!(typeBinding.isClass() || (typeBinding.isInterface() && !typeBinding.isAnnotationType()))) return IMPOSSIBLE_MATCH;
699
				break;
700
			case CLASS_AND_ENUM_SUFFIX:
701
				if (!(typeBinding.isClass() || typeBinding.isEnum())) return IMPOSSIBLE_MATCH;
702
				break;
703
			case INTERFACE_SUFFIX:
704
				if (!typeBinding.isInterface() || typeBinding.isAnnotationType()) return IMPOSSIBLE_MATCH;
705
				break;
706
			case INTERFACE_AND_ANNOTATION_SUFFIX:
707
				if (!(typeBinding.isInterface() || typeBinding.isAnnotationType())) return IMPOSSIBLE_MATCH;
708
				break;
709
			case ENUM_SUFFIX:
710
				if (!typeBinding.isEnum()) return IMPOSSIBLE_MATCH;
711
				break;
712
			case ANNOTATION_TYPE_SUFFIX:
713
				if (!typeBinding.isAnnotationType()) return IMPOSSIBLE_MATCH;
714
				break;
715
			case TYPE_SUFFIX : // nothing
716
		}
717
	}
718
	return resolveLevelForType( this.pattern.simpleName,
719
						this.pattern.qualification,
720
						this.pattern.getTypeArguments(),
721
						0,
722
						typeBinding);
696
}
723
}
697
/**
724
/**
698
 * Returns whether the given type binding or one of its enclosing types
725
 * 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 (+115 lines)
Lines 60-65 Link Here
60
// Debug
60
// Debug
61
static {
61
static {
62
//	 org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
62
//	 org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
63
//	TESTS_NAMES = new String[] {"testBug306223c"};
63
}
64
}
64
65
65
public JavaSearchBugsTests(String name) {
66
public JavaSearchBugsTests(String name) {
Lines 11566-11569 Link Here
11566
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11567
		removeClasspathEntry(JAVA_PROJECT, new Path(libPath));
11567
	}
11568
	}
11568
}
11569
}
11570
11571
/**
11572
 * @bug 306223:  [search] Searching for annotation references report all type references
11573
 * @test Ensures the following - 
11574
 * 		 1. Search for annotation references does not report type references
11575
 * 		 2. Search for annotation references even report a non-annotation references to an annotation type
11576
 *		 3. Search for annotation references report an unknown reference as POTENTIAL_MATCH
11577
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=306223"
11578
 */
11579
public void testBug306223a() throws CoreException {
11580
	this.workingCopies = new ICompilationUnit[2];
11581
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11582
			"import b306223.MyAnnot;\n"+
11583
			"@MyAnnot\n" + 
11584
			"public class TestAnnot {\n" +
11585
				"MyAnnot annon;\n" +
11586
				"Zork x;\n" +
11587
			    "String test;\n" +
11588
			    "void foo(String str) {\n" +
11589
			        "this.test = str;\n" +
11590
			    "}\n" +
11591
			"}\n"		
11592
		);
11593
	this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java",
11594
			"@interface MyAnnot {}\n");
11595
	SearchPattern pattern = SearchPattern.createPattern(
11596
			"*",
11597
			ANNOTATION_TYPE,
11598
			REFERENCES,
11599
			EXACT_RULE);
11600
	new SearchEngine(this.workingCopies).search(pattern,
11601
	new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11602
	getJavaSearchWorkingCopiesScope(),
11603
	this.resultCollector,
11604
	null);
11605
	assertSearchResults(
11606
			"src/b306223/Test.java [b306223.MyAnnot] EXACT_MATCH\n" + 
11607
			"src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH\n" + 
11608
			"src/b306223/Test.java b306223.TestAnnot.annon [MyAnnot] EXACT_MATCH\n" + 
11609
			"src/b306223/Test.java b306223.TestAnnot.x [Zork] POTENTIAL_MATCH"
11610
	);
11611
}
11612
/**
11613
 * This ensures that using ANNOTATION_TYPE_REFERENCE as fine grain constant reports only 
11614
 * annotations and not any other references to an annotation type
11615
 */
11616
public void testBug306223b() throws CoreException {
11617
	this.workingCopies = new ICompilationUnit[2];
11618
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11619
			"import b306223.MyAnnot;\n"+
11620
			"@MyAnnot\n" + 
11621
			"public class TestAnnot {\n" +
11622
				"MyAnnot annon;\n" +
11623
			    "String test;\n" +
11624
			    "void foo(String str) {\n" +
11625
			        "this.test = str;\n" +
11626
			    "}\n" +
11627
			"}\n"		
11628
		);
11629
	this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java",
11630
			"@interface MyAnnot {}\n");
11631
	SearchPattern pattern = SearchPattern.createPattern(
11632
			"*",
11633
			ANNOTATION_TYPE,
11634
			REFERENCES|ANNOTATION_TYPE_REFERENCE,
11635
			EXACT_RULE);
11636
	new SearchEngine(this.workingCopies).search(pattern,
11637
	new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11638
	getJavaSearchWorkingCopiesScope(),
11639
	this.resultCollector,
11640
	null);
11641
	assertSearchResults(
11642
			"src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH"
11643
	);
11644
}
11645
/**
11646
 * This ensures that search for enum references does not report type references.
11647
 */
11648
public void testBug306223c() throws CoreException {
11649
	this.workingCopies = new ICompilationUnit[1];
11650
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11651
			"public class TestEnum {\n" +
11652
			"	String foo(MyEnum e) {\n" +
11653
			"		switch (e) {\n"+
11654
			"			case ONE:\n" +
11655
			"				return \"1\";\n" +
11656
			"			case TWO:\n" +
11657
			"				return \"2\";\n" +
11658
			"			default:\n" +
11659
			"				return \"-1\";\n" +
11660
			"			}\n" +
11661
			"		}\n" +
11662
			"	}\n" +
11663
11664
			"enum MyEnum {\n" +
11665
			"	ONE, TWO\n" +
11666
			"}\n"
11667
	);
11668
11669
	SearchPattern pattern = SearchPattern.createPattern(
11670
			"*",
11671
			ENUM,
11672
			REFERENCES,
11673
			EXACT_RULE);
11674
	new SearchEngine(this.workingCopies).search(pattern,
11675
	new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11676
	getJavaSearchWorkingCopiesScope(),
11677
	this.resultCollector,
11678
	null);
11679
	assertSearchResults(
11680
			"src/b306223/Test.java String b306223.TestEnum.foo(MyEnum) [MyEnum] EXACT_MATCH"
11681
	);
11682
}
11683
11569
}
11684
}

Return to bug 306223