use of org.qi4j.api.composite.CompositeInvoker in project qi4j-sdk by Qi4j.
the class ASMTest method createClass.
@Test
public void createClass() throws Exception {
FragmentClassLoader classLoader = new FragmentClassLoader(SomeMixin.class.getClassLoader());
Class clazz = classLoader.loadClass(SomeMixin.class.getName() + "_Stub");
// Class clazz = SomeMixin_Stubx.class;
final Other other = new Other() {
public String other() {
return "other";
}
public String foo(String bar, int x) {
return "bar:" + bar;
}
public void bar(double doub, boolean bool, float fl, char ch, int integer, long lg, short sh, byte b, Double doubObj, Object[] objArr, int[] intArr) {
}
public void multiEx(String bar) throws Exception1, Exception2 {
}
public long unwrapResult() {
return 0;
}
public void generic(List<String> list) {
list.add("Hello World");
}
};
final Some instance = (Some) clazz.getConstructor().newInstance();
CompositeInvoker invoker = new CompositeInvoker() {
public Object invokeComposite(Method method, Object[] args) throws Throwable {
Method fakeMethod = null;
try {
fakeMethod = instance.getClass().getMethod("_" + method.getName(), method.getParameterTypes());
try {
return fakeMethod.invoke(instance, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
} catch (NoSuchMethodException e) {
try {
return method.invoke(other, args);
} catch (InvocationTargetException ex) {
throw ex.getCause();
}
}
}
};
clazz.getField("_instance").set(instance, invoker);
System.out.println(instance.some());
System.out.println(instance.testConcern());
}
Aggregations