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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java (-2 / +368 lines)
Lines 14-27 Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.util.Map;
15
import java.util.Map;
16
16
17
import junit.framework.*;
17
import junit.framework.Test;
18
18
19
import org.eclipse.jdt.core.ToolFactory;
19
import org.eclipse.jdt.core.ToolFactory;
20
import org.eclipse.jdt.core.tests.util.Util;
20
import org.eclipse.jdt.core.tests.util.Util;
21
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
21
import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
22
import org.eclipse.jdt.core.util.IClassFileReader;
23
import org.eclipse.jdt.core.util.IMethodInfo;
22
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
24
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
23
25
24
public class MethodVerifyTest extends AbstractComparableTest {
26
public class MethodVerifyTest extends AbstractComparableTest {
27
//	 Use this static initializer to specify subset for tests
28
//	 All specified tests which does not belong to the class are skipped...
29
	static {
30
		// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
31
//		TESTS_NAMES = new String[] { "Bug58069" };
32
		// Numbers of tests to run: "test<number>" will be run for each number of this array
33
		TESTS_NUMBERS = new int[] { 102, 103, 104, 105, 106 };
34
		// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last }
35
//		TESTS_RANGE = new int[] { 85, -1 };
36
	}
25
37
26
	public MethodVerifyTest(String name) {
38
	public MethodVerifyTest(String name) {
27
		super(name);
39
		super(name);
Lines 5256-5262 Link Here
5256
		);
5268
		);
5257
	}
5269
	}
5258
}
5270
}
5259
5260
// name conflict
5271
// name conflict
5261
public void test101() {
5272
public void test101() {
5262
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5273
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
Lines 5295-5298 Link Here
5295
		);
5306
		);
5296
	}
5307
	}
5297
}
5308
}
5309
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973
5310
public void test102() {
5311
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5312
		Map options = this.getCompilerOptions();
5313
		options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
5314
		this.runNegativeTest(
5315
			new String[] {
5316
				"X.java",
5317
				"public class X {\n" + 
5318
				"	private interface ReturnBase {\n" + 
5319
				"	}\n" + 
5320
				"\n" + 
5321
				"	private interface ReturnDerived extends ReturnBase {\n" + 
5322
				"	}\n" + 
5323
				"\n" + 
5324
				"	private interface ReturnLeaf extends ReturnDerived {\n" + 
5325
				"	}\n" + 
5326
				"\n" + 
5327
				"	private interface Interface {\n" + 
5328
				"		ReturnBase bar();\n" + 
5329
				"	}\n" + 
5330
				"\n" + 
5331
				"	private static class Implementation {\n" + 
5332
				"		public final ReturnDerived bar() {\n" + 
5333
				"			return null;\n" + 
5334
				"		}\n" + 
5335
				"	}\n" + 
5336
				"\n" + 
5337
				"	private static class Child extends Implementation implements Interface {\n" + 
5338
				"	}\n" + 
5339
				"\n" + 
5340
				"	private static class Grandchild extends Child implements Interface {\n" +
5341
				"		@Override\n" + 
5342
				"		public ReturnLeaf bar() {\n" + 
5343
				"			return null;\n" + 
5344
				"		}\n" + 
5345
				"	}\n" + 
5346
				"\n" + 
5347
				"	public static void main(String[] args) {\n" + 
5348
				"		new Grandchild();\n" + 
5349
				"	}\n" + 
5350
				"}"
5351
			},
5352
			"----------\n" + 
5353
			"1. ERROR in X.java (at line 26)\n" + 
5354
			"	public ReturnLeaf bar() {\n" + 
5355
			"	                  ^^^^^\n" + 
5356
			"Cannot override the final method from X.Implementation\n" + 
5357
			"----------\n",
5358
			null,
5359
			true,
5360
			options
5361
		);
5362
	}
5363
}
5364
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973
5365
public void test103() {
5366
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5367
		Map options = this.getCompilerOptions();
5368
		options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
5369
		this.runConformTest(
5370
			new String[] {
5371
				"X.java",
5372
				"public class X {\n" + 
5373
				"	private interface ReturnBase {\n" + 
5374
				"	}\n" + 
5375
				"\n" + 
5376
				"	private interface ReturnDerived extends ReturnBase {\n" + 
5377
				"	}\n" + 
5378
				"\n" + 
5379
				"	private interface Interface {\n" + 
5380
				"		ReturnBase bar();\n" + 
5381
				"	}\n" + 
5382
				"\n" + 
5383
				"	private static class Implementation {\n" + 
5384
				"		public final ReturnDerived bar() {\n" + 
5385
				"			return null;\n" + 
5386
				"		}\n" + 
5387
				"	}\n" + 
5388
				"\n" + 
5389
				"	private static class Grandchild extends Child implements Interface {\n" + 
5390
				"	}\n" + 
5391
				"\n" + 
5392
				"	private static class Child extends Implementation implements Interface {\n" + 
5393
				"	}\n" + 
5394
				"\n" + 
5395
				"	public static void main(String[] args) {\n" + 
5396
				"		new Grandchild();\n" + 
5397
				"	}\n" + 
5398
				"}"
5399
			},
5400
			"",
5401
			null,
5402
			true,
5403
			null,
5404
			options,
5405
			null
5406
		);
5407
		File fileX = new File(OUTPUT_DIR + File.separator  +"X$Child.class");
5408
		IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5409
		IMethodInfo[] methodInfos = reader.getMethodInfos();
5410
		boolean found = false;
5411
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5412
			if (new String(methodInfos[i].getName()).equals("bar")) {
5413
				found = true;
5414
				break;
5415
			}
5416
		}
5417
		assertTrue("bar should be there", found);
5418
		
5419
		fileX = new File(OUTPUT_DIR + File.separator  +"X$Grandchild.class");
5420
		reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5421
		methodInfos = reader.getMethodInfos();
5422
		found = false;
5423
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5424
			if (new String(methodInfos[i].getName()).equals("bar")) {
5425
				found = true;
5426
				break;
5427
			}
5428
		}
5429
		assertFalse("bar should not be there", found);		
5430
	}
5431
}
5432
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973
5433
public void test104() {
5434
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5435
		Map options = this.getCompilerOptions();
5436
		options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
5437
		this.runConformTest(
5438
			new String[] {
5439
				"X.java",
5440
				"public class X {\n" + 
5441
				"	private interface ReturnBase {\n" + 
5442
				"	}\n" + 
5443
				"\n" + 
5444
				"	private interface ReturnDerived extends ReturnBase {\n" + 
5445
				"	}\n" + 
5446
				"\n" + 
5447
				"	private interface Interface {\n" + 
5448
				"		ReturnBase bar();\n" + 
5449
				"	}\n" + 
5450
				"\n" + 
5451
				"	private static class Implementation {\n" + 
5452
				"		public final ReturnDerived bar() {\n" + 
5453
				"			return null;\n" + 
5454
				"		}\n" + 
5455
				"	}\n" + 
5456
				"\n" + 
5457
				"	private static class Child extends Implementation implements Interface {\n" + 
5458
				"	}\n" + 
5459
				"\n" + 
5460
				"	private static class Grandchild extends Child implements Interface {\n" + 
5461
				"	}\n" + 
5462
				"\n" + 
5463
				"	public static void main(String[] args) {\n" + 
5464
				"		new Grandchild();\n" + 
5465
				"	}\n" + 
5466
				"}"
5467
			},
5468
			"",
5469
			null,
5470
			true,
5471
			null,
5472
			options,
5473
			null
5474
		);
5475
		File fileX = new File(OUTPUT_DIR + File.separator  +"X$Child.class");
5476
		IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5477
		IMethodInfo[] methodInfos = reader.getMethodInfos();
5478
		boolean found = false;
5479
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5480
			if (new String(methodInfos[i].getName()).equals("bar")) {
5481
				found = true;
5482
				break;
5483
			}
5484
		}
5485
		assertTrue("bar should be there", found);
5486
		
5487
		fileX = new File(OUTPUT_DIR + File.separator  +"X$Grandchild.class");
5488
		reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5489
		methodInfos = reader.getMethodInfos();
5490
		found = false;
5491
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5492
			if (new String(methodInfos[i].getName()).equals("bar")) {
5493
				found = true;
5494
				break;
5495
			}
5496
		}
5497
		assertFalse("bar should not be there", found);		
5498
	}
5499
}
5500
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973
5501
public void test105() {
5502
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5503
		Map options = this.getCompilerOptions();
5504
		options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
5505
		this.runConformTest(
5506
			new String[] {
5507
				"X.java",
5508
				"public class X {\n" + 
5509
				"	private interface ReturnBase {\n" + 
5510
				"	}\n" + 
5511
				"\n" + 
5512
				"	private interface ReturnDerived extends ReturnBase {\n" + 
5513
				"	}\n" + 
5514
				"\n" + 
5515
				"	private class Super {\n" + 
5516
				"		ReturnBase bar() {\n" + 
5517
				"			return null;\n" + 
5518
				"		}\n" + 
5519
				"	}\n" + 
5520
				"\n" + 
5521
				"	private static class Implementation {\n" + 
5522
				"		public final ReturnDerived bar() {\n" + 
5523
				"			return null;\n" + 
5524
				"		}\n" + 
5525
				"	}\n" + 
5526
				"\n" + 
5527
				"	private static class Child extends Implementation {\n" + 
5528
				"	}\n" + 
5529
				"\n" + 
5530
				"	private static class Grandchild extends Child {\n" + 
5531
				"	}\n" + 
5532
				"\n" + 
5533
				"	public static void main(String[] args) {\n" + 
5534
				"		new Grandchild();\n" + 
5535
				"	}\n" + 
5536
				"}"
5537
			},
5538
			"",
5539
			null,
5540
			true,
5541
			null,
5542
			options,
5543
			null
5544
		);
5545
		File fileX = new File(OUTPUT_DIR + File.separator  +"X$Child.class");
5546
		IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5547
		IMethodInfo[] methodInfos = reader.getMethodInfos();
5548
		boolean found = false;
5549
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5550
			if (new String(methodInfos[i].getName()).equals("bar")) {
5551
				found = true;
5552
				break;
5553
			}
5554
		}
5555
		assertFalse("bar should not be there", found);
5556
		
5557
		fileX = new File(OUTPUT_DIR + File.separator  +"X$Grandchild.class");
5558
		reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5559
		methodInfos = reader.getMethodInfos();
5560
		found = false;
5561
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5562
			if (new String(methodInfos[i].getName()).equals("bar")) {
5563
				found = true;
5564
				break;
5565
			}
5566
		}
5567
		assertFalse("bar should not be there", found);
5568
		
5569
		fileX = new File(OUTPUT_DIR + File.separator  +"X$Implementation.class");
5570
		reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5571
		methodInfos = reader.getMethodInfos();
5572
		found = false;
5573
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5574
			if (new String(methodInfos[i].getName()).equals("bar")) {
5575
				found = true;
5576
				break;
5577
			}
5578
		}
5579
		assertTrue("bar should be there", found);
5580
	}
5581
}
5582
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=159973
5583
public void test106() {
5584
	if (this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
5585
		Map options = this.getCompilerOptions();
5586
		options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE);
5587
		this.runConformTest(
5588
			new String[] {
5589
				"X.java",
5590
				"public class X {\n" + 
5591
				"	private interface ReturnBase {\n" + 
5592
				"	}\n" + 
5593
				"\n" + 
5594
				"	private interface ReturnDerived extends ReturnBase {\n" + 
5595
				"	}\n" + 
5596
				"\n" + 
5597
				"	private class Super {\n" + 
5598
				"		ReturnBase bar() {\n" + 
5599
				"			return null;\n" + 
5600
				"		}\n" + 
5601
				"	}\n" + 
5602
				"\n" + 
5603
				"	private static abstract class Implementation {\n" + 
5604
				"		public final ReturnDerived bar() {\n" + 
5605
				"			return null;\n" + 
5606
				"		}\n" + 
5607
				"	}\n" + 
5608
				"\n" + 
5609
				"	private static class Child extends Implementation {\n" + 
5610
				"	}\n" + 
5611
				"\n" + 
5612
				"	private static class Grandchild extends Child {\n" + 
5613
				"	}\n" + 
5614
				"\n" + 
5615
				"	public static void main(String[] args) {\n" + 
5616
				"		new Grandchild();\n" + 
5617
				"	}\n" + 
5618
				"}"
5619
			},
5620
			"",
5621
			null,
5622
			true,
5623
			null,
5624
			options,
5625
			null
5626
		);
5627
		File fileX = new File(OUTPUT_DIR + File.separator  +"X$Child.class");
5628
		IClassFileReader reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5629
		IMethodInfo[] methodInfos = reader.getMethodInfos();
5630
		boolean found = false;
5631
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5632
			if (new String(methodInfos[i].getName()).equals("bar")) {
5633
				found = true;
5634
				break;
5635
			}
5636
		}
5637
		assertFalse("bar should not be there", found);
5638
		
5639
		fileX = new File(OUTPUT_DIR + File.separator  +"X$Grandchild.class");
5640
		reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5641
		methodInfos = reader.getMethodInfos();
5642
		found = false;
5643
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5644
			if (new String(methodInfos[i].getName()).equals("bar")) {
5645
				found = true;
5646
				break;
5647
			}
5648
		}
5649
		assertFalse("bar should not be there", found);
5650
		
5651
		fileX = new File(OUTPUT_DIR + File.separator  +"X$Implementation.class");
5652
		reader = ToolFactory.createDefaultClassFileReader(fileX.getAbsolutePath(), IClassFileReader.ALL_BUT_METHOD_BODIES);
5653
		methodInfos = reader.getMethodInfos();
5654
		found = false;
5655
		for (int i = 0, max = methodInfos.length; i < max; i++) {
5656
			if (new String(methodInfos[i].getName()).equals("bar")) {
5657
				found = true;
5658
				break;
5659
			}
5660
		}
5661
		assertTrue("bar should be there", found);
5662
	}
5663
}
5298
}
5664
}

Return to bug 159973