Search in sources :

Example 1 with ExcelIgnore

use of com.alibaba.excel.annotation.ExcelIgnore in project easyexcel by alibaba.

the class ClassUtils method declaredOneField.

private static void declaredOneField(Field field, Map<Integer, List<Field>> orderFieldMap, Map<Integer, Field> indexFieldMap, Map<String, Field> ignoreMap, ExcelIgnoreUnannotated excelIgnoreUnannotated) {
    ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class);
    if (excelIgnore != null) {
        ignoreMap.put(field.getName(), field);
        return;
    }
    ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
    boolean noExcelProperty = excelProperty == null && excelIgnoreUnannotated != null;
    if (noExcelProperty) {
        ignoreMap.put(field.getName(), field);
        return;
    }
    boolean isStaticFinalOrTransient = (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) || Modifier.isTransient(field.getModifiers());
    if (excelProperty == null && isStaticFinalOrTransient) {
        ignoreMap.put(field.getName(), field);
        return;
    }
    if (excelProperty != null && excelProperty.index() >= 0) {
        if (indexFieldMap.containsKey(excelProperty.index())) {
            throw new ExcelCommonException("The index of '" + indexFieldMap.get(excelProperty.index()).getName() + "' and '" + field.getName() + "' must be inconsistent");
        }
        indexFieldMap.put(excelProperty.index(), field);
        return;
    }
    int order = Integer.MAX_VALUE;
    if (excelProperty != null) {
        order = excelProperty.order();
    }
    List<Field> orderFieldList = orderFieldMap.computeIfAbsent(order, key -> ListUtils.newArrayList());
    orderFieldList.add(field);
}
Also used : Field(java.lang.reflect.Field) ExcelProperty(com.alibaba.excel.annotation.ExcelProperty) ExcelIgnore(com.alibaba.excel.annotation.ExcelIgnore) ExcelCommonException(com.alibaba.excel.exception.ExcelCommonException)

Aggregations

ExcelIgnore (com.alibaba.excel.annotation.ExcelIgnore)1 ExcelProperty (com.alibaba.excel.annotation.ExcelProperty)1 ExcelCommonException (com.alibaba.excel.exception.ExcelCommonException)1 Field (java.lang.reflect.Field)1