/** * {@inheritDoc} */ public Boolean onTypeVariable(Generic typeVariable) { if (typeVariable.equals(this.typeVariable)) { return true; } for (Generic upperBound : typeVariable.getUpperBounds()) { if (isAssignableFrom(upperBound)) { return true; } } return false; }
@Override public boolean equals(Object other) { if (this == other) { return true; } else if (!(other instanceof Generic)) { return false; } Generic typeDescription = (Generic) other; return typeDescription.getSort().isWildcard() && getUpperBounds().equals(typeDescription.getUpperBounds()) && getLowerBounds().equals(typeDescription.getLowerBounds()); }
/** * {@inheritDoc} */ public MethodDefinition.ImplementationDefinition<S> define(MethodDescription methodDescription) { MethodDefinition.ParameterDefinition.Initial<S> initialParameterDefinition = methodDescription.isConstructor() ? defineConstructor(methodDescription.getModifiers()) : defineMethod(methodDescription.getInternalName(), methodDescription.getReturnType(), methodDescription.getModifiers()); ParameterList<?> parameterList = methodDescription.getParameters(); MethodDefinition.ExceptionDefinition<S> exceptionDefinition; if (parameterList.hasExplicitMetaData()) { MethodDefinition.ParameterDefinition<S> parameterDefinition = initialParameterDefinition; for (ParameterDescription parameter : parameterList) { parameterDefinition = parameterDefinition.withParameter(parameter.getType(), parameter.getName(), parameter.getModifiers()); } exceptionDefinition = parameterDefinition; } else { exceptionDefinition = initialParameterDefinition.withParameters(parameterList.asTypeList()); } MethodDefinition.TypeVariableDefinition<S> typeVariableDefinition = exceptionDefinition.throwing(methodDescription.getExceptionTypes()); for (TypeDescription.Generic typeVariable : methodDescription.getTypeVariables()) { typeVariableDefinition = typeVariableDefinition.typeVariable(typeVariable.getSymbol(), typeVariable.getUpperBounds()); } return typeVariableDefinition; }
/** * {@inheritDoc} */ public SignatureVisitor onWildcard(Generic wildcard) { TypeList.Generic upperBounds = wildcard.getUpperBounds(), lowerBounds = wildcard.getLowerBounds(); if (lowerBounds.isEmpty() && upperBounds.getOnly().represents(Object.class)) { signatureVisitor.visitTypeArgument(); } else if (!lowerBounds.isEmpty() /* && upperBounds.isEmpty() */) { lowerBounds.getOnly().accept(new ForSignatureVisitor(signatureVisitor.visitTypeArgument(SignatureVisitor.SUPER))); } else /* if (!upperBounds.isEmpty() && lowerBounds.isEmpty()) */ { upperBounds.getOnly().accept(new ForSignatureVisitor(signatureVisitor.visitTypeArgument(SignatureVisitor.EXTENDS))); } return signatureVisitor; }
/** * {@inheritDoc} */ public Boolean onWildcard(Generic wildcard) { if (!isValid(wildcard)) { return false; } TypeList.Generic lowerBounds = wildcard.getLowerBounds(); return (lowerBounds.isEmpty() ? wildcard.getUpperBounds() : lowerBounds).getOnly().accept(this); }
/** * {@inheritDoc} */ public Dispatcher onWildcard(Generic wildcard) { TypeList.Generic lowerBounds = wildcard.getLowerBounds(); return lowerBounds.isEmpty() ? new CovariantBinding(wildcard.getUpperBounds().getOnly()) : new ContravariantBinding(lowerBounds.getOnly()); }
/** * {@inheritDoc} */ public Boolean onTypeVariable(Generic typeVariable) { for (Generic upperBound : typeVariable.getUpperBounds()) { if (isAssignableFrom(upperBound)) { return true; } } return false; }
/** * {@inheritDoc} */ public Generic onWildcard(Generic wildcard) { return new OfWildcardType.Latent(wildcard.getUpperBounds().accept(this), wildcard.getLowerBounds().accept(this), Empty.INSTANCE); }
/** * Transforms a type variable into a type variable token with its bounds detached. * * @param typeVariable A type variable in its attached state. * @param matcher A matcher that identifies types to detach from the upper bound types. * @return A token representing the detached type variable. */ public static TypeVariableToken of(TypeDescription.Generic typeVariable, ElementMatcher<? super TypeDescription> matcher) { return new TypeVariableToken(typeVariable.getSymbol(), typeVariable.getUpperBounds().accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)), typeVariable.getDeclaredAnnotations()); }
/** * {@inheritDoc} */ public TypeList.Generic getUpperBounds() { return resolve().getUpperBounds(); }
/** * {@inheritDoc} */ public TypeList.Generic getUpperBounds() { return typeVariable.getUpperBounds(); }
/** * {@inheritDoc} */ public Generic onWildcard(Generic wildcard) { return new OfWildcardType.Latent(wildcard.getUpperBounds().accept(this), wildcard.getLowerBounds().accept(this), wildcard); }
/** {@inheritDoc} */ public Boolean onTypeVariable(Generic typeVariable) { for (TypeDescription.Generic bound : typeVariable.getUpperBounds()) { if (bound.accept(this)) { return true; } } return false; }
/** * {@inheritDoc} */ public TypeList.Generic getUpperBounds() { return typeVariable.getUpperBounds(); }
/** * {@inheritDoc} */ public AnnotationAppender onWildcard(TypeDescription.Generic wildcard) { TypeList.Generic lowerBounds = wildcard.getLowerBounds(); return (lowerBounds.isEmpty() ? wildcard.getUpperBounds().getOnly() : lowerBounds.getOnly()).accept(new ForTypeAnnotations(apply(wildcard, typePath), annotationValueFilter, typeReference, typePath + WILDCARD_TYPE_PATH)); }
/** * {@inheritDoc} */ public TypeList.Generic getUpperBounds() { return typeVariable.getUpperBounds(); }
/** * {@inheritDoc} */ public TypeList.Generic getUpperBounds() { return typeVariable.getUpperBounds().accept(ForTypeVariableBinding.this); }
/** * {@inheritDoc} */ public boolean isAssignableFrom(Generic typeDescription) { if (typeDescription.getSort().isWildcard()) { return typeDescription.getLowerBounds().isEmpty() && upperBound.accept(Assigner.INSTANCE) .isAssignableFrom(typeDescription.getUpperBounds().getOnly()); } else { return upperBound.accept(Assigner.INSTANCE).isAssignableFrom(typeDescription); } } }
/** * {@inheritDoc} */ public TypeList.Generic getUpperBounds() { return typeVariable.getUpperBounds(); }
/** * {@inheritDoc} */ public Boolean onTypeVariable(Generic typeVariable) { for (Generic upperBound : typeVariable.getUpperBounds()) { if (isAssignableFrom(upperBound)) { return true; } } return false; }