Adding getGenericSuperclass and getGenericInterface methods but without the Parameter...
authorRahmadi Trimananda <rtrimana@uci.edu>
Fri, 21 Jun 2019 01:18:31 +0000 (18:18 -0700)
committerRahmadi Trimananda <rtrimana@uci.edu>
Fri, 21 Jun 2019 01:18:31 +0000 (18:18 -0700)
src/classes/java/lang/Class.java
src/peers/gov/nasa/jpf/vm/JPF_java_lang_Class.java

index 0231de7a1cea703af59c1b57676c49d7ca5869ab..00a55b0c1cc890d3958c1d41f4579737d4a75f1a 100644 (file)
@@ -274,13 +274,15 @@ public final class Class<T> implements Serializable, GenericDeclaration, Type, A
   // TODO: Fix for Groovy's model-checking
   public native TypeVariable<Class<T>>[] getTypeParameters();
 
-  public Type getGenericSuperclass() {
+  public native Type getGenericSuperclass();
+  /*public Type getGenericSuperclass() {
     throw new UnsupportedOperationException();
-  }
-  
-  public Type[] getGenericInterfaces() {
+  }*/
+
+  public native Type[] getGenericInterfaces();
+  /*public Type[] getGenericInterfaces() {
     throw new UnsupportedOperationException();
-  }
+  }*/
 
   public Object[] getSigners() {
     throw new UnsupportedOperationException();
index 10d63c7003595629d09eb79ef2659a14b55285ac..ccc98155190d4016c3e1ed2574b4ae958e61d597 100644 (file)
@@ -108,6 +108,39 @@ public class JPF_java_lang_Class extends NativePeer {
   }
 
   // TODO: Fix for Groovy's model-checking
+  @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();
+    } else {
+      return MJIEnv.NULL;
+    }
+  }
+
+  @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());
+    }
+
+    return aref;
+  }
+
   @MJI
   public int getTypeParameters_____3Ljava_lang_reflect_TypeVariable_2 (MJIEnv env, int robj){
     // Get the ClassInfo for this class