2c90e54d52af940d2a34e3ac065e497d8dfcf5ad
[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 Generic<Integer,String,Double,Short,Float> setSampleField(Class<?> clazz, List<String> listString, Map<Integer,String> mapString,
28                                                                          Generic<Integer,String,Double,Short,Float> test,
29                                                                          String sampleField, int one, short two, double three, Object obj) {
30             this.sampleField = sampleField;
31             return test;
32         }
33                  
34            
35            /*public String getSampleField() {
36                   return sampleField;
37            }*/
38            
39            /*public void setSampleField(String sampleField) {
40               this.sampleField = sampleField;
41            }
42            
43            public List<String> setSampleField(List<String> listString) {
44                   return listString;
45            }*/
46         }
47
48    public static void main(String[] args) {
49
50       /*Method[] methods = SampleClass.class.getMethods();
51       //  Method[] methods = Class.class.getMethods();
52         Method method = null;
53         for(Method meth : methods) {
54             if (meth.getName().equals("setSampleField")) {
55                 method = meth;
56             }
57         }
58         Type[] parameters = method.getGenericParameterTypes();
59       //Type[] parameters = methods[0].getGenericParameterTypes();
60       for (int i = 0; i < parameters.length; i++) {
61          System.out.println(parameters[i]);
62       }
63       System.out.println();*/
64       /*Type superCls = Generic.class.getGenericSuperclass();
65       //Type superCls = String.class.getGenericSuperclass();
66       System.out.println(superCls);
67         System.out.println();
68         Type[] interfaces = Generic.class.getGenericInterfaces();
69         for (int i = 0; i < interfaces.length; i++) {
70             System.out.println(interfaces[i]);
71         }*/
72       
73       Method[] methods = Class.class.getMethods();
74         Method method = null;
75         for(Method mth : methods) {
76             if (mth.getName().equals("isAssignableFrom")) {
77                 method = mth;
78             }
79         }
80       Type[] parameters = method.getGenericParameterTypes();
81       //Type[] parameters = methods[0].getGenericParameterTypes();
82       for (int i = 0; i < parameters.length; i++) {
83          System.out.println(parameters[i]);
84       }
85       System.out.println();
86       /*Class[] parameterTypes = methods[0].getParameterTypes();
87       for(Class parameterType: parameterTypes){
88          System.out.println(parameterType.getName());   
89  
90       }
91       System.out.println();*/
92       /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
93       //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
94       for(TypeVariable typeVar: typeParameters){
95          System.out.println(typeVar);   
96  
97       }
98       System.out.println();
99
100       Type[] bounds = typeParameters[0].getBounds();
101       for (Type bound : bounds) {
102           System.out.println(bound);
103       }
104       System.out.println();
105       Type returnType = methods[0].getGenericReturnType();
106       System.out.println(returnType);
107           */
108    }
109 }
110