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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/AndLocator.java (+9 lines)
Lines 255-258 Link Here
255
	}
255
	}
256
	return level;
256
	return level;
257
}
257
}
258
/* (non-Javadoc)
259
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#setFlavors(int)
260
 */
261
void setFlavors(int flavors) {
262
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
263
		this.patternLocators[i].setFlavors(flavors);
264
	}
265
}
266
258
}
267
}
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocatorParser.java (+10 lines)
Lines 256-266 Link Here
256
}
256
}
257
257
258
protected void consumeClassHeaderExtends() {
258
protected void consumeClassHeaderExtends() {
259
	this.patternLocator.setFlavors(PatternLocator.SUPERTYPE_REF_FLAVOR);
259
	super.consumeClassHeaderExtends();
260
	super.consumeClassHeaderExtends();
260
	if ((this.patternFineGrain & IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE) != 0) {
261
	if ((this.patternFineGrain & IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE) != 0) {
261
		TypeDeclaration typeDeclaration = (TypeDeclaration) this.astStack[this.astPtr];
262
		TypeDeclaration typeDeclaration = (TypeDeclaration) this.astStack[this.astPtr];
262
		this.patternLocator.match(typeDeclaration.superclass, this.nodeSet);
263
		this.patternLocator.match(typeDeclaration.superclass, this.nodeSet);
263
	}
264
	}
265
	this.patternLocator.setFlavors(PatternLocator.NO_FLAVOR);
264
}
266
}
265
267
266
protected void consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() {
268
protected void consumeClassInstanceCreationExpressionQualifiedWithTypeArguments() {
Lines 283-288 Link Here
283
	}
285
	}
284
}
286
}
285
287
288
protected void consumeEnterAnonymousClassBody(boolean qualified) {
289
	this.patternLocator.setFlavors(PatternLocator.SUPERTYPE_REF_FLAVOR);
290
	super.consumeEnterAnonymousClassBody(qualified);
291
	this.patternLocator.setFlavors(PatternLocator.NO_FLAVOR);
292
}
293
286
protected void consumeEnterVariable() {
294
protected void consumeEnterVariable() {
287
	boolean isLocalDeclaration = this.nestedMethod[this.nestedType] != 0;
295
	boolean isLocalDeclaration = this.nestedMethod[this.nestedType] != 0;
288
	super.consumeEnterVariable();
296
	super.consumeEnterVariable();
Lines 337-347 Link Here
337
	}
345
	}
338
}
346
}
339
protected void consumeInterfaceType() {
347
protected void consumeInterfaceType() {
348
	this.patternLocator.setFlavors(PatternLocator.SUPERTYPE_REF_FLAVOR);
340
	super.consumeInterfaceType();
349
	super.consumeInterfaceType();
341
	if ((this.patternFineGrain & IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE) != 0) {
350
	if ((this.patternFineGrain & IJavaSearchConstants.SUPERTYPE_TYPE_REFERENCE) != 0) {
342
		TypeReference typeReference = (TypeReference) this.astStack[this.astPtr];
351
		TypeReference typeReference = (TypeReference) this.astStack[this.astPtr];
343
		this.patternLocator.match(typeReference, this.nodeSet);
352
		this.patternLocator.match(typeReference, this.nodeSet);
344
	}
353
	}
354
	this.patternLocator.setFlavors(PatternLocator.NO_FLAVOR);
345
}
355
}
346
356
347
protected void consumeLocalVariableDeclaration() {
357
protected void consumeLocalVariableDeclaration() {
(-)search/org/eclipse/jdt/internal/core/search/matching/OrLocator.java (+9 lines)
Lines 307-310 Link Here
307
	}
307
	}
308
	return level;
308
	return level;
309
}
309
}
310
/* (non-Javadoc)
311
 * @see org.eclipse.jdt.internal.core.search.matching.PatternLocator#setFlavors(int)
312
 */
313
void setFlavors(int flavors) {
314
	for (int i = 0, length = this.patternLocators.length; i < length; i++) {
315
		this.patternLocators[i].setFlavors(flavors);
316
	}
317
}
318
310
}
319
}
(-)search/org/eclipse/jdt/internal/core/search/matching/PatternLocator.java (+14 lines)
Lines 39-45 Link Here
39
public static final int ERASURE_MATCH = 4;
39
public static final int ERASURE_MATCH = 4;
40
40
41
// Possible rule match flavors
41
// Possible rule match flavors
42
int flavors = 0;
42
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79866
43
// see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=79866
44
public static final int NO_FLAVOR = 0x0000;
43
public static final int EXACT_FLAVOR = 0x0010;
45
public static final int EXACT_FLAVOR = 0x0010;
44
public static final int PREFIX_FLAVOR = 0x0020;
46
public static final int PREFIX_FLAVOR = 0x0020;
45
public static final int PATTERN_FLAVOR = 0x0040;
47
public static final int PATTERN_FLAVOR = 0x0040;
Lines 48-53 Link Here
48
public static final int SUPER_INVOCATION_FLAVOR = 0x0200;
50
public static final int SUPER_INVOCATION_FLAVOR = 0x0200;
49
public static final int SUB_INVOCATION_FLAVOR = 0x0400;
51
public static final int SUB_INVOCATION_FLAVOR = 0x0400;
50
public static final int OVERRIDDEN_METHOD_FLAVOR = 0x0800;
52
public static final int OVERRIDDEN_METHOD_FLAVOR = 0x0800;
53
public static final int SUPERTYPE_REF_FLAVOR = 0x1000;
51
public static final int MATCH_LEVEL_MASK = 0x0F;
54
public static final int MATCH_LEVEL_MASK = 0x0F;
52
public static final int FLAVORS_MASK = ~MATCH_LEVEL_MASK;
55
public static final int FLAVORS_MASK = ~MATCH_LEVEL_MASK;
53
56
Lines 436-441 Link Here
436
	// need to do instance of checks to find out exact type of ASTNode
439
	// need to do instance of checks to find out exact type of ASTNode
437
	return IMPOSSIBLE_MATCH;
440
	return IMPOSSIBLE_MATCH;
438
}
441
}
442
/**
443
 * Set the flavors for which the locator has to be focused on.
444
 * If not set, the locator will accept all matches with or without flavors.
445
 * When set, the locator will only accept match having the corresponding flavors.
446
 * 
447
 * @param flavors Bits mask specifying the flavors to be accepted or
448
 * 	<code>0</code> to ignore the flavors while accepting matches.
449
 */
450
void setFlavors(int flavors) {
451
	this.flavors = flavors;
452
}
439
/*
453
/*
440
 * Update pattern locator match for parameterized top level types.
454
 * Update pattern locator match for parameterized top level types.
441
 * Set match raw flag and recurse to enclosing types if any...
455
 * Set match raw flag and recurse to enclosing types if any...
(-)search/org/eclipse/jdt/internal/core/search/matching/SuperTypeReferenceLocator.java (+1 lines)
Lines 34-39 Link Here
34
//public int match(Reference node, MatchingNodeSet nodeSet) - SKIP IT
34
//public int match(Reference node, MatchingNodeSet nodeSet) - SKIP IT
35
//public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
35
//public int match(TypeDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
36
public int match(TypeReference node, MatchingNodeSet nodeSet) {
36
public int match(TypeReference node, MatchingNodeSet nodeSet) {
37
	if (this.flavors != SUPERTYPE_REF_FLAVOR) return IMPOSSIBLE_MATCH;
37
	if (this.pattern.superSimpleName == null)
38
	if (this.pattern.superSimpleName == null)
38
		return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
39
		return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH);
39
40
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaSearchTests.java (-4 / +4 lines)
Lines 42-51 Link Here
42
	public static List JAVA_SEARCH_SUITES = null;
42
	public static List JAVA_SEARCH_SUITES = null;
43
	protected static IJavaProject JAVA_PROJECT;
43
	protected static IJavaProject JAVA_PROJECT;
44
	protected static boolean COPY_DIRS = true;
44
	protected static boolean COPY_DIRS = true;
45
	protected static int EXACT_RULE = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
45
	protected final static int EXACT_RULE = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE;
46
	protected static int EQUIVALENT_RULE = EXACT_RULE | SearchPattern.R_EQUIVALENT_MATCH;
46
	protected final static int EQUIVALENT_RULE = EXACT_RULE | SearchPattern.R_EQUIVALENT_MATCH;
47
	protected static int ERASURE_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH;
47
	protected final static int ERASURE_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH;
48
	protected static int RAW_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH | SearchPattern.R_EQUIVALENT_MATCH;
48
	protected final static int RAW_RULE = EXACT_RULE | SearchPattern.R_ERASURE_MATCH | SearchPattern.R_EQUIVALENT_MATCH;
49
49
50
//	ICompilationUnit[] workingCopies;
50
//	ICompilationUnit[] workingCopies;
51
//	boolean discard;
51
//	boolean discard;
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+240 lines)
Lines 12073-12078 Link Here
12073
}
12073
}
12074
12074
12075
/**
12075
/**
12076
 * @bug 322979: [search] use of IJavaSearchConstants.IMPLEMENTORS yields surprising results
12077
 * @test search of implementors does no longer report matches in type arguments
12078
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=322979"
12079
 */
12080
public void testBug322979a() throws CoreException {
12081
	try
12082
	{
12083
		IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
12084
		createFile("/P/Test.java", 
12085
			"public class Test extends Object implements Comparable<Object>{\n"+
12086
		    "public int compareTo(Object o) {\n"+
12087
		        "return 0;\n"+
12088
		    "}\n"+
12089
			"}\n");
12090
		waitUntilIndexesReady();
12091
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12092
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
12093
		this.resultCollector.showAccuracy(true);
12094
		this.resultCollector.showSelection();
12095
		search("Object", TYPE, IMPLEMENTORS, scope);
12096
		assertSearchResults(
12097
			"Test.java Test [public class Test extends !|Object|! implements Comparable<Object>{] EXACT_MATCH"
12098
		);
12099
	} finally {
12100
		deleteProject("P");
12101
	}
12102
}
12103
12104
public void testBug322979b() throws CoreException {
12105
	try
12106
	{
12107
		IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
12108
		createFile("/P/Test.java", 
12109
			"public class Test extends java.lang.Object implements Comparable<Object>{\n"+
12110
		    "public int compareTo(Object o) {\n"+
12111
		        "return 0;\n"+
12112
		    "}\n"+
12113
			"}\n");
12114
		waitUntilIndexesReady();
12115
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12116
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
12117
		IType type = getClassFile("P", getExternalJCLPathString("1.5"), "java.lang", "Object.class").getType();
12118
		this.resultCollector.showAccuracy(true);
12119
		this.resultCollector.showSelection();
12120
		search(type, IMPLEMENTORS, scope);
12121
		assertSearchResults(
12122
			"Test.java Test [public class Test extends !|java.lang.Object|! implements Comparable<Object>{] EXACT_MATCH"
12123
		);
12124
	} finally {
12125
		deleteProject("P");
12126
	}
12127
}
12128
12129
public void testBug322979c() throws CoreException {
12130
	try
12131
	{
12132
		IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
12133
		createFile("/P/Test.java", 
12134
			"public class Test extends Object implements I01a<Object>, I01b<String>, I01c<Object> {\n" + 
12135
			"}\n" + 
12136
			"interface I01a<T> {}\n" + 
12137
			"interface I01b<T> {}\n" + 
12138
			"interface I01c<T> {}\n"
12139
		);
12140
		waitUntilIndexesReady();
12141
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12142
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
12143
		this.resultCollector.showSelection();
12144
		search("java.lang.Object", TYPE, IMPLEMENTORS, scope);
12145
		assertSearchResults(
12146
			"Test.java Test [public class Test extends !|Object|! implements I01a<Object>, I01b<String>, I01c<Object> {] EXACT_MATCH"
12147
		);
12148
	} finally {
12149
		deleteProject("P");
12150
	}
12151
}
12152
12153
public void testBug322979d() throws CoreException {
12154
	try
12155
	{
12156
		IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
12157
		createFile("/P/Test.java", 
12158
			"public class Test extends Object implements I01<\n" + 
12159
			"	I02<\n" + 
12160
			"		I03<Object,\n" + 
12161
			"			I02<Object, I01<Object>>,\n" + 
12162
			"			I03<Object, I01<Object>, I02<Object, I01<Object>>>\n" + 
12163
			"			>,\n" + 
12164
			"		I01<Object>>> {\n" + 
12165
			"}\n" + 
12166
			"interface I01<T> {}\n" + 
12167
			"interface I02<T, U> {}\n" + 
12168
			"interface I03<T, U, V> {}\n"
12169
		);
12170
		waitUntilIndexesReady();
12171
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12172
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
12173
		this.resultCollector.showSelection();
12174
		search("Object", TYPE, IMPLEMENTORS, scope);
12175
		assertSearchResults(
12176
			"Test.java Test [public class Test extends !|Object|! implements I01<] EXACT_MATCH"
12177
		);
12178
	} finally {
12179
		deleteProject("P");
12180
	}
12181
}
12182
12183
public void testBug322979e() throws CoreException {
12184
	try
12185
	{
12186
		IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
12187
		createFile("/P/Test.java", 
12188
			"public class Test extends Object implements I01<\n" + 
12189
			"	I02<\n" + 
12190
			"		I03<Object,\n" + 
12191
			"			I02<Object, I01<Object>>,\n" + 
12192
			"			I03<Object, I01<Object>, I02<Object, I01<Object>>>\n" + 
12193
			"			>,\n" + 
12194
			"		I01<Object>>> {\n" + 
12195
			"}\n" + 
12196
			"interface I01<T> {}\n" + 
12197
			"interface I02<T, U> {}\n" + 
12198
			"interface I03<T, U, V> {}\n"
12199
		);
12200
		waitUntilIndexesReady();
12201
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12202
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
12203
		this.resultCollector.showSelection();
12204
		search("Object", TYPE, REFERENCES, scope);
12205
		assertSearchResults(
12206
			"Test.java Test [public class Test extends !|Object|! implements I01<] EXACT_MATCH\n" + 
12207
			"Test.java Test [		I03<!|Object|!,] EXACT_MATCH\n" + 
12208
			"Test.java Test [			I02<!|Object|!, I01<Object>>,] EXACT_MATCH\n" + 
12209
			"Test.java Test [			I02<Object, I01<!|Object|!>>,] EXACT_MATCH\n" + 
12210
			"Test.java Test [			I03<!|Object|!, I01<Object>, I02<Object, I01<Object>>>] EXACT_MATCH\n" + 
12211
			"Test.java Test [			I03<Object, I01<!|Object|!>, I02<Object, I01<Object>>>] EXACT_MATCH\n" + 
12212
			"Test.java Test [			I03<Object, I01<Object>, I02<!|Object|!, I01<Object>>>] EXACT_MATCH\n" + 
12213
			"Test.java Test [			I03<Object, I01<Object>, I02<Object, I01<!|Object|!>>>] EXACT_MATCH\n" + 
12214
			"Test.java Test [		I01<!|Object|!>>> {] EXACT_MATCH\n" + 
12215
			""+ getExternalJCLPathString("1.5") + " java.lang.Object java.lang.Object.clone() EXACT_MATCH\n" + 
12216
			""+ getExternalJCLPathString("1.5") + " boolean java.lang.Object.equals(java.lang.Object) EXACT_MATCH\n" + 
12217
			""+ getExternalJCLPathString("1.5") + " java.lang.Class<? extends java.lang.Object> java.lang.Object.getClass() EXACT_MATCH"
12218
		);
12219
	} finally {
12220
		deleteProject("P");
12221
	}
12222
}
12223
12224
public void testBug322979f() throws CoreException {
12225
	try
12226
	{
12227
		IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
12228
		createFile("/P/Test.java", 
12229
			"public class Test extends Object implements I01<\n" + 
12230
			"	I02<\n" + 
12231
			"		I03<Object,\n" + 
12232
			"			I02<Object, I01<Object>>,\n" + 
12233
			"			I03<Object, I01<Object>, I02<Object, I01<Object>>>\n" + 
12234
			"			>,\n" + 
12235
			"		I01<Object>>> {\n" + 
12236
			"}\n" + 
12237
			"interface I01<T> {}\n" + 
12238
			"interface I02<T, U> {}\n" + 
12239
			"interface I03<T, U, V> {}\n"
12240
		);
12241
		waitUntilIndexesReady();
12242
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12243
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
12244
		this.resultCollector.showSelection();
12245
		search("Object", TYPE, REFERENCES | SUPERTYPE_TYPE_REFERENCE, scope);
12246
		assertSearchResults(
12247
			"Test.java Test [public class Test extends !|Object|! implements I01<] EXACT_MATCH"
12248
		);
12249
	} finally {
12250
		deleteProject("P");
12251
	}
12252
}
12253
12254
public void testBug322979g() throws CoreException {
12255
	try
12256
	{
12257
		IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
12258
		createFile("/P/Test.java", 
12259
			"public class Test extends Object implements I<A<Object>.B<I<Object>>.C<I<A<Object>.B<Object>.C<Object>>>> {\n" + 
12260
			"}\n" + 
12261
			"interface I<T> {\n" + 
12262
			"}\n" + 
12263
			"class A<T> {\n" + 
12264
			"	class B<U> {\n" + 
12265
			"		class C<V> {}\n" + 
12266
			"	}\n" + 
12267
			"}\n"
12268
		);
12269
		waitUntilIndexesReady();
12270
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12271
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
12272
		this.resultCollector.showSelection();
12273
		search("Object", TYPE, IMPLEMENTORS, scope);
12274
		assertSearchResults(
12275
			"Test.java Test [public class Test extends !|Object|! implements I<A<Object>.B<I<Object>>.C<I<A<Object>.B<Object>.C<Object>>>> {] EXACT_MATCH"
12276
		);
12277
	} finally {
12278
		deleteProject("P");
12279
	}
12280
}
12281
public void testBug322979h() throws CoreException {
12282
	try
12283
	{
12284
		IJavaProject project = createJavaProject("P", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
12285
		createFile("/P/Test.java", 
12286
			"public class Test extends Object implements I1<String>, I2<Object>{\n"+
12287
		    "}\n"+
12288
		    "Interface I1<T> {}\n"+
12289
			"Interface I2<T> {}\n");
12290
		waitUntilIndexesReady();
12291
		int mask = IJavaSearchScope.SOURCES ;
12292
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
12293
		this.resultCollector.showAccuracy(true);
12294
		this.resultCollector.showSelection();
12295
		SearchPattern leftPattern = SearchPattern.createPattern(
12296
				"Object",
12297
				TYPE,
12298
				IMPLEMENTORS,
12299
				EXACT_RULE);
12300
		SearchPattern rightPattern = SearchPattern.createPattern(
12301
				"String",
12302
				TYPE,
12303
				REFERENCES,
12304
				EXACT_RULE);
12305
		search(SearchPattern.createOrPattern(leftPattern, rightPattern), scope, this.resultCollector);
12306
		assertSearchResults(
12307
			"Test.java Test [public class Test extends !|Object|! implements I1<String>, I2<Object>{] EXACT_MATCH\n" + 
12308
			"Test.java Test [public class Test extends Object implements I1<!|String|!>, I2<Object>{] EXACT_MATCH"
12309
		);
12310
	} finally {
12311
		deleteProject("P");
12312
	}
12313
}
12314
12315
/**
12076
 * @bug 324109: [search] Java search shows incorrect results as accurate matches
12316
 * @bug 324109: [search] Java search shows incorrect results as accurate matches
12077
 * @test search of method declaration off missing types should report potential matches and not accurate.
12317
 * @test search of method declaration off missing types should report potential matches and not accurate.
12078
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324109"
12318
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=324109"

Return to bug 322979