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

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier.java (-2 / +17 lines)
Lines 423-437 Link Here
423
void checkMethods() {
423
void checkMethods() {
424
	boolean mustImplementAbstractMethods = mustImplementAbstractMethods();
424
	boolean mustImplementAbstractMethods = mustImplementAbstractMethods();
425
	boolean skipInheritedMethods = mustImplementAbstractMethods && canSkipInheritedMethods(); // have a single concrete superclass so only check overridden methods
425
	boolean skipInheritedMethods = mustImplementAbstractMethods && canSkipInheritedMethods(); // have a single concrete superclass so only check overridden methods
426
	boolean isOrEnclosedByPrivateType = this.type.isOrEnclosedByPrivateType();
426
	char[][] methodSelectors = this.inheritedMethods.keyTable;
427
	char[][] methodSelectors = this.inheritedMethods.keyTable;
427
	nextSelector : for (int s = methodSelectors.length; --s >= 0;) {
428
	nextSelector : for (int s = methodSelectors.length; --s >= 0;) {
428
		if (methodSelectors[s] == null) continue nextSelector;
429
		if (methodSelectors[s] == null) continue nextSelector;
429
430
430
		MethodBinding[] current = (MethodBinding[]) this.currentMethods.get(methodSelectors[s]);
431
		MethodBinding[] current = (MethodBinding[]) this.currentMethods.get(methodSelectors[s]);
432
		MethodBinding[] inherited = (MethodBinding[]) this.inheritedMethods.valueTable[s];
433
		
434
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660, if current type is exposed,
435
		// inherited methods of super classes are too. current != null case handled below.
436
		if (current == null && !isOrEnclosedByPrivateType) {
437
			int length = inherited.length;
438
			for (int i = 0; i < length; i++){
439
				inherited[i].original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
440
			}
441
		}
442
431
		if (current == null && skipInheritedMethods)
443
		if (current == null && skipInheritedMethods)
432
			continue nextSelector;
444
			continue nextSelector;
433
445
434
		MethodBinding[] inherited = (MethodBinding[]) this.inheritedMethods.valueTable[s];
435
		if (inherited.length == 1 && current == null) { // handle the common case
446
		if (inherited.length == 1 && current == null) { // handle the common case
436
			if (mustImplementAbstractMethods && inherited[0].isAbstract())
447
			if (mustImplementAbstractMethods && inherited[0].isAbstract())
437
				checkAbstractMethod(inherited[0]);
448
				checkAbstractMethod(inherited[0]);
Lines 462-468 Link Here
462
		for (int i = 0, length = inherited.length; i < length; i++) {
473
		for (int i = 0, length = inherited.length; i < length; i++) {
463
			MethodBinding inheritedMethod = inherited[i];
474
			MethodBinding inheritedMethod = inherited[i];
464
			if (inheritedMethod == null) continue;
475
			if (inheritedMethod == null) continue;
465
476
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660, if current type is exposed,
477
			// inherited methods of super classes are too. current == null case handled already.
478
			if (!isOrEnclosedByPrivateType && current != null) {
479
				inheritedMethod.original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
480
			}
466
			matchingInherited[++index] = inheritedMethod;
481
			matchingInherited[++index] = inheritedMethod;
467
			for (int j = i + 1; j < length; j++) {
482
			for (int j = i + 1; j < length; j++) {
468
				MethodBinding otherInheritedMethod = inherited[j];
483
				MethodBinding otherInheritedMethod = inherited[j];
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodVerifier15.java (-2 / +18 lines)
Lines 366-380 Link Here
366
void checkMethods() {
366
void checkMethods() {
367
	boolean mustImplementAbstractMethods = mustImplementAbstractMethods();
367
	boolean mustImplementAbstractMethods = mustImplementAbstractMethods();
368
	boolean skipInheritedMethods = mustImplementAbstractMethods && canSkipInheritedMethods(); // have a single concrete superclass so only check overridden methods
368
	boolean skipInheritedMethods = mustImplementAbstractMethods && canSkipInheritedMethods(); // have a single concrete superclass so only check overridden methods
369
	boolean isOrEnclosedByPrivateType = this.type.isOrEnclosedByPrivateType();
369
	char[][] methodSelectors = this.inheritedMethods.keyTable;
370
	char[][] methodSelectors = this.inheritedMethods.keyTable;
370
	nextSelector : for (int s = methodSelectors.length; --s >= 0;) {
371
	nextSelector : for (int s = methodSelectors.length; --s >= 0;) {
371
		if (methodSelectors[s] == null) continue nextSelector;
372
		if (methodSelectors[s] == null) continue nextSelector;
372
373
373
		MethodBinding[] current = (MethodBinding[]) this.currentMethods.get(methodSelectors[s]);
374
		MethodBinding[] current = (MethodBinding[]) this.currentMethods.get(methodSelectors[s]);
375
		MethodBinding[] inherited = (MethodBinding[]) this.inheritedMethods.valueTable[s];
376
		
377
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660, if current type is exposed,
378
		// inherited methods of super classes are too. current != null case handled below.
379
		if (current == null && !isOrEnclosedByPrivateType) {
380
			int length = inherited.length;
381
			for (int i = 0; i < length; i++){
382
				inherited[i].original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
383
			}
384
		}
385
374
		if (current == null && skipInheritedMethods)
386
		if (current == null && skipInheritedMethods)
375
			continue nextSelector;
387
			continue nextSelector;
376
388
377
		MethodBinding[] inherited = (MethodBinding[]) this.inheritedMethods.valueTable[s];
378
		if (inherited.length == 1 && current == null) { // handle the common case
389
		if (inherited.length == 1 && current == null) { // handle the common case
379
			if (mustImplementAbstractMethods && inherited[0].isAbstract())
390
			if (mustImplementAbstractMethods && inherited[0].isAbstract())
380
				checkAbstractMethod(inherited[0]);
391
				checkAbstractMethod(inherited[0]);
Lines 420-428 Link Here
420
		// either because they match the same currentMethod or match each other
431
		// either because they match the same currentMethod or match each other
421
		boolean[] skip = new boolean[inheritedLength];
432
		boolean[] skip = new boolean[inheritedLength];
422
		for (int i = 0; i < inheritedLength; i++) {
433
		for (int i = 0; i < inheritedLength; i++) {
434
			MethodBinding matchMethod = foundMatch[i];
435
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660, if current type is exposed,
436
			// inherited methods of super classes are too. current == null case handled already.
437
			if (!isOrEnclosedByPrivateType && matchMethod == null && current != null) {
438
				inherited[i].original().modifiers |= ExtraCompilerModifiers.AccLocallyUsed;	
439
			}
423
			if (skip[i]) continue;
440
			if (skip[i]) continue;
424
			MethodBinding inheritedMethod = inherited[i];
441
			MethodBinding inheritedMethod = inherited[i];
425
			MethodBinding matchMethod = foundMatch[i];
426
			if (matchMethod == null)
442
			if (matchMethod == null)
427
				matchingInherited[++index] = inheritedMethod;
443
				matchingInherited[++index] = inheritedMethod;
428
			for (int j = i + 1; j < inheritedLength; j++) {
444
			for (int j = i + 1; j < inheritedLength; j++) {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java (+264 lines)
Lines 4984-4987 Link Here
4984
		"TheFieldDeclaratation cannot be resolved to a type\n" + 
4984
		"TheFieldDeclaratation cannot be resolved to a type\n" + 
4985
		"----------\n");
4985
		"----------\n");
4986
}
4986
}
4987
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
4988
public void test098() {
4989
	this.runNegativeTest(
4990
		new String[] {
4991
			"X.java",
4992
			"public class X {\n" +
4993
			"    private class A {\n" +
4994
			"    	public void foo(int a) {\n" +
4995
			"   		System.out.println(\"Hello\");\n" +    
4996
			"    	}\n" +
4997
			"	    public void foo(float a) {\n" +
4998
			"   		System.out.println(\"Hello\");\n" + 
4999
			"   	}\n" +
5000
			"   	public void foo(boolean a) {\n" +
5001
			"   		System.out.println(\"Hello\");\n" +    
5002
			"   	}\n" +
5003
			"      	public void foo(Integer a) {\n" +
5004
			"   		System.out.println(\"Hello\");\n" +    
5005
			"   	}\n" +
5006
			"   }\n" + 
5007
			"   private class B extends A {\n" +
5008
			"		public void foo(int a) {\n" +
5009
			"   		System.out.println(\"Hello\");\n" +    
5010
			"   	}\n" +
5011
			"		public void foo(float a) {\n" +
5012
			"   		System.out.println(\"Hello\");\n" +    
5013
			"   	}\n" +
5014
			"   	public void foo(double a) {\n" +
5015
			"   		System.out.println(\"Hello\");\n" +    
5016
			"   	}\n" +
5017
			"   	public void foo(char a) {\n" +
5018
			"   		System.out.println(\"Hello\");\n" +    
5019
			"   	}\n" +
5020
			"   }\n" +
5021
			"}\n"
5022
		},
5023
		"----------\n" + 
5024
		"1. WARNING in X.java (at line 3)\n" + 
5025
		"	public void foo(int a) {\n" + 
5026
		"	            ^^^^^^^^^^\n" + 
5027
		"The method foo(int) from the type X.A is never used locally\n" + 
5028
		"----------\n" + 
5029
		"2. WARNING in X.java (at line 6)\n" + 
5030
		"	public void foo(float a) {\n" + 
5031
		"	            ^^^^^^^^^^^^\n" + 
5032
		"The method foo(float) from the type X.A is never used locally\n" + 
5033
		"----------\n" + 
5034
		"3. WARNING in X.java (at line 9)\n" + 
5035
		"	public void foo(boolean a) {\n" + 
5036
		"	            ^^^^^^^^^^^^^^\n" + 
5037
		"The method foo(boolean) from the type X.A is never used locally\n" + 
5038
		"----------\n" + 
5039
		"4. WARNING in X.java (at line 12)\n" + 
5040
		"	public void foo(Integer a) {\n" + 
5041
		"	            ^^^^^^^^^^^^^^\n" + 
5042
		"The method foo(Integer) from the type X.A is never used locally\n" + 
5043
		"----------\n" + 
5044
		"5. WARNING in X.java (at line 16)\n" + 
5045
		"	private class B extends A {\n" + 
5046
		"	              ^\n" + 
5047
		"The type X.B is never used locally\n" + 
5048
		"----------\n" + 
5049
		"6. WARNING in X.java (at line 16)\n" + 
5050
		"	private class B extends A {\n" + 
5051
		"	              ^\n" + 
5052
		"Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + 
5053
		"----------\n" + 
5054
		"7. WARNING in X.java (at line 23)\n" + 
5055
		"	public void foo(double a) {\n" + 
5056
		"	            ^^^^^^^^^^^^^\n" + 
5057
		"The method foo(double) from the type X.B is never used locally\n" + 
5058
		"----------\n" + 
5059
		"8. WARNING in X.java (at line 26)\n" + 
5060
		"	public void foo(char a) {\n" + 
5061
		"	            ^^^^^^^^^^^\n" + 
5062
		"The method foo(char) from the type X.B is never used locally\n" + 
5063
		"----------\n");
5064
}
5065
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5066
public void test098b() {
5067
	this.runNegativeTest(
5068
		new String[] {
5069
			"X.java",
5070
			"public class X {\n" +
5071
			"    private class A {\n" +
5072
			"    	public void foo(int a) {\n" +
5073
			"   		System.out.println(\"Hello\");\n" +    
5074
			"    	}\n" +
5075
			"	    public void foo(float a) {\n" +
5076
			"   		System.out.println(\"Hello\");\n" + 
5077
			"   	}\n" +
5078
			"   	public void foo(boolean a) {\n" +
5079
			"   		System.out.println(\"Hello\");\n" +    
5080
			"   	}\n" +
5081
			"      	public void foo(Integer a) {\n" +
5082
			"   		System.out.println(\"Hello\");\n" +    
5083
			"   	}\n" +
5084
			"   }\n" + 
5085
			"   private class B extends A {\n" +
5086
			"		public void foo(int a) {\n" +
5087
			"   		System.out.println(\"Hello\");\n" +    
5088
			"   	}\n" +
5089
			"		public void foo(float a) {\n" +
5090
			"   		System.out.println(\"Hello\");\n" +    
5091
			"   	}\n" +
5092
			"   	public void foo(double a) {\n" +
5093
			"   		System.out.println(\"Hello\");\n" +    
5094
			"   	}\n" +
5095
			"   	public void foo(char a) {\n" +
5096
			"   		System.out.println(\"Hello\");\n" +    
5097
			"   	}\n" +
5098
			"   }\n" +
5099
			"   public class C extends B {\n" +
5100
		    "		public void foo(int a) {\n" +
5101
			"			System.out.println(\"Hello\");\n" +    
5102
			"		}\n" +
5103
		    "		public void foo(double a) {\n" +
5104
			"			System.out.println(\"Hello\");\n" +    
5105
			"		}\n" +
5106
			"		public void foo(boolean a) {\n" +
5107
			"			System.out.println(\"Hello\");\n" +    
5108
			"		}\n" +
5109
			"		public void foo(byte a) {\n" +
5110
			"			System.out.println(\"Hello\");\n" +     
5111
			"		}\n" +
5112
		    "   }\n" +
5113
			"}\n"
5114
		},
5115
		"----------\n" + 
5116
		"1. WARNING in X.java (at line 3)\n" + 
5117
		"	public void foo(int a) {\n" + 
5118
		"	            ^^^^^^^^^^\n" + 
5119
		"The method foo(int) from the type X.A is never used locally\n" + 
5120
		"----------\n" + 
5121
		"2. WARNING in X.java (at line 6)\n" + 
5122
		"	public void foo(float a) {\n" + 
5123
		"	            ^^^^^^^^^^^^\n" + 
5124
		"The method foo(float) from the type X.A is never used locally\n" + 
5125
		"----------\n" + 
5126
		"3. WARNING in X.java (at line 9)\n" + 
5127
		"	public void foo(boolean a) {\n" + 
5128
		"	            ^^^^^^^^^^^^^^\n" + 
5129
		"The method foo(boolean) from the type X.A is never used locally\n" + 
5130
		"----------\n" + 
5131
		"4. WARNING in X.java (at line 16)\n" + 
5132
		"	private class B extends A {\n" + 
5133
		"	              ^\n" + 
5134
		"Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + 
5135
		"----------\n" + 
5136
		"5. WARNING in X.java (at line 23)\n" + 
5137
		"	public void foo(double a) {\n" + 
5138
		"	            ^^^^^^^^^^^^^\n" + 
5139
		"The method foo(double) from the type X.B is never used locally\n" + 
5140
		"----------\n" + 
5141
		"6. WARNING in X.java (at line 30)\n" + 
5142
		"	public class C extends B {\n" + 
5143
		"	             ^\n" + 
5144
		"Access to enclosing constructor X.B() is emulated by a synthetic accessor method\n" + 
5145
		"----------\n");
5146
}
5147
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5148
public void test098c() {
5149
	this.runNegativeTest(
5150
		new String[] {
5151
			"X.java",
5152
			"public class X {\n" +
5153
			"    private class A {\n" +
5154
			"        public void foo() {}\n" +
5155
			"    }\n" +
5156
			"    public class B extends A {}\n" +
5157
			"}"
5158
		},
5159
		"----------\n" + 
5160
		"1. WARNING in X.java (at line 5)\n" + 
5161
		"	public class B extends A {}\n" + 
5162
		"	             ^\n" + 
5163
		"Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + 
5164
		"----------\n");
5165
}
5166
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5167
public void test098d() {
5168
	this.runNegativeTest(
5169
		new String[] {
5170
			"X.java",
5171
			"public class X {\n" +
5172
			"    private class A {\n" +
5173
			"        public void foo() {}\n" +
5174
			"        public void foo(int a) {}\n" +
5175
			"    }\n" +
5176
			"    public class B extends A {}\n" +
5177
			"}"
5178
		},
5179
		"----------\n" + 
5180
		"1. WARNING in X.java (at line 6)\n" + 
5181
		"	public class B extends A {}\n" + 
5182
		"	             ^\n" + 
5183
		"Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + 
5184
		"----------\n");
5185
}
5186
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5187
public void test098e() {
5188
	this.runNegativeTest(
5189
		new String[] {
5190
			"X.java",
5191
			"public class X {\n" +
5192
			"    private class A {\n" +
5193
			"        private void foo() {}\n" +
5194
			"        private void foo(int a) {}\n" +
5195
			"    }\n" +
5196
			"    public class B extends A {}\n" +
5197
			"}"
5198
		},
5199
		"----------\n" + 
5200
		"1. WARNING in X.java (at line 3)\n" + 
5201
		"	private void foo() {}\n" + 
5202
		"	             ^^^^^\n" + 
5203
		"The method foo() from the type X.A is never used locally\n" + 
5204
		"----------\n" + 
5205
		"2. WARNING in X.java (at line 4)\n" + 
5206
		"	private void foo(int a) {}\n" + 
5207
		"	             ^^^^^^^^^^\n" + 
5208
		"The method foo(int) from the type X.A is never used locally\n" + 
5209
		"----------\n" + 
5210
		"3. WARNING in X.java (at line 6)\n" + 
5211
		"	public class B extends A {}\n" + 
5212
		"	             ^\n" + 
5213
		"Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + 
5214
		"----------\n");
5215
}
5216
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=296660
5217
public void test098f() {
5218
	this.runNegativeTest(
5219
		new String[] {
5220
			"X.java",
5221
			"public class X {\n" +
5222
			"    private class A {\n" +
5223
			"        public void foo() {}\n" +
5224
			"        public void foo(int a) {}\n" +
5225
			"    }\n" +
5226
			"    private class B extends A {}\n" +
5227
			"}"
5228
		},
5229
		"----------\n" + 
5230
		"1. WARNING in X.java (at line 3)\n" + 
5231
		"	public void foo() {}\n" + 
5232
		"	            ^^^^^\n" + 
5233
		"The method foo() from the type X.A is never used locally\n" + 
5234
		"----------\n" + 
5235
		"2. WARNING in X.java (at line 4)\n" + 
5236
		"	public void foo(int a) {}\n" + 
5237
		"	            ^^^^^^^^^^\n" + 
5238
		"The method foo(int) from the type X.A is never used locally\n" + 
5239
		"----------\n" + 
5240
		"3. WARNING in X.java (at line 6)\n" + 
5241
		"	private class B extends A {}\n" + 
5242
		"	              ^\n" + 
5243
		"The type X.B is never used locally\n" + 
5244
		"----------\n" + 
5245
		"4. WARNING in X.java (at line 6)\n" + 
5246
		"	private class B extends A {}\n" + 
5247
		"	              ^\n" + 
5248
		"Access to enclosing constructor X.A() is emulated by a synthetic accessor method\n" + 
5249
		"----------\n");
5250
}
4987
}
5251
}

Return to bug 296660