private void createCRUDRepository(JavaClassSource entitySource, Project project) { // build interface declaration final String name = entitySource.getName(); final String idFieldType = entitySource.getFields().stream() .filter(field -> field.hasAnnotation(Id.class)) .findFirst() .orElseThrow(IllegalArgumentException::new) .getType() .getSimpleName(); final String repoInterfaceDeclaration = "public interface " + name + "Repository extends CrudRepository<" + name + "," + idFieldType + "> {}"; JavaInterfaceSource repoSource = Roaster.parse(JavaInterfaceSource.class, repoInterfaceDeclaration) .setPackage(entitySource.getPackage()); repoSource.addImport("org.springframework.data.repository.CrudRepository"); Roaster.format(repoSource.toString()); // Create Java Classes Greeting and GreetingProperties JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class); facet.saveJavaSource(repoSource); }
/** * Base template for a resource representation. * Covers the resource attributes * * @param index * @param plan * @return */ public JavaType create(ClassIndex index, ClassPlan plan) { // base class JavaInterfaceSource type = Roaster.parse( JavaInterfaceSource.class, "public interface " + plan.getClassName() + "Consumer<T extends " + plan.getClassName() + "<T>> {}" ); type.setPackage(plan.getPackageName()); type.addImport(plan.getPackageName() + "." + plan.getClassName()); type.addAnnotation(FunctionalInterface.class); addAccept(type, plan); addAndThen(type, plan); return type; }
/** * Base template for a resource representation. * Covers the resource attributes * * @param index * @param plan * @return */ public JavaType create(ClassIndex index, ClassPlan plan) { // base class JavaInterfaceSource type = Roaster.parse( JavaInterfaceSource.class, "public interface " + plan.getClassName() + "Consumer<T extends " + plan.getClassName() + "<T>> {}" ); type.setPackage(plan.getPackageName()); type.addImport(plan.getPackageName() + "." + plan.getClassName()); type.addAnnotation(FunctionalInterface.class); addAccept(type, plan); addAndThen(type, plan); return type; }