Fixing the method getGenericParameterTypes to recognize the GenericArrayTypeImpl...
[jpf-core.git] / examples / Reflection.java
1 import java.lang.reflect.Method;
2 import java.lang.reflect.Type;
3 import java.lang.reflect.TypeVariable;
4 import java.io.Serializable;
5
6 import java.util.List;
7 import java.util.Map;
8 import java.util.ArrayList;
9 import java.util.Arrays;
10
11 public class Reflection {
12
13     interface GenericSuperShort<XYZ> {
14
15     }
16
17     class GenericShort<TUVW,ABCD> {
18     }
19
20     class Generic<TUVW,ABCD,KLM,NOP,XYZ> extends GenericShort<TUVW,ABCD> implements GenericSuperShort<XYZ>, Serializable {
21
22     }
23
24     class SampleClass<VWXZ> {
25         private String sampleField;
26
27         public Class<?> setSampleField(Class<?> clazz,
28                         Class<? extends List> list, Class<? super Map> map,
29                         List<String> listString, Map<Integer,String> mapString, 
30                         Generic<Integer,String,Double,Short,Float> test, 
31                         String sampleField, int one, short two, double three, Object obj) {
32             
33                         this.sampleField = sampleField;
34             return clazz;
35         }
36                  
37            
38            /*public String getSampleField() {
39                   return sampleField;
40            }*/
41            
42            /*public void setSampleField(String sampleField) {
43               this.sampleField = sampleField;
44            }
45            
46            public List<String> setSampleField(List<String> listString) {
47                   return listString;
48            }*/
49         }
50
51    public static void main(String[] args) {
52
53       /*Method[] methods = SampleClass.class.getMethods();
54       //  Method[] methods = Class.class.getMethods();
55         Method method = null;
56         for(Method meth : methods) {
57             if (meth.getName().equals("setSampleField")) {
58                 method = meth;
59             }
60         }
61         Type[] parameters = method.getGenericParameterTypes();
62       //Type[] parameters = methods[0].getGenericParameterTypes();
63       for (int i = 0; i < parameters.length; i++) {
64          System.out.println(parameters[i]);
65       }
66       System.out.println();*/
67       /*Type superCls = Generic.class.getGenericSuperclass();
68       //Type superCls = String.class.getGenericSuperclass();
69       System.out.println(superCls);
70         System.out.println();
71         Type[] interfaces = Generic.class.getGenericInterfaces();
72         for (int i = 0; i < interfaces.length; i++) {
73             System.out.println(interfaces[i]);
74         }*/
75       
76           Method[] methods = Class.class.getMethods();
77           Method method = null;
78       for(Method mth : methods) {
79         //if (mth.getName().equals("getConstructor")) {
80         if (mth.getName().equals("isAssignableFrom")) {
81            method = mth;
82         }
83       }
84       Type[] parameters = method.getGenericParameterTypes();
85       //Type[] parameters = methods[0].getGenericParameterTypes();
86       for (int i = 0; i < parameters.length; i++) {
87          System.out.println(parameters[i]);
88       }
89       System.out.println();
90       /*Class[] parameterTypes = methods[0].getParameterTypes();
91       for(Class parameterType: parameterTypes){
92          System.out.println(parameterType.getName());   
93  
94       }
95       System.out.println();*/
96       /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
97       //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
98       for(TypeVariable typeVar: typeParameters){
99          System.out.println(typeVar);   
100  
101       }
102       System.out.println();
103
104       Type[] bounds = typeParameters[0].getBounds();
105       for (Type bound : bounds) {
106           System.out.println(bound);
107       }
108       System.out.println();*/
109       Type returnType = method.getGenericReturnType();
110       System.out.println(returnType);
111           
112    }
113 }
114