90 |
} |
} |
91 |
|
|
92 |
/** Cache of methods found in getAllMethods(). */ |
/** Cache of methods found in getAllMethods(). */ |
93 |
static Hashtable allMethods = new Hashtable(); |
private static Map allMethods = new HashMap(); |
|
|
|
|
/** Cache of methods found in getAllMethodsAtDeclaration(). */ |
|
|
static Hashtable allMethodsAtDeclaration = new Hashtable(); |
|
94 |
|
|
95 |
/** |
/** |
96 |
* Get all the methods, public, private and otherwise, from the class, |
* Get all the methods, public, private and otherwise, from the class, |
97 |
* getting them from the most recent class to find them. |
* getting them from the most recent class to find them. This may not |
98 |
|
* be quite the correct approach, as this includes methods that are not |
99 |
|
* inherited or accessible from clazz, so beware. |
100 |
* |
* |
101 |
* @param clazz the class to start at |
* @param clazz the class to start at |
102 |
* @return all methods declared or inherited in clazz |
* @return all methods declared or inherited in clazz |
106 |
Method[] retval = (Method[]) allMethods.get(clazz); |
Method[] retval = (Method[]) allMethods.get(clazz); |
107 |
if (retval == null) |
if (retval == null) |
108 |
{ |
{ |
109 |
Method[] superMethods; |
Set methods = new HashSet(); |
110 |
if (clazz.getSuperclass() != null) |
Class c = clazz; |
111 |
superMethods = getAllMethods(clazz.getSuperclass()); |
while (c != null) |
|
else |
|
|
superMethods = new Method[0]; |
|
|
Vector v = new Vector(); |
|
|
Method[] currentMethods = clazz.getDeclaredMethods(); |
|
|
for (int i = 0; i < currentMethods.length; i++) |
|
|
v.addElement(currentMethods[i]); |
|
|
for (int i = 0; i < superMethods.length; i++) |
|
|
{ |
|
|
boolean addOK = true; |
|
|
for (int j = 0; j < currentMethods.length; j++) |
|
|
{ |
|
|
if (getTruncatedName(superMethods[i].getName()) |
|
|
.equals(getTruncatedName(currentMethods[j].getName())) |
|
|
&& ArrayHelper.equalsArray(superMethods[i].getParameterTypes(), |
|
|
currentMethods[j].getParameterTypes())) |
|
|
{ |
|
|
addOK = false; |
|
|
} |
|
|
} |
|
|
if(addOK) |
|
|
v.addElement(superMethods[i]); |
|
|
} |
|
|
retval = new Method[v.size()]; |
|
|
v.copyInto(retval); |
|
|
allMethods.put(clazz,retval); |
|
|
} |
|
|
return retval; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Get all the methods, public, private and otherwise, from the class, |
|
|
* and get them from their point of declaration. |
|
|
* |
|
|
* @param clazz the class to start at |
|
|
* @return all methods declared or inherited in clazz |
|
|
*/ |
|
|
public static Method[] getAllMethodsAtDeclaration(Class clazz) |
|
|
{ |
|
|
Method[] retval = (Method[]) allMethodsAtDeclaration.get(clazz); |
|
|
if (retval == null) |
|
|
{ |
|
|
Method[] superMethods; |
|
|
if (clazz.getSuperclass() != null) |
|
|
superMethods = getAllMethodsAtDeclaration(clazz.getSuperclass()); |
|
|
else |
|
|
superMethods = new Method[0]; |
|
|
Vector v = new Vector(); |
|
|
Method[] currentMethods = clazz.getDeclaredMethods(); |
|
|
for (int i = 0; i < superMethods.length; i++) |
|
|
v.addElement(superMethods[i]); |
|
|
for (int i = 0; i < superMethods.length; i++) |
|
112 |
{ |
{ |
113 |
boolean addOK = true; |
Method[] currentMethods = c.getDeclaredMethods(); |
114 |
for (int j = 0; j < currentMethods.length; j++) |
loop: |
115 |
|
for (int i = 0; i < currentMethods.length; i++) |
116 |
{ |
{ |
117 |
if (getTruncatedName(superMethods[i].getName()) |
Method current = currentMethods[i]; |
118 |
.equals(getTruncatedName(currentMethods[j].getName())) |
int size = methods.size(); |
119 |
&& ArrayHelper.equalsArray(superMethods[i].getParameterTypes(), |
Iterator iter = methods.iterator(); |
120 |
currentMethods[j].getParameterTypes())) |
while (--size >= 0) |
121 |
{ |
{ |
122 |
addOK = false; |
Method override = (Method) iter.next(); |
123 |
|
if (current.getName().equals(override.getName()) |
124 |
|
&& Arrays.equals(current.getParameterTypes(), |
125 |
|
override.getParameterTypes()) |
126 |
|
&& current.getReturnType() == override.getReturnType()) |
127 |
|
continue loop; |
128 |
} |
} |
129 |
|
methods.add(current); |
130 |
} |
} |
131 |
if(addOK) |
c = c.getSuperclass(); |
|
v.addElement(superMethods[i]); |
|
132 |
} |
} |
133 |
retval = new Method[v.size()]; |
retval = new Method[methods.size()]; |
134 |
v.copyInto(retval); |
methods.toArray(retval); |
135 |
allMethodsAtDeclaration.put(clazz,retval); |
allMethods.put(clazz, retval); |
136 |
} |
} |
137 |
return retval; |
return retval; |
138 |
} |
} |
139 |
|
|
140 |
/** Cache of fields found in getAllFields(). */ |
/** Cache of fields found in getAllFields(). */ |
141 |
static Hashtable allFields = new Hashtable(); |
private static Map allFields = new HashMap(); |
|
|
|
|
/** Cache of fields found in getAllFieldsAtDeclaration(). */ |
|
|
static Hashtable allFieldsAtDeclaration = new Hashtable(); |
|
142 |
|
|
143 |
/** |
/** |
144 |
* Get all the fields, public, private and otherwise, from the class, |
* Get all the fields, public, private and otherwise, from the class, |
145 |
* getting them from the most recent class to find them. |
* getting them from the most recent class to find them. This may not |
146 |
|
* be quite the correct approach, as this includes fields that are not |
147 |
|
* inherited or accessible from clazz, so beware. |
148 |
* |
* |
149 |
* @param clazz the class to start at |
* @param clazz the class to start at |
150 |
* @return all fields declared or inherited in clazz |
* @return all fields declared or inherited in clazz |
154 |
Field[] retval = (Field[]) allFields.get(clazz); |
Field[] retval = (Field[]) allFields.get(clazz); |
155 |
if (retval == null) |
if (retval == null) |
156 |
{ |
{ |
157 |
Field[] superFields; |
Set fields = new HashSet(); |
158 |
if (clazz.getSuperclass() != null) |
Class c = clazz; |
159 |
superFields = getAllFields(clazz.getSuperclass()); |
while (c != null) |
|
else |
|
|
superFields = new Field[0]; |
|
|
Vector v = new Vector(); |
|
|
Field[] currentFields = clazz.getDeclaredFields(); |
|
|
for (int i = 0; i < currentFields.length; i++) |
|
|
v.addElement(currentFields[i]); |
|
|
for (int i = 0; i < superFields.length; i++) |
|
|
{ |
|
|
boolean addOK = true; |
|
|
for (int j = 0; j < currentFields.length; j++) |
|
|
{ |
|
|
if (getTruncatedName(superFields[i].getName()) |
|
|
.equals(getTruncatedName(currentFields[j].getName()))) |
|
|
{ |
|
|
addOK = false; |
|
|
} |
|
|
} |
|
|
if (addOK) |
|
|
v.addElement(superFields[i]); |
|
|
} |
|
|
retval = new Field[v.size()]; |
|
|
v.copyInto(retval); |
|
|
allFields.put(clazz,retval); |
|
|
} |
|
|
return retval; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Get all the fields, public, private and otherwise, from the class, |
|
|
* and get them from their point of declaration. |
|
|
* |
|
|
* @param clazz the class to start at |
|
|
* @return all fields declared or inherited in clazz |
|
|
*/ |
|
|
public static Field[] getAllFieldsAtDeclaration(Class clazz) |
|
|
{ |
|
|
Field[] retval = (Field[]) allFieldsAtDeclaration.get(clazz); |
|
|
if (retval == null) |
|
|
{ |
|
|
Field[] superFields; |
|
|
if (clazz.getSuperclass() != null) |
|
|
superFields = getAllFieldsAtDeclaration(clazz.getSuperclass()); |
|
|
else |
|
|
superFields = new Field[0]; |
|
|
Vector v = new Vector(); |
|
|
Field[] currentFields = clazz.getDeclaredFields(); |
|
|
for (int i = 0; i < superFields.length; i++) |
|
|
v.addElement(superFields[i]); |
|
|
for (int i = 0; i < superFields.length; i++) |
|
160 |
{ |
{ |
161 |
boolean addOK = true; |
Field[] currentFields = c.getDeclaredFields(); |
162 |
for (int j = 0; j < currentFields.length; j++) |
loop: |
163 |
|
for (int i = 0; i < currentFields.length; i++) |
164 |
{ |
{ |
165 |
if (getTruncatedName(superFields[i].getName()) |
Field current = currentFields[i]; |
166 |
.equals(getTruncatedName(currentFields[j].getName()))) |
int size = fields.size(); |
167 |
|
Iterator iter = fields.iterator(); |
168 |
|
while (--size >= 0) |
169 |
{ |
{ |
170 |
addOK = false; |
Field override = (Field) iter.next(); |
171 |
|
if (current.getName().equals(override.getName()) |
172 |
|
&& current.getType() == override.getType()) |
173 |
|
continue loop; |
174 |
} |
} |
175 |
|
fields.add(current); |
176 |
} |
} |
177 |
if(addOK) |
c = c.getSuperclass(); |
|
v.addElement(superFields[i]); |
|
178 |
} |
} |
179 |
retval = new Field[v.size()]; |
retval = new Field[fields.size()]; |
180 |
v.copyInto(retval); |
fields.toArray(retval); |
181 |
allFieldsAtDeclaration.put(clazz,retval); |
allFields.put(clazz, retval); |
182 |
} |
} |
183 |
return retval; |
return retval; |
184 |
} |
} |