Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 250975
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/eval/target/CodeSnippetClassLoader.java (-1 / +1 lines)
Lines 40-46 Link Here
40
 * If only  the class definition is known to this runner, makes it a class and returns it.
40
 * If only  the class definition is known to this runner, makes it a class and returns it.
41
 * Otherwise delegates to the real class loader.
41
 * Otherwise delegates to the real class loader.
42
 */
42
 */
43
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
43
protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
44
	if (DEVELOPMENT_MODE) {
44
	if (DEVELOPMENT_MODE) {
45
		try {
45
		try {
46
			return delegateLoadClass(name);
46
			return delegateLoadClass(name);
(-)src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java (+85 lines)
Lines 2404-2408 Link Here
2404
			},
2404
			},
2405
			"");
2405
			"");
2406
	}
2406
	}
2407
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211
2408
	public void test070() {
2409
		this.runConformTest(
2410
			new String[] {
2411
				"node/Test.java",//------------------------------
2412
				"package node;\n" + 
2413
				"public class Test {\n" + 
2414
				"        public static void node() {}\n" + 
2415
				"}\n",
2416
				"node2/Test2.java",//------------------------------
2417
				"package node2;\n" + 
2418
				"import static node.Test.node;\n" + 
2419
				"public class Test2 {\n" + 
2420
				"}\n",
2421
			},
2422
			"");
2423
	}	
2424
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation
2425
	public void test071() {
2426
		this.runNegativeTest(
2427
			new String[] {
2428
				"node/Test/node.java",//------------------------------
2429
				"package node.Test;\n" + 
2430
				"public class node {\n" + 
2431
				"}\n",					
2432
				"node/Test.java",//------------------------------
2433
				"package node;\n" + 
2434
				"public class Test {\n" + 
2435
				"        public static void node() {}\n" + 
2436
				"}\n",
2437
				"node2/Test2.java",//------------------------------
2438
				"package node2;\n" + 
2439
				"import node.Test;\n" +
2440
				"import static Test.node;\n" + 
2441
				"public class Test2 {\n" + 
2442
				"}\n",
2443
			},
2444
			"----------\n" + 
2445
			"1. WARNING in node\\Test.java (at line 2)\n" + 
2446
			"	public class Test {\n" + 
2447
			"	             ^^^^\n" + 
2448
			"The type Test collides with a package\n" + 
2449
			"----------\n" + 
2450
			"----------\n" + 
2451
			"1. ERROR in node2\\Test2.java (at line 3)\n" + 
2452
			"	import static Test.node;\n" + 
2453
			"	              ^^^^\n" + 
2454
			"The import Test cannot be resolved\n" + 
2455
			"----------\n");
2456
	}		
2457
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=93913 - variation
2458
	public void test072() {
2459
		this.runNegativeTest(
2460
			new String[] {
2461
				"p1/A.java",
2462
				"package p1;\n" +
2463
				"import static p2.C.B;\n" +
2464
				"public class A extends B {\n" +
2465
				"	void test() {" +
2466
				"		int i = B;\n" +
2467
				"		B b = null;\n" +
2468
				"		int v1 = b.fooB;\n" +
2469
				"		int v2 = b.fooC;\n" +
2470
				"		int v3 = fooC;\n" +
2471
				"	}\n" +
2472
				"}\n",
2473
				"p1/B.java",
2474
				"package p1;\n" +
2475
				"public class B {\n" +
2476
				"	public int fooB;\n" +
2477
				"}\n",
2478
				"p2/C.java",
2479
				"package p2;\n" +
2480
				"public class C {\n" +
2481
				"	public static class B { public int fooC; }\n" +
2482
				"	public static int B;\n" +
2483
				"}\n",
2484
			},
2485
			"----------\n" + 
2486
			"1. ERROR in p1\\A.java (at line 7)\n" + 
2487
			"	int v2 = b.fooC;\n" + 
2488
			"	         ^^^^^^\n" + 
2489
			"b.fooC cannot be resolved or is not a field\n" + 
2490
			"----------\n");
2491
	}	
2407
}
2492
}
2408
2493
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (+94 lines)
Lines 2935-2940 Link Here
2935
		"The type X cannot be a superinterface of Member; a superinterface must be an interface\n" + 
2935
		"The type X cannot be a superinterface of Member; a superinterface must be an interface\n" + 
2936
		"----------\n");
2936
		"----------\n");
2937
}
2937
}
2938
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation
2939
public void test091() {
2940
	this.runNegativeTest(
2941
		new String[] {
2942
			"foo/Test.java",//------------------------------
2943
			"package foo;\n" + 
2944
			"public class Test {\n" + 
2945
			"        public class M1 {\n" +
2946
			"              public class M2 {}\n" +
2947
			"        }\n" +
2948
			"}\n",
2949
			"bar/Test2.java",//------------------------------
2950
			"package bar;\n" + 
2951
			"import foo.Test;\n" + 
2952
			"import Test.M1.M2;\n" + 
2953
			"public class Test2 {\n" + 
2954
			"}\n",
2955
		},
2956
		"----------\n" + 
2957
		"1. ERROR in bar\\Test2.java (at line 3)\n" + 
2958
		"	import Test.M1.M2;\n" + 
2959
		"	       ^^^^\n" + 
2960
		"The import Test cannot be resolved\n" + 
2961
		"----------\n");
2962
}
2963
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation
2964
public void test092() {
2965
	this.runNegativeTest(
2966
		new String[] {
2967
			"foo/Test.java",//------------------------------
2968
			"package foo;\n" + 
2969
			"public class Test {\n" + 
2970
			"        public class M1 {\n" +
2971
			"              public class M2 {}\n" +
2972
			"        }\n" +
2973
			"}\n",
2974
			"bar/Test2.java",//------------------------------
2975
			"package bar;\n" + 
2976
			"import foo.*;\n" + 
2977
			"import Test.M1.M2;\n" + 
2978
			"public class Test2 {\n" + 
2979
			"}\n",
2980
		},
2981
		"----------\n" + 
2982
		"1. ERROR in bar\\Test2.java (at line 3)\n" + 
2983
		"	import Test.M1.M2;\n" + 
2984
		"	       ^^^^\n" + 
2985
		"The import Test cannot be resolved\n" + 
2986
		"----------\n");
2987
}
2988
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation
2989
public void test093() {
2990
	this.runNegativeTest(
2991
		new String[] {
2992
			"foo/Test.java",//------------------------------
2993
			"package foo;\n" + 
2994
			"public class Test {\n" + 
2995
			"        public class M1 {\n" +
2996
			"              public class foo {}\n" +
2997
			"        }\n" +
2998
			"}\n",
2999
			"bar/Test2.java",//------------------------------
3000
			"package bar;\n" + 
3001
			"import foo.Test;\n" + 
3002
			"import Test.M1.foo;\n" + 
3003
			"public class Test2 {\n" + 
3004
			"}\n",
3005
		},
3006
		"----------\n" + 
3007
		"1. ERROR in bar\\Test2.java (at line 3)\n" + 
3008
		"	import Test.M1.foo;\n" + 
3009
		"	       ^^^^\n" + 
3010
		"The import Test cannot be resolved\n" + 
3011
		"----------\n");
3012
}	
3013
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=250211 - variation
3014
public void test094() {
3015
	this.runConformTest(
3016
		new String[] {
3017
			"foo/Test.java",//------------------------------
3018
			"package foo;\n" + 
3019
			"public class Test {\n" + 
3020
			"        public class M1 {\n" +
3021
			"              public class foo {}\n" +
3022
			"        }\n" +
3023
			"}\n",
3024
			"bar/Test2.java",//------------------------------
3025
			"package bar;\n" + 
3026
			"import foo.Test.M1.foo;\n" + 
3027
			"public class Test2 {\n" + 
3028
			"}\n",
3029
		},
3030
		"");
3031
}	
2938
public static Class testClass() {	return LookupTest.class;
3032
public static Class testClass() {	return LookupTest.class;
2939
}
3033
}
2940
}
3034
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java (-10 / +10 lines)
Lines 356-362 Link Here
356
			}
356
			}
357
			resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference);
357
			resolvedImports[index++] = new ImportBinding(compoundName, true, importBinding, importReference);
358
		} else {
358
		} else {
359
			Binding importBinding = findSingleImport(compoundName, importReference.isStatic());
359
			Binding importBinding = findSingleImport(compoundName, Binding.TYPE | Binding.FIELD | Binding.METHOD, importReference.isStatic());
360
			if (!importBinding.isValidBinding()) {
360
			if (!importBinding.isValidBinding()) {
361
				if (importBinding.problemId() == ProblemReasons.Ambiguous) {
361
				if (importBinding.problemId() == ProblemReasons.Ambiguous) {
362
					// keep it unless a duplicate can be found below
362
					// keep it unless a duplicate can be found below
Lines 442-448 Link Here
442
	if(onDemand) {
442
	if(onDemand) {
443
		return findImport(compoundName, compoundName.length);
443
		return findImport(compoundName, compoundName.length);
444
	} else {
444
	} else {
445
		return findSingleImport(compoundName, findStaticImports);
445
		return findSingleImport(compoundName, Binding.TYPE | Binding.FIELD | Binding.METHOD, findStaticImports);
446
	}
446
	}
447
}
447
}
448
private Binding findImport(char[][] compoundName, int length) {
448
private Binding findImport(char[][] compoundName, int length) {
Lines 493-499 Link Here
493
		return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotVisible);
493
		return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotVisible);
494
	return type;
494
	return type;
495
}
495
}
496
private Binding findSingleImport(char[][] compoundName, boolean findStaticImports) {
496
private Binding findSingleImport(char[][] compoundName, int mask, boolean findStaticImports) {
497
	if (compoundName.length == 1) {
497
	if (compoundName.length == 1) {
498
		// findType records the reference
498
		// findType records the reference
499
		// the name cannot be a package
499
		// the name cannot be a package
Lines 506-515 Link Here
506
	}
506
	}
507
507
508
	if (findStaticImports)
508
	if (findStaticImports)
509
		return findSingleStaticImport(compoundName);
509
		return findSingleStaticImport(compoundName, mask);
510
	return findImport(compoundName, compoundName.length);
510
	return findImport(compoundName, compoundName.length);
511
}
511
}
512
private Binding findSingleStaticImport(char[][] compoundName) {
512
private Binding findSingleStaticImport(char[][] compoundName, int mask) {
513
	Binding binding = findImport(compoundName, compoundName.length - 1);
513
	Binding binding = findImport(compoundName, compoundName.length - 1);
514
	if (!binding.isValidBinding()) return binding;
514
	if (!binding.isValidBinding()) return binding;
515
515
Lines 523-529 Link Here
523
523
524
	// look to see if its a static field first
524
	// look to see if its a static field first
525
	ReferenceBinding type = (ReferenceBinding) binding;
525
	ReferenceBinding type = (ReferenceBinding) binding;
526
	FieldBinding field = findField(type, name, null, true);
526
	FieldBinding field = (mask & Binding.FIELD) != 0 ? findField(type, name, null, true) : null;
527
	if (field != null) {
527
	if (field != null) {
528
		if (field.problemId() == ProblemReasons.Ambiguous && ((ProblemFieldBinding) field).closestMatch.isStatic())
528
		if (field.problemId() == ProblemReasons.Ambiguous && ((ProblemFieldBinding) field).closestMatch.isStatic())
529
			return field; // keep the ambiguous field instead of a possible method match
529
			return field; // keep the ambiguous field instead of a possible method match
Lines 532-538 Link Here
532
	}
532
	}
533
533
534
	// look to see if there is a static method with the same selector
534
	// look to see if there is a static method with the same selector
535
	MethodBinding method = findStaticMethod(type, name);
535
	MethodBinding method = (mask & Binding.METHOD) != 0 ? findStaticMethod(type, name) : null;
536
	if (method != null) return method;
536
	if (method != null) return method;
537
537
538
	type = findMemberType(name, type);
538
	type = findMemberType(name, type);
Lines 589-595 Link Here
589
public final Binding getImport(char[][] compoundName, boolean onDemand, boolean isStaticImport) {
589
public final Binding getImport(char[][] compoundName, boolean onDemand, boolean isStaticImport) {
590
	if (onDemand)
590
	if (onDemand)
591
		return findImport(compoundName, compoundName.length);
591
		return findImport(compoundName, compoundName.length);
592
	return findSingleImport(compoundName, isStaticImport);
592
	return findSingleImport(compoundName, Binding.TYPE | Binding.FIELD | Binding.METHOD, isStaticImport);
593
}
593
}
594
594
595
public int nextCaptureID() {
595
public int nextCaptureID() {
Lines 708-716 Link Here
708
			referencedTypes.add(actualType);
708
			referencedTypes.add(actualType);
709
	}
709
	}
710
}
710
}
711
Binding resolveSingleImport(ImportBinding importBinding) {
711
Binding resolveSingleImport(ImportBinding importBinding, int mask) {
712
	if (importBinding.resolvedImport == null) {
712
	if (importBinding.resolvedImport == null) {
713
		importBinding.resolvedImport = findSingleImport(importBinding.compoundName, importBinding.isStatic());
713
		importBinding.resolvedImport = findSingleImport(importBinding.compoundName, mask, importBinding.isStatic());
714
		if (!importBinding.resolvedImport.isValidBinding() || importBinding.resolvedImport instanceof PackageBinding) {
714
		if (!importBinding.resolvedImport.isValidBinding() || importBinding.resolvedImport instanceof PackageBinding) {
715
			if (importBinding.resolvedImport.problemId() == ProblemReasons.Ambiguous)
715
			if (importBinding.resolvedImport.problemId() == ProblemReasons.Ambiguous)
716
				return importBinding.resolvedImport;
716
				return importBinding.resolvedImport;
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-6 / +2 lines)
Lines 1576-1582 Link Here
1576
							ImportBinding importBinding = imports[i];
1576
							ImportBinding importBinding = imports[i];
1577
							if (importBinding.isStatic() && !importBinding.onDemand) {
1577
							if (importBinding.isStatic() && !importBinding.onDemand) {
1578
								if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
1578
								if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
1579
									if (unitScope.resolveSingleImport(importBinding) != null && importBinding.resolvedImport instanceof FieldBinding) {
1579
									if (unitScope.resolveSingleImport(importBinding, Binding.TYPE | Binding.FIELD | Binding.METHOD) != null && importBinding.resolvedImport instanceof FieldBinding) {
1580
										foundField = (FieldBinding) importBinding.resolvedImport;
1580
										foundField = (FieldBinding) importBinding.resolvedImport;
1581
										ImportReference importReference = importBinding.reference;
1581
										ImportReference importReference = importBinding.reference;
1582
										if (importReference != null && needResolve) {
1582
										if (importReference != null && needResolve) {
Lines 2437-2448 Link Here
2437
					ImportBinding importBinding = imports[i];
2437
					ImportBinding importBinding = imports[i];
2438
					if (!importBinding.onDemand) {
2438
					if (!importBinding.onDemand) {
2439
						if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
2439
						if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
2440
							Binding resolvedImport = unitScope.resolveSingleImport(importBinding);
2440
							Binding resolvedImport = unitScope.resolveSingleImport(importBinding, Binding.TYPE);
2441
							if (resolvedImport == null) continue nextImport;
2441
							if (resolvedImport == null) continue nextImport;
2442
							if (resolvedImport instanceof MethodBinding) {
2443
								resolvedImport = getType(importBinding.compoundName, importBinding.compoundName.length);
2444
								if (!resolvedImport.isValidBinding()) continue nextImport;
2445
							}
2446
							if (resolvedImport instanceof TypeBinding) {
2442
							if (resolvedImport instanceof TypeBinding) {
2447
								ImportReference importReference = importBinding.reference;
2443
								ImportReference importReference = importBinding.reference;
2448
								if (importReference != null)
2444
								if (importReference != null)

Return to bug 250975