Search in sources :

Example 6 with AnnotationTypeMismatchException

use of java.lang.annotation.AnnotationTypeMismatchException in project robovm by robovm.

the class AnnotationTypeMismatchExceptionTest method testGetters.

public void testGetters() throws Exception {
    Method m = String.class.getMethod("length");
    AnnotationTypeMismatchException ex = new AnnotationTypeMismatchException(m, "poop");
    assertSame(m, ex.element());
    assertEquals("poop", ex.foundType());
}
Also used : Method(java.lang.reflect.Method) AnnotationTypeMismatchException(java.lang.annotation.AnnotationTypeMismatchException)

Example 7 with AnnotationTypeMismatchException

use of java.lang.annotation.AnnotationTypeMismatchException in project epoxy by airbnb.

the class EpoxyProcessor method addDefaultLayoutMethodIfNeeded.

/**
   * If there is no existing implementation of getDefaultLayout we can generate an implementation.
   * This relies on a layout res being set in the @EpoxyModelClass annotation.
   */
private void addDefaultLayoutMethodIfNeeded(TypeElement originalClassElement, List<MethodSpec> methods) {
    MethodSpec getDefaultLayoutMethod = MethodSpec.methodBuilder(GET_DEFAULT_LAYOUT_METHOD_NAME).addAnnotation(Override.class).addAnnotation(LayoutRes.class).addModifiers(Modifier.PROTECTED).returns(TypeName.INT).build();
    if (implementsMethod(originalClassElement, getDefaultLayoutMethod, typeUtils)) {
        return;
    }
    EpoxyModelClass annotation = findClassAnnotationWithLayout(originalClassElement);
    if (annotation == null) {
        logError("Model must use %s annotation if it does not implement %s. (class: %s)", EpoxyModelClass.class, GET_DEFAULT_LAYOUT_METHOD_NAME, originalClassElement.getSimpleName());
        return;
    }
    int layoutRes;
    try {
        layoutRes = annotation.layout();
    } catch (AnnotationTypeMismatchException e) {
        logError("Invalid layout value in %s annotation. (class: %s). %s: %s", EpoxyModelClass.class, originalClassElement.getSimpleName(), e.getClass().getSimpleName(), e.getMessage());
        return;
    }
    if (layoutRes == 0) {
        logError("Model must specify a valid layout resource in the %s annotation. (class: %s)", EpoxyModelClass.class, originalClassElement.getSimpleName());
        return;
    }
    AndroidResource layoutResource = resourceProcessor.getResourceForValue(layoutRes);
    getDefaultLayoutMethod = getDefaultLayoutMethod.toBuilder().addStatement("return $L", layoutResource.code).build();
    methods.add(getDefaultLayoutMethod);
}
Also used : LayoutRes(android.support.annotation.LayoutRes) MethodSpec(com.squareup.javapoet.MethodSpec) AnnotationTypeMismatchException(java.lang.annotation.AnnotationTypeMismatchException)

Aggregations

AnnotationTypeMismatchException (java.lang.annotation.AnnotationTypeMismatchException)7 Method (java.lang.reflect.Method)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 NotSerializableException (java.io.NotSerializableException)2 ObjectOutputStream (java.io.ObjectOutputStream)2 LayoutRes (android.support.annotation.LayoutRes)1 MethodSpec (com.squareup.javapoet.MethodSpec)1 TypeElement (javax.lang.model.element.TypeElement)1