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); }
@Override public boolean hasAnnotation(String type) { boolean hasAnnotation = false; FieldSource<O> field = getField(); if (field != null) { hasAnnotation = field.hasAnnotation(type); } if (!hasAnnotation) { MethodSource<O> accessor = getAccessor(); if (accessor != null) { hasAnnotation = accessor.hasAnnotation(type); } } if (!hasAnnotation) { MethodSource<O> mutator = getMutator(); if (mutator != null) { hasAnnotation = mutator.hasAnnotation(type); } } return hasAnnotation; } }
@Override public boolean hasAnnotation(Class<? extends java.lang.annotation.Annotation> type) { boolean hasAnnotation = false; FieldSource<O> field = getField(); if (field != null) { hasAnnotation = field.hasAnnotation(type); } if (!hasAnnotation) { MethodSource<O> accessor = getAccessor(); if (accessor != null) { hasAnnotation = accessor.hasAnnotation(type); } } if (!hasAnnotation) { MethodSource<O> mutator = getMutator(); if (mutator != null) { hasAnnotation = mutator.hasAnnotation(type); } } return hasAnnotation; }
@Override public boolean hasAnnotation(Class<? extends java.lang.annotation.Annotation> type) { boolean hasAnnotation = false; FieldSource<O> field = getField(); if (field != null) { hasAnnotation = field.hasAnnotation(type); } if (!hasAnnotation) { MethodSource<O> accessor = getAccessor(); if (accessor != null) { hasAnnotation = accessor.hasAnnotation(type); } } if (!hasAnnotation) { MethodSource<O> mutator = getMutator(); if (mutator != null) { hasAnnotation = mutator.hasAnnotation(type); } } return hasAnnotation; }
@Override public boolean hasAnnotation(String type) { boolean hasAnnotation = false; FieldSource<O> field = getField(); if (field != null) { hasAnnotation = field.hasAnnotation(type); } if (!hasAnnotation) { MethodSource<O> accessor = getAccessor(); if (accessor != null) { hasAnnotation = accessor.hasAnnotation(type); } } if (!hasAnnotation) { MethodSource<O> mutator = getMutator(); if (mutator != null) { hasAnnotation = mutator.hasAnnotation(type); } } return hasAnnotation; } }
for (FieldSource<JavaClassSource> field : entity.getFields()) if (field.hasAnnotation(OneToOne.class))