Adding tests for Type parameter, wild card, and class types for generic classes.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / Types.java
index f9723a6689c36f5c95e27d7c6f5b2ab9586bef8b..fcc8ec24b49bc5e9dce3886d60b4c7c661cda6d5 100644 (file)
@@ -1288,7 +1288,11 @@ public class Types {
   }
 
   public static boolean isWildcardType(String signature) {
-    return (signature.startsWith("+L") || signature.startsWith("-L") || signature.equals("*"));
+    return (signature.startsWith("+L") ||
+            signature.startsWith("-L") ||
+            signature.startsWith("+")  ||
+            signature.startsWith("-")  ||
+            signature.equals("*"));
   }
 
   public static String getWildcardType(String signature) {
@@ -1297,5 +1301,32 @@ public class Types {
     }
     return signature.replaceAll("\\+L|-L", "");
   }
+
+  public static String getTypeParameter(String signature) {
+    if (signature == null || signature.equals(""))
+      return signature;
+
+    if (signature.equals("*")) {
+      return signature;
+    }
+
+    String cleanSig = signature.replaceAll("\\+|-", "");
+    // This kind of signature should be a repetition of its class' type parameter, e.g., TT for Class<T>
+    if (cleanSig.length()%2 != 0) {
+      // This is probably a class, e.g., +java.lang.Class
+      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
+      return signature;
+    }
+  }
   // TODO: Fix for Groovy's model-checking
 }