View | Details | Raw Unified | Return to bug 325418
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java (-20 / +48 lines)
Lines 215-220 Link Here
215
	return availableFields;
215
	return availableFields;
216
}
216
}
217
217
218
private TypeVariableBinding[] addMethodTypeVariables(TypeVariableBinding[] methodTypeVars) {
219
	if (this.typeVariables == null || this.typeVariables == Binding.NO_TYPE_VARIABLES) {
220
		return methodTypeVars;
221
	} 
222
	if (methodTypeVars == null || methodTypeVars == Binding.NO_TYPE_VARIABLES) {
223
		return this.typeVariables;
224
	}
225
	// uniq-merge both the arrays
226
	int total = this.typeVariables.length + methodTypeVars.length;
227
	TypeVariableBinding[] combinedTypeVars = new TypeVariableBinding[total];
228
	System.arraycopy(this.typeVariables, 0, combinedTypeVars, 0, this.typeVariables.length);
229
	int size = this.typeVariables.length;
230
	loop: for (int i = 0, len = methodTypeVars.length; i < len; i++) {
231
		for (int j = this.typeVariables.length -1 ; j >= 0; j--) {
232
			if (CharOperation.equals(methodTypeVars[i].sourceName, this.typeVariables[j].sourceName))
233
				continue loop;
234
		}
235
		combinedTypeVars[size++] = methodTypeVars[i];
236
	}
237
	if (size != total) {
238
		System.arraycopy(combinedTypeVars, 0, combinedTypeVars = new TypeVariableBinding[size], 0, size);
239
	}
240
	return combinedTypeVars;
241
}
242
218
/**
243
/**
219
 * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#availableMethods()
244
 * @see org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding#availableMethods()
220
 */
245
 */
Lines 275-281 Link Here
275
		this.tagBits |= binaryType.getTagBits();
300
		this.tagBits |= binaryType.getTagBits();
276
		
301
		
277
		char[][][] missingTypeNames = binaryType.getMissingTypeNames();
302
		char[][][] missingTypeNames = binaryType.getMissingTypeNames();
278
		if (typeSignature == null) {
303
		SignatureWrapper wrapper = null;
304
		if (typeSignature != null) {
305
			// ClassSignature = ParameterPart(optional) super_TypeSignature interface_signature
306
			wrapper = new SignatureWrapper(typeSignature);
307
			if (wrapper.signature[wrapper.start] == '<') {
308
				// ParameterPart = '<' ParameterSignature(s) '>'
309
				wrapper.start++; // skip '<'
310
				this.typeVariables = createTypeVariables(wrapper, true, missingTypeNames);
311
				wrapper.start++; // skip '>'
312
				this.tagBits |=  TagBits.HasUnresolvedTypeVariables;
313
				this.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
314
			}
315
		}
316
		TypeVariableBinding[] typeVars = Binding.NO_TYPE_VARIABLES;
317
		char[] methodDescriptor = binaryType.getEnclosingMethod();
318
		if (methodDescriptor != null) {
319
			MethodBinding enclosingMethod = findMethod(methodDescriptor, missingTypeNames);
320
			if (enclosingMethod != null) {
321
				typeVars = enclosingMethod.typeVariables;
322
				this.typeVariables = addMethodTypeVariables(typeVars);			
323
			}
324
		}
325
		if (typeSignature == null)  {
279
			char[] superclassName = binaryType.getSuperclassName();
326
			char[] superclassName = binaryType.getSuperclassName();
280
			if (superclassName != null) {
327
			if (superclassName != null) {
281
				// attempt to find the superclass if it exists in the cache (otherwise - resolve it when requested)
328
				// attempt to find the superclass if it exists in the cache (otherwise - resolve it when requested)
Lines 296-320 Link Here
296
				}
343
				}
297
			}
344
			}
298
		} else {
345
		} else {
299
			// ClassSignature = ParameterPart(optional) super_TypeSignature interface_signature
300
			SignatureWrapper wrapper = new SignatureWrapper(typeSignature);
301
			if (wrapper.signature[wrapper.start] == '<') {
302
				// ParameterPart = '<' ParameterSignature(s) '>'
303
				wrapper.start++; // skip '<'
304
				this.typeVariables = createTypeVariables(wrapper, true, missingTypeNames);
305
				wrapper.start++; // skip '>'
306
				this.tagBits |=  TagBits.HasUnresolvedTypeVariables;
307
				this.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
308
			}
309
			TypeVariableBinding[] typeVars = Binding.NO_TYPE_VARIABLES;
310
			char[] methodDescriptor = binaryType.getEnclosingMethod();
311
			if (methodDescriptor != null) {
312
				MethodBinding enclosingMethod = findMethod(methodDescriptor, missingTypeNames);
313
				if (enclosingMethod != null) {
314
					typeVars = enclosingMethod.typeVariables;
315
				}
316
			}
317
318
			// attempt to find the superclass if it exists in the cache (otherwise - resolve it when requested)
346
			// attempt to find the superclass if it exists in the cache (otherwise - resolve it when requested)
319
			this.superclass = (ReferenceBinding) this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames);
347
			this.superclass = (ReferenceBinding) this.environment.getTypeFromTypeSignature(wrapper, typeVars, this, missingTypeNames);
320
			this.tagBits |= TagBits.HasUnresolvedSuperclass;
348
			this.tagBits |= TagBits.HasUnresolvedSuperclass;
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (-1 / +142 lines)
Lines 61-67 Link Here
61
// Debug
61
// Debug
62
static {
62
static {
63
//	 org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
63
//	 org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
64
//	TESTS_NAMES = new String[] {"testBug306223"};
64
//	TESTS_NAMES = new String[] {"testBug325418b"};
65
}
65
}
66
66
67
public JavaSearchBugsTests(String name) {
67
public JavaSearchBugsTests(String name) {
Lines 12337-12340 Link Here
12337
		"src/b324109/X.java void b324109.X.run() [run] POTENTIAL_MATCH"
12337
		"src/b324109/X.java void b324109.X.run() [run] POTENTIAL_MATCH"
12338
	);
12338
	);
12339
}
12339
}
12340
12341
/**
12342
 * @bug 325418: [search] Search for method declarations returns spurious potential matches for anonymous classes
12343
 * @test search of method declarations of binary anonymous classes using 
12344
 * 		 enclosing method's type variables should yield correct results.
12345
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=325418"
12346
 */
12347
public void testBug325418a() throws Exception {
12348
	try
12349
	{
12350
		IJavaProject p = createJavaProject("P", new String[] {}, new String[] {"/P/lib325418.jar","JCL15_LIB"}, "","1.5");
12351
		org.eclipse.jdt.core.tests.util.Util.createJar(new String[] {
12352
				"p325418/Test.java",
12353
				"package p325418;\n" +
12354
				"public class Test{\n"+	
12355
				"	public <T> T foo() {\n"+	
12356
				"		return new Inner<T>() {T  run() {  return null;  }}.run();\n"+		 
12357
				"	}\n"+	
12358
				"}\n"+	
12359
				"abstract class Inner <T> {\n"+	
12360
				"	 abstract T run();\n"+	
12361
				"}\n"
12362
			}, p.getProject().getLocation().append("lib325418.jar").toOSString(), "1.5");
12363
			refresh(p);
12364
		//addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b325418.jar"), null, null));
12365
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12366
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { p }, mask);
12367
		search("Inner.run()", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, scope, this.resultCollector);
12368
		assertSearchResults("Unexpected search results!", 
12369
				"lib325418.jar T p325418.Inner.run() [No source] EXACT_MATCH\n" + 
12370
				"lib325418.jar T p325418.<anonymous>.run() [No source] EXACT_MATCH",
12371
				this.resultCollector);		
12372
	} finally {
12373
		deleteProject("P");
12374
	}
12375
}
12376
// local named class instead of anonymous class
12377
public void testBug325418b() throws Exception {
12378
	try
12379
	{
12380
		IJavaProject p = createJavaProject("P", new String[] {}, new String[] {"/P/lib325418.jar","JCL15_LIB"}, "","1.5");
12381
		org.eclipse.jdt.core.tests.util.Util.createJar(new String[] {
12382
				"p325418/Test.java",
12383
				"package p325418;\n" +
12384
				"public class Test {\n" +	
12385
				"	public <T> T foo() {\n" +
12386
				"		class ExtendsInner extends Inner<T> {\n" +
12387
				"			T run() { return null; } \n" +
12388
				"		} \n" +
12389
				"		return null; \n" +	 
12390
				"	} \n" +
12391
				"} \n" +
12392
				"abstract class Inner <T> {\n" +
12393
				"	 abstract T run();\n" +
12394
				"}"
12395
			}, p.getProject().getLocation().append("lib325418.jar").toOSString(), "1.5");
12396
			refresh(p);
12397
		//addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b325418.jar"), null, null));
12398
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12399
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { p }, mask);
12400
		search("Inner.run", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, scope, this.resultCollector);
12401
		assertSearchResults("Unexpected search results!", 
12402
				"lib325418.jar T p325418.Inner.run() [No source] EXACT_MATCH\n" + 
12403
				"lib325418.jar T p325418.ExtendsInner.run() [No source] EXACT_MATCH",
12404
				this.resultCollector);		
12405
	} finally {
12406
		deleteProject("P");
12407
	}
12408
}
12409
// should work good even if both the inner type and the enclosing methods have type variables
12410
public void testBug325418c() throws Exception {
12411
	try
12412
	{
12413
		IJavaProject p = createJavaProject("P", new String[] {}, new String[] {"/P/lib325418.jar","JCL15_LIB"}, "","1.5");
12414
		org.eclipse.jdt.core.tests.util.Util.createJar(new String[] {
12415
				"p325418/Test.java",
12416
				"package p325418;\n" +
12417
				"public class Test {\n" +	
12418
				"	public <T> T foo() {\n" +
12419
				"		class ExtendsInner<U> extends Inner<T, U> {\n" +
12420
				"			T run() { return null; } \n" +
12421
				"			T run(U obj) { return null; } \n" +
12422
				"		} \n" +
12423
				"		return null; \n" +	 
12424
				"	} \n" +
12425
				"} \n" +
12426
				"abstract class Inner <T, U> {\n" +
12427
				"	 abstract T run();\n" +
12428
				"	 abstract T run(U obj);\n" +
12429
				"}"
12430
			}, p.getProject().getLocation().append("lib325418.jar").toOSString(), "1.5");
12431
			refresh(p);
12432
		//addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b325418.jar"), null, null));
12433
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12434
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { p }, mask);
12435
		search("Inner.run", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, scope, this.resultCollector);
12436
		assertSearchResults("Unexpected search results!", 
12437
				"lib325418.jar T p325418.Inner.run() [No source] EXACT_MATCH\n" + 
12438
				"lib325418.jar T p325418.Inner.run(U) [No source] EXACT_MATCH\n" + 
12439
				"lib325418.jar T p325418.ExtendsInner.run() [No source] EXACT_MATCH\n" + 
12440
				"lib325418.jar T p325418.ExtendsInner.run(U) [No source] EXACT_MATCH",
12441
				this.resultCollector);		
12442
	} finally {
12443
		deleteProject("P");
12444
	}
12445
}
12446
// should work good even if the enclosing method having type variables is more than one level
12447
public void testBug325418d() throws Exception {
12448
	try
12449
	{
12450
		IJavaProject p = createJavaProject("P", new String[] {}, new String[] {"/P/lib325418.jar","JCL15_LIB"}, "","1.5");
12451
		org.eclipse.jdt.core.tests.util.Util.createJar(new String[] {
12452
				"p325418/Test.java",
12453
				"package p325418;\n" +
12454
				"public class Test {\n" +
12455
				"	public <T> T foo() {\n" +
12456
				"		class Inner {\n" +
12457
				"			T run() {\n" +
12458
				"				return new TwoLevelInner<T>() {T  run() {  return null;  }}.run();\n" +
12459
				"			}\n" +
12460
				"		}\n" +
12461
				"		return null;\n" +
12462
				"	}\n" +
12463
				"}\n" +
12464
				"abstract class TwoLevelInner <T> {\n" +
12465
				"	 abstract T run();\n" +
12466
				"}\n"
12467
			}, p.getProject().getLocation().append("lib325418.jar").toOSString(), "1.5");
12468
			refresh(p);
12469
		//addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b325418.jar"), null, null));
12470
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES ;
12471
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { p }, mask);
12472
		search("TwoLevelInner.run", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, scope, this.resultCollector);
12473
		assertSearchResults("Unexpected search results!", 
12474
				"lib325418.jar T p325418.<anonymous>.run() [No source] EXACT_MATCH\n" + 
12475
				"lib325418.jar T p325418.TwoLevelInner.run() [No source] EXACT_MATCH",
12476
				this.resultCollector);		
12477
	} finally {
12478
		deleteProject("P");
12479
	}
12480
}
12340
}
12481
}

Return to bug 325418