Revision a97b23e3
Added by Andreas Müller about 15 years ago
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/CdmUtils.java | ||
---|---|---|
316 | 316 |
* @param clazz |
317 | 317 |
* @return |
318 | 318 |
*/ |
319 |
public static Map<String, Field> getAllFields(Class clazz, Class highestClass, boolean includeStatic, boolean includeTransient, boolean makeAccessible) { |
|
319 |
public static Map<String, Field> getAllFields(Class clazz, Class highestClass, boolean includeStatic, boolean includeTransient, boolean makeAccessible, boolean includeHighestClass) {
|
|
320 | 320 |
Map<String, Field> result = new HashMap<String, Field>(); |
321 |
//exclude static |
|
322 |
for (Field field: clazz.getDeclaredFields()){ |
|
323 |
if (includeStatic || ! Modifier.isStatic(field.getModifiers())){ |
|
324 |
if (includeTransient || ! isTransient(field)){ |
|
325 |
field.setAccessible(makeAccessible); |
|
326 |
result.put(field.getName(), field); |
|
321 |
if ( highestClass.isAssignableFrom(clazz) && (clazz != highestClass || includeHighestClass)){ |
|
322 |
//exclude static |
|
323 |
for (Field field: clazz.getDeclaredFields()){ |
|
324 |
if (includeStatic || ! Modifier.isStatic(field.getModifiers())){ |
|
325 |
if (includeTransient || ! isTransient(field)){ |
|
326 |
field.setAccessible(makeAccessible); |
|
327 |
result.put(field.getName(), field); |
|
328 |
} |
|
327 | 329 |
} |
328 | 330 |
} |
329 |
} |
|
330 |
|
|
331 |
//include superclass fields
|
|
332 |
Class superclass = clazz.getSuperclass();
|
|
333 |
if (superclass != null && highestClass.isAssignableFrom(superclass)){
|
|
334 |
result.putAll(getAllFields(superclass, highestClass, includeStatic, includeTransient, makeAccessible));
|
|
331 |
|
|
332 |
//include superclass fields |
|
333 |
Class superclass = clazz.getSuperclass();
|
|
334 |
if (superclass != null){
|
|
335 |
result.putAll(getAllFields(superclass, highestClass, includeStatic, includeTransient, makeAccessible, includeHighestClass));
|
|
336 |
}
|
|
335 | 337 |
} |
336 | 338 |
return result; |
337 | 339 |
} |
Also available in: Unified diff
change in signature of CDMUtils.getAllFields