class GenericShort<TUVW,ABCD> {
}
- class Generic<TUVW,ABCD,KLM,NOP> {
+ class Generic<TUVW,ABCD,KLM,NOP> extends GenericShort<TUVW,ABCD> {
}
public static void main(String[] args) {
- Method[] methods = SampleClass.class.getMethods();
+ /*Method[] methods = SampleClass.class.getMethods();
// Method[] methods = Class.class.getMethods();
Method method = null;
for(Method meth : methods) {
for (int i = 0; i < parameters.length; i++) {
System.out.println(parameters[i]);
}
- System.out.println();
+ System.out.println();*/
+ Type superCls = Generic.class.getGenericSuperclass();
+ //Type superCls = String.class.getGenericSuperclass();
+ System.out.println(superCls);
/*Class[] parameterTypes = methods[0].getParameterTypes();
for(Class parameterType: parameterTypes){
System.out.println(parameterType.getName());
}
// TODO: Fix for Groovy's model-checking
+ private static int getParameterizedTypeImplObj(String className, String[] parameterizedTypes, String ownerType,
+ MJIEnv env, int objRef, int superObjRef) {
+
+ ThreadInfo ti = env.getThreadInfo();
+ ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
+ ClassInfo ci = cli.getResolvedClassInfo("sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl");
+ // Create a new object of type ParameterizedTypeImpl
+ int paramTypeRef = env.newObject(ci);
+ ElementInfo ei = env.getModifiableElementInfo(paramTypeRef);
+ // Get field information and fill out the fields
+ // rawType field
+ ei.setReferenceField("rawType", superObjRef);
+
+ // actualTypeArguments
+ int[] types = new int[parameterizedTypes.length];
+ for(int j = 0; j < parameterizedTypes.length; j++) {
+ types[j] = getTypeVariableImplObject(env, objRef, parameterizedTypes[j]);
+ }
+ int aRef = env.newObjectArray("Ljava/lang/reflect/Type;", parameterizedTypes.length);
+ // Set references for every array element
+ for (int j = 0; j < parameterizedTypes.length; j++) {
+ env.setReferenceArrayElement(aRef, j, types[j]);
+ }
+ ei.setReferenceField("actualTypeArguments", aRef);
+
+ // ownerType
+ if (ownerType != null) {
+ ClassInfo oci = ClassLoaderInfo.getCurrentResolvedClassInfo(ownerType);
+ if (!oci.isRegistered()) {
+ oci.registerClass(ti);
+ }
+ ei.setReferenceField("ownerType", oci.getClassObjectRef());
+ } else {
+ ei.setReferenceField("ownerType", MJIEnv.NULL);
+ }
+
+ return paramTypeRef;
+ }
+
+ private static int getTypeVariableImplObject(MJIEnv env, int objRef, 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;
+ }
+
@MJI
public int getGenericSuperclass____Ljava_lang_reflect_Type_2 (MJIEnv env, int robj){
- // TODO: Need to add ParameterizedTypeImpl
ClassInfo ci = env.getReferredClassInfo( robj);
ClassInfo sci = ci.getSuperClass();
if (sci != null) {
- return sci.getClassObjectRef();
+ String[] typeVars = sci.getGenericTypeVariableNames();
+ // Not a generic class
+ if (typeVars.length == 0) {
+ return sci.getClassObjectRef();
+ }
+ String className = sci.getName();
+ String ownerType = Types.getOwnerClassName(className);
+ int gRef = getParameterizedTypeImplObj(className, typeVars, ownerType, env, ci.getClassObjectRef(),
+ sci.getClassObjectRef());
+
+ return gRef;
} else {
return MJIEnv.NULL;
}
for(int j = 0; j < parameterizedTypes.length; j++) {
if (Types.isTypeParameter(parameterizedTypes[j], methodGenericSig) ||
Types.isTypeParameter(parameterizedTypes[j], classGenericSig)) {
- types[j] = getTypeVariableImplObject(env, objRef, mi, parameterizedTypes[j]);
+ types[j] = getTypeVariableImplObject(env, objRef, parameterizedTypes[j]);
} else {
ClassInfo pci = cli.getResolvedClassInfo(parameterizedTypes[j]);
if (!pci.isRegistered()) {
return paramTypeRef;
}
- private static int getTypeVariableImplObject(MJIEnv env, int objRef, MethodInfo mi, String parameterizedType) {
+ private static int getTypeVariableImplObject(MJIEnv env, int objRef, String parameterizedType) {
ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
ClassInfo ci = cli.getResolvedClassInfo("sun.reflect.generics.reflectiveObjects.TypeVariableImpl");