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:
+38
@@ -0,0 +1,38 @@
|
||||
call text: WithReflectionAccess result = Test.invoke();
|
||||
class:
|
||||
static class Test {
|
||||
static WithReflectionAccess invoke() {
|
||||
return newWithReflectionAccess1(50);
|
||||
}
|
||||
|
||||
public static WithReflectionAccess newWithReflectionAccess1(int value) {
|
||||
try {
|
||||
Class<?> klass = Class.forName("WithReflectionAccess");
|
||||
java.lang.reflect.Constructor<?> member = null;
|
||||
int interfaceNumber = -1;
|
||||
Class<?>[] interfaces = null;
|
||||
while (member == null) {
|
||||
try {
|
||||
member = klass.getDeclaredConstructor(int.class);
|
||||
} 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 (WithReflectionAccess) member.newInstance(value);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
call text: new Test(instance).invoke();
|
||||
class:
|
||||
static class Test {
|
||||
private WithReflectionAccess instance;
|
||||
|
||||
public Test(WithReflectionAccess instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public static int accessToFieldField1(Object object, Object value) {
|
||||
try {
|
||||
Class<?> klass = Class.forName("WithReflectionAccess");
|
||||
java.lang.reflect.Field member = null;
|
||||
int interfaceNumber = -1;
|
||||
Class<?>[] interfaces = null;
|
||||
while (member == null) {
|
||||
try {
|
||||
member = klass.getDeclaredField("field");
|
||||
} 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 (int) member.get(object);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void invoke() {
|
||||
System.out.println(accessToFieldField1(instance, null));
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
call text: Test.invoke();
|
||||
class:
|
||||
static class Test {
|
||||
static void invoke() {
|
||||
callMethod1(null);
|
||||
}
|
||||
|
||||
public static void callMethod1(Object object) {
|
||||
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");
|
||||
} 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);
|
||||
member.invoke(object);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
call text: Test.invoke();
|
||||
class:
|
||||
static class Test {
|
||||
static void invoke() {
|
||||
apply(() -> callMethod1(null));
|
||||
}
|
||||
|
||||
public static void callMethod1(Object object) {
|
||||
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");
|
||||
} 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);
|
||||
member.invoke(object);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+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);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
call text: int result = new Test(instance).invoke();
|
||||
class:
|
||||
static class Test {
|
||||
private WithReflectionAccess instance;
|
||||
|
||||
public Test(WithReflectionAccess instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public static int callMethod1(Object object, int 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", int.class);
|
||||
} 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 (int) member.invoke(object, arg);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int invoke() {
|
||||
return callMethod1(instance, 42);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
call text: int result = new Test(instance).invoke();
|
||||
class:
|
||||
static class Test {
|
||||
private WithReflectionAccess instance;
|
||||
|
||||
public Test(WithReflectionAccess instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public static int accessToFieldField1(Object object, Object value) {
|
||||
try {
|
||||
Class<?> klass = Class.forName("WithReflectionAccess");
|
||||
java.lang.reflect.Field member = null;
|
||||
int interfaceNumber = -1;
|
||||
Class<?>[] interfaces = null;
|
||||
while (member == null) {
|
||||
try {
|
||||
member = klass.getDeclaredField("field");
|
||||
} 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 (int) member.get(object);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static int accessToFieldField2(Object object, Object value) {
|
||||
try {
|
||||
Class<?> klass = Class.forName("WithReflectionAccess");
|
||||
java.lang.reflect.Field member = null;
|
||||
int interfaceNumber = -1;
|
||||
Class<?>[] interfaces = null;
|
||||
while (member == null) {
|
||||
try {
|
||||
member = klass.getDeclaredField("field");
|
||||
} 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 (int) member.get(object);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int invoke() {
|
||||
return accessToFieldField1(instance, null) + accessToFieldField2(instance, null);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
call text: new Test(instance).invoke();
|
||||
class:
|
||||
static class Test {
|
||||
private WithReflectionAccess instance;
|
||||
|
||||
public Test(WithReflectionAccess instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public static void accessToFieldField1(Object object, Object value) {
|
||||
try {
|
||||
Class<?> klass = Class.forName("WithReflectionAccess");
|
||||
java.lang.reflect.Field member = null;
|
||||
int interfaceNumber = -1;
|
||||
Class<?>[] interfaces = null;
|
||||
while (member == null) {
|
||||
try {
|
||||
member = klass.getDeclaredField("field");
|
||||
} 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);
|
||||
member.set(object, value);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void invoke() {
|
||||
accessToFieldField1(instance, 50);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user