我需要在jOOQ生成的每个类的顶部和底部放置一个// @formatter:on
和// @formatter:off
注释。我创建了一个JavaGenerator
类,如下所示:
package ch.acme.backend.server.metamodel
import org.jooq.codegen.JavaGenerator
import org.jooq.codegen.JavaWriter
import org.jooq.meta.ArrayDefinition
import org.jooq.meta.EnumDefinition
import org.jooq.meta.PackageDefinition
import org.jooq.meta.RoutineDefinition
import org.jooq.meta.SchemaDefinition
import org.jooq.meta.TableDefinition
import org.jooq.meta.UDTDefinition
class NoFormatJavaGenerator : JavaGenerator() {
override fun generateRecordClassJavadoc(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateArrayClassJavadoc(arrayDefinition: ArrayDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateDaoClassJavadoc(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateEnumClassJavadoc(enum: EnumDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateInterfaceClassJavadoc(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generatePackageClassJavadoc(pkg: PackageDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generatePojoClassJavadoc(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateRoutineClassJavadoc(routine: RoutineDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateSchemaClassJavadoc(schema: SchemaDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateTableClassJavadoc(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateUDTClassJavadoc(udt: UDTDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateUDTRecordClassJavadoc(udt: UDTDefinition, out: JavaWriter) {
out.println("// @formatter:off")
}
override fun generateRecordClassFooter(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateArrayClassFooter(arrayDefinition: ArrayDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateDaoClassFooter(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateEnumClassFooter(enum: EnumDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateInterfaceClassFooter(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generatePackageClassFooter(pkg: PackageDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generatePojoClassFooter(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateRoutineClassFooter(routine: RoutineDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateSchemaClassFooter(schema: SchemaDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateTableClassFooter(table: TableDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateUDTClassFooter(udt: UDTDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
override fun generateUDTRecordClassFooter(udt: UDTDefinition, out: JavaWriter) {
out.println("// @formatter:on")
}
}
这适用于大多数文件,但是“ DefaultCatalog”,“索引”,“键”,“公共”和“表”并未受到影响。我该如何添加呢?
答案 0 :(得分:3)
JavaGenerator
您可以扩展org.jooq.codegen.JavaGenerator.newJavaWriter(File)
方法,并使用自己的扩展名替换返回的实现,该扩展名会将这些注释添加到所有jOOQ生成的文件中并将其附加到所有文件中。
但是,我认为仅使用com.google.code.maven-replacer-plugin
之类的东西对所有生成的文件进行后处理会容易得多,因为您对文件的特定添加实际上并不需要了解Java代码。内部结构。您可以在每个生成的// @formatter:off
文件的开头添加// @formatter:on
,并在结尾添加*.java
。然后,这对于不是由jOOQ而是由其他工具生成的文件也将起作用。