/** * Adds all fields declared directly in the object's class to the output * @return this */ @GwtIncompatible("Class.getDeclaredFields") public ToStringBuilder addDeclaredFields() { Field[] fields = instance.getClass().getDeclaredFields(); for(Field field : fields) { addField(field); } return this; }
/** * @param fieldName the name of the field to add to the output using reflection * @return this */ @GwtIncompatible("Class.getDeclaredField(String)") public ToStringBuilder addField(final String fieldName) { List<Field> fields = getAllDeclaredFields(instance.getClass()); for(Field field : fields) { if(fieldName.equals(field.getName())) { addField(field); break; } } return this; }
/** * Adds all fields declared in the object's class and its superclasses to the output. * @return this */ @GwtIncompatible("Class.getDeclaredFields") public ToStringBuilder addAllFields() { List<Field> fields = getAllDeclaredFields(instance.getClass()); for(Field field : fields) { addField(field); } return this; }
/** * @param fieldName the name of the field to add to the output using reflection * @return this */ @GwtIncompatible("Class.getDeclaredField(String)") public ToStringBuilder addField(final String fieldName) { Class<?> _class = this.instance.getClass(); ArrayList<Field> _allDeclaredFields = this.getAllDeclaredFields(_class); final Function1<Field, Boolean> _function = new Function1<Field, Boolean>() { @Override public Boolean apply(final Field it) { String _name = it.getName(); return Boolean.valueOf(Objects.equal(_name, fieldName)); } }; Field _findFirst = IterableExtensions.<Field>findFirst(_allDeclaredFields, _function); return this.addField(_findFirst); }