Example usage for javax.lang.model.element TypeElement getTypeParameters

List of usage examples for javax.lang.model.element TypeElement getTypeParameters

Introduction

In this page you can find the example usage for javax.lang.model.element TypeElement getTypeParameters.

Prototype

List<? extends TypeParameterElement> getTypeParameters();

Source Link

Document

Returns the formal type parameters of this type element in declaration order.

Usage

From source file:auto.parse.processor.AutoParseProcessor.java

private static String formalTypeString(TypeElement type) {
    List<? extends TypeParameterElement> typeParameters = type.getTypeParameters();
    if (typeParameters.isEmpty()) {
        return "";
    } else {//  ww  w  .ja  v  a  2s.com
        String s = "<";
        String sep = "";
        for (TypeParameterElement typeParameter : typeParameters) {
            s += sep + typeParameterString(typeParameter);
            sep = ", ";
        }
        return s + ">";
    }
}

From source file:auto.parse.processor.AutoParseProcessor.java

private static String actualTypeString(TypeElement type) {
    List<? extends TypeParameterElement> typeParameters = type.getTypeParameters();
    if (typeParameters.isEmpty()) {
        return "";
    } else {//from www.  j  a  va2 s. c o m
        String s = "<";
        String sep = "";
        for (TypeParameterElement typeParameter : typeParameters) {
            s += sep + typeParameter.getSimpleName();
            sep = ", ";
        }
        return s + ">";
    }
}

From source file:auto.parse.processor.AutoParseProcessor.java

private static String wildcardTypeString(TypeElement type) {
    List<? extends TypeParameterElement> typeParameters = type.getTypeParameters();
    if (typeParameters.isEmpty()) {
        return "";
    } else {//from w  w  w.  j av  a  2s.  co  m
        String s = "<";
        String sep = "";
        for (int i = 0; i < typeParameters.size(); i++) {
            s += sep + "?";
            sep = ", ";
        }
        return s + ">";
    }
}

From source file:uniol.apt.compiler.AbstractServiceProcessor.java

private boolean isValidClass(Element ele) {
    if (ele.getKind() != ElementKind.CLASS) {
        error(ele, "Non-Class %s annotated with %s.", ele.getSimpleName().toString(),
                this.annotationClass.getCanonicalName());
    }//from   www.j av a2  s .c  om

    TypeElement classEle = (TypeElement) ele;

    if (!classEle.getModifiers().contains(Modifier.PUBLIC)) {
        error(classEle, "Class %s is not public.", classEle.getQualifiedName().toString());
        return false;
    }

    if (classEle.getModifiers().contains(Modifier.ABSTRACT)) {
        error(classEle, "Class %s is abstract.", classEle.getQualifiedName().toString());
        return false;
    }

    TypeMirror expected = this.types.erasure(this.elements.getTypeElement(this.interfaceName).asType());
    boolean found = false;
    for (TypeMirror actual : classEle.getInterfaces()) {
        if (this.types.isAssignable(actual, expected)) {
            found = true;
            break;
        }
    }
    if (!found) {
        error(classEle, "Class %s doesn't implement interface %s.", classEle.getQualifiedName().toString(),
                this.interfaceName);
        return false;
    }

    if (!allowGenerics && !classEle.getTypeParameters().isEmpty()) {
        error(classEle, "Class %s is generic.", classEle.getQualifiedName().toString());
        return false;
    }

    for (Element enclosed : classEle.getEnclosedElements()) {
        if (enclosed.getKind() == ElementKind.CONSTRUCTOR) {
            ExecutableElement constructorEle = (ExecutableElement) enclosed;
            if (constructorEle.getParameters().size() == 0
                    && constructorEle.getModifiers().contains(Modifier.PUBLIC)) {
                return true;
            }
        }
    }

    error(classEle, String.format("Class %s needs an public no-arg constructor",
            classEle.getQualifiedName().toString()));
    return false;
}