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());
}
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);
}
Aggregations