mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-172425 Add tests to check that generated code is correct
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
call text: Object result = new Test(instance).invoke();
|
||||
class:
|
||||
static class Test {
|
||||
private WithReflectionAccess instance;
|
||||
|
||||
public Test(WithReflectionAccess instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public static Object callMethod1(Object object, WithReflectionAccess arg) {
|
||||
try {
|
||||
Class<?> klass = Class.forName("WithReflectionAccess");
|
||||
java.lang.reflect.Method member = null;
|
||||
int interfaceNumber = -1;
|
||||
Class<?>[] interfaces = null;
|
||||
while (member == null) {
|
||||
try {
|
||||
member = klass.getDeclaredMethod("method", Class.forName("WithReflectionAccess"));
|
||||
} catch (ReflectiveOperationException e) {
|
||||
if (interfaceNumber == -1) {
|
||||
interfaces = klass.getInterfaces();
|
||||
interfaceNumber = 0;
|
||||
}
|
||||
if (interfaceNumber < interfaces.length) {
|
||||
klass = interfaces[interfaceNumber];
|
||||
interfaceNumber += 1;
|
||||
} else {
|
||||
klass = klass.getSuperclass();
|
||||
if (klass == null) throw e;
|
||||
interfaceNumber = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
member.setAccessible(true);
|
||||
return (Object) member.invoke(object, arg);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object invoke() {
|
||||
return callMethod1(instance, instance);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user