Adding ParameterizedTypeImpl to the getGenericInterfaces method.
authorrtrimana <rtrimana@uci.edu>
Fri, 21 Jun 2019 18:34:38 +0000 (11:34 -0700)
committerrtrimana <rtrimana@uci.edu>
Fri, 21 Jun 2019 18:34:38 +0000 (11:34 -0700)
examples/Reflection.java
src/peers/gov/nasa/jpf/vm/JPF_java_lang_Class.java

index d8f6e44a742d498236b5627405e938167caab8cc..21fdd5763aad5b00d8b15b8672de93fb746237eb 100644 (file)
@@ -1,6 +1,7 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 import java.lang.reflect.TypeVariable;
+import java.io.Serializable;
 
 import java.util.List;
 import java.util.Map;
@@ -9,22 +10,26 @@ import java.util.Arrays;
 
 public class Reflection {
 
-       class GenericShort<TUVW,ABCD> {
-       }
+    interface GenericSuperShort<XYZ> {
 
-       class Generic<TUVW,ABCD,KLM,NOP> extends GenericShort<TUVW,ABCD> {
-       
-       }
+    }
 
-       class SampleClass<VWXZ> {
-          private String sampleField;
+    class GenericShort<TUVW,ABCD> {
+    }
 
-          public Generic<Integer,String,Double,Short> setSampleField(Class<VWXZ> clazz, List<String> listString, Map<Integer,String> mapString,
-                               Generic<Integer,String,Double,Short> test,
-                               String sampleField, int one, short two, double three, Object obj) {
-                 this.sampleField = sampleField; 
-                 return test;
-          }
+    class Generic<TUVW,ABCD,KLM,NOP,XYZ> extends GenericShort<TUVW,ABCD> implements GenericSuperShort<XYZ>, Serializable {
+
+    }
+
+    class SampleClass<VWXZ> {
+        private String sampleField;
+
+        public Generic<Integer,String,Double,Short,Float> setSampleField(Class<VWXZ> clazz, List<String> listString, Map<Integer,String> mapString,
+                                                                         Generic<Integer,String,Double,Short,Float> test,
+                                                                         String sampleField, int one, short two, double three, Object obj) {
+            this.sampleField = sampleField;
+            return test;
+        }
           
           
           /*public String getSampleField() {
@@ -59,6 +64,11 @@ public class Reflection {
       Type superCls = Generic.class.getGenericSuperclass();
       //Type superCls = String.class.getGenericSuperclass();
       System.out.println(superCls);
+        System.out.println();
+        Type[] interfaces = Generic.class.getGenericInterfaces();
+        for (int i = 0; i < interfaces.length; i++) {
+            System.out.println(interfaces[i]);
+        }
       /*Class[] parameterTypes = methods[0].getParameterTypes();
       for(Class parameterType: parameterTypes){
          System.out.println(parameterType.getName());   
index cdc5dd709359a91bf10779a84a2ec15e84d7343b..2c769f243638a7d279a564598de37d599097e651 100644 (file)
@@ -108,8 +108,8 @@ public class JPF_java_lang_Class extends NativePeer {
   }
 
   // TODO: Fix for Groovy's model-checking
-  private static int getParameterizedTypeImplObj(String className, String[] parameterizedTypes, String ownerType,
-                                                 MJIEnv env, int objRef, int superObjRef) {
+  private static int getParameterizedTypeImplObj(String[] parameterizedTypes, String ownerType,
+                                                 MJIEnv env, int actObjRef, int rawObjRef) {
 
     ThreadInfo ti = env.getThreadInfo();
     ClassLoaderInfo cli = env.getSystemClassLoaderInfo();
@@ -119,12 +119,12 @@ public class JPF_java_lang_Class extends NativePeer {
     ElementInfo ei = env.getModifiableElementInfo(paramTypeRef);
     // Get field information and fill out the fields
     // rawType field
-    ei.setReferenceField("rawType", superObjRef);
+    ei.setReferenceField("rawType", rawObjRef);
 
     // actualTypeArguments
     int[] types = new int[parameterizedTypes.length];
     for(int j = 0; j < parameterizedTypes.length; j++) {
-        types[j] = getTypeVariableImplObject(env, objRef, parameterizedTypes[j]);
+        types[j] = getTypeVariableImplObject(env, actObjRef, parameterizedTypes[j]);
     }
     int aRef = env.newObjectArray("Ljava/lang/reflect/Type;", parameterizedTypes.length);
     // Set references for every array element
@@ -173,8 +173,7 @@ public class JPF_java_lang_Class extends NativePeer {
       }
       String className = sci.getName();
       String ownerType = Types.getOwnerClassName(className);
-      int gRef = getParameterizedTypeImplObj(className, typeVars, ownerType, env, ci.getClassObjectRef(),
-              sci.getClassObjectRef());
+      int gRef = getParameterizedTypeImplObj(typeVars, ownerType, env, ci.getClassObjectRef(), sci.getClassObjectRef());
 
       return gRef;
     } else {
@@ -184,20 +183,28 @@ public class JPF_java_lang_Class extends NativePeer {
 
   @MJI
   public int getGenericInterfaces_____3Ljava_lang_reflect_Type_2 (MJIEnv env, int robj) {
-    // TODO: Need to add ParameterizedTypeImpl
     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){
-      env.setReferenceArrayElement(aref, i++, ifc.getClassObjectRef());
+      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;