Example usage for javax.lang.model.util Types getDeclaredType

List of usage examples for javax.lang.model.util Types getDeclaredType

Introduction

In this page you can find the example usage for javax.lang.model.util Types getDeclaredType.

Prototype

DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs);

Source Link

Document

Returns the type corresponding to a type element and actual type arguments.

Usage

From source file:com.vimeo.stag.processor.utils.TypeUtils.java

@NotNull
public static DeclaredType getDeclaredType(TypeElement typeElem, TypeMirror... typeArgs) {
    Types types = getUtils();
    return types.getDeclaredType(typeElem, typeArgs);
}

From source file:com.vimeo.stag.processor.utils.TypeUtils.java

@NotNull
public static DeclaredType getDeclaredTypeForParameterizedClass(@NotNull String className) {
    Types types = getUtils();
    WildcardType wildcardType = types.getWildcardType(null, null);
    TypeMirror[] typex = { wildcardType };
    return types.getDeclaredType(ElementUtils.getTypeElementFromQualifiedName(className), typex);
}

From source file:com.vimeo.stag.processor.utils.TypeUtils.java

@NotNull
private static TypeMirror resolveTypeVars(@NotNull TypeMirror element,
        @NotNull final List<? extends TypeMirror> inheritedTypes,
        @NotNull final List<? extends TypeMirror> concreteTypes) {
    if (isConcreteType(element)) {
        return element;
    }//from   ww  w  . j  a v a  2s. c om

    if (element.getKind() == TypeKind.TYPEVAR) {
        int index = inheritedTypes.indexOf(element);
        return concreteTypes.get(index);
    }

    Types types = getUtils();
    List<? extends TypeMirror> typeMirrors = ((DeclaredType) element).getTypeArguments();
    TypeElement typeElement = (TypeElement) types.asElement(element);
    List<TypeMirror> concreteGenericTypes = new ArrayList<>(typeMirrors.size());
    for (TypeMirror type : typeMirrors) {
        concreteGenericTypes.add(resolveTypeVars(type, inheritedTypes, concreteTypes));
    }
    TypeMirror[] concreteTypeArray = concreteGenericTypes.toArray(new TypeMirror[concreteGenericTypes.size()]);
    return types.getDeclaredType(typeElement, concreteTypeArray);
}