br.com.jarch.apt.generate.RepositoryCodeGenerate Maven / Gradle / Ivy
The newest version!
package br.com.jarch.apt.generate;
import br.com.jarch.apt.type.CodeType;
import br.com.jarch.apt.type.ModuleType;
import br.com.jarch.core.annotation.JArchGenerateCrud;
import javax.lang.model.element.Element;
import static br.com.jarch.apt.util.ProcessorUtils.addCode;
import static br.com.jarch.apt.util.ProcessorUtils.addLineBlank;
public class RepositoryCodeGenerate extends BaseCodeGenerate {
public static void generate(Element element, JArchGenerateCrud generateCrud) {
new RepositoryCodeGenerate(element, generateCrud).generate();
}
public static void generate(Element element, String useCase, String nameSubPackage) {
new RepositoryCodeGenerate(element, useCase, nameSubPackage).generate();
}
RepositoryCodeGenerate(Element element, String useCase, String nameSubPackage) {
super(element, useCase, nameSubPackage);
}
RepositoryCodeGenerate(Element element, JArchGenerateCrud generateCrud) {
super(element, generateCrud);
}
@Override
public ModuleType getModule() {
return ModuleType.CLIENT;
}
@Override
public CodeType getType() {
return CodeType.REPOSITORY;
}
@Override
public String getContent() {
StringBuilder code = new StringBuilder();
addPackage(code);
addImports(code);
addBody(code);
return code.toString();
}
private void addPackage(StringBuilder sbListCode) {
addCode(sbListCode, "package " + getNamePackage() + ";");
addLineBlank(sbListCode);
}
private void addImports(StringBuilder sbListCode) {
addCode(sbListCode, "import br.com.jarch.core.annotation.JArchRepository;");
addCode(sbListCode, "import br.com.jarch.core.crud.repository.CrudRepository;");
addCode(sbListCode, "import javax.enterprise.inject.spi.CDI;");
addLineBlank(sbListCode);
}
private void addBody(StringBuilder sbListCode) {
addCode(sbListCode, "@JArchRepository");
addCode(sbListCode, "public interface " + getName() + " extends CrudRepository<" + getNameEntity() + "> {");
addLineBlank(sbListCode);
addCode(sbListCode, "\tstatic " + getName() + " getInstance() {");
addCode(sbListCode, "\t\treturn CDI.current().select(" + getName() + ".class).get();");
addCode(sbListCode, "\t}");
addCode(sbListCode, "}");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy