Search in sources :

Example 1 with GoetheException

use of com.palantir.goethe.GoetheException in project tritium by palantir.

the class TritiumAnnotationProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> _annotations, RoundEnvironment roundEnv) {
    if (roundEnv.processingOver()) {
        if (!invalidElements.isEmpty()) {
            messager.printMessage(Kind.ERROR, "Processing completed with unresolved elements: " + invalidElements);
        }
        return false;
    }
    for (Element element : getElementsToProcess(roundEnv)) {
        if (element.getKind() != ElementKind.INTERFACE) {
            messager.printMessage(Kind.ERROR, "Only interfaces may be instrumented using @" + Instrument.class.getSimpleName(), element);
            continue;
        }
        TypeElement typeElement = (TypeElement) element;
        List<DeclaredType> allInterfaces = new ArrayList<>();
        List<DeclaredType> minimalInterfaces = new ArrayList<>();
        if (isInvalid(element.asType(), allInterfaces, minimalInterfaces)) {
            invalidElements.add(typeElement.getQualifiedName());
            continue;
        }
        if (allInterfaces.isEmpty()) {
            messager.printMessage(Kind.ERROR, "Cannot generate a instrumented implementation. " + "The annotated class implements no interfaces.", typeElement);
            continue;
        }
        try {
            JavaFile generatedFile = generate(typeElement, allInterfaces, minimalInterfaces);
            try {
                Goethe.formatAndEmit(generatedFile, filer);
            } catch (GoetheException e) {
                messager.printMessage(Kind.ERROR, "Failed to write instrumented class: " + Throwables.getStackTraceAsString(e));
            }
        } catch (RuntimeException e) {
            messager.printMessage(Kind.ERROR, "Failed to generate instrumented class: " + Throwables.getStackTraceAsString(e));
        }
    }
    return false;
}
Also used : GoetheException(com.palantir.goethe.GoetheException) TypeElement(javax.lang.model.element.TypeElement) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList) JavaFile(com.squareup.javapoet.JavaFile) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

GoetheException (com.palantir.goethe.GoetheException)1 JavaFile (com.squareup.javapoet.JavaFile)1 ArrayList (java.util.ArrayList)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1