/** * {@inheritDoc} */ public Generic onTypeVariable(Generic typeVariable) { return declaringType.isGenerified() ? new Generic.OfNonGenericType.Latent(typeVariable.asErasure(), typeVariable) : typeVariable; }
/** * Creates a new generic type representation for an erasure where any generified type is reified. * * @param typeDescription The erasure to represent. * @return An appropriate generic type representation where any generified type is reified. */ protected static Generic of(TypeDescription typeDescription) { return typeDescription.isGenerified() ? new ForReifiedErasure(typeDescription) : new ForErasure(typeDescription); }
/** * Represents the supplied type description as a generified erasure if it is generified or as a non-generic type if not so. * * @param typeDescription The represented erasure. * @return An appropriate generic type. */ public static Generic of(TypeDescription typeDescription) { return typeDescription.isGenerified() ? new ForGenerifiedErasure(typeDescription) : new OfNonGenericType.ForErasure(typeDescription); }
/** * {@inheritDoc} */ public Generic onGenericArray(Generic genericArray) { return declaringType.isGenerified() ? new Generic.OfNonGenericType.Latent(genericArray.asErasure(), genericArray) : genericArray; }
/** * {@inheritDoc} */ public Generic onNonGenericType(Generic typeDescription) { TypeDescription erasure = typeDescription.asErasure(); return erasure.isGenerified() ? new OfNonGenericType.ForReifiedErasure(erasure) : typeDescription; } }
/** * {@inheritDoc} */ public Generic onParameterizedType(Generic parameterizedType) { return declaringType.isGenerified() ? new Generic.OfNonGenericType.Latent(parameterizedType.asErasure(), parameterizedType) : parameterizedType; }
/** * {@inheritDoc} */ public boolean isGenerified() { if (!getTypeVariables().isEmpty()) { return true; } else if (isStatic()) { return false; } TypeDescription declaringType = getDeclaringType(); return declaringType != null && declaringType.isGenerified(); }
/** * {@inheritDoc} */ public Generic getOwnerType() { TypeDescription declaringType = typeDescription.getDeclaringType(); if (declaringType == null) { return Generic.UNDEFINED; } else { return !typeDescription.isStatic() && declaringType.isGenerified() ? new LazyParameterizedReceiverType(declaringType) : new LazyNonGenericReceiverType(declaringType); } }
/** * Creates a parameterized type. * * @param rawType A raw version of the type to describe as a parameterized type. * @param ownerType The owner type of the parameterized type. * @param parameters The type arguments to attach to the raw type as parameters. * @return A builder for creating a parameterized type. */ public static Builder parameterizedType(TypeDescription rawType, Generic ownerType, Collection<? extends TypeDefinition> parameters) { TypeDescription declaringType = rawType.getDeclaringType(); if (ownerType == null && declaringType != null && rawType.isStatic()) { ownerType = declaringType.asGenericType(); } if (!rawType.represents(TargetType.class)) { if (!rawType.isGenerified()) { throw new IllegalArgumentException(rawType + " is not a parameterized type"); } else if (ownerType == null && declaringType != null && !rawType.isStatic()) { throw new IllegalArgumentException(rawType + " requires an owner type"); } else if (ownerType != null && !ownerType.asErasure().equals(declaringType)) { throw new IllegalArgumentException(ownerType + " does not represent required owner for " + rawType); } else if (ownerType != null && (rawType.isStatic() ^ ownerType.getSort().isNonGeneric())) { throw new IllegalArgumentException(ownerType + " does not define the correct parameters for owning " + rawType); } else if (rawType.getTypeVariables().size() != parameters.size()) { throw new IllegalArgumentException(parameters + " does not contain number of required parameters for " + rawType); } } return new Builder.OfParameterizedType(rawType, ownerType, new TypeList.Generic.Explicit(new ArrayList<TypeDefinition>(parameters))); }
/** * {@inheritDoc} */ public Generic getReceiverType() { if (isStatic()) { return Generic.UNDEFINED; } else if (isConstructor()) { TypeDescription declaringType = getDeclaringType(), enclosingDeclaringType = declaringType.getEnclosingType(); if (enclosingDeclaringType == null) { return declaringType.isGenerified() ? new LazyParameterizedReceiverType(declaringType) : new LazyNonGenericReceiverType(declaringType); } else { return !declaringType.isStatic() && declaringType.isGenerified() ? new LazyParameterizedReceiverType(enclosingDeclaringType) : new LazyNonGenericReceiverType(enclosingDeclaringType); } } else { return LazyTypeDescription.this.isGenerified() ? new LazyParameterizedReceiverType() : new LazyNonGenericReceiverType(); } }