Adding ParameterizedTypeImpl to getGenericSuperclass method.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / Types.java
index 873b06578d4edb16a6c34617453815a8bce44aae..90e7f54dca5a3a8ba6316ee3d83a07e9daf4d07a 100644 (file)
@@ -919,7 +919,8 @@ public class Types {
       return signature.substring(1, len1).replace('/', '.').
               replaceAll(";L", ", ").
               replace("<L","<").
       return signature.substring(1, len1).replace('/', '.').
               replaceAll(";L", ", ").
               replace("<L","<").
-              replace(";>", ">");
+              replace(";>", ">").
+              replaceAll("<T", "<");
     }
 
 
     }
 
 
@@ -1177,21 +1178,22 @@ public class Types {
     throw new JPFException("invalid method declaration: " + methodDecl);
   }
 
     throw new JPFException("invalid method declaration: " + methodDecl);
   }
 
+  // TODO: Fix for Groovy's model-checking
   public static String[] getGenericTypeVariableNames(String signature) {
     int pos = 0;
   public static String[] getGenericTypeVariableNames(String signature) {
     int pos = 0;
-    int opening = 0;
+    int marker = 0;
     ArrayList<String> typeVarNames = new ArrayList<>();
 
     while (pos < signature.length()) {
       if (pos > 0) {
         // Start from ';' if this is not the first type variable name
     ArrayList<String> typeVarNames = new ArrayList<>();
 
     while (pos < signature.length()) {
       if (pos > 0) {
         // Start from ';' if this is not the first type variable name
-        opening = signature.indexOf(';', pos);
+        marker = signature.indexOf(';', pos);
         // Break if this is the end of the type variable names
         // Break if this is the end of the type variable names
-        if (signature.charAt(opening + 1) == '>')
+        if (signature.charAt(marker + 1) == '>')
           break;
       }
       int colon = signature.indexOf(':', pos);
           break;
       }
       int colon = signature.indexOf(':', pos);
-      String typeVarName = signature.substring(opening + 1, colon);
+      String typeVarName = signature.substring(marker + 1, colon);
       typeVarNames.add(typeVarName);
       pos = colon + 1;
     }
       typeVarNames.add(typeVarName);
       pos = colon + 1;
     }
@@ -1201,5 +1203,62 @@ public class Types {
 
     return arrTypeVarNames;
   }
 
     return arrTypeVarNames;
   }
-  
+
+  // TODO: Fix for Groovy's model-checking
+  public static String[] getParameterizedTypes(String signature) {
+    int pos = signature.indexOf('<', 0);
+    if (pos == -1)
+      return new String[0];
+    ArrayList<String> typeVarNames = new ArrayList<>();
+
+    while (pos < signature.length()) {
+      String typeVarName = "";
+      int comma = signature.indexOf(',', pos);
+      if (comma == -1) {
+        int closing = signature.indexOf('>', pos);
+        typeVarName = signature.substring(pos + 1, closing);
+        pos = signature.length();
+      } else {
+        typeVarName = signature.substring(pos + 1, comma);
+        pos = comma + 1;
+      }
+      typeVarNames.add(typeVarName);
+    }
+
+    String[] arrTypeVarNames = new String[typeVarNames.size()];
+    typeVarNames.toArray(arrTypeVarNames);
+
+    return arrTypeVarNames;
+  }
+
+  public static String getGenericClassName(String signature) {
+    int opening = signature.indexOf('<');
+    if (opening == -1)
+      return signature;
+    else
+      return signature.substring(0, opening);
+  }
+
+  public static String getOwnerClassName(String signature) {
+    int marker = signature.indexOf('$');
+    if (marker == -1)
+      return null;
+    else
+      return signature.substring(0, marker);
+  }
+
+  public static boolean isGenericSignature(String signature) {
+    if (signature == null || signature.equals(""))
+      return false;
+    int opening = signature.indexOf('<');
+    return (opening != -1);
+  }
+
+  public static boolean isTypeParameter(String parameterizedType, String signature) {
+    if (signature == null || signature.equals(""))
+      return false;
+    String typeParamSig = parameterizedType.concat(":");
+    return signature.contains(typeParamSig);
+  }
+  // TODO: Fix for Groovy's model-checking
 }
 }