return staticFetchers.containsKey(name)
|| instanceFetchers.containsKey(name);
}
private void init() {
FieldCallback fieldCallback = new ReflectionUtils.FieldCallback() {
public void doWith(Field field) {
if (field.isSynthetic()) {
return;
}
final int modifiers = field.getModifiers();
if (!Modifier.isPublic(modifiers)) {
return;
}
final String name = field.getName();
if (name.indexOf('$') == -1) {
boolean staticField = Modifier.isStatic(modifiers);
if (staticField) {
staticFetchers.put(name, new FieldReaderFetcher(field,
staticField));
} else {
instanceFetchers.put(name, new FieldReaderFetcher(
field, staticField));
}
}
}
};
MethodCallback methodCallback = new ReflectionUtils.MethodCallback() {
public void doWith(Method method) throws IllegalArgumentException,
IllegalAccessException {
if (method.isSynthetic()) {
return;
}
if (!Modifier.isPublic(method.getModifiers())) {
return;
}
if (Modifier.isStatic(method.getModifiers())
&& method.getReturnType() != Void.class) {
if (method.getParameterTypes().length == 0) {
String name = method.getName();
if (name.indexOf('$') == -1) {
if (name.length() > 3 && name.startsWith("get")
&& Character.isUpperCase(name.charAt(3))) {
name = name.substring(3);
} else if (name.length() > 2
&& name.startsWith("is")
&& Character.isUpperCase(name.charAt(2))
&& (method.getReturnType() == Boolean.class ||
method.getReturnType() == boolean.class)) {
name = name.substring(2);
}
PropertyFetcher fetcher = new GetterPropertyFetcher(
method, true);
staticFetchers.put(name, fetcher);
staticFetchers.put(StringUtils.uncapitalize(name), fetcher);
}
}
}
}
};
List<Class<?>> allClasses = resolveAllClasses(clazz);
for (Class<?> c : allClasses) {
Field[] fields = c.getDeclaredFields();
for (Field field : fields) {
try {
fieldCallback.doWith(field);
} catch (IllegalAccessException ex) {
throw new IllegalStateException(
"Shouldn't be illegal to access field '"
+ field.getName() + "': " + ex);
}