Lines 11-19
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; |
|
|
15 |
import java.util.Map; |
14 |
import java.util.Map; |
16 |
import java.util.Set; |
|
|
17 |
|
15 |
|
18 |
import org.eclipse.jdt.core.compiler.CharOperation; |
16 |
import org.eclipse.jdt.core.compiler.CharOperation; |
19 |
import org.eclipse.jdt.internal.compiler.ClassFilePool; |
17 |
import org.eclipse.jdt.internal.compiler.ClassFilePool; |
Lines 386-508
Link Here
|
386 |
return packageBinding; |
384 |
return packageBinding; |
387 |
} |
385 |
} |
388 |
|
386 |
|
389 |
public TypeBinding convertEliminatingTypeVariables(TypeBinding originalType, ReferenceBinding genericType, int rank, Set eliminatedVariables) { |
|
|
390 |
if ((originalType.tagBits & TagBits.HasTypeVariable) != 0) { |
391 |
switch (originalType.kind()) { |
392 |
case Binding.ARRAY_TYPE : |
393 |
ArrayBinding originalArrayType = (ArrayBinding) originalType; |
394 |
TypeBinding originalLeafComponentType = originalArrayType.leafComponentType; |
395 |
TypeBinding substitute = convertEliminatingTypeVariables(originalLeafComponentType, genericType, rank, eliminatedVariables); // substitute could itself be array type |
396 |
if (substitute != originalLeafComponentType) { |
397 |
return createArrayType(substitute.leafComponentType(), substitute.dimensions() + originalArrayType.dimensions()); |
398 |
} |
399 |
break; |
400 |
case Binding.PARAMETERIZED_TYPE : |
401 |
ParameterizedTypeBinding paramType = (ParameterizedTypeBinding) originalType; |
402 |
ReferenceBinding originalEnclosing = paramType.enclosingType(); |
403 |
ReferenceBinding substitutedEnclosing = originalEnclosing; |
404 |
if (originalEnclosing != null) { |
405 |
substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariables); |
406 |
} |
407 |
TypeBinding[] originalArguments = paramType.arguments; |
408 |
TypeBinding[] substitutedArguments = originalArguments; |
409 |
for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) { |
410 |
TypeBinding originalArgument = originalArguments[i]; |
411 |
TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, paramType.genericType(), i, eliminatedVariables); |
412 |
if (substitutedArgument != originalArgument) { |
413 |
if (substitutedArguments == originalArguments) { |
414 |
System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i); |
415 |
} |
416 |
substitutedArguments[i] = substitutedArgument; |
417 |
} else if (substitutedArguments != originalArguments) { |
418 |
substitutedArguments[i] = originalArgument; |
419 |
} |
420 |
} |
421 |
if (originalEnclosing != substitutedEnclosing || originalArguments != substitutedArguments) { |
422 |
return createParameterizedType(paramType.genericType(), substitutedArguments, substitutedEnclosing); |
423 |
} |
424 |
break; |
425 |
case Binding.TYPE_PARAMETER : |
426 |
if (eliminatedVariables != null && eliminatedVariables.contains(originalType)) { |
427 |
return createWildcard(genericType, rank, null, null, Wildcard.UNBOUND); |
428 |
} |
429 |
TypeVariableBinding variable = (TypeVariableBinding) originalType; |
430 |
TypeBinding originalUpperBound = variable.upperBound(); |
431 |
if (eliminatedVariables == null) { |
432 |
eliminatedVariables = new HashSet(2); |
433 |
} |
434 |
eliminatedVariables.add(variable); |
435 |
TypeBinding substitutedUpperBound = convertEliminatingTypeVariables(originalUpperBound, genericType, rank, eliminatedVariables); |
436 |
eliminatedVariables.remove(variable); |
437 |
return createWildcard(genericType, rank, substitutedUpperBound, null, Wildcard.EXTENDS); |
438 |
case Binding.RAW_TYPE : |
439 |
break; |
440 |
case Binding.GENERIC_TYPE : |
441 |
ReferenceBinding currentType = (ReferenceBinding) originalType; |
442 |
originalEnclosing = currentType.enclosingType(); |
443 |
substitutedEnclosing = originalEnclosing; |
444 |
if (originalEnclosing != null) { |
445 |
substitutedEnclosing = (ReferenceBinding) convertEliminatingTypeVariables(originalEnclosing, genericType, rank, eliminatedVariables); |
446 |
} |
447 |
originalArguments = currentType.typeVariables(); |
448 |
substitutedArguments = originalArguments; |
449 |
for (int i = 0, length = originalArguments == null ? 0 : originalArguments.length; i < length; i++) { |
450 |
TypeBinding originalArgument = originalArguments[i]; |
451 |
TypeBinding substitutedArgument = convertEliminatingTypeVariables(originalArgument, currentType, i, eliminatedVariables); |
452 |
if (substitutedArgument != originalArgument) { |
453 |
if (substitutedArguments == originalArguments) { |
454 |
System.arraycopy(originalArguments, 0, substitutedArguments = new TypeBinding[length], 0, i); |
455 |
} |
456 |
substitutedArguments[i] = substitutedArgument; |
457 |
} else if (substitutedArguments != originalArguments) { |
458 |
substitutedArguments[i] = originalArgument; |
459 |
} |
460 |
} |
461 |
if (originalEnclosing != substitutedEnclosing || originalArguments != substitutedArguments) { |
462 |
return createParameterizedType(genericType, substitutedArguments, substitutedEnclosing); |
463 |
} |
464 |
break; |
465 |
case Binding.WILDCARD_TYPE : |
466 |
WildcardBinding wildcard = (WildcardBinding) originalType; |
467 |
TypeBinding originalBound = wildcard.bound; |
468 |
TypeBinding substitutedBound = originalBound; |
469 |
if (originalBound != null) { |
470 |
substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariables); |
471 |
if (substitutedBound != originalBound) { |
472 |
return createWildcard(wildcard.genericType, wildcard.rank, substitutedBound, null, wildcard.boundKind); |
473 |
} |
474 |
} |
475 |
break; |
476 |
case Binding.INTERSECTION_TYPE : |
477 |
WildcardBinding intersection = (WildcardBinding) originalType; |
478 |
originalBound = intersection.bound; |
479 |
substitutedBound = originalBound; |
480 |
if (originalBound != null) { |
481 |
substitutedBound = convertEliminatingTypeVariables(originalBound, genericType, rank, eliminatedVariables); |
482 |
} |
483 |
TypeBinding[] originalOtherBounds = intersection.otherBounds; |
484 |
TypeBinding[] substitutedOtherBounds = originalOtherBounds; |
485 |
for (int i = 0, length = originalOtherBounds == null ? 0 : originalOtherBounds.length; i < length; i++) { |
486 |
TypeBinding originalOtherBound = originalOtherBounds[i]; |
487 |
TypeBinding substitutedOtherBound = convertEliminatingTypeVariables(originalOtherBound, genericType, rank, eliminatedVariables); |
488 |
if (substitutedOtherBound != originalOtherBound) { |
489 |
if (substitutedOtherBounds == originalOtherBounds) { |
490 |
System.arraycopy(originalOtherBounds, 0, substitutedOtherBounds = new TypeBinding[length], 0, i); |
491 |
} |
492 |
substitutedOtherBounds[i] = substitutedOtherBound; |
493 |
} else if (substitutedOtherBounds != originalOtherBounds) { |
494 |
substitutedOtherBounds[i] = originalOtherBound; |
495 |
} |
496 |
} |
497 |
if (substitutedBound != originalBound || substitutedOtherBounds != originalOtherBounds) { |
498 |
return createWildcard(intersection.genericType, intersection.rank, substitutedBound, substitutedOtherBounds, intersection.boundKind); |
499 |
} |
500 |
break; |
501 |
} |
502 |
} |
503 |
return originalType; |
504 |
} |
505 |
|
506 |
/** |
387 |
/** |
507 |
* Convert a given source type into a parameterized form if generic. |
388 |
* Convert a given source type into a parameterized form if generic. |
508 |
* generic X<E> --> param X<E> |
389 |
* generic X<E> --> param X<E> |
Lines 598-603
Link Here
|
598 |
return type; |
479 |
return type; |
599 |
} |
480 |
} |
600 |
|
481 |
|
|
|
482 |
/** |
483 |
* Convert an array of types in raw forms. |
484 |
* Only allocate an array if anything is different. |
485 |
*/ |
486 |
public ReferenceBinding[] convertToRawTypes(ReferenceBinding[] originalTypes, boolean forceErasure, boolean forceRawEnclosingType) { |
487 |
if (originalTypes == null) return null; |
488 |
ReferenceBinding[] convertedTypes = originalTypes; |
489 |
for (int i = 0, length = originalTypes.length; i < length; i++) { |
490 |
ReferenceBinding originalType = originalTypes[i]; |
491 |
ReferenceBinding convertedType = (ReferenceBinding) convertToRawType(forceErasure ? originalType.erasure() : originalType, forceRawEnclosingType); |
492 |
if (convertedType != originalType) { |
493 |
if (convertedTypes == originalTypes) { |
494 |
System.arraycopy(originalTypes, 0, convertedTypes = new ReferenceBinding[length], 0, i); |
495 |
} |
496 |
convertedTypes[i] = convertedType; |
497 |
} else if (convertedTypes != originalTypes) { |
498 |
convertedTypes[i] = originalType; |
499 |
} |
500 |
} |
501 |
return convertedTypes; |
502 |
} |
601 |
|
503 |
|
602 |
// variation for unresolved types in binaries (consider generic type as raw) |
504 |
// variation for unresolved types in binaries (consider generic type as raw) |
603 |
public TypeBinding convertUnresolvedBinaryToRawType(TypeBinding type) { |
505 |
public TypeBinding convertUnresolvedBinaryToRawType(TypeBinding type) { |
Lines 657-663
Link Here
|
657 |
} |
559 |
} |
658 |
return type; |
560 |
return type; |
659 |
} |
561 |
} |
660 |
|
|
|
661 |
/* |
562 |
/* |
662 |
* Used to guarantee annotation identity. |
563 |
* Used to guarantee annotation identity. |
663 |
*/ |
564 |
*/ |
Lines 667-672
Link Here
|
667 |
} |
568 |
} |
668 |
return new AnnotationBinding(annotationType, pairs); |
569 |
return new AnnotationBinding(annotationType, pairs); |
669 |
} |
570 |
} |
|
|
571 |
|
670 |
/* |
572 |
/* |
671 |
* Used to guarantee array type identity. |
573 |
* Used to guarantee array type identity. |
672 |
*/ |
574 |
*/ |
Lines 708-717
Link Here
|
708 |
this.uniqueArrayBindings[dimIndex] = arrayBindings; |
610 |
this.uniqueArrayBindings[dimIndex] = arrayBindings; |
709 |
return arrayBindings[length] = new ArrayBinding(leafComponentType, dimensionCount, this); |
611 |
return arrayBindings[length] = new ArrayBinding(leafComponentType, dimensionCount, this); |
710 |
} |
612 |
} |
711 |
|
|
|
712 |
public BinaryTypeBinding createBinaryTypeFrom(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) { |
613 |
public BinaryTypeBinding createBinaryTypeFrom(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) { |
713 |
return createBinaryTypeFrom(binaryType, packageBinding, true, accessRestriction); |
614 |
return createBinaryTypeFrom(binaryType, packageBinding, true, accessRestriction); |
714 |
} |
615 |
} |
|
|
616 |
|
715 |
public BinaryTypeBinding createBinaryTypeFrom(IBinaryType binaryType, PackageBinding packageBinding, boolean needFieldsAndMethods, AccessRestriction accessRestriction) { |
617 |
public BinaryTypeBinding createBinaryTypeFrom(IBinaryType binaryType, PackageBinding packageBinding, boolean needFieldsAndMethods, AccessRestriction accessRestriction) { |
716 |
BinaryTypeBinding binaryBinding = new BinaryTypeBinding(packageBinding, binaryType, this); |
618 |
BinaryTypeBinding binaryBinding = new BinaryTypeBinding(packageBinding, binaryType, this); |
717 |
|
619 |
|
Lines 1342-1348
Link Here
|
1342 |
return this.nameEnvironment.isPackage(null, name); |
1244 |
return this.nameEnvironment.isPackage(null, name); |
1343 |
return this.nameEnvironment.isPackage(compoundName, name); |
1245 |
return this.nameEnvironment.isPackage(compoundName, name); |
1344 |
} |
1246 |
} |
1345 |
|
|
|
1346 |
// The method verifier is lazily initialized to guarantee the receiver, the compiler & the oracle are ready. |
1247 |
// The method verifier is lazily initialized to guarantee the receiver, the compiler & the oracle are ready. |
1347 |
public MethodVerifier methodVerifier() { |
1248 |
public MethodVerifier methodVerifier() { |
1348 |
if (this.verifier == null) |
1249 |
if (this.verifier == null) |
Lines 1351-1356
Link Here
|
1351 |
: new MethodVerifier15(this); // covariance only if sourceLevel is >= 1.5 |
1252 |
: new MethodVerifier15(this); // covariance only if sourceLevel is >= 1.5 |
1352 |
return this.verifier; |
1253 |
return this.verifier; |
1353 |
} |
1254 |
} |
|
|
1255 |
|
1354 |
public void releaseClassFiles(org.eclipse.jdt.internal.compiler.ClassFile[] classFiles) { |
1256 |
public void releaseClassFiles(org.eclipse.jdt.internal.compiler.ClassFile[] classFiles) { |
1355 |
for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) |
1257 |
for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) |
1356 |
this.classFilePool.release(classFiles[i]); |
1258 |
this.classFilePool.release(classFiles[i]); |