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 339478 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java (-2 / +15 lines)
Lines 29-35 Link Here
29
	public TypeReference[] typeArguments;
29
	public TypeReference[] typeArguments;
30
	public TypeBinding[] genericTypeArguments;
30
	public TypeBinding[] genericTypeArguments;
31
	public FieldDeclaration enumConstant; // for enum constant initializations
31
	public FieldDeclaration enumConstant; // for enum constant initializations
32
32
	protected TypeBinding expectedType;
33
	
33
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
34
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) {
34
	// check captured variables are initialized in current context (26134)
35
	// check captured variables are initialized in current context (26134)
35
	checkCapturedLocalInitializationIfNecessary((ReferenceBinding)this.binding.declaringClass.erasure(), currentScope, flowInfo);
36
	checkCapturedLocalInitializationIfNecessary((ReferenceBinding)this.binding.declaringClass.erasure(), currentScope, flowInfo);
Lines 255-261 Link Here
255
		// initialization of an enum constant
256
		// initialization of an enum constant
256
		this.resolvedType = scope.enclosingReceiverType();
257
		this.resolvedType = scope.enclosingReceiverType();
257
	} else {
258
	} else {
258
		this.resolvedType = this.type.resolveType(scope, true /* check bounds*/);
259
		TypeBinding inferredArguments[] = null;
260
		if ((scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7) && (this.type.bits & ASTNode.IsDiamond) != 0) {
261
			if (this.expectedType != null && this.expectedType.isParameterizedTypeWithActualArguments())
262
				inferredArguments = ((ParameterizedTypeBinding)this.expectedType).arguments;
263
		}
264
		this.resolvedType = this.type.resolveType(scope, true /* check bounds*/, inferredArguments);
259
		checkParameterizedAllocation: {
265
		checkParameterizedAllocation: {
260
			if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
266
			if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
261
				ReferenceBinding currentType = (ReferenceBinding)this.resolvedType;
267
				ReferenceBinding currentType = (ReferenceBinding)this.resolvedType;
Lines 409-412 Link Here
409
	}
415
	}
410
	visitor.endVisit(this, scope);
416
	visitor.endVisit(this, scope);
411
}
417
}
418
/**
419
 * @see org.eclipse.jdt.internal.compiler.ast.Expression#setExpectedType(org.eclipse.jdt.internal.compiler.lookup.TypeBinding)
420
 */
421
public void setExpectedType(TypeBinding expectedType) {
422
	this.expectedType = expectedType;
423
}
424
412
}
425
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java (-4 / +18 lines)
Lines 27-32 Link Here
27
public class ParameterizedQualifiedTypeReference extends ArrayQualifiedTypeReference {
27
public class ParameterizedQualifiedTypeReference extends ArrayQualifiedTypeReference {
28
28
29
	public TypeReference[][] typeArguments;
29
	public TypeReference[][] typeArguments;
30
	public TypeBinding[] inferredTypeArgs;
30
31
31
	/**
32
	/**
32
	 * @param tokens
33
	 * @param tokens
Lines 37-42 Link Here
37
38
38
		super(tokens, dim, positions);
39
		super(tokens, dim, positions);
39
		this.typeArguments = typeArguments;
40
		this.typeArguments = typeArguments;
41
		this.inferredTypeArgs = null;
40
	}
42
	}
41
	public void checkBounds(Scope scope) {
43
	public void checkBounds(Scope scope) {
42
		if (this.resolvedType == null) return;
44
		if (this.resolvedType == null) return;
Lines 68-73 Link Here
68
	 * @return char[][]
70
	 * @return char[][]
69
	 */
71
	 */
70
	public char [][] getParameterizedTypeName(){
72
	public char [][] getParameterizedTypeName(){
73
		if ((this.bits & ASTNode.IsDiamond) != 0)
74
			return this.getTypeName();
71
		int length = this.tokens.length;
75
		int length = this.tokens.length;
72
		char[][] qParamName = new char[length][];
76
		char[][] qParamName = new char[length][];
73
		for (int i = 0; i < length; i++) {
77
		for (int i = 0; i < length; i++) {
Lines 223-228 Link Here
223
						argTypes[j] = argType;
227
						argTypes[j] = argType;
224
					}
228
					}
225
				}
229
				}
230
				if (argLength == 0 && (this.bits & ASTNode.IsDiamond) != 0 && this.inferredTypeArgs != null) {
231
					argTypes = this.inferredTypeArgs;
232
				}
226
				if (argHasError) {
233
				if (argHasError) {
227
					return null;
234
					return null;
228
				}
235
				}
Lines 247-255 Link Here
247
						this.resolvedType = scope.createArrayType(this.resolvedType, this.dimensions);
254
						this.resolvedType = scope.createArrayType(this.resolvedType, this.dimensions);
248
					}
255
					}
249
					return this.resolvedType;
256
					return this.resolvedType;
250
				} else if (argLength != typeVariables.length && !isDiamond) { // check arity
257
				} else if (argLength != typeVariables.length) {
251
					scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes, i);
258
					if (!isDiamond) { // check arity
252
					return null;
259
						scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes, i);
260
						return null;
261
					}
262
					checkBounds = false; // successful <> inference needs no bounds check, we will scream foul if needed during inference.
253
				}
263
				}
254
				// check parameterizing non-static member type of raw type
264
				// check parameterizing non-static member type of raw type
255
				if (typeIsConsistent && !currentType.isStatic()) {
265
				if (typeIsConsistent && !currentType.isStatic()) {
Lines 344-350 Link Here
344
		}
354
		}
345
		return output;
355
		return output;
346
	}
356
	}
347
357
	
358
	public TypeBinding resolveType(BlockScope scope, boolean checkBounds, TypeBinding[] inferredArgs) {
359
		this.inferredTypeArgs = inferredArgs;
360
	    return internalResolveType(scope, checkBounds);
361
	}
348
	public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
362
	public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
349
	    return internalResolveType(scope, checkBounds);
363
	    return internalResolveType(scope, checkBounds);
350
	}
364
	}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java (-3 / +23 lines)
Lines 27-37 Link Here
27
public class ParameterizedSingleTypeReference extends ArrayTypeReference {
27
public class ParameterizedSingleTypeReference extends ArrayTypeReference {
28
28
29
	public TypeReference[] typeArguments;
29
	public TypeReference[] typeArguments;
30
	public TypeBinding[] inferredTypeArgs;
30
31
31
	public ParameterizedSingleTypeReference(char[] name, TypeReference[] typeArguments, int dim, long pos){
32
	public ParameterizedSingleTypeReference(char[] name, TypeReference[] typeArguments, int dim, long pos){
32
		super(name, dim, pos);
33
		super(name, dim, pos);
33
		this.originalSourceEnd = this.sourceEnd;
34
		this.originalSourceEnd = this.sourceEnd;
34
		this.typeArguments = typeArguments;
35
		this.typeArguments = typeArguments;
36
		this.inferredTypeArgs = null;
35
	}
37
	}
36
	public void checkBounds(Scope scope) {
38
	public void checkBounds(Scope scope) {
37
		if (this.resolvedType == null) return;
39
		if (this.resolvedType == null) return;
Lines 57-62 Link Here
57
	 * @return char[][]
59
	 * @return char[][]
58
	 */
60
	 */
59
	public char [][] getParameterizedTypeName(){
61
	public char [][] getParameterizedTypeName(){
62
		if ((this.bits & ASTNode.IsDiamond) != 0)
63
			return this.getTypeName();
60
		StringBuffer buffer = new StringBuffer(5);
64
		StringBuffer buffer = new StringBuffer(5);
61
		buffer.append(this.token).append('<');
65
		buffer.append(this.token).append('<');
62
		for (int i = 0, length = this.typeArguments.length; i < length; i++) {
66
		for (int i = 0, length = this.typeArguments.length; i < length; i++) {
Lines 188-193 Link Here
188
			    argTypes[i] = argType;
192
			    argTypes[i] = argType;
189
		     }
193
		     }
190
		}
194
		}
195
		if (argLength == 0 && (this.bits & ASTNode.IsDiamond) != 0 && this.inferredTypeArgs != null) {
196
			argTypes = this.inferredTypeArgs;
197
		}
191
		if (argHasError) {
198
		if (argHasError) {
192
			return null;
199
			return null;
193
		}
200
		}
Lines 221-229 Link Here
221
				return this.resolvedType = type;
228
				return this.resolvedType = type;
222
			}
229
			}
223
			// if missing generic type, and compliance >= 1.5, then will rebuild a parameterized binding
230
			// if missing generic type, and compliance >= 1.5, then will rebuild a parameterized binding
224
		} else if (argLength != typeVariables.length && (this.bits & ASTNode.IsDiamond) == 0) { // check arity, IsDiamond never set for 1.6-
231
		} else if (argLength != typeVariables.length) {
225
			scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes);
232
			if ((this.bits & ASTNode.IsDiamond) == 0) { // check arity, IsDiamond never set for 1.6-
226
			return null;
233
				scope.problemReporter().incorrectArityForParameterizedType(this, currentType, argTypes);
234
				return null;
235
			} 
236
			checkBounds = false; // successful <> inference needs no bounds check, we will scream foul if needed during inference.
227
		} else if (!currentType.isStatic()) {
237
		} else if (!currentType.isStatic()) {
228
			ReferenceBinding actualEnclosing = currentType.enclosingType();
238
			ReferenceBinding actualEnclosing = currentType.enclosingType();
229
			if (actualEnclosing != null && actualEnclosing.isRawType()){
239
			if (actualEnclosing != null && actualEnclosing.isRawType()){
Lines 281-286 Link Here
281
		return output;
291
		return output;
282
	}
292
	}
283
293
294
	public TypeBinding resolveType(BlockScope scope, boolean checkBounds, TypeBinding[] inferredArgs) {
295
		this.inferredTypeArgs = inferredArgs;
296
	    return internalResolveType(scope, null, checkBounds);
297
	}
298
	
284
	public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
299
	public TypeBinding resolveType(BlockScope scope, boolean checkBounds) {
285
	    return internalResolveType(scope, null, checkBounds);
300
	    return internalResolveType(scope, null, checkBounds);
286
	}
301
	}
Lines 292-297 Link Here
292
	public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType) {
307
	public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType) {
293
	    return internalResolveType(scope, enclosingType, true/*check bounds*/);
308
	    return internalResolveType(scope, enclosingType, true/*check bounds*/);
294
	}
309
	}
310
	
311
	public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingType, TypeBinding[] inferredArgs) {
312
		this.inferredTypeArgs = inferredArgs;
313
	    return internalResolveType(scope, enclosingType, true/*check bounds*/);
314
	}
295
315
296
	public void traverse(ASTVisitor visitor, BlockScope scope) {
316
	public void traverse(ASTVisitor visitor, BlockScope scope) {
297
		if (visitor.visit(this, scope)) {
317
		if (visitor.visit(this, scope)) {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java (-2 / +22 lines)
Lines 23-28 Link Here
23
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
23
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
24
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
24
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
25
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
26
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
27
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
27
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
28
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
28
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
Lines 261-267 Link Here
261
				scope.problemReporter().invalidType(this.enclosingInstance, enclosingInstanceType);
262
				scope.problemReporter().invalidType(this.enclosingInstance, enclosingInstanceType);
262
				hasError = true;
263
				hasError = true;
263
			} else {
264
			} else {
264
				receiverType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingInstanceType);
265
				TypeBinding inferredArguments[] = null;
266
				if ((scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7) && (this.type.bits & ASTNode.IsDiamond) != 0) {
267
					if (this.expectedType != null && this.expectedType.isParameterizedTypeWithActualArguments())
268
						inferredArguments = ((ParameterizedTypeBinding)this.expectedType).arguments;
269
				}
270
				receiverType = ((SingleTypeReference) this.type).resolveTypeEnclosing(scope, (ReferenceBinding) enclosingInstanceType, inferredArguments);
265
				if (receiverType != null && enclosingInstanceContainsCast) {
271
				if (receiverType != null && enclosingInstanceContainsCast) {
266
					CastExpression.checkNeedForEnclosingInstanceCast(scope, this.enclosingInstance, enclosingInstanceType, receiverType);
272
					CastExpression.checkNeedForEnclosingInstanceCast(scope, this.enclosingInstance, enclosingInstanceType, receiverType);
267
				}
273
				}
Lines 271-277 Link Here
271
				// initialization of an enum constant
277
				// initialization of an enum constant
272
				receiverType = scope.enclosingSourceType();
278
				receiverType = scope.enclosingSourceType();
273
			} else {
279
			} else {
274
				receiverType = this.type.resolveType(scope, true /* check bounds*/);
280
				TypeBinding inferredArguments[] = null;
281
				if ((scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_7) && (this.type.bits & ASTNode.IsDiamond) != 0) {
282
					if (this.expectedType != null && this.expectedType.isParameterizedTypeWithActualArguments())
283
						inferredArguments = ((ParameterizedTypeBinding)this.expectedType).arguments;
284
				}
285
				receiverType = this.type.resolveType(scope, true /* check bounds*/, inferredArguments);
275
				checkParameterizedAllocation: {
286
				checkParameterizedAllocation: {
276
					if (receiverType == null || !receiverType.isValidBinding()) break checkParameterizedAllocation;
287
					if (receiverType == null || !receiverType.isValidBinding()) break checkParameterizedAllocation;
277
					if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
288
					if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
Lines 498-501 Link Here
498
		}
509
		}
499
		visitor.endVisit(this, scope);
510
		visitor.endVisit(this, scope);
500
	}
511
	}
512
	
513
	/**
514
	 * @see org.eclipse.jdt.internal.compiler.ast.Expression#setExpectedType(org.eclipse.jdt.internal.compiler.lookup.TypeBinding)
515
	 */
516
	public void setExpectedType(TypeBinding expectedType) {
517
		this.expectedType = expectedType;
518
		if (this.expectedType != null && this.enclosingInstance != null)
519
			this.enclosingInstance.setExpectedType(this.expectedType.enclosingType());
520
	}
501
}
521
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/SingleTypeReference.java (-1 / +5 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 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 93-96 Link Here
93
		visitor.visit(this, scope);
93
		visitor.visit(this, scope);
94
		visitor.endVisit(this, scope);
94
		visitor.endVisit(this, scope);
95
	}
95
	}
96
	
97
	public TypeBinding resolveTypeEnclosing(BlockScope scope, ReferenceBinding enclosingInstanceType, TypeBinding[] inferredArguments) {
98
		return this.resolveTypeEnclosing(scope, enclosingInstanceType);
99
	}
96
}
100
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/TypeReference.java (+4 lines)
Lines 208-213 Link Here
208
	return internalResolveType(scope);
208
	return internalResolveType(scope);
209
}
209
}
210
210
211
public TypeBinding resolveType(BlockScope scope, boolean checkBounds, TypeBinding[] inferredArgs) {
212
	return internalResolveType(scope);
213
}
214
211
public TypeBinding resolveType(ClassScope scope) {
215
public TypeBinding resolveType(ClassScope scope) {
212
	return internalResolveType(scope);
216
	return internalResolveType(scope);
213
}
217
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java (-2 / +10 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2010 IBM Corporation and others.
2
 * Copyright (c) 2005, 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 31-36 Link Here
31
	public ReferenceBinding[] memberTypes;
31
	public ReferenceBinding[] memberTypes;
32
	public MethodBinding[] methods;
32
	public MethodBinding[] methods;
33
	private ReferenceBinding enclosingType;
33
	private ReferenceBinding enclosingType;
34
	private TypeBinding[] expectedArgumentTypes;
34
35
35
	public ParameterizedTypeBinding(ReferenceBinding type, TypeBinding[] arguments,  ReferenceBinding enclosingType, LookupEnvironment environment){
36
	public ParameterizedTypeBinding(ReferenceBinding type, TypeBinding[] arguments,  ReferenceBinding enclosingType, LookupEnvironment environment){
36
		this.environment = environment;
37
		this.environment = environment;
Lines 451-457 Link Here
451
	public MethodBinding getExactConstructor(TypeBinding[] argumentTypes) {
452
	public MethodBinding getExactConstructor(TypeBinding[] argumentTypes) {
452
		int argCount = argumentTypes.length;
453
		int argCount = argumentTypes.length;
453
		MethodBinding match = null;
454
		MethodBinding match = null;
454
455
		this.expectedArgumentTypes = argumentTypes;
455
		if ((this.tagBits & TagBits.AreMethodsComplete) != 0) { // have resolved all arg types & return type of the methods
456
		if ((this.tagBits & TagBits.AreMethodsComplete) != 0) { // have resolved all arg types & return type of the methods
456
			long range;
457
			long range;
457
			if ((range = ReferenceBinding.binarySearch(TypeConstants.INIT, this.methods)) >= 0) {
458
			if ((range = ReferenceBinding.binarySearch(TypeConstants.INIT, this.methods)) >= 0) {
Lines 955-960 Link Here
955
			    // lazy init, since cannot do so during binding creation if during supertype connection
956
			    // lazy init, since cannot do so during binding creation if during supertype connection
956
			    if (currentType.arguments == null)
957
			    if (currentType.arguments == null)
957
					currentType.initializeArguments(); // only for raw types
958
					currentType.initializeArguments(); // only for raw types
959
			    else if (currentType.arguments.length == 0) {	// diamond case
960
			    	// this.expectedArgumentTypes should have the argument list
961
			    	 if (currentType.expectedArgumentTypes != null  && currentType.expectedArgumentTypes.length != 0) {
962
			    		 return currentType.expectedArgumentTypes[originalVariable.rank];
963
			    	 }
964
			    	return originalVariable;
965
			    }
958
			    if (currentType.arguments != null)
966
			    if (currentType.arguments != null)
959
					return currentType.arguments[originalVariable.rank];
967
					return currentType.arguments[originalVariable.rank];
960
			}
968
			}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java (-80 / +26 lines)
Lines 14-21 Link Here
14
 *******************************************************************************/
14
 *******************************************************************************/
15
package org.eclipse.jdt.core.tests.compiler.regression;
15
package org.eclipse.jdt.core.tests.compiler.regression;
16
16
17
import java.util.Map;
18
19
import junit.framework.Test;
17
import junit.framework.Test;
20
public class GenericsRegressionTest_1_7 extends AbstractRegressionTest {
18
public class GenericsRegressionTest_1_7 extends AbstractRegressionTest {
21
19
Lines 30-36 Link Here
30
public static Test suite() {
28
public static Test suite() {
31
	return buildMinimalComplianceTestSuite(testClass(), F_1_7);
29
	return buildMinimalComplianceTestSuite(testClass(), F_1_7);
32
}
30
}
33
public void _test001() {
31
public void test001() {
34
	this.runConformTest(
32
	this.runConformTest(
35
		new String[] {
33
		new String[] {
36
			"X.java",
34
			"X.java",
Lines 46-52 Link Here
46
		},
44
		},
47
		"SUCCESS");
45
		"SUCCESS");
48
}
46
}
49
public void _test001a() {
47
public void test001a() {
50
	this.runNegativeTest(
48
	this.runNegativeTest(
51
		new String[] {
49
		new String[] {
52
			"X.java",
50
			"X.java",
Lines 67-73 Link Here
67
		"The method testFunction(String) in the type X<String> is not applicable for the arguments (int)\n" + 
65
		"The method testFunction(String) in the type X<String> is not applicable for the arguments (int)\n" + 
68
		"----------\n");
66
		"----------\n");
69
}
67
}
70
public void _test001b() {
68
public void test001b() {
71
	this.runConformTest(
69
	this.runConformTest(
72
		new String[] {
70
		new String[] {
73
			"X.java",
71
			"X.java",
Lines 82-88 Link Here
82
		"SUCCESS");
80
		"SUCCESS");
83
}
81
}
84
// fields
82
// fields
85
public void _test001b_1() {
83
public void test001b_1() {
86
	this.runConformTest(
84
	this.runConformTest(
87
		new String[] {
85
		new String[] {
88
			"X.java",
86
			"X.java",
Lines 96-102 Link Here
96
		},
94
		},
97
		"SUCCESS");
95
		"SUCCESS");
98
}
96
}
99
public void _test001c() {
97
public void test001c() {
100
	this.runNegativeTest(
98
	this.runNegativeTest(
101
		new String[] {
99
		new String[] {
102
			"X.java",
100
			"X.java",
Lines 116-122 Link Here
116
		"----------\n");
114
		"----------\n");
117
}
115
}
118
// fields
116
// fields
119
public void _test001c_1() {
117
public void test001c_1() {
120
	this.runNegativeTest(
118
	this.runNegativeTest(
121
		new String[] {
119
		new String[] {
122
			"X.java",
120
			"X.java",
Lines 174-180 Link Here
174
		"The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Integer>)\n" + 
172
		"The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Integer>)\n" + 
175
		"----------\n");
173
		"----------\n");
176
}
174
}
177
public void _test001f() {
175
public void test001f() {
178
	this.runConformTest(
176
	this.runConformTest(
179
		new String[] {
177
		new String[] {
180
			"X.java",
178
			"X.java",
Lines 193-199 Link Here
193
		"SUCCESS");
191
		"SUCCESS");
194
}
192
}
195
// fields
193
// fields
196
public void _test001f_1() {
194
public void test001f_1() {
197
	this.runConformTest(
195
	this.runConformTest(
198
		new String[] {
196
		new String[] {
199
			"X.java",
197
			"X.java",
Lines 213-219 Link Here
213
		},
211
		},
214
		"SUCCESS");
212
		"SUCCESS");
215
}
213
}
216
public void _test001g() {
214
public void test001g() {
217
	this.runConformTest(
215
	this.runConformTest(
218
		new String[] {
216
		new String[] {
219
			"X.java",
217
			"X.java",
Lines 232-238 Link Here
232
		},
230
		},
233
		"SUCCESS\n1");
231
		"SUCCESS\n1");
234
}
232
}
235
public void _test001g_1() {
233
public void test001g_1() {
236
	this.runConformTest(
234
	this.runConformTest(
237
		new String[] {
235
		new String[] {
238
			"X.java",
236
			"X.java",
Lines 253-259 Link Here
253
		},
251
		},
254
		"SUCCESS\n1");
252
		"SUCCESS\n1");
255
}
253
}
256
public void _test001h() {
254
public void test001h() {
257
	this.runNegativeTest(
255
	this.runNegativeTest(
258
		new String[] {
256
		new String[] {
259
			"X.java",
257
			"X.java",
Lines 281-287 Link Here
281
		"The method methodx(String) in the type X<String>.X2<String> is not applicable for the arguments (int)\n" + 
279
		"The method methodx(String) in the type X<String>.X2<String> is not applicable for the arguments (int)\n" + 
282
		"----------\n");
280
		"----------\n");
283
}
281
}
284
public void _test001h_1() {
282
public void test001h_1() {
285
	this.runNegativeTest(
283
	this.runNegativeTest(
286
		new String[] {
284
		new String[] {
287
			"X.java",
285
			"X.java",
Lines 326-332 Link Here
326
		"Type safety: The method methodx(Object) belongs to the raw type X.X2. References to generic type X<T>.X2<T> should be parameterized\n" + 
324
		"Type safety: The method methodx(Object) belongs to the raw type X.X2. References to generic type X<T>.X2<T> should be parameterized\n" + 
327
		"----------\n");
325
		"----------\n");
328
}
326
}
329
public void _test001i() {
327
public void test001i() {
330
	this.runConformTest(
328
	this.runConformTest(
331
		new String[] {
329
		new String[] {
332
			"X.java",
330
			"X.java",
Lines 347-353 Link Here
347
		},
345
		},
348
		"SUCCESS");
346
		"SUCCESS");
349
}
347
}
350
public void _test002() {
348
public void test002() {
351
	this.runNegativeTest(
349
	this.runNegativeTest(
352
		new String[] {
350
		new String[] {
353
			"X.java",
351
			"X.java",
Lines 389-395 Link Here
389
		"SUCCESS");
387
		"SUCCESS");
390
}
388
}
391
389
392
public void _test004b() {
390
public void test004b() {
393
	this.runNegativeTest(
391
	this.runNegativeTest(
394
		new String[] {
392
		new String[] {
395
			"X.java",
393
			"X.java",
Lines 408-417 Link Here
408
		"1. ERROR in X.java (at line 5)\n" + 
406
		"1. ERROR in X.java (at line 5)\n" + 
409
		"	new X<>().new X2<>(){\n" + 
407
		"	new X<>().new X2<>(){\n" + 
410
		"	              ^^\n" + 
408
		"	              ^^\n" + 
411
		"Empty type argument list cannot be used in anonymous class declaration\n" + 
409
		"Incorrect number of arguments for type X<>.X2; it cannot be parameterized with arguments <>\n" + 
412
		"----------\n");
410
		"----------\n");
413
}
411
}
414
public void _test004c() {
412
public void test004c() {
415
	this.runConformTest(
413
	this.runConformTest(
416
		new String[] {
414
		new String[] {
417
			"X.java",
415
			"X.java",
Lines 434-440 Link Here
434
		"1");
432
		"1");
435
}
433
}
436
434
437
public void _test006() {
435
public void test006() {
438
	this.runConformTest(
436
	this.runConformTest(
439
		new String[] {
437
		new String[] {
440
			"X.java",
438
			"X.java",
Lines 530-588 Link Here
530
		"2");
528
		"2");
531
}
529
}
532
530
533
// To be activated if we introduce a warning to be raised when <> can be used but is not used.
531
public void test0014() {
534
public void _test012() {
535
	Map options = getCompilerOptions();
536
	//options.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR);
537
	this.runNegativeTest(
538
		new String[] {
539
			"X.java",
540
			"public class X<T> {\n" +
541
			"	X<String> f1 = new X<String>();\n" +
542
			"	public void foo() {\n" +
543
			"		X<Integer> i1 = new X<Integer>();\n" +
544
			"	}\n" +
545
			"}",
546
		},
547
		"----------\n" + 
548
		"1. ERROR in X.java (at line 2)\n" + 
549
		"	X<String> f1 = new X<String>();\n" + 
550
		"	               ^^^^^^^^^^^^^^^\n" + 
551
		"Redundant declaration of type arguments <String>\n" + 
552
		"----------\n" + 
553
		"2. ERROR in X.java (at line 4)\n" + 
554
		"	X<Integer> i1 = new X<Integer>();\n" + 
555
		"	                ^^^^^^^^^^^^^^^^\n" + 
556
		"Redundant declaration of type arguments <Integer>\n" + 
557
		"----------\n",
558
		null,
559
		true,
560
		options);
561
}
562
// To be activated if we introduce a warning to be raised when <> can be used but is not used.
563
public void _test013a() {
564
	Map options = getCompilerOptions();
565
	//options.put(CompilerOptions.OPTION_ReportRedundantDeclarationOfTypeArguments, CompilerOptions.ERROR);
566
	this.runConformTest(
567
		new String[] {
568
			"X.java",
569
			"public class X<T> {\n" +
570
			"	class Y<U>{}\n" +
571
			"	Y<String> f1 = new Y();\n" +
572
			"	public static void main(String[] args) {\n" +
573
			"		X<Integer> i1 = new X<>();\n" +
574
			"		System.out.println(\"SUCCESS\");\n" +
575
			"	}\n" +
576
			"}",
577
		},
578
		"SUCCESS",
579
		null,
580
		true,
581
		null,
582
		options,
583
		null);
584
}
585
public void _test0014() {
586
	this.runConformTest(
532
	this.runConformTest(
587
		new String[] {
533
		new String[] {
588
			"X.java",
534
			"X.java",
Lines 600-606 Link Here
600
		"SUCCESS\n" +
546
		"SUCCESS\n" +
601
		"123");
547
		"123");
602
}
548
}
603
public void _test0014a() {
549
public void test0014a() {
604
	this.runNegativeTest(
550
	this.runNegativeTest(
605
		new String[] {
551
		new String[] {
606
			"X.java",
552
			"X.java",
Lines 622-628 Link Here
622
		"The method testFunction(String, Integer) in the type X<String,Integer> is not applicable for the arguments (int, String)\n" + 
568
		"The method testFunction(String, Integer) in the type X<String,Integer> is not applicable for the arguments (int, String)\n" + 
623
		"----------\n");
569
		"----------\n");
624
}
570
}
625
public void _test0015() {
571
public void test0015() {
626
	this.runConformTest(
572
	this.runConformTest(
627
		new String[] {
573
		new String[] {
628
			"X.java",
574
			"X.java",
Lines 643-649 Link Here
643
}
589
}
644
// To verify that a parameterized invocation of a generic constructor works even if <> is used
590
// To verify that a parameterized invocation of a generic constructor works even if <> is used
645
// to elide class type parameters.
591
// to elide class type parameters.
646
public void _test0016() {
592
public void test0016() {
647
	this.runConformTest(
593
	this.runConformTest(
648
		new String[] {
594
		new String[] {
649
			"X.java",
595
			"X.java",
Lines 664-670 Link Here
664
}
610
}
665
// To verify that a parameterized invocation of a generic constructor works even if <> is used
611
// To verify that a parameterized invocation of a generic constructor works even if <> is used
666
// to elide class type parameters. This test handles fields
612
// to elide class type parameters. This test handles fields
667
public void _test0016b() {
613
public void test0016b() {
668
	this.runConformTest(
614
	this.runConformTest(
669
		new String[] {
615
		new String[] {
670
			"X.java",
616
			"X.java",
Lines 689-695 Link Here
689
// To verify that a parameterized invocation of a non-generic constructor works even if <> is used
635
// To verify that a parameterized invocation of a non-generic constructor works even if <> is used
690
// to elide class type parameters.
636
// to elide class type parameters.
691
// This was not allowed in java 1.6 and 1.5 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230)
637
// This was not allowed in java 1.6 and 1.5 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230)
692
public void _test0017() {
638
public void test0017() {
693
	this.runConformTest(
639
	this.runConformTest(
694
		new String[] {
640
		new String[] {
695
			"X.java",
641
			"X.java",
Lines 711-717 Link Here
711
		"const.1\nconst.1\nconst.2");
657
		"const.1\nconst.1\nconst.2");
712
}
658
}
713
// To verify that the correct constructor is found by parameter substitution in the diamond case
659
// To verify that the correct constructor is found by parameter substitution in the diamond case
714
public void _test0018() {
660
public void test0018() {
715
	this.runConformTest(
661
	this.runConformTest(
716
		new String[] {
662
		new String[] {
717
			"X.java",
663
			"X.java",
Lines 732-738 Link Here
732
}
678
}
733
// To verify that the correct constructor is found by parameter substitution 
679
// To verify that the correct constructor is found by parameter substitution 
734
// in the diamond case -- fields
680
// in the diamond case -- fields
735
public void _test0018b() {
681
public void test0018b() {
736
	this.runConformTest(
682
	this.runConformTest(
737
		new String[] {
683
		new String[] {
738
			"X.java",
684
			"X.java",

Return to bug 339478