public static void main(String[] args) {
Method[] methods = SampleClass.class.getMethods();
- Type[] parameters = methods[3].getGenericParameterTypes();
+ // Method[] methods = Class.class.getMethods();
+ Method method = null;
+ for(Method meth : methods) {
+ if (meth.getName().equals("setSampleField")) {
+ method = meth;
+ }
+ }
+ Type[] parameters = method.getGenericParameterTypes();
//Type[] parameters = methods[0].getGenericParameterTypes();
for (int i = 0; i < parameters.length; i++) {
System.out.println(parameters[i]);
}
System.out.println();*/
- TypeVariable[] typeParameters = Generic.class.getTypeParameters();
+ /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
//TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
for(TypeVariable typeVar: typeParameters){
System.out.println(typeVar);
System.out.println();
Type returnType = methods[0].getGenericReturnType();
System.out.println(returnType);
-
+ */
}
}
import gov.nasa.jpf.util.RunListener;
import gov.nasa.jpf.util.RunRegistry;
+import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
}
// TODO: Fix for Groovy's model-checking
- private static int getParameterizedTypeImplObj(String signature, MJIEnv env) {
+ private static int getParameterizedTypeImplObj(String signature, MJIEnv env, int objRef, MethodInfo mi) {
ThreadInfo ti = env.getThreadInfo();
ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
ei.setReferenceField("rawType", gci.getClassObjectRef());
// actualTypeArguments
- String[] parameterizedTypes = Types.getParameterizedTypesFromArgumentTypeNames(signature);
+ String[] parameterizedTypes = Types.getParameterizedTypes(signature);
int[] types = new int[parameterizedTypes.length];
+ String classGenericSig = mi.getClassInfo().getGenericSignature();
+ String methodGenericSig = mi.getGenericSignature();
for(int j = 0; j < parameterizedTypes.length; j++) {
- ClassInfo pci = cli.getResolvedClassInfo(parameterizedTypes[j]);
- if (!pci.isRegistered()) {
- pci.registerClass(ti);
+ if (Types.isTypeParameter(parameterizedTypes[j], methodGenericSig) ||
+ Types.isTypeParameter(parameterizedTypes[j], classGenericSig)) {
+ types[j] = getTypeVariableImplObject(env, objRef, mi, parameterizedTypes[j]);
+ } else {
+ ClassInfo pci = cli.getResolvedClassInfo(parameterizedTypes[j]);
+ if (!pci.isRegistered()) {
+ pci.registerClass(ti);
+ }
+ types[j] = pci.getClassObjectRef();
}
- types[j] = pci.getClassObjectRef();
}
int aRef = env.newObjectArray("Ljava/lang/reflect/Type;", parameterizedTypes.length);
// Set references for every array element
return paramTypeRef;
}
+ private static int getTypeVariableImplObject(MJIEnv env, int objRef, MethodInfo mi, String parameterizedType) {
+
+ ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
+ ClassInfo ci = cli.getResolvedClassInfo("sun.reflect.generics.reflectiveObjects.TypeVariableImpl");
+
+ int typeVarRef = env.newObject(ci);
+ ElementInfo ei = env.getModifiableElementInfo(typeVarRef);
+ // genericDeclaration contains this java.lang.reflect.Method object
+ ei.setReferenceField("genericDeclaration", objRef);
+ ei.setReferenceField("name", env.newString(parameterizedType));
+
+ return typeVarRef;
+ }
+
static int getGenericParameterTypes( MJIEnv env, int objRef, MethodInfo mi) {
ThreadInfo ti = env.getThreadInfo();
String[] argTypeNames = mi.getArgumentGenericTypeNames();
for (int i = 0; i < argTypeNames.length; i++) {
// Change this into just the generic class type if it is a generic class
if (Types.isGenericSignature(argTypeNames[i])) {
- ar[i] = getParameterizedTypeImplObj(argTypeNames[i], env);
+ ar[i] = getParameterizedTypeImplObj(argTypeNames[i], env, objRef, mi);
} else {
ClassInfo ci = ClassLoaderInfo.getCurrentResolvedClassInfo(argTypeNames[i]);
if (!ci.isRegistered()) {
int retRef;
if (Types.isGenericSignature(mi.getGenericReturnTypeName())) {
- retRef = getParameterizedTypeImplObj(mi.getGenericReturnTypeName(), env);
+ retRef = getParameterizedTypeImplObj(mi.getGenericReturnTypeName(), env, objRef, mi);
} else {
ClassInfo ci = ClassLoaderInfo.getCurrentResolvedClassInfo(mi.getReturnTypeName());
if (!ci.isRegistered()) {