}
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) {
}
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
}