[jOOQ/jOOQ#14534] Add <generatedAnnotationJooqVersion/> option to the code generator

This commit is contained in:
Lukas Eder 2023-02-13 17:06:26 +01:00
parent f1233381bf
commit 38f2ccef8a
6 changed files with 79 additions and 5 deletions

View File

@ -75,7 +75,8 @@ abstract class AbstractGenerator implements Generator {
VisibilityModifier generateVisibilityModifier = VisibilityModifier.DEFAULT;
boolean generateGeneratedAnnotation = false;
GeneratedAnnotationType generatedGeneratedAnnotationType = GeneratedAnnotationType.DETECT_FROM_JDK;
boolean generateGeneratedAnnotationDate = true;
boolean generateGeneratedAnnotationDate = false;
boolean generateGeneratedAnnotationJooqVersion = true;
boolean generateNonnullAnnotation = false;
String generatedNonnullAnnotationType = "javax.annotation.Nonnull";
boolean generateNullableAnnotation = false;
@ -375,6 +376,16 @@ abstract class AbstractGenerator implements Generator {
this.generateGeneratedAnnotationDate = generateGeneratedAnnotationDate;
}
@Override
public boolean generateGeneratedAnnotationJooqVersion() {
return generateGeneratedAnnotationJooqVersion;
}
@Override
public void setGenerateGeneratedAnnotationJooqVersion(boolean generateGeneratedAnnotationJooqVersion) {
this.generateGeneratedAnnotationJooqVersion = generateGeneratedAnnotationJooqVersion;
}
@Override
public boolean generateNonnullAnnotation() {
return generateNonnullAnnotation;

View File

@ -749,6 +749,8 @@ public class GenerationTool {
generator.setGenerateGeneratedAnnotationType(g.getGenerate().getGeneratedAnnotationType());
if (g.getGenerate().isGeneratedAnnotationDate() != null)
generator.setGenerateGeneratedAnnotationDate(g.getGenerate().isGeneratedAnnotationDate());
if (g.getGenerate().isGeneratedAnnotationJooqVersion() != null)
generator.setGenerateGeneratedAnnotationJooqVersion(g.getGenerate().isGeneratedAnnotationJooqVersion());
if (g.getGenerate().isNonnullAnnotation() != null)
generator.setGenerateNonnullAnnotation(g.getGenerate().isNonnullAnnotation());
if (g.getGenerate().getNonnullAnnotationType() != null)

View File

@ -210,6 +210,18 @@ public interface Generator {
*/
void setGenerateGeneratedAnnotationDate(boolean generateGeneratedAnnotationDate);
/**
* Whether the {@link javax.annotation.processing.Generated} annotation
* should include the jOOQ version.
*/
boolean generateGeneratedAnnotationJooqVersion();
/**
* Whether the {@link javax.annotation.processing.Generated} annotation
* should include the jOOQ version.
*/
void setGenerateGeneratedAnnotationJooqVersion(boolean generateGeneratedAnnotationJooqVersion);
/**
* Whether Nonnull annotations should be generated.
* <p>

View File

@ -9194,9 +9194,10 @@ public class JavaGenerator extends AbstractGenerator {
else
out.println("value = {");
out.println("\"https://www.jooq.org\",");
out.println("\"jOOQ version:%s\"%s", Constants.VERSION, (hasCatalogVersion || hasSchemaVersion ? "," : ""));
out.println("\"https://www.jooq.org\"%s", (generateGeneratedAnnotationJooqVersion() || hasCatalogVersion || hasSchemaVersion ? "," : ""));
if (generateGeneratedAnnotationJooqVersion())
out.println("\"jOOQ version:%s\"%s", Constants.VERSION, (hasCatalogVersion || hasSchemaVersion ? "," : ""));
if (hasCatalogVersion)
out.println("\"catalog version:%s\"%s", escapeString(catalogVersions.get(catalog)), (hasSchemaVersion ? "," : ""));
if (hasSchemaVersion)
@ -9221,8 +9222,10 @@ public class JavaGenerator extends AbstractGenerator {
else
out.println("value = {");
out.println("\"https://www.jooq.org\",");
out.println("\"jOOQ version:%s\"", Constants.VERSION);
out.println("\"https://www.jooq.org\"%s", (generateGeneratedAnnotationJooqVersion() ? "," : ""));
if (generateGeneratedAnnotationJooqVersion())
out.println("\"jOOQ version:%s\"", Constants.VERSION);
if (scala)
out.println("),");

View File

@ -58,6 +58,8 @@ public class Generate implements Serializable, XMLAppendable
protected GeneratedAnnotationType generatedAnnotationType = GeneratedAnnotationType.DETECT_FROM_JDK;
@XmlElement(defaultValue = "false")
protected Boolean generatedAnnotationDate = false;
@XmlElement(defaultValue = "true")
protected Boolean generatedAnnotationJooqVersion = true;
@XmlElement(defaultValue = "false")
protected Boolean nonnullAnnotation = false;
@XmlElement(defaultValue = "javax.annotation.Nonnull")
@ -551,6 +553,30 @@ public class Generate implements Serializable, XMLAppendable
this.generatedAnnotationDate = value;
}
/**
* Whether the {@link javax.annotation.processing.Generated} annotation should include the jOOQ version.
*
* @return
* possible object is
* {@link Boolean }
*
*/
public Boolean isGeneratedAnnotationJooqVersion() {
return generatedAnnotationJooqVersion;
}
/**
* Sets the value of the generatedAnnotationJooqVersion property.
*
* @param value
* allowed object is
* {@link Boolean }
*
*/
public void setGeneratedAnnotationJooqVersion(Boolean value) {
this.generatedAnnotationJooqVersion = value;
}
/**
* Whether non-nullable items should be annotated with the annotation type specified in {@link #nonnullAnnotationType}. In SQL and by consequence in jOOQ, non-nullability cannot be guaranteed statically. There may still be some cases (e.g. after unions, outer joins, etc.) where a normally non-null value turns out to be null!
*
@ -2665,6 +2691,11 @@ public class Generate implements Serializable, XMLAppendable
return this;
}
public Generate withGeneratedAnnotationJooqVersion(Boolean value) {
setGeneratedAnnotationJooqVersion(value);
return this;
}
public Generate withNonnullAnnotation(Boolean value) {
setNonnullAnnotation(value);
return this;
@ -3159,6 +3190,7 @@ public class Generate implements Serializable, XMLAppendable
builder.append("generatedAnnotation", generatedAnnotation);
builder.append("generatedAnnotationType", generatedAnnotationType);
builder.append("generatedAnnotationDate", generatedAnnotationDate);
builder.append("generatedAnnotationJooqVersion", generatedAnnotationJooqVersion);
builder.append("nonnullAnnotation", nonnullAnnotation);
builder.append("nonnullAnnotationType", nonnullAnnotationType);
builder.append("nullableAnnotation", nullableAnnotation);
@ -3384,6 +3416,15 @@ public class Generate implements Serializable, XMLAppendable
return false;
}
}
if (generatedAnnotationJooqVersion == null) {
if (other.generatedAnnotationJooqVersion!= null) {
return false;
}
} else {
if (!generatedAnnotationJooqVersion.equals(other.generatedAnnotationJooqVersion)) {
return false;
}
}
if (nonnullAnnotation == null) {
if (other.nonnullAnnotation!= null) {
return false;
@ -4187,6 +4228,7 @@ public class Generate implements Serializable, XMLAppendable
result = ((prime*result)+((generatedAnnotation == null)? 0 :generatedAnnotation.hashCode()));
result = ((prime*result)+((generatedAnnotationType == null)? 0 :generatedAnnotationType.hashCode()));
result = ((prime*result)+((generatedAnnotationDate == null)? 0 :generatedAnnotationDate.hashCode()));
result = ((prime*result)+((generatedAnnotationJooqVersion == null)? 0 :generatedAnnotationJooqVersion.hashCode()));
result = ((prime*result)+((nonnullAnnotation == null)? 0 :nonnullAnnotation.hashCode()));
result = ((prime*result)+((nonnullAnnotationType == null)? 0 :nonnullAnnotationType.hashCode()));
result = ((prime*result)+((nullableAnnotation == null)? 0 :nullableAnnotation.hashCode()));

View File

@ -2010,6 +2010,10 @@ jOOQ version used for source code.]]></jxb:javadoc></jxb:property></appinfo></an
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether the {@link javax.annotation.processing.Generated} annotation should include the <code>date</code> attribute.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="generatedAnnotationJooqVersion" type="boolean" default="true" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether the {@link javax.annotation.processing.Generated} annotation should include the jOOQ version.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="nonnullAnnotation" type="boolean" default="false" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Whether non-nullable items should be annotated with the annotation type specified in {@link #nonnullAnnotationType}. In SQL and by consequence in jOOQ, non-nullability cannot be guaranteed statically. There may still be some cases (e.g. after unions, outer joins, etc.) where a normally non-null value turns out to be null!]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>