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;
11 import java.math.BigInteger;
13 public class Reflection {
15 interface GenericSuperShort<XYZ> {
19 class GenericShort<TUVW,ABCD> {
22 class Generic<TUVW,ABCD,KLM,NOP,XYZ> extends GenericShort<TUVW,ABCD> implements GenericSuperShort<XYZ>, Serializable {
26 class SampleClass<VWXZ> {
27 private String sampleField;
29 public Class<?> setSampleField(Class<?> clazz,
30 Class<? extends List> list, Class<? super Map> map, Class<?> clazz2, Class<VWXZ> clazz3,
31 List<String> listString, Map<Integer,String> mapString,
32 Generic<Integer,String,Double,Short,Float> test,
33 String sampleField, int one, short two, double three, Object obj) {
35 this.sampleField = sampleField;
40 /*public String getSampleField() {
44 /*public void setSampleField(String sampleField) {
45 this.sampleField = sampleField;
48 public List<String> setSampleField(List<String> listString) {
53 private static int digitsPerInt[] = {0, 0, 30, 19, 15, 13, 11,
54 11, 10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
55 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5};
57 private static long bitsPerDigit[] = { 0, 0,
58 1024, 1624, 2048, 2378, 2648, 2875, 3072, 3247, 3402, 3543, 3672,
59 3790, 3899, 4001, 4096, 4186, 4271, 4350, 4426, 4498, 4567, 4633,
60 4696, 4756, 4814, 4870, 4923, 4975, 5025, 5074, 5120, 5166, 5210,
63 public static void main(String[] args) {
65 /*Method[] methods = SampleClass.class.getMethods();
66 // Method[] methods = Class.class.getMethods();
68 for(Method meth : methods) {
69 if (meth.getName().equals("setSampleField")) {
73 Type[] parameters = method.getGenericParameterTypes();
74 //Type[] parameters = methods[0].getGenericParameterTypes();
75 for (int i = 0; i < parameters.length; i++) {
76 System.out.println(parameters[i]);
79 Type returnType = method.getGenericReturnType();
80 Class.class.getSimpleName();*/
81 //System.out.println(returnType);
82 BigInteger bi = new BigInteger("-1");
83 System.out.println(bi);
85 /* TODO: This is an excerpt of the BigInteger library
91 int cursor = 0, numDigits;
92 final int len = val.length();
94 if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
95 throw new NumberFormatException("Radix out of range");
97 throw new NumberFormatException("Zero length BigInteger");
99 // Check for at most one leading sign
101 int index1 = val.lastIndexOf('-');
102 int index2 = val.lastIndexOf('+');
104 if (index1 != 0 || index2 >= 0) {
105 throw new NumberFormatException("Illegal embedded sign character");
109 } else if (index2 >= 0) {
111 throw new NumberFormatException("Illegal embedded sign character");
115 System.out.println(cursor);
117 throw new NumberFormatException("Zero length BigInteger");
119 // Skip leading zeros and compute number of digits in magnitude
120 while (cursor < len &&
121 Character.digit(val.charAt(cursor), radix) == 0) {
132 numDigits = len - cursor;
135 long numBits = ((numDigits * bitsPerDigit[radix]) >>> 10) + 1;
136 if (numBits + 31 >= (1L << 32)) {
137 System.out.println("Overflow!");
139 int numWords = (int) (numBits + 31) >>> 5;
140 int[] magnitude = new int[numWords];
142 // Process first (potentially short) digit group
143 int firstGroupLen = numDigits % digitsPerInt[radix];
144 if (firstGroupLen == 0)
145 firstGroupLen = digitsPerInt[radix];
146 int cursor2 = cursor + firstGroupLen;
147 String group = val.substring(cursor, cursor2);
148 magnitude[numWords - 1] = Integer.parseInt(group, radix);
149 if (magnitude[numWords - 1] < 0)
150 throw new NumberFormatException("Illegal digit");*/
152 /*Type superCls = Generic.class.getGenericSuperclass();
153 //Type superCls = String.class.getGenericSuperclass();
154 System.out.println(superCls);
155 System.out.println();
156 Type[] interfaces = Generic.class.getGenericInterfaces();
157 for (int i = 0; i < interfaces.length; i++) {
158 System.out.println(interfaces[i]);
162 /*Method[] methods = Class.class.getMethods();
163 Method method = null;
164 for(Method mth : methods) {
165 if (mth.getName().equals("getConstructor")) {
166 //if (mth.getName().equals("isAssignableFrom")) {
167 //if (mth.getName().equals("getSuperclass")) {
171 Type[] parameters = method.getGenericParameterTypes();
172 //Type[] parameters = methods[0].getGenericParameterTypes();
173 for (int i = 0; i < parameters.length; i++) {
174 System.out.println(parameters[i]);
176 System.out.println();
177 Type returnType = method.getGenericReturnType();
178 System.out.println(returnType);*/
180 /* TODO: Enumerate all methods in Class.class
181 Method[] methods = Class.class.getMethods();
182 for(Method mth : methods) {
183 System.out.println("===========================");
184 System.out.println("Method: " + mth.getName());
185 Type[] parameters = mth.getGenericParameterTypes();
186 for (int i = 0; i < parameters.length; i++) {
187 System.out.println(parameters[i]);
189 System.out.println();
190 Type returnType = mth.getGenericReturnType();
191 System.out.println(returnType + "\n");
194 /*Class[] parameterTypes = methods[0].getParameterTypes();
195 for(Class parameterType: parameterTypes){
196 System.out.println(parameterType.getName());
199 System.out.println();*/
200 /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
201 //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
202 for(TypeVariable typeVar: typeParameters){
203 System.out.println(typeVar);
206 System.out.println();
208 Type[] bounds = typeParameters[0].getBounds();
209 for (Type bound : bounds) {
210 System.out.println(bound);
212 System.out.println();*/