List of utility methods to do Reflection Field Find
AnnotatedElement | findField0(Class clazz, String name, String methodName) find Field if (clazz == Object.class) { return null; try { return clazz.getDeclaredField(name); } catch (NoSuchFieldException e) { try { return clazz.getDeclaredMethod(methodName); ... |
Field | findFieldByName(Class> owner, String name) find Field By Name try { return owner.getDeclaredField(name); } catch (NoSuchFieldException e) { return findFieldByName(owner.getSuperclass(), name); |
Field | findFieldEx(Class> type, Class find Field Ex for (Field field : type.getDeclaredFields()) { if (field.getAnnotation(annotationClass) != null) { return field; throw new IllegalArgumentException("Specific ".concat(type.getName()).concat(" must have annotation ") .concat(annotationClass.getName())); |
Field | findFieldFromClassHierarchy(Class> clazz, String fieldName) Finds the requested field from the class hierarchy. Class<?> current = clazz; do { try { return current.getDeclaredField(fieldName); } catch (Exception e) { } while ((current = current.getSuperclass()) != null); throw new NoSuchFieldException(String.format("No field found with the field name %s", fieldName)); ... |
Field | findFieldFromGetter(Class> clazz, Method method) Find field from getter. String fieldName = getFieldNameFromGetter(method.getName());
Field found = findField(clazz, fieldName);
return found;
|
Field | findFieldIn(Class> type, String name) find Field In Field foundField = null; Class<?> currentClass = type; while (currentClass != null && currentClass != Object.class && foundField == null) { for (Field currentField : currentClass.getDeclaredFields()) { if (currentField.getName().equals(name)) { foundField = currentField; break; currentClass = currentClass.getSuperclass(); return foundField; |
Field | findFieldInClass(Class> clazz, String fieldName) find Field In Class try { return clazz.getDeclaredField(fieldName); catch (NoSuchFieldException e) { if (clazz.getSuperclass().equals(Object.class)) { throw e; return findFieldInClass(clazz.getSuperclass(), fieldName); ... |
Field | findFieldInClassHierarchy(Class> clazz, String fieldName) find Field In Class Hierarchy Field field = getDeclaredField(clazz, fieldName); while (field == null && clazz != Object.class) { clazz = clazz.getSuperclass(); field = getDeclaredField(clazz, fieldName); return field; |
Field | findFieldIncludeSuperclass(String fieldName, Class> clazz) find Field Include Superclass Field retValue = null; try { retValue = clazz.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { clazz = clazz.getSuperclass(); if (clazz != null) { retValue = findFieldIncludeSuperclass(fieldName, clazz); return retValue; |
void | findFieldInternal(Class currentClass, Class extends Annotation> annotation, Set find Field Internal for (Field field : currentClass.getDeclaredFields()) { if (isAnnotationListed(annotation, field.getDeclaredAnnotations())) { fields.add(field); |