// we can't even pass exceptions without re-wraping them since classes on the invoking side are incompatible
// also flatten to avoid getting nested ITEs
private static Object invokeAnnotation(Class<?> clazz, Object[] trees) throws InstantiationException, IllegalAccessException, InvocationTargetException {
        Constructor<?> ctor = clazz.getDeclaredConstructors()[0];
        ctor.setAccessible(true);
        Object instance = ctor.newInstance();
        Method method = null;
        Method[] declaredMethods = clazz.getDeclaredMethods();
        for (Method m : declaredMethods) {
            if (m.getName().equals("apply")) method = m;
        }
        assert method != null: "Method 'apply' not found in annotation class";
        method.setAccessible(true);
        Object result;
        try {
            result = method.invoke(instance, trees);
        }   catch (InvocationTargetException e) {
            // we can't even pass exceptions without re-wraping them since classes on the invoking side are incompatible
            // also flatten to avoid getting nested ITEs
            RuntimeException exception = new RuntimeException(e.getTargetException().toString());
            exception.setStackTrace(e.getStackTrace());
            throw exception;
        }
        return result;
    }
result = method.invoke(instance, trees);
} catch (InvocationTargetException e) {
// we can't even pass exceptions without re-wraping them since classes on the invoking side are incompatible
// also flatten to avoid getting nested ITEs
RuntimeException exception = new RuntimeException(e.getTargetException().toString());
exception.setStackTrace(e.getStackTrace());
Method[] declaredMethods = clazz.getDeclaredMethods();
for (Method m : declaredMethods) {
if (m.getName().equals("apply")) method = m;
}
assert method != null: "Method 'apply' not found in annotation class";
method.setAccessible(true);
Object result;
try {
result = method.invoke(instance, trees);
} catch (InvocationTargetException e) {
// we can't even pass exceptions without re-wraping them since classes on the invoking side are incompatible
// also flatten to avoid getting nested ITEs
RuntimeException exception = new RuntimeException(e.getTargetException().toString());
exception.setStackTrace(e.getStackTrace());
throw exception;
}
return result;
}
private static Object invokeAnnotation(Class<?> clazz, Object[] trees) throws InstantiationException, IllegalAccessException, InvocationTargetException {
Constructor<?> ctor = clazz.getDeclaredConstructors()[0];
ctor.setAccessible(true);
Object instance = ctor.newInstance();
Method method = null;
Method[] declaredMethods = clazz.getDeclaredMethods();
for (Method m : declaredMethods) {
if (m.getName().equals("apply")) method = m;
}
assert method != null: "Method 'apply' not found in annotation class";
method.setAccessible(true);
Object result;
try {
result = method.invoke(instance, trees);
} catch (InvocationTargetException e) {
// we can't even pass exceptions without re-wraping them since classes on the invoking side are incompatible
// also flatten to avoid getting nested ITEs
RuntimeException exception = new RuntimeException(e.getTargetException().toString());
exception.setStackTrace(e.getStackTrace());
throw exception;
}
return result;
}