Fixing a bug: Map's parameterized type signature with wildcard was not handled properly.
authorrtrimana <rtrimana@uci.edu>
Wed, 3 Jul 2019 22:18:30 +0000 (15:18 -0700)
committerrtrimana <rtrimana@uci.edu>
Wed, 3 Jul 2019 22:18:30 +0000 (15:18 -0700)
examples/Reflection.java
src/main/gov/nasa/jpf/vm/Types.java

index 312248fae527671f1f97bf6120965501d78ca650..0918964c6fa547d29581b8c8518cffba5e5eefc9 100644 (file)
@@ -54,13 +54,13 @@ public class Reflection {
 
    public static void main(String[] args) {
           
 
    public static void main(String[] args) {
           
-         BigInteger bi = new BigInteger("-1");
-         System.out.println(bi);
+         //BigInteger bi = new BigInteger("-1");
+         //System.out.println(bi);
           
           
-         /* TODO: Enumerate all methods in Class.class 
-      Method[] methods = Class.class.getMethods();
+         /* TODO: Enumerate all methods in Class.class */ 
+      Method[] methods = Collection.class.getMethods();
       for(Method mth : methods) {
       for(Method mth : methods) {
-                 //System.out.println("===========================");
+                 System.out.println("===========================");
          //System.out.println("Method: " + mth.getName());
                  Type[] parameters = mth.getGenericParameterTypes();
                  for (int i = 0; i < parameters.length; i++) {
          //System.out.println("Method: " + mth.getName());
                  Type[] parameters = mth.getGenericParameterTypes();
                  for (int i = 0; i < parameters.length; i++) {
@@ -69,9 +69,9 @@ public class Reflection {
                  System.out.println();
                  Type returnType = mth.getGenericReturnType();
                  System.out.println(returnType + "\n");
                  System.out.println();
                  Type returnType = mth.getGenericReturnType();
                  System.out.println(returnType + "\n");
-      }*/
+      }
 
 
-      Method[] methods = Collection.class.getMethods();
+      /*Method[] methods = Collection.class.getMethods();
       //  Method[] methods = Class.class.getMethods();
         Method method = null;
         for(Method meth : methods) {
       //  Method[] methods = Class.class.getMethods();
         Method method = null;
         for(Method meth : methods) {
@@ -84,7 +84,7 @@ public class Reflection {
                        Type returnType = meth.getGenericReturnType();
                        System.out.println(returnType);
                        System.out.println("===========================");
                        Type returnType = meth.getGenericReturnType();
                        System.out.println(returnType);
                        System.out.println("===========================");
-        }
+        }*/
          
         /* TODO: This is an excerpt of the BigInteger library
                int radix = 10;
          
         /* TODO: This is an excerpt of the BigInteger library
                int radix = 10;
@@ -162,11 +162,11 @@ public class Reflection {
             System.out.println(interfaces[i]);
         }*/
       
             System.out.println(interfaces[i]);
         }*/
       
-      /*
-         Method[] methods = Collection.class.getMethods();
+      
+         /*Method[] methods = Map.class.getMethods();
          Method method = null;
       for(Method mth : methods) {
          Method method = null;
       for(Method mth : methods) {
-        if (mth.getName().equals("toArray")) {
+        if (mth.getName().equals("putAll")) {
         //if (mth.getName().equals("isAssignableFrom")) {
         //if (mth.getName().equals("getSuperclass")) {
            method = mth;
         //if (mth.getName().equals("isAssignableFrom")) {
         //if (mth.getName().equals("getSuperclass")) {
            method = mth;
index ba71512c0b219217936e81a00cf803a0f7899476..981ac10df0fc4c917a6e0b17d031645559f4bb36 100644 (file)
@@ -1222,20 +1222,30 @@ public class Types {
     int pos = signature.indexOf('<', 0);
     if (pos == -1)
       return new String[0];
     int pos = signature.indexOf('<', 0);
     if (pos == -1)
       return new String[0];
+
+    pos = pos + 1;
     ArrayList<String> typeVarNames = new ArrayList<>();
 
     while (pos < signature.length()) {
       String typeVarName = "";
     ArrayList<String> typeVarNames = new ArrayList<>();
 
     while (pos < signature.length()) {
       String typeVarName = "";
+      // Try comma first
       int comma = signature.indexOf(',', pos);
       if (comma == -1) {
       int comma = signature.indexOf(',', pos);
       if (comma == -1) {
-        int closing = signature.lastIndexOf('>', signature.length());
-        typeVarName = signature.substring(pos + 1, closing);
-        pos = signature.length();
+        // If not comma then perhaps semicolon
+        int semicolon = signature.indexOf(';', pos);
+        if (semicolon == -1) {
+          int closing = signature.lastIndexOf('>', signature.length());
+          typeVarName = signature.substring(pos, closing);
+          pos = signature.length();
+        } else {
+          typeVarName = signature.substring(pos, semicolon);
+          pos = semicolon + 1;
+        }
       } else {
       } else {
-        typeVarName = signature.substring(pos + 1, comma);
+        typeVarName = signature.substring(pos, comma);
         pos = comma + 1;
       }
         pos = comma + 1;
       }
-      typeVarNames.add(typeVarName);
+      typeVarNames.add(typeVarName.trim());
     }
 
     String[] arrTypeVarNames = new String[typeVarNames.size()];
     }
 
     String[] arrTypeVarNames = new String[typeVarNames.size()];