All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.struchkov.haiti.utils.fieldconstants.generator.GeneratorSimpleMode Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package dev.struchkov.haiti.utils.fieldconstants.generator;

import dev.struchkov.haiti.utils.fieldconstants.creator.CreatorClassSimpleMode;
import dev.struchkov.haiti.utils.fieldconstants.domain.Mode;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.ClassSimpleDto;
import dev.struchkov.haiti.utils.fieldconstants.domain.mode.simple.SimpleFieldDto;
import dev.struchkov.haiti.utils.fieldconstants.util.Generator;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;
import java.util.ArrayList;
import java.util.List;

import static dev.struchkov.haiti.utils.fieldconstants.util.Generator.getPackage;

public class GeneratorSimpleMode {

    public static void generate(ProcessingEnvironment processingEnv, Element annotatedElement) {
        final String oldClassName = annotatedElement.getSimpleName().toString();

        final List allFields = annotatedElement.getEnclosedElements().stream()
                .filter(Generator::isField)
                .filter(Generator::isNotIgnoreField)
                .toList();

        final List simpleFields = getSimpleFields(allFields);

        final ClassSimpleDto newClass = new ClassSimpleDto();
        newClass.setNewClassName(oldClassName + Mode.SIMPLE.getDefaultPostfix());
        newClass.setOldClassName(oldClassName);
        newClass.setSimpleFields(simpleFields);
        newClass.setClassPackage(getPackage(annotatedElement));

        CreatorClassSimpleMode.record(newClass, processingEnv);
    }

    private static List getSimpleFields(List allFields) {
        final List resultList = new ArrayList<>();
        for (Element field : allFields) {
            final String fieldName = field.getSimpleName().toString();
            resultList.add(SimpleFieldDto.of(fieldName));
        }
        return resultList;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy