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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java (-3 / +7 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 381-387 Link Here
381
			ReferenceBinding conflictingType = null;
381
			ReferenceBinding conflictingType = null;
382
			if (importBinding instanceof MethodBinding) {
382
			if (importBinding instanceof MethodBinding) {
383
				conflictingType = (ReferenceBinding) getType(compoundName, compoundName.length);
383
				conflictingType = (ReferenceBinding) getType(compoundName, compoundName.length);
384
				if (!conflictingType.isValidBinding())
384
				if (!conflictingType.isValidBinding() || (importReference.isStatic() && !conflictingType.isStatic()))
385
					conflictingType = null;
385
					conflictingType = null;
386
			}
386
			}
387
			// collisions between an imported static field & a type should be checked according to spec... but currently not by javac
387
			// collisions between an imported static field & a type should be checked according to spec... but currently not by javac
Lines 396-403 Link Here
396
				ReferenceBinding existingType = typesBySimpleNames.get(compoundName[compoundName.length - 1]);
396
				ReferenceBinding existingType = typesBySimpleNames.get(compoundName[compoundName.length - 1]);
397
				if (existingType != null) {
397
				if (existingType != null) {
398
					// duplicate test above should have caught this case, but make sure
398
					// duplicate test above should have caught this case, but make sure
399
					if (existingType == referenceBinding)
399
					if (existingType == referenceBinding) {
400
						// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865
401
						problemReporter().duplicateImport(importReference);
402
						resolvedImports[index++] = new ImportBinding(compoundName, false, importBinding, importReference);
400
						continue nextImport;
403
						continue nextImport;
404
					}
401
					// either the type collides with a top level type or another imported type
405
					// either the type collides with a top level type or another imported type
402
					for (int j = 0, length = this.topLevelTypes.length; j < length; j++) {
406
					for (int j = 0, length = this.topLevelTypes.length; j < length; j++) {
403
						if (CharOperation.equals(this.topLevelTypes[j].sourceName, existingType.sourceName)) {
407
						if (CharOperation.equals(this.topLevelTypes[j].sourceName, existingType.sourceName)) {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java (-8 / +75 lines)
Lines 489-530 Link Here
489
				"}\n",
489
				"}\n",
490
			},
490
			},
491
			"----------\n" +
491
			"----------\n" +
492
			"1. ERROR in X.java (at line 6)\r\n" +
492
			"1. ERROR in X.java (at line 3)\n" +
493
			"	import static p.Z.Zz.WW;\n" +
494
			"	              ^^^^^^^^^\n" +
495
			"The import p.Z.Zz.WW collides with another import statement\n" +
496
			"----------\n" +
497
			"2. ERROR in X.java (at line 6)\r\n" +
493
			"	import static p.Y.Zz;\r\n" +
498
			"	import static p.Y.Zz;\r\n" +
494
			"	              ^^^^^^\n" +
499
			"	              ^^^^^^\n" +
495
			"The import p.Y.Zz cannot be resolved\n" +
500
			"The import p.Y.Zz cannot be resolved\n" +
496
			"----------\n" +
501
			"----------\n" +
497
			"2. ERROR in X.java (at line 7)\r\n" +
502
			"3. ERROR in X.java (at line 7)\r\n" +
498
			"	import static p.Z.Zz.WW.*;\r\n" +
503
			"	import static p.Z.Zz.WW.*;\r\n" +
499
			"	              ^^^^^^^^^\n" +
504
			"	              ^^^^^^^^^\n" +
500
			"The import p.Z.Zz.WW cannot be resolved\n" +
505
			"The import p.Z.Zz.WW cannot be resolved\n" +
501
			"----------\n" +
506
			"----------\n" +
502
			"3. ERROR in X.java (at line 8)\r\n" +
507
			"4. ERROR in X.java (at line 8)\r\n" +
503
			"	import p.Y.ZZ;\r\n" +
508
			"	import p.Y.ZZ;\r\n" +
504
			"	       ^^^^^^\n" +
509
			"	       ^^^^^^\n" +
505
			"The import p.Y.ZZ cannot be resolved\n" +
510
			"The import p.Y.ZZ cannot be resolved\n" +
506
			"----------\n" +
511
			"----------\n" +
507
			"4. ERROR in X.java (at line 9)\r\n" +
512
			"5. ERROR in X.java (at line 9)\r\n" +
508
			"	import static p.Y.ZZ.*;\r\n" +
513
			"	import static p.Y.ZZ.*;\r\n" +
509
			"	              ^^^^^^\n" +
514
			"	              ^^^^^^\n" +
510
			"The import p.Y.ZZ cannot be resolved\n" +
515
			"The import p.Y.ZZ cannot be resolved\n" +
511
			"----------\n" +
516
			"----------\n" +
512
			"5. ERROR in X.java (at line 10)\r\n" +
517
			"6. ERROR in X.java (at line 10)\r\n" +
513
			"	import static p.Y.ZZ.WW;\r\n" +
518
			"	import static p.Y.ZZ.WW;\r\n" +
514
			"	              ^^^^^^\n" +
519
			"	              ^^^^^^\n" +
515
			"The import p.Y.ZZ cannot be resolved\n" +
520
			"The import p.Y.ZZ cannot be resolved\n" +
516
			"----------\n" +
521
			"----------\n" +
517
			"6. ERROR in X.java (at line 11)\r\n" +
522
			"7. ERROR in X.java (at line 11)\r\n" +
518
			"	import static p.Y.ZZ.WW.*;\r\n" +
523
			"	import static p.Y.ZZ.WW.*;\r\n" +
519
			"	              ^^^^^^\n" +
524
			"	              ^^^^^^\n" +
520
			"The import p.Y.ZZ cannot be resolved\n" +
525
			"The import p.Y.ZZ cannot be resolved\n" +
521
			"----------\n" +
526
			"----------\n" +
522
			"7. ERROR in X.java (at line 12)\r\n" +
527
			"8. ERROR in X.java (at line 12)\r\n" +
523
			"	import static p.Y.ZZ.ZZZ;\r\n" +
528
			"	import static p.Y.ZZ.ZZZ;\r\n" +
524
			"	              ^^^^^^\n" +
529
			"	              ^^^^^^\n" +
525
			"The import p.Y.ZZ cannot be resolved\n" +
530
			"The import p.Y.ZZ cannot be resolved\n" +
526
			"----------\n" +
531
			"----------\n" +
527
			"8. ERROR in X.java (at line 13)\r\n" +
532
			"9. ERROR in X.java (at line 13)\r\n" +
528
			"	import static p.Y.ZZ.WW.WWW;\r\n" +
533
			"	import static p.Y.ZZ.WW.WWW;\r\n" +
529
			"	              ^^^^^^\n" +
534
			"	              ^^^^^^\n" +
530
			"The import p.Y.ZZ cannot be resolved\n" +
535
			"The import p.Y.ZZ cannot be resolved\n" +
Lines 2533-2537 Link Here
2533
			},
2538
			},
2534
			"");
2539
			"");
2535
	}		
2540
	}		
2541
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865
2542
	// To verify that a static import importing a type which has already been
2543
	// imported by a single type import is reported as duplicate
2544
	// while the other static members imported by it are not shadowed.
2545
	public void test075() {
2546
		this.runNegativeTest(
2547
			new String[] {
2548
				"A/A.java",
2549
				"package A;\n" +
2550
				"import B.B.C1;\n" +
2551
				"import static B.B.C1;\n" +
2552
				"public abstract class A {\n" +
2553
				"	protected void A1(Object task) {\n" +
2554
				"		C1 c = C1(task);\n" +
2555
				"	}\n" +
2556
				"}\n",
2557
				"B/B.java",
2558
				"package B;\n" +
2559
				"final public class B {\n" +
2560
				"	private B() {}\n" +
2561
				"	public static class C1 {}\n" +
2562
				"	public static C1 C1(Object o) {\n" +
2563
				"		return new C1();\n" +
2564
				"	}\n" +
2565
				"}\n",
2566
			},
2567
			"----------\n" +
2568
			"1. ERROR in A\\A.java (at line 3)\n" +
2569
			"	import static B.B.C1;\n" +
2570
			"	              ^^^^^^\n" +
2571
			"The import B.B.C1 collides with another import statement\n" +
2572
			"----------\n"
2573
		);
2574
	}
2575
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865
2576
	// To verify that a static import importing a static method doesnt collide
2577
	// with a single type import importing a non-static type with the same name as the method
2578
	public void test076() {
2579
		this.runConformTest(
2580
			new String[] {
2581
				"A/A.java",
2582
				"package A;\n" +
2583
				"import B.B.C1;\n" +
2584
				"import static B.B.C1;\n" +
2585
				"public class A {\n" +
2586
				"	protected void A1(Object task) {\n" +
2587
				"		C1 c1;\n" +
2588
				"		int c = C1(task);\n" +
2589
				"	}\n" +
2590
				"}\n",
2591
				"B/B.java",
2592
				"package B;\n" +
2593
				"final public class B {\n" +
2594
				"	private B() {}\n" +
2595
				"	public class C1 {}\n" +
2596
				"	public static int C1(Object o) {\n" +
2597
				"		return 1;\n" +
2598
				"	}\n" +
2599
				"}\n",
2600
			},
2601
			"");
2602
	}
2536
}
2603
}
2537
2604

Return to bug 302865