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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+125 lines)
Lines 20475-20478 Link Here
20475
			requestor.getResults());
20475
			requestor.getResults());
20476
}
20476
}
20477
20477
20478
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=276526
20479
public void test276526a() throws JavaModelException {
20480
	// This test is to ensure that an existing super interface is not offered as a completion choice,
20481
	// when all of them are in the same compilation unit.
20482
	this.workingCopies = new ICompilationUnit[1];
20483
	this.workingCopies[0] = getWorkingCopy(
20484
			"/Completion/src/test/Test276526a.java",
20485
			"package test;\n" +
20486
			"interface IFoo {}\n" +
20487
			"interface IBar {}\n" +
20488
			"class Foo implements IFoo, test. {}\n");
20489
			
20490
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
20491
	String str = this.workingCopies[0].getSource();
20492
	String completeBehind = "test.";
20493
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20494
20495
	// In the absence of the fix, it would have been:
20496
	// "IBar[TYPE_REF]{IBar, test, Ltest.IBar;, null, 44}\n" +
20497
	// "IFoo[TYPE_REF]{IFoo, test, Ltest.IFoo;, null, 44}"
20498
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20499
	assertResults(
20500
			"IBar[TYPE_REF]{IBar, test, Ltest.IBar;, null, 44}",
20501
			requestor.getResults());
20502
}
20503
20504
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=276526
20505
public void test276526b() throws JavaModelException {
20506
	// This test is to ensure that an existing super interface is not offered as a completion choice,
20507
	// when they are in different compilation units.
20508
	this.workingCopies = new ICompilationUnit[3];
20509
	this.workingCopies[0] = getWorkingCopy(
20510
			"/Completion/src/test/Test276526b1.java",
20511
			"package test;\n" +
20512
			"public class TestClazz implements Interface1, test. {}");
20513
			
20514
	this.workingCopies[1] = getWorkingCopy(
20515
			"/Completion/src/test/Test276526b2.java",
20516
			"package test;\n" +
20517
			"public interface Interface1 {}");
20518
			
20519
	this.workingCopies[2] = getWorkingCopy(
20520
			"/Completion/src/test/Test276526b3.java",
20521
			"package test;\n" +
20522
			"public interface Interface2 {}");
20523
			
20524
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
20525
	String str = this.workingCopies[0].getSource();
20526
	String completeBehind = "test.";
20527
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20528
20529
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
20530
	assertResults(
20531
			// In the absence of the fix, it would also complete to Interface1:
20532
			//"Interface1[TYPE_REF]{Interface1, test, Ltest.Interface1;, null, 44}\n"+
20533
			"Interface2[TYPE_REF]{Interface2, test, Ltest.Interface2;, null, 44}",
20534
			requestor.getResults());
20535
}
20536
20537
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=276526
20538
public void test276526c() throws JavaModelException {
20539
	// This test is to ensure that an existing super interface is not offered as a completion choice,
20540
	// when they are in different compilation units and nested-types.
20541
	this.workingCopies = new ICompilationUnit[3];
20542
	this.workingCopies[0] = getWorkingCopy(
20543
			"/Completion/src/p/Enclosing.java",
20544
			"package p;\n" +
20545
			"public class Enclosing {\n" +
20546
			"	public interface Interface1 {}\n" +
20547
			"	public interface Interface2 {}\n" +
20548
			"}\n");
20549
			
20550
	this.workingCopies[1] = getWorkingCopy(
20551
			"/Completion/src/TestClazz.java",
20552
			"public class TestClazz implements p.Enclosing.Interface1, Interf {}");
20553
			
20554
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
20555
	String str = this.workingCopies[1].getSource();
20556
	String completeBehind = "Interf";
20557
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20558
20559
	this.workingCopies[1].codeComplete(cursorLocation, requestor, this.wcOwner);
20560
	assertResults(
20561
			// In the absence of the fix, it would suggest both p.Enclosing.Interface2, and
20562
			// p.Enclosing.Interface1 while it should have suppressed the latter which is in use.
20563
			"Enclosing.Interface2[TYPE_REF]{p.Enclosing.Interface2, p, Lp.Enclosing$Interface2;, null, 44}",
20564
			requestor.getResults());
20565
}
20566
20567
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=276526
20568
public void test276526d() throws JavaModelException {
20569
	// This test is to ensure that an existing super interface is not offered as a completion choice,
20570
	// when they are in different compilation units and combination of nested and top-level types.
20571
	this.workingCopies = new ICompilationUnit[3];
20572
	this.workingCopies[0] = getWorkingCopy(
20573
			"/Completion/src/p/Eclosing.java",
20574
			"package p;\n" +
20575
			"public class Enclosing {\n" +
20576
			"	public interface Interface1 {}\n" +
20577
			"	public interface Interface2 {}\n" +
20578
			"}\n");
20579
			
20580
	this.workingCopies[1] = getWorkingCopy(
20581
			"/Completion/src/p/Interface1.java",
20582
			"package p;\n" +
20583
			"public interface Interface1 {}");
20584
			
20585
	this.workingCopies[2] = getWorkingCopy(
20586
			"/Completion/src/TestClazz.java",
20587
			"public class TestClazz implements p.Interface1, Interf {}");
20588
			
20589
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2();
20590
	String str = this.workingCopies[2].getSource();
20591
	String completeBehind = "Interf";
20592
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
20593
20594
	this.workingCopies[2].codeComplete(cursorLocation, requestor, this.wcOwner);
20595
	assertResults(
20596
			// In the absence of the fix, it would suggest only p.Enclosing.Interface2, as it
20597
			// was wrongly suppressing p.Enclosing.Interface1 confusing it with p.Interface1.
20598
			"Enclosing.Interface1[TYPE_REF]{p.Enclosing.Interface1, p, Lp.Enclosing$Interface1;, null, 44}\n" +
20599
			"Enclosing.Interface2[TYPE_REF]{p.Enclosing.Interface2, p, Lp.Enclosing$Interface2;, null, 44}",
20600
			requestor.getResults());
20601
}
20602
20478
}
20603
}

Return to bug 276526