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 204564 Details for
Bug 318401
FUP of 317858: Clarify eclipse compiler behavior on imports & shadowing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
proposed fix v1.0 + regression tests
HEAD--Fixed-bug-318401-FUP-of-317858-Clarify-eclipse.patch (text/plain), 8.67 KB, created by
Ayushman Jain
on 2011-10-05 02:00:46 EDT
(
hide
)
Description:
proposed fix v1.0 + regression tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2011-10-05 02:00:46 EDT
Size:
8.67 KB
patch
obsolete
>diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java >index bae6a3c..f1da7df 100644 >--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java >+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java >@@ -2484,10 +2484,10 @@ > "}\n", > }, > "----------\n" + >- "1. ERROR in p1\\A.java (at line 7)\n" + >- " int v2 = b.fooC;\n" + >+ "1. ERROR in p1\\A.java (at line 6)\n" + >+ " int v1 = b.fooB;\n" + > " ^^^^\n" + >- "fooC cannot be resolved or is not a field\n" + >+ "fooB cannot be resolved or is not a field\n" + > "----------\n"); > } > //https://bugs.eclipse.org/bugs/show_bug.cgi?id=256375 >@@ -2720,5 +2720,132 @@ > "----------\n" > ); > } >+ >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401 >+ public void test081() { >+ this.runConformTest( >+ new String[] { >+ "Test.java", >+ "import static p1.Bar.B;\n" + >+ "import p3.Foo.*;\n" + >+ "public class Test {\n" + >+ " public static void main(String [] args){\n" + >+ " new Test().beginTest();" + >+ " }\n" + >+ " public void beginTest(){\n" + >+ " System.out.print(\"1 + 1 = \");\n" + >+ " if(alwaysTrue()) System.out.println(\"2\");\n" + >+ " else System.out.println(\"3\"); " + >+ " }\n" + >+ " public boolean alwaysTrue(){\n" + >+ " String myB = B.class.getCanonicalName();;\n" + // refers to p1.Bar.B (class) >+ " String realB = p1.Bar.B.class.getCanonicalName();;\n" + // refers to p1.Bar.B (class) >+ " B();\n" + // refers to p1.Bar.B() (method) >+ " return myB.equals(realB);\n" + >+ " }\n" + >+ "}\n", >+ "p1/Bar.java", >+ "package p1;\n" + >+ "public class Bar{\n" + >+ " public static class B{}\n" + >+ " final public static String B = new String(\"random\");\n" + >+ " public static void B(){}\n" + >+ "}\n", >+ "p3/Foo.java", >+ "package p3;\n" + >+ "public class Foo {\n" + >+ " public class B{\n" + >+ " public int a;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "1 + 1 = 2"); >+ } >+ >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401 >+ public void test082() { >+ this.runNegativeTest( >+ new String[] { >+ "p1/Bar.java", >+ "package p1;\n" + >+ "public class Bar{\n" + >+ " public static class B{}\n" + >+ " final public static String B = new String(\"random\");\n" + >+ " public static void B(){}\n" + >+ "}\n", >+ "p3/Foo.java", >+ "package p3;\n" + >+ "public class Foo {\n" + >+ " public class B{\n" + >+ " public int a;\n" + >+ " }\n" + >+ "}\n", >+ "p2/Test.java", >+ "package p2;\n" + >+ "import static p1.Bar.B;\n" + >+ "import p3.Foo.*;\n" + >+ "public class Test {\n" + >+ " public static void main(String [] args){\n" + >+ " new Test().beginTest();" + >+ " }\n" + >+ " public void beginTest(){\n" + >+ " System.out.print(\"1 + 1 = \");\n" + >+ " if(alwaysTrue()) System.out.println(\"2\");\n" + >+ " else System.out.println(\"3\"); " + >+ " }\n" + >+ " public boolean alwaysTrue(){\n" + >+ " B b = null;\n" + // refers to p1.Bar.B (class) >+ " String realB = B;\n" + // refers to p1.Bar.B (field) >+ " B();\n" + // refers to p1.Bar.B() (method) >+ " int abc = b.a;\n;" + // static import for Bar.B overshadows on demand import Foo.B >+ " }\n" + >+ "}\n", >+ }, >+ "----------\n" + >+ "1. ERROR in p2\\Test.java (at line 15)\n" + >+ " int abc = b.a;\n" + >+ " ^\n" + >+ "a cannot be resolved or is not a field\n" + >+ "----------\n"); >+ } >+ >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401 >+ public void test083() { >+ this.runConformTest( >+ new String[] { >+ "Test.java", >+ "import static p1.Bar.B;\n" + >+ "import p3.Foo.*;\n" + >+ "public class Test {\n" + >+ " public static void main(String [] args){\n" + >+ " new Test().test2();" + >+ " }\n" + >+ " public void test2(){\n" + >+ " System.out.println(B.toString());\n" + // Field obscures class B >+ " System.out.println(p1.Bar.B.toString());\n" + // Field obscures the class B >+ " System.out.println(B.class.getCanonicalName().toString());\n" + // the class B >+ " System.out.println(p1.Bar.B.class.getCanonicalName().toString());" + // class B >+ " }\n" + >+ "}\n", >+ "p1/Bar.java", >+ "package p1;\n" + >+ "public class Bar{\n" + >+ " public static class B{}\n" + >+ " final public static String B = new String(\"random\");\n" + >+ " public static void B(){}\n" + >+ "}\n", >+ "p3/Foo.java", >+ "package p3;\n" + >+ "public class Foo {\n" + >+ " public class B{\n" + >+ " public int a;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "random\n" + >+ "random\n" + >+ "p1.Bar.B\n" + >+ "p1.Bar.B"); >+ } > } > >diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java >index 4eada31..2e945b0 100644 >--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java >+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java >@@ -2712,6 +2712,77 @@ > } > } > } >+ // walk single static imports. A type found here will shadow types with same name in other CU's, or types coming >+ // from on-demand imports. JLS 7.5.3 >+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=318401 >+ if (imports != null) { >+ boolean foundInImport = false; >+ ReferenceBinding type = null; >+ nextImport : for (int i = 0, length = imports.length; i < length; i++) { >+ ImportBinding importBinding = imports[i]; >+ if (importBinding.isStatic()) { >+ ReferenceBinding temp = null; >+ if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) { >+ Binding resolvedImport = importBinding.resolvedImport; >+ if (resolvedImport == null) continue nextImport; >+ if (resolvedImport instanceof MethodBinding) { >+ // check to see if there are also member types with the same name >+ MethodBinding staticMethod = (MethodBinding) resolvedImport; >+ if (CharOperation.equals(staticMethod.selector, name)) { >+ // must find the importRef's type again since the field can be from an inherited type >+ char[][] importName = importBinding.reference.tokens; >+ TypeBinding referencedType = getType(importName, importName.length - 1); >+ if (referencedType != null) { >+ temp = findMemberType(name, staticMethod.declaringClass); >+ if (temp != null && !temp.isStatic()) temp = null; >+ } >+ } >+ } else if (resolvedImport instanceof FieldBinding) { >+ // check to see if there are also member types with the same name >+ FieldBinding staticField = (FieldBinding) resolvedImport; >+ if (CharOperation.equals(staticField.name, name)) { >+ // must find the importRef's type again since the field can be from an inherited type >+ char[][] importName = importBinding.reference.tokens; >+ TypeBinding referencedType = getType(importName, importName.length - 1); >+ if (referencedType != null) { >+ temp = findMemberType(name, staticField.declaringClass); >+ if (temp != null && !temp.isStatic()) temp = null; >+ } >+ } >+ } >+ if (temp != type && temp != null) { >+ if (temp.isValidBinding()) { >+ if (!temp.canBeSeenBy(unitScope.fPackage)) { >+ // Answer error binding - type is not visible >+ foundType = new ProblemReferenceBinding(new char[][]{name}, type, ProblemReasons.NotVisible); >+ } else { >+ ImportReference importReference = importBinding.reference; >+ if (importReference != null) { >+ importReference.bits |= ASTNode.Used; >+ } >+ if (foundInImport) { >+ // Answer error binding -- import on demand conflict; name found in two import on demand packages. >+ temp = new ProblemReferenceBinding(new char[][]{name}, type, ProblemReasons.Ambiguous); >+ if (typeOrPackageCache != null) >+ typeOrPackageCache.put(name, temp); >+ return temp; >+ } >+ type = temp; >+ foundInImport = true; >+ } >+ } else if (foundType == null) { >+ foundType = temp; >+ } >+ } >+ } >+ } >+ } >+ if (type != null) { >+ if (typeOrPackageCache != null) >+ typeOrPackageCache.put(name, type); >+ return type; >+ } >+ } > > // check if the name is in the current package, skip it if its a sub-package > PackageBinding currentPackage = unitScope.fPackage;
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 318401
:
204564
|
205405
|
205471