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

(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-8 / +36 lines)
Lines 487-492 Link Here
487
	TypeBinding[] expectedTypes = new TypeBinding[1];
487
	TypeBinding[] expectedTypes = new TypeBinding[1];
488
	int expectedTypesFilter;
488
	int expectedTypesFilter;
489
	boolean hasJavaLangObjectAsExpectedType = false;
489
	boolean hasJavaLangObjectAsExpectedType = false;
490
	boolean hasExpectedArrayTypes = false;
491
	boolean hasComputedExpectedArrayTypes = false;
490
	int uninterestingBindingsPtr = -1;
492
	int uninterestingBindingsPtr = -1;
491
	Binding[] uninterestingBindings = new Binding[1];
493
	Binding[] uninterestingBindings = new Binding[1];
492
	int forbbidenBindingsPtr = -1;
494
	int forbbidenBindingsPtr = -1;
Lines 759-765 Link Here
759
				final int extraFlags = acceptedConstructor.extraFlags;
761
				final int extraFlags = acceptedConstructor.extraFlags;
760
				final int accessibility = acceptedConstructor.accessibility;
762
				final int accessibility = acceptedConstructor.accessibility;
761
				
763
				
762
				boolean proposeType = (extraFlags & ExtraFlags.HasNonPrivateStaticMemberTypes) != 0;
764
				boolean proposeType = hasArrayTypeAsExpectedSuperTypes() || (extraFlags & ExtraFlags.HasNonPrivateStaticMemberTypes) != 0;
763
				
765
				
764
				char[] fullyQualifiedName = CharOperation.concat(packageName, simpleTypeName, '.');
766
				char[] fullyQualifiedName = CharOperation.concat(packageName, simpleTypeName, '.');
765
						
767
						
Lines 9249-9255 Link Here
9249
			if (!this.assistNodeIsConstructor ||
9251
			if (!this.assistNodeIsConstructor ||
9250
					!allowingLongComputationProposals ||
9252
					!allowingLongComputationProposals ||
9251
					hasStaticMemberTypes(memberType, invocationType, this.unitScope) ||
9253
					hasStaticMemberTypes(memberType, invocationType, this.unitScope) ||
9252
					(memberType instanceof SourceTypeBinding && hasMemberTypesInEnclosingScope((SourceTypeBinding)memberType, scope))) {
9254
					(memberType instanceof SourceTypeBinding && hasMemberTypesInEnclosingScope((SourceTypeBinding)memberType, scope)) ||
9255
					hasArrayTypeAsExpectedSuperTypes()) {
9253
				createTypeProposal(
9256
				createTypeProposal(
9254
						memberType,
9257
						memberType,
9255
						memberType.qualifiedSourceName(),
9258
						memberType.qualifiedSourceName(),
Lines 9689-9695 Link Here
9689
								relevance += computeRelevanceForAnnotationTarget(localType);
9692
								relevance += computeRelevanceForAnnotationTarget(localType);
9690
9693
9691
								boolean allowingLongComputationProposals = isAllowingLongComputationProposals();
9694
								boolean allowingLongComputationProposals = isAllowingLongComputationProposals();
9692
								if (!this.assistNodeIsConstructor || !allowingLongComputationProposals) {
9695
								if (!this.assistNodeIsConstructor || !allowingLongComputationProposals || hasArrayTypeAsExpectedSuperTypes()) {
9693
									this.noProposal = false;
9696
									this.noProposal = false;
9694
									if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
9697
									if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
9695
										createTypeProposal(
9698
										createTypeProposal(
Lines 10085-10091 Link Here
10085
						(!this.assistNodeIsConstructor ||
10088
						(!this.assistNodeIsConstructor ||
10086
								!allowingLongComputationProposals ||
10089
								!allowingLongComputationProposals ||
10087
								hasStaticMemberTypes(sourceType, null, this.unitScope) ||
10090
								hasStaticMemberTypes(sourceType, null, this.unitScope) ||
10088
								hasMemberTypesInEnclosingScope(sourceType, scope))) {
10091
								hasMemberTypesInEnclosingScope(sourceType, scope)) ||
10092
								hasArrayTypeAsExpectedSuperTypes()) {
10089
					char[] typeName = sourceType.sourceName();
10093
					char[] typeName = sourceType.sourceName();
10090
					createTypeProposal(
10094
					createTypeProposal(
10091
							sourceType,
10095
							sourceType,
Lines 10313-10319 Link Here
10313
						(!this.assistNodeIsConstructor ||
10317
						(!this.assistNodeIsConstructor ||
10314
								!allowingLongComputationProposals ||
10318
								!allowingLongComputationProposals ||
10315
								hasStaticMemberTypes(sourceType, null, this.unitScope) ||
10319
								hasStaticMemberTypes(sourceType, null, this.unitScope) ||
10316
								hasMemberTypesInEnclosingScope(sourceType, scope))) {
10320
								hasMemberTypesInEnclosingScope(sourceType, scope)) ||
10321
								hasArrayTypeAsExpectedSuperTypes()) {
10317
					char[] typeName = sourceType.sourceName();
10322
					char[] typeName = sourceType.sourceName();
10318
					createTypeProposal(
10323
					createTypeProposal(
10319
							sourceType,
10324
							sourceType,
Lines 10433-10439 Link Here
10433
10438
10434
					for (int j = 0; j < typesFound.size(); j++) {
10439
					for (int j = 0; j < typesFound.size(); j++) {
10435
						ReferenceBinding typeFound = (ReferenceBinding)typesFound.elementAt(j);
10440
						ReferenceBinding typeFound = (ReferenceBinding)typesFound.elementAt(j);
10436
						if (typeFound == refBinding) {
10441
						if (typeFound == refBinding.erasure()) {
10437
							continue next;
10442
							continue next;
10438
						}
10443
						}
10439
					}
10444
					}
Lines 10484-10490 Link Here
10484
							relevance += computeRelevanceForInterface();
10489
							relevance += computeRelevanceForInterface();
10485
						}
10490
						}
10486
						
10491
						
10487
						if (proposeType && (!this.assistNodeIsConstructor || !allowingLongComputationProposals || hasStaticMemberTypes(refBinding, scope.enclosingSourceType() ,this.unitScope))) {
10492
						if (proposeType &&
10493
								(!this.assistNodeIsConstructor ||
10494
										!allowingLongComputationProposals ||
10495
										hasStaticMemberTypes(refBinding, scope.enclosingSourceType() ,this.unitScope)) ||
10496
										hasArrayTypeAsExpectedSuperTypes()) {
10488
							this.noProposal = false;
10497
							this.noProposal = false;
10489
							if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
10498
							if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
10490
								InternalCompletionProposal proposal =  createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition);
10499
								InternalCompletionProposal proposal =  createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition);
Lines 10610-10616 Link Here
10610
								relevance += computeRelevanceForException(typeBinding.sourceName);
10619
								relevance += computeRelevanceForException(typeBinding.sourceName);
10611
							}
10620
							}
10612
							
10621
							
10613
							if (proposeType && hasStaticMemberTypes(typeBinding, scope.enclosingSourceType(), this.unitScope)) {
10622
							if (proposeType && 
10623
									(hasStaticMemberTypes(typeBinding, scope.enclosingSourceType(), this.unitScope) || hasArrayTypeAsExpectedSuperTypes())) {
10614
								this.noProposal = false;
10624
								this.noProposal = false;
10615
								if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
10625
								if(!this.requestor.isIgnored(CompletionProposal.TYPE_REF)) {
10616
									InternalCompletionProposal proposal =  createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition);
10626
									InternalCompletionProposal proposal =  createProposal(CompletionProposal.TYPE_REF, this.actualCompletionPosition);
Lines 11508-11513 Link Here
11508
11518
11509
		return this.parser;
11519
		return this.parser;
11510
	}
11520
	}
11521
	protected boolean hasArrayTypeAsExpectedSuperTypes() {
11522
		if ((this.expectedTypesFilter & ~SUBTYPE) != 0) return false;
11523
		
11524
		if (!this.hasComputedExpectedArrayTypes) {
11525
			if(this.expectedTypes != null) {
11526
				done : for (int i = 0; i <= this.expectedTypesPtr; i++) {
11527
					if(this.expectedTypes[i].isArrayType()) {
11528
						this.hasExpectedArrayTypes = true;
11529
						break done;
11530
					}
11531
				}
11532
			}
11533
			
11534
			this.hasComputedExpectedArrayTypes = true;
11535
		}
11536
		
11537
		return this.hasExpectedArrayTypes;
11538
	}
11511
	protected boolean hasPossibleAnnotationTarget(TypeBinding typeBinding, Scope scope) {
11539
	protected boolean hasPossibleAnnotationTarget(TypeBinding typeBinding, Scope scope) {
11512
		if (this.targetedElement == TagBits.AnnotationForPackage) {
11540
		if (this.targetedElement == TagBits.AnnotationForPackage) {
11513
			long target = typeBinding.getAnnotationTagBits() & TagBits.AnnotationTargetMASK;
11541
			long target = typeBinding.getAnnotationTagBits() & TagBits.AnnotationTargetMASK;
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+191 lines)
Lines 15484-15489 Link Here
15484
		}
15484
		}
15485
	}
15485
	}
15486
}
15486
}
15487
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932
15488
public void testConstructor1() throws JavaModelException {
15489
	this.workingCopies = new ICompilationUnit[2];
15490
	this.workingCopies[0] = getWorkingCopy(
15491
		"/Completion/src/test/Test.java",
15492
		"package test;"+
15493
		"public class Test {\n" +
15494
		"        public void foo() {\n" +
15495
		"                TestConstructor1[] var = new TestConstructor\n" +
15496
		"        }\n" +
15497
		"}");
15498
	this.workingCopies[1] = getWorkingCopy(
15499
		"/Completion/src/test/TestConstructor1.java",
15500
		"package test;"+
15501
		"public class TestConstructor1 {\n" +
15502
		"        public TestConstructor1(int i) {\n" +
15503
		"        }\n" +
15504
		"}");
15505
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
15506
	requestor.allowAllRequiredProposals();
15507
	NullProgressMonitor monitor = new NullProgressMonitor();
15508
	String str = this.workingCopies[0].getSource();
15509
	String completeBehind = "TestConstructor";
15510
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15511
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
15512
15513
	assertResults(
15514
			"TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15515
			"TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15516
			"   TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
15517
			requestor.getResults());
15518
}
15519
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932
15520
public void testConstructor2() throws JavaModelException {
15521
	this.workingCopies = new ICompilationUnit[2];
15522
	this.workingCopies[0] = getWorkingCopy(
15523
		"/Completion/src/test/Test.java",
15524
		"package test;"+
15525
		"public class Test {\n" +
15526
		"        public void foo(TestConstructor1[] var) {\n" +
15527
		"                foo(new TestConstructor\n" +
15528
		"        }\n" +
15529
		"}");
15530
	this.workingCopies[1] = getWorkingCopy(
15531
		"/Completion/src/test/TestConstructor1.java",
15532
		"package test;"+
15533
		"public class TestConstructor1 {\n" +
15534
		"        public TestConstructor1(int i) {\n" +
15535
		"        }\n" +
15536
		"}");
15537
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
15538
	requestor.allowAllRequiredProposals();
15539
	NullProgressMonitor monitor = new NullProgressMonitor();
15540
	String str = this.workingCopies[0].getSource();
15541
	String completeBehind = "TestConstructor";
15542
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15543
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
15544
15545
	assertResults(
15546
			"TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15547
			"TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15548
			"   TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
15549
			requestor.getResults());
15550
}
15551
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932
15552
public void testConstructor3() throws JavaModelException {
15553
	this.workingCopies = new ICompilationUnit[2];
15554
	this.workingCopies[0] = getWorkingCopy(
15555
		"/Completion/src/test/Test.java",
15556
		"package test;"+
15557
		"public class Test {\n" +
15558
		"        public TestConstructor1[] foo() {\n" +
15559
		"                return new TestConstructor\n" +
15560
		"        }\n" +
15561
		"}");
15562
	this.workingCopies[1] = getWorkingCopy(
15563
		"/Completion/src/test/TestConstructor1.java",
15564
		"package test;"+
15565
		"public class TestConstructor1 {\n" +
15566
		"        public TestConstructor1(int i) {\n" +
15567
		"        }\n" +
15568
		"}");
15569
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
15570
	requestor.allowAllRequiredProposals();
15571
	NullProgressMonitor monitor = new NullProgressMonitor();
15572
	String str = this.workingCopies[0].getSource();
15573
	String completeBehind = "TestConstructor";
15574
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15575
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
15576
15577
	assertResults(
15578
			"TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15579
			"TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15580
			"   TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
15581
			requestor.getResults());
15582
}
15583
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932
15584
public void testConstructor4() throws JavaModelException {
15585
	this.workingCopies = new ICompilationUnit[2];
15586
	this.workingCopies[0] = getWorkingCopy(
15587
		"/Completion/src/test/Test.java",
15588
		"package test;"+
15589
		"public class Test {\n" +
15590
		"        public Test(TestConstructor1[] var) {}\n" +
15591
		"        public void foo() {\n" +
15592
		"                new Test(new TestConstructor\n" +
15593
		"        }\n" +
15594
		"}");
15595
	this.workingCopies[1] = getWorkingCopy(
15596
		"/Completion/src/test/TestConstructor1.java",
15597
		"package test;"+
15598
		"public class TestConstructor1 {\n" +
15599
		"        public TestConstructor1(int i) {\n" +
15600
		"        }\n" +
15601
		"}");
15602
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
15603
	requestor.allowAllRequiredProposals();
15604
	NullProgressMonitor monitor = new NullProgressMonitor();
15605
	String str = this.workingCopies[0].getSource();
15606
	String completeBehind = "TestConstructor";
15607
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15608
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
15609
15610
	assertResults(
15611
			"TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15612
			"TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15613
			"   TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
15614
			requestor.getResults());
15615
}
15616
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932
15617
public void testConstructor5() throws JavaModelException {
15618
	this.workingCopies = new ICompilationUnit[2];
15619
	this.workingCopies[0] = getWorkingCopy(
15620
		"/Completion/src/test/Test.java",
15621
		"package test;"+
15622
		"public class Test {\n" +
15623
		"        public void foo(TestConstructor1[] var) {\n" +
15624
		"                if (var == new TestConstructor) {}\n" +
15625
		"        }\n" +
15626
		"}");
15627
	this.workingCopies[1] = getWorkingCopy(
15628
		"/Completion/src/test/TestConstructor1.java",
15629
		"package test;"+
15630
		"public class TestConstructor1 {\n" +
15631
		"        public TestConstructor1(int i) {\n" +
15632
		"        }\n" +
15633
		"}");
15634
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
15635
	requestor.allowAllRequiredProposals();
15636
	NullProgressMonitor monitor = new NullProgressMonitor();
15637
	String str = this.workingCopies[0].getSource();
15638
	String completeBehind = "TestConstructor";
15639
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15640
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
15641
15642
	assertResults(
15643
			"TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15644
			"   TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
15645
			requestor.getResults());
15646
}
15647
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=262932
15648
public void testConstructor6() throws JavaModelException {
15649
	this.workingCopies = new ICompilationUnit[2];
15650
	this.workingCopies[0] = getWorkingCopy(
15651
		"/Completion/src/test/Test.java",
15652
		"package test;"+
15653
		"public class Test {\n" +
15654
		"        public void foo(Object o) {\n" +
15655
		"                o = (TestConstructor1[])new TestConstructor\n" +
15656
		"        }\n" +
15657
		"}");
15658
	this.workingCopies[1] = getWorkingCopy(
15659
		"/Completion/src/test/TestConstructor1.java",
15660
		"package test;"+
15661
		"public class TestConstructor1 {\n" +
15662
		"        public TestConstructor1(int i) {\n" +
15663
		"        }\n" +
15664
		"}");
15665
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
15666
	requestor.allowAllRequiredProposals();
15667
	NullProgressMonitor monitor = new NullProgressMonitor();
15668
	String str = this.workingCopies[0].getSource();
15669
	String completeBehind = "TestConstructor";
15670
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
15671
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
15672
15673
	assertResults(
15674
			"TestConstructor1[CONSTRUCTOR_INVOCATION]{(), Ltest.TestConstructor1;, (I)V, TestConstructor1, (i), "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}\n" +
15675
			"   TestConstructor1[TYPE_REF]{TestConstructor1, test, Ltest.TestConstructor1;, null, null, "+(R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_UNQUALIFIED + R_NON_RESTRICTED)+"}",
15676
			requestor.getResults());
15677
}
15487
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127296
15678
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=127296
15488
public void testDeprecationCheck1() throws JavaModelException {
15679
public void testDeprecationCheck1() throws JavaModelException {
15489
	Hashtable options = JavaCore.getOptions();
15680
	Hashtable options = JavaCore.getOptions();

Return to bug 262932