renamed all modules

This commit is contained in:
Andy Clement
2014-01-15 11:36:24 -08:00
parent 342420b2ed
commit ceef61cf98
1055 changed files with 301 additions and 259 deletions

View File

@@ -0,0 +1,129 @@
package reflection;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import reflection.targets.ClassTarget;
/**
* A rather 'add-hoc' created ClassInvoker containing various bits and pieces of reflective code that calls (mostly) methods in the
* class API.
* <p>
* This is renamed from 'ClassInvoker' which has since been replaced with a more systematic 'generated' Invoker class.
*
* @author kdvolder
*/
public class AdHocClassInvoker {
static ClassTarget t = new ClassTarget();
public Field callGetDeclaredField(Class<?> clazz, String fieldName) throws Exception {
return clazz.getDeclaredField(fieldName);
}
public Field callGetDeclaredFieldForThisName(Class<?> clazz, String name) throws Exception {
Field f = clazz.getDeclaredField(name);
return f;
}
public List<Field> callClassGetDeclaredFields(Class<?> clazz) throws Exception {
return Arrays.asList(clazz.getDeclaredFields());
}
public List<Field> callClassGetFields(Class<?> clazz) throws Exception {
return Arrays.asList(clazz.getFields());
}
public int callClassGetModifiers(Class<?> clazz) throws Exception {
System.out.println(clazz);
System.out.println(clazz.getModifiers());
return clazz.getModifiers();
}
public Field callClassGetField(Class<?> clazz, String name) throws Exception {
return clazz.getField(name);
}
public Field callClassGetDeclaredField(Class<?> clazz, String name) throws Exception {
return clazz.getDeclaredField(name);
}
public Method callGetDeclaredMethod(Class<?> clazz, String name, Class<?>... params) throws Exception {
return clazz.getDeclaredMethod(name, params);
}
public Method callGetDeclaredMethodForThisName(Class<?> clazz, String name, Class<?>... paramTypes) throws Exception {
Method m = clazz.getDeclaredMethod(name, paramTypes);
return m;
}
public List<Method> callGetDeclaredMethods(Class<?> clazz) throws Exception {
return Arrays.asList(clazz.getDeclaredMethods());
}
public List<Method> callGetMethods(Class<?> clazz) throws Exception {
return Arrays.asList(clazz.getMethods());
}
public Method callGetMethod(Class<?> clazz, String name, Class<?>... params) throws SecurityException, NoSuchMethodException {
return clazz.getMethod(name, params);
}
public Constructor<?> callGetDeclaredConstructor(Class<?> clazz, Class<?>... params) throws SecurityException,
NoSuchMethodException {
return clazz.getDeclaredConstructor(params);
}
public Constructor<?>[] callGetDeclaredConstructors(Class<?> clazz) throws SecurityException, NoSuchMethodException {
return clazz.getDeclaredConstructors();
}
public <T> T callNewInstance(Constructor<T> ctor, Object... params) throws IllegalArgumentException, InstantiationException,
IllegalAccessException, InvocationTargetException {
return ctor.newInstance(params);
}
/**
* Calls private method in reloadable class, can override access constraints if requested to do so.
*/
public String callMethodWithAccess(String whichMethod, boolean setAccess) throws Exception {
Method theMethod = ClassTarget.class.getDeclaredMethod(whichMethod);
if (setAccess) {
theMethod.setAccessible(true);
}
return (String) theMethod.invoke(t);
}
public Object getFieldValue(Field f) throws Exception {
return f.get(t);
}
public Object runThisMethod(Method m) throws Exception {
return m.invoke(t);
}
public Object runThisMethodOn(Object t, Method m, Object... args) throws Exception {
return m.invoke(t, args);
}
public Object runThisMethodWithParam(Method m, Object[] params) throws Exception {
return m.invoke(t, params);
}
public void setFieldValue(Field f, Object newValue) throws Exception {
f.set(t, newValue);
}
public boolean callMethodIsSynthetic(Method m) {
return m.isSynthetic();
}
public boolean callMethodIsBridge(Method m) {
return m.isBridge();
}
}

View File

@@ -0,0 +1,8 @@
package reflection;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface AnnoT {
}

View File

@@ -0,0 +1,8 @@
package reflection;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface AnnoT2 {
}

View File

@@ -0,0 +1,9 @@
package reflection;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface AnnoT3 {
String value();
}

View File

@@ -0,0 +1,11 @@
package reflection;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Inherited
@Retention(RetentionPolicy.RUNTIME)
public @interface AnnoTInherit {
String value();
}

View File

@@ -0,0 +1,127 @@
package reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A class that provides method containing test code that calls different reflective methods related to annotations.
*
* @author kdvolder
*/
public class AnnotationsInvoker {
///////////////////////////////////////////
// AnnotatedElement
public List<Annotation> callAnnotatedElementGetAnnotations(AnnotatedElement m) {
return Arrays.asList(m.getAnnotations());
}
public List<Annotation> callAnnotatedElementGetDeclaredAnnotations(AnnotatedElement m) {
return Arrays.asList(m.getDeclaredAnnotations());
}
public Annotation callAnnotatedElementGetAnnotation(AnnotatedElement m, Class<? extends Annotation> annotClass) {
return m.getAnnotation(annotClass);
}
public boolean callAnnotatedElementIsAnnotationPresent(AnnotatedElement m, Class<? extends Annotation> annotClass) {
return m.isAnnotationPresent(annotClass);
}
///////////////////////////////////////////
// AccessibleObject
public List<Annotation> callAccessibleObjectGetAnnotations(AccessibleObject m) {
return Arrays.asList(m.getAnnotations());
}
public List<Annotation> callAccessibleObjectGetDeclaredAnnotations(AccessibleObject m) {
return Arrays.asList(m.getDeclaredAnnotations());
}
public Annotation callAccessibleObjectGetAnnotation(AccessibleObject m, Class<? extends Annotation> annotClass) {
return m.getAnnotation(annotClass);
}
public boolean callAccessibleObjectIsAnnotationPresent(AccessibleObject m, Class<? extends Annotation> annotClass) {
return m.isAnnotationPresent(annotClass);
}
///////////////////////////////////////////
// Method
public List<Annotation> callMethodGetAnnotations(Method m) {
return Arrays.asList(m.getAnnotations());
}
public List<Annotation> callMethodGetDeclaredAnnotations(Method m) {
return Arrays.asList(m.getDeclaredAnnotations());
}
public boolean callMethodIsAnnotationPresent(Method m, Class<? extends Annotation> annotClass) {
return m.isAnnotationPresent(annotClass);
}
public Annotation callMethodGetAnnotation(Method m, Class<? extends Annotation> annotClass) {
return m.getAnnotation(annotClass);
}
public List<List<Annotation>> callMethodGetParameterAnnotations(Method m) {
Annotation[][] array = m.getParameterAnnotations();
List<List<Annotation>> result = new ArrayList<List<Annotation>>(array.length);
for (int i = 0; i < array.length; i++) {
result.add(Arrays.asList(array[i]));
}
return result;
}
///////////////////////////////////////////
// Constructor
public List<Annotation> callConstructorGetAnnotations(Constructor<?> m) {
return Arrays.asList(m.getAnnotations());
}
public List<Annotation> callConstructorGetDeclaredAnnotations(Constructor<?> m) {
return Arrays.asList(m.getDeclaredAnnotations());
}
public boolean callConstructorIsAnnotationPresent(Constructor<?> m, Class<? extends Annotation> annotClass) {
return m.isAnnotationPresent(annotClass);
}
public Annotation callConstructorGetAnnotation(Constructor<?> m, Class<? extends Annotation> annotClass) {
return m.getAnnotation(annotClass);
}
public List<List<Annotation>> callConstructorGetParameterAnnotations(Constructor<?> m) {
Annotation[][] array = m.getParameterAnnotations();
List<List<Annotation>> result = new ArrayList<List<Annotation>>(array.length);
for (int i = 0; i < array.length; i++) {
result.add(Arrays.asList(array[i]));
}
return result;
}
///////////////////////////////////////////
// Field
public List<Annotation> callFieldGetAnnotations(Field m) {
return Arrays.asList(m.getAnnotations());
}
public List<Annotation> callFieldGetDeclaredAnnotations(Field m) {
return Arrays.asList(m.getDeclaredAnnotations());
}
public boolean callFieldIsAnnotationPresent(Field m, Class<? extends Annotation> annotClass) {
return m.isAnnotationPresent(annotClass);
}
public Annotation callFieldGetAnnotation(Field m, Class<? extends Annotation> annotClass) {
return m.getAnnotation(annotClass);
}
///////////////////////////////////////////
// Class
public List<Annotation> callClassGetAnnotations(Class<?> c) {
return Arrays.asList(c.getAnnotations());
}
public List<Annotation> callClassGetDeclaredAnnotations(Class<?> c) {
return Arrays.asList(c.getDeclaredAnnotations());
}
public boolean callClassIsAnnotationPresent(Class<?> c, Class<? extends Annotation> annotClass) {
return c.isAnnotationPresent(annotClass);
}
public Annotation callClassGetAnnotation(Class<?> c, Class<? extends Annotation> annotClass) {
return c.getAnnotation(annotClass);
}
}

View File

@@ -0,0 +1,8 @@
package reflection;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.CLASS)
public @interface CTAnnoT {
}

View File

@@ -0,0 +1,329 @@
package reflection;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.Arrays;
import java.util.List;
/**
* Class containing one method for each method in the java.lang.Class
* containing code calling that method.
* <p>
* Initial version generated with {@link InvokerGenerator} but afterwards
* edited to:
*
* - wrap returned arrays into lists for easier testing and nicer toStrings
*
*/
@SuppressWarnings({"unchecked","rawtypes"})public class ClassInvoker{
public static Class callAsSubclass(Class thiz, Class a0)
{
return thiz.asSubclass(a0);
}
public static Object callCast(Class thiz, Object a0)
{
return thiz.cast(a0);
}
public static boolean callDesiredAssertionStatus(Class thiz)
{
return thiz.desiredAssertionStatus();
}
public static Class callForName(String a0)
throws ClassNotFoundException
{
return Class.forName(a0);
}
public static Class callForName(String a0, boolean a1, ClassLoader a2)
throws ClassNotFoundException
{
return Class.forName(a0, a1, a2);
}
public static Annotation callGetAnnotation(Class thiz, Class a0)
{
return thiz.getAnnotation(a0);
}
public static Annotation[] callGetAnnotations(Class thiz)
{
return thiz.getAnnotations();
}
public static String callGetCanonicalName(Class thiz)
{
return thiz.getCanonicalName();
}
public static Class[] callGetClasses(Class thiz)
{
return thiz.getClasses();
}
public static ClassLoader callGetClassLoader(Class thiz)
{
return thiz.getClassLoader();
}
public static Class callGetComponentType(Class thiz)
{
return thiz.getComponentType();
}
public static Constructor callGetConstructor(Class thiz, Class[] a0)
throws NoSuchMethodException, SecurityException
{
return thiz.getConstructor(a0);
}
public static List<Constructor> callGetConstructors(Class thiz)
throws SecurityException
{
return Arrays.asList(thiz.getConstructors());
}
public static Annotation[] callGetDeclaredAnnotations(Class thiz)
{
return thiz.getDeclaredAnnotations();
}
public static Class[] callGetDeclaredClasses(Class thiz)
throws SecurityException
{
return thiz.getDeclaredClasses();
}
public static Constructor callGetDeclaredConstructor(Class thiz, Class[] a0)
throws NoSuchMethodException, SecurityException
{
return thiz.getDeclaredConstructor(a0);
}
public static List<Constructor> callGetDeclaredConstructors(Class thiz)
throws SecurityException
{
return Arrays.asList(thiz.getDeclaredConstructors());
}
public static Field callGetDeclaredField(Class thiz, String a0)
throws NoSuchFieldException, SecurityException
{
return thiz.getDeclaredField(a0);
}
public static List<Field> callGetDeclaredFields(Class thiz)
throws SecurityException
{
return Arrays.asList(thiz.getDeclaredFields());
}
public static Method callGetDeclaredMethod(Class thiz, String a0, Class[] a1)
throws NoSuchMethodException, SecurityException
{
return thiz.getDeclaredMethod(a0, a1);
}
public static List<Method> callGetDeclaredMethods(Class thiz)
throws SecurityException
{
return Arrays.asList(thiz.getDeclaredMethods());
}
public static Class callGetDeclaringClass(Class thiz)
{
return thiz.getDeclaringClass();
}
public static Class callGetEnclosingClass(Class thiz)
{
return thiz.getEnclosingClass();
}
public static Constructor callGetEnclosingConstructor(Class thiz)
{
return thiz.getEnclosingConstructor();
}
public static Method callGetEnclosingMethod(Class thiz)
{
return thiz.getEnclosingMethod();
}
public static Object[] callGetEnumConstants(Class thiz)
{
return thiz.getEnumConstants();
}
public static Field callGetField(Class thiz, String a0)
throws NoSuchFieldException, SecurityException
{
return thiz.getField(a0);
}
public static List<Field> callGetFields(Class thiz)
throws SecurityException
{
return Arrays.asList(thiz.getFields());
}
public static Type[] callGetGenericInterfaces(Class thiz)
{
return thiz.getGenericInterfaces();
}
public static Type callGetGenericSuperclass(Class thiz)
{
return thiz.getGenericSuperclass();
}
public static Class[] callGetInterfaces(Class thiz)
{
return thiz.getInterfaces();
}
public static Method callGetMethod(Class thiz, String a0, Class[] a1)
throws NoSuchMethodException, SecurityException
{
return thiz.getMethod(a0, a1);
}
public static List<Method> callGetMethods(Class thiz)
throws SecurityException
{
return Arrays.asList(thiz.getMethods());
}
public static int callGetModifiers(Class thiz)
{
return thiz.getModifiers();
}
public static String callGetName(Class thiz)
{
return thiz.getName();
}
public static Package callGetPackage(Class thiz)
{
return thiz.getPackage();
}
public static ProtectionDomain callGetProtectionDomain(Class thiz)
{
return thiz.getProtectionDomain();
}
public static URL callGetResource(Class thiz, String a0)
{
return thiz.getResource(a0);
}
public static InputStream callGetResourceAsStream(Class thiz, String a0)
{
return thiz.getResourceAsStream(a0);
}
public static Object[] callGetSigners(Class thiz)
{
return thiz.getSigners();
}
public static String callGetSimpleName(Class thiz)
{
return thiz.getSimpleName();
}
public static Class callGetSuperclass(Class thiz)
{
return thiz.getSuperclass();
}
public static TypeVariable[] callGetTypeParameters(Class thiz)
{
return thiz.getTypeParameters();
}
public static boolean callIsAnnotation(Class thiz)
{
return thiz.isAnnotation();
}
public static boolean callIsAnnotationPresent(Class thiz, Class a0)
{
return thiz.isAnnotationPresent(a0);
}
public static boolean callIsAnonymousClass(Class thiz)
{
return thiz.isAnonymousClass();
}
public static boolean callIsArray(Class thiz)
{
return thiz.isArray();
}
public static boolean callIsAssignableFrom(Class thiz, Class a0)
{
return thiz.isAssignableFrom(a0);
}
public static boolean callIsEnum(Class thiz)
{
return thiz.isEnum();
}
public static boolean callIsInstance(Class thiz, Object a0)
{
return thiz.isInstance(a0);
}
public static boolean callIsInterface(Class thiz)
{
return thiz.isInterface();
}
public static boolean callIsLocalClass(Class thiz)
{
return thiz.isLocalClass();
}
public static boolean callIsMemberClass(Class thiz)
{
return thiz.isMemberClass();
}
public static boolean callIsPrimitive(Class thiz)
{
return thiz.isPrimitive();
}
public static boolean callIsSynthetic(Class thiz)
{
return thiz.isSynthetic();
}
public static Object callNewInstance(Class thiz)
throws InstantiationException, IllegalAccessException
{
return thiz.newInstance();
}
public static String callToString(Class thiz)
{
return thiz.toString();
}
}

View File

@@ -0,0 +1,104 @@
package reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.List;
@SuppressWarnings({ "rawtypes" })
public class ConstructorInvoker {
///////////////////////////////////////////////////////////////////////////////////
/// Section below contains an invoker for each method on the Constructor class
//TODO: [refl] tests calling this
public static boolean callEquals(Constructor thiz, Object a0) {
return thiz.equals(a0);
}
//TODO: [refl] tests calling this
public static String callToString(Constructor thiz) {
return thiz.toString();
}
//TODO: [refl] tests calling this
public static int callHashCode(Constructor thiz) {
return thiz.hashCode();
}
public static int callGetModifiers(Constructor thiz) {
return thiz.getModifiers();
}
public static String callGetName(Constructor thiz) {
return thiz.getName();
}
// See AnnotationsInvoker
// public static Annotation callGetAnnotation(Constructor thiz, Class a0)
// {
// return thiz.getAnnotation(a0);
// }
//
// public static Annotation[] callGetDeclaredAnnotations(Constructor thiz)
// {
// return thiz.getDeclaredAnnotations();
// }
public static Class callGetDeclaringClass(Constructor thiz) {
return thiz.getDeclaringClass();
}
public static Class[] callGetParameterTypes(Constructor thiz) {
return thiz.getParameterTypes();
}
public static TypeVariable[] callGetTypeParameters(Constructor thiz) {
return thiz.getTypeParameters();
}
public static boolean callIsSynthetic(Constructor thiz) {
return thiz.isSynthetic();
}
public static Object callNewInstance(Constructor thiz, Object[] a0) throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
return thiz.newInstance(a0);
}
public static String callToGenericString(Constructor thiz) {
return thiz.toGenericString();
}
public static Class[] callGetExceptionTypes(Constructor thiz) {
return thiz.getExceptionTypes();
}
public static List<Type> callGetGenericExceptionTypes(Constructor thiz) {
return Arrays.asList(thiz.getGenericExceptionTypes());
}
public static Type[] callGetGenericParameterTypes(Constructor thiz) {
return thiz.getGenericParameterTypes();
}
public static Annotation[][] callGetParameterAnnotations(Constructor thiz) {
return thiz.getParameterAnnotations();
}
public static boolean callIsVarArgs(Constructor thiz) {
return thiz.isVarArgs();
}
///////////////////////////////////////////////////////////////////////////////////
/// Section below contains 'Ad-Hoc' invokers. Used in testing related
/// functionality
public static String callClassNewInstance(Class<?> clazz) throws InstantiationException, IllegalAccessException {
return clazz.newInstance().toString();
}
}

View File

@@ -0,0 +1,224 @@
package reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
@SuppressWarnings({ "unchecked" })
public class FieldInvoker {
public static boolean callEquals(Field thiz, Object a0) {
return thiz.equals(a0);
}
public static String callToString(Field thiz) {
return thiz.toString();
}
public static int callHashCode(Field thiz) {
return thiz.hashCode();
}
public static int callGetModifiers(Field thiz) {
return thiz.getModifiers();
}
public static String callToGenericString(Field thiz) {
return thiz.toGenericString();
}
public static Object callGet(Field thiz, Object o) throws IllegalArgumentException, IllegalAccessException {
return thiz.get(o);
}
public static long callSetAndGetLong(Field thiz, Object o) throws IllegalArgumentException, IllegalAccessException {
thiz.setLong(o, thiz.getLong(o));
return thiz.getLong(o);
}
public static short callSetAndGetShort(Field thiz, Object o) throws IllegalArgumentException, IllegalAccessException {
thiz.setShort(o, (short) (thiz.getShort(o) + 1));
return thiz.getShort(o);
}
public static boolean callSetAndGetBoolean(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setBoolean(obj, !thiz.getBoolean(obj));
return thiz.getBoolean(obj);
}
public static byte callSetAndGetByte(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setByte(obj, (byte) (thiz.getByte(obj) + 1));
return thiz.getByte(obj);
}
public static char callSetAndGetChar(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setChar(obj, (char) (thiz.getChar(obj) + 1));
return thiz.getChar(obj);
}
public static int callSetAndGetInt(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setInt(obj, thiz.getInt(obj) + 1);
return thiz.getInt(obj);
}
public static float callSetAndGetFloat(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setFloat(obj, (float) (thiz.getFloat(obj) + 1.5));
return thiz.getFloat(obj);
}
public static double callSetAndGetDouble(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setDouble(obj, thiz.getDouble(obj) + 1.5);
return thiz.getDouble(obj);
}
public static long callSetLong(Field thiz, Object o) throws IllegalArgumentException, IllegalAccessException {
thiz.setLong(o, 12345);
return thiz.getLong(o);
}
public static short callSetShort(Field thiz, Object o) throws IllegalArgumentException, IllegalAccessException {
thiz.setShort(o, (short) 1234);
return thiz.getShort(o);
}
public static boolean callSetBoolean(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setBoolean(obj, true);
return thiz.getBoolean(obj);
}
public static byte callSetByte(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setByte(obj, (byte) 123);
return thiz.getByte(obj);
}
public static char callSetChar(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setChar(obj, 'Y');
return thiz.getChar(obj);
}
public static int callSetInt(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setInt(obj, 1234);
return thiz.getInt(obj);
}
public static float callSetFloat(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setFloat(obj, (float) 1.234);
return thiz.getFloat(obj);
}
public static double callSetDouble(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.setDouble(obj, 1.234);
return thiz.getDouble(obj);
}
public static String callGetName(Field thiz) {
return thiz.getName();
}
public static Annotation callGetAnnotation(Field thiz, Class<? extends Annotation> a0) {
return thiz.getAnnotation(a0);
}
public static Annotation[] callGetDeclaredAnnotations(Field thiz) {
return thiz.getDeclaredAnnotations();
}
public static Class<?> callGetDeclaringClass(Field thiz) {
return thiz.getDeclaringClass();
}
public static boolean callIsSynthetic(Field thiz) {
return thiz.isSynthetic();
}
public static Type callGetGenericType(Field thiz) {
return thiz.getGenericType();
}
public static Class<?> callGetType(Field thiz) {
return thiz.getType();
}
public static boolean callIsEnumConstant(Field thiz) {
return thiz.isEnumConstant();
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// Methods below don't correspond directly to a single method in the Field type, but do a bunch of things at
/// once.
/**
* Gets a field in class, can override access constraints if requested to do so.
*/
public String getFieldWithAccess(Class<?> targetClass, String whichField, boolean setAccess) throws Exception {
Object targetInstance = targetClass.newInstance();
Field field = targetClass.getDeclaredField(whichField);
if (setAccess) {
field.setAccessible(true);
}
return (String) field.get(targetInstance);
}
/**
* Sets a field in class, can override access constraints if requested to do so.
*/
public void setFieldWithAccess(Class<?> targetClass, String whichField, boolean setAccess) throws Exception {
Object targetInstance = targetClass.newInstance();
Field field = targetClass.getDeclaredField(whichField);
if (setAccess) {
field.setAccessible(true);
}
// Not checking for type errors in this test, make sure we set correct type of value
if (field.getType().equals(int.class)) {
field.set(targetInstance, 888);
} else {
field.set(targetInstance, "<BANG>");
}
}
/**
* Sets and gets a field in so we can see if the value was actually set.
*/
public String setAndGetFieldWithAccess(Class<?> targetClass, String whichField, boolean setAccess) throws Exception {
Object targetInstance = targetClass.newInstance();
Field field = targetClass.getDeclaredField(whichField);
if (setAccess) {
field.setAccessible(true);
}
String orgVal = (String) field.get(targetInstance);
field.set(targetInstance, orgVal + "<BANG>");
return (String) field.get(targetInstance);
}
public static Object callSetAndGet(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.set(obj, thiz.get(obj) + "<BANG>");
return thiz.get(obj);
}
public static Object callSetNull(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
thiz.set(obj, null);
return thiz.get(obj);
}
public static Object callSetUnboxAndGet(Field thiz, Object obj) throws IllegalArgumentException, IllegalAccessException {
Object val = thiz.get(obj);
if (val instanceof Integer) {
thiz.set(obj, ((Integer) val) + 1);
} else if (val instanceof Boolean) {
thiz.set(obj, !((Boolean) val));
} else if (val instanceof Float) {
thiz.set(obj, new Float(((Float) val) + 1.5));
} else if (val instanceof Double) {
thiz.set(obj, new Double(((Double) val) + 1.5));
} else if (val instanceof SubTestVal) {
//Try to put a value of a super type instead
thiz.set(obj, TestVal.it);
} else if (val instanceof TestVal) {
//Try to put a value of a sub type instead
thiz.set(obj, SubTestVal.it);
}
// Could add other primitive type cases but this is probably ok
return thiz.get(obj);
}
}

Binary file not shown.

View File

@@ -0,0 +1,334 @@
package reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
public class Invoker {
static Field f_i; // int
static Field f_z; // boolean
static Field f_zarray; // boolean[]
static Field f_is; // static int
static Field f_b; // byte
static Field f_c; // char
static Field f_s; // short
static Field f_j; // long
static Field f_f; // float
static Field f_d; // double
static Field f_l; // reference (String)
static Field f_annotated; // annotated field
static Target t = new Target();
{
try {
f_i = Target.class.getDeclaredField("i");
f_z = Target.class.getDeclaredField("z");
f_zarray = Target.class.getDeclaredField("zs");
f_is = Target.class.getDeclaredField("is");
f_b = Target.class.getDeclaredField("b");
f_c = Target.class.getDeclaredField("c");
f_s = Target.class.getDeclaredField("s");
f_j = Target.class.getDeclaredField("j");
f_f = Target.class.getDeclaredField("f");
f_d = Target.class.getDeclaredField("d");
f_l = Target.class.getDeclaredField("l");
f_annotated = Target.class.getDeclaredField("annotated");
} catch (Exception e) {
e.printStackTrace();
}
}
// int
public void setI() throws Exception {
f_i.set(t, 42);
}
public void setIntI() throws Exception {
f_i.setInt(t, 45);
}
public int getI() {
return t.i;
}
public int getReflectI() throws Exception {
return f_i.getInt(t);
}
public int getReflectObjectI() throws Exception {
return (Integer) f_i.get(t);
}
// --- boolean
public void setZ() throws Exception {
f_z.setAccessible(true);
f_z.set(t, true);
}
public void setIntZ() throws Exception {
f_z.setAccessible(true);
f_z.setBoolean(t, false);
}
public boolean getZ() {
return t.z;
}
public boolean getReflectZ() throws Exception {
return f_z.getBoolean(t);
}
public boolean getReflectObjectZ() throws Exception {
return (Boolean) f_z.get(t);
}
// --- byte
public void setB() throws Exception {
f_b.setAccessible(true);
f_b.set(t, (byte) 65);
}
public void setIllegalB() throws Exception {
f_b.setAccessible(true);
f_b.set(t, 32); // cannot supply int
}
public void setByteB() throws Exception {
f_b.setAccessible(true);
f_b.setByte(t, (byte) 70);
}
public byte getB() {
return t.b;
}
public byte getReflectB() throws Exception {
return f_b.getByte(t);
}
public byte getReflectObjectB() throws Exception {
return (Byte) f_b.get(t);
}
// --- char
public void setC() throws Exception {
f_c.setAccessible(true);
f_c.set(t, (char) 66);
}
public void setIllegalC() throws Exception {
f_c.setAccessible(true);
f_c.set(t, 32); // cannot supply int
}
public void setCharC() throws Exception {
f_c.setAccessible(true);
f_c.setChar(t, (char) 77);
}
public char getC() {
return t.c;
}
public char getReflectC() throws Exception {
return f_c.getChar(t);
}
public char getReflectObjectC() throws Exception {
return (Character) f_c.get(t);
}
// --- short
public void setS() throws Exception {
f_s.setAccessible(true);
f_s.set(t, (short) 660);
}
public void setIllegalS() throws Exception {
f_s.setAccessible(true);
f_s.set(t, 32); // cannot supply int
}
public void setShortS() throws Exception {
f_s.setAccessible(true);
f_s.setShort(t, (short) 77);
}
public short getS() {
return t.s;
}
public short getReflectS() throws Exception {
return f_s.getShort(t);
}
public short getReflectObjectS() throws Exception {
return (Short) f_s.get(t);
}
// --- long
public void setJ() throws Exception {
f_j.setAccessible(true);
f_j.set(t, (long) 660);
}
public void setIllegalJ() throws Exception {
f_j.setAccessible(true);
f_j.set(t, 32); // cannot supply int
}
public void setLongJ() throws Exception {
f_j.setAccessible(true);
f_j.setLong(t, (long) 77);
}
public long getJ() {
return t.j;
}
public long getReflectJ() throws Exception {
return f_j.getLong(t);
}
public long getReflectObjectJ() throws Exception {
return (Long) f_j.get(t);
}
// --- float
public void setF() throws Exception {
f_f.setAccessible(true);
f_f.set(t, (float) 660);
}
public void setIllegalF() throws Exception {
f_f.setAccessible(true);
f_f.set(t, 32); // cannot supply int
}
public void setFloatF() throws Exception {
f_f.setAccessible(true);
f_f.setFloat(t, (float) 77);
}
public float getF() {
return t.f;
}
public float getReflectF() throws Exception {
return f_f.getFloat(t);
}
public float getReflectObjectF() throws Exception {
return (Float) f_f.get(t);
}
// --- static int field
public void setIS() throws Exception {
f_is.setAccessible(true);
f_is.set(t, (int) 660);
}
public void setIllegalIS() throws Exception {
f_is.setAccessible(true);
f_is.set(t, "abc"); // cannot supply int
}
public void setintIS() throws Exception {
f_is.setAccessible(true);
f_is.setInt(t, (int) 77);
}
public int getIS() {
return Target.is;
}
public Integer getISInteger() {
return Target.is;
}
public Integer getReflectIS() throws Exception {
return f_is.getInt(t);
}
public Integer getReflectObjectIS() throws Exception {
return (Integer) f_is.get(t);
}
// --- double
public void setD() throws Exception {
f_d.setAccessible(true);
f_d.set(t, (double) 660);
}
public void setIllegalD() throws Exception {
f_d.setAccessible(true);
f_d.set(t, 32); // cannot supply int
}
public void setDoubleD() throws Exception {
f_d.setAccessible(true);
f_d.setDouble(t, (double) 77);
}
public double getD() {
return t.d;
}
public double getReflectD() throws Exception {
return f_d.getDouble(t);
}
public double getReflectObjectD() throws Exception {
return (Double) f_d.get(t);
}
// --- boolean array
public void setZArray() throws Exception {
f_zarray.setAccessible(true);
boolean[] bs = new boolean[] { true, false, true };
f_zarray.set(t, bs);
}
public void setIllegalZArray() throws Exception {
f_zarray.setAccessible(true);
f_zarray.set(t, 32); // cannot supply int
}
public boolean[] getZArray() {
return t.zs;
}
public boolean[] getReflectObjectZArray() throws Exception {
return (boolean[]) f_zarray.get(t);
}
// --- reference
public void setReference() throws Exception {
f_l.setAccessible(true);
f_l.set(t, "abcde");
}
public void setIllegalReference() throws Exception {
f_l.setAccessible(true);
f_l.set(t, 32); // cannot supply int
}
public String getReference() {
return t.l;
}
public String getReflectObjectReference() throws Exception {
return (String) f_l.get(t);
}
// ---
public Annotation getAnnotation(Class<? extends Annotation> clazz) {
return (Annotation) f_annotated.getAnnotation(clazz);
}
public Annotation[] getDeclaredAnnotations() {
return (Annotation[]) f_annotated.getDeclaredAnnotations();
}
}

View File

@@ -0,0 +1,32 @@
package reflection;
import java.lang.reflect.Field;
public class Invoker2 {
static Field f_zarray; // boolean[]
static Field f_f; // float
static Field f_d; // double
static Field f_l; // reference (String)
static Field f_annotated; // annotated field
static Target2 t = new Target2();
{
try {
f_zarray = Target2.class.getDeclaredField("zs");
f_f = Target2.class.getDeclaredField("f");
f_d = Target2.class.getDeclaredField("d");
f_l = Target2.class.getDeclaredField("l");
f_annotated = Target2.class.getDeclaredField("annotated");
} catch (Exception e) {
e.printStackTrace();
}
}
public String setString() throws Exception {
f_l.setAccessible(true);
f_l.set(t, "wibble");
return (String) f_l.get(t);
}
}

View File

@@ -0,0 +1,106 @@
package reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.List;
/**
* Class containing one method for each method in the java.lang.reflect.Method containing code calling that method.
*/
@SuppressWarnings({ "unchecked" })
public class MethodInvoker {
public static Object callInvoke(Method thiz, Object a0, Object[] a1) throws IllegalAccessException, IllegalArgumentException,
InvocationTargetException {
return thiz.invoke(a0, a1);
}
public static boolean callEquals(Method thiz, Object a0) {
return thiz.equals(a0);
}
public static String callToString(Method thiz) {
return thiz.toString();
}
public static int callHashCode(Method thiz) {
return thiz.hashCode();
}
public static int callGetModifiers(Method thiz) {
return thiz.getModifiers();
}
public static String callGetName(Method thiz) {
return thiz.getName();
}
public static Annotation callGetAnnotation(Method thiz, Class<? extends Annotation> a0) {
return thiz.getAnnotation(a0);
}
public static Annotation[] callGetDeclaredAnnotations(Method thiz) {
return thiz.getDeclaredAnnotations();
}
public static Class<?> callGetDeclaringClass(Method thiz) {
return thiz.getDeclaringClass();
}
public static Class<?>[] callGetParameterTypes(Method thiz) {
return thiz.getParameterTypes();
}
public static Class<?> callGetReturnType(Method thiz) {
return thiz.getReturnType();
}
public static List<TypeVariable<Method>> callGetTypeParameters(Method thiz) {
return Arrays.asList(thiz.getTypeParameters());
}
public static boolean callIsSynthetic(Method thiz) {
return thiz.isSynthetic();
}
public static String callToGenericString(Method thiz) {
return thiz.toGenericString();
}
public static Object callGetDefaultValue(Method thiz) {
return thiz.getDefaultValue();
}
public static List<Class<?>> callGetExceptionTypes(Method thiz) {
return Arrays.asList(thiz.getExceptionTypes());
}
public static List<Type> callGetGenericExceptionTypes(Method thiz) {
return Arrays.asList(thiz.getGenericExceptionTypes());
}
public static List<Type> callGetGenericParameterTypes(Method thiz) {
return Arrays.asList(thiz.getGenericParameterTypes());
}
public static Type callGetGenericReturnType(Method thiz) {
return thiz.getGenericReturnType();
}
public static Annotation[][] callGetParameterAnnotations(Method thiz) {
return thiz.getParameterAnnotations();
}
public static boolean callIsBridge(Method thiz) {
return thiz.isBridge();
}
public static boolean callIsVarArgs(Method thiz) {
return thiz.isVarArgs();
}
}

View File

@@ -0,0 +1,21 @@
package reflection;
public class MethodTarget {
public int methodOne() {
return 35;
}
@AnnoT
public void methodAnnotated() {
}
@AnnoT
public void methodAnnotated2() {
}
public void methodAnnotated3(@AnnoT String s, @AnnoT2 int i, @AnnoT @AnnoT2 float f) {
}
}

View File

@@ -0,0 +1,27 @@
package reflection;
public class MethodTarget002 {
public int methodOne() {
return 37;
}
public int lateMethod() {
return 42;
}
@AnnoT2
@AnnoT
public void methodAnnotated() {
}
@AnnoT2
public void methodAnnotated2() {
}
// changed, deleted, reordered
public void methodAnnotated3(@AnnoT2 String s, int i, @AnnoT2 @AnnoT float f) {
}
}

View File

@@ -0,0 +1,9 @@
package reflection;
public class NonReloadableSuperClass {
public String interfaceMethod() {
return "NonReloadableSuperClass.interfaceMethod";
}
}

View File

@@ -0,0 +1,12 @@
package reflection;
public class SubTestVal extends TestVal {
public static final SubTestVal it = new SubTestVal();
@Override
public String toString() {
return "SubTestVal";
}
}

Binary file not shown.

View File

@@ -0,0 +1,20 @@
package reflection;
public class Target {
// public String s;
public int i;
public boolean[] zs;
public static Integer is;
boolean z;
byte b;
public short s;
char c;
public long j;
public float f;
double d;
public String l;
@AnnoT
public String annotated;
}

View File

@@ -0,0 +1,19 @@
package reflection;
public class Target002 {
// public String s;
public int i;
public boolean[] zs;
public Integer[] is;
boolean z;
byte b;
public short s;
char c;
public long j;
public float f;
double d;
@AnnoT2
public String annotated;
}

View File

@@ -0,0 +1,20 @@
package reflection;
public class Target2 {
// public String s;
public int i;
public boolean[] zs;
public static Integer is;
boolean z;
byte b;
public short s;
char c;
public long j;
public float f;
double d;
public String l;
@AnnoT
public String annotated;
}

View File

@@ -0,0 +1,19 @@
package reflection;
/**
* A class for testing, used in conjuntion with "SubTestVal", for tests requring
* instances of sub/supertypes (e.g. when testing the type checking contraints
* that should be imposed by reflective field set operations.
*
* @author kdvolder
*/
public class TestVal {
public static final TestVal it = new TestVal();
@Override
public String toString() {
return "TestVal";
}
}

View File

@@ -0,0 +1,10 @@
package reflection.bridgemethods;
public class ClassWithBridgeMethod implements Cloneable {
@Override
protected Object clone() throws CloneNotSupportedException {
return this;
}
}

View File

@@ -0,0 +1,10 @@
package reflection.bridgemethods;
public class ClassWithBridgeMethod002 implements Cloneable {
@Override
protected ClassWithBridgeMethod002 clone() throws CloneNotSupportedException {
return this;
}
}

View File

@@ -0,0 +1,9 @@
package reflection.classannotations;
import reflection.AnnoT;
import reflection.AnnoTInherit;
@AnnoTInherit("C000") @AnnoT
public class ClassTarget {
}

View File

@@ -0,0 +1,9 @@
package reflection.classannotations;
import reflection.AnnoT2;
import reflection.AnnoTInherit;
@AnnoTInherit("C002") @AnnoT2
public class ClassTarget002 {
}

View File

@@ -0,0 +1,8 @@
package reflection.classannotations;
import reflection.AnnoT3;
@AnnoT3("003")
public class ClassTarget003 {
}

View File

@@ -0,0 +1,10 @@
package reflection.classannotations;
import reflection.AnnoT;
import reflection.AnnoTInherit;
@AnnoTInherit("I001")
@AnnoT
public interface InterfaceTarget {
}

View File

@@ -0,0 +1,10 @@
package reflection.classannotations;
import reflection.AnnoT2;
import reflection.AnnoTInherit;
@AnnoTInherit("I002")
@AnnoT2
public interface InterfaceTarget002 {
}

View File

@@ -0,0 +1,9 @@
package reflection.classannotations;
import reflection.AnnoT3;
import reflection.AnnoTInherit;
@AnnoTInherit("I003") @AnnoT3("IT3")
public interface InterfaceTarget003 {
}

View File

@@ -0,0 +1,8 @@
package reflection.classannotations;
import reflection.AnnoTInherit;
@AnnoTInherit("S001")
public class SubClassTarget extends ClassTarget implements InterfaceTarget {
}

View File

@@ -0,0 +1,8 @@
package reflection.classannotations;
import reflection.AnnoTInherit;
@AnnoTInherit("S002")
public class SubClassTarget002 extends ClassTarget implements InterfaceTarget {
}

View File

@@ -0,0 +1,5 @@
package reflection.classannotations;
public class SubClassTarget003 extends ClassTarget implements InterfaceTarget {
}

View File

@@ -0,0 +1,8 @@
package reflection.classannotations;
import reflection.AnnoT;
@AnnoT
public interface SubInterfaceTarget extends InterfaceTarget {
}

View File

@@ -0,0 +1,8 @@
package reflection.classannotations;
import reflection.AnnoT2;
@AnnoT2
public interface SubInterfaceTarget002 extends InterfaceTarget {
}

View File

@@ -0,0 +1,5 @@
package reflection.classmodifiers;
public class ClassTarget {
}

View File

@@ -0,0 +1,8 @@
package reflection.classmodifiers;
//TODO: right now class modifiers are not supposed to change on a reload.
// If in the future we decide to allow changing class modifiers this test class's public modifier
// can be removed to test whether reflection API picks up on those changes
public class ClassTarget002 {
}

View File

@@ -0,0 +1,5 @@
package reflection.classmodifiers;
public class ClassTarget003 {
}

View File

@@ -0,0 +1,75 @@
package reflection.constructors;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* Test class with constructors, for the purpose of testing constructor invocation.
* <p>
* Constructors in this class have some behavior (which is changed in a reloaded class), so that we can see when they are
* being called.
*
* @author kdvolder
*/
public class ClassForNewInstance {
private boolean b;
private String s;
private int i;
private double d;
public ClassForNewInstance() {
System.out.println("no args");
}
ClassForNewInstance(String x) {
this.s = x;
System.out.println("string "+x);
}
protected ClassForNewInstance(int x) {
this.i = x;
System.out.println("int "+x);
}
@SuppressWarnings("unused")
private ClassForNewInstance(boolean x) {
this.b = x;
System.out.println("bool "+x);
}
//Becomes public
@SuppressWarnings("unused")
private ClassForNewInstance(int x, String y) {
this.i = x; this.s = y;
System.out.println("int String "+x+" "+y);
}
//Becomes private
public ClassForNewInstance(double x) {
this.d = x;
System.out.println("double "+x);
}
// Will be deleted
public ClassForNewInstance(char c, char d) {
s = c+","+d;
}
@Override
public String toString() {
// The value of toString is used by the test to check expected result... so
return "001{ "+b+", "+s+","+i+","+d+"}";
}
/// We also use this class itself as an "invoker" for testing, so that we have some cases where it *is* allowed
// to call private methods etc. without setAccessible!
public static Object callNewInstance(Constructor<?> thiz, Object[] a0)
throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
return thiz.newInstance(a0);
}
}

View File

@@ -0,0 +1,79 @@
package reflection.constructors;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
/**
* Test class with constructors, for the purpose of testing constructor invocation.
* <p>
* Constructors in this class have some behavior (which is changed in a reloaded class), so that we can see when they are
* being called.
*
* @author kdvolder
*/
public class ClassForNewInstance002 {
private boolean b;
private String s;
private int i;
private double d;
public ClassForNewInstance002() {
System.out.println("002 no args");
}
ClassForNewInstance002(String x) {
this.s = "002"+x;
System.out.println("002 string "+x);
}
protected ClassForNewInstance002(int x) {
this.i = x+200;
System.out.println("002 int "+x);
}
@SuppressWarnings("unused")
private ClassForNewInstance002(boolean x) {
this.b = !x;
System.out.println("002 bool "+x);
}
//Becomes public
public ClassForNewInstance002(int x, String y) {
this.i = 20+x; this.s = "222"+y;
System.out.println("002 int String "+x+" "+y);
}
//Becomes private
@SuppressWarnings("unused")
private ClassForNewInstance002(double x) {
System.out.println("002 double "+x);
}
//New public one
public ClassForNewInstance002(float x) {
System.out.println("002 float "+x);
}
//New private one
@SuppressWarnings("unused")
private ClassForNewInstance002(char x) {
System.out.println("002 char "+x);
}
@Override
public String toString() {
// The value of toString is used by the test to check expected result... so
return "002{ "+b+", "+s+","+i+","+d+"}";
}
/// We also use this class itself as an "invoker" for testing, so that we have some cases where it *is* allowed
// to call private methods etc. without setAccessible!
public static Object callNewInstance(Constructor<?> thiz, Object[] a0)
throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
return thiz.newInstance(a0);
}
}

View File

@@ -0,0 +1,19 @@
package reflection.constructors;
/**
* This version (003) is only used for testing "Class.newInstance" so we only need a default constructor
*/
public class ClassForNewInstance003 {
private ClassForNewInstance003() {
System.out.println("003 no args");
}
@Override
public String toString() {
// The value of toString is used by the test to check expected result... so
return "003";
}
}

View File

@@ -0,0 +1,20 @@
package reflection.constructors;
/**
* This version (004) is only used for testing "Class.newInstance". Testing case where there is
* no default constructor
*/
public class ClassForNewInstance004 {
public ClassForNewInstance004(String noDefaultConstructor) {
System.out.println("004 blah");
}
@Override
public String toString() {
// The value of toString is used by the test to check expected result... so
return "004";
}
}

View File

@@ -0,0 +1,43 @@
package reflection.constructors;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
/**
* For testing constructor reloading and methods related to fetching annotation data from
* constructors.
*
* @author kdvolder
*/
public class ClassWithAnnotatedConstructors {
// We want our reloaded version to have
// - additional constructors (with annotations)
// - constructors with changed annotations
//The annotation will be removed
@SuppressWarnings("unused")
private @AnnoT ClassWithAnnotatedConstructors() {}
//The attribute value will be changed
public @AnnoT3("first") ClassWithAnnotatedConstructors(int x) {}
//Annotations will be added
protected ClassWithAnnotatedConstructors(double x) {}
//Annotations will be changed (some added some removed)
protected @AnnoT @AnnoT3("haa") ClassWithAnnotatedConstructors(boolean x) {}
//Annotations are not changed at all
public @AnnoT @AnnoT2 @AnnoT3("haa") ClassWithAnnotatedConstructors(char x) {}
// Annotations in the parameters will change
public ClassWithAnnotatedConstructors(@AnnoT2 String x, @AnnoT3("bah") double y, @AnnoT boolean z) {}
// Annotations in the parameters will be removed
public ClassWithAnnotatedConstructors(@AnnoT2 double x, @AnnoT3("boohoo") double y, @AnnoT boolean z) {}
// Annotations in the parameters will be added
public ClassWithAnnotatedConstructors(char x, double y, boolean z) {}
}

View File

@@ -0,0 +1,56 @@
package reflection.constructors;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
/**
* For testing constructor reloading and methods related to fetching annotation data from
* constructors.
*
* @author kdvolder
*/
public class ClassWithAnnotatedConstructors002 {
// We want our reloaded version to have
// - additional constructors (with annotations)
// - constructors with changed annotations
//The annotation will be removed
@SuppressWarnings("unused")
private /* @AnnoT */ ClassWithAnnotatedConstructors002() {}
//The attribute value will be changed
public @AnnoT3(/*"first"*/ "second") ClassWithAnnotatedConstructors002(int x) {}
//Annotations will be added
protected @AnnoT @AnnoT3("haa002") ClassWithAnnotatedConstructors002(double x) {}
//Annotations will be changed (some added some removed)
protected /*@AnnoT*/ @AnnoT3("haa") /*+*/ @AnnoT2 ClassWithAnnotatedConstructors002(boolean x) {}
//Annotations are not changed at all
public @AnnoT @AnnoT2 @AnnoT3("haa") ClassWithAnnotatedConstructors002(char x) {}
// Annotations in the parameters will change
public ClassWithAnnotatedConstructors002(@AnnoT3("002") String x, @AnnoT2 double y, boolean z) {}
// Annotations in the parameters will be removed
public ClassWithAnnotatedConstructors002(double x, double y, boolean z) {}
// Annotations in the parameters will be added
public ClassWithAnnotatedConstructors002(@AnnoT char x, @AnnoT2 String y, @AnnoT2 @AnnoT3("bongo") @AnnoT boolean z) {}
///////////////////////////////////////////
// Some new constructors with and without annotations
public @AnnoT @AnnoT2 @AnnoT3("haa") ClassWithAnnotatedConstructors002(String x) {}
public ClassWithAnnotatedConstructors002(Float x) {}
public @AnnoT2 ClassWithAnnotatedConstructors002(float x) {}
public ClassWithAnnotatedConstructors002(float x, @AnnoT2 String y, @AnnoT2 @AnnoT3("bongo") @AnnoT boolean z) {}
}

View File

@@ -0,0 +1,50 @@
package reflection.constructors;
import javax.crypto.IllegalBlockSizeException;
/**
* A class with some constructors, for testing methods like Class.getConstructor, Class.getConstructors etc.
* <p>
* We need a few variations in this class, some different parameter lists and different visibility modifiers on
* these constructors.
*
* @author kdvolder
*/
public class ClassWithConstructors {
//////////////////////////////////////////////////
// Constructors that will not be changed (one with each kind of scope)
private ClassWithConstructors() {
}
protected ClassWithConstructors(int x) {
this();
}
public ClassWithConstructors(boolean z) {
}
ClassWithConstructors(double z) {
}
/////////////////////////////////////////////////////////////////////////
// Some constructors that change in different ways in the reloaded class
// modifier will change
public ClassWithConstructors(int i, String s) {
}
// will be deleted
public ClassWithConstructors(boolean i, String s) {
}
// will get exceptions
public ClassWithConstructors(String i, String s) {
}
// will remove exceptions
public ClassWithConstructors(double i, String s) throws IllegalBlockSizeException {
}
}

View File

@@ -0,0 +1,66 @@
package reflection.constructors;
import java.io.IOException;
/**
* A class with some constructors, for testing methods like Class.getConstructor, Class.getConstructors etc.
* <p>
* We need a few variations in this class, some different parameter lists and different visibility modifiers on
* these constructors.
*
* @author kdvolder
*/
public class ClassWithConstructors002 {
//////////////////////////////////////////////////
// Constructors that will not be changed (one with each kind of scope)
private ClassWithConstructors002() {
}
protected ClassWithConstructors002(int x) {
this();
}
public ClassWithConstructors002(boolean z) {
}
ClassWithConstructors002(double z) {
}
/////////////////////////////////////////////////////////////////////////
// Some constructors that change in different ways in the reloaded class
// modifier will change
@SuppressWarnings("unused")
private ClassWithConstructors002(int i, String s) {
}
// will be deleted
// public ClassWithConstructors002(boolean i, String s) {
// }
// will get exceptions
public ClassWithConstructors002(String i, String s) throws IOException, InterruptedException {
}
// will remove exceptions
public ClassWithConstructors002(double i, String s) {
}
///////////////////////////////////////////////////////////////////////////
// Some constructors are added
@SuppressWarnings("unused")
private ClassWithConstructors002(double x, ClassWithConstructors002 copy) {
}
public ClassWithConstructors002(long x, ClassWithConstructors002 copy) {
}
protected ClassWithConstructors002(short x, ClassWithConstructors002 copy) {
}
ClassWithConstructors002(char x, ClassWithConstructors002 copy) {
}
}

View File

@@ -0,0 +1,26 @@
package reflection.fieldannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
import reflection.CTAnnoT;
public class ClassTarget {
public String fWithNo;
@AnnoT @AnnoT3("boing")
public String fWithSame;
public @AnnoT String fWithAdded;
@AnnoT3("del") @AnnoT2
public String fWithRemoved;
@AnnoT3("begin")
public String fWithChanged;
@AnnoT @AnnoT3("begin") @CTAnnoT
public String fWithMixed;
}

View File

@@ -0,0 +1,45 @@
package reflection.fieldannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
import reflection.CTAnnoT;
public class ClassTarget002 {
public String fWithNo;
@AnnoT @AnnoT3("boing")
public String fWithSame;
@AnnoT @AnnoT2 @AnnoT3("added")
public String fWithAdded;
@AnnoT2
public String fWithRemoved;
@AnnoT3("end")
public String fWithChanged;
@AnnoT2 @AnnoT3("doinf") @CTAnnoT
public String fWithMixed;
// Newly added fields below (so must have a version 003 to see if can make changes to them)
public String newWithNo;
@AnnoT @AnnoT3("boing")
public String newWithSame;
public @AnnoT String newWithAdded;
@AnnoT3("del") @AnnoT2
public String newWithRemoved;
@AnnoT3("begin")
public String newWithChanged;
@AnnoT @AnnoT3("begin") @CTAnnoT
public String newWithMixed;
}

View File

@@ -0,0 +1,26 @@
package reflection.fieldannotations;
import reflection.AnnoT;
import reflection.AnnoT3;
public class ClassTarget003 {
// Newly added fields below (so must have a version 003 to see if can make changes to them)
public String newWithNo;
@AnnoT @AnnoT3("boing")
public String newWithSame;
@AnnoT @AnnoT3("added to new")
public String newWithAdded;
public String newWithRemoved;
@AnnoT3("newly ended")
public String newWithChanged;
@AnnoT3("banana") @AnnoT
public String newWithMixed;
}

View File

@@ -0,0 +1,26 @@
package reflection.fieldannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
import reflection.CTAnnoT;
public interface InterfaceTarget {
String fWithNo = "fWithNo";
@AnnoT @AnnoT3("boing")
String fWithSame = "same";
@AnnoT String fWithAdded = "added";
@AnnoT3("del") @AnnoT2
String fWithRemoved = "removed";
@AnnoT3("begin")
String fWithChanged = "changed";
@AnnoT @AnnoT3("begin") @CTAnnoT
String fWithMixed = "mixed";
}

View File

@@ -0,0 +1,45 @@
package reflection.fieldannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
import reflection.CTAnnoT;
public interface InterfaceTarget002 {
String fWithNo = "no";
@AnnoT @AnnoT3("boing")
String fWithSame = "sam";
@AnnoT @AnnoT2 @AnnoT3("added")
String fWithAdded = "add";
@AnnoT2
String fWithRemoved = "rem";
@AnnoT3("end")
String fWithChanged = "cha";
@AnnoT2 @AnnoT3("doinf") @CTAnnoT
String fWithMixed = "mix";
// Newly added fields below (so must have a version 003 to see if can make changes to them)
String newWithNo = "nno";
@AnnoT @AnnoT3("boing")
String newWithSame = "nws";
@AnnoT String newWithAdded= "nwa";
@AnnoT3("del") @AnnoT2
String newWithRemoved = "nwr";
@AnnoT3("begin")
String newWithChanged = "nwc";
@AnnoT @AnnoT3("begin") @CTAnnoT
String newWithMixed = "nwm";
}

View File

@@ -0,0 +1,26 @@
package reflection.fieldannotations;
import reflection.AnnoT;
import reflection.AnnoT3;
public interface InterfaceTarget003 {
// Newly added fields below (so must have a version 003 to see if can make changes to them)
String newWithNo = "nno";
@AnnoT @AnnoT3("boing")
String newWithSame = "nws";
@AnnoT @AnnoT3("added to new")
String newWithAdded = "bingo";
String newWithRemoved = "something";
@AnnoT3("newly ended")
String newWithChanged = "ahah";
@AnnoT3("banana") @AnnoT
String newWithMixed = "blender";
}

View File

@@ -0,0 +1,22 @@
package reflection.fields;
import reflection.nonrelfields.NonReloadableClassWithFields;
@SuppressWarnings("unused")
public class ClassTarget extends NonReloadableClassWithFields implements InterfaceTarget {
public int myField = 999;
public static String myStaticField = "staticField";
private boolean myPrivateField = true;
public int myDeletedField = 100;
private String myDeletedPrivateField = "ClassTarget.myDeletedPrivateField";
static String myDeletedStaticField = "ClassTarget.myDeletedStaticField";
public int myChangedField = 101;
private int myChangedPrivateField = 102;
static int myChangedStaticField = 103;
private int madePublicField = 103;
public String madeStaticField = "notStaticYet";
}

View File

@@ -0,0 +1,22 @@
package reflection.fields;
import reflection.nonrelfields.NonReloadableClassWithFields;
@SuppressWarnings("unused")
public class ClassTarget002 extends NonReloadableClassWithFields implements InterfaceTarget {
public int myField = 666;
public static String myStaticField = "staticField";
private boolean myPrivateField = false;
public String myChangedField = "201";
private String myChangedPrivateField= "202"; // in ClassTarget was: private int myChangedPrivateField = 102;
static String myChangedStaticField;// = "203"; static int myChangedStaticField = 103;
public String myNewField = "201";
private String myNewPrivateField = "202";
static String myNewStaticField;// = "203";
public int madePublicField = 9103;
public static String madeStaticField;// = "nowStatic";
}

View File

@@ -0,0 +1,61 @@
package reflection.fields;
import java.lang.reflect.Field;
/**
* A class with some fields in it.
*
* @author kdvolder
*/
@SuppressWarnings("unused")
public class FieldSetAccessTarget {
// Fields that are still in the reloaded version with their value changed
private String privateField = "privateField value";
protected String protectedField = "protectedField value";
String defaultField = "defaultField value";
public String publicField = "publicField value";
public String deletedPublicField = "deletedPublicField value";
public final String finalPublicField = "finalPublicField value";
private final String finalPrivateField = "finalPrivateField value";
// Same as above, but also some primitive types (different code paths)
private int privatePrimField = 11;
protected int protectedPrimField = 12;
int defaultPrimField = 13;
public int publicPrimField = 14;
public int deletedPrimField = 15;
public final int finalPrimField = 16;
private final int finalPrivatePrimField = 17;
// For access checking when calls originate in "privileged" context (i.e. the class itself)
/**
* Gets a field in class, can override access constraints if requested to do so.
*/
public String getFieldWithAccess(Class<?> targetClass, String whichField, boolean setAccess) throws Exception {
Object targetInstance = targetClass.newInstance();
Field field = targetClass.getDeclaredField(whichField);
if (setAccess) {
field.setAccessible(true);
}
return (String) field.get(targetInstance);
}
/**
* Sets a field in class, can override access constraints if requested to do so.
*/
public void setFieldWithAccess(Class<?> targetClass, String whichField, boolean setAccess) throws Exception {
Object targetInstance = targetClass.newInstance();
Field field = targetClass.getDeclaredField(whichField);
if (setAccess) {
field.setAccessible(true);
}
// Not checking for type errors in this test, make sure we set correct type of value
if (field.getType().equals(int.class)) {
field.set(targetInstance, 888);
} else {
field.set(targetInstance, "<BANG>");
}
}
}

View File

@@ -0,0 +1,60 @@
package reflection.fields;
import java.lang.reflect.Field;
/**
* A class with some fields in it.
*
* @author kdvolder
*/
@SuppressWarnings("unused")
public class FieldSetAccessTarget002 {
// Fields that are still in the reloaded version with their value changed
private String privateField = "new privateField value";
protected String protectedField = "new protectedField value";
String defaultField = "new defaultField value";
public String publicField = "new publicField value";
public final String finalPublicField = "new finalPublicField value";
private final String finalPrivateField = "new finalPrivateField value";
// Same as above, but also some primitive types (different code paths)
private int privatePrimField = 21;
protected int protectedPrimField = 22;
int defaultPrimField = 23;
public int publicPrimField = 24;
public int deletedPrimField = 25;
public final int finalPrimField = 26;
private final int finalPrivatePrimField = 27;
// For access checking when calls originate in "privileged" context (i.e. the class itself)
/**
* Gets a field in class, can override access constraints if requested to do so.
*/
public String getFieldWithAccess(Class<?> targetClass, String whichField, boolean setAccess) throws Exception {
Object targetInstance = targetClass.newInstance();
Field field = targetClass.getDeclaredField(whichField);
if (setAccess) {
field.setAccessible(true);
}
return (String) field.get(targetInstance);
}
/**
* Sets a field in class, can override access constraints if requested to do so.
*/
public void setFieldWithAccess(Class<?> targetClass, String whichField, boolean setAccess) throws Exception {
Object targetInstance = targetClass.newInstance();
Field field = targetClass.getDeclaredField(whichField);
if (setAccess) {
field.setAccessible(true);
}
// Not checking for type errors in this test, make sure we set correct type of value
if (field.getType().equals(int.class)) {
field.set(targetInstance, 888);
} else {
field.set(targetInstance, "<BANG>");
}
}
}

View File

@@ -0,0 +1,11 @@
package reflection.fields;
public interface InterfaceTarget {
//TODO: currently we do not have tests that focus directly on interfaces and fields.
int iField = 999;
int iDeletedField = 100;
int iChangedField = 101;
}

View File

@@ -0,0 +1,10 @@
package reflection.fields;
public interface InterfaceTarget002 {
int iField = 666;
String iChangedField = "changedField";
String iAddedField = "newField";
}

View File

@@ -0,0 +1,8 @@
package reflection.fields;
public interface S1InterfaceTarget extends InterfaceTarget {
int iField = 1;
int i1Field = 2;
}

View File

@@ -0,0 +1,8 @@
package reflection.fields;
public interface S1InterfaceTarget002 extends InterfaceTarget {
int iField = 1;
int i1AddedField = 201;
}

View File

@@ -0,0 +1,7 @@
package reflection.fields;
public interface S2InterfaceTarget extends InterfaceTarget, S1InterfaceTarget {
int i2Field = 2222;
}

View File

@@ -0,0 +1,8 @@
package reflection.fields;
public interface S2InterfaceTarget002 extends InterfaceTarget, S1InterfaceTarget {
int i2Field = 222;
int i2Added = 202;
}

View File

@@ -0,0 +1,14 @@
package reflection.fields;
@SuppressWarnings("unused")
public class SubClassTarget extends ClassTarget {
public static String myStaticField = "mySub.staticField";
private String myPrivateField = "mySub.private";
public String subField = "sub.staticField";
public static String subStaticField = "sub.staticField";
private String subPrivateField = "sub.private";
}

View File

@@ -0,0 +1,45 @@
package reflection.fields;
import reflection.SubTestVal;
import reflection.TestVal;
@SuppressWarnings("unused")
public class SubClassTarget002 extends ClassTarget {
public static String myStaticField = "mySub.staticField";
private String myPrivateField = "mySub.private";
public String subField = "sub.staticField";
public static String subStaticField = "sub.staticField";
private String subPrivateField = "sub.private";
public String myDeletedField = "movedToSubclass";
private String myDeletedPrivateField = "movedToSubclassPrivate";
static String myDeletedStaticField;// = "movedToSubclassStatic";
// Ensure coverage of all primitive types.
byte byteField = 123;
long longField = 123123;
short shortField = 5;
boolean boolField = true;
char charField = 'A';
// int intField; //no need plenty of fields with ints elsewhere already
float floatField = (float)3.14;
double doubleField = 6.28;
// Ensure coverage of boxed types
Byte boxByteField = 123;
Long boxLongField = (long)123123;
Short boxShortField = 5;
Boolean boxBoolField = true;
Character boxCharField = 'A';
Integer intField = 10;
Float boxFloatField = (float)3.14;
Double boxDoubleField = 6.28;
// Ensure coverage of object types other than string, and having subtype relations
SubTestVal subSubTypeField = SubTestVal.it;
TestVal superSubTypeField = SubTestVal.it;
TestVal superSuperTypeField = TestVal.it;
}

View File

@@ -0,0 +1,46 @@
package reflection.generics;
import java.util.Iterator;
public class GenericClass<K extends Comparable<K>> implements GenericInterface<K>, Iterable<K> {
//what we need in this class...
// Following cases:
// - generic return type
// - generic method (i.e. with a generic parameter different from the class's type parameters
// - generically typed parameters
// - generically typed exception(s)
// - varargs method
// static and non-static versions of most cases
/**
* Method with Generic return type
*/
public Iterator<K> iterator() {
return null;
}
/**
* Static method with Generic return type
*/
public static Iterator<String> iterateStrings(Iterator<? extends Object> objs) {
return null;
}
public void processThem(String... strings) {
}
/**
* Generic method
*/
public static <T extends Comparable<T>> GenericClass<T> create(T ini) {
return null;
}
public <E extends RuntimeException> void genericThrow() throws E {}
public void checkMe() throws SecurityException, NoSuchFieldException {}
}

View File

@@ -0,0 +1,49 @@
package reflection.generics;
import java.util.Iterator;
public class GenericClass002<K extends Comparable<K>> implements GenericInterface<K>, Iterable<K> {
//what we need in this v002 class...
// Same as in original class, but also with methods added (fore these cases)
public Iterator<K> iterator() {
return null;
}
public static Iterator<String> iterateStrings(Iterator<? extends Object> objs) {
return null;
}
public void processThem(String... strings) {
}
public static <T extends Comparable<T>> GenericClass002<T> create(T ini) {
return null;
}
public <E extends RuntimeException> void genericThrow() throws E {}
public void checkMe() throws SecurityException, NoSuchFieldException {}
public Iterator<K> iterator2() {
return null;
}
public static Iterator<String> iterateStrings2(Iterator<? extends Object> objs) {
return null;
}
public void processThem2(String... strings) {
}
public static <T extends Comparable<T>> GenericClass002<T> create2(T ini) {
return null;
}
<E extends RuntimeException> void genericThrow2() throws E {}
void checkMe2() throws SecurityException, NoSuchFieldException {}
}

View File

@@ -0,0 +1,5 @@
package reflection.generics;
public interface GenericInterface<K> {
}

View File

@@ -0,0 +1,16 @@
package reflection.generics;
import java.util.Iterator;
public interface GenericInterface002<K> {
public Iterator<K> iterator();
public void processThem(String... strings);
<E extends RuntimeException> void genericThrow() throws E;
void checkMe() throws SecurityException, NoSuchFieldException;
}

View File

@@ -0,0 +1,40 @@
package reflection.invocation;
/**
* For invocation testing, we need a class hierarchy fo some complexity to see if dispatching works right.
*
* Will be using a 3 deep hierarchy C extends B extends A.
*
* Further we will be adding methods with different modifiers
*
* @author kdvolder
*/
public class A {
public String pubEarly() {
return "A.pubEarly()";
}
@SuppressWarnings("unused")
private String privEarly() {
return "A.privEarly()";
}
static String staticEarly() {
return "A.staticEarly()";
}
public String pubDeleted() {
return "A.pubDeleted()";
}
@SuppressWarnings("unused")
private String privDeleted() {
return "A.privDeleted()";
}
static String staticDeleted() {
return "A.staticDeleted()";
}
}

View File

@@ -0,0 +1,40 @@
package reflection.invocation;
/**
* For invocation testing, we need a class hierarchy fo some complexity to see if dispatching works right.
*
* Will be using a 3 deep hierarchy C extends B extends A.
*
* Further we will be adding methods with different modifiers
*
* @author kdvolder
*/
public class A002 {
public String pubEarly() {
return "A002.pubEarly()";
}
@SuppressWarnings("unused")
private String privEarly() {
return "A002.privEarly()";
}
static String staticEarly() {
return "A002.staticEarly()";
}
public String pubLate() {
return "A002.pubLate()";
}
@SuppressWarnings("unused")
private String privLate() {
return "A002.privLate()";
}
static String staticLate() {
return "A002.staticLate()";
}
}

View File

@@ -0,0 +1,40 @@
package reflection.invocation;
/**
* For invocation testing, we need a class hierarchy of some complexity to see if dispatching works right.
*
* Will be using a 3 deep hierarchy C extends B extends B.
*
* Further we will be adding methods with different modifiers
*
* @author kdvolder
*/
public class B extends A {
public String pubEarly() {
return "B.pubEarly()";
}
@SuppressWarnings("unused")
private String privEarly() {
return "B.privEarly()";
}
static String staticEarly() {
return "B.staticEarly()";
}
public String pubDeleted() {
return "B.pubDeleted()";
}
@SuppressWarnings("unused")
private String privDeleted() {
return "B.privDeleted()";
}
static String staticDeleted() {
return "B.staticDeleted()";
}
}

View File

@@ -0,0 +1,40 @@
package reflection.invocation;
/**
* For invocation testing, we need a class hierarchy fo some complexity to see if dispatching works right.
*
* Will be using a 3 deep hierarchy C extends B extends A.
*
* Further we will be adding methods with different modifiers
*
* @author kdvolder
*/
public class B002 extends A {
public String pubEarly() {
return "B002.pubEarly()";
}
@SuppressWarnings("unused")
private String privEarly() {
return "B002.privEarly()";
}
static String staticEarly() {
return "B002.staticEarly()";
}
public String pubLate() {
return "B002.pubLate()";
}
@SuppressWarnings("unused")
private String privLate() {
return "B002.privLate()";
}
static String staticLate() {
return "B002.staticLate()";
}
}

View File

@@ -0,0 +1,40 @@
package reflection.invocation;
/**
* For invocation testing, we need a class hierarchy of some complexity to see if dispatching works right.
*
* Will be using a 3 deep hierarchy C extends B extends C.
*
* Further we will be adding methods with different modifiers
*
* @author kdvolder
*/
public class C extends B {
public String pubEarly() {
return "C.pubEarly()";
}
@SuppressWarnings("unused")
private String privEarly() {
return "C.privEarly()";
}
static String staticEarly() {
return "C.staticEarly()";
}
public String pubDeleted() {
return "C.pubDeleted()";
}
@SuppressWarnings("unused")
private String privDeleted() {
return "C.privDeleted()";
}
static String staticDeleted() {
return "C.staticDeleted()";
}
}

View File

@@ -0,0 +1,40 @@
package reflection.invocation;
/**
* For invocation testing, we need a class hierarchy fo some complexity to see if dispatching works right.
*
* Will be using a 3 deep hierarchy C extends B extends A.
*
* Further we will be adding methods with different modifiers
*
* @author kdvolder
*/
public class C002 extends B {
public String pubEarly() {
return "C002.pubEarly()";
}
@SuppressWarnings("unused")
private String privEarly() {
return "C002.privEarly()";
}
static String staticEarly() {
return "C002.staticEarly()";
}
public String pubLate() {
return "C002.pubLate()";
}
@SuppressWarnings("unused")
private String privLate() {
return "C002.privLate()";
}
static String staticLate() {
return "C002.staticLate()";
}
}

View File

@@ -0,0 +1,34 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
@SuppressWarnings("unused")
public class ClassTarget {
@AnnoT3("field")
String s;
@AnnoT
public static final int ZERO = 0;
@AnnoT
public ClassTarget(String s) {
this.s = s;
}
@AnnoT
@AnnoT2
public void pubMethod() {
}
@AnnoT3(value = "Foo")
private void privMethod() {
}
boolean defaultMethod(String a, int b) {
return ("" + b).equals(a);
}
}

View File

@@ -0,0 +1,35 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
public class ClassTarget002 {
@AnnoT3("field")
String s;
@AnnoT
public ClassTarget002(String s) {
this.s = s;
}
@AnnoT2
@AnnoT3("noisy")
public void pubMethod() {
}
@SuppressWarnings("unused")
private void privMethod() {
}
@Deprecated
boolean defaultMethod(String a, int b) {
return ("" + b).equals(a);
}
public String addedMethod() {
return "ha";
}
}

View File

@@ -0,0 +1,36 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
@SuppressWarnings("unused")
public class ClassTarget003 {
@AnnoT3("field")
String s;
@AnnoT
public ClassTarget003(String s) {
this.s = s;
}
@AnnoT2
public void pubMethod() {
}
@AnnoT3(value = "Bar")
private void privMethod() {
}
@Deprecated
boolean defaultMethod(String a, int b) {
return ("" + b).equals(a);
}
@AnnoT3(value = "Hi")
public String addedMethod() {
return "ha";
}
}

View File

@@ -0,0 +1,21 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
@AnnoT3(value = "Itf")
public interface InterfaceTarget {
@AnnoT @AnnoT3("Boo")
static final String myConstant = "Boohoo";
@AnnoT @AnnoT2
void pubMethod();
@AnnoT3(value = "Foo")
void privMethod();
boolean defaultMethod(String a, int b);
}

View File

@@ -0,0 +1,23 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT3;
public interface InterfaceTarget002 {
@AnnoT @AnnoT3("Boo")
static final String myConstant = "Boohoo";
@AnnoT @AnnoT3("snazzy")
void pubMethod();
@AnnoT @AnnoT3("snazzy")
void dingdong();
@AnnoT3(value = "Bar")
void privMethod();
@Deprecated @AnnoT
boolean defaultMethod(String a, int b);
}

View File

@@ -0,0 +1,11 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT3;
public interface InterfaceTarget003 {
@AnnoT3("shiny")
Object brandNew(@AnnoT int x);
}

View File

@@ -0,0 +1,27 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
/**
* Test class containing methods with some annotations on their params.
*/
public class ParamAnnotClass {
@AnnoT
public ParamAnnotClass(@AnnoT String s) {
}
protected void noParams() {}
public void noAnnotations(String a, boolean b) { }
public int someAnnotations(@AnnoT int a, @AnnoT3("b") @AnnoT2 boolean b) {
return 654321;
}
public static int staticNoParams() { return 0; }
public static int staticSomeParams(@AnnoT int a, @AnnoT2 @AnnoT3("static") boolean b) { return 0; }
}

View File

@@ -0,0 +1,33 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
/**
* Test class containing methods with some annotations on their params.
*/
public class ParamAnnotClass002 {
@AnnoT
public ParamAnnotClass002(@AnnoT String s) {
}
protected void noParams() {}
public void noAnnotations(@AnnoT String a, boolean b) { }
public int someAnnotations(@AnnoT int a, @AnnoT3("b002") boolean b) {
return 654321;
}
public static int staticNoParams() { return 0; }
public static int staticSomeParams(@AnnoT3("reveresed") @AnnoT2 int a, @AnnoT boolean b) { return 0; }
public void addedMethodNoParams() {}
public void addedMethodNoAnnots(String a, double b) {}
public void addedMethodSomeAnnots(@AnnoT2 @AnnoT double a, @AnnoT3("boing") String b) {}
public static int addedStaticNoParams() { return 0; }
public static int addedStaticSomeParams(@AnnoT3("added") @AnnoT2 int a, @AnnoT boolean b) { return 0; }
}

View File

@@ -0,0 +1,16 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
/**
* Test class containing methods with some annotations on their params.
*/
public interface ParamAnnotInterface {
void noParams();
public void noAnnotations(String a, boolean b);
public int someAnnotations(@AnnoT int a, @AnnoT3("b") @AnnoT2 boolean b);
}

View File

@@ -0,0 +1,21 @@
package reflection.methodannotations;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
/**
* Test class containing methods with some annotations on their params.
*/
public interface ParamAnnotInterface002 {
void noParams();
public void noAnnotations(@AnnoT String a, boolean b);
int someAnnotations(int a, @AnnoT3("b002_itf") boolean b);
public void addedMethodNoParams();
public void addedMethodNoAnnots(String a, double b);
public void addedMethodSomeAnnots(@AnnoT2 @AnnoT double a, @AnnoT3("boing_itf") String b);
}

View File

@@ -0,0 +1,45 @@
package reflection.nonrelfields;
public class NonReloadableClassWithFields {
@SuppressWarnings("unused")
private String nrlPriv = "nrlPriv";
String nrlPub = "nrlPub";
static public String nrlStatic = "nrlPub";
// Coverage of different types (as needed to cover all kinds of "set/get" methods.
public boolean nrlBool = true;
protected byte nrlByte = 12;
char nrlChar = 'z';
@SuppressWarnings("unused")
private double nrlDouble = 12.3;
public float nrlFloat = (float) 10.3;
protected int nrlInt = 123;
long nrlLong = 12345;
public short nrlShort = 1;
// Coverage of different primtivi type fields that are 'final' to check that all
// generated error messages for setting those are formatted correctly
final boolean fnrlBool = true;
final protected byte fnrlByte = 12;
final char fnrlChar = 'z';
@SuppressWarnings("unused")
final private double fnrlDouble = 12.3;
final float fnrlFloat = (float) 10.3;
final protected int fnrlInt = 123;
final long fnrlLong = 12345;
final short fnrlShort = 1;
// One 'final public' of each type, to see if 'coerced' values in messages correctly formatted
final public boolean fpnrlBool = true;
final public byte fpnrlByte = 12;
final public char fpnrlChar = 'z';
final public double fpnrlDouble = 12.3;
final public float fpnrlFloat = (float) 10.3;
final public int fpnrlInt = 123;
final public long fpnrlLong = 12345;
final public short fpnrlShort = 1;
}

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,5 @@
package reflection.targets;
public class ChangeModClass {
}

View File

@@ -0,0 +1,5 @@
package reflection.targets;
final class ChangeModClass002 {
}

View File

@@ -0,0 +1,95 @@
package reflection.targets;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import reflection.AnnoT;
@AnnoT
public class ClassTarget {
public int myField = 999;
public static String myStaticField = "staticField";
@SuppressWarnings("unused")
private boolean myPrivateField = true;
public ClassTarget() {
}
public ClassTarget(float f) { // position on line20 important, must match in ClassTarget002
System.out.println(f);
}
public int methodStays() {
return 99;
}
public int methodDeleted() {
return 37;
}
public int methodChanged() {
return 1;
}
public String changeIt(String it) {
return it + "ho!";
}
public String changeReturn(String it) {
return it + "ho!";
}
public String changeThem(String it, int add) {
return it + add;
}
public String deleteThem(String it, int add) {
return it + add;
}
public String callPrivateMethod() throws Exception {
Method privateOne = ClassTarget.class.getDeclaredMethod("privateMethod");
return (String) privateOne.invoke(this);
}
@SuppressWarnings("unused")
private String privateMethod() {
return "privateMethod result";
}
protected String protectedMethod() {
return "protectedMethod result";
}
String defaultMethod() {
return "defaultMethod result";
}
public String overrideMethod() {
return "ClassTarget.overrideMethod";
}
public String overrideMethodDeleted() {
return "ClassTarget.overrideMethodDeleted";
}
public static String staticMethod() {
return "ClassTarget.staticMethod";
}
public int callPublicMethodOnDefaultClass() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
IllegalAccessException, InvocationTargetException {
Method publicOne = DefaultClass.class.getDeclaredMethod("publicMethod");
return (Integer) publicOne.invoke(new DefaultClass());
}
/**
* This main method is just here to have some place to put 'test' code so we can try what *should* happen when we run this
* normally without springloaded.
*/
public static void main(String[] args) throws Exception {
System.out.println(new ClassTarget().callPrivateMethod()); //Works!!!
}
}

View File

@@ -0,0 +1,94 @@
package reflection.targets;
import java.lang.reflect.Method;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
@AnnoT2
public class ClassTarget002 {
public int myField = 999;
public static String myStaticField = "staticField";
@SuppressWarnings("unused")
private boolean myPrivateField = true;
@AnnoT
public ClassTarget002() {
}
public ClassTarget002(float f) {
System.out.println(f);
}
@AnnoT3("can'tchange")
public ClassTarget002(int f) {
myField = f;
}
public int methodStays() {
return 99;
}
public int methodChanged() {
return 2;
}
public int lateMethod() {
return 42;
}
public String doubleIt(String it) {
return it + it;
}
public String changeIt(String it) {
return it + " " + it + "!";
}
public int changeReturn(String it) {
return it.length();
}
public String changeThem(String it, int repeat) {
String result = "";
for (int i = 0; i < repeat; i++) {
result += it;
}
return result;
}
public String callPrivateMethod() throws Exception {
Method privateOne = ClassTarget.class.getDeclaredMethod("privateMethod");
return (String) privateOne.invoke(this);
}
@SuppressWarnings("unused")
private String privateMethod() {
return "new privateMethod result";
}
protected String protectedMethod() {
return "new protectedMethod result";
}
public String overrideMethod() {
return "ClassTarget002.overrideMethod";
}
String defaultMethod() {
return "new defaultMethod result";
}
public static String staticMethod() {
return "ClassTarget002.staticMethod";
}
public static int staticMethodAdded() {
return 2;
}
public static String staticMethodAddedWithArgs(int i, String s) {
return i + s + "002";
}
}

View File

@@ -0,0 +1,87 @@
package reflection.targets;
import java.lang.reflect.Method;
import reflection.AnnoT;
import reflection.AnnoT2;
import reflection.AnnoT3;
@AnnoT2
public class ClassTarget003 {
@AnnoT2
int myField = 10;
@AnnoT
public ClassTarget003() {
}
@AnnoT3("can'tchange")
public ClassTarget003(int f) {
myField = f;
System.out.println("modified!");
}
public int methodStays() {
return 99;
}
public int methodChanged() {
return 3; //Changed from v002
}
public int lateMethod() {
return 42;
}
public String doubleIt(String it) {
return it + it;
}
public String changeIt(String it) {
return it + " " + it + "!";
}
public int changeReturn(String it) {
return it.length();
}
public String changeThem(String it, int repeat) {
String result = "";
for (int i = 0; i < repeat; i++) {
result += it;
}
return result;
}
public String callPrivateMethod() throws Exception {
Method privateOne = ClassTarget.class.getDeclaredMethod("privateMethod");
return (String) privateOne.invoke(this);
}
@SuppressWarnings("unused")
private String privateMethod() {
return "new privateMethod result";
}
protected String protectedMethod() {
return "new protectedMethod result";
}
String defaultMethod() {
return "new defaultMethod result";
}
public static int staticMethodAdded() {
return 3;
}
public static String staticMethodAddedWithArgs(int i, String s) {
return i + s + "003";
}
@Override
public String toString() {
return "ClassTarget003.toString";
}
}

View File

@@ -0,0 +1,9 @@
package reflection.targets;
class DefaultClass {
public int publicMethod() {
return 82;
}
}

View File

@@ -0,0 +1,9 @@
package reflection.targets;
class DefaultClass002 {
public int publicMethod() {
return 999;
}
}

View File

@@ -0,0 +1,12 @@
package reflection.targets;
public abstract class GetMethodClass implements GetMethodInterface {
public void im1(int a, String b) {
}
public boolean sim2(int a, String b) {
return false;
}
}

View File

@@ -0,0 +1,23 @@
package reflection.targets;
public abstract class GetMethodClass002 implements GetMethodInterface {
public void im1(int a, String b) {
}
public boolean sim2(int a, String b) {
return false;
}
public boolean im2(int a, String b) {
return false;
}
public static void findMeInSubclass() {
}
@SuppressWarnings("unused")
private void findMeNot() {
}
}

View File

@@ -0,0 +1,12 @@
package reflection.targets;
/**
* Used by ClassGetMethodsTest
* @author kdvolder
*/
public interface GetMethodInterface {
void im1(int a, String b);
boolean im2(int a, String b);
}

View File

@@ -0,0 +1,13 @@
package reflection.targets;
/**
* Used by ClassGetMethodsTest
* @author kdvolder
*/
public interface GetMethodInterface002 {
void im1(int a, String b);
void sim1(int a, String b);
boolean im2(int a, String b);
}

View File

@@ -0,0 +1,9 @@
package reflection.targets;
public abstract class GetMethodSubClass extends GetMethodClass implements GetMethodSubInterface {
@Override
public void sim1(int a, String b) {
}
}

Some files were not shown because too many files have changed in this diff Show More