A clean implementation for getTypeParameters' native method version.
[jpf-core.git] / src / main / gov / nasa / jpf / vm / Types.java
index c5b2f7f82d3cee8b4b4f843a4aaccd25d00687a2..873b06578d4edb16a6c34617453815a8bce44aae 100644 (file)
@@ -1176,5 +1176,30 @@ public class Types {
 
     throw new JPFException("invalid method declaration: " + methodDecl);
   }
+
+  public static String[] getGenericTypeVariableNames(String signature) {
+    int pos = 0;
+    int opening = 0;
+    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);
+        // Break if this is the end of the type variable names
+        if (signature.charAt(opening + 1) == '>')
+          break;
+      }
+      int colon = signature.indexOf(':', pos);
+      String typeVarName = signature.substring(opening + 1, colon);
+      typeVarNames.add(typeVarName);
+      pos = colon + 1;
+    }
+
+    String[] arrTypeVarNames = new String[typeVarNames.size()];
+    typeVarNames.toArray(arrTypeVarNames);
+
+    return arrTypeVarNames;
+  }
   
 }