Добавил поле CLASS_NAME в SimpleMode

This commit is contained in:
Struchkov Mark 2023-01-24 13:18:56 +03:00
parent f83a3b235f
commit 8e79e74c0b
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
3 changed files with 17 additions and 18 deletions

View File

@ -1,8 +1,7 @@
package dev.struchkov.haiti.utils.fieldconstants.creator; package dev.struchkov.haiti.utils.fieldconstants.creator;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.SimpleFieldDto;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.table.SimpleTableFieldDto;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.ClassSimpleDto; import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.ClassSimpleDto;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.SimpleFieldDto;
import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.ProcessingEnvironment;
import javax.tools.JavaFileObject; import javax.tools.JavaFileObject;
@ -27,7 +26,7 @@ public final class CreatorClassSimpleMode {
public static void record(ClassSimpleDto classDto, ProcessingEnvironment environment) { public static void record(ClassSimpleDto classDto, ProcessingEnvironment environment) {
JavaFileObject builderFile = null; JavaFileObject builderFile = null;
try { try {
builderFile = environment.getFiler().createSourceFile(classDto.getClassName()); builderFile = environment.getFiler().createSourceFile(classDto.getNewClassName());
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -36,8 +35,9 @@ public final class CreatorClassSimpleMode {
out.println("package " + classDto.getClassPackage() + ";"); out.println("package " + classDto.getClassPackage() + ";");
out.println(); out.println();
out.println(); out.println();
out.print(format("public class {0} '{'", classDto.getClassName())); out.println(format("public class {0} '{'", classDto.getNewClassName()));
out.println(); out.println();
out.println(format(" public static final String CLASS_NAME = \"{0}\";", classDto.getOldClassName()));
out.println(); out.println();
generateSimpleNames(classDto.getSimpleFields(), out); generateSimpleNames(classDto.getSimpleFields(), out);
out.println("}"); out.println("}");

View File

@ -5,8 +5,8 @@ import java.util.List;
public class ClassSimpleDto { public class ClassSimpleDto {
private String classPackage; private String classPackage;
private String className; private String newClassName;
private String tableName; private String oldClassName;
private List<SimpleFieldDto> simpleFields; private List<SimpleFieldDto> simpleFields;
public String getClassPackage() { public String getClassPackage() {
@ -17,20 +17,20 @@ public class ClassSimpleDto {
this.classPackage = classPackage; this.classPackage = classPackage;
} }
public String getClassName() { public String getNewClassName() {
return className; return newClassName;
} }
public void setClassName(String className) { public void setNewClassName(String newClassName) {
this.className = className; this.newClassName = newClassName;
} }
public String getTableName() { public String getOldClassName() {
return tableName; return oldClassName;
} }
public void setTableName(String tableName) { public void setOldClassName(String oldClassName) {
this.tableName = tableName; this.oldClassName = oldClassName;
} }
public List<SimpleFieldDto> getSimpleFields() { public List<SimpleFieldDto> getSimpleFields() {

View File

@ -14,9 +14,7 @@ import java.util.List;
public class GeneratorSimpleMode { public class GeneratorSimpleMode {
public static void generate(ProcessingEnvironment processingEnv, Element annotatedElement) { public static void generate(ProcessingEnvironment processingEnv, Element annotatedElement) {
final String annotatedElementName = annotatedElement.getSimpleName().toString(); final String oldClassName = annotatedElement.getSimpleName().toString();
final String newClassName = annotatedElementName + Mode.SIMPLE.getDefaultPostfix();
final List<? extends Element> allFields = annotatedElement.getEnclosedElements().stream() final List<? extends Element> allFields = annotatedElement.getEnclosedElements().stream()
.filter(Generator::isField) .filter(Generator::isField)
@ -26,7 +24,8 @@ public class GeneratorSimpleMode {
final List<SimpleFieldDto> simpleFields = getSimpleFields(allFields); final List<SimpleFieldDto> simpleFields = getSimpleFields(allFields);
final ClassSimpleDto newClass = new ClassSimpleDto(); final ClassSimpleDto newClass = new ClassSimpleDto();
newClass.setClassName(newClassName); newClass.setNewClassName(oldClassName + Mode.SIMPLE.getDefaultPostfix());
newClass.setOldClassName(oldClassName);
newClass.setSimpleFields(simpleFields); newClass.setSimpleFields(simpleFields);
newClass.setClassPackage(Generator.getPackage(annotatedElement)); newClass.setClassPackage(Generator.getPackage(annotatedElement));