Fixing a bug: getWildcardTypeImplObject could not recognize variations of class Type...
authorrtrimana <rtrimana@uci.edu>
Tue, 25 Jun 2019 17:24:25 +0000 (10:24 -0700)
committerrtrimana <rtrimana@uci.edu>
Tue, 25 Jun 2019 17:24:25 +0000 (10:24 -0700)
examples/Reflection.java
src/main/gov/nasa/jpf/vm/Types.java

index 788ef585547341268ab7aee8a4bafa5df9a03d9c..d5041d2b238817afa5d786a831ffc706748d05dd 100644 (file)
@@ -25,7 +25,7 @@ public class Reflection {
         private String sampleField;
 
         public Class<?> setSampleField(Class<?> clazz,
-                       Class<? extends List> list, Class<? super Map> map,
+                       Class<? extends List> list, Class<? super Map> map, Class<?> clazz2, Class<VWXZ> clazz3,
                        List<String> listString, Map<Integer,String> mapString, 
                        Generic<Integer,String,Double,Short,Float> test, 
                        String sampleField, int one, short two, double three, Object obj) {
@@ -50,7 +50,7 @@ public class Reflection {
 
    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) {
@@ -65,7 +65,7 @@ public class Reflection {
       }
       System.out.println();
       Type returnType = method.getGenericReturnType();
-      System.out.println(returnType);*/
+      System.out.println(returnType);
       
       /*Type superCls = Generic.class.getGenericSuperclass();
       //Type superCls = String.class.getGenericSuperclass();
@@ -77,7 +77,7 @@ public class Reflection {
         }*/
       
       
-         Method[] methods = Class.class.getMethods();
+         /*Method[] methods = Class.class.getMethods();
          Method method = null;
       for(Method mth : methods) {
         if (mth.getName().equals("getConstructor")) {
@@ -93,8 +93,21 @@ public class Reflection {
       }
       System.out.println();
       Type returnType = method.getGenericReturnType();
-      System.out.println(returnType);
-         
+      System.out.println(returnType);*/
+      
+      /* TODO: Enumerate all methods in Class.class
+      Method[] methods = Class.class.getMethods();
+      for(Method mth : methods) {
+                 System.out.println("===========================");
+         System.out.println("Method: " + mth.getName());
+                 Type[] parameters = mth.getGenericParameterTypes();
+                 for (int i = 0; i < parameters.length; i++) {
+                    System.out.println(parameters[i]);
+                 }
+                 System.out.println();
+                 Type returnType = mth.getGenericReturnType();
+                 System.out.println(returnType + "\n");
+      }*/
 
       /*Class[] parameterTypes = methods[0].getParameterTypes();
       for(Class parameterType: parameterTypes){
index fcc8ec24b49bc5e9dce3886d60b4c7c661cda6d5..c0edb793f6b50be7e2425f34571dda6231862d6b 100644 (file)
@@ -1317,16 +1317,16 @@ public class Types {
       return signature;
     }
 
-    // Check that the first and the second halves are the same, e.g., TT for Class<T>
-    int halfPos = cleanSig.length()/2;
-    String firstHalf = cleanSig.substring(0, halfPos);
-    String secondHalf = cleanSig.substring(halfPos, cleanSig.length());
-    if (firstHalf.equals(secondHalf)) {
-      return firstHalf;
-    } else {
-      // This is probably a class, e.g., +java.lang.Class
+    // Check if this is not a class name, e.g., +java.lang.Class
+    if (cleanSig.contains(".")) {
       return signature;
     }
+
+    // Just return the second half of the signature to get the Type parameter
+    int halfPos = cleanSig.length()/2;
+    //String firstHalf = cleanSig.substring(0, halfPos);
+    String secondHalf = cleanSig.substring(halfPos, cleanSig.length());
+    return secondHalf;
   }
   // TODO: Fix for Groovy's model-checking
 }