Finalizing the beta version of the implementation for Groovy extension in JPF: JPF...
[jpf-core.git] / src / main / gov / nasa / jpf / vm / Types.java
index f9723a6689c36f5c95e27d7c6f5b2ab9586bef8b..313e8aab7d0fb0f01027262c8ea64abc1ea0fe91 100644 (file)
@@ -1211,7 +1211,6 @@ public class Types {
     return arrTypeVarNames;
   }
 
-  // TODO: Fix for Groovy's model-checking
   public static String[] getParameterizedTypes(String signature) {
     int pos = signature.indexOf('<', 0);
     if (pos == -1)
@@ -1288,7 +1287,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 +1300,31 @@ 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("\\+|-", "");
+    if (cleanSig.length()%2 != 0) {
+      // This is probably a class, e.g., +java.lang.Class
+      return signature;
+    }
+
+    // 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
 }