[jOOQ/jOOQ#10778] Add support for Packages, UDTs, and ArrayRecord in
KotlinGenerator
This commit is contained in:
parent
41e1949d27
commit
a4728bafe9
@ -351,6 +351,8 @@ public class DefaultGeneratorStrategy extends AbstractGeneratorStrategy {
|
||||
packageName = packageName + "." + className + ".references";
|
||||
else if (RoutineDefinition.class.isAssignableFrom(objectType))
|
||||
packageName = packageName + "." + className + ".references";
|
||||
else if (UDTDefinition.class.isAssignableFrom(objectType))
|
||||
packageName = packageName + "." + className + ".references";
|
||||
else
|
||||
packageName = packageName + "." + className;
|
||||
}
|
||||
|
||||
@ -796,6 +796,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -2821,7 +2825,16 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
|
||||
if (scala) {
|
||||
out.println("class %s extends %s[%s](\"%s\", null, %s, %s)[[before= with ][separator= with ][%s]] {", className, UDTImpl.class, recordType, udt.getOutputName(), packageId, synthetic, interfaces);
|
||||
out.println("class %s extends %s[%s](\"%s\", null, %s, %s)[[before= with ][separator= with ][%s]] {", className, UDTImpl.class, recordType, escapeString(udt.getOutputName()), packageId, synthetic, interfaces);
|
||||
}
|
||||
else if (kotlin) {
|
||||
out.println("public open class %s : %s<%s>(\"%s\", null, %s, %s)[[before=, ][%s]] {", className, UDTImpl.class, recordType, escapeString(udt.getOutputName()), packageId, synthetic, interfaces);
|
||||
|
||||
out.println();
|
||||
out.println("public companion object {");
|
||||
out.javadoc("The reference instance of <code>%s</code>", udt.getQualifiedOutputName());
|
||||
out.println("public val %s: %s = %s()", getStrategy().getJavaIdentifier(udt), className, className);
|
||||
out.println("}");
|
||||
}
|
||||
else {
|
||||
out.println("public class %s extends %s<%s>[[before= implements ][%s]] {", className, UDTImpl.class, recordType, interfaces);
|
||||
@ -2840,18 +2853,18 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
final List<String> converter = out.ref(list(attribute.getType(resolver(out)).getConverter()));
|
||||
final List<String> binding = out.ref(list(attribute.getType(resolver(out)).getBinding()));
|
||||
|
||||
if (scala) {
|
||||
printDeprecationIfUnknownType(out, attrTypeFull);
|
||||
out.println("private val %s: %s[%s, %s] = %s.createField(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")",
|
||||
attrId, UDTField.class, recordType, attrType, UDTImpl.class, DSL.class, attrName, attrTypeRef, escapeString(""), converter, binding);
|
||||
}
|
||||
else {
|
||||
if (!printDeprecationIfUnknownType(out, attrTypeFull))
|
||||
out.javadoc("The attribute <code>%s</code>.[[before= ][%s]]", attribute.getQualifiedOutputName(), list(escapeEntities(comment(attribute))));
|
||||
if (!printDeprecationIfUnknownType(out, attrTypeFull))
|
||||
out.javadoc("The attribute <code>%s</code>.[[before= ][%s]]", attribute.getQualifiedOutputName(), list(escapeEntities(comment(attribute))));
|
||||
|
||||
if (scala)
|
||||
out.println("private val %s: %s[%s, %s] = %s.createField(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")",
|
||||
attrId, UDTField.class, recordType, attrType, UDTImpl.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), converter, binding);
|
||||
else if (kotlin)
|
||||
out.println("public val %s: %s<%s, %s> = %s.createField(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ")",
|
||||
attrId, UDTField.class, recordType, attrType, UDTImpl.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), converter, binding);
|
||||
else
|
||||
out.println("public static final %s<%s, %s> %s = createField(%s.name(\"%s\"), %s, %s, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + ");",
|
||||
UDTField.class, recordType, attrType, attrId, DSL.class, attrName, attrTypeRef, udtId, escapeString(""), converter, binding);
|
||||
}
|
||||
UDTField.class, recordType, attrType, attrId, DSL.class, escapeString(attrName), attrTypeRef, udtId, escapeString(""), converter, binding);
|
||||
}
|
||||
|
||||
// [#799] Oracle UDT's can have member procedures
|
||||
@ -2878,7 +2891,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
if (scala) {
|
||||
if (scala || kotlin) {
|
||||
}
|
||||
else {
|
||||
out.javadoc(NO_FURTHER_INSTANCES_ALLOWED);
|
||||
@ -2891,6 +2904,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
out.println();
|
||||
out.println("override def getSchema: %s = %s", Schema.class, schemaId);
|
||||
}
|
||||
else if (kotlin) {
|
||||
out.println();
|
||||
out.println("public override fun getSchema(): %s = %s", Schema.class, schemaId);
|
||||
}
|
||||
else {
|
||||
out.overrideInherit();
|
||||
out.println("public %s getSchema() {", Schema.class);
|
||||
@ -3319,6 +3336,22 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -3748,6 +3781,16 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -6037,16 +6080,20 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private String escapeString(String comment) {
|
||||
private String escapeString(String string) {
|
||||
|
||||
if (comment == null)
|
||||
if (string == null)
|
||||
return null;
|
||||
|
||||
// [#3450] Escape also the escape sequence, among other things that break Java strings.
|
||||
String result = comment.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\"")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\r", "\\r");
|
||||
String result = string.replace("\\", "\\\\")
|
||||
.replace("\"", "\\\"")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\r", "\\r");
|
||||
|
||||
// [#10869] Prevent string interpolation in Kotlin
|
||||
if (kotlin)
|
||||
result = result.replace("$", "\\$");
|
||||
|
||||
// [#10007] [#10318] Very long strings cannot be handled by the javac compiler.
|
||||
int max = 16384;
|
||||
@ -7095,20 +7142,8 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
}
|
||||
|
||||
if (routine.getOverload() != null) {
|
||||
if (scala)
|
||||
out.println("setOverloaded(true)");
|
||||
else if (kotlin)
|
||||
out.println("overloaded = true");
|
||||
else
|
||||
out.println("setOverloaded(true);");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (routine.getOverload() != null)
|
||||
out.println("setOverloaded(true)%s", semicolon);
|
||||
|
||||
|
||||
|
||||
@ -7979,7 +8014,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
protected String refExtendsNumberType(JavaWriter out, DataTypeDefinition type) {
|
||||
if (type.isGenericNumberType())
|
||||
return (scala ? "_ <: " : "? extends ") + out.ref(Number.class);
|
||||
return (scala ? "_ <: " : kotlin ? "out ": "? extends ") + out.ref(Number.class);
|
||||
else
|
||||
return out.ref(getJavaType(type, out));
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user