From: rtrimana Date: Tue, 25 Jun 2019 17:24:25 +0000 (-0700) Subject: Fixing a bug: getWildcardTypeImplObject could not recognize variations of class Type... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=jpf-core.git;a=commitdiff_plain;h=2bf7cc4008fee54fde4b494d3711e7eee8e8b8b2 Fixing a bug: getWildcardTypeImplObject could not recognize variations of class Type parameters, e.g., +TT vs. +TU. --- diff --git a/examples/Reflection.java b/examples/Reflection.java index 788ef58..d5041d2 100644 --- a/examples/Reflection.java +++ b/examples/Reflection.java @@ -25,7 +25,7 @@ public class Reflection { private String sampleField; public Class setSampleField(Class clazz, - Class list, Class map, + Class list, Class map, Class clazz2, Class clazz3, List listString, Map mapString, Generic test, String sampleField, int one, short two, double three, Object obj) { @@ -50,7 +50,7 @@ public class Reflection { public static void main(String[] args) { - /*Method[] methods = SampleClass.class.getMethods(); + Method[] methods = SampleClass.class.getMethods(); // Method[] methods = Class.class.getMethods(); Method method = null; for(Method meth : methods) { @@ -65,7 +65,7 @@ public class Reflection { } System.out.println(); Type returnType = method.getGenericReturnType(); - System.out.println(returnType);*/ + System.out.println(returnType); /*Type superCls = Generic.class.getGenericSuperclass(); //Type superCls = String.class.getGenericSuperclass(); @@ -77,7 +77,7 @@ public class Reflection { }*/ - Method[] methods = Class.class.getMethods(); + /*Method[] methods = Class.class.getMethods(); Method method = null; for(Method mth : methods) { if (mth.getName().equals("getConstructor")) { @@ -93,8 +93,21 @@ public class Reflection { } System.out.println(); Type returnType = method.getGenericReturnType(); - System.out.println(returnType); - + System.out.println(returnType);*/ + + /* TODO: Enumerate all methods in Class.class + Method[] methods = Class.class.getMethods(); + for(Method mth : methods) { + System.out.println("==========================="); + System.out.println("Method: " + mth.getName()); + Type[] parameters = mth.getGenericParameterTypes(); + for (int i = 0; i < parameters.length; i++) { + System.out.println(parameters[i]); + } + System.out.println(); + Type returnType = mth.getGenericReturnType(); + System.out.println(returnType + "\n"); + }*/ /*Class[] parameterTypes = methods[0].getParameterTypes(); for(Class parameterType: parameterTypes){ diff --git a/src/main/gov/nasa/jpf/vm/Types.java b/src/main/gov/nasa/jpf/vm/Types.java index fcc8ec2..c0edb79 100644 --- a/src/main/gov/nasa/jpf/vm/Types.java +++ b/src/main/gov/nasa/jpf/vm/Types.java @@ -1317,16 +1317,16 @@ public class Types { return signature; } - // Check that the first and the second halves are the same, e.g., TT for Class - 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 + // 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 }