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);
59 StringBuilder sb = new StringBuilder(0);
62 System.out.println(sb.toString());
64 /* TODO: Enumerate all methods in Class.class
65 Method[] methods = Collection.class.getMethods();
66 for(Method mth : methods) {
67 System.out.println("===========================");
68 //System.out.println("Method: " + mth.getName());
69 Type[] parameters = mth.getGenericParameterTypes();
70 for (int i = 0; i < parameters.length; i++) {
71 System.out.println(parameters[i]);
74 Type returnType = mth.getGenericReturnType();
75 System.out.println(returnType + "\n");
78 /*Method[] methods = Collection.class.getMethods();
79 // Method[] methods = Class.class.getMethods();
81 for(Method meth : methods) {
82 System.out.println("===========================");
83 //System.out.println("Method: " + meth.toString());
84 Type[] parameters = meth.getGenericParameterTypes();
85 for (int i = 0; i < parameters.length; i++) {
86 System.out.println(parameters[i]);
88 Type returnType = meth.getGenericReturnType();
89 System.out.println(returnType);
90 System.out.println("===========================");
93 /* TODO: This is an excerpt of the BigInteger library
99 int cursor = 0, numDigits;
100 final int len = val.length();
102 if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
103 throw new NumberFormatException("Radix out of range");
105 throw new NumberFormatException("Zero length BigInteger");
107 // Check for at most one leading sign
109 int index1 = val.lastIndexOf('-');
110 int index2 = val.lastIndexOf('+');
112 if (index1 != 0 || index2 >= 0) {
113 throw new NumberFormatException("Illegal embedded sign character");
117 } else if (index2 >= 0) {
119 throw new NumberFormatException("Illegal embedded sign character");
123 System.out.println(cursor);
125 throw new NumberFormatException("Zero length BigInteger");
127 // Skip leading zeros and compute number of digits in magnitude
128 while (cursor < len &&
129 Character.digit(val.charAt(cursor), radix) == 0) {
140 numDigits = len - cursor;
143 long numBits = ((numDigits * bitsPerDigit[radix]) >>> 10) + 1;
144 if (numBits + 31 >= (1L << 32)) {
145 System.out.println("Overflow!");
147 int numWords = (int) (numBits + 31) >>> 5;
148 int[] magnitude = new int[numWords];
150 // Process first (potentially short) digit group
151 int firstGroupLen = numDigits % digitsPerInt[radix];
152 if (firstGroupLen == 0)
153 firstGroupLen = digitsPerInt[radix];
154 int cursor2 = cursor + firstGroupLen;
155 String group = val.substring(cursor, cursor2);
156 magnitude[numWords - 1] = Integer.parseInt(group, radix);
157 if (magnitude[numWords - 1] < 0)
158 throw new NumberFormatException("Illegal digit");*/
160 /*Type superCls = Generic.class.getGenericSuperclass();
161 //Type superCls = String.class.getGenericSuperclass();
162 System.out.println(superCls);
163 System.out.println();
164 Type[] interfaces = Generic.class.getGenericInterfaces();
165 for (int i = 0; i < interfaces.length; i++) {
166 System.out.println(interfaces[i]);
170 /*Method[] methods = Map.class.getMethods();
171 Method method = null;
172 for(Method mth : methods) {
173 if (mth.getName().equals("putAll")) {
174 //if (mth.getName().equals("isAssignableFrom")) {
175 //if (mth.getName().equals("getSuperclass")) {
180 Type[] parameters = method.getGenericParameterTypes();
181 //Type[] parameters = methods[0].getGenericParameterTypes();
182 for (int i = 0; i < parameters.length; i++) {
183 System.out.println(parameters[i]);
185 System.out.println();
186 Type returnType = method.getGenericReturnType();
187 System.out.println(returnType);*/
189 /*Class[] parameterTypes = methods[0].getParameterTypes();
190 for(Class parameterType: parameterTypes){
191 System.out.println(parameterType.getName());
194 System.out.println();*/
195 /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
196 //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
197 for(TypeVariable typeVar: typeParameters){
198 System.out.println(typeVar);
201 System.out.println();
203 Type[] bounds = typeParameters[0].getBounds();
204 for (Type bound : bounds) {
205 System.out.println(bound);
207 System.out.println();*/
209 //ProtectionDomain pd = Class.class.getProtectionDomain();
210 //System.out.println(pd);