Search in sources :

Example 1 with FormField

use of com.qlangtech.tis.plugin.annotation.FormField in project plugins by qlangtech.

the class ContextDesc method descBuild.

public static void descBuild(Class<?> clazz, boolean reader) {
    Field[] declaredFields = clazz.getDeclaredFields();
    FormField ff = null;
    // Validator[] validate = null;
    StringBuffer buffer = new StringBuffer();
    StringBuffer template = new StringBuffer();
    StringBuffer optionProp = new StringBuffer();
    boolean propRequire;
    for (Field f : declaredFields) {
        ff = f.getAnnotation(FormField.class);
        if (ff == null) {
            continue;
        }
        propRequire = propRequire(ff);
        // validate = ff.validate();
        if (!propRequire) {
            buffer.append("public boolean isContain").append(StringUtils.capitalize(f.getName())).append("(){ \n");
            if (f.getType() == String.class) {
                buffer.append("\t return StringUtils.isNotBlank(this.").append(getRefName(reader)).append(".").append(f.getName()).append(");\n");
            } else {
                buffer.append("\t return this.").append(getRefName(reader)).append(".").append(f.getName()).append("!= null;\n");
            }
            buffer.append("}\n");
            optionProp.append(f.getName()).append("\n");
        }
        buffer.append(" public ").append(f.getType().getSimpleName()).append(" get").append(StringUtils.capitalize(f.getName())).append("() { \n");
        buffer.append("    return this.").append(getRefName(reader)).append(".").append(f.getName()).append(";\n");
        buffer.append(" }\n");
        if (propRequire) {
            appendPropTpl(reader, template, f);
        } else {
            template.append("#if($").append(getRefName(reader)).append(".contain").append(StringUtils.capitalize(f.getName())).append(")\n");
            template.append("\t\t");
            appendPropTpl(reader, template, f);
            template.append("#end\n");
        }
    }
    // PropertyUtilsBean propertyUtils = BeanUtilsBean.getInstance().getPropertyUtils();
    // PropertyDescriptor[] propertyDescriptors = propertyUtils.getPropertyDescriptors(clazz);
    // for (PropertyDescriptor desc : propertyDescriptors) {
    // System.out.println(desc.getName() + ":" + desc.getPropertyType());
    // buffer.append("public boolean isContain").append(StringUtils.capitalize(desc.getName()))
    // .append("(){ \n");
    // if (desc.getPropertyType() == String.class) {
    // buffer.append("\t return StringUtils.isNotBlank(this.writer.").append(desc.getName()).append(");\n");
    // } else {
    // buffer.append("\t return this.writer.").append(desc.getName()).append("!= null;\n");
    // }
    // buffer.append("}\n");
    // }
    System.out.println(buffer.toString());
    System.out.println("===========================================");
    System.out.println(template.toString());
    System.out.println("option props===========================================");
    System.out.println(optionProp.toString());
}
Also used : FormField(com.qlangtech.tis.plugin.annotation.FormField) Field(java.lang.reflect.Field) FormField(com.qlangtech.tis.plugin.annotation.FormField)

Aggregations

FormField (com.qlangtech.tis.plugin.annotation.FormField)1 Field (java.lang.reflect.Field)1