Search in sources :

Example 1 with AnnotationTypeMismatchException

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

the class EpoxyProcessor method findClassAnnotationWithLayout.

/**
   * Looks for {@link EpoxyModelClass} annotation in the original class and his parents.
   */
private EpoxyModelClass findClassAnnotationWithLayout(TypeElement classElement) {
    if (!isEpoxyModel(classElement)) {
        return null;
    }
    EpoxyModelClass annotation = classElement.getAnnotation(EpoxyModelClass.class);
    if (annotation == null) {
        return null;
    }
    try {
        int layoutRes = annotation.layout();
        if (layoutRes != 0) {
            return annotation;
        }
    } catch (AnnotationTypeMismatchException e) {
        logError("Invalid layout value in %s annotation. (class: %s). %s: %s", EpoxyModelClass.class, classElement.getSimpleName(), e.getClass().getSimpleName(), e.getMessage());
        return null;
    }
    TypeElement superclassElement = (TypeElement) typeUtils.asElement(classElement.getSuperclass());
    EpoxyModelClass annotationOnSuperClass = findClassAnnotationWithLayout(superclassElement);
    // Return the last annotation value we have so the proper error can be thrown if needed
    return annotationOnSuperClass != null ? annotationOnSuperClass : annotation;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) AnnotationTypeMismatchException(java.lang.annotation.AnnotationTypeMismatchException)

Example 2 with AnnotationTypeMismatchException

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

the class AnnotationTypeMismatchExceptionTest method testSerialization.

public void testSerialization() throws Exception {
    Method m = String.class.getMethod("length");
    AnnotationTypeMismatchException original = new AnnotationTypeMismatchException(m, "poop");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // AnnotationTypeMismatchException is broken: it's Serializable but has a non-transient
        // non-serializable field of type Method.
        new ObjectOutputStream(out).writeObject(original);
        fail();
    } catch (NotSerializableException expected) {
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) Method(java.lang.reflect.Method) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) AnnotationTypeMismatchException(java.lang.annotation.AnnotationTypeMismatchException)

Example 3 with AnnotationTypeMismatchException

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

the class AnnotationTypeMismatchExceptionTest method test_constructorLjava_lang_reflect_MethodLjava_lang_String.

/**
     * @throws ClassNotFoundException 
     * @throws SecurityException 
     * @tests java.lang.annotation.AnnotationTypeMismatchException#AnnotationTypeMismatchException(Method,
     *        String)
     */
@SuppressWarnings("nls")
public void test_constructorLjava_lang_reflect_MethodLjava_lang_String() throws SecurityException, ClassNotFoundException {
    Method[] methods = Class.forName("java.lang.String").getMethods();
    Method m = methods[0];
    AnnotationTypeMismatchException e = new AnnotationTypeMismatchException(m, "some type");
    assertNotNull("can not instantiate AnnotationTypeMismatchException", e);
    assertSame("wrong method name", m, e.element());
    assertEquals("wrong found type", "some type", e.foundType());
}
Also used : Method(java.lang.reflect.Method) AnnotationTypeMismatchException(java.lang.annotation.AnnotationTypeMismatchException)

Example 4 with AnnotationTypeMismatchException

use of java.lang.annotation.AnnotationTypeMismatchException in project j2objc by google.

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 5 with AnnotationTypeMismatchException

use of java.lang.annotation.AnnotationTypeMismatchException in project j2objc by google.

the class AnnotationTypeMismatchExceptionTest method testSerialization.

public void testSerialization() throws Exception {
    Method m = String.class.getMethod("length");
    AnnotationTypeMismatchException original = new AnnotationTypeMismatchException(m, "poop");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        // AnnotationTypeMismatchException is broken: it's Serializable but has a non-transient
        // non-serializable field of type Method.
        new ObjectOutputStream(out).writeObject(original);
        fail();
    } catch (NotSerializableException expected) {
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) Method(java.lang.reflect.Method) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) 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