### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java,v retrieving revision 1.126 diff -u -r1.126 CompilationUnitScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 22 Apr 2009 19:49:57 -0000 1.126 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 13 Apr 2010 14:36:18 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -381,7 +381,7 @@ ReferenceBinding conflictingType = null; if (importBinding instanceof MethodBinding) { conflictingType = (ReferenceBinding) getType(compoundName, compoundName.length); - if (!conflictingType.isValidBinding()) + if (!conflictingType.isValidBinding() || (importReference.isStatic() && !conflictingType.isStatic())) conflictingType = null; } // collisions between an imported static field & a type should be checked according to spec... but currently not by javac @@ -396,8 +396,12 @@ ReferenceBinding existingType = typesBySimpleNames.get(compoundName[compoundName.length - 1]); if (existingType != null) { // duplicate test above should have caught this case, but make sure - if (existingType == referenceBinding) + if (existingType == referenceBinding) { + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 + problemReporter().duplicateImport(importReference); + resolvedImports[index++] = new ImportBinding(compoundName, false, importBinding, importReference); continue nextImport; + } // either the type collides with a top level type or another imported type for (int j = 0, length = this.topLevelTypes.length; j < length; j++) { if (CharOperation.equals(this.topLevelTypes[j].sourceName, existingType.sourceName)) { #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java,v retrieving revision 1.78 diff -u -r1.78 StaticImportTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 9 Mar 2010 04:28:15 -0000 1.78 +++ src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 13 Apr 2010 14:36:21 -0000 @@ -489,42 +489,47 @@ "}\n", }, "----------\n" + - "1. ERROR in X.java (at line 6)\r\n" + + "1. ERROR in X.java (at line 3)\n" + + " import static p.Z.Zz.WW;\n" + + " ^^^^^^^^^\n" + + "The import p.Z.Zz.WW collides with another import statement\n" + + "----------\n" + + "2. ERROR in X.java (at line 6)\r\n" + " import static p.Y.Zz;\r\n" + " ^^^^^^\n" + "The import p.Y.Zz cannot be resolved\n" + "----------\n" + - "2. ERROR in X.java (at line 7)\r\n" + + "3. ERROR in X.java (at line 7)\r\n" + " import static p.Z.Zz.WW.*;\r\n" + " ^^^^^^^^^\n" + "The import p.Z.Zz.WW cannot be resolved\n" + "----------\n" + - "3. ERROR in X.java (at line 8)\r\n" + + "4. ERROR in X.java (at line 8)\r\n" + " import p.Y.ZZ;\r\n" + " ^^^^^^\n" + "The import p.Y.ZZ cannot be resolved\n" + "----------\n" + - "4. ERROR in X.java (at line 9)\r\n" + + "5. ERROR in X.java (at line 9)\r\n" + " import static p.Y.ZZ.*;\r\n" + " ^^^^^^\n" + "The import p.Y.ZZ cannot be resolved\n" + "----------\n" + - "5. ERROR in X.java (at line 10)\r\n" + + "6. ERROR in X.java (at line 10)\r\n" + " import static p.Y.ZZ.WW;\r\n" + " ^^^^^^\n" + "The import p.Y.ZZ cannot be resolved\n" + "----------\n" + - "6. ERROR in X.java (at line 11)\r\n" + + "7. ERROR in X.java (at line 11)\r\n" + " import static p.Y.ZZ.WW.*;\r\n" + " ^^^^^^\n" + "The import p.Y.ZZ cannot be resolved\n" + "----------\n" + - "7. ERROR in X.java (at line 12)\r\n" + + "8. ERROR in X.java (at line 12)\r\n" + " import static p.Y.ZZ.ZZZ;\r\n" + " ^^^^^^\n" + "The import p.Y.ZZ cannot be resolved\n" + "----------\n" + - "8. ERROR in X.java (at line 13)\r\n" + + "9. ERROR in X.java (at line 13)\r\n" + " import static p.Y.ZZ.WW.WWW;\r\n" + " ^^^^^^\n" + "The import p.Y.ZZ cannot be resolved\n" + @@ -2533,5 +2538,67 @@ }, ""); } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 + // To verify that a static import importing a type which has already been + // imported by a single type import is reported as duplicate + // while the other static members imported by it are not shadowed. + public void test075() { + this.runNegativeTest( + new String[] { + "A/A.java", + "package A;\n" + + "import B.B.C1;\n" + + "import static B.B.C1;\n" + + "public abstract class A {\n" + + " protected void A1(Object task) {\n" + + " C1 c = C1(task);\n" + + " }\n" + + "}\n", + "B/B.java", + "package B;\n" + + "final public class B {\n" + + " private B() {}\n" + + " public static class C1 {}\n" + + " public static C1 C1(Object o) {\n" + + " return new C1();\n" + + " }\n" + + "}\n", + }, + "----------\n" + + "1. ERROR in A\\A.java (at line 3)\n" + + " import static B.B.C1;\n" + + " ^^^^^^\n" + + "The import B.B.C1 collides with another import statement\n" + + "----------\n" + ); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 + // To verify that a static import importing a static method doesnt collide + // with a single type import importing a non-static type with the same name as the method + public void test076() { + this.runConformTest( + new String[] { + "A/A.java", + "package A;\n" + + "import B.B.C1;\n" + + "import static B.B.C1;\n" + + "public class A {\n" + + " protected void A1(Object task) {\n" + + " C1 c1;\n" + + " int c = C1(task);\n" + + " }\n" + + "}\n", + "B/B.java", + "package B;\n" + + "final public class B {\n" + + " private B() {}\n" + + " public class C1 {}\n" + + " public static int C1(Object o) {\n" + + " return 1;\n" + + " }\n" + + "}\n", + }, + ""); + } }