+ private static int getParameterizedTypeImplObj(String[] parameterizedTypes, String ownerType,
+ MJIEnv env, int actObjRef, int rawObjRef) {
+
+ 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", rawObjRef);
+
+ // actualTypeArguments
+ int[] types = new int[parameterizedTypes.length];
+ for(int j = 0; j < parameterizedTypes.length; j++) {
+ types[j] = getTypeVariableImplObject(env, actObjRef, 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){
+ ClassInfo ci = env.getReferredClassInfo( robj);
+ ClassInfo sci = ci.getSuperClass();
+ if (sci != null) {
+ 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(typeVars, ownerType, env, ci.getClassObjectRef(), sci.getClassObjectRef());
+
+ return gRef;
+ } else {
+ return MJIEnv.NULL;
+ }
+ }
+
+ @MJI
+ public int getGenericInterfaces_____3Ljava_lang_reflect_Type_2 (MJIEnv env, int robj) {
+ ClassInfo ci = env.getReferredClassInfo(robj);
+ int aref = MJIEnv.NULL;
+ ThreadInfo ti = env.getThreadInfo();
+ // contrary to the API doc, this only returns the interfaces directly
+ // implemented by this class, not it's bases
+ // <2do> this is not exactly correct, since the interfaces should be ordered
+ Set<ClassInfo> interfaces = ci.getInterfaceClassInfos();
+
+ aref = env.newObjectArray("Ljava/lang/Class;", interfaces.size());
+
+ int i=0;
+ for (ClassInfo ifc: interfaces){
+ if (Types.isGenericSignature(ifc.getGenericSignature())) {
+ String className = ifc.getName();
+ String ownerType = Types.getOwnerClassName(className);
+ String[] typeVars = ifc.getGenericTypeVariableNames();
+ int paramTypeObj = getParameterizedTypeImplObj(typeVars, ownerType, env, ci.getClassObjectRef(),
+ ifc.getClassObjectRef());
+ env.setReferenceArrayElement(aref, i++, paramTypeObj);
+ } else {
+ env.setReferenceArrayElement(aref, i++, ifc.getClassObjectRef());
+ }
+ }
+
+ return aref;
+ }
+