View | Details | Raw Unified | Return to bug 159893
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-17 / +21 lines)
Lines 1720-1725 Link Here
1720
		MethodBinding foundProblem = null;
1720
		MethodBinding foundProblem = null;
1721
		Scope scope = this;
1721
		Scope scope = this;
1722
		int depth = 0;
1722
		int depth = 0;
1723
		// in 1.4 mode (inherited visible shadows enclosing)
1724
		CompilerOptions options;
1725
		boolean inheritedHasPrecedence = (options = compilerOptions()).complianceLevel >= ClassFileConstants.JDK1_4;
1726
		
1723
		done : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
1727
		done : while (true) { // done when a COMPILATION_UNIT_SCOPE is found
1724
			switch (scope.kind) {
1728
			switch (scope.kind) {
1725
				case METHOD_SCOPE :
1729
				case METHOD_SCOPE :
Lines 1751-1774 Link Here
1751
												? ProblemReasons.NonStaticReferenceInConstructorInvocation
1755
												? ProblemReasons.NonStaticReferenceInConstructorInvocation
1752
												: ProblemReasons.NonStaticReferenceInStaticContext);
1756
												: ProblemReasons.NonStaticReferenceInStaticContext);
1753
									}
1757
									}
1754
1758
									if (inheritedHasPrecedence
1755
									if (receiverType == methodBinding.declaringClass
1759
											|| receiverType == methodBinding.declaringClass
1756
										|| ((foundProblem == null || foundProblem.problemId() != ProblemReasons.NotVisible) && compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
1760
											|| (receiverType.getMethods(selector)) != Binding.NO_METHODS) {
1757
										|| (receiverType.getMethods(selector)) != Binding.NO_METHODS) {
1761
										// found a valid method in the 'immediate' scope (ie. not inherited)
1758
											// found a valid method in the 'immediate' scope (ie. not inherited)
1762
										// OR in 1.4 mode (inherited visible shadows enclosing)
1759
											// OR in 1.4 mode (inherited visible shadows enclosing)
1763
										// OR the receiverType implemented a method with the correct name
1760
											// OR the receiverType implemented a method with the correct name
1764
										// return the methodBinding if it is not declared in a superclass of the scope's binding (that is, inherited)
1761
											// return the methodBinding if it is not declared in a superclass of the scope's binding (that is, inherited)
1765
										if (foundProblem != null && foundProblem.problemId() != ProblemReasons.NotVisible)
1762
											if (foundProblem != null && foundProblem.problemId() != ProblemReasons.NotVisible)
1766
											return foundProblem;
1763
												return foundProblem;
1767
										if (depth > 0) {
1764
											if (depth > 0) {
1768
											invocationSite.setDepth(depth);
1765
												invocationSite.setDepth(depth);
1769
											invocationSite.setActualReceiverType(receiverType);
1766
												invocationSite.setActualReceiverType(receiverType);
1770
										}
1767
											}
1771
										return methodBinding;
1768
											return methodBinding;
1769
									}
1772
									}
1770
1773
1771
									if (foundProblem == null) {
1774
									if (foundProblem == null || foundProblem.problemId() == ProblemReasons.NotVisible) {
1775
										if (foundProblem != null) foundProblem = null;
1772
										// only remember the methodBinding if its the first one found
1776
										// only remember the methodBinding if its the first one found
1773
										// remember that private methods are visible if defined directly by an enclosing class
1777
										// remember that private methods are visible if defined directly by an enclosing class
1774
										if (depth > 0) {
1778
										if (depth > 0) {
Lines 1813-1819 Link Here
1813
			scope = scope.parent;
1817
			scope = scope.parent;
1814
		}
1818
		}
1815
1819
1816
		if (insideStaticContext && compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) {
1820
		if (insideStaticContext && options.sourceLevel >= ClassFileConstants.JDK1_5) {
1817
			if (foundProblem != null) {
1821
			if (foundProblem != null) {
1818
				if (foundProblem.declaringClass != null && foundProblem.declaringClass.id == TypeIds.T_JavaLangObject)
1822
				if (foundProblem.declaringClass != null && foundProblem.declaringClass.id == TypeIds.T_JavaLangObject)
1819
					return foundProblem; // static imports lose to methods from Object
1823
					return foundProblem; // static imports lose to methods from Object
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (+71 lines)
Lines 2594-2599 Link Here
2594
	}
2594
	}
2595
}
2595
}
2596
2596
2597
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159893
2598
public void test077() {
2599
	this.runConformTest(
2600
		new String[] {
2601
			"X.java",	//===================
2602
			"abstract  class B {\n" + 
2603
			"  public String getValue(){\n" + 
2604
			"    return \"pippo\";\n" + 
2605
			"  }\n" + 
2606
			"}\n" + 
2607
			"class D {\n" + 
2608
			"  private String value;\n" + 
2609
			"  public D(String p_Value){\n" + 
2610
			"    value = p_Value;\n" + 
2611
			"  }\n" + 
2612
			"  private  String getValue(){\n" + 
2613
			"    return \"pippoD\";\n" + 
2614
			"  }\n" + 
2615
			"}\n" + 
2616
			"public class X extends B {\n" + 
2617
			"  class C extends D{\n" + 
2618
			"    public C() {\n" + 
2619
			"      super(getValue());\n" + 
2620
			"      String s = getValue();\n" + 
2621
			"    }\n" + 
2622
			"  }\n" + 
2623
			"}\n", 		// =================
2624
		},
2625
		"");
2626
}
2627
2628
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159893 - variation
2629
public void test078() {
2630
	this.runNegativeTest(
2631
		new String[] {
2632
			"X.java",	//===================
2633
			"class D {\n" + 
2634
			"  private String value;\n" + 
2635
			"  public D(String p_Value){\n" + 
2636
			"    value = p_Value;\n" + 
2637
			"  }\n" + 
2638
			"  private  String getValue(){\n" + 
2639
			"    return \"pippoD\";\n" + 
2640
			"  }\n" + 
2641
			"}\n" + 
2642
			"public class X {\n" + 
2643
			"  class C extends D{\n" + 
2644
			"    public C() {\n" + 
2645
			"      super(getValue());\n" + 
2646
			"      String s = getValue();\n" + 
2647
			"    }\n" + 
2648
			"  }\n" + 
2649
			"}\n", 		// =================
2650
		},
2651
		"----------\n" + 
2652
		"1. WARNING in X.java (at line 2)\n" + 
2653
		"	private String value;\n" + 
2654
		"	               ^^^^^\n" + 
2655
		"The field D.value is never read locally\n" + 
2656
		"----------\n" + 
2657
		"2. ERROR in X.java (at line 13)\n" + 
2658
		"	super(getValue());\n" + 
2659
		"	      ^^^^^^^^\n" + 
2660
		"The method getValue() from the type D is not visible\n" + 
2661
		"----------\n" + 
2662
		"3. ERROR in X.java (at line 14)\n" + 
2663
		"	String s = getValue();\n" + 
2664
		"	           ^^^^^^^^\n" + 
2665
		"The method getValue() from the type D is not visible\n" + 
2666
		"----------\n");
2667
}
2597
public static Class testClass() {	return LookupTest.class;
2668
public static Class testClass() {	return LookupTest.class;
2598
}
2669
}
2599
}
2670
}

Return to bug 159893