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

(-)model/org/eclipse/jdt/core/CompletionProposal.java (+5 lines)
Lines 1463-1468 Link Here
1463
	 *    <li><code>TYPE_REF</code></li>
1463
	 *    <li><code>TYPE_REF</code></li>
1464
	 *   </ul>
1464
	 *   </ul>
1465
	 *  </li>
1465
	 *  </li>
1466
	 *  <li><code>ANONYMOUS_CLASS_DECLARATION</code> - The allowed required proposals for this kind are:
1467
	 *   <ul>
1468
	 *    <li><code>TYPE_REF</code></li>
1469
	 *   </ul>
1470
	 *  </li>
1466
	 * </ul>
1471
	 * </ul>
1467
	 * </p>
1472
	 * </p>
1468
	 * <p>
1473
	 * <p>
(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-27 / +160 lines)
Lines 1540-1545 Link Here
1540
				argTypes,
1540
				argTypes,
1541
				scope,
1541
				scope,
1542
				constructorCall,
1542
				constructorCall,
1543
				false,
1544
				null,
1545
				null,
1546
				null,
1543
				false);
1547
				false);
1544
		}
1548
		}
1545
	}
1549
	}
Lines 1618-1624 Link Here
1618
1622
1619
		ReferenceBinding ref = (ReferenceBinding) qualifiedBinding;
1623
		ReferenceBinding ref = (ReferenceBinding) qualifiedBinding;
1620
		if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF) && ref.isClass()) {
1624
		if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF) && ref.isClass()) {
1621
			findConstructors(ref, argTypes, scope, allocExpression, false);
1625
			findConstructors(ref, argTypes, scope, allocExpression, false, null, null, null, false);
1622
		}
1626
		}
1623
	}
1627
	}
1624
	//TODO
1628
	//TODO
Lines 1690-1696 Link Here
1690
					if (this.completionToken == null
1694
					if (this.completionToken == null
1691
							|| CharOperation.prefixEquals(this.completionToken, refBinding.sourceName)
1695
							|| CharOperation.prefixEquals(this.completionToken, refBinding.sourceName)
1692
							|| (this.options.camelCaseMatch && CharOperation.camelCaseMatch(this.completionToken, refBinding.sourceName))) {
1696
							|| (this.options.camelCaseMatch && CharOperation.camelCaseMatch(this.completionToken, refBinding.sourceName))) {
1693
						findConstructors(refBinding, null, scope, fieldRef, false);
1697
						findConstructors(refBinding, null, scope, fieldRef, false, null, null, null, false);
1694
					}
1698
					}
1695
				}
1699
				}
1696
			}
1700
			}
Lines 2277-2303 Link Here
2277
		TypeBinding[] argTypes = computeTypes(allocExpression.arguments);
2281
		TypeBinding[] argTypes = computeTypes(allocExpression.arguments);
2278
2282
2279
		ReferenceBinding ref = (ReferenceBinding) qualifiedBinding;
2283
		ReferenceBinding ref = (ReferenceBinding) qualifiedBinding;
2280
		if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)
2284
		
2281
				&& ref.isClass()
2285
		if (ref.problemId() == ProblemReasons.NotFound) {
2282
				&& !ref.isAbstract()) {
2286
			findConstructorsFromMissingType(
2283
				findConstructors(
2287
					allocExpression.type,
2288
					argTypes,
2289
					scope,
2290
					allocExpression);
2291
		} else {
2292
			if (!this.requestor.isIgnored(CompletionProposal.METHOD_REF)
2293
					&& ref.isClass()
2294
					&& !ref.isAbstract()) {
2295
					findConstructors(
2296
						ref,
2297
						argTypes,
2298
						scope,
2299
						allocExpression,
2300
						false,
2301
						null,
2302
						null,
2303
						null,
2304
						false);
2305
			}
2306
			
2307
			checkCancel();
2308
			
2309
			if (!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION)
2310
					&& !ref.isFinal()
2311
					&& !ref.isEnum()){
2312
				findAnonymousType(
2284
					ref,
2313
					ref,
2285
					argTypes,
2314
					argTypes,
2286
					scope,
2315
					scope,
2287
					allocExpression,
2316
					allocExpression,
2317
					null,
2318
					null,
2319
					null,
2288
					false);
2320
					false);
2289
		}
2321
			}
2290
		
2291
		checkCancel();
2292
		
2293
		if (!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION)
2294
				&& !ref.isFinal()
2295
				&& !ref.isEnum()){
2296
			findAnonymousType(
2297
				ref,
2298
				argTypes,
2299
				scope,
2300
				allocExpression);
2301
		}
2322
		}
2302
	}
2323
	}
2303
	
2324
	
Lines 3942-3952 Link Here
3942
			}
3963
			}
3943
		}
3964
		}
3944
	}
3965
	}
3945
	private void findAnonymousType(
3966
	void findAnonymousType(
3946
		ReferenceBinding currentType,
3967
		ReferenceBinding currentType,
3947
		TypeBinding[] argTypes,
3968
		TypeBinding[] argTypes,
3948
		Scope scope,
3969
		Scope scope,
3949
		InvocationSite invocationSite) {
3970
		InvocationSite invocationSite,
3971
		Binding[] missingElements,
3972
		int[] missingElementsStarts,
3973
		int[] missingElementsEnds,
3974
		boolean missingElementsHaveProblems) {
3950
3975
3951
		if (currentType.isInterface()) {
3976
		if (currentType.isInterface()) {
3952
			char[] completion = CharOperation.NO_CHAR;
3977
			char[] completion = CharOperation.NO_CHAR;
Lines 3954-3962 Link Here
3954
			relevance += computeRelevanceForResolution();
3979
			relevance += computeRelevanceForResolution();
3955
			relevance += computeRelevanceForInterestingProposal();
3980
			relevance += computeRelevanceForInterestingProposal();
3956
			relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
3981
			relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
3982
			
3983
			if (missingElements != null) {
3984
				relevance += computeRelevanceForMissingElements(missingElementsHaveProblems);
3985
			}
3957
3986
3958
			this.noProposal = false;
3987
			this.noProposal = false;
3959
			if(!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION)) {
3988
			if(!isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, missingElements != null)) {
3960
				InternalCompletionProposal proposal = createProposal(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, this.actualCompletionPosition);
3989
				InternalCompletionProposal proposal = createProposal(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, this.actualCompletionPosition);
3961
				proposal.setDeclarationSignature(getSignature(currentType));
3990
				proposal.setDeclarationSignature(getSignature(currentType));
3962
				proposal.setDeclarationKey(currentType.computeUniqueKey());
3991
				proposal.setDeclarationKey(currentType.computeUniqueKey());
Lines 3974-3979 Link Here
3974
				//proposal.setParameterTypeNames(null);
4003
				//proposal.setParameterTypeNames(null);
3975
				//proposal.setPackageName(null);
4004
				//proposal.setPackageName(null);
3976
				//proposal.setTypeName(null);
4005
				//proposal.setTypeName(null);
4006
				if (missingElements != null) {
4007
					CompletionProposal[] subProposals = new CompletionProposal[missingElements.length];
4008
					for (int i = 0; i < missingElements.length; i++) {
4009
						subProposals[i] =
4010
							createRequiredTypeProposal(
4011
									missingElements[i],
4012
									missingElementsStarts[i],
4013
									missingElementsEnds[i],
4014
									relevance);
4015
					}
4016
					proposal.setRequiredProposals(subProposals);
4017
				}
3977
				proposal.setCompletion(completion);
4018
				proposal.setCompletion(completion);
3978
				proposal.setFlags(Flags.AccPublic);
4019
				proposal.setFlags(Flags.AccPublic);
3979
				proposal.setReplaceRange(this.endPosition - this.offset, this.endPosition - this.offset);
4020
				proposal.setReplaceRange(this.endPosition - this.offset, this.endPosition - this.offset);
Lines 3990-3996 Link Here
3990
				argTypes,
4031
				argTypes,
3991
				scope,
4032
				scope,
3992
				invocationSite,
4033
				invocationSite,
3993
				true);
4034
				true,
4035
				missingElements,
4036
				missingElementsStarts,
4037
				missingElementsEnds,
4038
				missingElementsHaveProblems);
3994
		}
4039
		}
3995
	}
4040
	}
3996
	private void findClassField(
4041
	private void findClassField(
Lines 4069-4080 Link Here
4069
			}
4114
			}
4070
		}
4115
		}
4071
	}
4116
	}
4072
	private void findConstructors(
4117
	void findConstructors(
4073
		ReferenceBinding currentType,
4118
		ReferenceBinding currentType,
4074
		TypeBinding[] argTypes,
4119
		TypeBinding[] argTypes,
4075
		Scope scope,
4120
		Scope scope,
4076
		InvocationSite invocationSite,
4121
		InvocationSite invocationSite,
4077
		boolean forAnonymousType) {
4122
		boolean forAnonymousType,
4123
		Binding[] missingElements,
4124
		int[] missingElementsStarts,
4125
		int[] missingElementsEnds,
4126
		boolean missingElementsHaveProblems) {
4078
4127
4079
		// No visibility checks can be performed without the scope & invocationSite
4128
		// No visibility checks can be performed without the scope & invocationSite
4080
		MethodBinding[] methods = currentType.availableMethods();
4129
		MethodBinding[] methods = currentType.availableMethods();
Lines 4122-4130 Link Here
4122
						relevance += computeRelevanceForResolution();
4171
						relevance += computeRelevanceForResolution();
4123
						relevance += computeRelevanceForInterestingProposal();
4172
						relevance += computeRelevanceForInterestingProposal();
4124
						relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
4173
						relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
4174
						
4175
						if (missingElements != null) {
4176
							relevance += computeRelevanceForMissingElements(missingElementsHaveProblems);
4177
						}
4125
4178
4126
						this.noProposal = false;
4179
						this.noProposal = false;
4127
						if(!this.requestor.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION)) {
4180
						if(!this.isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, missingElements != null)) {
4128
							InternalCompletionProposal proposal = createProposal(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, this.actualCompletionPosition);
4181
							InternalCompletionProposal proposal = createProposal(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, this.actualCompletionPosition);
4129
							proposal.setDeclarationSignature(getSignature(currentType));
4182
							proposal.setDeclarationSignature(getSignature(currentType));
4130
							proposal.setDeclarationKey(currentType.computeUniqueKey());
4183
							proposal.setDeclarationKey(currentType.computeUniqueKey());
Lines 4140-4145 Link Here
4140
							proposal.setParameterTypeNames(parameterTypeNames);
4193
							proposal.setParameterTypeNames(parameterTypeNames);
4141
							//proposal.setPackageName(null);
4194
							//proposal.setPackageName(null);
4142
							//proposal.setTypeName(null);
4195
							//proposal.setTypeName(null);
4196
							if (missingElements != null) {
4197
								CompletionProposal[] subProposals = new CompletionProposal[missingElements.length];
4198
								for (int i = 0; i < missingElements.length; i++) {
4199
									subProposals[i] =
4200
										createRequiredTypeProposal(
4201
												missingElements[i],
4202
												missingElementsStarts[i],
4203
												missingElementsEnds[i],
4204
												relevance);
4205
								}
4206
								proposal.setRequiredProposals(subProposals);
4207
							}
4143
							proposal.setCompletion(completion);
4208
							proposal.setCompletion(completion);
4144
							proposal.setFlags(constructor.modifiers);
4209
							proposal.setFlags(constructor.modifiers);
4145
							proposal.setReplaceRange(this.endPosition - this.offset, this.endPosition - this.offset);
4210
							proposal.setReplaceRange(this.endPosition - this.offset, this.endPosition - this.offset);
Lines 4156-4161 Link Here
4156
						relevance += computeRelevanceForResolution();
4221
						relevance += computeRelevanceForResolution();
4157
						relevance += computeRelevanceForInterestingProposal();
4222
						relevance += computeRelevanceForInterestingProposal();
4158
						relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
4223
						relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE);
4224
						
4225
						if (missingElements != null) {
4226
							relevance += computeRelevanceForMissingElements(missingElementsHaveProblems);
4227
						}
4159
4228
4160
						// Special case for completion in javadoc
4229
						// Special case for completion in javadoc
4161
						if (this.assistNodeInJavadoc > 0) {
4230
						if (this.assistNodeInJavadoc > 0) {
Lines 4212-4218 Link Here
4212
4281
4213
						// Create standard proposal
4282
						// Create standard proposal
4214
						this.noProposal = false;
4283
						this.noProposal = false;
4215
						if(!this.requestor.isIgnored(CompletionProposal.METHOD_REF) && (this.assistNodeInJavadoc & CompletionOnJavadoc.ONLY_INLINE_TAG) == 0) {
4284
						if(!this.isIgnored(CompletionProposal.METHOD_REF, missingElements != null) && (this.assistNodeInJavadoc & CompletionOnJavadoc.ONLY_INLINE_TAG) == 0) {
4216
							InternalCompletionProposal proposal =  createProposal(CompletionProposal.METHOD_REF, this.actualCompletionPosition);
4285
							InternalCompletionProposal proposal =  createProposal(CompletionProposal.METHOD_REF, this.actualCompletionPosition);
4217
							proposal.setDeclarationSignature(getSignature(currentType));
4286
							proposal.setDeclarationSignature(getSignature(currentType));
4218
							proposal.setSignature(getSignature(constructor));
4287
							proposal.setSignature(getSignature(constructor));
Lines 4227-4232 Link Here
4227
							//proposal.setPackageName(null);
4296
							//proposal.setPackageName(null);
4228
							//proposal.setTypeName(null);
4297
							//proposal.setTypeName(null);
4229
							proposal.setName(currentType.sourceName());
4298
							proposal.setName(currentType.sourceName());
4299
							if (missingElements != null) {
4300
								CompletionProposal[] subProposals = new CompletionProposal[missingElements.length];
4301
								for (int i = 0; i < missingElements.length; i++) {
4302
									subProposals[i] =
4303
										createRequiredTypeProposal(
4304
												missingElements[i],
4305
												missingElementsStarts[i],
4306
												missingElementsEnds[i],
4307
												relevance);
4308
								}
4309
								proposal.setRequiredProposals(subProposals);
4310
							}
4230
							proposal.setIsContructor(true);
4311
							proposal.setIsContructor(true);
4231
							proposal.setCompletion(completion);
4312
							proposal.setCompletion(completion);
4232
							proposal.setFlags(constructor.modifiers);
4313
							proposal.setFlags(constructor.modifiers);
Lines 5925-5930 Link Here
5925
			};
6006
			};
5926
		missingTypesConverter.guess(typeRef, scope, substitutionRequestor);
6007
		missingTypesConverter.guess(typeRef, scope, substitutionRequestor);
5927
	}
6008
	}
6009
	
6010
	private void findConstructorsFromMissingType(
6011
			TypeReference typeRef,
6012
			final TypeBinding[] argTypes,
6013
			final Scope scope,
6014
			final InvocationSite invocationSite) {
6015
		MissingTypesGuesser missingTypesConverter = new MissingTypesGuesser(this);
6016
		MissingTypesGuesser.GuessedTypeRequestor substitutionRequestor =
6017
			new MissingTypesGuesser.GuessedTypeRequestor() {
6018
				public void accept(
6019
						TypeBinding guessedType,
6020
						Binding[] missingElements,
6021
						int[] missingElementsStarts,
6022
						int[] missingElementsEnds,
6023
						boolean hasProblems) {
6024
					if (guessedType instanceof ReferenceBinding) {
6025
						ReferenceBinding ref = (ReferenceBinding) guessedType;
6026
						if (!isIgnored(CompletionProposal.METHOD_REF, missingElements != null)
6027
								&& ref.isClass()
6028
								&& !ref.isAbstract()) {
6029
								findConstructors(
6030
									ref,
6031
									argTypes,
6032
									scope,
6033
									invocationSite,
6034
									false,
6035
									missingElements,
6036
									missingElementsStarts,
6037
									missingElementsEnds,
6038
									hasProblems);
6039
						}
6040
								
6041
						checkCancel();
6042
			
6043
						if (!isIgnored(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, missingElements != null)
6044
								&& !ref.isFinal()
6045
								&& !ref.isEnum()){
6046
							findAnonymousType(
6047
								ref,
6048
								argTypes,
6049
								scope,
6050
								invocationSite,
6051
								missingElements,
6052
								missingElementsStarts,
6053
								missingElementsEnds,
6054
								hasProblems);
6055
						}
6056
					}
6057
				}
6058
			};
6059
		missingTypesConverter.guess(typeRef, scope, substitutionRequestor);
6060
	}
5928
6061
5929
	private void findFieldsAndMethodsFromStaticImports(
6062
	private void findFieldsAndMethodsFromStaticImports(
5930
			char[] token,
6063
			char[] token,
Lines 10275-10281 Link Here
10275
	private boolean isIgnored(int kind) {
10408
	private boolean isIgnored(int kind) {
10276
		return this.requestor.isIgnored(kind);
10409
		return this.requestor.isIgnored(kind);
10277
	}
10410
	}
10278
	private boolean isIgnored(int kind, boolean missingTypes) {
10411
	boolean isIgnored(int kind, boolean missingTypes) {
10279
		return this.requestor.isIgnored(kind) ||
10412
		return this.requestor.isIgnored(kind) ||
10280
			(missingTypes && !this.requestor.isAllowingRequiredProposals(kind, CompletionProposal.TYPE_REF));
10413
			(missingTypes && !this.requestor.isAllowingRequiredProposals(kind, CompletionProposal.TYPE_REF));
10281
	}
10414
	}
(-)src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests.java (+205 lines)
Lines 1667-1670 Link Here
1667
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
1667
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
1668
			requestor.getResults());
1668
			requestor.getResults());
1669
}
1669
}
1670
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260717
1671
public void test0041() throws JavaModelException {
1672
	this.workingCopies = new ICompilationUnit[3];
1673
	this.workingCopies[0] = getWorkingCopy(
1674
		"/Completion/src/test/Test.java",
1675
		"package test;"+
1676
		"public class Test {\n" +
1677
		"  void foo() {\n" +
1678
		"    new MissingType(\n" +
1679
		"  }\n" +
1680
		"}\n");
1681
1682
	this.workingCopies[1] = getWorkingCopy(
1683
		"/Completion/src/missing/MissingType.java",
1684
		"package missing;"+
1685
		"public class MissingType {\n" +
1686
		"}\n");
1687
1688
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
1689
	requestor.allowAllRequiredProposals();
1690
	String str = this.workingCopies[0].getSource();
1691
	String completeBehind = "new MissingType(";
1692
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
1693
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
1694
1695
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED + R_NO_PROBLEMS;
1696
	int start1 = str.lastIndexOf("new MissingType(") + "new MissingType(".length();
1697
	int end1 = start1 + "".length();
1698
	int start2 = str.indexOf("MissingType");
1699
	int end2 = start2 + "MissingType".length();
1700
	assertResults(
1701
			"MissingType[ANONYMOUS_CLASS_DECLARATION]{, Lmissing.MissingType;, ()V, null, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
1702
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}\n" +
1703
			"MissingType[METHOD_REF<CONSTRUCTOR>]{, Lmissing.MissingType;, ()V, MissingType, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
1704
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
1705
			requestor.getResults());
1706
}
1707
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260717
1708
public void test0042() throws JavaModelException {
1709
	this.workingCopies = new ICompilationUnit[3];
1710
	this.workingCopies[0] = getWorkingCopy(
1711
		"/Completion/src/test/Test.java",
1712
		"package test;"+
1713
		"public class Test {\n" +
1714
		"  void foo() {\n" +
1715
		"    new MissingType.Member(\n" +
1716
		"  }\n" +
1717
		"}\n");
1718
1719
	this.workingCopies[1] = getWorkingCopy(
1720
		"/Completion/src/missing/MissingType.java",
1721
		"package missing;"+
1722
		"public class MissingType {\n" +
1723
		"  public static class Member {}\n" +
1724
		"}\n");
1725
1726
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
1727
	requestor.allowAllRequiredProposals();
1728
	String str = this.workingCopies[0].getSource();
1729
	String completeBehind = "new MissingType.Member(";
1730
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
1731
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
1732
1733
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED + R_NO_PROBLEMS;
1734
	int start1 = str.lastIndexOf("new MissingType.Member(") + "new MissingType.Member(".length();
1735
	int end1 = start1 + "".length();
1736
	int start2 = str.indexOf("MissingType");
1737
	int end2 = start2 + "MissingType".length();
1738
	assertResults(
1739
			"Member[METHOD_REF<CONSTRUCTOR>]{, Lmissing.MissingType$Member;, ()V, Member, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
1740
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}\n" +
1741
			"MissingType.Member[ANONYMOUS_CLASS_DECLARATION]{, Lmissing.MissingType$Member;, ()V, null, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
1742
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
1743
			requestor.getResults());
1744
}
1745
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260717
1746
public void test0043() throws JavaModelException {
1747
	this.workingCopies = new ICompilationUnit[3];
1748
	this.workingCopies[0] = getWorkingCopy(
1749
		"/Completion/src/test/Test.java",
1750
		"package test;"+
1751
		"public class Test {\n" +
1752
		"  void foo() {\n" +
1753
		"    this.new MissingType(\n" +
1754
		"  }\n" +
1755
		"}\n");
1756
1757
	this.workingCopies[1] = getWorkingCopy(
1758
		"/Completion/src/missing/MissingType.java",
1759
		"package missing;"+
1760
		"public class MissingType {\n" +
1761
		"}\n");
1762
1763
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
1764
	requestor.allowAllRequiredProposals();
1765
	String str = this.workingCopies[0].getSource();
1766
	String completeBehind = "new MissingType(";
1767
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
1768
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
1769
1770
	assertResults(
1771
			"",
1772
			requestor.getResults());
1773
}
1774
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260717
1775
public void test0044() throws JavaModelException {
1776
	this.workingCopies = new ICompilationUnit[3];
1777
	this.workingCopies[0] = getWorkingCopy(
1778
		"/Completion/src/test/Test.java",
1779
		"package test;"+
1780
		"public class Test {\n" +
1781
		"  void foo() {\n" +
1782
		"    MissingType m = null;\n" +
1783
		"    m.new Member(\n" +
1784
		"  }\n" +
1785
		"}\n");
1786
1787
	this.workingCopies[1] = getWorkingCopy(
1788
		"/Completion/src/missing/MissingType.java",
1789
		"package missing;"+
1790
		"public class MissingType {\n" +
1791
		"  public class Member {}\n" +
1792
		"}\n");
1793
1794
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
1795
	requestor.allowAllRequiredProposals();
1796
	String str = this.workingCopies[0].getSource();
1797
	String completeBehind = "new Member(";
1798
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
1799
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
1800
1801
	assertResults(
1802
			"",
1803
			requestor.getResults());
1804
}
1805
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260717
1806
public void test0045() throws JavaModelException {
1807
	this.workingCopies = new ICompilationUnit[3];
1808
	this.workingCopies[0] = getWorkingCopy(
1809
		"/Completion/src/test/Test.java",
1810
		"package test;"+
1811
		"public class Test {\n" +
1812
		"  void foo() {\n" +
1813
		"    new MissingType(\n" +
1814
		"  }\n" +
1815
		"}\n");
1816
1817
	this.workingCopies[1] = getWorkingCopy(
1818
		"/Completion/src/missing/MissingType.java",
1819
		"package missing;"+
1820
		"public interface MissingType {\n" +
1821
		"}\n");
1822
1823
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
1824
	requestor.allowAllRequiredProposals();
1825
	String str = this.workingCopies[0].getSource();
1826
	String completeBehind = "new MissingType(";
1827
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
1828
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
1829
1830
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED + R_NO_PROBLEMS;
1831
	int start1 = str.lastIndexOf("new MissingType(") + "new MissingType(".length();
1832
	int end1 = start1 + "".length();
1833
	int start2 = str.indexOf("MissingType");
1834
	int end2 = start2 + "MissingType".length();
1835
	assertResults(
1836
			"MissingType[ANONYMOUS_CLASS_DECLARATION]{, Lmissing.MissingType;, ()V, null, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
1837
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
1838
			requestor.getResults());
1839
}
1840
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260717
1841
public void test0046() throws JavaModelException {
1842
	this.workingCopies = new ICompilationUnit[3];
1843
	this.workingCopies[0] = getWorkingCopy(
1844
		"/Completion/src/test/Test.java",
1845
		"package test;"+
1846
		"public class Test {\n" +
1847
		"  void foo() {\n" +
1848
		"    new MissingType(\n" +
1849
		"  }\n" +
1850
		"}\n");
1851
1852
	this.workingCopies[1] = getWorkingCopy(
1853
		"/Completion/src/missing/MissingType.java",
1854
		"package missing;"+
1855
		"public abstract class MissingType {\n" +
1856
		"}\n");
1857
1858
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
1859
	requestor.allowAllRequiredProposals();
1860
	String str = this.workingCopies[0].getSource();
1861
	String completeBehind = "new MissingType(";
1862
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
1863
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
1864
1865
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED + R_NO_PROBLEMS;
1866
	int start1 = str.lastIndexOf("new MissingType(") + "new MissingType(".length();
1867
	int end1 = start1 + "".length();
1868
	int start2 = str.indexOf("MissingType");
1869
	int end2 = start2 + "MissingType".length();
1870
	assertResults(
1871
			"MissingType[ANONYMOUS_CLASS_DECLARATION]{, Lmissing.MissingType;, ()V, null, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
1872
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
1873
			requestor.getResults());
1874
}
1670
}
1875
}
(-)src/org/eclipse/jdt/core/tests/model/CompletionWithMissingTypesTests_1_5.java (+38 lines)
Lines 636-639 Link Here
636
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
636
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
637
			requestor.getResults());
637
			requestor.getResults());
638
}
638
}
639
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=260717
640
public void test0015() throws JavaModelException {
641
	this.workingCopies = new ICompilationUnit[3];
642
	this.workingCopies[0] = getWorkingCopy(
643
		"/Completion/src/test/Test.java",
644
		"package test;"+
645
		"public class Test {\n" +
646
		"  void foo() {\n" +
647
		"    new <String>MissingType(\n" +
648
		"  }\n" +
649
		"}\n");
650
651
	this.workingCopies[1] = getWorkingCopy(
652
		"/Completion/src/missing/MissingType.java",
653
		"package missing;"+
654
		"public class MissingType {\n" +
655
		"  public <T> MissingType() {}\n" +
656
		"}\n");
657
658
	CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, false, true);
659
	requestor.allowAllRequiredProposals();
660
	String str = this.workingCopies[0].getSource();
661
	String completeBehind = "new <String>MissingType(";
662
	int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
663
	this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
664
665
	int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED + R_NO_PROBLEMS;
666
	int start1 = str.lastIndexOf("new <String>MissingType(") + "new <String>MissingType(".length();
667
	int end1 = start1 + "".length();
668
	int start2 = str.indexOf("MissingType");
669
	int end2 = start2 + "MissingType".length();
670
	assertResults(
671
			"MissingType[ANONYMOUS_CLASS_DECLARATION]{, Lmissing.MissingType;, <T:Ljava.lang.Object;>()V, null, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
672
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}\n" +
673
			"MissingType[METHOD_REF<CONSTRUCTOR>]{, Lmissing.MissingType;, <T:Ljava.lang.Object;>()V, MissingType, null, ["+start1+", "+end1+"], " + (relevance1) + "}\n" +
674
			"   MissingType[TYPE_REF]{missing.MissingType, missing, Lmissing.MissingType;, null, null, ["+start2+", "+end2+"], " + (relevance1) + "}",
675
			requestor.getResults());
676
}
639
}
677
}

Return to bug 260717