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;
12 import java.security.ProtectionDomain;
14 public class Reflection {
16 interface GenericSuperShort<XYZ> {
20 class GenericShort<TUVW,ABCD> {
23 class Generic<TUVW,ABCD,KLM,NOP,XYZ> extends GenericShort<TUVW,ABCD> implements GenericSuperShort<XYZ>, Serializable {
27 class SampleClass<VWXZ> {
28 private String sampleField;
30 public Class<?> setSampleField(Class<?> clazz,
31 Class<? extends List> list, Class<? super Map> map, Class<?> clazz2, Class<VWXZ> clazz3,
32 List<String> listString, Map<Integer,String> mapString,
33 Generic<Integer,String,Double,Short,Float> test,
34 String sampleField, int one, short two, double three, Object obj) {
36 this.sampleField = sampleField;
41 /*public String getSampleField() {
45 /*public void setSampleField(String sampleField) {
46 this.sampleField = sampleField;
49 public List<String> setSampleField(List<String> listString) {
54 private static int digitsPerInt[] = {0, 0, 30, 19, 15, 13, 11,
55 11, 10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
56 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5};
58 private static long bitsPerDigit[] = { 0, 0,
59 1024, 1624, 2048, 2378, 2648, 2875, 3072, 3247, 3402, 3543, 3672,
60 3790, 3899, 4001, 4096, 4186, 4271, 4350, 4426, 4498, 4567, 4633,
61 4696, 4756, 4814, 4870, 4923, 4975, 5025, 5074, 5120, 5166, 5210,
64 public static void main(String[] args) {
66 /*Method[] methods = SampleClass.class.getMethods();
67 // Method[] methods = Class.class.getMethods();
69 for(Method meth : methods) {
70 if (meth.getName().equals("setSampleField")) {
74 Type[] parameters = method.getGenericParameterTypes();
75 //Type[] parameters = methods[0].getGenericParameterTypes();
76 for (int i = 0; i < parameters.length; i++) {
77 System.out.println(parameters[i]);
80 Type returnType = method.getGenericReturnType();
81 Class.class.getSimpleName();*/
82 //System.out.println(returnType);
84 //BigInteger bi = new BigInteger("-1");
85 //System.out.println(bi);
87 /* TODO: This is an excerpt of the BigInteger library
93 int cursor = 0, numDigits;
94 final int len = val.length();
96 if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
97 throw new NumberFormatException("Radix out of range");
99 throw new NumberFormatException("Zero length BigInteger");
101 // Check for at most one leading sign
103 int index1 = val.lastIndexOf('-');
104 int index2 = val.lastIndexOf('+');
106 if (index1 != 0 || index2 >= 0) {
107 throw new NumberFormatException("Illegal embedded sign character");
111 } else if (index2 >= 0) {
113 throw new NumberFormatException("Illegal embedded sign character");
117 System.out.println(cursor);
119 throw new NumberFormatException("Zero length BigInteger");
121 // Skip leading zeros and compute number of digits in magnitude
122 while (cursor < len &&
123 Character.digit(val.charAt(cursor), radix) == 0) {
134 numDigits = len - cursor;
137 long numBits = ((numDigits * bitsPerDigit[radix]) >>> 10) + 1;
138 if (numBits + 31 >= (1L << 32)) {
139 System.out.println("Overflow!");
141 int numWords = (int) (numBits + 31) >>> 5;
142 int[] magnitude = new int[numWords];
144 // Process first (potentially short) digit group
145 int firstGroupLen = numDigits % digitsPerInt[radix];
146 if (firstGroupLen == 0)
147 firstGroupLen = digitsPerInt[radix];
148 int cursor2 = cursor + firstGroupLen;
149 String group = val.substring(cursor, cursor2);
150 magnitude[numWords - 1] = Integer.parseInt(group, radix);
151 if (magnitude[numWords - 1] < 0)
152 throw new NumberFormatException("Illegal digit");*/
154 /*Type superCls = Generic.class.getGenericSuperclass();
155 //Type superCls = String.class.getGenericSuperclass();
156 System.out.println(superCls);
157 System.out.println();
158 Type[] interfaces = Generic.class.getGenericInterfaces();
159 for (int i = 0; i < interfaces.length; i++) {
160 System.out.println(interfaces[i]);
164 /*Method[] methods = Class.class.getMethods();
165 Method method = null;
166 for(Method mth : methods) {
167 if (mth.getName().equals("getConstructor")) {
168 //if (mth.getName().equals("isAssignableFrom")) {
169 //if (mth.getName().equals("getSuperclass")) {
173 Type[] parameters = method.getGenericParameterTypes();
174 //Type[] parameters = methods[0].getGenericParameterTypes();
175 for (int i = 0; i < parameters.length; i++) {
176 System.out.println(parameters[i]);
178 System.out.println();
179 Type returnType = method.getGenericReturnType();
180 System.out.println(returnType);*/
182 /* TODO: Enumerate all methods in Class.class */
183 /*Method[] methods = Class.class.getMethods();
184 for(Method mth : methods) {
185 System.out.println("===========================");
186 System.out.println("Method: " + mth.getName());
187 Type[] parameters = mth.getGenericParameterTypes();
188 for (int i = 0; i < parameters.length; i++) {
189 System.out.println(parameters[i]);
191 System.out.println();
192 Type returnType = mth.getGenericReturnType();
193 System.out.println(returnType + "\n");
196 /*Class[] parameterTypes = methods[0].getParameterTypes();
197 for(Class parameterType: parameterTypes){
198 System.out.println(parameterType.getName());
201 System.out.println();*/
202 /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
203 //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
204 for(TypeVariable typeVar: typeParameters){
205 System.out.println(typeVar);
208 System.out.println();
210 Type[] bounds = typeParameters[0].getBounds();
211 for (Type bound : bounds) {
212 System.out.println(bound);
214 System.out.println();*/
216 ProtectionDomain pd = Class.class.getProtectionDomain();
217 System.out.println(pd);