Search in sources :

Example 6 with DqJavaAnnotationDesc

use of com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc in project dq-easy-cloud by dq-open-cloud.

the class DqGenerateJavaLogicImplBO method getAnnotations.

@Override
protected List<DqJavaAnnotationDesc> getAnnotations() {
    List<DqJavaAnnotationDesc> annotationDescs = new ArrayList<>();
    DqJavaAnnotationDesc serviceAnnotation = new DqJavaAnnotationDesc();
    serviceAnnotation.setName(Component.class.getSimpleName());
    serviceAnnotation.setSimpleClassType(Component.class.getSimpleName());
    serviceAnnotation.setFullClassType(Component.class.getName());
    List<DqJavaAnnotationParamDesc> serviceAnnotationParamDescs = new ArrayList<>();
    String value = DqStringUtils.uncapitalize(generateJavaBaseDTO.getClassBodyName() + DqClassNameEndWith.SERVICE_INF);
    serviceAnnotationParamDescs.add(new DqJavaAnnotationParamDesc("value", value));
    serviceAnnotation.setParams(serviceAnnotationParamDescs);
    annotationDescs.add(serviceAnnotation);
    return annotationDescs;
}
Also used : DqJavaAnnotationParamDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationParamDesc) DqJavaAnnotationDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc) ArrayList(java.util.ArrayList) Component(org.springframework.stereotype.Component)

Example 7 with DqJavaAnnotationDesc

use of com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc in project dq-easy-cloud by dq-open-cloud.

the class DqGenerateJavaServiceImplBO method getFields.

@Override
protected List<DqJavaFieldContentDesc> getFields() {
    List<DqJavaFieldContentDesc> fieldContentDescs = new ArrayList<>();
    DqJavaFieldContentDesc fieldContentDesc = new DqJavaFieldContentDesc();
    fieldContentDesc.setComment(javaClassContentDesc.getComment() + DqClassCommentEndWith.DAO_INF);
    // 设置属性注解
    List<DqJavaAnnotationDesc> annotationDescs = new ArrayList<>();
    DqJavaAnnotationDesc annotationDesc = new DqJavaAnnotationDesc();
    annotationDesc.setName(Autowired.class.getSimpleName());
    annotationDesc.setSimpleClassType(Autowired.class.getSimpleName());
    annotationDesc.setFullClassType(Autowired.class.getName());
    annotationDescs.add(annotationDesc);
    fieldContentDesc.setAnnotations(annotationDescs);
    // 设置属性的modifiers
    List<DqJavaModifierDesc> modifiers = new ArrayList<>();
    DqJavaModifierDesc modifierDesc = new DqJavaModifierDesc(DqModifierMappingEnum.PRIVATE);
    modifiers.add(modifierDesc);
    fieldContentDesc.setModifiers(modifiers);
    // 设置属性名称和类型
    String daoName = super.generateJavaBaseDTO.getClassBodyName() + DqClassNameEndWith.DAO_INF;
    fieldContentDesc.setName(daoName);
    fieldContentDesc.setSimpleClassType(daoName);
    fieldContentDesc.setPackageName(getFullPackageName(DqSubModuleDefaultPackageName.DAO_INF));
    fieldContentDesc.buildFullClassType();
    fieldContentDescs.add(fieldContentDesc);
    return fieldContentDescs;
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) DqJavaAnnotationDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc) DqJavaFieldContentDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaFieldContentDesc) ArrayList(java.util.ArrayList) DqJavaModifierDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaModifierDesc)

Example 8 with DqJavaAnnotationDesc

use of com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc in project dq-easy-cloud by dq-open-cloud.

the class DqGenerateJavaServiceImplBO method getAnnotations.

@Override
protected List<DqJavaAnnotationDesc> getAnnotations() {
    List<DqJavaAnnotationDesc> annotationDescs = new ArrayList<>();
    DqJavaAnnotationDesc serviceAnnotation = new DqJavaAnnotationDesc();
    serviceAnnotation.setName(Service.class.getSimpleName());
    serviceAnnotation.setSimpleClassType(Service.class.getSimpleName());
    serviceAnnotation.setFullClassType(Service.class.getName());
    List<DqJavaAnnotationParamDesc> serviceAnnotationParamDescs = new ArrayList<>();
    String value = DqStringUtils.uncapitalize(generateJavaBaseDTO.getClassBodyName() + DqClassNameEndWith.DAO_INF);
    serviceAnnotationParamDescs.add(new DqJavaAnnotationParamDesc("value", value));
    serviceAnnotation.setParams(serviceAnnotationParamDescs);
    annotationDescs.add(serviceAnnotation);
    return annotationDescs;
}
Also used : DqJavaAnnotationParamDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationParamDesc) DqJavaAnnotationDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc) ArrayList(java.util.ArrayList) DqBaseService(com.dq.easy.cloud.module.basic.service.DqBaseService) Service(org.springframework.stereotype.Service)

Example 9 with DqJavaAnnotationDesc

use of com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc in project dq-easy-cloud by dq-open-cloud.

the class GenerateJavaTest method testGenerateBO.

@Test
public void testGenerateBO() {
    DqFileDesc fileDesc = new DqFileDesc();
    fileDesc.setFileDirectoryFullPath(DqCodeProject.PROJECT_ROOT_BASE_PATH_DEFAULT + "//src//main//java//com//dq//easy//user//entity//");
    fileDesc.setFileName("UserDO");
    fileDesc.setFileSuffix("java");
    DqGenerateJavaClassRule generateRule = new DqGenerateJavaClassRule(true, true, true, true);
    DqJavaClassContentDesc javaClassContentDesc = new DqJavaClassContentDesc(generateRule);
    // 设置包名
    javaClassContentDesc.setPackageName("com.dq.easy.user.entity");
    // 设置导入的class名称
    // Set<String> importClassNames = new HashSet<>();
    // importClassNames.add(Service.class.getName());
    // importClassNames.add(DqBaseBO.class.getName());
    // importClassNames.add(Serializable.class.getName());
    // javaClassContentDesc.setImportClassNames(importClassNames);
    // 设置注释
    javaClassContentDesc.setComment("测试");
    // 设置类注解列表---begin
    List<DqJavaAnnotationDesc> annotations = new ArrayList<>();
    DqJavaAnnotationDesc annotationDesc1 = new DqJavaAnnotationDesc();
    annotationDesc1.setName("@Service");
    annotationDesc1.setSimpleClassType(Service.class.getSimpleName());
    annotationDesc1.setFullClassType(Service.class.getName());
    // 设置类注解
    List<DqJavaAnnotationParamDesc> annotationParamDescs = new ArrayList<>();
    DqJavaAnnotationParamDesc annotationParamDesc1 = new DqJavaAnnotationParamDesc();
    annotationParamDesc1.setName("value");
    annotationParamDesc1.setValue("userService");
    annotationParamDescs.add(annotationParamDesc1);
    annotationDesc1.setParams(annotationParamDescs);
    annotations.add(annotationDesc1);
    javaClassContentDesc.setAnnotations(annotations);
    // 设置类注解列表---end
    // 设置类的modifier列表---begin
    List<DqJavaModifierDesc> modifiers = new ArrayList<>();
    modifiers.add(new DqJavaModifierDesc(DqModifierMappingEnum.PUBLIC));
    modifiers.add(new DqJavaModifierDesc(DqModifierMappingEnum.CLASS));
    javaClassContentDesc.setModifiers(modifiers);
    // 设置类的modifier列表---end
    // 设置类名称
    javaClassContentDesc.setName("UserDO");
    javaClassContentDesc.setSimpleClassType("UserDO");
    // 设置继承父类---begin
    DqJavaClassContentDesc extendsParentClass = new DqJavaClassContentDesc();
    extendsParentClass.setName("DqBaseDO");
    extendsParentClass.setSimpleClassType(DqBaseBO.class.getSimpleName());
    extendsParentClass.setFullClassType(DqBaseBO.class.getName());
    javaClassContentDesc.setExtendsParentClass(extendsParentClass);
    // 设置继承父类---end
    // 设置实现的接口--begin
    List<DqJavaImplInterfaceContentDesc> implementsInterfaces = new ArrayList<>();
    DqJavaImplInterfaceContentDesc implementsClassName1 = new DqJavaImplInterfaceContentDesc();
    implementsClassName1.setName(Serializable.class.getSimpleName());
    implementsClassName1.setSimpleClassType(Serializable.class.getSimpleName());
    implementsClassName1.setFullClassType(Serializable.class.getName());
    implementsInterfaces.add(implementsClassName1);
    DqJavaImplInterfaceContentDesc implementsClassName3 = new DqJavaImplInterfaceContentDesc();
    implementsClassName3.setName(ImageInputStream.class.getSimpleName());
    implementsClassName3.setSimpleClassType(ImageInputStream.class.getSimpleName());
    implementsClassName3.setFullClassType(ImageInputStream.class.getName());
    implementsInterfaces.add(implementsClassName3);
    javaClassContentDesc.setImplementsInterfaces(implementsInterfaces);
    // 设置实现的接口---end
    // 设置类的属性--begin
    List<DqJavaFieldContentDesc> fields = new ArrayList<>();
    DqJavaFieldContentDesc field1 = new DqJavaFieldContentDesc();
    field1.setComment("用户名称");
    // 设置注解描述信息
    List<DqJavaAnnotationDesc> fieldAnnotationDescs = new ArrayList<>();
    // 设置注解描述信息1---begin
    DqJavaAnnotationDesc fieldAnnotationDesc1 = new DqJavaAnnotationDesc();
    fieldAnnotationDesc1.setName("@" + Column.class.getSimpleName());
    fieldAnnotationDesc1.setSimpleClassType(Column.class.getSimpleName());
    ;
    fieldAnnotationDesc1.setFullClassType(Column.class.getName());
    // 设置属性注解参数描述列表信息
    List<DqJavaAnnotationParamDesc> fieldAnnotationParamDescs = new ArrayList<>();
    DqJavaAnnotationParamDesc fieldAnnotationParamDesc1 = new DqJavaAnnotationParamDesc();
    fieldAnnotationParamDesc1.setName("name");
    fieldAnnotationParamDesc1.setValue("name");
    fieldAnnotationParamDescs.add(fieldAnnotationParamDesc1);
    DqJavaAnnotationParamDesc fieldAnnotationParamDesc2 = new DqJavaAnnotationParamDesc();
    fieldAnnotationParamDesc2.setName("columnDefinition");
    fieldAnnotationParamDesc2.setValue("VARCHAR");
    fieldAnnotationParamDescs.add(fieldAnnotationParamDesc2);
    fieldAnnotationDesc1.setParams(fieldAnnotationParamDescs);
    fieldAnnotationDescs.add(fieldAnnotationDesc1);
    // 设置属性注解描述1---end
    // 设置注解描述信息2---begin
    DqJavaAnnotationDesc fieldAnnotationDesc2 = new DqJavaAnnotationDesc();
    fieldAnnotationDesc2.setName("@" + JSONField.class.getSimpleName());
    fieldAnnotationDesc2.setSimpleClassType(JSONField.class.getSimpleName());
    ;
    fieldAnnotationDesc2.setFullClassType(JSONField.class.getName());
    // 设置属性注解参数描述列表信息
    List<DqJavaAnnotationParamDesc> fieldAnnotationParamDescs2 = new ArrayList<>();
    DqJavaAnnotationParamDesc fieldAnnotationParamDesc21 = new DqJavaAnnotationParamDesc();
    fieldAnnotationParamDesc21.setName("deserialize");
    fieldAnnotationParamDesc21.setValue(true);
    fieldAnnotationParamDescs2.add(fieldAnnotationParamDesc21);
    DqJavaAnnotationParamDesc fieldAnnotationParamDesc22 = new DqJavaAnnotationParamDesc();
    fieldAnnotationParamDesc22.setName("name");
    fieldAnnotationParamDesc22.setValue("name");
    fieldAnnotationParamDescs2.add(fieldAnnotationParamDesc22);
    fieldAnnotationDesc2.setParams(fieldAnnotationParamDescs2);
    fieldAnnotationDescs.add(fieldAnnotationDesc2);
    // 设置属性注解描述2---end
    field1.setAnnotations(fieldAnnotationDescs);
    List<DqJavaModifierDesc> fieldsModifiers = new ArrayList<>();
    fieldsModifiers.add(new DqJavaModifierDesc(DqModifierMappingEnum.PRIVATE));
    field1.setModifiers(fieldsModifiers);
    field1.setSimpleClassType(String.class.getSimpleName());
    field1.setName("name");
    field1.setFullClassType(String.class.getName());
    // 根据属性生成get方法---begin
    DqJavaMethodContentDesc methodContentDesc1 = new DqJavaMethodContentDesc();
    methodContentDesc1.setComment("获取名称");
    List<DqJavaModifierDesc> methodModifierDescs = new ArrayList<>();
    methodModifierDescs.add(new DqJavaModifierDesc(DqModifierMappingEnum.PUBLIC));
    methodContentDesc1.setModifiers(methodModifierDescs);
    methodContentDesc1.setSimpleClassType(field1.getSimpleClassType());
    methodContentDesc1.setFullClassType(field1.getFullClassType());
    methodContentDesc1.setName("name");
    methodContentDesc1.setType(1);
    methodContentDesc1.setReturnSimpleClassType(field1.getSimpleClassType());
    methodContentDesc1.setReturnFullClassType(field1.getFullClassType());
    // 根据属性生成get方法---end
    // 根据属性生成set方法---begin
    DqJavaMethodContentDesc methodContentDesc2 = new DqJavaMethodContentDesc();
    methodContentDesc2.setComment("获取名称");
    List<DqJavaModifierDesc> methodModifierDescs2 = new ArrayList<>();
    methodModifierDescs2.add(new DqJavaModifierDesc(DqModifierMappingEnum.PUBLIC));
    methodContentDesc2.setModifiers(methodModifierDescs2);
    methodContentDesc2.setSimpleClassType(field1.getSimpleClassType());
    methodContentDesc2.setFullClassType(field1.getFullClassType());
    methodContentDesc2.setName("name");
    methodContentDesc2.setType(2);
    methodContentDesc2.setReturnSimpleClassType(void.class.getSimpleName());
    methodContentDesc2.setReturnFullClassType(void.class.getName());
    // 根据属性生成set方法---end
    // 根据属性生成build方法---begin
    DqJavaMethodContentDesc methodContentDesc3 = new DqJavaMethodContentDesc();
    methodContentDesc3.setComment("构建名称");
    List<DqJavaModifierDesc> methodModifierDescs31 = new ArrayList<>();
    methodModifierDescs31.add(new DqJavaModifierDesc(DqModifierMappingEnum.PUBLIC));
    methodContentDesc3.setModifiers(methodModifierDescs31);
    methodContentDesc3.setSimpleClassType(field1.getSimpleClassType());
    methodContentDesc3.setFullClassType(field1.getFullClassType());
    methodContentDesc3.setName("name");
    methodContentDesc3.setType(3);
    methodContentDesc3.setReturnSimpleClassType(javaClassContentDesc.getSimpleClassType());
    methodContentDesc3.setReturnFullClassType(javaClassContentDesc.getFullClassType());
    // 根据属性生成build方法---end
    fields.add(field1);
    javaClassContentDesc.setFields(fields);
    // 设置属性---end
    // 设置方法---begin
    List<DqJavaMethodContentDesc> javaMethodContentDescs = new ArrayList<>();
    javaMethodContentDescs.add(methodContentDesc1);
    javaMethodContentDescs.add(methodContentDesc2);
    javaMethodContentDescs.add(methodContentDesc3);
    javaClassContentDesc.setMethods(javaMethodContentDescs);
    // 设置方法---end
    DqTemplateDesc templateDesc = new DqTemplateDesc(DqCodeGenerateConfig.CODE_TEMPLATE_BASE_PACKAGE_PATH, "test.ftl");
    // 生成文件
    try {
        javaClassContentDesc.addImportFullClassType();
        new DqGenerateBO(fileDesc, javaClassContentDesc, templateDesc).generateCode();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Serializable(java.io.Serializable) DqJavaMethodContentDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaMethodContentDesc) DqFileDesc(com.dq.easy.cloud.module.common.file.pojo.desc.DqFileDesc) ArrayList(java.util.ArrayList) JSONField(com.alibaba.fastjson.annotation.JSONField) DqJavaAnnotationDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc) Column(javax.persistence.Column) DqGenerateBO(com.dq.easy.cloud.module.common.generator.code.base.pojo.bo.DqGenerateBO) DqJavaFieldContentDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaFieldContentDesc) ImageInputStream(javax.imageio.stream.ImageInputStream) Service(org.springframework.stereotype.Service) DqGenerateJavaClassRule(com.dq.easy.cloud.module.common.generator.code.java.rule.DqGenerateJavaClassRule) DqJavaImplInterfaceContentDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaImplInterfaceContentDesc) DqTemplateDesc(com.dq.easy.cloud.module.common.generator.code.base.pojo.desc.DqTemplateDesc) DqJavaAnnotationParamDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationParamDesc) DqBaseBO(com.dq.easy.cloud.module.basic.pojo.bo.DqBaseBO) DqJavaClassContentDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaClassContentDesc) DqJavaModifierDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaModifierDesc) Test(org.junit.Test)

Example 10 with DqJavaAnnotationDesc

use of com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc in project dq-easy-cloud by dq-open-cloud.

the class DqJavaClassContentDesc method addImportMethodsFullClassType.

/**
 * 增加导入方法列表的完整类类型
 */
private void addImportMethodsFullClassType() {
    DqGenerateJavaClassRule javaClassRule = (DqGenerateJavaClassRule) getGenerateRule();
    boolean returnCondition = DqCollectionsUtils.isEmpty(methods) || DqBaseUtils.isNull(javaClassRule);
    if (returnCondition) {
        return;
    }
    for (DqJavaMethodContentDesc method : methods) {
        // 需要跳出当前循环的条件
        boolean getContinue = DqMethodTypeEnum.isGet(method.getType()) && !javaClassRule.isGenerateGetMethod();
        boolean setContinue = DqMethodTypeEnum.isSet(method.getType()) && !javaClassRule.isGenerateSetMethod();
        boolean buildContinue = DqMethodTypeEnum.isBuild(method.getType()) && !javaClassRule.isGenerateBuildMethod();
        if (getContinue || setContinue || buildContinue) {
            continue;
        }
        doAddImportFullClassTypes(method.getReturnFullClassType());
        if (DqCollectionsUtils.isEmpty(method.getAnnotations())) {
            continue;
        }
        for (DqJavaAnnotationDesc methodAnnotationDesc : method.getAnnotations()) {
            doAddImportFullClassTypes(methodAnnotationDesc.getFullClassType());
        }
    }
}
Also used : DqJavaAnnotationDesc(com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc) DqGenerateJavaClassRule(com.dq.easy.cloud.module.common.generator.code.java.rule.DqGenerateJavaClassRule)

Aggregations

DqJavaAnnotationDesc (com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationDesc)12 ArrayList (java.util.ArrayList)10 DqJavaAnnotationParamDesc (com.dq.easy.cloud.module.common.generator.code.java.desc.anno.DqJavaAnnotationParamDesc)7 DqJavaFieldContentDesc (com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaFieldContentDesc)3 DqJavaModifierDesc (com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaModifierDesc)3 DqGenerateJavaClassRule (com.dq.easy.cloud.module.common.generator.code.java.rule.DqGenerateJavaClassRule)3 Column (javax.persistence.Column)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Service (org.springframework.stereotype.Service)2 JSONField (com.alibaba.fastjson.annotation.JSONField)1 DqBaseController (com.dq.easy.cloud.module.basic.controller.DqBaseController)1 DqBaseBO (com.dq.easy.cloud.module.basic.pojo.bo.DqBaseBO)1 DqBaseEntity (com.dq.easy.cloud.module.basic.pojo.entity.DqBaseEntity)1 DqBaseRepository (com.dq.easy.cloud.module.basic.repository.DqBaseRepository)1 DqBaseService (com.dq.easy.cloud.module.basic.service.DqBaseService)1 DqFileDesc (com.dq.easy.cloud.module.common.file.pojo.desc.DqFileDesc)1 DqGenerateBO (com.dq.easy.cloud.module.common.generator.code.base.pojo.bo.DqGenerateBO)1 DqTemplateDesc (com.dq.easy.cloud.module.common.generator.code.base.pojo.desc.DqTemplateDesc)1 DqJavaClassContentDesc (com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaClassContentDesc)1 DqJavaImplInterfaceContentDesc (com.dq.easy.cloud.module.common.generator.code.java.desc.DqJavaImplInterfaceContentDesc)1