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 = Collection.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("===========================");
89 /* TODO: This is an excerpt of the BigInteger library
95 int cursor = 0, numDigits;
96 final int len = val.length();
98 if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
99 throw new NumberFormatException("Radix out of range");
101 throw new NumberFormatException("Zero length BigInteger");
103 // Check for at most one leading sign
105 int index1 = val.lastIndexOf('-');
106 int index2 = val.lastIndexOf('+');
108 if (index1 != 0 || index2 >= 0) {
109 throw new NumberFormatException("Illegal embedded sign character");
113 } else if (index2 >= 0) {
115 throw new NumberFormatException("Illegal embedded sign character");
119 System.out.println(cursor);
121 throw new NumberFormatException("Zero length BigInteger");
123 // Skip leading zeros and compute number of digits in magnitude
124 while (cursor < len &&
125 Character.digit(val.charAt(cursor), radix) == 0) {
136 numDigits = len - cursor;
139 long numBits = ((numDigits * bitsPerDigit[radix]) >>> 10) + 1;
140 if (numBits + 31 >= (1L << 32)) {
141 System.out.println("Overflow!");
143 int numWords = (int) (numBits + 31) >>> 5;
144 int[] magnitude = new int[numWords];
146 // Process first (potentially short) digit group
147 int firstGroupLen = numDigits % digitsPerInt[radix];
148 if (firstGroupLen == 0)
149 firstGroupLen = digitsPerInt[radix];
150 int cursor2 = cursor + firstGroupLen;
151 String group = val.substring(cursor, cursor2);
152 magnitude[numWords - 1] = Integer.parseInt(group, radix);
153 if (magnitude[numWords - 1] < 0)
154 throw new NumberFormatException("Illegal digit");*/
156 /*Type superCls = Generic.class.getGenericSuperclass();
157 //Type superCls = String.class.getGenericSuperclass();
158 System.out.println(superCls);
159 System.out.println();
160 Type[] interfaces = Generic.class.getGenericInterfaces();
161 for (int i = 0; i < interfaces.length; i++) {
162 System.out.println(interfaces[i]);
166 /*Method[] methods = Map.class.getMethods();
167 Method method = null;
168 for(Method mth : methods) {
169 if (mth.getName().equals("putAll")) {
170 //if (mth.getName().equals("isAssignableFrom")) {
171 //if (mth.getName().equals("getSuperclass")) {
176 Type[] parameters = method.getGenericParameterTypes();
177 //Type[] parameters = methods[0].getGenericParameterTypes();
178 for (int i = 0; i < parameters.length; i++) {
179 System.out.println(parameters[i]);
181 System.out.println();
182 Type returnType = method.getGenericReturnType();
183 System.out.println(returnType);*/
185 /*Class[] parameterTypes = methods[0].getParameterTypes();
186 for(Class parameterType: parameterTypes){
187 System.out.println(parameterType.getName());
190 System.out.println();*/
191 /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
192 //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
193 for(TypeVariable typeVar: typeParameters){
194 System.out.println(typeVar);
197 System.out.println();
199 Type[] bounds = typeParameters[0].getBounds();
200 for (Type bound : bounds) {
201 System.out.println(bound);
203 System.out.println();*/
205 //ProtectionDomain pd = Class.class.getProtectionDomain();
206 //System.out.println(pd);