View | Details | Raw Unified | Return to bug 201912 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse Java Tests Compiler/org/eclipse/jdt/tests/compiler/regression/NegativeTest.java (-8 / +40 lines)
Lines 7840-7851 Link Here
7840
		"	                     ^^^^^^\n" +
7840
		"	                     ^^^^^^\n" +
7841
		"The type AClass.Inner3 is never used locally\n" +
7841
		"The type AClass.Inner3 is never used locally\n" +
7842
		"----------\n" +
7842
		"----------\n" +
7843
		"2. WARNING in p\\z\\AClass.java (at line 18)\n" +
7843
		"2. WARNING in p\\z\\AClass.java (at line 14)\n" +
7844
		"	String test() {\n" +
7845
		"	       ^^^^^^\n" +
7846
		"The method test() from the type AClass.Inner3 is never used locally\n" +
7847
		"----------\n" +
7848
		"3. WARNING in p\\z\\AClass.java (at line 18)\n" +
7844
		"	private class Inner4 {\n" +
7849
		"	private class Inner4 {\n" +
7845
		"	              ^^^^^^\n" +
7850
		"	              ^^^^^^\n" +
7846
		"The type AClass.Inner4 is never used locally\n" +
7851
		"The type AClass.Inner4 is never used locally\n" +
7847
		"----------\n" +
7852
		"----------\n" +
7848
		"3. WARNING in p\\z\\AClass.java (at line 31)\n" +
7853
		"4. WARNING in p\\z\\AClass.java (at line 19)\n" +
7854
		"	String test() {\n" +
7855
		"	       ^^^^^^\n" +
7856
		"The method test() from the type AClass.Inner4 is never used locally\n" +
7857
		"----------\n" +
7858
		"5. WARNING in p\\z\\AClass.java (at line 31)\n" +
7849
		"	public String test() {\n" +
7859
		"	public String test() {\n" +
7850
		"	              ^^^^^^\n" +
7860
		"	              ^^^^^^\n" +
7851
		"The method test() from the type new Object(){} is never used locally\n" +
7861
		"The method test() from the type new Object(){} is never used locally\n" +
Lines 9035-9041 Link Here
9035
	"	int i = new AA().new Inner().i; // THIS LINE SHOULD CAUSE AN ERROR\n" +
9045
	"	int i = new AA().new Inner().i; // THIS LINE SHOULD CAUSE AN ERROR\n" +
9036
	"	                     ^^^^^\n" +
9046
	"	                     ^^^^^\n" +
9037
	"The type AA.Inner is not visible\n" +
9047
	"The type AA.Inner is not visible\n" +
9038
	"----------\n"	);
9048
	"----------\n" +
9049
	"----------\n" +
9050
	"1. WARNING in p\\k\\AA.java (at line 4)\n" +
9051
	"	int i = 10;\n" +
9052
	"	    ^\n" +
9053
	"The field AA.Inner.i is never read locally\n" +
9054
	"----------\n");
9039
}
9055
}
9040
public void test227() {
9056
public void test227() {
9041
	this.runNegativeTest(
9057
	this.runNegativeTest(
Lines 12204-12209 Link Here
12204
			"}	\n",
12220
			"}	\n",
12205
		},
12221
		},
12206
		"----------\n" +
12222
		"----------\n" +
12223
		"1. WARNING in p\\X.java (at line 4)\n" +
12224
		"	public class Z {	\n" +
12225
		"	             ^\n" +
12226
		"The type X.Y.Z is never used locally\n" +
12227
		"----------\n" +
12228
		"----------\n" +
12207
		"1. ERROR in q\\Y.java (at line 2)\n" +
12229
		"1. ERROR in q\\Y.java (at line 2)\n" +
12208
		"	import p.X.Y.Z;	\n" +
12230
		"	import p.X.Y.Z;	\n" +
12209
		"	       ^^^^^\n" +
12231
		"	       ^^^^^\n" +
Lines 12911-12917 Link Here
12911
		"	               ^^^^^^^^^^\n" +
12933
		"	               ^^^^^^^^^^\n" +
12912
		"The method foo(int) from the type X.Member is never used locally\n" +
12934
		"The method foo(int) from the type X.Member is never used locally\n" +
12913
		"----------\n" +
12935
		"----------\n" +
12914
		"3. WARNING in X.java (at line 7)\n" +
12936
		"3. WARNING in X.java (at line 5)\n" +
12937
		"	return new Object(){ \n" +
12938
		"	           ^^^^^^^^\n" +
12939
		"The type new Object(){} is never used locally\n" +
12940
		"----------\n" +
12941
		"4. WARNING in X.java (at line 7)\n" +
12915
		"	return foo(2);	\n" +
12942
		"	return foo(2);	\n" +
12916
		"	       ^^^^^^\n" +
12943
		"	       ^^^^^^\n" +
12917
		"Access to enclosing method foo(int) from the type X.Member is emulated by a synthetic accessor method\n" +
12944
		"Access to enclosing method foo(int) from the type X.Member is emulated by a synthetic accessor method\n" +
Lines 16481-16502 Link Here
16481
		"	              ^^^^^^^\n" +
16508
		"	              ^^^^^^^\n" +
16482
		"Access to enclosing constructor X.M() is emulated by a synthetic accessor method\n" +
16509
		"Access to enclosing constructor X.M() is emulated by a synthetic accessor method\n" +
16483
		"----------\n" +
16510
		"----------\n" +
16484
		"4. WARNING in X.java (at line 9)\n" +
16511
		"4. WARNING in X.java (at line 6)\n" +
16512
		"	M.Member2 m2;\n" +
16513
		"	          ^^\n" +
16514
		"The field X.M.m2 is never read locally\n" +
16515
		"----------\n" +
16516
		"5. WARNING in X.java (at line 9)\n" +
16485
		"	class Local1 {} \n" +
16517
		"	class Local1 {} \n" +
16486
		"	      ^^^^^^\n" +
16518
		"	      ^^^^^^\n" +
16487
		"The type Local1 is never used locally\n" +
16519
		"The type Local1 is never used locally\n" +
16488
		"----------\n" +
16520
		"----------\n" +
16489
		"5. WARNING in X.java (at line 10)\n" +
16521
		"6. WARNING in X.java (at line 10)\n" +
16490
		"	class Local2 { \n" +
16522
		"	class Local2 { \n" +
16491
		"	      ^^^^^^\n" +
16523
		"	      ^^^^^^\n" +
16492
		"The type Local2 is never used locally\n" +
16524
		"The type Local2 is never used locally\n" +
16493
		"----------\n" +
16525
		"----------\n" +
16494
		"6. WARNING in X.java (at line 11)\n" +
16526
		"7. WARNING in X.java (at line 11)\n" +
16495
		"	class LMember1 {} \n" +
16527
		"	class LMember1 {} \n" +
16496
		"	      ^^^^^^^^\n" +
16528
		"	      ^^^^^^^^\n" +
16497
		"The type Local2.LMember1 is never used locally\n" +
16529
		"The type Local2.LMember1 is never used locally\n" +
16498
		"----------\n" +
16530
		"----------\n" +
16499
		"7. WARNING in X.java (at line 12)\n" +
16531
		"8. WARNING in X.java (at line 12)\n" +
16500
		"	class LMember2 extends Local2 { \n" +
16532
		"	class LMember2 extends Local2 { \n" +
16501
		"	      ^^^^^^^^\n" +
16533
		"	      ^^^^^^^^\n" +
16502
		"The type Local2.LMember2 is never used locally\n" +
16534
		"The type Local2.LMember2 is never used locally\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java (-8 / +53 lines)
Lines 1468-1477 Link Here
1468
		"	              ^\n" +
1468
		"	              ^\n" +
1469
		"Access to enclosing constructor A2.B() is emulated by a synthetic accessor method\n" +
1469
		"Access to enclosing constructor A2.B() is emulated by a synthetic accessor method\n" +
1470
		"----------\n" +
1470
		"----------\n" +
1471
		"3. ERROR in p1\\A2.java (at line 20)\n" +
1471
		"3. WARNING in p1\\A2.java (at line 19)\n" +
1472
		"	public void foo() {	\n" +
1473
		"	            ^^^^^\n" +
1474
		"The method foo() from the type A2.C is never used locally\n" +
1475
		"----------\n" +
1476
		"4. ERROR in p1\\A2.java (at line 20)\n" +
1472
		"	(new D.E(null, null, null, new F(get()) {}) {}).execute();	\n" +
1477
		"	(new D.E(null, null, null, new F(get()) {}) {}).execute();	\n" +
1473
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1478
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1474
		"No enclosing instance of type D is accessible. Must qualify the allocation with an enclosing instance of type D (e.g. x.new A() where x is an instance of D).\n" +
1479
		"No enclosing instance of type D is accessible. Must qualify the allocation with an enclosing instance of type D (e.g. x.new A() where x is an instance of D).\n" +
1480
		"----------\n" +
1481
		"5. WARNING in p1\\A2.java (at line 20)\n" +
1482
		"	(new D.E(null, null, null, new F(get()) {}) {}).execute();	\n" +
1483
		"	     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1484
		"The type new D.E(){} is never used locally\n" +
1485
		"----------\n" +
1486
		"6. WARNING in p1\\A2.java (at line 20)\n" +
1487
		"	(new D.E(null, null, null, new F(get()) {}) {}).execute();	\n" +
1488
		"	                               ^^^^^^^^\n" +
1489
		"The type new F(){} is never used locally\n" +
1475
		"----------\n");
1490
		"----------\n");
1476
}
1491
}
1477
/**
1492
/**
Lines 1556-1565 Link Here
1556
		"	              ^\n" +
1571
		"	              ^\n" +
1557
		"Access to enclosing constructor A2.B() is emulated by a synthetic accessor method\n" +
1572
		"Access to enclosing constructor A2.B() is emulated by a synthetic accessor method\n" +
1558
		"----------\n" +
1573
		"----------\n" +
1559
		"3. ERROR in p1\\A2.java (at line 20)\n" +
1574
		"3. WARNING in p1\\A2.java (at line 19)\n" +
1575
		"	public void foo() {	\n" +
1576
		"	            ^^^^^\n" +
1577
		"The method foo() from the type A2.C is never used locally\n" +
1578
		"----------\n" +
1579
		"4. ERROR in p1\\A2.java (at line 20)\n" +
1560
		"	(new D.E(null, null, null, new F(get()) {})).execute();	\n" +
1580
		"	(new D.E(null, null, null, new F(get()) {})).execute();	\n" +
1561
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1581
		"	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
1562
		"No enclosing instance of type D is accessible. Must qualify the allocation with an enclosing instance of type D (e.g. x.new A() where x is an instance of D).\n" +
1582
		"No enclosing instance of type D is accessible. Must qualify the allocation with an enclosing instance of type D (e.g. x.new A() where x is an instance of D).\n" +
1583
		"----------\n" +
1584
		"5. WARNING in p1\\A2.java (at line 20)\n" +
1585
		"	(new D.E(null, null, null, new F(get()) {})).execute();	\n" +
1586
		"	                               ^^^^^^^^\n" +
1587
		"The type new F(){} is never used locally\n" +
1563
		"----------\n");
1588
		"----------\n");
1564
}
1589
}
1565
/**
1590
/**
Lines 5579-5585 Link Here
5579
			"}", // =================,
5604
			"}", // =================,
5580
		},
5605
		},
5581
		"----------\n" +
5606
		"----------\n" +
5582
		"1. ERROR in p\\X.java (at line 11)\n" +
5607
		"1. WARNING in p\\X.java (at line 5)\n" +
5608
		"	String variable = \"my testing\";\n" +
5609
		"	       ^^^^^^^^\n" +
5610
		"The field X.Outer.Inner.variable is never read locally\n" + 
5611
		"----------\n" +
5612
		"2. ERROR in p\\X.java (at line 11)\n" +
5583
		"	Zork z;\n" +
5613
		"	Zork z;\n" +
5584
		"	^^^^\n" +
5614
		"	^^^^\n" +
5585
		"Zork cannot be resolved to a type\n" +
5615
		"Zork cannot be resolved to a type\n" +
Lines 5633-5639 Link Here
5633
			"}", // =================,
5663
			"}", // =================,
5634
		},
5664
		},
5635
		"----------\n" +
5665
		"----------\n" +
5636
		"1. ERROR in p\\X.java (at line 12)\n" +
5666
		"1. WARNING in p\\X.java (at line 4)\n" + 
5667
		"	String variable = \"my testing\";\n" +
5668
		"	       ^^^^^^^^\n" + 
5669
		"The field X.Outer.Inner.variable is never read locally\n" + 
5670
		"----------\n" +
5671
		"2. ERROR in p\\X.java (at line 12)\n" +
5637
		"	Zork z;\n" +
5672
		"	Zork z;\n" +
5638
		"	^^^^\n" +
5673
		"	^^^^\n" +
5639
		"Zork cannot be resolved to a type\n" +
5674
		"Zork cannot be resolved to a type\n" +
Lines 6423-6444 Link Here
6423
				"	              ^^^^^\n" +
6458
				"	              ^^^^^\n" +
6424
				"The type X.Test4 is never used locally\n" +
6459
				"The type X.Test4 is never used locally\n" +
6425
				"----------\n" +
6460
				"----------\n" +
6426
				"2. ERROR in X.java (at line 16)\n" +
6461
				"2. WARNING in X.java (at line 13)\n" +
6462
				"	public Test4() {\n" +
6463
				"	       ^^^^^^^\n" +
6464
				"The constructor X.Test4() is never used locally\n" + 
6465
				"----------\n" +
6466
				"3. WARNING in X.java (at line 14)\n" + 
6467
				"	super(\"available\", new Test3() {\n" + 
6468
				"	                       ^^^^^^^\n" +
6469
				"The type new X.Test3(){} is never used locally\n" + 
6470
				"----------\n" +
6471
				"4. ERROR in X.java (at line 16)\n" +
6427
				"	System.out.println(X.this.var1.trim());\n" +
6472
				"	System.out.println(X.this.var1.trim());\n" +
6428
				"	                   ^^^^^^\n" +
6473
				"	                   ^^^^^^\n" +
6429
				"No enclosing instance of the type X is accessible in scope\n" +
6474
				"No enclosing instance of the type X is accessible in scope\n" +
6430
				"----------\n" +
6475
				"----------\n" +
6431
				"3. WARNING in X.java (at line 16)\n" +
6476
				"5. WARNING in X.java (at line 16)\n" +
6432
				"	System.out.println(X.this.var1.trim());\n" +
6477
				"	System.out.println(X.this.var1.trim());\n" +
6433
				"	                          ^^^^\n" +
6478
				"	                          ^^^^\n" +
6434
				"Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" +
6479
				"Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" +
6435
				"----------\n" +
6480
				"----------\n" +
6436
				"4. WARNING in X.java (at line 17)\n" +
6481
				"6. WARNING in X.java (at line 17)\n" +
6437
				"	System.out.println(var1.trim());\n" +
6482
				"	System.out.println(var1.trim());\n" +
6438
				"	                   ^^^^\n" +
6483
				"	                   ^^^^\n" +
6439
				"Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" +
6484
				"Read access to enclosing field X.var1 is emulated by a synthetic accessor method\n" +
6440
				"----------\n" +
6485
				"----------\n" +
6441
				"5. ERROR in X.java (at line 17)\n" +
6486
				"7. ERROR in X.java (at line 17)\n" +
6442
				"	System.out.println(var1.trim());\n" +
6487
				"	System.out.println(var1.trim());\n" +
6443
				"	                   ^^^^\n" +
6488
				"	                   ^^^^\n" +
6444
				"No enclosing instance of the type X is accessible in scope\n" +
6489
				"No enclosing instance of the type X is accessible in scope\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (-2 / +12 lines)
Lines 6286-6292 Link Here
6286
			"}"
6286
			"}"
6287
		},
6287
		},
6288
		"----------\n" +
6288
		"----------\n" +
6289
		"1. ERROR in X.java (at line 26)\n" +
6289
		"1. WARNING in X.java (at line 12)\n" +
6290
		"	ReturnBase bar();\n" +
6291
		"	           ^^^^^\n" +
6292
		"The method bar() from the type X.Interface is never used locally\n" +
6293
		"----------\n" +
6294
		"2. ERROR in X.java (at line 26)\n" +
6290
		"	public ReturnLeaf bar() {\n" +
6295
		"	public ReturnLeaf bar() {\n" +
6291
		"	                  ^^^^^\n" +
6296
		"	                  ^^^^^\n" +
6292
		"Cannot override the final method from X.Implementation\n" +
6297
		"Cannot override the final method from X.Implementation\n" +
Lines 6707-6713 Link Here
6707
			"}"
6712
			"}"
6708
		},
6713
		},
6709
		"----------\n" +
6714
		"----------\n" +
6710
		"1. ERROR in X.java (at line 26)\n" +
6715
		"1. WARNING in X.java (at line 12)\n" +
6716
		"	ReturnBase bar();\n" +
6717
		"	           ^^^^^\n" +
6718
		"The method bar() from the type X.Interface<E> is never used locally\n" +
6719
		"----------\n" +
6720
		"2. ERROR in X.java (at line 26)\n" +
6711
		"	public ReturnLeaf bar() {\n" +
6721
		"	public ReturnLeaf bar() {\n" +
6712
		"	                  ^^^^^\n" +
6722
		"	                  ^^^^^\n" +
6713
		"Cannot override the final method from X.Implementation<V>\n" +
6723
		"Cannot override the final method from X.Implementation<V>\n" +
(-)src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java (+49 lines)
Lines 271-276 Link Here
271
				"	}\n" +
271
				"	}\n" +
272
				"}\n" };
272
				"}\n" };
273
	}
273
	}
274
	// The fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=201912 results in these additional
275
	// diagnostics to be generated. Just as we arrange for the ``referencedClasses'' to be compiled
276
	// automatically, we need to include these diagnostics automatically in the expected messages.
277
	static String expectedDiagnosticsFromReferencedClasses = 
278
		"----------\n" + 
279
		"1. WARNING in test\\AbstractVisibility.java (at line 5)\n" + 
280
		"	public int avf_public = avf_private;\n" + 
281
		"	           ^^^^^^^^^^\n" + 
282
		"The field AbstractVisibility.AvcPrivate.avf_public is never read locally\n" + 
283
		"----------\n" + 
284
		"2. WARNING in test\\AbstractVisibility.java (at line 10)\n" + 
285
		"	public int avm_public() {\n" + 
286
		"	           ^^^^^^^^^^^^\n" + 
287
		"The method avm_public() from the type AbstractVisibility.AvcPrivate is never used locally\n" + 
288
		"----------\n" + 
289
		"----------\n" + 
290
		"1. WARNING in test\\Visibility.java (at line 5)\n" + 
291
		"	public int vf_public = vf_private;\n" + 
292
		"	           ^^^^^^^^^\n" + 
293
		"The field Visibility.VcPrivate.vf_public is never read locally\n" + 
294
		"----------\n" + 
295
		"2. WARNING in test\\Visibility.java (at line 11)\n" + 
296
		"	public int vm_public() {\n" + 
297
		"	           ^^^^^^^^^^^\n" + 
298
		"The method vm_public() from the type Visibility.VcPrivate is never used locally\n" + 
299
		"----------\n" + 
300
		"----------\n" + 
301
		"1. WARNING in test\\copy\\VisibilityPackage.java (at line 5)\n" + 
302
		"	public int vf_public = vf_private;\n" + 
303
		"	           ^^^^^^^^^\n" + 
304
		"The field VisibilityPackage.VpPrivate.vf_public is never read locally\n" + 
305
		"----------\n" + 
306
		"2. WARNING in test\\copy\\VisibilityPackage.java (at line 10)\n" + 
307
		"	public int vm_public() {\n" + 
308
		"	           ^^^^^^^^^^^\n" + 
309
		"The method vm_public() from the type VisibilityPackage.VpPrivate is never used locally\n" + 
310
		"----------\n" + 
311
		"----------\n" + 
312
		"1. WARNING in test\\copy\\VisibilityPublic.java (at line 5)\n" + 
313
		"	public int vf_public = vf_private;\n" + 
314
		"	           ^^^^^^^^^\n" + 
315
		"The field VisibilityPublic.VpPrivate.vf_public is never read locally\n" + 
316
		"----------\n" + 
317
		"2. WARNING in test\\copy\\VisibilityPublic.java (at line 10)\n" + 
318
		"	public int vm_public() {\n" + 
319
		"	           ^^^^^^^^^^^\n" + 
320
		"The method vm_public() from the type VisibilityPublic.VpPrivate is never used locally\n" + 
321
		"----------\n";
274
	/* (non-Javadoc)
322
	/* (non-Javadoc)
275
	 * @see junit.framework.TestCase#setUp()
323
	 * @see junit.framework.TestCase#setUp()
276
	 */
324
	 */
Lines 312-317 Link Here
312
			completedFiles = new String[testFiles.length + referencedClasses.length];
360
			completedFiles = new String[testFiles.length + referencedClasses.length];
313
			System.arraycopy(referencedClasses, 0, completedFiles, 0, referencedClasses.length);
361
			System.arraycopy(referencedClasses, 0, completedFiles, 0, referencedClasses.length);
314
			System.arraycopy(testFiles, 0, completedFiles, referencedClasses.length, testFiles.length);
362
			System.arraycopy(testFiles, 0, completedFiles, referencedClasses.length, testFiles.length);
363
			expected = expectedDiagnosticsFromReferencedClasses + expected;
315
		}
364
		}
316
		runNegativeTest(completedFiles, expected, javacTestOptions);
365
		runNegativeTest(completedFiles, expected, javacTestOptions);
317
	}
366
	}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProblemConstructorTest.java (+56 lines)
Lines 138-141 Link Here
138
		"Zork cannot be resolved to a type\n" +
138
		"Zork cannot be resolved to a type\n" +
139
		"----------\n");
139
		"----------\n");
140
}
140
}
141
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=201912, test to make sure that unused public members of 
142
// private class (including constructors, fields, types and methods) get warned about.
143
public void test004() {
144
	this.runNegativeTest(
145
		new String[] {
146
				"X.java",
147
				"public class X {\n" +
148
				"	private class M { \n" + // expect unused field, method, constructor and type warnings
149
				"       private int state = 0;\n" +
150
				"       public int unusedMethod() { return this.state; }\n" +
151
				"       public M (int state) { this.state = state;} \n" +
152
				"       public int unusedField = 0;\n" +
153
				"       public class N {}\n" +
154
				"	}\n" +
155
				"	private class N { \n" +  // No warnings should come from within here
156
				"       private int state = 0;\n" +
157
				"       public int usedMethod() { new O(); return new N(this.state + this.usedField).state; }\n" +
158
				"       public N (int state) { this.state = state;} \n" +
159
				"       public int usedField = 0;\n" +
160
				"       public class O {}\n" +
161
				"	}\n" +
162
				"	public class P { \n" + // No warnings should come from within here.
163
				"       private int state = 0;\n" +
164
				"       public int unusedMethod() { return this.state; }\n" +
165
				"       public P (int state) { this.state = state;} \n" +
166
				"       public int unusedField = 0;\n" +
167
				"       public class N {}\n" +
168
				"	}\n" +
169
				"	public M foo(M m, N n) {\n" +
170
				"   n.usedMethod(); return m;\n" +
171
				"	}\n" +
172
				"} \n"
173
			},
174
			"----------\n" + 
175
			"1. WARNING in X.java (at line 4)\n" + 
176
			"	public int unusedMethod() { return this.state; }\n" + 
177
			"	           ^^^^^^^^^^^^^^\n" + 
178
			"The method unusedMethod() from the type X.M is never used locally\n" + 
179
			"----------\n" + 
180
			"2. WARNING in X.java (at line 5)\n" + 
181
			"	public M (int state) { this.state = state;} \n" + 
182
			"	       ^^^^^^^^^^^^^\n" + 
183
			"The constructor X.M(int) is never used locally\n" + 
184
			"----------\n" + 
185
			"3. WARNING in X.java (at line 6)\n" + 
186
			"	public int unusedField = 0;\n" + 
187
			"	           ^^^^^^^^^^^\n" + 
188
			"The field X.M.unusedField is never read locally\n" + 
189
			"----------\n" + 
190
			"4. WARNING in X.java (at line 7)\n" + 
191
			"	public class N {}\n" + 
192
			"	             ^\n" + 
193
			"The type X.M.N is never used locally\n" + 
194
			"----------\n"
195
			);
196
}
141
}
197
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-1 / +6 lines)
Lines 41220-41226 Link Here
41220
		"The type A.P is not visible\n" +
41220
		"The type A.P is not visible\n" +
41221
		"----------\n" +
41221
		"----------\n" +
41222
		"----------\n" +
41222
		"----------\n" +
41223
		"1. WARNING in p\\A.java (at line 18)\n" +
41223
		"1. WARNING in p\\A.java (at line 9)\n" +
41224
		"	public int pval;\n" +
41225
		"	           ^^^^\n" +
41226
		"The field A.P.pval is never read locally\n" +
41227
		"----------\n" +
41228
		"2. WARNING in p\\A.java (at line 18)\n" +
41224
		"	this.box.set(new P());\n" +
41229
		"	this.box.set(new P());\n" +
41225
		"	             ^^^^^^^\n" +
41230
		"	             ^^^^^^^\n" +
41226
		"Access to enclosing constructor A.P() is emulated by a synthetic accessor method\n" +
41231
		"Access to enclosing constructor A.P() is emulated by a synthetic accessor method\n" +
(-)compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java (-1 / +1 lines)
Lines 49-55 Link Here
49
49
50
			if (!this.binding.isUsed() &&
50
			if (!this.binding.isUsed() &&
51
					(this.binding.isPrivate()
51
					(this.binding.isPrivate()
52
						|| (((this.binding.modifiers & (ExtraCompilerModifiers.AccOverriding|ExtraCompilerModifiers.AccImplementing)) == 0) && this.binding.declaringClass.isLocalType()))) {
52
						|| (((this.binding.modifiers & (ExtraCompilerModifiers.AccOverriding|ExtraCompilerModifiers.AccImplementing)) == 0) && (this.binding.declaringClass.isLocalType() || this.binding.isOrEnclosedByPrivateType())))) {
53
				if (!classScope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
53
				if (!classScope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
54
					this.scope.problemReporter().unusedPrivateMethod(this);
54
					this.scope.problemReporter().unusedPrivateMethod(this);
55
				}
55
				}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/FieldDeclaration.java (-1 / +1 lines)
Lines 52-58 Link Here
52
52
53
public FlowInfo analyseCode(MethodScope initializationScope, FlowContext flowContext, FlowInfo flowInfo) {
53
public FlowInfo analyseCode(MethodScope initializationScope, FlowContext flowContext, FlowInfo flowInfo) {
54
	if (this.binding != null && !this.binding.isUsed()) {
54
	if (this.binding != null && !this.binding.isUsed()) {
55
		if (this.binding.isPrivate() || (this.binding.declaringClass != null && this.binding.declaringClass.isLocalType())) {
55
		if (this.binding.isOrEnclosedByPrivateType() || (this.binding.declaringClass != null && this.binding.declaringClass.isLocalType())) {
56
			if (!initializationScope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
56
			if (!initializationScope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
57
				initializationScope.problemReporter().unusedPrivateField(this);
57
				initializationScope.problemReporter().unusedPrivateField(this);
58
			}
58
			}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java (-1 / +1 lines)
Lines 611-617 Link Here
611
 *	Common flow analysis for all types
611
 *	Common flow analysis for all types
612
 */
612
 */
613
private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) {
613
private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) {
614
	if ((this.binding.isPrivate() || (this.binding.tagBits & (TagBits.IsAnonymousType|TagBits.IsLocalType)) == TagBits.IsLocalType) && !this.binding.isUsed()) {
614
	if ((this.binding.isOrEnclosedByPrivateType() || (this.binding.tagBits & (TagBits.IsAnonymousType|TagBits.IsLocalType)) == TagBits.IsLocalType) && !this.binding.isUsed()) {
615
		if (!this.scope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
615
		if (!this.scope.referenceCompilationUnit().compilationResult.hasSyntaxError) {
616
			this.scope.problemReporter().unusedPrivateType(this);
616
			this.scope.problemReporter().unusedPrivateType(this);
617
		}
617
		}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java (+2 lines)
Lines 59-64 Link Here
59
		if (constructorBinding.isPrivate()) {
59
		if (constructorBinding.isPrivate()) {
60
			if ((this.binding.declaringClass.tagBits & TagBits.HasNonPrivateConstructor) == 0)
60
			if ((this.binding.declaringClass.tagBits & TagBits.HasNonPrivateConstructor) == 0)
61
				break checkUnused; // tolerate as known pattern to block instantiation
61
				break checkUnused; // tolerate as known pattern to block instantiation
62
		} else if (constructorBinding.isOrEnclosedByPrivateType()) {
63
			// fall through and complain unused: https://bugs.eclipse.org/bugs/show_bug.cgi?id=201912
62
		} else if ((this.binding.declaringClass.tagBits & (TagBits.IsAnonymousType|TagBits.IsLocalType)) != TagBits.IsLocalType) {
64
		} else if ((this.binding.declaringClass.tagBits & (TagBits.IsAnonymousType|TagBits.IsLocalType)) != TagBits.IsLocalType) {
63
			break checkUnused;
65
			break checkUnused;
64
		}
66
		}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java (-3 / +3 lines)
Lines 356-362 Link Here
356
		// ignore references insing Javadoc comments
356
		// ignore references insing Javadoc comments
357
		if ((this.bits & ASTNode.InsideJavadoc) ==0 &&
357
		if ((this.bits & ASTNode.InsideJavadoc) ==0 &&
358
				!isStrictlyAssigned &&
358
				!isStrictlyAssigned &&
359
				(field.isPrivate() || (field.declaringClass != null && field.declaringClass.isLocalType())) && !scope.isDefinedInField(field)) {
359
				(field.isOrEnclosedByPrivateType() || (field.declaringClass != null && field.declaringClass.isLocalType())) && !scope.isDefinedInField(field)) {
360
			// ignore cases where field is used from within inside itself
360
			// ignore cases where field is used from within inside itself
361
			field.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
361
			field.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
362
		}
362
		}
Lines 393-399 Link Here
393
			boolean isExplicitUse) {
393
			boolean isExplicitUse) {
394
		// ignore references insing Javadoc comments
394
		// ignore references insing Javadoc comments
395
		if ((this.bits & ASTNode.InsideJavadoc) ==0 &&
395
		if ((this.bits & ASTNode.InsideJavadoc) ==0 &&
396
				(method.isPrivate() || method.declaringClass.isLocalType()) && !scope.isDefinedInMethod(method)) {
396
				(method.isOrEnclosedByPrivateType() || method.declaringClass.isLocalType()) && !scope.isDefinedInMethod(method)) {
397
			// ignore cases where method is used from within inside itself (e.g. direct recursions)
397
			// ignore cases where method is used from within inside itself (e.g. direct recursions)
398
			method.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
398
			method.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
399
		}
399
		}
Lines 452-458 Link Here
452
		ReferenceBinding refType = (ReferenceBinding) type;
452
		ReferenceBinding refType = (ReferenceBinding) type;
453
		// ignore references insing Javadoc comments
453
		// ignore references insing Javadoc comments
454
		if ((this.bits & ASTNode.InsideJavadoc) == 0 &&
454
		if ((this.bits & ASTNode.InsideJavadoc) == 0 &&
455
				(refType.isPrivate() || refType.isLocalType()) && !scope.isDefinedInType(refType)) {
455
				(refType.isOrEnclosedByPrivateType() || refType.isLocalType()) && !scope.isDefinedInType(refType)) {
456
			// ignore cases where type is used from within inside itself
456
			// ignore cases where type is used from within inside itself
457
			((ReferenceBinding)refType.erasure()).modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
457
			((ReferenceBinding)refType.erasure()).modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
458
		}
458
		}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java (+5 lines)
Lines 205-210 Link Here
205
	if (concreteMethod.thrownExceptions != Binding.NO_EXCEPTIONS)
205
	if (concreteMethod.thrownExceptions != Binding.NO_EXCEPTIONS)
206
		for (int i = abstractMethods.length; --i >= 0;)
206
		for (int i = abstractMethods.length; --i >= 0;)
207
			checkExceptions(concreteMethod, abstractMethods[i]);
207
			checkExceptions(concreteMethod, abstractMethods[i]);
208
	if (concreteMethod.isOrEnclosedByPrivateType()) {
209
		// A subclass inheriting this method and putting it up as the implementation to meet its own
210
		// obligations should qualify as a use.
211
		concreteMethod.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
212
	}
208
}
213
}
209
214
210
/*
215
/*
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java (+8 lines)
Lines 286-291 Link Here
286
public final boolean isPrivate() {
286
public final boolean isPrivate() {
287
	return (this.modifiers & ClassFileConstants.AccPrivate) != 0;
287
	return (this.modifiers & ClassFileConstants.AccPrivate) != 0;
288
}
288
}
289
/* Answer true if the receiver has private visibility or is enclosed by a class that does.
290
*/
291
292
public final boolean isOrEnclosedByPrivateType() {
293
	if ((this.modifiers & ClassFileConstants.AccPrivate) != 0)
294
		return true;
295
	return this.declaringClass != null && this.declaringClass.isOrEnclosedByPrivateType();
296
}
289
/* Answer true if the receiver has private visibility and is used locally
297
/* Answer true if the receiver has private visibility and is used locally
290
*/
298
*/
291
299
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java (+9 lines)
Lines 748-753 Link Here
748
public final boolean isPrivate() {
748
public final boolean isPrivate() {
749
	return (this.modifiers & ClassFileConstants.AccPrivate) != 0;
749
	return (this.modifiers & ClassFileConstants.AccPrivate) != 0;
750
}
750
}
751
752
/* Answer true if the receiver has private visibility or if any of its enclosing types do.
753
*/
754
public final boolean isOrEnclosedByPrivateType() {
755
	if ((this.modifiers & ClassFileConstants.AccPrivate) != 0)
756
		return true;
757
	return this.declaringClass != null && this.declaringClass.isOrEnclosedByPrivateType();
758
}
759
751
/* Answer true if the receiver has protected visibility
760
/* Answer true if the receiver has protected visibility
752
*/
761
*/
753
public final boolean isProtected() {
762
public final boolean isProtected() {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java (+14 lines)
Lines 1077-1082 Link Here
1077
}
1077
}
1078
1078
1079
/**
1079
/**
1080
 * Answer true if the receiver or any of its enclosing types have private visibility
1081
 */
1082
public final boolean isOrEnclosedByPrivateType() {
1083
	ReferenceBinding type = this;
1084
	while (type != null) {
1085
		if ((type.modifiers & ClassFileConstants.AccPrivate) != 0)
1086
			return true;
1087
		type = type.enclosingType();
1088
	}
1089
	return false;
1090
}
1091
1092
1093
/**
1080
 * Answer true if the receiver has protected visibility
1094
 * Answer true if the receiver has protected visibility
1081
 */
1095
 */
1082
public final boolean isProtected() {
1096
public final boolean isProtected() {

Return to bug 201912