### Eclipse Workspace Patch 1.0 #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.66 diff -u -r1.66 StaticImportTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 6 May 2008 18:48:23 -0000 1.66 +++ src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java 12 May 2008 13:50:18 -0000 @@ -2284,7 +2284,7 @@ ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - public void _test065() { + public void test065() { this.runConformTest( new String[] { "X.java", @@ -2305,7 +2305,7 @@ ); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - variation - public void _test066() { + public void test066() { this.runConformTest( new String[] { "X.java", @@ -2324,9 +2324,9 @@ }, "" ); - } + } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - variation - public void _test067() { + public void test067() { this.runNegativeTest( new String[] { "X.java", @@ -2349,6 +2349,46 @@ " ^^^^^^^\n" + "The import p.I.E.C cannot be resolved\n" + "----------\n"); - } + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - variation + public void test068() { + this.runConformTest( + new String[] { + "X.java", + "import static p.I.E.C;\n" + + "class C {}\n" + + "class B {}\n" + + "public class X extends B{\n" + + " static void test() { int i = C; }\n" + + "}", + "p/I.java", + "package p;\n" + + "public interface I {\n" + + " public static class E extends F {}\n" + + " public static class F { public static int C; }\n" + + "}", + }, + ""); + } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=230026 - variation + public void test069() { + this.runConformTest( + new String[] { + "X.java", + "import static p.I.E.C;\n" + + "class C {}\n" + + "class B {}\n" + + "public class X extends B{\n" + + " static void test() { C(); }\n" + + "}", + "p/I.java", + "package p;\n" + + "public interface I {\n" + + " public static class E extends F {}\n" + + " public static class F { public static void C() {} }\n" + + "}", + }, + ""); + } } #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java,v retrieving revision 1.102 diff -u -r1.102 ParameterizedTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java 27 Feb 2008 15:41:19 -0000 1.102 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java 12 May 2008 13:50:20 -0000 @@ -666,6 +666,10 @@ // do nothing for true parameterized types (only for raw types) } + void initializeForStaticImports() { + this.type.initializeForStaticImports(); + } + public boolean isEquivalentTo(TypeBinding otherType) { if (this == otherType) return true; Index: compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java,v retrieving revision 1.155 diff -u -r1.155 SourceTypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 3 Apr 2008 18:37:49 -0000 1.155 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java 12 May 2008 13:50:20 -0000 @@ -62,8 +62,8 @@ this.scope = scope; // expect the fields & methods to be initialized correctly later - this.fields = Binding.NO_FIELDS; - this.methods = Binding.NO_METHODS; + this.fields = Binding.UNINITIALIZED_FIELDS; + this.methods = Binding.UNINITIALIZED_METHODS; computeId(); } @@ -539,6 +539,12 @@ } return accessMethod; } +boolean areFieldsInitialized() { + return this.fields != Binding.UNINITIALIZED_FIELDS; +} +boolean areMethodsInitialized() { + return this.fields != Binding.UNINITIALIZED_FIELDS; +} public int kind() { if (this.typeVariables != Binding.NO_TYPE_VARIABLES) return Binding.GENERIC_TYPE; return Binding.TYPE; @@ -994,6 +1000,15 @@ } } +// ensure the receiver knows its hierarchy & fields/methods so static imports can be resolved correctly +// see bug 230026 +void initializeForStaticImports() { + if (this.superInterfaces == null) + this.scope.connectTypeHierarchy(); + this.scope.buildFields(); + this.scope.buildMethods(); +} + /** * Returns true if a type is identical to another one, * or for generic types, true if compared to its raw type. Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java,v retrieving revision 1.95 diff -u -r1.95 TypeBinding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java 26 Feb 2008 13:17:52 -0000 1.95 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java 12 May 2008 13:50:20 -0000 @@ -359,6 +359,10 @@ public abstract PackageBinding getPackage(); +void initializeForStaticImports() { + // only applicable to source types +} + public boolean isAnnotationType() { return false; } 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.116 diff -u -r1.116 CompilationUnitScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 20 Mar 2008 20:11:22 -0000 1.116 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java 12 May 2008 13:50:19 -0000 @@ -547,11 +547,13 @@ return new ProblemReferenceBinding(compoundName, ((ProblemReferenceBinding) type).closestMatch, ProblemReasons.NotVisible); return type; } -MethodBinding findStaticMethod(ReferenceBinding currentType, char[] selector) { +// helper method for findSingleStaticImport() +private MethodBinding findStaticMethod(ReferenceBinding currentType, char[] selector) { if (!currentType.canBeSeenBy(this)) return null; do { + currentType.initializeForStaticImports(); MethodBinding[] methods = currentType.getMethods(selector); if (methods != Binding.NO_METHODS) { for (int i = methods.length; --i >= 0;) { @@ -560,8 +562,6 @@ return method; } } - if (currentType.superInterfaces() == null) // needed for statically imported types which don't know their hierarchy yet - ((SourceTypeBinding) currentType).scope.connectTypeHierarchy(); } while ((currentType = currentType.superclass()) != null); return null; } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.329 diff -u -r1.329 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 6 May 2008 15:24:03 -0000 1.329 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 12 May 2008 13:50:20 -0000 @@ -857,6 +857,7 @@ if (!currentType.canBeSeenBy(this)) return new ProblemFieldBinding(currentType, fieldName, ProblemReasons.ReceiverTypeNotVisible); + currentType.initializeForStaticImports(); FieldBinding field = currentType.getField(fieldName, needResolve); if (field != null) { if (invocationSite == null @@ -874,10 +875,6 @@ // we could hold onto the not visible field for extra error reporting while (keepLooking) { ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); - if (itsInterfaces == null) { // needed for statically imported types which don't know their hierarchy yet - ((SourceTypeBinding) currentType).scope.connectTypeHierarchy(); - itsInterfaces = currentType.superInterfaces(); - } if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { if (interfacesToVisit == null) { interfacesToVisit = itsInterfaces; @@ -898,6 +895,7 @@ break; unitScope.recordTypeReference(currentType); + currentType.initializeForStaticImports(); if ((field = currentType.getField(fieldName, needResolve)) != null) { keepLooking = false; if (field.canBeSeenBy(receiverType, invocationSite, this)) { Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java,v retrieving revision 1.31 diff -u -r1.31 Binding.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java 25 Mar 2008 23:26:12 -0000 1.31 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Binding.java 12 May 2008 13:50:19 -0000 @@ -44,6 +44,9 @@ public static final AnnotationBinding[] NO_ANNOTATIONS = new AnnotationBinding[0]; public static final ElementValuePair[] NO_ELEMENT_VALUE_PAIRS = new ElementValuePair[0]; + public static final FieldBinding[] UNINITIALIZED_FIELDS = new FieldBinding[0]; + public static final MethodBinding[] UNINITIALIZED_METHODS = new MethodBinding[0]; + /* * Answer the receiver's binding type from Binding.BindingID. */ Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java,v retrieving revision 1.158 diff -u -r1.158 ClassScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 21 Apr 2008 10:45:21 -0000 1.158 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 12 May 2008 13:50:19 -0000 @@ -69,8 +69,9 @@ anonymousType.verifyMethods(environment().methodVerifier()); } - private void buildFields() { - SourceTypeBinding sourceType = this.referenceContext.binding; + void buildFields() { + SourceTypeBinding sourceType = this.referenceContext.binding; + if (sourceType.areFieldsInitialized()) return; if (this.referenceContext.fields == null) { sourceType.setFields(Binding.NO_FIELDS); return; @@ -270,7 +271,10 @@ sourceType.memberTypes = memberTypeBindings; } - private void buildMethods() { + void buildMethods() { + SourceTypeBinding sourceType = this.referenceContext.binding; + if (sourceType.areMethodsInitialized()) return; + boolean isEnum = TypeDeclaration.kind(this.referenceContext.modifiers) == TypeDeclaration.ENUM_DECL; if (this.referenceContext.methods == null && !isEnum) { this.referenceContext.binding.setMethods(Binding.NO_METHODS); @@ -292,7 +296,6 @@ int count = isEnum ? 2 : 0; // reserve 2 slots for special enum methods: #values() and #valueOf(String) MethodBinding[] methodBindings = new MethodBinding[(clinitIndex == -1 ? size : size - 1) + count]; // create special methods for enums - SourceTypeBinding sourceType = this.referenceContext.binding; if (isEnum) { methodBindings[0] = sourceType.addSyntheticEnumMethod(TypeConstants.VALUES); // add [] values() methodBindings[1] = sourceType.addSyntheticEnumMethod(TypeConstants.VALUEOF); // add valueOf()