[jOOQ/jOOQ#10851] Add <visibilityModifier/> to allow for generating explicit / implicit public visibility, as well as internal in KotlinGenerator

This commit is contained in:
Lukas Eder 2020-11-12 16:39:59 +01:00
parent 3a4254518e
commit b5f80d0b0f
7 changed files with 547 additions and 355 deletions

View File

@ -50,6 +50,7 @@ import java.util.Set;
import org.jooq.meta.Database;
import org.jooq.meta.jaxb.GeneratedAnnotationType;
import org.jooq.meta.jaxb.GeneratedSerialVersionUID;
import org.jooq.meta.jaxb.VisibilityModifier;
import org.jooq.tools.JooqLogger;
@ -68,6 +69,7 @@ abstract class AbstractGenerator implements Generator {
boolean generateRelations = true;
boolean generateImplicitJoinPathsToOne = true;
boolean generateInstanceFields = true;
VisibilityModifier generateVisibilityModifier = VisibilityModifier.DEFAULT;
boolean generateGeneratedAnnotation = false;
GeneratedAnnotationType generatedGeneratedAnnotationType = GeneratedAnnotationType.DETECT_FROM_JDK;
boolean generateGeneratedAnnotationDate = true;
@ -294,6 +296,16 @@ abstract class AbstractGenerator implements Generator {
this.generateInstanceFields = generateInstanceFields;
}
@Override
public void setGenerateVisibilityModifier(VisibilityModifier generateVisibilityModifier) {
this.generateVisibilityModifier = generateVisibilityModifier;
}
@Override
public VisibilityModifier generateVisibilityModifier() {
return generateVisibilityModifier;
}
@Override
public boolean generateGeneratedAnnotation() {

View File

@ -684,6 +684,8 @@ public class GenerationTool {
generator.setGenerateDeprecationOnUnknownTypes(g.getGenerate().isDeprecationOnUnknownTypes());
if (g.getGenerate().isInstanceFields() != null)
generator.setGenerateInstanceFields(g.getGenerate().isInstanceFields());
if (g.getGenerate().getVisibilityModifier() != null)
generator.setGenerateVisibilityModifier(g.getGenerate().getVisibilityModifier());
if (g.getGenerate().isGeneratedAnnotation() != null)
generator.setGenerateGeneratedAnnotation(g.getGenerate().isGeneratedAnnotation());
if (g.getGenerate().getGeneratedAnnotationType() != null)

View File

@ -44,6 +44,7 @@ import java.util.Locale;
import org.jooq.meta.Database;
import org.jooq.meta.jaxb.GeneratedAnnotationType;
import org.jooq.meta.jaxb.GeneratedSerialVersionUID;
import org.jooq.meta.jaxb.VisibilityModifier;
/**
* The Generator provides a basic interface for java code generation
@ -147,6 +148,16 @@ public interface Generator {
*/
boolean generateGeneratedAnnotation();
/**
* The {@link VisibilityModifier} that should be used in generated code.
*/
void setGenerateVisibilityModifier(VisibilityModifier generateVisibilityModifier);
/**
* The {@link VisibilityModifier} that should be used in generated code.
*/
VisibilityModifier generateVisibilityModifier();
/**
* Whether the {@link javax.annotation.Generated} or
* {@link javax.annotation.processing.Generated} annotation should be

View File

@ -44,6 +44,9 @@ public class Generate implements Serializable, XMLAppendable
protected Boolean deprecationOnUnknownTypes = true;
@XmlElement(defaultValue = "true")
protected Boolean instanceFields = true;
@XmlElement(defaultValue = "DEFAULT")
@XmlSchemaType(name = "string")
protected VisibilityModifier visibilityModifier = VisibilityModifier.DEFAULT;
@XmlElement(defaultValue = "false")
protected Boolean generatedAnnotation = false;
@XmlElement(defaultValue = "DETECT_FROM_JDK")
@ -376,6 +379,22 @@ public class Generate implements Serializable, XMLAppendable
this.instanceFields = value;
}
/**
* The visibility modifier to be used with generated code.
*
*/
public VisibilityModifier getVisibilityModifier() {
return visibilityModifier;
}
/**
* The visibility modifier to be used with generated code.
*
*/
public void setVisibilityModifier(VisibilityModifier value) {
this.visibilityModifier = value;
}
/**
* Generate the {@link javax.annotation.Generated} or {@link javax.annotation.processing.Generated} annotation to indicate
* jOOQ version used for source code.
@ -2220,6 +2239,15 @@ public class Generate implements Serializable, XMLAppendable
return this;
}
/**
* The visibility modifier to be used with generated code.
*
*/
public Generate withVisibilityModifier(VisibilityModifier value) {
setVisibilityModifier(value);
return this;
}
public Generate withGeneratedAnnotation(Boolean value) {
setGeneratedAnnotation(value);
return this;
@ -2655,6 +2683,7 @@ public class Generate implements Serializable, XMLAppendable
builder.append("deprecated", deprecated);
builder.append("deprecationOnUnknownTypes", deprecationOnUnknownTypes);
builder.append("instanceFields", instanceFields);
builder.append("visibilityModifier", visibilityModifier);
builder.append("generatedAnnotation", generatedAnnotation);
builder.append("generatedAnnotationType", generatedAnnotationType);
builder.append("generatedAnnotationDate", generatedAnnotationDate);
@ -2816,6 +2845,15 @@ public class Generate implements Serializable, XMLAppendable
return false;
}
}
if (visibilityModifier == null) {
if (other.visibilityModifier!= null) {
return false;
}
} else {
if (!visibilityModifier.equals(other.visibilityModifier)) {
return false;
}
}
if (generatedAnnotation == null) {
if (other.generatedAnnotation!= null) {
return false;
@ -3523,6 +3561,7 @@ public class Generate implements Serializable, XMLAppendable
result = ((prime*result)+((deprecated == null)? 0 :deprecated.hashCode()));
result = ((prime*result)+((deprecationOnUnknownTypes == null)? 0 :deprecationOnUnknownTypes.hashCode()));
result = ((prime*result)+((instanceFields == null)? 0 :instanceFields.hashCode()));
result = ((prime*result)+((visibilityModifier == null)? 0 :visibilityModifier.hashCode()));
result = ((prime*result)+((generatedAnnotation == null)? 0 :generatedAnnotation.hashCode()));
result = ((prime*result)+((generatedAnnotationType == null)? 0 :generatedAnnotationType.hashCode()));
result = ((prime*result)+((generatedAnnotationDate == null)? 0 :generatedAnnotationDate.hashCode()));

View File

@ -0,0 +1,42 @@
package org.jooq.meta.jaxb;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for VisibilityModifier.
*
* <p>The following schema fragment specifies the expected content contained within this class.
* <p>
* <pre>
* &lt;simpleType name="VisibilityModifier"&gt;
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string"&gt;
* &lt;enumeration value="DEFAULT"/&gt;
* &lt;enumeration value="NONE"/&gt;
* &lt;enumeration value="PUBLIC"/&gt;
* &lt;enumeration value="INTERNAL"/&gt;
* &lt;/restriction&gt;
* &lt;/simpleType&gt;
* </pre>
*
*/
@XmlType(name = "VisibilityModifier")
@XmlEnum
public enum VisibilityModifier {
DEFAULT,
NONE,
PUBLIC,
INTERNAL;
public String value() {
return name();
}
public static VisibilityModifier fromValue(String v) {
return valueOf(v);
}
}

View File

@ -1425,6 +1425,10 @@ jOOQ API, without adding custom data type bindings to them.]]></jxb:javadoc></jx
</appinfo>
</annotation>
</element>
<element name="visibilityModifier" type="tns:VisibilityModifier" default="DEFAULT" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The visibility modifier to be used with generated code.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="generatedAnnotation" type="boolean" default="false" minOccurs="0" maxOccurs="1">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[Generate the {@link javax.annotation.Generated} or {@link javax.annotation.processing.Generated} annotation to indicate
@ -1848,6 +1852,15 @@ e.g. org.jooq.generated.schema1, org.jooq.generated.schema2]]></jxb:javadoc></jx
</restriction>
</simpleType>
<simpleType name="VisibilityModifier">
<restriction base="string">
<enumeration value="DEFAULT"/>
<enumeration value="NONE"/>
<enumeration value="PUBLIC"/>
<enumeration value="INTERNAL"/>
</restriction>
</simpleType>
<simpleType name="GeneratedAnnotationType">
<restriction base="string">
<enumeration value="DETECT_FROM_JDK"/>