else { String field_name=Util.methodNameToAttributeName(method.getName()); method_name=Util.attributeNameToMethodName(field_name);
else { String field_name=Util.methodNameToAttributeName(method.getName()); method_name=Util.attributeNameToMethodName(field_name);
else { String field_name=Util.methodNameToAttributeName(method.getName()); method_name=Util.attributeNameToMethodName(field_name);
/** Finds an accessor for an attribute. Tries to find setAttrName(), attrName() methods. If not * found, tries to use reflection to set the value of attr_name. If still not found, creates a NullAccessor. */ public static Accessor findSetter(Object target, String attr_name) { final String name=Util.attributeNameToMethodName(attr_name); final String fluent_name=toLowerCase(name); Class<?> clazz=target.getClass(); Class<?> field_type=null; Field field=Util.getField(clazz, attr_name); field_type=field != null? field.getType() : null; String setter_name="set" + name; if(field_type != null) { Method method=Util.findMethod(target, Arrays.asList(fluent_name, setter_name), field_type); if(method != null && isSetMethod(method)) return new MethodAccessor(method, target); } // Find all methods but don't include methods from Object class List<Method> methods=new ArrayList<>(Arrays.asList(clazz.getMethods())); methods.removeAll(OBJECT_METHODS); for(Method method: methods) { String method_name=method.getName(); if((method_name.equals(name) || method_name.equals(fluent_name) || method_name.equals(setter_name)) && isSetMethod(method)) return new MethodAccessor(method, target); } // Find a field last_name if(field != null) return new FieldAccessor(field, target); return new NoopAccessor(); }
/** Finds an accessor for an attribute. Tries to find setAttrName(), attrName() methods. If not * found, tries to use reflection to set the value of attr_name. If still not found, creates a NullAccessor. */ public static Accessor findSetter(Object target, String attr_name) { final String name=Util.attributeNameToMethodName(attr_name); final String fluent_name=toLowerCase(name); Class<?> clazz=target.getClass(); Class<?> field_type=null; Field field=Util.getField(clazz, attr_name); field_type=field != null? field.getType() : null; String setter_name="set" + name; if(field_type != null) { Method method=Util.findMethod(target, Arrays.asList(fluent_name, setter_name), field_type); if(method != null && isSetMethod(method)) return new MethodAccessor(method, target); } // Find all methods but don't include methods from Object class List<Method> methods=new ArrayList<>(Arrays.asList(clazz.getMethods())); methods.removeAll(OBJECT_METHODS); for(Method method: methods) { String method_name=method.getName(); if((method_name.equals(name) || method_name.equals(fluent_name) || method_name.equals(setter_name)) && isSetMethod(method)) return new MethodAccessor(method, target); } // Find a field last_name if(field != null) return new FieldAccessor(field, target); return new NoopAccessor(); }
/** Finds an accessor for an attribute. Tries to find setAttrName(), attrName() methods. If not * found, tries to use reflection to set the value of attr_name. If still not found, creates a NullAccessor. */ public static Accessor findSetter(Object target, String attr_name) { final String name=Util.attributeNameToMethodName(attr_name); final String fluent_name=toLowerCase(name); Class<?> clazz=target.getClass(); Class<?> field_type=null; Field field=Util.getField(clazz, attr_name); field_type=field != null? field.getType() : null; String setter_name="set" + name; if(field_type != null) { Method method=Util.findMethod(target, Arrays.asList(fluent_name, setter_name), field_type); if(method != null && isSetMethod(method)) return new MethodAccessor(method, target); } // Find all methods but don't include methods from Object class List<Method> methods=new ArrayList<>(Arrays.asList(clazz.getMethods())); methods.removeAll(OBJECT_METHODS); for(Method method: methods) { String method_name=method.getName(); if((method_name.equals(name) || method_name.equals(fluent_name) || method_name.equals(setter_name)) && isSetMethod(method)) return new MethodAccessor(method, target); } // Find a field last_name if(field != null) return new FieldAccessor(field, target); return new NoopAccessor(); }
/** Finds an accessor for an attribute. Tries to find getAttrName(), isAttrName(), attrName() methods. If not * found, tries to use reflection to get the value of attr_name. If still not found, creates a NullAccessor. */ protected static Accessor findGetter(Object target, String attr_name) { final String name=Util.attributeNameToMethodName(attr_name); Class<?> clazz=target.getClass(); Method method=Util.findMethod(target, Arrays.asList("get" + name, "is" + name, toLowerCase(name))); if(method != null && (isGetMethod(method) || isIsMethod(method))) return new MethodAccessor(method, target); // 4. Find a field last_name Field field=Util.getField(clazz, attr_name); if(field != null) return new FieldAccessor(field, target); return new NoopAccessor(); }
/** Finds an accessor for an attribute. Tries to find getAttrName(), isAttrName(), attrName() methods. If not * found, tries to use reflection to get the value of attr_name. If still not found, creates a NullAccessor. */ protected static Accessor findGetter(Object target, String attr_name) { final String name=Util.attributeNameToMethodName(attr_name); Class<?> clazz=target.getClass(); Method method=Util.findMethod(target, Arrays.asList("get" + name, "is" + name, toLowerCase(name))); if(method != null && (isGetMethod(method) || isIsMethod(method))) return new MethodAccessor(method, target); // 4. Find a field last_name Field field=Util.getField(clazz, attr_name); if(field != null) return new FieldAccessor(field, target); return new NoopAccessor(); }
/** Finds an accessor for an attribute. Tries to find getAttrName(), isAttrName(), attrName() methods. If not * found, tries to use reflection to get the value of attr_name. If still not found, creates a NullAccessor. */ protected static Accessor findGetter(Object target, String attr_name) { final String name=Util.attributeNameToMethodName(attr_name); Class<?> clazz=target.getClass(); Method method=Util.findMethod(target, Arrays.asList("get" + name, "is" + name, toLowerCase(name))); if(method != null && (isGetMethod(method) || isIsMethod(method))) return new MethodAccessor(method, target); // 4. Find a field last_name Field field=Util.getField(clazz, attr_name); if(field != null) return new FieldAccessor(field, target); return new NoopAccessor(); }