static Object fieldValue(Object value, IOpenField field) { if (value == null) { return null; } if (value.getClass().isArray()) { int length = Array.getLength(value); Object array = Array.newInstance(field.getType().getInstanceClass(), length); for (int i = 0; i < length; i++) { Array.set(array, i, fieldValue(Array.get(value, i), field)); } return array; } else { return field.get(value, null); } }
/** * Find all non empty fields from all test results. * If some field of any test result is not null, it will be included in result. * If some field is null in all test results, it will not be included in result. * WARNING: This method is very expensive! Don't invoke it too often. * * @param type Type of a checking object * @param values All possible values for a given type. Is got from test result. * @return all non empty fields from all test results (values). */ static List<FieldDescriptor> nonEmptyFields(IOpenClass type, List<?> values) { return nonEmptyFieldsForFlatten(type, ExportUtils.flatten(values)); }
List<Object> childFieldValues = ExportUtils.flatten(ExportUtils.fieldValues(values, field));
/** * Returns maximum array elements of the the field value from a given parent object * * @param object parent object (contains this field) * @return max array size if exist or 1 if there are no arrays */ public int getMaxArraySize(Object object) { if (object == null) { return 1; } if (object.getClass().isArray()) { int count = Array.getLength(object); int height = 0; for (int i = 0; i < count; i++) { height += getMaxArraySize(Array.get(object, i)); } return height == 0 ? 1 : height; } Object fieldValue = ExportUtils.fieldValue(object, getField()); return calcArraySizeForChild(fieldValue); }
protected Object getSimpleValue(Object value) { if (value == null) { return null; } if (value instanceof ParameterWithValueDeclaration) { ParameterWithValueDeclaration parameter = (ParameterWithValueDeclaration) value; Object simpleValue = parameter.getValue(); // Return key field for complex objects IOpenField keyField = parameter.getKeyField(); if (keyField != null) { // If key can't be found, return the object itself Object key = ExportUtils.fieldValue(simpleValue, keyField); simpleValue = key == null ? simpleValue : key; } return getSimpleValue(simpleValue); } return value; } }
private void addValueTasks(TreeSet<WriteTask> tasks, Cursor cursor, List<FieldDescriptor> fields, Object value, int rowHeight) { int colNum = cursor.getColNum(); int rowNum = cursor.getRowNum(); if (value != null && value.getClass().isArray()) { int count = Array.getLength(value); int heightLeft = rowHeight; for (int i = 0; i < count; i++) { Object elem = Array.get(value, i); int height = getRowHeight(elem, fields); if (i < count - 1) { addValueTasks(tasks, new Cursor(rowNum, colNum), fields, elem, height); heightLeft -= height; } else { addValueTasks(tasks, new Cursor(rowNum, colNum), fields, elem, heightLeft); } rowNum += height; } } else { for (FieldDescriptor fieldDescriptor : fields) { Object fieldValue = ExportUtils.fieldValue(value, fieldDescriptor.getField()); List<FieldDescriptor> children = fieldDescriptor.getChildren(); if (children == null) { tasks.add(new WriteTask(new Cursor(rowNum, colNum), fieldValue, styles.parameterValue, rowHeight)); } else { addValueTasks(tasks, new Cursor(rowNum, colNum), children, fieldValue, rowHeight); } colNum += fieldDescriptor.getLeafNodeCount(); } } }
Object id = ExportUtils.fieldValue(parameter.getValue(), keyField);