/** Actually invokes from a compile-time invocation (by using runtime reflection). */ @SuppressWarnings("unchecked") public static <T> T invoke(CtInvocation<T> i) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Object target = i.getTarget() == null ? null : ((CtLiteral<?>) i.getTarget()).getValue(); List<Object> args = new ArrayList<Object>(); for (CtExpression<?> e : i.getArguments()) { args.add(((CtLiteral<?>) e).getValue()); } Class<?> c = i.getExecutable().getDeclaringType().getActualClass(); ArrayList<Class<?>> argTypes = new ArrayList<Class<?>>(); for (CtTypeReference<?> type : i.getExecutable().getActualTypeArguments()) { argTypes.add(type.getActualClass()); } return (T) c.getMethod(i.getExecutable().getSimpleName(), argTypes.toArray(new Class[argTypes.size()])) .invoke(target, args.toArray()); }