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

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java (-8 / +21 lines)
Lines 464-485 Link Here
464
			problemReporter().deprecatedType(referenceBinding, invocationNode);
464
			problemReporter().deprecatedType(referenceBinding, invocationNode);
465
		}
465
		}
466
	}
466
	}
467
	Binding problemFieldBinding = null;
467
	while (currentIndex < length) {
468
	while (currentIndex < length) {
468
		referenceBinding = (ReferenceBinding) binding;
469
		referenceBinding = (ReferenceBinding) binding;
469
		char[] nextName = compoundName[currentIndex++];
470
		char[] nextName = compoundName[currentIndex++];
470
		invocationSite.setFieldIndex(currentIndex);
471
		invocationSite.setFieldIndex(currentIndex);
471
		invocationSite.setActualReceiverType(referenceBinding);
472
		invocationSite.setActualReceiverType(referenceBinding);
472
		if ((mask & Binding.FIELD) != 0 && (binding = findField(referenceBinding, nextName, invocationSite, true /*resolve*/)) != null) {
473
		if ((mask & Binding.FIELD) != 0 && (binding = findField(referenceBinding, nextName, invocationSite, true /*resolve*/)) != null) {
473
			if (!binding.isValidBinding()) {
474
			if (binding.isValidBinding()) {
474
				return new ProblemFieldBinding(
475
				break; // binding is now a field
475
					((ProblemFieldBinding)binding).closestMatch,
476
			}
476
					((ProblemFieldBinding)binding).declaringClass,
477
			problemFieldBinding = new ProblemFieldBinding(
477
					CharOperation.concatWith(CharOperation.subarray(compoundName, 0, currentIndex), '.'),
478
				((ProblemFieldBinding)binding).closestMatch,
478
					binding.problemId());
479
				((ProblemFieldBinding)binding).declaringClass,
480
				CharOperation.concatWith(CharOperation.subarray(compoundName, 0, currentIndex), '.'),
481
				binding.problemId()); 
482
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858 : If field is inaccessible,
483
			// don't give up yet, continue to look for a visible member type 
484
			if (binding.problemId() != ProblemReasons.NotVisible) {  
485
				return problemFieldBinding;
479
			}
486
			}
480
			break; // binding is now a field
481
		}
487
		}
482
		if ((binding = findMemberType(nextName, referenceBinding)) == null) {
488
		if ((binding = findMemberType(nextName, referenceBinding)) == null) {
489
			if (problemFieldBinding != null) {
490
				return problemFieldBinding;
491
			}
483
			if ((mask & Binding.FIELD) != 0) {
492
			if ((mask & Binding.FIELD) != 0) {
484
				return new ProblemFieldBinding(
493
				return new ProblemFieldBinding(
485
						null,
494
						null,
Lines 498-508 Link Here
498
				ProblemReasons.NotFound);
507
				ProblemReasons.NotFound);
499
		}
508
		}
500
		// binding is a ReferenceBinding
509
		// binding is a ReferenceBinding
501
		if (!binding.isValidBinding())
510
		if (!binding.isValidBinding()) {
511
			if (problemFieldBinding != null) {
512
				return problemFieldBinding;
513
			}
502
			return new ProblemReferenceBinding(
514
			return new ProblemReferenceBinding(
503
				CharOperation.subarray(compoundName, 0, currentIndex),
515
				CharOperation.subarray(compoundName, 0, currentIndex),
504
				(ReferenceBinding)((ReferenceBinding)binding).closestMatch(),
516
				(ReferenceBinding)((ReferenceBinding)binding).closestMatch(),
505
				binding.problemId());
517
				binding.problemId());
518
		}
506
		if (invocationSite instanceof ASTNode) {
519
		if (invocationSite instanceof ASTNode) {
507
			referenceBinding = (ReferenceBinding) binding;
520
			referenceBinding = (ReferenceBinding) binding;
508
			ASTNode invocationNode = (ASTNode) invocationSite;
521
			ASTNode invocationNode = (ASTNode) invocationSite;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java (+135 lines)
Lines 3176-3181 Link Here
3176
		"The type B$A is not visible\n" + 
3176
		"The type B$A is not visible\n" + 
3177
		"----------\n");
3177
		"----------\n");
3178
}
3178
}
3179
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858
3180
public void test098() {
3181
	this.runConformTest(
3182
		new String[] {
3183
			"B.java",//------------------------------
3184
			"class A {\n" +
3185
			"    public final static class B {\n" +
3186
			"        public final static String length = \"very long\";\n" +
3187
			"    }\n" +
3188
			"    private  int [] B = new int[5];\n" +    
3189
			"}\n" +
3190
			"public class B {\n" +
3191
			"    public static void main(String[] args) {\n" +
3192
			"        System.out.println(A.B.length);\n" +
3193
			"    }\n" +   
3194
			"}\n",
3195
		},
3196
		"very long");
3197
}
3198
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858
3199
public void test099() {
3200
	this.runNegativeTest(
3201
		new String[] {
3202
			"B.java",//------------------------------
3203
			"class A {\n" +
3204
			"    public final static class B {\n" +
3205
			"        public final static String length = \"very long\";\n" +
3206
			"    }\n" +
3207
			"    public int [] B = new int[5];\n" +    
3208
			"}\n" +
3209
			"public class B {\n" +
3210
			"    public static void main(String[] args) {\n" +
3211
			"        System.out.println(A.B.length);\n" +
3212
			"    }\n" +   
3213
			"}\n",
3214
		},
3215
		"----------\n" + 
3216
		"1. ERROR in B.java (at line 9)\n" + 
3217
		"	System.out.println(A.B.length);\n" + 
3218
		"	                   ^^^^^^^^^^\n" + 
3219
		"Cannot make a static reference to the non-static field A.B\n" + 
3220
		"----------\n");
3221
}
3222
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858
3223
public void test100() {
3224
	this.runConformTest(
3225
		new String[] {
3226
			"B.java",//------------------------------
3227
			"class A {\n" +
3228
			"    public final class B {\n" +
3229
			"        public final String length = \"very long\";\n" +
3230
			"    }\n" +
3231
			"    public static int [] B = new int[5];\n" +    
3232
			"}\n" +
3233
			"public class B {\n" +
3234
			"    public static void main(String[] args) {\n" +
3235
			"        System.out.println(A.B.length);\n" +
3236
			"    }\n" +   
3237
			"}\n",
3238
		},
3239
		"5");
3240
}
3241
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858
3242
public void test101() {
3243
	this.runNegativeTest(
3244
		new String[] {
3245
			"B.java",//------------------------------
3246
			"class A {\n" +
3247
			"    private final class B {\n" +
3248
			"        public final String length = \"very long\";\n" +
3249
			"    }\n" +
3250
			"    private int [] B = new int[5];\n" +    
3251
			"}\n" +
3252
			"public class B {\n" +
3253
			"    public static void main(String[] args) {\n" +
3254
			"        System.out.println(A.B.length);\n" +
3255
			"    }\n" +   
3256
			"}\n",
3257
		},
3258
		"----------\n" + 
3259
		"1. WARNING in B.java (at line 2)\n" + 
3260
		"	private final class B {\n" + 
3261
		"	                    ^\n" + 
3262
		"The type A.B is never used locally\n" + 
3263
		"----------\n" + 
3264
		"2. WARNING in B.java (at line 3)\n" + 
3265
		"	public final String length = \"very long\";\n" + 
3266
		"	                    ^^^^^^\n" + 
3267
		"The field A.B.length is never read locally\n" + 
3268
		"----------\n" + 
3269
		"3. WARNING in B.java (at line 5)\n" + 
3270
		"	private int [] B = new int[5];\n" + 
3271
		"	               ^\n" + 
3272
		"The field A.B is never read locally\n" + 
3273
		"----------\n" + 
3274
		"4. ERROR in B.java (at line 9)\n" + 
3275
		"	System.out.println(A.B.length);\n" + 
3276
		"	                     ^\n" + 
3277
		"The field A.B is not visible\n" + 
3278
		"----------\n");
3279
}
3280
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317858
3281
public void test102() {
3282
	this.runNegativeTest(
3283
		new String[] {
3284
			"B.java",//------------------------------
3285
			"class A {\n" +
3286
			"    public final class B {\n" +
3287
			"        private final String length = \"very long\";\n" +
3288
			"    }\n" +
3289
			"    private int [] B = new int[5];\n" +    
3290
			"}\n" +
3291
			"public class B {\n" +
3292
			"    public static void main(String[] args) {\n" +
3293
			"        System.out.println(A.B.length);\n" +
3294
			"    }\n" +   
3295
			"}\n",
3296
		},
3297
		"----------\n" + 
3298
		"1. WARNING in B.java (at line 3)\n" + 
3299
		"	private final String length = \"very long\";\n" + 
3300
		"	                     ^^^^^^\n" + 
3301
		"The field A.B.length is never read locally\n" + 
3302
		"----------\n" + 
3303
		"2. WARNING in B.java (at line 5)\n" + 
3304
		"	private int [] B = new int[5];\n" + 
3305
		"	               ^\n" + 
3306
		"The field A.B is never read locally\n" + 
3307
		"----------\n" + 
3308
		"3. ERROR in B.java (at line 9)\n" + 
3309
		"	System.out.println(A.B.length);\n" + 
3310
		"	                       ^^^^^^\n" + 
3311
		"The field A.B.length is not visible\n" + 
3312
		"----------\n");
3313
}
3179
public static Class testClass() {	return LookupTest.class;
3314
public static Class testClass() {	return LookupTest.class;
3180
}
3315
}
3181
}
3316
}

Return to bug 317858