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

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java (-1 / +1 lines)
Lines 496-502 Link Here
496
	// look to see if its a static field first
496
	// look to see if its a static field first
497
	ReferenceBinding type = (ReferenceBinding) binding;
497
	ReferenceBinding type = (ReferenceBinding) binding;
498
	FieldBinding field = findField(type, name, null, true);
498
	FieldBinding field = findField(type, name, null, true);
499
	if (field != null && field.isValidBinding() && field.isStatic() && field.canBeSeenBy(fPackage))
499
	if (field != null && field.isValidBinding() && field.isStatic() && field.canBeSeenBy(type, null, this))
500
		return field;
500
		return field;
501
501
502
	// look to see if there is a static method with the same selector
502
	// look to see if there is a static method with the same selector
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-7 / +7 lines)
Lines 1653-1667 Link Here
1653
							if (importBinding.isStatic() && !importBinding.onDemand) {
1653
							if (importBinding.isStatic() && !importBinding.onDemand) {
1654
								if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
1654
								if (CharOperation.equals(importBinding.compoundName[importBinding.compoundName.length - 1], name)) {
1655
									if (unitScope.resolveSingleImport(importBinding) != null && importBinding.resolvedImport instanceof FieldBinding) {
1655
									if (unitScope.resolveSingleImport(importBinding) != null && importBinding.resolvedImport instanceof FieldBinding) {
1656
										ReferenceBinding declaringClass = ((FieldBinding) importBinding.resolvedImport).declaringClass;
1656
										foundField = (FieldBinding) importBinding.resolvedImport;
1657
										if (declaringClass.canBeSeenBy(this)) {
1657
										ImportReference importReference = importBinding.reference;
1658
											ImportReference importReference = importBinding.reference;
1658
										if (importReference != null) importReference.used = true;
1659
											if (importReference != null) importReference.used = true;
1659
										invocationSite.setActualReceiverType(foundField.declaringClass);											
1660
											invocationSite.setActualReceiverType(declaringClass);											
1660
										if (foundField.isValidBinding()) {
1661
											return importBinding.resolvedImport;
1661
											return foundField;
1662
										}
1662
										}
1663
										if (problemField == null)
1663
										if (problemField == null)
1664
											problemField = new ProblemFieldBinding(declaringClass, name, ProblemReasons.ReceiverTypeNotVisible);
1664
											problemField = foundField;
1665
									}
1665
									}
1666
								}
1666
								}
1667
							}
1667
							}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java (-34 / +14 lines)
Lines 129-152 Link Here
129
			},
129
			},
130
			""
130
			""
131
		);
131
		);
132
		this.runNegativeTest(
132
		this.runConformTest(
133
			new String[] {
133
			new String[] {
134
				"X.java",
134
				"X.java",
135
				"import static p.A.C;\n" + 
135
				"import static p.A.C;\n" + 
136
				"public class X { int i = C; }\n",
136
				"public class X { \n" +
137
				"	int i = C; \n" +
138
				"	int j = p.A.C; \n" +
139
				"}\n",
137
				"p/A.java",
140
				"p/A.java",
138
				"package p;\n" + 
141
				"package p;\n" + 
139
				"public class A implements I {}\n" +
142
				"public class A implements I {}\n" +
140
				"interface I { public static int C = 1; }\n"
143
				"interface I { public static int C = 1; }\n"
141
			},
144
			},
142
			"----------\n" + 
145
			"");
143
			"1. ERROR in X.java (at line 2)\n" + 
144
			"	public class X { int i = C; }\n" + 
145
			"	                         ^\n" + 
146
			"The type I is not visible\n" + 
147
			"----------\n"
148
			// C in p.I is not defined in a public class or interface; cannot be accessed from outside package
149
		);
150
	}
146
	}
151
147
152
	public void test004() { // test static vs. instance
148
	public void test004() { // test static vs. instance
Lines 1341-1347 Link Here
1341
		);
1337
		);
1342
	}
1338
	}
1343
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126564
1339
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126564
1344
	public void _test036() {
1340
	public void test036() {
1345
		this.runNegativeTest(
1341
		this.runNegativeTest(
1346
			new String[] {
1342
			new String[] {
1347
				"X.java",
1343
				"X.java",
Lines 1360-1400 Link Here
1360
				"class B { int CONSTANT_B = 1; }",
1356
				"class B { int CONSTANT_B = 1; }",
1361
			}, 
1357
			}, 
1362
			"----------\n" + 
1358
			"----------\n" + 
1363
			"1. ERROR in X.java (at line 1)\n" + 
1359
			"1. ERROR in X.java (at line 2)\n" + 
1364
			"	import static p.A.CONSTANT_I;\n" + 
1365
			"	              ^^^^^^^^^^^^^^\n" + 
1366
			"The type I is not visible\n" + 
1367
			"----------\n" + 
1368
			"2. ERROR in X.java (at line 2)\n" + 
1369
			"	import static p.A.CONSTANT_B;\n" + 
1360
			"	import static p.A.CONSTANT_B;\n" + 
1370
			"	              ^^^^^^^^^^^^^^\n" + 
1361
			"	              ^^^^^^^^^^^^^^\n" + 
1371
			"The type B is not visible\n" + 
1362
			"The type B is not visible\n" + 
1372
			"----------\n" + 
1363
			"----------\n" + 
1373
			"3. ERROR in X.java (at line 4)\n" + 
1364
			"2. ERROR in X.java (at line 5)\n" + 
1374
			"	static int i = p.A.CONSTANT_I;\n" + 
1375
			"	               ^^^^^^^^^^^^^^\n" + 
1376
			"The type I is not visible\n" + 
1377
			"----------\n" + 
1378
			"4. ERROR in X.java (at line 5)\n" + 
1379
			"	static int j = p.A.CONSTANT_B;\n" + 
1365
			"	static int j = p.A.CONSTANT_B;\n" + 
1380
			"	               ^^^^^^^^^^^^^^\n" + 
1366
			"	               ^^^^^^^^^^^^^^\n" + 
1381
			"The type B is not visible\n" + 
1367
			"The type B is not visible\n" + 
1382
			"----------\n" + 
1368
			"----------\n" + 
1383
			"5. ERROR in X.java (at line 6)\n" + 
1369
			"3. ERROR in X.java (at line 7)\n" + 
1384
			"	static int m = CONSTANT_I;\n" + 
1385
			"	               ^^^^^^^^^^\n" + 
1386
			"CONSTANT_I cannot be resolved\n" + 
1387
			"----------\n" + 
1388
			"6. ERROR in X.java (at line 7)\n" + 
1389
			"	static int n = CONSTANT_B;\n" + 
1370
			"	static int n = CONSTANT_B;\n" + 
1390
			"	               ^^^^^^^^^^\n" + 
1371
			"	               ^^^^^^^^^^\n" + 
1391
			"CONSTANT_B cannot be resolved\n" + 
1372
			"CONSTANT_B cannot be resolved\n" + 
1392
			"----------\n"
1373
			"----------\n");
1393
		);
1394
	}
1374
	}
1395
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126564 - variation
1375
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=126564 - variation
1396
	public void _test037() {
1376
	public void test037() {
1397
		this.runNegativeTest(
1377
		this.runConformTest(
1398
			new String[] {
1378
			new String[] {
1399
				"X.java",
1379
				"X.java",
1400
				"import static p.A.CONSTANT_I;\n" + 
1380
				"import static p.A.CONSTANT_I;\n" + 
Lines 1411-1416 Link Here
1411
				"interface I { int CONSTANT_I = 1; }\n" + 
1391
				"interface I { int CONSTANT_I = 1; }\n" + 
1412
				"class B { public static int CONSTANT_B = 1; }",
1392
				"class B { public static int CONSTANT_B = 1; }",
1413
			}, 
1393
			}, 
1414
			"?");
1394
			"");
1415
	}	
1395
	}	
1416
}
1396
}

Return to bug 126564