Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 164880 Details for
Bug 302865
Issue with "import" a class and "import static" a method with the same name
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression tests
patch_302865.txt (text/plain), 15.37 KB, created by
Olivier Thomann
on 2010-04-14 15:27:42 EDT
(
hide
)
Description:
Proposed fix + regression tests
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-04-14 15:27:42 EDT
Size:
15.37 KB
patch
obsolete
>### 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 14 Apr 2010 19:26:37 -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,28 @@ > 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) { >+ for (int j = 0; j < index; j++) { >+ ImportBinding resolved = resolvedImports[j]; >+ if (resolved instanceof ImportConflictBinding) { >+ ImportConflictBinding importConflictBinding = (ImportConflictBinding) resolved; >+ if (importConflictBinding.conflictingTypeBinding == referenceBinding) { >+ if (!importReference.isStatic()) { >+ // resolved is implicitly static >+ problemReporter().duplicateImport(importReference); >+ resolvedImports[index++] = new ImportBinding(compoundName, false, importBinding, importReference); >+ } >+ } >+ } else if (resolved.resolvedImport == referenceBinding) { >+ if (importReference.isStatic() && !resolved.isStatic()) { >+ problemReporter().duplicateImport(importReference); >+ resolvedImports[index++] = new ImportBinding(compoundName, false, importBinding, importReference); >+ } >+ } >+ } >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 > 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 14 Apr 2010 19:26:38 -0000 >@@ -18,8 +18,8 @@ > // All specified tests which do not belong to the class are skipped... > static { > // TESTS_NAMES = new String[] { "test036" }; >-// TESTS_NUMBERS = new int[] { 46 }; >-// TESTS_RANGE = new int[] { 169, 180 }; >+// TESTS_NUMBERS = new int[] { 78 }; >+// TESTS_RANGE = new int[] { 75, -1 }; > } > > public StaticImportTest(String name) { >@@ -488,46 +488,46 @@ > " public static class WW { public static final int WWW = 0; }\n" + > "}\n", > }, >- "----------\n" + >- "1. 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" + >- " 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" + >- " 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" + >- " 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" + >- " 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" + >- " 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" + >- " 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" + >- " import static p.Y.ZZ.WW.WWW;\r\n" + >- " ^^^^^^\n" + >- "The import p.Y.ZZ cannot be resolved\n" + >+ "----------\n" + >+ "1. ERROR in X.java (at line 6)\n" + >+ " import static p.Y.Zz;\n" + >+ " ^^^^^^\n" + >+ "The import p.Y.Zz cannot be resolved\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 7)\n" + >+ " import static p.Z.Zz.WW.*;\n" + >+ " ^^^^^^^^^\n" + >+ "The import p.Z.Zz.WW cannot be resolved\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 8)\n" + >+ " import p.Y.ZZ;\n" + >+ " ^^^^^^\n" + >+ "The import p.Y.ZZ cannot be resolved\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 9)\n" + >+ " import static p.Y.ZZ.*;\n" + >+ " ^^^^^^\n" + >+ "The import p.Y.ZZ cannot be resolved\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 10)\n" + >+ " import static p.Y.ZZ.WW;\n" + >+ " ^^^^^^\n" + >+ "The import p.Y.ZZ cannot be resolved\n" + >+ "----------\n" + >+ "6. ERROR in X.java (at line 11)\n" + >+ " import static p.Y.ZZ.WW.*;\n" + >+ " ^^^^^^\n" + >+ "The import p.Y.ZZ cannot be resolved\n" + >+ "----------\n" + >+ "7. ERROR in X.java (at line 12)\n" + >+ " import static p.Y.ZZ.ZZZ;\n" + >+ " ^^^^^^\n" + >+ "The import p.Y.ZZ cannot be resolved\n" + >+ "----------\n" + >+ "8. ERROR in X.java (at line 13)\n" + >+ " import static p.Y.ZZ.WW.WWW;\n" + >+ " ^^^^^^\n" + >+ "The import p.Y.ZZ cannot be resolved\n" + > "----------\n" > ); > } >@@ -590,8 +590,8 @@ > "public class X {}\n" > }, > "----------\n" + >- "1. ERROR in X.java (at line 1)\r\n" + >- " import static java.lang.*;\r\n" + >+ "1. ERROR in X.java (at line 1)\n" + >+ " import static java.lang.*;\n" + > " ^^^^^^^^^\n" + > "Only a type can be imported. java.lang resolves to a package\n" + > "----------\n" >@@ -887,8 +887,8 @@ > "public class C { public static void m() {} }\n" > }, > "----------\n" + >- "1. ERROR in p\\B.java (at line 5)\r\n" + >- " public class B { public static void main(String[] args) { m(); } }\r\n" + >+ "1. ERROR in p\\B.java (at line 5)\n" + >+ " public class B { public static void main(String[] args) { m(); } }\n" + > " ^\n" + > "The method m() is ambiguous for the type B\n" + > "----------\n" >@@ -1154,8 +1154,8 @@ > "}\n" > }, > "----------\n" + >- "1. ERROR in X2.java (at line 3)\r\n" + >- " public class X2 { void test() {foo();} }\r\n" + >+ "1. ERROR in X2.java (at line 3)\n" + >+ " public class X2 { void test() {foo();} }\n" + > " ^^^\n" + > "The method foo() is ambiguous for the type X2\n" + > "----------\n" >@@ -1313,8 +1313,8 @@ > "}\n" > }, > "----------\n" + >- "1. ERROR in C.java (at line 6)\r\n" + >- " void test() { foo(1); }\r\n" + >+ "1. ERROR in C.java (at line 6)\n" + >+ " void test() { foo(1); }\n" + > " ^^^\n" + > "The method foo(Object, String) in the type A.B is not applicable for the arguments (int)\n" + > "----------\n"); >@@ -1464,18 +1464,18 @@ > "class B { public static int foo_B() { return 2;} }", > }, > "----------\n" + >- "1. ERROR in X.java (at line 1)\r\n" + >- " import static p.A.foo_I;\r\n" + >+ "1. ERROR in X.java (at line 1)\n" + >+ " import static p.A.foo_I;\n" + > " ^^^^^^^^^\n" + > "The import p.A.foo_I cannot be resolved\n" + > "----------\n" + >- "2. ERROR in X.java (at line 4)\r\n" + >- " static int i = p.A.foo_I();\r\n" + >+ "2. ERROR in X.java (at line 4)\n" + >+ " static int i = p.A.foo_I();\n" + > " ^^^^^^^^^^^\n" + > "Cannot make a static reference to the non-static method foo_I() from the type I\n" + > "----------\n" + >- "3. ERROR in X.java (at line 6)\r\n" + >- " static int m = foo_I();\r\n" + >+ "3. ERROR in X.java (at line 6)\n" + >+ " static int m = foo_I();\n" + > " ^^^^^\n" + > "The method foo_I() is undefined for the type X\n" + > "----------\n"); >@@ -1567,8 +1567,8 @@ > "}\n", > }, > "----------\n" + >- "1. ERROR in ImportTest.java (at line 4)\r\n" + >- " static void printArgs(Object... args) { toString2(args); }\r\n" + >+ "1. ERROR in ImportTest.java (at line 4)\n" + >+ " static void printArgs(Object... args) { toString2(args); }\n" + > " ^^^^^^^^^\n" + > "The method toString2() in the type SuperTest is not applicable for the arguments (Object[])\n" + > "----------\n" >@@ -1715,8 +1715,8 @@ > "public class Three extends Two { public static void test(String s) { arrayList(s); } }\n", > }, > "----------\n" + >- "1. ERROR in test\\Three.java (at line 3)\r\n" + >- " public class Three extends Two { public static void test(String s) { arrayList(s); } }\r\n" + >+ "1. ERROR in test\\Three.java (at line 3)\n" + >+ " public class Three extends Two { public static void test(String s) { arrayList(s); } }\n" + > " ^^^^^^^^^\n" + > "The method arrayList(int) in the type Two is not applicable for the arguments (String)\n" + > "----------\n" >@@ -2221,8 +2221,8 @@ > "}\n", > }, > "----------\n" + >- "1. ERROR in p\\X.java (at line 2)\r\n" + >- " import static q.A.a;\r\n" + >+ "1. ERROR in p\\X.java (at line 2)\n" + >+ " import static q.A.a;\n" + > " ^^^^^\n" + > "The import q.A.a cannot be resolved\n" + > "----------\n"); >@@ -2358,8 +2358,8 @@ > "}", > }, > "----------\n" + >- "1. ERROR in X.java (at line 1)\r\n" + >- " import static p.I.E.C;\r\n" + >+ "1. ERROR in X.java (at line 1)\n" + >+ " import static p.I.E.C;\n" + > " ^^^^^^^\n" + > "The import p.I.E.C cannot be resolved\n" + > "----------\n"); >@@ -2533,5 +2533,134 @@ > }, > ""); > } >+ // 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 doesn't 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", >+ }, >+ ""); >+ } >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=302865 >+ // To verify that two static imports importing the same type don't collide >+ public void test077() { >+ this.runConformTest( >+ new String[] { >+ "p1/X.java", >+ "package p1;\n" + >+ "import p2.A;\n" + >+ "import static p2.A.C;\n" + >+ "import static p1.B.C;\n" + >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " foo();\n" + >+ " }\n" + >+ " public static void foo() {\n" + >+ " if (C.CONST == 1) {\n" + >+ " System.out.println(\"SUCCESS\");\n" + >+ " return;\n" + >+ " }\n" + >+ " System.out.println(\"FAILED\");\n" + >+ " }\n" + >+ "}\n" + >+ "class B extends A {}", >+ "p2/A.java", >+ "package p2;\n" + >+ "public class A {\n" + >+ " public static class C {\n" + >+ " public static int CONST = 1;\n" + >+ " }\n" + >+ "}" >+ }, >+ "SUCCESS"); >+ } >+ // 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 test078() { >+ this.runNegativeTest( >+ new String[] { >+ "A/A.java", >+ "package A;\n" + >+ "import static B.B.C1;\n" + >+ "import 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 B.B.C1;\n" + >+ " ^^^^^^\n" + >+ "The import B.B.C1 collides with another import statement\n" + >+ "----------\n" >+ ); >+ } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 302865
:
159212
|
162986
|
164727
|
164880
|
164916
|
164951