Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 346454 | Differences between
and this patch

Collapse All | Expand All

(-)codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java (-1 / +16 lines)
Lines 5003-5009 Link Here
5003
		int relevance) {
5003
		int relevance) {
5004
5004
5005
		// No visibility checks can be performed without the scope & invocationSite
5005
		// No visibility checks can be performed without the scope & invocationSite
5006
		MethodBinding[] methods = currentType.availableMethods();
5006
		MethodBinding[] methods = null;
5007
		if (currentType instanceof ParameterizedTypeBinding && invocationSite instanceof CompletionOnQualifiedAllocationExpression) {
5008
			CompletionOnQualifiedAllocationExpression alloc = (CompletionOnQualifiedAllocationExpression) invocationSite;
5009
			if ((alloc.bits & ASTNode.IsDiamond) != 0) {
5010
				// inference failed. So don't substitute type arguments. Just return the unsubstituted methods
5011
				// and let the user decide what to substitute.
5012
				ParameterizedTypeBinding binding = (ParameterizedTypeBinding) currentType;
5013
				ReferenceBinding originalGenericType = binding.genericType();
5014
				if (originalGenericType != null)
5015
					methods = originalGenericType.methods();
5016
			} else {
5017
				methods = currentType.availableMethods();
5018
			}
5019
		} else {
5020
			methods = currentType.availableMethods();
5021
		}
5007
		if(methods != null) {
5022
		if(methods != null) {
5008
			int minArgLength = argTypes == null ? 0 : argTypes.length;
5023
			int minArgLength = argTypes == null ? 0 : argTypes.length;
5009
			next : for (int f = methods.length; --f >= 0;) {
5024
			next : for (int f = methods.length; --f >= 0;) {
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionOnQualifiedAllocationExpression.java (-5 / +37 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 39-62 Link Here
39
39
40
public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
40
public class CompletionOnQualifiedAllocationExpression extends QualifiedAllocationExpression {
41
public TypeBinding resolveType(BlockScope scope) {
41
public TypeBinding resolveType(BlockScope scope) {
42
	TypeBinding[] argumentTypes = Binding.NO_PARAMETERS;
42
	if (this.arguments != null) {
43
	if (this.arguments != null) {
43
		int argsLength = this.arguments.length;
44
		int argsLength = this.arguments.length;
44
		for (int a = argsLength; --a >= 0;)
45
		int length = this.arguments.length;
45
			this.arguments[a].resolveType(scope);
46
		argumentTypes = new TypeBinding[length];
47
		for (int a = argsLength; --a >= 0;) {
48
			argumentTypes[a] = this.arguments[a].resolveType(scope);
49
		}
46
	}
50
	}
47
51
	final boolean isDiamond = this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0;
48
	if (this.enclosingInstance != null) {
52
	if (this.enclosingInstance != null) {
49
		TypeBinding enclosingType = this.enclosingInstance.resolveType(scope);
53
		TypeBinding enclosingType = this.enclosingInstance.resolveType(scope);
54
		if (enclosingType == null) {
55
			// try to propose something even if enclosing type cannot be resolved.
56
			// Eg.: new Test<>().new Test<>(#cursor#
57
			if (this.enclosingInstance instanceof AllocationExpression) {
58
				TypeReference enclosingInstanceType = ((AllocationExpression) this.enclosingInstance).type;
59
				if (enclosingInstanceType != null) {
60
					enclosingType = enclosingInstanceType.resolvedType;
61
				}
62
			}
63
		}
50
		if (enclosingType == null || !(enclosingType instanceof ReferenceBinding)) {
64
		if (enclosingType == null || !(enclosingType instanceof ReferenceBinding)) {
51
			throw new CompletionNodeFound();
65
			throw new CompletionNodeFound();
52
		}
66
		}
53
		this.resolvedType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType);
67
		this.resolvedType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingType);
68
		if (isDiamond && (this.resolvedType instanceof ParameterizedTypeBinding)) {
69
			TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), null, argumentTypes, scope);
70
			if (inferredTypes != null) {
71
				this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType());
72
			} else {
73
				// inference failed. Resolved type will be of the form Test<>
74
				this.bits |= ASTNode.IsDiamond;
75
			}
76
	 	}
54
		if (!(this.resolvedType instanceof ReferenceBinding))
77
		if (!(this.resolvedType instanceof ReferenceBinding))
55
			throw new CompletionNodeFound(); // no need to continue if its an array or base type
78
			throw new CompletionNodeFound(); // no need to continue if its an array or base type
56
		if (this.resolvedType.isInterface()) // handle the anonymous class definition case
79
		if (this.resolvedType.isInterface()) // handle the anonymous class definition case
57
			this.resolvedType = scope.getJavaLangObject();
80
			this.resolvedType = scope.getJavaLangObject();
58
	} else {
81
	} else {
59
		this.resolvedType = this.type.resolveType(scope, true /* check bounds*/);
82
	 	this.resolvedType = this.type.resolveType(scope, true /* check bounds*/);
83
	 	if (isDiamond && (this.resolvedType instanceof ParameterizedTypeBinding)) {
84
			TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), null, argumentTypes, scope);
85
			if (inferredTypes != null) {
86
				this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType());
87
			} else {
88
				// inference failed. Resolved type will be of the form Test<>
89
				this.bits |= ASTNode.IsDiamond;
90
			}
91
	 	}
60
		if (!(this.resolvedType instanceof ReferenceBinding))
92
		if (!(this.resolvedType instanceof ReferenceBinding))
61
			throw new CompletionNodeFound(); // no need to continue if its an array or base type
93
			throw new CompletionNodeFound(); // no need to continue if its an array or base type
62
	}
94
	}
(-)codeassist/org/eclipse/jdt/internal/codeassist/complete/CompletionParser.java (-1 / +12 lines)
Lines 2614-2619 Link Here
2614
		this.listLength++;
2614
		this.listLength++;
2615
	}
2615
	}
2616
}
2616
}
2617
protected void consumeGenericTypeWithDiamond() {
2618
	super.consumeGenericTypeWithDiamond();
2619
	// we need to pop the <> of the diamond from the stack.
2620
	// This is not required in usual case when the type argument isn't elided
2621
	// since the < and > get popped while parsing the type argument. 
2622
	popElement(K_BINARY_OPERATOR); // pop >
2623
	popElement(K_BINARY_OPERATOR); // pop <
2624
}
2617
protected void consumeStatementFor() {
2625
protected void consumeStatementFor() {
2618
	super.consumeStatementFor();
2626
	super.consumeStatementFor();
2619
2627
Lines 4366-4372 Link Here
4366
4374
4367
protected TypeReference getTypeReferenceForGenericType(int dim,	int identifierLength, int numberOfIdentifiers) {
4375
protected TypeReference getTypeReferenceForGenericType(int dim,	int identifierLength, int numberOfIdentifiers) {
4368
	TypeReference ref = super.getTypeReferenceForGenericType(dim, identifierLength, numberOfIdentifiers);
4376
	TypeReference ref = super.getTypeReferenceForGenericType(dim, identifierLength, numberOfIdentifiers);
4369
4377
	// in completion case we might have encountered the assist node before really parsing
4378
	// the complete class instance creation, and so a separate check for diamond is needed here.
4379
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
4380
	checkForDiamond(ref);
4370
	if(this.assistNode != null) {
4381
	if(this.assistNode != null) {
4371
		if (identifierLength == 1 && numberOfIdentifiers == 1) {
4382
		if (identifierLength == 1 && numberOfIdentifiers == 1) {
4372
			ParameterizedSingleTypeReference singleRef = (ParameterizedSingleTypeReference) ref;
4383
			ParameterizedSingleTypeReference singleRef = (ParameterizedSingleTypeReference) ref;
(-)codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java (-1 / +1 lines)
Lines 989-995 Link Here
989
	int currentIdentifiersLength = identifierLength;
989
	int currentIdentifiersLength = identifierLength;
990
	while (index > 0) {
990
	while (index > 0) {
991
		int currentTypeArgumentsLength = this.genericsLengthStack[this.genericsLengthPtr--];
991
		int currentTypeArgumentsLength = this.genericsLengthStack[this.genericsLengthPtr--];
992
		if (currentTypeArgumentsLength != 0) {
992
		if (currentTypeArgumentsLength > 0) {
993
			this.genericsPtr -= currentTypeArgumentsLength;
993
			this.genericsPtr -= currentTypeArgumentsLength;
994
			System.arraycopy(this.genericsStack, this.genericsPtr + 1, typeArguments[index - 1] = new TypeReference[currentTypeArgumentsLength], 0, currentTypeArgumentsLength);
994
			System.arraycopy(this.genericsStack, this.genericsPtr + 1, typeArguments[index - 1] = new TypeReference[currentTypeArgumentsLength], 0, currentTypeArgumentsLength);
995
		}
995
		}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java (+3 lines)
Lines 250-255 Link Here
250
250
251
	// for type reference (diamond case) - Java 7
251
	// for type reference (diamond case) - Java 7
252
	public static final int IsUnionType = Bit30;
252
	public static final int IsUnionType = Bit30;
253
	// Used to tag ParameterizedSingleTypeReference or ParameterizedQualifiedTypeReference when they are
254
	// used without any type args. It is also used to tag CompletionOnQualifiedExpression when the
255
	// generics inference has failed and the resolved type still has <>.
253
	public static final int IsDiamond = Bit20;
256
	public static final int IsDiamond = Bit20;
254
257
255
	// this is only used for method invocation as the expression inside an expression statement
258
	// this is only used for method invocation as the expression inside an expression statement
(-)src/org/eclipse/jdt/core/tests/compiler/parser/CompletionParserTest.java (+76 lines)
Lines 8868-8871 Link Here
8868
		expectedReplacedSource,
8868
		expectedReplacedSource,
8869
		testName);
8869
		testName);
8870
}
8870
}
8871
8872
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
8873
public void testBug346454(){
8874
	if (this.complianceLevel < ClassFileConstants.JDK1_7)
8875
		return;
8876
	String str =
8877
		"public class Test<T> {\n" +
8878
		"	public void foo() {\n" +
8879
		"      Test<String> t = new Test<>()\n" +
8880
		"   }" +
8881
		"}\n";
8882
8883
	String testName = "<complete after diamond type>";
8884
	String completeBehind = "new Test<>(";
8885
	String expectedCompletionNodeToString = "<CompleteOnAllocationExpression:new Test<>()>";
8886
	String completionIdentifier = "";
8887
	String expectedReplacedSource = "";
8888
	String expectedUnitDisplayString =			
8889
		"public class Test<T> {\n" + 
8890
		"  public Test() {\n" + 
8891
		"  }\n" + 
8892
		"  public void foo() {\n" + 
8893
		"    Test<String> t = <CompleteOnAllocationExpression:new Test<>()>;\n" + 
8894
		"  }\n" + 
8895
		"}\n";
8896
8897
	int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1;
8898
	checkMethodParse(
8899
		str.toCharArray(),
8900
		cursorLocation,
8901
		expectedCompletionNodeToString,
8902
		expectedUnitDisplayString,
8903
		completionIdentifier,
8904
		expectedReplacedSource,
8905
		testName);
8906
}
8907
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
8908
public void testBug346454b(){
8909
	if (this.complianceLevel < ClassFileConstants.JDK1_7)
8910
		return;
8911
	String str =
8912
		"public class Test<T> {\n" +
8913
		"	public class T2<Z>{}\n" +
8914
		"	public void foo() {\n" +
8915
		"      Test<String>.T2<String> t = new Test<>().new T2<>()\n" +
8916
		"   }" +
8917
		"}\n";
8918
8919
	String testName = "<complete after diamond type>";
8920
	String completeBehind = "new Test<>().new T2<>(";
8921
	String expectedCompletionNodeToString = "<CompleteOnQualifiedAllocationExpression:new Test<>().new T2<>()>";
8922
	String completionIdentifier = "";
8923
	String expectedReplacedSource = "";
8924
	String expectedUnitDisplayString =			
8925
		"public class Test<T> {\n" + 
8926
		"  public class T2<Z> {\n" + 
8927
		"    public T2() {\n" + 
8928
		"    }\n" + 
8929
		"  }\n" + 
8930
		"  public Test() {\n" + 
8931
		"  }\n" + 
8932
		"  public void foo() {\n" + 
8933
		"    Test<String>.T2<String> t = <CompleteOnQualifiedAllocationExpression:new Test<>().new T2<>()>;\n" + 
8934
		"  }\n" + 
8935
		"}\n";
8936
8937
	int cursorLocation = str.indexOf(completeBehind) + completeBehind.length() - 1;
8938
	checkMethodParse(
8939
		str.toCharArray(),
8940
		cursorLocation,
8941
		expectedCompletionNodeToString,
8942
		expectedUnitDisplayString,
8943
		completionIdentifier,
8944
		expectedReplacedSource,
8945
		testName);
8946
}
8871
}
8947
}
(-)src/org/eclipse/jdt/core/tests/model/CompletionTests.java (+408 lines)
Lines 1006-1011 Link Here
1006
	suite.addTest(new CompletionTests("testBug343637f"));
1006
	suite.addTest(new CompletionTests("testBug343637f"));
1007
	suite.addTest(new CompletionTests("testBug343637g"));
1007
	suite.addTest(new CompletionTests("testBug343637g"));
1008
	suite.addTest(new CompletionTests("testBug343637h"));
1008
	suite.addTest(new CompletionTests("testBug343637h"));
1009
	suite.addTest(new CompletionTests("testBug346454"));
1010
	suite.addTest(new CompletionTests("testBug346454b"));
1011
	suite.addTest(new CompletionTests("testBug346454c"));
1012
	suite.addTest(new CompletionTests("testBug346454c_2"));
1013
	suite.addTest(new CompletionTests("testBug346454d"));
1014
	suite.addTest(new CompletionTests("testBug346454e"));
1015
	suite.addTest(new CompletionTests("testBug346454f"));
1016
	suite.addTest(new CompletionTests("testBug346454g"));
1017
	suite.addTest(new CompletionTests("testBug346454h"));
1018
	suite.addTest(new CompletionTests("testBug346454i"));
1009
	return suite;
1019
	return suite;
1010
}
1020
}
1011
public CompletionTests(String name) {
1021
public CompletionTests(String name) {
Lines 24008-24011 Link Here
24008
		COMPLETION_PROJECT.setOptions(options);	
24018
		COMPLETION_PROJECT.setOptions(options);	
24009
	}
24019
	}
24010
}
24020
}
24021
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24022
// Should not get NegativeArraySizeException or show proposals for types
24023
public void testBug346454() throws JavaModelException {
24024
	Map options = COMPLETION_PROJECT.getOptions(true);
24025
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24026
	try {
24027
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24028
		COMPLETION_PROJECT.setOptions(options);
24029
		this.workingCopies = new ICompilationUnit[1];
24030
		this.workingCopies[0] = getWorkingCopy(
24031
			"/Completion/src/test/Test.java",
24032
			"package test;"+
24033
			"public class Test<T> {\n" +
24034
			"	public void foo() {\n" +
24035
			"     Test<String> x = new Test<>\n" +
24036
			"   }" +
24037
			"}\n");
24038
24039
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24040
		String str = this.workingCopies[0].getSource();
24041
		String completeBehind = "new Test<>";
24042
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24043
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24044
		assertResults(
24045
			"",
24046
			requestor.getResults());
24047
	} finally {
24048
		// Restore compliance settings.
24049
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24050
		COMPLETION_PROJECT.setOptions(options);	
24051
	}
24052
}
24053
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24054
// Should not get NegativeArraySizeException
24055
public void testBug346454b() throws JavaModelException {
24056
	Map options = COMPLETION_PROJECT.getOptions(true);
24057
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24058
	try {
24059
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24060
		COMPLETION_PROJECT.setOptions(options);
24061
		this.workingCopies = new ICompilationUnit[1];
24062
		this.workingCopies[0] = getWorkingCopy(
24063
			"/Completion/src/test/Test.java",
24064
			"package test;"+
24065
			"public class Test<T> {\n" +
24066
			"	public void foo() {\n" +
24067
			"     Test<String> x = new Test<>.\n" +
24068
			"   }" +
24069
			"}\n");
24070
24071
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24072
		String str = this.workingCopies[0].getSource();
24073
		String completeBehind = "new Test<>.";
24074
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24075
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24076
		assertResults(
24077
			"",
24078
			requestor.getResults());
24079
	} finally {
24080
		// Restore compliance settings.
24081
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24082
		COMPLETION_PROJECT.setOptions(options);	
24083
	}
24084
}
24085
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24086
// Should get proposals for constructor parameters
24087
public void testBug346454c() throws JavaModelException {
24088
	Map options = COMPLETION_PROJECT.getOptions(true);
24089
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24090
	try {
24091
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24092
		COMPLETION_PROJECT.setOptions(options);
24093
		this.workingCopies = new ICompilationUnit[1];
24094
		this.workingCopies[0] = getWorkingCopy(
24095
			"/Completion/src/test/Test.java",
24096
			"package test;"+
24097
			"public class Test<T> {\n" +
24098
			"	public Test(int i){}\n" +
24099
			"	public void foo() {\n" +
24100
			"	  int j = 1;\n" +
24101
			"     new Test<>()\n" +
24102
			"   }" +
24103
			"}\n");
24104
24105
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24106
		String str = this.workingCopies[0].getSource();
24107
		String completeBehind = "new Test<>(";
24108
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24109
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24110
		assertResults(
24111
			"Test[METHOD_REF<CONSTRUCTOR>]{, Ltest.Test<>;, (I)V, Test, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24112
			"Test<>[ANONYMOUS_CLASS_DECLARATION]{, Ltest.Test<>;, (I)V, null, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}",
24113
			requestor.getResults());
24114
	} finally {
24115
		// Restore compliance settings.
24116
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24117
		COMPLETION_PROJECT.setOptions(options);	
24118
	}
24119
}
24120
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24121
// Inference fails but be resilient. At least propose unsubstituted methods.
24122
public void testBug346454c_2() throws JavaModelException {
24123
	Map options = COMPLETION_PROJECT.getOptions(true);
24124
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24125
	try {
24126
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24127
		COMPLETION_PROJECT.setOptions(options);
24128
		this.workingCopies = new ICompilationUnit[1];
24129
		this.workingCopies[0] = getWorkingCopy(
24130
			"/Completion/src/test/Test.java",
24131
			"package test;"+
24132
			"public class Test<T> {\n" +
24133
			"	public Test(T t){}\n" +
24134
			"	public Test(int i){}\n" +
24135
			"	public void foo() {\n" +
24136
			"       new Test<>()\n" +
24137
			"   }" +
24138
			"}\n");
24139
24140
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24141
		String str = this.workingCopies[0].getSource();
24142
		String completeBehind = "new Test<>(";
24143
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24144
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24145
		assertResults(
24146
			"Test[METHOD_REF<CONSTRUCTOR>]{, Ltest.Test<>;, (I)V, Test, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24147
			"Test[METHOD_REF<CONSTRUCTOR>]{, Ltest.Test<>;, (TT;)V, Test, (t), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24148
			"Test<>[ANONYMOUS_CLASS_DECLARATION]{, Ltest.Test<>;, (I)V, null, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24149
			"Test<>[ANONYMOUS_CLASS_DECLARATION]{, Ltest.Test<>;, (TT;)V, null, (t), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}",
24150
			requestor.getResults());
24151
	} finally {
24152
		// Restore compliance settings.
24153
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24154
		COMPLETION_PROJECT.setOptions(options);	
24155
	}
24156
}
24157
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24158
// Qualified exp case. Should get proposals for constructor parameters.
24159
// This tests changes in CompleteOnQualifiedAllocationExpression
24160
public void testBug346454d() throws JavaModelException {
24161
	Map options = COMPLETION_PROJECT.getOptions(true);
24162
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24163
	try {
24164
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24165
		COMPLETION_PROJECT.setOptions(options);
24166
		this.workingCopies = new ICompilationUnit[2];
24167
		this.workingCopies[0] = getWorkingCopy(
24168
			"/Completion/src/test/X.java",
24169
			"package test;"+
24170
			"public class X<T> {\n" +
24171
			"	public void foo() {\n" +
24172
			"     new pack.Test<>()\n" +
24173
			"   }" +
24174
			"}\n");
24175
		
24176
		this.workingCopies[1] = getWorkingCopy(
24177
				"/Completion/src/pack/Test.java",
24178
				"package pack;"+
24179
				"public class Test<T> {\n" +
24180
				"	public Test(T t){}\n" +
24181
				"	public Test(int i){}\n" +
24182
				"}\n");
24183
24184
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24185
		String str = this.workingCopies[0].getSource();
24186
		String completeBehind = " new pack.Test<>(";
24187
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24188
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24189
		assertResults(
24190
				"Test[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>;, (I)V, Test, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24191
				"Test[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>;, (TT;)V, Test, (t), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24192
				"Test<>[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>;, (I)V, null, (i), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24193
				"Test<>[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>;, (TT;)V, null, (t), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}",
24194
				requestor.getResults());
24195
	} finally {
24196
		// Restore compliance settings.
24197
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24198
		COMPLETION_PROJECT.setOptions(options);	
24199
	}
24200
}
24201
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24202
// Qualified exp case. Should get proposals for constructor completion
24203
public void testBug346454e() throws JavaModelException {
24204
	Map options = COMPLETION_PROJECT.getOptions(true);
24205
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24206
	try {
24207
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24208
		COMPLETION_PROJECT.setOptions(options);
24209
		this.workingCopies = new ICompilationUnit[2];
24210
		this.workingCopies[0] = getWorkingCopy(
24211
			"/Completion/src/test/X.java",
24212
			"package test;"+
24213
			"public class X<T> {\n" +
24214
			"	public void foo() {\n" +
24215
			"     new pack.Test<>.\n" +
24216
			"   }" +
24217
			"}\n");
24218
		
24219
		this.workingCopies[1] = getWorkingCopy(
24220
				"/Completion/src/pack/Test.java",
24221
				"package pack;"+
24222
				"public class Test<T> {\n" +
24223
				"	public Test(T t){}\n" +
24224
				"	public Test(int i){}\n" +
24225
				"}\n");
24226
24227
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24228
		String str = this.workingCopies[0].getSource();
24229
		String completeBehind = "new pack.Test<>.";
24230
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24231
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24232
		assertResults(
24233
				"",
24234
				requestor.getResults());
24235
	} finally {
24236
		// Restore compliance settings.
24237
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24238
		COMPLETION_PROJECT.setOptions(options);	
24239
	}
24240
}
24241
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24242
// Qualified allocation case. Should get proposals for constructor completion
24243
// This tests changes in CompleteOnQualifiedAllocationExpression
24244
public void testBug346454f() throws JavaModelException {
24245
	Map options = COMPLETION_PROJECT.getOptions(true);
24246
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24247
	try {
24248
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24249
		COMPLETION_PROJECT.setOptions(options);
24250
		this.workingCopies = new ICompilationUnit[2];
24251
		this.workingCopies[0] = getWorkingCopy(
24252
			"/Completion/src/test/Test.java",
24253
			"package test;" +
24254
			"import pack.Test;\n"+
24255
			"public class X {\n" +
24256
			"	public void foo() {\n" +
24257
			"     Test<String>.T2<String> t = new Test<>().new T2<>()\n" +
24258
			"   }" +
24259
			"}\n");
24260
		
24261
		this.workingCopies[1] = getWorkingCopy(
24262
				"/Completion/src/pack/Test.java",
24263
				"package pack;"+
24264
				"public class Test<T> {\n" +
24265
				"	public class T2<Z> {\n" +
24266
				"		public T2(Z z){}\n" +
24267
				"   }" +
24268
				"}\n");
24269
24270
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24271
		String str = this.workingCopies[0].getSource();
24272
		String completeBehind = "new Test<>().new T2<>(";
24273
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24274
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24275
		assertResults(
24276
			"T2[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>.T2;, (TZ;)V, T2, (z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24277
			"Test<>.T2[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>.T2;, (TZ;)V, null, (z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}",
24278
			requestor.getResults());
24279
	} finally {
24280
		// Restore compliance settings.
24281
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24282
		COMPLETION_PROJECT.setOptions(options);	
24283
	}
24284
}
24285
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24286
// Qualified allocation case. Should get proposals for constructor completion
24287
// This tests changes in CompleteOnQualifiedAllocationExpression
24288
public void testBug346454g() throws JavaModelException {
24289
	Map options = COMPLETION_PROJECT.getOptions(true);
24290
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24291
	try {
24292
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24293
		COMPLETION_PROJECT.setOptions(options);
24294
		this.workingCopies = new ICompilationUnit[2];
24295
		this.workingCopies[0] = getWorkingCopy(
24296
			"/Completion/src/test/Test.java",
24297
			"package test;" +
24298
			"public class X {\n" +
24299
			"	public void foo() {\n" +
24300
			"     new pack.Test<>().new T2<>()\n" +
24301
			"   }" +
24302
			"}\n");
24303
		
24304
		this.workingCopies[1] = getWorkingCopy(
24305
				"/Completion/src/pack/Test.java",
24306
				"package pack;"+
24307
				"public class Test<T> {\n" +
24308
				"	public Test(T t){}\n" +
24309
				"	public class T2<Z> {\n" +
24310
				"		public T2(Z z){}\n" +
24311
				"   }" +
24312
				"}\n");
24313
24314
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24315
		String str = this.workingCopies[0].getSource();
24316
		String completeBehind = "new pack.Test<>().new T2<>(";
24317
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24318
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24319
		assertResults(
24320
				"T2[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>.T2;, (TZ;)V, T2, (z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24321
				"Test<>.T2[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>.T2;, (TZ;)V, null, (z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}",
24322
				requestor.getResults());
24323
	} finally {
24324
		// Restore compliance settings.
24325
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24326
		COMPLETION_PROJECT.setOptions(options);	
24327
	}
24328
}
24329
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24330
// Allocation case with explicit type args and diamond together. Should not throw exception.
24331
// This tests changes in CompleteOnQualifiedAllocationExpression
24332
public void testBug346454h() throws JavaModelException {
24333
	Map options = COMPLETION_PROJECT.getOptions(true);
24334
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24335
	try {
24336
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24337
		COMPLETION_PROJECT.setOptions(options);
24338
		this.workingCopies = new ICompilationUnit[2];
24339
		this.workingCopies[0] = getWorkingCopy(
24340
			"/Completion/src/test/Test.java",
24341
			"package test;" +
24342
			"import pack.Test;\n"+
24343
			"public class X {\n" +
24344
			"	public void foo() {\n" +
24345
			"     new <String> Test<>()\n" +
24346
			"   }" +
24347
			"}\n");
24348
		
24349
		this.workingCopies[1] = getWorkingCopy(
24350
				"/Completion/src/pack/Test.java",
24351
				"package pack;"+
24352
				"public class Test<T> {\n" +
24353
				"	public <Z> Test(T t, Z z) {\n" +
24354
				"   }" +
24355
				"}\n");
24356
24357
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24358
		String str = this.workingCopies[0].getSource();
24359
		String completeBehind = "new <String> Test<>(";
24360
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24361
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24362
		assertResults(
24363
			"Test[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>;, <Z:Ljava.lang.Object;>(TT;TZ;)V, Test, (t, z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24364
			"Test<>[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>;, <Z:Ljava.lang.Object;>(TT;TZ;)V, null, (t, z), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}",	
24365
			requestor.getResults());
24366
	} finally {
24367
		// Restore compliance settings.
24368
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24369
		COMPLETION_PROJECT.setOptions(options);	
24370
	}
24371
}
24372
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=346454
24373
// Qualified Allocation case with explicit type args and diamond together. Should not throw exception.
24374
// This tests changes in CompleteOnQualifiedAllocationExpression
24375
public void testBug346454i() throws JavaModelException {
24376
	Map options = COMPLETION_PROJECT.getOptions(true);
24377
	Object savedOptionCompliance = options.get(CompilerOptions.OPTION_Compliance);
24378
	try {
24379
		options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_7);
24380
		COMPLETION_PROJECT.setOptions(options);
24381
		this.workingCopies = new ICompilationUnit[2];
24382
		this.workingCopies[0] = getWorkingCopy(
24383
			"/Completion/src/test/Test.java",
24384
			"package test;" +
24385
			"import pack.Test;\n"+
24386
			"public class X {\n" +
24387
			"	public void foo() {\n" +
24388
			"     new <String> Test<>().new T2<>()\n" +
24389
			"   }" +
24390
			"}\n");
24391
		
24392
		this.workingCopies[1] = getWorkingCopy(
24393
				"/Completion/src/pack/Test.java",
24394
				"package pack;"+
24395
				"public class Test<T> {\n" +
24396
				"	public <Z> Test(T t) {\n" +
24397
				"   }\n" +
24398
				"	public class T2<U> {\n" +
24399
				"		public T2(U u) {\n" +
24400
				"   	}\n" +
24401
				"	}\n" +
24402
				"}\n");
24403
24404
		CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true);
24405
		String str = this.workingCopies[0].getSource();
24406
		String completeBehind = "new <String> Test<>().new T2<>(";
24407
		int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
24408
		this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
24409
		assertResults(
24410
				"T2[METHOD_REF<CONSTRUCTOR>]{, Lpack.Test<>.T2;, (TU;)V, T2, (u), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}\n" +
24411
				"Test<>.T2[ANONYMOUS_CLASS_DECLARATION]{, Lpack.Test<>.T2;, (TU;)V, null, (u), " + (R_DEFAULT + R_RESOLVED + R_INTERESTING + R_NON_RESTRICTED) + "}",	
24412
				requestor.getResults());
24413
	} finally {
24414
		// Restore compliance settings.
24415
		options.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
24416
		COMPLETION_PROJECT.setOptions(options);	
24417
	}
24418
}
24011
}
24419
}

Return to bug 346454