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 (-16 / +159 lines)
Lines 17-28 Link Here
17
 *******************************************************************************/
17
 *******************************************************************************/
18
package org.eclipse.jdt.internal.compiler.ast;
18
package org.eclipse.jdt.internal.compiler.ast;
19
19
20
import org.eclipse.jdt.core.compiler.CharOperation;
20
import org.eclipse.jdt.internal.compiler.ASTVisitor;
21
import org.eclipse.jdt.internal.compiler.ASTVisitor;
21
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
22
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
22
import org.eclipse.jdt.internal.compiler.codegen.*;
23
import org.eclipse.jdt.internal.compiler.codegen.*;
23
import org.eclipse.jdt.internal.compiler.flow.*;
24
import org.eclipse.jdt.internal.compiler.flow.*;
24
import org.eclipse.jdt.internal.compiler.impl.Constant;
25
import org.eclipse.jdt.internal.compiler.impl.Constant;
25
import org.eclipse.jdt.internal.compiler.lookup.*;
26
import org.eclipse.jdt.internal.compiler.lookup.*;
27
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
26
28
27
public class AllocationExpression extends Expression implements InvocationSite {
29
public class AllocationExpression extends Expression implements InvocationSite {
28
30
Lines 260-270 Link Here
260
		// initialization of an enum constant
262
		// initialization of an enum constant
261
		this.resolvedType = scope.enclosingReceiverType();
263
		this.resolvedType = scope.enclosingReceiverType();
262
	} else {
264
	} else {
263
		if ((this.type.bits & ASTNode.IsDiamond) != 0) {
265
		this.resolvedType = this.type.resolveType(scope, true /* check bounds*/);
264
			this.resolvedType = null; // can be done only after type arguments and method arguments resolution.
265
		} else {
266
			this.resolvedType = this.type.resolveType(scope, true /* check bounds*/);
267
		}
268
		// check for parameterized allocation deferred to below.
266
		// check for parameterized allocation deferred to below.
269
	}
267
	}
270
	// will check for null after args are resolved
268
	// will check for null after args are resolved
Lines 338-346 Link Here
338
			return this.resolvedType;
336
			return this.resolvedType;
339
		}
337
		}
340
	}
338
	}
341
	if (this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0) {
339
	if (this.resolvedType == null || !this.resolvedType.isValidBinding()) {
342
		// Perform diamond inference here. (Not done yet.) 
340
		return null;
343
		this.resolvedType = this.type.resolveType(scope, true /* check bounds*/);  // for now just do what we do for 1.6-
341
	}
342
343
	// null type denotes fake allocation for enum constant inits
344
	if (this.type != null && !this.resolvedType.canBeInstantiated()) {
345
		scope.problemReporter().cannotInstantiate(this.type, this.resolvedType);
346
		return this.resolvedType;
347
	}
348
	if (this.type != null && this.resolvedType != null && (this.type.bits & ASTNode.IsDiamond) != 0) {
349
		TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) this.resolvedType).genericType(), argumentTypes, scope);
350
		this.resolvedType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) this.resolvedType).genericType(), inferredTypes, ((ParameterizedTypeBinding) this.resolvedType).enclosingType());
351
		// inject inferred args ??
344
	}
352
	}
345
	checkParameterizedAllocation: {
353
	checkParameterizedAllocation: {
346
		if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
354
		if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
Lines 360-374 Link Here
360
			}
368
			}
361
		}
369
		}
362
	}
370
	}
363
	if (this.resolvedType == null || !this.resolvedType.isValidBinding()) {
364
		return null;
365
	}
366
371
367
	// null type denotes fake allocation for enum constant inits
368
	if (this.type != null && !this.resolvedType.canBeInstantiated()) {
369
		scope.problemReporter().cannotInstantiate(this.type, this.resolvedType);
370
		return this.resolvedType;
371
	}
372
	ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType;
372
	ReferenceBinding allocationType = (ReferenceBinding) this.resolvedType;
373
	if (!(this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
373
	if (!(this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
374
		if (this.binding.declaringClass == null) {
374
		if (this.binding.declaringClass == null) {
Lines 394-399 Link Here
394
	return allocationType;
394
	return allocationType;
395
}
395
}
396
396
397
public TypeBinding[] inferElidedTypes(ReferenceBinding allocationType, TypeBinding[] argumentTypes, final BlockScope scope) {
398
	MethodBinding factory = getStaticFactory(allocationType, argumentTypes, scope);
399
	if (factory instanceof ParameterizedGenericMethodBinding) {
400
		return ((ParameterizedGenericMethodBinding) factory).typeArguments;
401
	}
402
	// Either inference failed or no inference was needed (exact match) ...
403
	int arity = allocationType.typeVariables().length;
404
	TypeBinding [] inferredTypes = new TypeBinding[arity];
405
	for (int i = 0; i < arity; i++) {
406
		inferredTypes[i] = new ProblemReferenceBinding(CharOperation.NO_CHAR_CHAR, null, ProblemReasons.InferenceFailed);
407
	}
408
	return inferredTypes;
409
}
410
411
private MethodBinding getStaticFactory (ReferenceBinding allocationType, TypeBinding[] argumentTypes, final BlockScope scope) {
412
	TypeVariableBinding[] classTypeVariables = allocationType.typeVariables();
413
	int classTypeVariablesArity = classTypeVariables.length;
414
	MethodBinding[] methods = allocationType.getMethods(TypeConstants.INIT, argumentTypes.length);
415
	MethodBinding [] staticFactories = new MethodBinding[methods.length];
416
	int sfi = 0;
417
	for (int i = 0, length = methods.length; i < length; i++) {
418
		MethodBinding method = methods[i];
419
		
420
//		if (method.parameters.length == argumentTypes.length) {
421
//			TypeBinding[] toMatch = method.parameters;
422
//			for (int iarg = 0, argCount = argumentTypes.length; iarg < argCount; iarg++) {
423
//				if (toMatch[iarg] != argumentTypes[iarg])
424
//					break;
425
//			}
426
//			// we have an exact match, no inference is called for ...
427
//			return method;
428
//		}
429
430
		TypeVariableBinding[] methodTypeVariables = method.typeVariables();
431
		int methodTypeVariablesArity = methodTypeVariables.length;
432
433
		if (this.genericTypeArguments != null && this.genericTypeArguments.length < methodTypeVariablesArity)
434
			continue; // wrong tree, don't bark.
435
		MethodBinding staticFactory = new MethodBinding(method.modifiers | ClassFileConstants.AccStatic, TypeConstants.SYNTHETIC_STATIC_FACTORY,
436
																	null, null, null, method.declaringClass);
437
		staticFactory.typeVariables = new TypeVariableBinding[classTypeVariablesArity + (this.genericTypeArguments == null ? methodTypeVariablesArity : 0)];
438
		final SimpleLookupTable map = new SimpleLookupTable(classTypeVariablesArity + methodTypeVariablesArity);
439
		// Rename each type variable T of the type to T'
440
		for (int j = 0; j < classTypeVariablesArity; j++) {
441
			map.put(classTypeVariables[j], staticFactory.typeVariables[j] = new TypeVariableBinding(CharOperation.concat(classTypeVariables[j].sourceName, "'".toCharArray()), //$NON-NLS-1$
442
																		staticFactory, j, scope.environment()));
443
		}
444
		// Rename each type variable U of method U to U'' if not explicitly parameterized. Otherwise use the parameterizing type.
445
		for (int j = classTypeVariablesArity, max = classTypeVariablesArity + methodTypeVariablesArity; j < max; j++) {
446
			map.put(methodTypeVariables[j - classTypeVariablesArity], 
447
					this.genericTypeArguments != null ? this.genericTypeArguments[j - classTypeVariablesArity] :
448
						(staticFactory.typeVariables[j] = new TypeVariableBinding(CharOperation.concat(methodTypeVariables[j - classTypeVariablesArity].sourceName, "''".toCharArray()), //$NON-NLS-1$
449
																		staticFactory, j, scope.environment())));
450
		}
451
		
452
		Substitution substitution = new Substitution() {
453
				public LookupEnvironment environment() {
454
					return scope.environment();
455
				}
456
				public boolean isRawSubstitution() {
457
					return false;
458
				}
459
				public TypeBinding substitute(TypeVariableBinding typeVariable) {
460
					return (TypeBinding) map.get(typeVariable);
461
				}
462
			};
463
464
		staticFactory.parameters = Scope.substitute(substitution, method.parameters);
465
		
466
		// initialize new variable bounds
467
		for (int j = 0, max = classTypeVariablesArity + methodTypeVariablesArity; j < max; j++) {
468
			TypeVariableBinding originalVariable = j < classTypeVariablesArity ? classTypeVariables[j] : methodTypeVariables[j - classTypeVariablesArity];
469
			TypeBinding substitutedType = (TypeBinding) map.get(originalVariable);
470
			if (substitutedType instanceof TypeVariableBinding) {
471
				TypeVariableBinding substitutedVariable = (TypeVariableBinding) substitutedType;
472
				TypeBinding substitutedSuperclass = Scope.substitute(substitution, originalVariable.superclass);
473
				ReferenceBinding[] substitutedInterfaces = Scope.substitute(substitution, originalVariable.superInterfaces);
474
				if (originalVariable.firstBound != null) {
475
					substitutedVariable.firstBound = originalVariable.firstBound == originalVariable.superclass
476
							? substitutedSuperclass // could be array type or interface
477
									: substitutedInterfaces[0];
478
				}
479
				switch (substitutedSuperclass.kind()) {
480
					case Binding.ARRAY_TYPE :
481
						substitutedVariable.superclass = scope.environment().getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null);
482
						substitutedVariable.superInterfaces = substitutedInterfaces;
483
						break;
484
					default:
485
						if (substitutedSuperclass.isInterface()) {
486
							substitutedVariable.superclass = scope.environment().getResolvedType(TypeConstants.JAVA_LANG_OBJECT, null);
487
							int interfaceCount = substitutedInterfaces.length;
488
							System.arraycopy(substitutedInterfaces, 0, substitutedInterfaces = new ReferenceBinding[interfaceCount+1], 1, interfaceCount);
489
							substitutedInterfaces[0] = (ReferenceBinding) substitutedSuperclass;
490
							substitutedVariable.superInterfaces = substitutedInterfaces;
491
						} else {
492
							substitutedVariable.superclass = (ReferenceBinding) substitutedSuperclass; // typeVar was extending other typeVar which got substituted with interface
493
							substitutedVariable.superInterfaces = substitutedInterfaces;
494
						}
495
				}
496
			}
497
		}
498
	    TypeVariableBinding[] returnTypeParameters = new TypeVariableBinding[classTypeVariablesArity];
499
		for (int j = 0; j < classTypeVariablesArity; j++) {
500
			returnTypeParameters[j] = (TypeVariableBinding) map.get(classTypeVariables[j]);
501
		}
502
		staticFactory.returnType = scope.environment().createParameterizedType(allocationType, returnTypeParameters, allocationType.enclosingType());
503
		staticFactory.thrownExceptions = Scope.substitute(substitution, method.thrownExceptions);
504
		if (staticFactory.thrownExceptions == null) { 
505
			staticFactory.thrownExceptions = Binding.NO_EXCEPTIONS;
506
		}
507
		ParameterizedMethodBinding aFactory = new ParameterizedMethodBinding((ParameterizedTypeBinding) scope.environment().convertToParameterizedType(staticFactory.declaringClass),
508
																													staticFactory);
509
		staticFactories[sfi++] = aFactory; 
510
	}
511
	if (sfi != methods.length) {
512
		System.arraycopy(staticFactories, 0, staticFactories = new MethodBinding[sfi], 0, sfi);
513
	}
514
	MethodBinding[] compatible = new MethodBinding[sfi];
515
	int compatibleIndex = 0;
516
	for (int i = 0; i < sfi; i++) {
517
		MethodBinding compatibleMethod = scope.computeCompatibleMethod(staticFactories[i], argumentTypes, this);
518
		if (compatibleMethod != null) {
519
			if (compatibleMethod.isValidBinding())
520
				compatible[compatibleIndex++] = compatibleMethod;
521
		}
522
	}
523
524
	if (compatibleIndex == 0) {
525
		return null;
526
	}
527
	MethodBinding[] visible = new MethodBinding[compatibleIndex];
528
	int visibleIndex = 0;
529
	for (int i = 0; i < compatibleIndex; i++) {
530
		MethodBinding method = compatible[i];
531
		if (method.canBeSeenBy(this, scope))
532
			visible[visibleIndex++] = method;
533
	}
534
	if (visibleIndex == 0) {
535
		return null;
536
	}
537
	return visibleIndex == 1 ? visible[0] : scope.mostSpecificMethodBinding(visible, visibleIndex, argumentTypes, this, allocationType);
538
}
539
397
public void setActualReceiverType(ReferenceBinding receiverType) {
540
public void setActualReceiverType(ReferenceBinding receiverType) {
398
	// ignored
541
	// ignored
399
}
542
}
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedQualifiedTypeReference.java (-1 / +1 lines)
Lines 268-274 Link Here
268
				// check argument type compatibility
268
				// check argument type compatibility
269
				if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
269
				if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
270
					parameterizedType.boundCheck(scope, args);
270
					parameterizedType.boundCheck(scope, args);
271
				else
271
				else if (!isDiamond)
272
					scope.deferBoundCheck(this);
272
					scope.deferBoundCheck(this);
273
				qualifyingType = parameterizedType;
273
				qualifyingType = parameterizedType;
274
		    } else {
274
		    } else {
(-)compiler/org/eclipse/jdt/internal/compiler/ast/ParameterizedSingleTypeReference.java (-1 / +1 lines)
Lines 245-251 Link Here
245
		// check argument type compatibility
245
		// check argument type compatibility
246
		if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
246
		if (checkBounds) // otherwise will do it in Scope.connectTypeVariables() or generic method resolution
247
			parameterizedType.boundCheck(scope, this.typeArguments);
247
			parameterizedType.boundCheck(scope, this.typeArguments);
248
		else
248
		else if ((this.bits & ASTNode.IsDiamond) == 0)
249
			scope.deferBoundCheck(this);
249
			scope.deferBoundCheck(this);
250
		if (isTypeUseDeprecated(parameterizedType, scope))
250
		if (isTypeUseDeprecated(parameterizedType, scope))
251
			reportDeprecatedType(parameterizedType, scope);
251
			reportDeprecatedType(parameterizedType, scope);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java (-30 / +26 lines)
Lines 27-32 Link Here
27
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
27
import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers;
28
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
28
import org.eclipse.jdt.internal.compiler.lookup.LocalTypeBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
29
import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding;
30
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.ProblemMethodBinding;
31
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
32
import org.eclipse.jdt.internal.compiler.lookup.ProblemReasons;
32
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
33
import org.eclipse.jdt.internal.compiler.lookup.ProblemReferenceBinding;
Lines 275-288 Link Here
275
				// initialization of an enum constant
276
				// initialization of an enum constant
276
				receiverType = scope.enclosingSourceType();
277
				receiverType = scope.enclosingSourceType();
277
			} else {
278
			} else {
278
				if ((this.type.bits & ASTNode.IsDiamond) == 0) {
279
				receiverType = this.type.resolveType(scope, true /* check bounds*/);
279
					receiverType = this.type.resolveType(scope, true /* check bounds*/);
280
				checkParameterizedAllocation: {
280
				} else {
281
					if (receiverType == null || !receiverType.isValidBinding()) break checkParameterizedAllocation;
281
					// can be done only after type arguments and method arguments resolution
282
					if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
283
						ReferenceBinding currentType = (ReferenceBinding)receiverType;
284
						do {
285
							// isStatic() is answering true for toplevel types
286
							if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
287
							if (currentType.isRawType()) break checkParameterizedAllocation;
288
						} while ((currentType = currentType.enclosingType())!= null);
289
						ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
290
						for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
291
							if (qRef.typeArguments[i] != null) {
292
								scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, receiverType);
293
								break;
294
							}
295
						}
296
					}
282
				}
297
				}
283
				// check for parameterized allocation deferred to below.
284
			}
298
			}
285
		}
299
		}
300
		if (receiverType == null || !receiverType.isValidBinding()) {
301
			hasError = true;
302
		}
286
303
287
		// resolve type arguments (for generic constructor call)
304
		// resolve type arguments (for generic constructor call)
288
		if (this.typeArguments != null) {
305
		if (this.typeArguments != null) {
Lines 324-354 Link Here
324
				}
341
				}
325
			}
342
			}
326
		}
343
		}
327
		if (this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0) {
328
			// Perform diamond inference here. (Not done yet.)
329
			receiverType = this.type.resolveType(scope, true /* check bounds*/); // for now just do what we do for 1.6-
330
		}	
331
		checkParameterizedAllocation: {
332
			if (receiverType == null || !receiverType.isValidBinding()) break checkParameterizedAllocation;
333
			if (this.type instanceof ParameterizedQualifiedTypeReference) { // disallow new X<String>.Y<Integer>()
334
				ReferenceBinding currentType = (ReferenceBinding)receiverType;
335
				do {
336
					// isStatic() is answering true for toplevel types
337
					if ((currentType.modifiers & ClassFileConstants.AccStatic) != 0) break checkParameterizedAllocation;
338
					if (currentType.isRawType()) break checkParameterizedAllocation;
339
				} while ((currentType = currentType.enclosingType())!= null);
340
				ParameterizedQualifiedTypeReference qRef = (ParameterizedQualifiedTypeReference) this.type;
341
				for (int i = qRef.typeArguments.length - 2; i >= 0; i--) {
342
					if (qRef.typeArguments[i] != null) {
343
						scope.problemReporter().illegalQualifiedParameterizedTypeAllocation(this.type, receiverType);
344
						break;
345
					}
346
				}
347
			}
348
		}
349
		if (receiverType == null || !receiverType.isValidBinding()) {
350
			hasError = true;
351
		}
352
344
353
		// limit of fault-tolerance
345
		// limit of fault-tolerance
354
		if (hasError) {
346
		if (hasError) {
Lines 394-399 Link Here
394
				scope.problemReporter().cannotInstantiate(this.type, receiverType);
386
				scope.problemReporter().cannotInstantiate(this.type, receiverType);
395
				return this.resolvedType = receiverType;
387
				return this.resolvedType = receiverType;
396
			}
388
			}
389
			if (this.type != null && (this.type.bits & ASTNode.IsDiamond) != 0) {
390
				TypeBinding [] inferredTypes = inferElidedTypes(((ParameterizedTypeBinding) receiverType).genericType(), argumentTypes, scope);
391
				receiverType = this.type.resolvedType = scope.environment().createParameterizedType(((ParameterizedTypeBinding) receiverType).genericType(), inferredTypes, ((ParameterizedTypeBinding) receiverType).enclosingType());
392
			}
397
			ReferenceBinding allocationType = (ReferenceBinding) receiverType;
393
			ReferenceBinding allocationType = (ReferenceBinding) receiverType;
398
			if ((this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
394
			if ((this.binding = scope.getConstructor(allocationType, argumentTypes, this)).isValidBinding()) {
399
				if (isMethodUseDeprecated(this.binding, scope, true)) {
395
				if (isMethodUseDeprecated(this.binding, scope, true)) {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemReasons.java (+1 lines)
Lines 31-34 Link Here
31
	final int TypeArgumentsForRawGenericMethod = 13; // for generic method
31
	final int TypeArgumentsForRawGenericMethod = 13; // for generic method
32
	final int InvalidTypeForStaticImport = 14;
32
	final int InvalidTypeForStaticImport = 14;
33
	final int InvalidTypeForAutoManagedResource = 15;
33
	final int InvalidTypeForAutoManagedResource = 15;
34
	final int InferenceFailed = 16;
34
}
35
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-2 / +2 lines)
Lines 511-517 Link Here
511
	 * Will answer a substituted method in case the method was generic and type inference got triggered;
511
	 * Will answer a substituted method in case the method was generic and type inference got triggered;
512
	 * in case the method was originally compatible, then simply answer it back.
512
	 * in case the method was originally compatible, then simply answer it back.
513
	 */
513
	 */
514
	protected final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments, InvocationSite invocationSite) {
514
	public final MethodBinding computeCompatibleMethod(MethodBinding method, TypeBinding[] arguments, InvocationSite invocationSite) {
515
		TypeBinding[] genericTypeArguments = invocationSite.genericTypeArguments();
515
		TypeBinding[] genericTypeArguments = invocationSite.genericTypeArguments();
516
		TypeBinding[] parameters = method.parameters;
516
		TypeBinding[] parameters = method.parameters;
517
		TypeVariableBinding[] typeVariables = method.typeVariables;
517
		TypeVariableBinding[] typeVariables = method.typeVariables;
Lines 3686-3692 Link Here
3686
	}
3686
	}
3687
3687
3688
	// caveat: this is not a direct implementation of JLS
3688
	// caveat: this is not a direct implementation of JLS
3689
	protected final MethodBinding mostSpecificMethodBinding(MethodBinding[] visible, int visibleSize, TypeBinding[] argumentTypes, final InvocationSite invocationSite, ReferenceBinding receiverType) {
3689
	public final MethodBinding mostSpecificMethodBinding(MethodBinding[] visible, int visibleSize, TypeBinding[] argumentTypes, final InvocationSite invocationSite, ReferenceBinding receiverType) {
3690
		int[] compatibilityLevels = new int[visibleSize];
3690
		int[] compatibilityLevels = new int[visibleSize];
3691
		for (int i = 0; i < visibleSize; i++)
3691
		for (int i = 0; i < visibleSize; i++)
3692
			compatibilityLevels[i] = parameterCompatibilityLevel(visible[i], argumentTypes);
3692
			compatibilityLevels[i] = parameterCompatibilityLevel(visible[i], argumentTypes);
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java (+1 lines)
Lines 170-175 Link Here
170
	char[] SYNTHETIC_ENCLOSING_INSTANCE_PREFIX = "this$".toCharArray(); //$NON-NLS-1$
170
	char[] SYNTHETIC_ENCLOSING_INSTANCE_PREFIX = "this$".toCharArray(); //$NON-NLS-1$
171
	char[] SYNTHETIC_ACCESS_METHOD_PREFIX =  "access$".toCharArray(); //$NON-NLS-1$
171
	char[] SYNTHETIC_ACCESS_METHOD_PREFIX =  "access$".toCharArray(); //$NON-NLS-1$
172
	char[] SYNTHETIC_ENUM_CONSTANT_INITIALIZATION_METHOD_PREFIX =  " enum constant initialization$".toCharArray(); //$NON-NLS-1$
172
	char[] SYNTHETIC_ENUM_CONSTANT_INITIALIZATION_METHOD_PREFIX =  " enum constant initialization$".toCharArray(); //$NON-NLS-1$
173
	char[] SYNTHETIC_STATIC_FACTORY =  "<factory>".toCharArray(); //$NON-NLS-1$
173
174
174
	// synthetic package-info name
175
	// synthetic package-info name
175
	public static final char[] PACKAGE_INFO_NAME = "package-info".toCharArray(); //$NON-NLS-1$
176
	public static final char[] PACKAGE_INFO_NAME = "package-info".toCharArray(); //$NON-NLS-1$
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_1_7.java (-40 / +85 lines)
Lines 18-24 Link Here
18
public class GenericsRegressionTest_1_7 extends AbstractRegressionTest {
18
public class GenericsRegressionTest_1_7 extends AbstractRegressionTest {
19
19
20
static {
20
static {
21
//	TESTS_NAMES = new String[] { "test0014" };
21
//	TESTS_NAMES = new String[] { "test001f" };
22
//	TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 };
22
//	TESTS_NUMBERS = new int[] { 40, 41, 43, 45, 63, 64 };
23
//	TESTS_RANGE = new int[] { 11, -1 };
23
//	TESTS_RANGE = new int[] { 11, -1 };
24
}
24
}
Lines 28-34 Link Here
28
public static Test suite() {
28
public static Test suite() {
29
	return buildMinimalComplianceTestSuite(testClass(), F_1_7);
29
	return buildMinimalComplianceTestSuite(testClass(), F_1_7);
30
}
30
}
31
public void _test001() {
31
public void test001() {
32
	this.runConformTest(
32
	this.runConformTest(
33
		new String[] {
33
		new String[] {
34
			"X.java",
34
			"X.java",
Lines 44-50 Link Here
44
		},
44
		},
45
		"SUCCESS");
45
		"SUCCESS");
46
}
46
}
47
public void _test001a() {
47
public void test001a() {
48
	this.runNegativeTest(
48
	this.runNegativeTest(
49
		new String[] {
49
		new String[] {
50
			"X.java",
50
			"X.java",
Lines 65-71 Link Here
65
		"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" + 
66
		"----------\n");
66
		"----------\n");
67
}
67
}
68
public void _test001b() {
68
public void test001b() {
69
	this.runConformTest(
69
	this.runConformTest(
70
		new String[] {
70
		new String[] {
71
			"X.java",
71
			"X.java",
Lines 80-86 Link Here
80
		"SUCCESS");
80
		"SUCCESS");
81
}
81
}
82
// fields
82
// fields
83
public void _test001b_1() {
83
public void test001b_1() {
84
	this.runConformTest(
84
	this.runConformTest(
85
		new String[] {
85
		new String[] {
86
			"X.java",
86
			"X.java",
Lines 94-100 Link Here
94
		},
94
		},
95
		"SUCCESS");
95
		"SUCCESS");
96
}
96
}
97
public void _test001c() {
97
public void test001c() {
98
	this.runNegativeTest(
98
	this.runNegativeTest(
99
		new String[] {
99
		new String[] {
100
			"X.java",
100
			"X.java",
Lines 114-120 Link Here
114
		"----------\n");
114
		"----------\n");
115
}
115
}
116
// fields
116
// fields
117
public void _test001c_1() {
117
public void test001c_1() {
118
	this.runNegativeTest(
118
	this.runNegativeTest(
119
		new String[] {
119
		new String[] {
120
			"X.java",
120
			"X.java",
Lines 133-139 Link Here
133
		"The method add(int, String) in the type ArrayList<String> is not applicable for the arguments (int)\n" + 
133
		"The method add(int, String) in the type ArrayList<String> is not applicable for the arguments (int)\n" + 
134
		"----------\n");
134
		"----------\n");
135
}
135
}
136
public void _test001d() {
136
public void test001d() {
137
	this.runNegativeTest(
137
	this.runNegativeTest(
138
		new String[] {
138
		new String[] {
139
			"X.java",
139
			"X.java",
Lines 155-161 Link Here
155
		"The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Object>)\n" + 
155
		"The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Object>)\n" + 
156
		"----------\n");
156
		"----------\n");
157
}
157
}
158
public void _test001e() {
158
public void test001e() {
159
	this.runNegativeTest(
159
	this.runNegativeTest(
160
		new String[] {
160
		new String[] {
161
			"X.java",
161
			"X.java",
Lines 177-184 Link Here
177
		"The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Object>)\n" + 
177
		"The method ab(ArrayList<String>) in the type X<String> is not applicable for the arguments (ArrayList<Object>)\n" + 
178
		"----------\n");
178
		"----------\n");
179
}
179
}
180
public void _test001f() {
180
public void test001f() {
181
	this.runConformTest(
181
	this.runNegativeTest(
182
		new String[] {
182
		new String[] {
183
			"X.java",
183
			"X.java",
184
			"public class X<T> {\n" +
184
			"public class X<T> {\n" +
Lines 193-199 Link Here
193
			"	}\n" +
193
			"	}\n" +
194
			"}",
194
			"}",
195
		},
195
		},
196
		"SUCCESS");
196
		"----------\n" + 
197
		"1. WARNING in X.java (at line 2)\n" + 
198
		"	class X2<T>{\n" + 
199
		"	         ^\n" + 
200
		"The type parameter T is hiding the type T\n" + 
201
		"----------\n" + 
202
		"2. ERROR in X.java (at line 8)\n" + 
203
		"	X<String>.X2<String> x = new X<>().new X2<>();\n" + 
204
		"	                         ^^^^^^^^^^^^^^^^^^^^\n" + 
205
		"Type mismatch: cannot convert from X<Object>.X2<String> to X<String>.X2<String>\n" + 
206
		"----------\n");
197
}
207
}
198
// fields
208
// fields
199
public void test001f_1() {
209
public void test001f_1() {
Lines 216-223 Link Here
216
		},
226
		},
217
		"SUCCESS");
227
		"SUCCESS");
218
}
228
}
219
public void _test001g() {
229
public void test001g() {
220
	this.runConformTest(
230
	this.runNegativeTest(
221
		new String[] {
231
		new String[] {
222
			"X.java",
232
			"X.java",
223
			"public class X<T> {\n" +
233
			"public class X<T> {\n" +
Lines 233-239 Link Here
233
			"	}\n" +
243
			"	}\n" +
234
			"}",
244
			"}",
235
		},
245
		},
236
		"SUCCESS\n1");
246
		"----------\n" + 
247
		"1. ERROR in X.java (at line 9)\n" + 
248
		"	X<String>.X2<Integer> x = new X<>().new X2<>();\n" + 
249
		"	                          ^^^^^^^^^^^^^^^^^^^^\n" + 
250
		"Type mismatch: cannot convert from X<Object>.X2<Integer> to X<String>.X2<Integer>\n" + 
251
		"----------\n");
237
}
252
}
238
public void test001g_1() {
253
public void test001g_1() {
239
	this.runConformTest(
254
	this.runConformTest(
Lines 256-262 Link Here
256
		},
271
		},
257
		"SUCCESS\n1");
272
		"SUCCESS\n1");
258
}
273
}
259
public void _test001h() {
274
public void test001h() {
260
	this.runNegativeTest(
275
	this.runNegativeTest(
261
		new String[] {
276
		new String[] {
262
			"X.java",
277
			"X.java",
Lines 278-290 Link Here
278
		"	         ^\n" + 
293
		"	         ^\n" + 
279
		"The type parameter T is hiding the type T\n" + 
294
		"The type parameter T is hiding the type T\n" + 
280
		"----------\n" + 
295
		"----------\n" + 
281
		"2. ERROR in X.java (at line 9)\n" + 
296
		"2. ERROR in X.java (at line 8)\n" + 
297
		"	X<String>.X2<String> x = new X<>().new X2<>();\n" + 
298
		"	                         ^^^^^^^^^^^^^^^^^^^^\n" + 
299
		"Type mismatch: cannot convert from X<Object>.X2<String> to X<String>.X2<String>\n" + 
300
		"----------\n" + 
301
		"3. ERROR in X.java (at line 9)\n" + 
282
		"	x.methodx(1);\n" + 
302
		"	x.methodx(1);\n" + 
283
		"	  ^^^^^^^\n" + 
303
		"	  ^^^^^^^\n" + 
284
		"The method methodx(String) in the type X<String>.X2<String> is not applicable for the arguments (int)\n" + 
304
		"The method methodx(String) in the type X<String>.X2<String> is not applicable for the arguments (int)\n" + 
285
		"----------\n");
305
		"----------\n");
286
}
306
}
287
public void _test001h_1() {
307
public void test001h_1() {
288
	this.runNegativeTest(
308
	this.runNegativeTest(
289
		new String[] {
309
		new String[] {
290
			"X.java",
310
			"X.java",
Lines 329-336 Link Here
329
		"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" + 
349
		"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" + 
330
		"----------\n");
350
		"----------\n");
331
}
351
}
332
public void _test001i() {
352
public void test001i() {
333
	this.runConformTest(
353
	this.runNegativeTest(
334
		new String[] {
354
		new String[] {
335
			"X.java",
355
			"X.java",
336
			"public class X<T> {\n" +
356
			"public class X<T> {\n" +
Lines 348-354 Link Here
348
			"	}\n" +
368
			"	}\n" +
349
			"}",
369
			"}",
350
		},
370
		},
351
		"SUCCESS");
371
		"----------\n" + 
372
		"1. ERROR in X.java (at line 10)\n" + 
373
		"	X<String> test = new X<>();		X<String>.X2<Integer>.X22<X<String>> x = new X<>().new X2<>().new X22<>();\n" + 
374
		"	                           		                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
375
		"Type mismatch: cannot convert from X<Object>.X2<Object>.X22<X<String>> to X<String>.X2<Integer>.X22<X<String>>\n" + 
376
		"----------\n");
352
}
377
}
353
public void test002() {
378
public void test002() {
354
	this.runNegativeTest(
379
	this.runNegativeTest(
Lines 376-382 Link Here
376
		"Type safety: The method testFunction(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + 
401
		"Type safety: The method testFunction(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + 
377
		"----------\n");
402
		"----------\n");
378
}
403
}
379
public void _test003() {
404
public void test003() {
380
	this.runConformTest(
405
	this.runConformTest(
381
		new String[] {
406
		new String[] {
382
			"X.java",
407
			"X.java",
Lines 392-398 Link Here
392
		"SUCCESS");
417
		"SUCCESS");
393
}
418
}
394
419
395
public void _test004b() {
420
public void test004b() {
396
	this.runNegativeTest(
421
	this.runNegativeTest(
397
		new String[] {
422
		new String[] {
398
			"X.java",
423
			"X.java",
Lines 437-443 Link Here
437
		"1");
462
		"1");
438
}
463
}
439
464
440
public void _test006() {
465
public void test006() {
441
	this.runConformTest(
466
	this.runConformTest(
442
		new String[] {
467
		new String[] {
443
			"X.java",
468
			"X.java",
Lines 460-466 Link Here
460
		"SUCCESS");
485
		"SUCCESS");
461
}
486
}
462
// shows the difference between using <> and the raw type - different semantics
487
// shows the difference between using <> and the raw type - different semantics
463
public void _test007() {
488
public void test007() {
464
	this.runConformTest(
489
	this.runConformTest(
465
		new String[] {
490
		new String[] {
466
			"X.java",
491
			"X.java",
Lines 487-493 Link Here
487
		"1\n" + 
512
		"1\n" + 
488
		"2");
513
		"2");
489
}
514
}
490
public void _test007a() {
515
public void test007a() {
491
	this.runNegativeTest(
516
	this.runNegativeTest(
492
		new String[] {
517
		new String[] {
493
			"X.java",
518
			"X.java",
Lines 529-540 Link Here
529
		"----------\n");
554
		"----------\n");
530
}
555
}
531
//shows the difference between using <> and the raw type - different semantics
556
//shows the difference between using <> and the raw type - different semantics
532
public void _test008() {
557
public void test008() {
533
	this.runConformTest(
558
	this.runNegativeTest(
534
		new String[] {
559
		new String[] {
535
			"X.java",
560
			"X.java",
536
			"public class X<T> {\n" +
561
			"public class X<T> {\n" +
537
			"	T field1;" +
562
			"	T field1;\n" +
538
			"	public X(T param){\n" +
563
			"	public X(T param){\n" +
539
			"		field1 = param;\n" +
564
			"		field1 = param;\n" +
540
			"	}\n" +
565
			"	}\n" +
Lines 547-556 Link Here
547
			"	}\n" + 
572
			"	}\n" + 
548
			"}",
573
			"}",
549
		},
574
		},
550
		"");
575
		"----------\n" + 
576
		"1. WARNING in X.java (at line 7)\n" + 
577
		"	X<?> x1 = new X(1).get(\"\");\n" + 
578
		"	          ^^^^^^^^\n" + 
579
		"Type safety: The constructor X(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + 
580
		"----------\n" + 
581
		"2. WARNING in X.java (at line 7)\n" + 
582
		"	X<?> x1 = new X(1).get(\"\");\n" + 
583
		"	          ^^^^^^^^^^^^^^^^\n" + 
584
		"Type safety: The method get(Object) belongs to the raw type X. References to generic type X<T> should be parameterized\n" + 
585
		"----------\n" + 
586
		"3. WARNING in X.java (at line 7)\n" + 
587
		"	X<?> x1 = new X(1).get(\"\");\n" + 
588
		"	              ^\n" + 
589
		"X is a raw type. References to generic type X<T> should be parameterized\n" + 
590
		"----------\n" + 
591
		"4. ERROR in X.java (at line 8)\n" + 
592
		"	X<?> x2 = new X<>(1).get(\"\");\n" + 
593
		"	                     ^^^\n" + 
594
		"The method get(Integer) in the type X<Integer> is not applicable for the arguments (String)\n" + 
595
		"----------\n");
551
}
596
}
552
597
553
public void _test0014() {
598
public void test0014() {
554
	this.runConformTest(
599
	this.runConformTest(
555
		new String[] {
600
		new String[] {
556
			"X.java",
601
			"X.java",
Lines 568-574 Link Here
568
		"SUCCESS\n" +
613
		"SUCCESS\n" +
569
		"123");
614
		"123");
570
}
615
}
571
public void _test0014a() {
616
public void test0014a() {
572
	this.runNegativeTest(
617
	this.runNegativeTest(
573
		new String[] {
618
		new String[] {
574
			"X.java",
619
			"X.java",
Lines 590-596 Link Here
590
		"The method testFunction(String, Integer) in the type X<String,Integer> is not applicable for the arguments (int, String)\n" + 
635
		"The method testFunction(String, Integer) in the type X<String,Integer> is not applicable for the arguments (int, String)\n" + 
591
		"----------\n");
636
		"----------\n");
592
}
637
}
593
public void _test0015() {
638
public void test0015() {
594
	this.runConformTest(
639
	this.runConformTest(
595
		new String[] {
640
		new String[] {
596
			"X.java",
641
			"X.java",
Lines 611-617 Link Here
611
}
656
}
612
// To verify that a parameterized invocation of a generic constructor works even if <> is used
657
// To verify that a parameterized invocation of a generic constructor works even if <> is used
613
// to elide class type parameters.
658
// to elide class type parameters.
614
public void _test0016() {
659
public void test0016() {
615
	this.runConformTest(
660
	this.runConformTest(
616
		new String[] {
661
		new String[] {
617
			"X.java",
662
			"X.java",
Lines 632-638 Link Here
632
}
677
}
633
// To verify that a parameterized invocation of a generic constructor works even if <> is used
678
// To verify that a parameterized invocation of a generic constructor works even if <> is used
634
// to elide class type parameters. This test handles fields
679
// to elide class type parameters. This test handles fields
635
public void _test0016b() {
680
public void test0016b() {
636
	this.runConformTest(
681
	this.runConformTest(
637
		new String[] {
682
		new String[] {
638
			"X.java",
683
			"X.java",
Lines 657-663 Link Here
657
// To verify that a parameterized invocation of a non-generic constructor works even if <> is used
702
// To verify that a parameterized invocation of a non-generic constructor works even if <> is used
658
// to elide class type parameters.
703
// to elide class type parameters.
659
// This was not allowed in java 1.6 and 1.5 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230)
704
// This was not allowed in java 1.6 and 1.5 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=168230)
660
public void _test0017() {
705
public void test0017() {
661
	this.runConformTest(
706
	this.runConformTest(
662
		new String[] {
707
		new String[] {
663
			"X.java",
708
			"X.java",
Lines 679-685 Link Here
679
		"const.1\nconst.1\nconst.2");
724
		"const.1\nconst.1\nconst.2");
680
}
725
}
681
// To verify that the correct constructor is found by parameter substitution in the diamond case
726
// To verify that the correct constructor is found by parameter substitution in the diamond case
682
public void _test0018() {
727
public void test0018() {
683
	this.runConformTest(
728
	this.runConformTest(
684
		new String[] {
729
		new String[] {
685
			"X.java",
730
			"X.java",
Lines 700-706 Link Here
700
}
745
}
701
// To verify that the correct constructor is found by parameter substitution 
746
// To verify that the correct constructor is found by parameter substitution 
702
// in the diamond case -- fields
747
// in the diamond case -- fields
703
public void _test0018b() {
748
public void test0018b() {
704
	this.runConformTest(
749
	this.runConformTest(
705
		new String[] {
750
		new String[] {
706
			"X.java",
751
			"X.java",
Lines 738-744 Link Here
738
		"----------\n");
783
		"----------\n");
739
}
784
}
740
// check inference at method argument position.
785
// check inference at method argument position.
741
public void _test0020() {
786
public void test0020() {
742
	this.runNegativeTest(
787
	this.runNegativeTest(
743
		new String[] {
788
		new String[] {
744
			"X.java",
789
			"X.java",
Lines 757-763 Link Here
757
		"----------\n");
802
		"----------\n");
758
}
803
}
759
//check inference at method argument position.
804
//check inference at method argument position.
760
public void _test0021() {
805
public void test0021() {
761
	this.runNegativeTest(
806
	this.runNegativeTest(
762
		new String[] {
807
		new String[] {
763
			"X.java",
808
			"X.java",

Return to bug 339478