Exemplo n.º 1
0
 /** Constructor used when creating a raw type. */
 public ReferenceType(ResolvedType theGenericType, World aWorld) {
   super(theGenericType.getErasureSignature(), theGenericType.getErasureSignature(), aWorld);
   ReferenceType genericReferenceType = (ReferenceType) theGenericType;
   this.typeParameters = null;
   this.genericType = genericReferenceType;
   this.typeKind = TypeKind.RAW;
   this.delegate = genericReferenceType.getDelegate();
   genericReferenceType.addDependentType(this);
 }
Exemplo n.º 2
0
 /** Constructor used when creating a parameterized type. */
 public ReferenceType(ResolvedType theGenericType, ResolvedType[] theParameters, World aWorld) {
   super(
       makeParameterizedSignature(theGenericType, theParameters),
       theGenericType.signatureErasure,
       aWorld);
   ReferenceType genericReferenceType = (ReferenceType) theGenericType;
   this.typeParameters = theParameters;
   this.genericType = genericReferenceType;
   this.typeKind = TypeKind.PARAMETERIZED;
   this.delegate = genericReferenceType.getDelegate();
   genericReferenceType.addDependentType(this);
 }
Exemplo n.º 3
0
 private final boolean isCoerceableFromParameterizedType(ResolvedType other) {
   if (!other.isParameterizedType()) return false;
   ResolvedType myRawType = (ResolvedType) getRawType();
   ResolvedType theirRawType = (ResolvedType) other.getRawType();
   if (myRawType == theirRawType) {
     if (getTypeParameters().length == other.getTypeParameters().length) {
       // there's a chance it can be done
       ResolvedType[] myTypeParameters = getResolvedTypeParameters();
       ResolvedType[] theirTypeParameters = other.getResolvedTypeParameters();
       for (int i = 0; i < myTypeParameters.length; i++) {
         if (myTypeParameters[i] != theirTypeParameters[i]) {
           // thin ice now... but List<String> may still be coerceable from e.g. List<T>
           if (myTypeParameters[i].isGenericWildcard()) {
             BoundedReferenceType wildcard = (BoundedReferenceType) myTypeParameters[i];
             if (!wildcard.canBeCoercedTo(theirTypeParameters[i])) return false;
           } else if (myTypeParameters[i].isTypeVariableReference()) {
             TypeVariableReferenceType tvrt = (TypeVariableReferenceType) myTypeParameters[i];
             TypeVariable tv = tvrt.getTypeVariable();
             tv.resolve(world);
             if (!tv.canBeBoundTo(theirTypeParameters[i])) return false;
           } else if (theirTypeParameters[i].isTypeVariableReference()) {
             TypeVariableReferenceType tvrt = (TypeVariableReferenceType) theirTypeParameters[i];
             TypeVariable tv = tvrt.getTypeVariable();
             tv.resolve(world);
             if (!tv.canBeBoundTo(myTypeParameters[i])) return false;
           } else {
             return false;
           }
         }
       }
       return true;
     }
   } else {
     // we do this walk for situations like the following:
     // Base<T>, Sub<S,T> extends Base<S>
     // is Sub<Y,Z> coerceable from Base<X> ???
     for (Iterator i = getDirectSupertypes(); i.hasNext(); ) {
       ReferenceType parent = (ReferenceType) i.next();
       if (parent.isCoerceableFromParameterizedType(other)) return true;
     }
   }
   return false;
 }
Exemplo n.º 4
0
  public void setDelegate(ReferenceTypeDelegate delegate) {
    // Don't copy from BcelObjectType to EclipseSourceType - the context may be tidied (result
    // null'd) after previous weaving
    if (this.delegate != null
        && !(this.delegate instanceof BcelObjectType)
        && this.delegate.getSourceContext() != SourceContextImpl.UNKNOWN_SOURCE_CONTEXT)
      ((AbstractReferenceTypeDelegate) delegate).setSourceContext(this.delegate.getSourceContext());
    this.delegate = delegate;
    for (Iterator it = this.derivativeTypes.iterator(); it.hasNext(); ) {
      ReferenceType dependent = (ReferenceType) it.next();
      dependent.setDelegate(delegate);
    }

    // If we are raw, we have a generic type - we should ensure it uses the
    // same delegate
    if (isRawType() && getGenericType() != null) {
      ReferenceType genType = (ReferenceType) getGenericType();
      if (genType.getDelegate() != delegate) { // avoids circular updates
        genType.setDelegate(delegate);
      }
    }
    clearParameterizationCaches();
  }
Exemplo n.º 5
0
 public static ReferenceType fromTypeX(UnresolvedType tx, World world) {
   ReferenceType rt = new ReferenceType(tx.getErasureSignature(), world);
   rt.typeKind = tx.typeKind;
   return rt;
 }