private TypeMirror getUpperBound(TypeMirror type) { TypeVariable typeVariable = (TypeVariable) type; return typeVariable.getUpperBound(); }
private TypeMirror getParamTypeMirror(VariableElement param, Messager messager) { TypeMirror typeMirror = param.asType(); // Check for generic type if (typeMirror instanceof TypeVariable) { TypeMirror upperBound = ((TypeVariable) typeMirror).getUpperBound(); if (upperBound instanceof DeclaredType) { if (messager != null) { messager.printMessage(Diagnostic.Kind.NOTE, "Using upper bound type " + upperBound + " for generic parameter", param); } typeMirror = upperBound; } } return typeMirror; }
private TypeMirror upperBound(TypeMirror type) { switch (type.getKind()) { case WILDCARD: return MoreObjects.firstNonNull(((WildcardType) type).getExtendsBound(), objectType); case TYPEVAR: return ((TypeVariable) type).getUpperBound(); default: return type; } }
private TypeMirror normalize(TypeMirror type) { if (type.getKind() == TypeKind.TYPEVAR) { TypeVariable typeVar = (TypeVariable) type; if (typeVar.getUpperBound() != null) { return typeVar.getUpperBound(); } } else if (type.getKind() == TypeKind.WILDCARD) { WildcardType wildcard = (WildcardType) type; if (wildcard.getExtendsBound() != null) { return wildcard.getExtendsBound(); } } return type; }
@Override public TypeElement visitTypeVariable(TypeVariable t, Void p) { if (t.getUpperBound() != null) { return visit(t.getUpperBound()); } else if (t.getLowerBound() != null) { return visit(t.getLowerBound()); } else { return null; } }
@Override public AnnotationMetaAttribute visitTypeVariable(TypeVariable t, Element element) { // METAGEN-29 - for a type variable we use the upper bound TypeMirror mirror = t.getUpperBound(); TypeMirror erasedType = context.getTypeUtils().erasure( mirror ); return new AnnotationMetaSingleAttribute( entity, element, erasedType.toString() ); }
@Override public List<String> visitTypeVariable(TypeVariable t, Boolean p) { List<String> rv = visitBase(t); if (t.getUpperBound() != null) { rv.addAll(visit(t.getUpperBound(), p)); } if (t.getLowerBound() != null) { rv.addAll(visit(t.getLowerBound(), p)); } return rv; }
public static String extractClosestRealTypeAsString(TypeMirror type, Context context) { if ( type instanceof TypeVariable ) { final TypeMirror compositeUpperBound = ( (TypeVariable) type ).getUpperBound(); return extractClosestRealTypeAsString( compositeUpperBound, context ); } else { final TypeMirror erasureType = context.getTypeUtils().erasure( type ); if ( TypeKind.ARRAY.equals( erasureType.getKind() ) ) { // keep old behavior here for arrays since #asElement returns null for them. return erasureType.toString(); } else { return ( (TypeElement) context.getTypeUtils().asElement( erasureType ) ).getQualifiedName().toString(); } } }
viewType = typeVariable.getUpperBound();
if (returnType instanceof TypeVariable) { TypeVariable typeVariable = (TypeVariable) returnType; returnType = typeVariable.getUpperBound(); if (methodParameterType instanceof TypeVariable) { TypeVariable typeVariable = (TypeVariable) methodParameterType; methodParameterType = typeVariable.getUpperBound();
if (elementType.getKind() == TypeKind.TYPEVAR) { TypeVariable typeVariable = (TypeVariable) elementType; elementType = typeVariable.getUpperBound();
@Override public Type visitTypeVariable(TypeVariable typeVariable, Boolean p) { String varName = typeVariable.toString(); if (typeVariable.getUpperBound() != null) { Type type = visit(typeVariable.getUpperBound(), p); return new TypeExtends(varName, type); } else if (typeVariable.getLowerBound() != null && !(typeVariable.getLowerBound() instanceof NullType)) { Type type = visit(typeVariable.getLowerBound(), p); return new TypeSuper(varName, type); } else { return null; } }
inheritedAnnotations.addAll(typeVar.getUpperBound().getAnnotationMirrors()); if (typeVar.asElement().getKind() == TYPE_PARAMETER) { Element genericElt = ((TypeParameterElement) typeVar.asElement()).getGenericElement();
@Override public TypeMirror visitTypeVariable(TypeVariable x, State state) { if (x.equals(x.getUpperBound())) { // See comment in TransportableTypeVisitor return state.types.erasure(x); } return x.getUpperBound().accept(this, state); }
@Override public TypeMirror visitTypeVariable(TypeVariable x, State state) { // Convert <T extends FooProxy> to FooDomain return x.getUpperBound().accept(this, state); }
@Override public Boolean visitTypeVariable(TypeVariable t, State state) { if (t.equals(t.getUpperBound())) { /* * Weird case seen in Eclipse with self-parameterized type variables such * as <T extends Enum<T>>. * * TODO(bobv): Should intersection types be allowed at all? They don't * seem to make much sense in the most-derived interface types, since the * RF Generator won't know how to implement them. */ return state.types.erasure(t).accept(this, state); } // Allow <T extends FooProxy> return t.getUpperBound().accept(this, state); }
return viewAs(desiredType, ((TypeVariable) searchElement).getUpperBound(), state);
@Override public String convert(TypeVariable typeVariable) throws TemplateModelException { String conversion = "NSObject"; if (typeVariable.getUpperBound() != null) { conversion = convert(typeVariable.getUpperBound()); } return conversion; }
@Override public String convert(TypeVariable typeVariable) throws TemplateModelException { String conversion = "mixed"; if (typeVariable.getUpperBound() != null) { conversion = convert(typeVariable.getUpperBound()); } return conversion; }
@Override public JsonType visitTypeVariable(TypeVariable typeVariable, Context context) { TypeMirror bound = typeVariable.getUpperBound(); if (bound == null) { return context.isInArray() || context.isInCollection() ? new JsonArrayType(KnownJsonType.OBJECT) : KnownJsonType.OBJECT; } else { JsonType jsonType = bound.accept(this, new Context(context.context, false, false, context.stack)); return context.isInArray() || context.isInCollection() ? new JsonArrayType(jsonType) : jsonType; } }