1 import java.lang.reflect.Method;
2 import java.lang.reflect.Type;
3 import java.lang.reflect.TypeVariable;
4 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Arrays;
10 import java.util.Collection;
12 import java.math.BigInteger;
13 import java.security.ProtectionDomain;
15 public class Reflection {
17 interface GenericSuperShort<XYZ> {
21 class GenericShort<TUVW,ABCD> {
24 class Generic<TUVW,ABCD,KLM,NOP,XYZ> extends GenericShort<TUVW,ABCD> implements GenericSuperShort<XYZ>, Serializable {
28 class SampleClass<VWXZ> {
29 private String sampleField;
31 public Class<?> setSampleField(Class<?> clazz,
32 Class<? extends List> list, Class<? super Map> map, Class<?> clazz2, Class<VWXZ> clazz3,
33 List<String> listString, Map<Integer,String> mapString,
34 Generic<Integer,String,Double,Short,Float> test,
35 String sampleField, int one, short two, double three, Object obj) {
37 this.sampleField = sampleField;
42 /*public String getSampleField() {
46 /*public void setSampleField(String sampleField) {
47 this.sampleField = sampleField;
50 public List<String> setSampleField(List<String> listString) {
55 public static void main(String[] args) {
57 BigInteger bi = new BigInteger("-1");
58 System.out.println(bi);
60 /* TODO: Enumerate all methods in Class.class
61 Method[] methods = Class.class.getMethods();
62 for(Method mth : methods) {
63 //System.out.println("===========================");
64 //System.out.println("Method: " + mth.getName());
65 Type[] parameters = mth.getGenericParameterTypes();
66 for (int i = 0; i < parameters.length; i++) {
67 System.out.println(parameters[i]);
70 Type returnType = mth.getGenericReturnType();
71 System.out.println(returnType + "\n");
74 Method[] methods = Collection.class.getMethods();
75 // Method[] methods = Class.class.getMethods();
77 for(Method meth : methods) {
78 System.out.println("===========================");
79 //System.out.println("Method: " + meth.toString());
80 Type[] parameters = meth.getGenericParameterTypes();
81 for (int i = 0; i < parameters.length; i++) {
82 System.out.println(parameters[i]);
84 Type returnType = meth.getGenericReturnType();
85 System.out.println(returnType);
86 System.out.println("===========================");
88 Type[] parameters = method.getGenericParameterTypes();
89 //Type[] parameters = methods[0].getGenericParameterTypes();
90 for (int i = 0; i < parameters.length; i++) {
91 System.out.println(parameters[i]);
94 Type returnType = method.getGenericReturnType();
95 System.out.println(returnType);
97 /* TODO: This is an excerpt of the BigInteger library
103 int cursor = 0, numDigits;
104 final int len = val.length();
106 if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
107 throw new NumberFormatException("Radix out of range");
109 throw new NumberFormatException("Zero length BigInteger");
111 // Check for at most one leading sign
113 int index1 = val.lastIndexOf('-');
114 int index2 = val.lastIndexOf('+');
116 if (index1 != 0 || index2 >= 0) {
117 throw new NumberFormatException("Illegal embedded sign character");
121 } else if (index2 >= 0) {
123 throw new NumberFormatException("Illegal embedded sign character");
127 System.out.println(cursor);
129 throw new NumberFormatException("Zero length BigInteger");
131 // Skip leading zeros and compute number of digits in magnitude
132 while (cursor < len &&
133 Character.digit(val.charAt(cursor), radix) == 0) {
144 numDigits = len - cursor;
147 long numBits = ((numDigits * bitsPerDigit[radix]) >>> 10) + 1;
148 if (numBits + 31 >= (1L << 32)) {
149 System.out.println("Overflow!");
151 int numWords = (int) (numBits + 31) >>> 5;
152 int[] magnitude = new int[numWords];
154 // Process first (potentially short) digit group
155 int firstGroupLen = numDigits % digitsPerInt[radix];
156 if (firstGroupLen == 0)
157 firstGroupLen = digitsPerInt[radix];
158 int cursor2 = cursor + firstGroupLen;
159 String group = val.substring(cursor, cursor2);
160 magnitude[numWords - 1] = Integer.parseInt(group, radix);
161 if (magnitude[numWords - 1] < 0)
162 throw new NumberFormatException("Illegal digit");*/
164 /*Type superCls = Generic.class.getGenericSuperclass();
165 //Type superCls = String.class.getGenericSuperclass();
166 System.out.println(superCls);
167 System.out.println();
168 Type[] interfaces = Generic.class.getGenericInterfaces();
169 for (int i = 0; i < interfaces.length; i++) {
170 System.out.println(interfaces[i]);
174 Method[] methods = Collection.class.getMethods();
175 Method method = null;
176 for(Method mth : methods) {
177 if (mth.getName().equals("toArray")) {
178 //if (mth.getName().equals("isAssignableFrom")) {
179 //if (mth.getName().equals("getSuperclass")) {
184 Type[] parameters = method.getGenericParameterTypes();
185 //Type[] parameters = methods[0].getGenericParameterTypes();
186 for (int i = 0; i < parameters.length; i++) {
187 System.out.println(parameters[i]);
189 System.out.println();
190 Type returnType = method.getGenericReturnType();
191 System.out.println(returnType);*/
193 /*Class[] parameterTypes = methods[0].getParameterTypes();
194 for(Class parameterType: parameterTypes){
195 System.out.println(parameterType.getName());
198 System.out.println();*/
199 /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
200 //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
201 for(TypeVariable typeVar: typeParameters){
202 System.out.println(typeVar);
205 System.out.println();
207 Type[] bounds = typeParameters[0].getBounds();
208 for (Type bound : bounds) {
209 System.out.println(bound);
211 System.out.println();*/
213 //ProtectionDomain pd = Class.class.getProtectionDomain();
214 //System.out.println(pd);