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 import java.beans.Introspector;
17 public class Reflection {
19 interface GenericSuperShort<XYZ> {
23 class GenericShort<TUVW,ABCD> {
26 class Generic<TUVW,ABCD,KLM,NOP,XYZ> extends GenericShort<TUVW,ABCD> implements GenericSuperShort<XYZ>, Serializable {
30 class SampleClass<VWXZ> {
31 private String sampleField;
33 public Class<?> setSampleField(Class<?> clazz,
34 Class<? extends List> list, Class<? super Map> map, Class<?> clazz2, Class<VWXZ> clazz3,
35 List<String> listString, Map<Integer,String> mapString,
36 Generic<Integer,String,Double,Short,Float> test,
37 String sampleField, int one, short two, double three, Object obj) {
39 this.sampleField = sampleField;
44 /*public String getSampleField() {
48 /*public void setSampleField(String sampleField) {
49 this.sampleField = sampleField;
52 public List<String> setSampleField(List<String> listString) {
57 public static void main(String[] args) throws Exception {
59 //BigInteger bi = new BigInteger("-1");
60 //System.out.println(bi);
61 /*StringBuilder sb = new StringBuilder(0);
64 System.out.println(sb.toString());*/
66 //Class cls = Class.forName("groovy.runtime.metaclass.Logger.LoggerMetaClass");
67 //Class cls2 = Class.forName("groovy.runtime.metaclass.[Ljava.lang.Object;MetaClass");
68 //Class cls2 = Class.forName("[Ljava.lang.Object;BeanInfo");
69 Class cls = Object[].class;
70 System.out.println("Bean introspection do not ignore bean info: " + cls.getSimpleName());
71 System.out.println("Bean introspection do not ignore bean info: " + cls.getName());
72 Object obj = Introspector.getBeanInfo(cls);
74 /* TODO: Enumerate all methods in Class.class
75 Method[] methods = Collection.class.getMethods();
76 for(Method mth : methods) {
77 System.out.println("===========================");
78 //System.out.println("Method: " + mth.getName());
79 Type[] parameters = mth.getGenericParameterTypes();
80 for (int i = 0; i < parameters.length; i++) {
81 System.out.println(parameters[i]);
84 Type returnType = mth.getGenericReturnType();
85 System.out.println(returnType + "\n");
88 /*Method[] methods = Collection.class.getMethods();
89 // Method[] methods = Class.class.getMethods();
91 for(Method meth : methods) {
92 System.out.println("===========================");
93 //System.out.println("Method: " + meth.toString());
94 Type[] parameters = meth.getGenericParameterTypes();
95 for (int i = 0; i < parameters.length; i++) {
96 System.out.println(parameters[i]);
98 Type returnType = meth.getGenericReturnType();
99 System.out.println(returnType);
100 System.out.println("===========================");
103 /* TODO: This is an excerpt of the BigInteger library
109 int cursor = 0, numDigits;
110 final int len = val.length();
112 if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
113 throw new NumberFormatException("Radix out of range");
115 throw new NumberFormatException("Zero length BigInteger");
117 // Check for at most one leading sign
119 int index1 = val.lastIndexOf('-');
120 int index2 = val.lastIndexOf('+');
122 if (index1 != 0 || index2 >= 0) {
123 throw new NumberFormatException("Illegal embedded sign character");
127 } else if (index2 >= 0) {
129 throw new NumberFormatException("Illegal embedded sign character");
133 System.out.println(cursor);
135 throw new NumberFormatException("Zero length BigInteger");
137 // Skip leading zeros and compute number of digits in magnitude
138 while (cursor < len &&
139 Character.digit(val.charAt(cursor), radix) == 0) {
150 numDigits = len - cursor;
153 long numBits = ((numDigits * bitsPerDigit[radix]) >>> 10) + 1;
154 if (numBits + 31 >= (1L << 32)) {
155 System.out.println("Overflow!");
157 int numWords = (int) (numBits + 31) >>> 5;
158 int[] magnitude = new int[numWords];
160 // Process first (potentially short) digit group
161 int firstGroupLen = numDigits % digitsPerInt[radix];
162 if (firstGroupLen == 0)
163 firstGroupLen = digitsPerInt[radix];
164 int cursor2 = cursor + firstGroupLen;
165 String group = val.substring(cursor, cursor2);
166 magnitude[numWords - 1] = Integer.parseInt(group, radix);
167 if (magnitude[numWords - 1] < 0)
168 throw new NumberFormatException("Illegal digit");*/
170 /*Type superCls = Generic.class.getGenericSuperclass();
171 //Type superCls = String.class.getGenericSuperclass();
172 System.out.println(superCls);
173 System.out.println();
174 Type[] interfaces = Generic.class.getGenericInterfaces();
175 for (int i = 0; i < interfaces.length; i++) {
176 System.out.println(interfaces[i]);
180 /*Method[] methods = Map.class.getMethods();
181 Method method = null;
182 for(Method mth : methods) {
183 if (mth.getName().equals("putAll")) {
184 //if (mth.getName().equals("isAssignableFrom")) {
185 //if (mth.getName().equals("getSuperclass")) {
190 Type[] parameters = method.getGenericParameterTypes();
191 //Type[] parameters = methods[0].getGenericParameterTypes();
192 for (int i = 0; i < parameters.length; i++) {
193 System.out.println(parameters[i]);
195 System.out.println();
196 Type returnType = method.getGenericReturnType();
197 System.out.println(returnType);*/
199 /*Class[] parameterTypes = methods[0].getParameterTypes();
200 for(Class parameterType: parameterTypes){
201 System.out.println(parameterType.getName());
204 System.out.println();*/
205 /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
206 //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
207 for(TypeVariable typeVar: typeParameters){
208 System.out.println(typeVar);
211 System.out.println();
213 Type[] bounds = typeParameters[0].getBounds();
214 for (Type bound : bounds) {
215 System.out.println(bound);
217 System.out.println();*/
219 //ProtectionDomain pd = Class.class.getProtectionDomain();
220 //System.out.println(pd);