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

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java (-11 / +18 lines)
Lines 11-17 Link Here
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
12
13
import java.util.HashMap;
13
import java.util.HashMap;
14
import java.util.HashSet;
14
import java.util.Map;
15
import java.util.Map;
16
import java.util.Set;
15
17
16
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.internal.compiler.ClassFilePool;
19
import org.eclipse.jdt.internal.compiler.ClassFilePool;
Lines 415-427 Link Here
415
	return originalType;
417
	return originalType;
416
}
418
}
417
419
418
public TypeBinding convertEliminatingTypeVariables(TypeBinding originalType, ReferenceBinding genericType, int rank, TypeVariableBinding eliminatedVariable) {
420
public TypeBinding convertEliminatingTypeVariables(TypeBinding originalType, ReferenceBinding genericType, int rank, Set eliminatedVariables) {
419
	if ((originalType.tagBits & TagBits.HasTypeVariable) != 0) {
421
	if ((originalType.tagBits & TagBits.HasTypeVariable) != 0) {
420
		switch (originalType.kind()) {
422
		switch (originalType.kind()) {
421
			case Binding.ARRAY_TYPE :
423
			case Binding.ARRAY_TYPE :
422
				ArrayBinding originalArrayType = (ArrayBinding) originalType;
424
				ArrayBinding originalArrayType = (ArrayBinding) originalType;
423
				TypeBinding originalLeafComponentType = originalArrayType.leafComponentType;
425
				TypeBinding originalLeafComponentType = originalArrayType.leafComponentType;
424
				TypeBinding substitute = convertEliminatingTypeVariables(originalLeafComponentType, genericType, rank, eliminatedVariable); // substitute could itself be array type
426
				TypeBinding substitute = convertEliminatingTypeVariables(originalLeafComponentType, genericType, rank, eliminatedVariables); // substitute could itself be array type
425
				if (substitute != originalLeafComponentType) {
427
				if (substitute != originalLeafComponentType) {
426
					return createArrayType(substitute.leafComponentType(), substitute.dimensions() + originalArrayType.dimensions());
428
					return createArrayType(substitute.leafComponentType(), substitute.dimensions() + originalArrayType.dimensions());
427
				}
429
				}
Lines 431-443 Link Here
431
				ReferenceBinding originalEnclosing = paramType.enclosingType();
433
				ReferenceBinding originalEnclosing = paramType.enclosingType();
432
				ReferenceBinding substitutedEnclosing = originalEnclosing;
434
				ReferenceBinding substitutedEnclosing = originalEnclosing;
433
				if (originalEnclosing != null) {
435
				if (originalEnclosing != null) {
434
					substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariable);
436
					substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariables);
435
				}
437
				}
436
				TypeBinding[] originalArguments = paramType.arguments;
438
				TypeBinding[] originalArguments = paramType.arguments;
437
				TypeBinding[] substitutedArguments = originalArguments;
439
				TypeBinding[] substitutedArguments = originalArguments;
438
				for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) {
440
				for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) {
439
					TypeBinding originalArgument = originalArguments[i];
441
					TypeBinding originalArgument = originalArguments[i];
440
					TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, paramType.genericType(), i, eliminatedVariable);
442
					TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, paramType.genericType(), i, eliminatedVariables);
441
					if (substitutedArgument != originalArgument) {
443
					if (substitutedArgument != originalArgument) {
442
						if (substitutedArguments == originalArguments) {
444
						if (substitutedArguments == originalArguments) {
443
							System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i);
445
							System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i);
Lines 452-463 Link Here
452
				}
454
				}
453
				break;
455
				break;
454
			case Binding.TYPE_PARAMETER :
456
			case Binding.TYPE_PARAMETER :
455
				if (eliminatedVariable == originalType) {
457
				if (eliminatedVariables != null && eliminatedVariables.contains(originalType)) {
456
					return createWildcard(genericType, rank, null, null, Wildcard.UNBOUND);
458
					return createWildcard(genericType, rank, null, null, Wildcard.UNBOUND);
457
				}
459
				}
458
				TypeVariableBinding variable = (TypeVariableBinding) originalType;
460
				TypeVariableBinding variable = (TypeVariableBinding) originalType;
459
				TypeBinding originalUpperBound = variable.upperBound();
461
				TypeBinding originalUpperBound = variable.upperBound();
460
				TypeBinding substitutedUpperBound = convertEliminatingTypeVariables(originalUpperBound, genericType, rank, variable);
462
				if (eliminatedVariables == null) {
463
					eliminatedVariables = new HashSet(2);
464
				}
465
				eliminatedVariables.add(variable);
466
				TypeBinding substitutedUpperBound = convertEliminatingTypeVariables(originalUpperBound, genericType, rank, eliminatedVariables);
467
				eliminatedVariables.remove(variable);
461
				return createWildcard(genericType, rank, substitutedUpperBound, null, Wildcard.EXTENDS);
468
				return createWildcard(genericType, rank, substitutedUpperBound, null, Wildcard.EXTENDS);
462
			case Binding.RAW_TYPE :
469
			case Binding.RAW_TYPE :
463
				break;
470
				break;
Lines 466-478 Link Here
466
				originalEnclosing = currentType.enclosingType();
473
				originalEnclosing = currentType.enclosingType();
467
				substitutedEnclosing = originalEnclosing;
474
				substitutedEnclosing = originalEnclosing;
468
				if (originalEnclosing != null) {
475
				if (originalEnclosing != null) {
469
					substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariable);
476
					substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariables);
470
				}
477
				}
471
				originalArguments = currentType.typeVariables();
478
				originalArguments = currentType.typeVariables();
472
				substitutedArguments = originalArguments;
479
				substitutedArguments = originalArguments;
473
				for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) {
480
				for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) {
474
					TypeBinding originalArgument = originalArguments[i];
481
					TypeBinding originalArgument = originalArguments[i];
475
					TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, currentType, i, eliminatedVariable);
482
					TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, currentType, i, eliminatedVariables);
476
					if (substitutedArgument != originalArgument) {
483
					if (substitutedArgument != originalArgument) {
477
						if (substitutedArguments == originalArguments) {
484
						if (substitutedArguments == originalArguments) {
478
							System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i);
485
							System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i);
Lines 491-497 Link Here
491
				TypeBinding originalBound = wildcard.bound;
498
				TypeBinding originalBound = wildcard.bound;
492
				TypeBinding substitutedBound = originalBound;
499
				TypeBinding substitutedBound = originalBound;
493
				if (originalBound != null) {
500
				if (originalBound != null) {
494
					substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariable);
501
					substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariables);
495
					if (substitutedBound != originalBound) {
502
					if (substitutedBound != originalBound) {
496
						return createWildcard(wildcard.genericType, wildcard.rank, substitutedBound, null, wildcard.boundKind);
503
						return createWildcard(wildcard.genericType, wildcard.rank, substitutedBound, null, wildcard.boundKind);
497
					}
504
					}
Lines 502-514 Link Here
502
				originalBound = intersection.bound;
509
				originalBound = intersection.bound;
503
				substitutedBound = originalBound;
510
				substitutedBound = originalBound;
504
				if (originalBound != null) {
511
				if (originalBound != null) {
505
					substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariable);
512
					substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariables);
506
				}
513
				}
507
				TypeBinding[] originalOtherBounds = intersection.otherBounds;
514
				TypeBinding[] originalOtherBounds = intersection.otherBounds;
508
				TypeBinding[] substitutedOtherBounds = originalOtherBounds;
515
				TypeBinding[] substitutedOtherBounds = originalOtherBounds;
509
				for (int i = 0, length = originalOtherBounds == null ? 0 : originalOtherBounds.length; i < length; i++) {
516
				for (int i = 0, length = originalOtherBounds == null ? 0 : originalOtherBounds.length; i < length; i++) {
510
					TypeBinding originalOtherBound = originalOtherBounds[i];
517
					TypeBinding originalOtherBound = originalOtherBounds[i];
511
					TypeBinding substitutedOtherBound = convertEliminatingTypeVariables(originalOtherBound, genericType, rank, eliminatedVariable);
518
					TypeBinding substitutedOtherBound = convertEliminatingTypeVariables(originalOtherBound, genericType, rank, eliminatedVariables);
512
					if (substitutedOtherBound != originalOtherBound) {
519
					if (substitutedOtherBound != originalOtherBound) {
513
						if (substitutedOtherBounds == originalOtherBounds) {
520
						if (substitutedOtherBounds == originalOtherBounds) {
514
							System.arraycopy(originalOtherBounds, 0, substitutedOtherBounds = new TypeBinding[length], 0, i);
521
							System.arraycopy(originalOtherBounds, 0, substitutedOtherBounds = new TypeBinding[length], 0, i);

Return to bug 207299