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 (+209 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[] {"testBug306223"};
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
 *		
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
			    "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"
11608
	);
11609
}
11610
/**
11611
 * This ensures that using ANNOTATION_TYPE_REFERENCE as fine grain constant reports only 
11612
 * annotations and not any other references to an annotation type
11613
 */
11614
public void testBug306223b() throws CoreException {
11615
	this.workingCopies = new ICompilationUnit[2];
11616
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11617
			"import b306223.MyAnnot;\n"+
11618
			"@MyAnnot\n" + 
11619
			"public class TestAnnot {\n" +
11620
				"MyAnnot annon;\n" +
11621
			    "String test;\n" +
11622
			    "void foo(String str) {\n" +
11623
			        "this.test = str;\n" +
11624
			    "}\n" +
11625
			"}\n"		
11626
		);
11627
	this.workingCopies[1] = getWorkingCopy("/JavaSearchBugs/src/b306223/MyAnnot.java",
11628
			"@interface MyAnnot {}\n");
11629
	SearchPattern pattern = SearchPattern.createPattern(
11630
			"*",
11631
			ANNOTATION_TYPE,
11632
			REFERENCES|ANNOTATION_TYPE_REFERENCE,
11633
			EXACT_RULE);
11634
	new SearchEngine(this.workingCopies).search(pattern,
11635
	new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11636
	getJavaSearchWorkingCopiesScope(),
11637
	this.resultCollector,
11638
	null);
11639
	assertSearchResults(
11640
			"src/b306223/Test.java b306223.TestAnnot [MyAnnot] EXACT_MATCH"
11641
	);
11642
}
11643
11644
/**
11645
 * This test 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/b306223/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/b306223/Test.java String b306223.TestEnum.foo(MyEnum) [MyEnum] EXACT_MATCH"
11680
	);
11681
}
11682
/**
11683
 * This test ensures that a reference search of ANNOTATION_TYPE should report POTENTIAL_MATCH
11684
 * for unknown references types.
11685
 */ 
11686
public void testBug306223d() throws CoreException {
11687
	this.workingCopies = new ICompilationUnit[1];
11688
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11689
			"public class TestAnnot {\n" +
11690
				"Zork annon;\n" +
11691
			"}\n"		
11692
		);
11693
	SearchPattern pattern = SearchPattern.createPattern(
11694
			"*",
11695
			ANNOTATION_TYPE,
11696
			REFERENCES,
11697
			EXACT_RULE);
11698
	new SearchEngine(this.workingCopies).search(pattern,
11699
	new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11700
	getJavaSearchWorkingCopiesScope(),
11701
	this.resultCollector,
11702
	null);
11703
	assertSearchResults(
11704
			"src/b306223/Test.java b306223.TestAnnot.annon [Zork] POTENTIAL_MATCH" 
11705
	);
11706
}
11707
/**
11708
 * This test ensures that an ANNOTATION_TYPE reference search for a non-existing
11709
 * type does not report any other references
11710
 */
11711
public void testBug306223e() throws CoreException {
11712
	this.workingCopies = new ICompilationUnit[1];
11713
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11714
			"public class Test {\n" +
11715
			"	Zork x;\n" +
11716
			"}\n"		
11717
		);
11718
	SearchPattern pattern = SearchPattern.createPattern(
11719
			"abc",
11720
			ANNOTATION_TYPE,
11721
			REFERENCES,
11722
			EXACT_RULE);
11723
	new SearchEngine(this.workingCopies).search(pattern,
11724
		new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11725
		getJavaSearchWorkingCopiesScope(),
11726
		this.resultCollector,
11727
		null);
11728
	assertSearchResults("");
11729
}
11730
/**
11731
 * This test ensures that a TYPE reference search reports EXACT_MATCH
11732
 * for missing types
11733
 */
11734
public void testBug306223f() throws CoreException {
11735
	this.workingCopies = new ICompilationUnit[1];
11736
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11737
			"public class Test {\n" +
11738
			"	Zork x;\n" +
11739
			"}\n"		
11740
		);
11741
	SearchPattern pattern = SearchPattern.createPattern(
11742
			"*",
11743
			TYPE,
11744
			REFERENCES,
11745
			EXACT_RULE);
11746
	new SearchEngine(this.workingCopies).search(pattern,
11747
		new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11748
		getJavaSearchWorkingCopiesScope(),
11749
		this.resultCollector,
11750
		null);
11751
	assertSearchResults(
11752
		"src/b306223/Test.java b306223.Test.x [Zork] EXACT_MATCH"
11753
	);
11754
}
11755
/**
11756
 * This test ensures that a TYPE reference search for a non-existing
11757
 * type does not report any other references
11758
 */
11759
public void testBug306223g() throws CoreException {
11760
	this.workingCopies = new ICompilationUnit[1];
11761
	this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b306223/Test.java",
11762
			"public class Test {\n" +
11763
			"	Zork x;\n" +
11764
			"}\n"		
11765
		);
11766
	SearchPattern pattern = SearchPattern.createPattern(
11767
			"abc",
11768
			TYPE,
11769
			REFERENCES,
11770
			EXACT_RULE);
11771
	new SearchEngine(this.workingCopies).search(pattern,
11772
		new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11773
		getJavaSearchWorkingCopiesScope(),
11774
		this.resultCollector,
11775
		null);
11776
	assertSearchResults("");
11777
}
11569
}
11778
}

Return to bug 306223