### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java,v retrieving revision 1.287 diff -u -r1.287 Scope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 20 Oct 2006 11:02:03 -0000 1.287 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java 25 Oct 2006 11:19:20 -0000 @@ -1720,6 +1720,10 @@ MethodBinding foundProblem = null; Scope scope = this; int depth = 0; + // in 1.4 mode (inherited visible shadows enclosing) + CompilerOptions options; + boolean inheritedHasPrecedence = (options = compilerOptions()).complianceLevel >= ClassFileConstants.JDK1_4; + done : while (true) { // done when a COMPILATION_UNIT_SCOPE is found switch (scope.kind) { case METHOD_SCOPE : @@ -1751,24 +1755,24 @@ ? ProblemReasons.NonStaticReferenceInConstructorInvocation : ProblemReasons.NonStaticReferenceInStaticContext); } - - if (receiverType == methodBinding.declaringClass - || ((foundProblem == null || foundProblem.problemId() != ProblemReasons.NotVisible) && compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) - || (receiverType.getMethods(selector)) != Binding.NO_METHODS) { - // found a valid method in the 'immediate' scope (ie. not inherited) - // OR in 1.4 mode (inherited visible shadows enclosing) - // OR the receiverType implemented a method with the correct name - // return the methodBinding if it is not declared in a superclass of the scope's binding (that is, inherited) - if (foundProblem != null && foundProblem.problemId() != ProblemReasons.NotVisible) - return foundProblem; - if (depth > 0) { - invocationSite.setDepth(depth); - invocationSite.setActualReceiverType(receiverType); - } - return methodBinding; + if (inheritedHasPrecedence + || receiverType == methodBinding.declaringClass + || (receiverType.getMethods(selector)) != Binding.NO_METHODS) { + // found a valid method in the 'immediate' scope (ie. not inherited) + // OR in 1.4 mode (inherited visible shadows enclosing) + // OR the receiverType implemented a method with the correct name + // return the methodBinding if it is not declared in a superclass of the scope's binding (that is, inherited) + if (foundProblem != null && foundProblem.problemId() != ProblemReasons.NotVisible) + return foundProblem; + if (depth > 0) { + invocationSite.setDepth(depth); + invocationSite.setActualReceiverType(receiverType); + } + return methodBinding; } - if (foundProblem == null) { + if (foundProblem == null || foundProblem.problemId() == ProblemReasons.NotVisible) { + if (foundProblem != null) foundProblem = null; // only remember the methodBinding if its the first one found // remember that private methods are visible if defined directly by an enclosing class if (depth > 0) { @@ -1813,7 +1817,7 @@ scope = scope.parent; } - if (insideStaticContext && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { + if (insideStaticContext && options.sourceLevel >= ClassFileConstants.JDK1_5) { if (foundProblem != null) { if (foundProblem.declaringClass != null && foundProblem.declaringClass.id == TypeIds.T_JavaLangObject) return foundProblem; // static imports lose to methods from Object #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java =================================================================== RCS file: /home/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java,v retrieving revision 1.62 diff -u -r1.62 LookupTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 17 Oct 2006 21:22:39 -0000 1.62 +++ src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java 25 Oct 2006 11:19:22 -0000 @@ -2594,6 +2594,77 @@ } } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159893 +public void test077() { + this.runConformTest( + new String[] { + "X.java", //=================== + "abstract class B {\n" + + " public String getValue(){\n" + + " return \"pippo\";\n" + + " }\n" + + "}\n" + + "class D {\n" + + " private String value;\n" + + " public D(String p_Value){\n" + + " value = p_Value;\n" + + " }\n" + + " private String getValue(){\n" + + " return \"pippoD\";\n" + + " }\n" + + "}\n" + + "public class X extends B {\n" + + " class C extends D{\n" + + " public C() {\n" + + " super(getValue());\n" + + " String s = getValue();\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + ""); +} + +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159893 - variation +public void test078() { + this.runNegativeTest( + new String[] { + "X.java", //=================== + "class D {\n" + + " private String value;\n" + + " public D(String p_Value){\n" + + " value = p_Value;\n" + + " }\n" + + " private String getValue(){\n" + + " return \"pippoD\";\n" + + " }\n" + + "}\n" + + "public class X {\n" + + " class C extends D{\n" + + " public C() {\n" + + " super(getValue());\n" + + " String s = getValue();\n" + + " }\n" + + " }\n" + + "}\n", // ================= + }, + "----------\n" + + "1. WARNING in X.java (at line 2)\n" + + " private String value;\n" + + " ^^^^^\n" + + "The field D.value is never read locally\n" + + "----------\n" + + "2. ERROR in X.java (at line 13)\n" + + " super(getValue());\n" + + " ^^^^^^^^\n" + + "The method getValue() from the type D is not visible\n" + + "----------\n" + + "3. ERROR in X.java (at line 14)\n" + + " String s = getValue();\n" + + " ^^^^^^^^\n" + + "The method getValue() from the type D is not visible\n" + + "----------\n"); +} public static Class testClass() { return LookupTest.class; } }