[jOOQ/jOOQ#228] Added ScalaGenerator support
This includes: - Refactor Internal methods, remove unnecessary type variables
This commit is contained in:
parent
41faba4241
commit
896d995476
@ -310,8 +310,8 @@ abstract class AbstractGenerator implements Generator {
|
||||
@Override
|
||||
public boolean generateUDTPaths() {
|
||||
|
||||
// [#228] TODO: Support this also in Scala and Kotlin
|
||||
return generateUDTPaths && language == Language.JAVA;
|
||||
// [#228] TODO: Support this also in Kotlin
|
||||
return generateUDTPaths && language != Language.KOTLIN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -3383,9 +3383,27 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
generateUDTPathClassJavadoc(udt, out);
|
||||
printClassAnnotations(out, udt, Mode.PATH);
|
||||
|
||||
out.println("%sclass %s<R extends %s, T> extends %s<R, %s, T>[[before= implements ][%s]] {",
|
||||
visibility(), className, Record.class, classExtends, recordType, interfaces);
|
||||
out.printSerial();
|
||||
if (scala) {
|
||||
out.println("%sclass %s[R <: %s, T](", visibility(), className, Record.class);
|
||||
out.println("name: %s,", Name.class);
|
||||
out.println("klass: %s[T],", DataType.class);
|
||||
out.println("qualifier: %s[R],", RecordQualifier.class);
|
||||
out.println("comment: %s,", Comment.class);
|
||||
out.println("binding: %s[_, T]", Binding.class);
|
||||
out.println(")");
|
||||
out.println("extends %s[R, %s, T](", classExtends, recordType);
|
||||
out.println("name, klass, qualifier, %s, comment, binding", udtId);
|
||||
if (interfaces.isEmpty())
|
||||
out.println(") {");
|
||||
else
|
||||
out.println(")")
|
||||
.println("[[before= with ][separator= with ][%s]] {", interfaces);
|
||||
}
|
||||
else {
|
||||
out.println("%sclass %s<R extends %s, T> extends %s<R, %s, T>[[before= implements ][%s]] {",
|
||||
visibility(), className, Record.class, classExtends, recordType, interfaces);
|
||||
out.printSerial();
|
||||
}
|
||||
|
||||
for (AttributeDefinition attribute : udt.getAttributes()) {
|
||||
final String attrTypeFull = getJavaType(attribute.getType(resolver(out)), out);
|
||||
@ -3395,31 +3413,45 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
final String attrName = attribute.getName();
|
||||
final List<String> converter = out.ref(list(attribute.getType(resolver(out)).getConverter()));
|
||||
final List<String> binding = out.ref(list(attribute.getType(resolver(out)).getBinding()));
|
||||
final boolean udtPath = attribute.getType().isUDT() && !attribute.getDatabase().isArrayType(attribute.getType().getType());
|
||||
|
||||
|
||||
if (!printDeprecationIfUnknownType(out, attrTypeFull))
|
||||
out.javadoc("The attribute <code>%s</code>.[[before= ][%s]]", attribute.getQualifiedOutputName(), list(escapeEntities(comment(attribute))));
|
||||
|
||||
if (attribute.getType().isUDT() && !attribute.getDatabase().isArrayType(attrTypeFull)) {
|
||||
if (udtPath) {
|
||||
final SchemaDefinition attrUdtSchema = attribute.getDatabase().getSchema(attribute.getType().getQualifiedUserType().qualifier().last());
|
||||
final UDTDefinition attrUdt = attribute.getDatabase().getUDT(attrUdtSchema, attribute.getType().getUserType());
|
||||
final String attrPathType = out.ref(getStrategy().getFullJavaClassName(attrUdt, Mode.PATH));
|
||||
|
||||
out.println("%sfinal %s<%s, %s> %s = %s.createUDTPathField(%s.name(\"%s\"), %s, this, \"%s\", %s.class" + converterTemplate(converter) + converterTemplate(binding) + ");",
|
||||
visibility(), attrPathType, recordType, attrType, attrId, Internal.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), attrPathType, converter, binding);
|
||||
if (scala)
|
||||
out.println("%sval %s: %s[%s, %s] = %s.createUDTPathField[ %s, %s[%s, %s] ](%s.name(\"%s\"), %s, this, \"%s\", classOf[ %s[%s, %s] ]" + converterTemplate(converter) + converterTemplate(binding) + ")",
|
||||
visibility(), scalaWhitespaceSuffix(attrId), attrPathType, recordType, attrType, Internal.class, attrType, attrPathType, recordType, attrType, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), attrPathType, recordType, attrType, converter, binding);
|
||||
else
|
||||
out.println("%sfinal %s<%s, %s> %s = %s.createUDTPathField(%s.name(\"%s\"), %s, this, \"%s\", %s.class" + converterTemplate(converter) + converterTemplate(binding) + ");",
|
||||
visibility(), attrPathType, recordType, attrType, attrId, Internal.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), attrPathType, converter, binding);
|
||||
}
|
||||
else {
|
||||
final String attrPathType = out.ref(UDTField.class);
|
||||
|
||||
out.println("%sfinal %s<%s, %s> %s = %s.createUDTPathField(%s.name(\"%s\"), %s, this, \"%s\", %s.class" + converterTemplate(converter) + converterTemplate(binding) + ");",
|
||||
visibility(), attrPathType, recordType, attrType, attrId, Internal.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), attrPathType, converter, binding);
|
||||
if (scala)
|
||||
out.println("%sval %s: %s[%s, %s] = %s.createUDTPathField(%s.name(\"%s\"), %s, this, \"%s\", classOf[ %s[%s, %s] ]" + converterTemplate(converter) + converterTemplate(binding) + ")",
|
||||
visibility(), scalaWhitespaceSuffix(attrId), attrPathType, recordType, attrType, Internal.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), attrPathType, recordType, attrType, converter, binding);
|
||||
else
|
||||
out.println("%sfinal %s<%s, %s> %s = %s.createUDTPathField(%s.name(\"%s\"), %s, this, \"%s\", %s.class" + converterTemplate(converter) + converterTemplate(binding) + ");",
|
||||
visibility(), attrPathType, recordType, attrType, attrId, Internal.class, DSL.class, escapeString(attrName), attrTypeRef, escapeString(""), attrPathType, converter, binding);
|
||||
}
|
||||
}
|
||||
|
||||
out.println();
|
||||
out.println("%s%s(%s name, %s<T> type, %s<R> qualifier, %s comment, %s<?, T> binding) {",
|
||||
visibility(), className, Name.class, DataType.class, RecordQualifier.class, Comment.class, Binding.class);
|
||||
out.println("super(name, type, qualifier, %s, comment, binding);", udtId);
|
||||
out.println("}");
|
||||
|
||||
if (scala) {}
|
||||
else {
|
||||
out.println("%s%s(%s name, %s<T> type, %s<R> qualifier, %s comment, %s<?, T> binding) {",
|
||||
visibility(), className, Name.class, DataType.class, RecordQualifier.class, Comment.class, Binding.class);
|
||||
out.println("super(name, type, qualifier, %s, comment, binding);", udtId);
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
generateUDTPathClassFooter(udt, out);
|
||||
out.println("}");
|
||||
@ -6373,6 +6405,9 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
|
||||
|
||||
final String columnVisibility;
|
||||
final boolean udtPath = generateUDTPaths()
|
||||
&& column.getType().isUDT()
|
||||
&& !column.getDatabase().isArrayType(column.getType().getType());
|
||||
|
||||
|
||||
|
||||
@ -6390,30 +6425,36 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
out.javadoc("The column <code>%s</code>.[[before= ][%s]]", column.getQualifiedOutputName(), list(escapeEntities(comment(column))));
|
||||
|
||||
if (scala) {
|
||||
if (udtPath) {
|
||||
final SchemaDefinition columnUdtSchema = column.getDatabase().getSchema(column.getType().getQualifiedUserType().qualifier().last());
|
||||
final UDTDefinition columnUdt = column.getDatabase().getUDT(columnUdtSchema, column.getType().getUserType());
|
||||
final String columnPathType = out.ref(getStrategy().getFullJavaClassName(columnUdt, Mode.PATH));
|
||||
|
||||
out.println("%sval %s: %s[%s, %s] = %s.createUDTPathTableField[ %s, %s, %s[%s, %s] ](%s.name(\"%s\"), %s, this, \"%s\", classOf[ %s[%s, %s] ]" + converterTemplate(converter) + converterTemplate(binding) + ")",
|
||||
columnVisibility, scalaWhitespaceSuffix(columnId), columnPathType, recordType, columnType, Internal.class, recordType, columnType, columnPathType, recordType, columnType, DSL.class, escapeString(columnName), columnTypeRef, escapeString(comment(column)), columnPathType, recordType, columnType, converter, binding);
|
||||
}
|
||||
|
||||
// [#9879] In scala, subclasses cannot call a superclass protected static method
|
||||
// only a superclass protected instance method. But to capture the Generator<?, TR, ?>
|
||||
// type variable, we need to pass it explicitly. The relevant createField0() method
|
||||
// can't be overloaded, so it has that "0" suffix...
|
||||
if (generator.isEmpty())
|
||||
// [#15505] TODO: Use Internal API instead
|
||||
else if (generator.isEmpty())
|
||||
out.println("%sval %s: %s[%s, %s] = createField(%s.name(\"%s\"), %s, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + converterTemplate(generator) + ")",
|
||||
columnVisibility, scalaWhitespaceSuffix(columnId), TableField.class, recordType, columnType, DSL.class, columnName, columnTypeRef, escapeString(comment(column)), converter, binding, generator);
|
||||
columnVisibility, scalaWhitespaceSuffix(columnId), TableField.class, recordType, columnType, DSL.class, escapeString(columnName), columnTypeRef, escapeString(comment(column)), converter, binding, generator);
|
||||
else
|
||||
out.println("%sval %s: %s[%s, %s] = createField0(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + converterTemplate(generator) + ")",
|
||||
columnVisibility, scalaWhitespaceSuffix(columnId), TableField.class, recordType, columnType, DSL.class, columnName, columnTypeRef, escapeString(comment(column)), converter, binding, generator);
|
||||
columnVisibility, scalaWhitespaceSuffix(columnId), TableField.class, recordType, columnType, DSL.class, escapeString(columnName), columnTypeRef, escapeString(comment(column)), converter, binding, generator);
|
||||
}
|
||||
else if (kotlin) {
|
||||
out.println("%sval %s: %s<%s, %s?> = createField(%s.name(\"%s\"), %s, this, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + converterTemplate(generator) + ")",
|
||||
columnVisibility, columnId, TableField.class, recordType, columnType, DSL.class, columnName, columnTypeRef, escapeString(comment(column)), converter, binding, generator);
|
||||
columnVisibility, columnId, TableField.class, recordType, columnType, DSL.class, escapeString(columnName), columnTypeRef, escapeString(comment(column)), converter, binding, generator);
|
||||
}
|
||||
else {
|
||||
String isStatic = generateInstanceFields() ? "" : "static ";
|
||||
String tableRef = generateInstanceFields() ? "this" : out.ref(getStrategy().getJavaIdentifier(table), 2);
|
||||
|
||||
if (generateInstanceFields()
|
||||
&& generateUDTPaths()
|
||||
&& column.getType().isUDT()
|
||||
&& !column.getDatabase().isArrayType(columnTypeFull)
|
||||
) {
|
||||
if (generateInstanceFields() && udtPath) {
|
||||
final SchemaDefinition columnUdtSchema = column.getDatabase().getSchema(column.getType().getQualifiedUserType().qualifier().last());
|
||||
final UDTDefinition columnUdt = column.getDatabase().getUDT(columnUdtSchema, column.getType().getUserType());
|
||||
final String columnPathType = out.ref(getStrategy().getFullJavaClassName(columnUdt, Mode.PATH));
|
||||
@ -6423,7 +6464,7 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
}
|
||||
else
|
||||
out.println("%s%sfinal %s<%s, %s> %s = createField(%s.name(\"%s\"), %s, %s, \"%s\"" + converterTemplate(converter) + converterTemplate(binding) + converterTemplate(generator) + ");",
|
||||
columnVisibility, isStatic, TableField.class, recordType, columnType, columnId, DSL.class, columnName, columnTypeRef, tableRef, escapeString(comment(column)), converter, binding, generator);
|
||||
columnVisibility, isStatic, TableField.class, recordType, columnType, columnId, DSL.class, escapeString(columnName), columnTypeRef, tableRef, escapeString(comment(column)), converter, binding, generator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -10553,8 +10594,10 @@ public class JavaGenerator extends AbstractGenerator {
|
||||
}
|
||||
|
||||
private void appendGetDataTypeCall(StringBuilder sb) {
|
||||
if (language == KOTLIN)
|
||||
if (kotlin)
|
||||
sb.append(".dataType");
|
||||
else if (scala)
|
||||
sb.append(".getDataType");
|
||||
else
|
||||
sb.append(".getDataType()");
|
||||
}
|
||||
|
||||
@ -125,7 +125,7 @@ import org.reactivestreams.Subscription;
|
||||
@org.jooq.Internal
|
||||
public final class Internal {
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, P extends UDTPathTableField<R, UR, T>> P createUDTPathTableField(
|
||||
public static final <R extends Record, T, P extends UDTPathTableField<R, ?, T>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
Table<R> table,
|
||||
@ -134,7 +134,7 @@ public final class Internal {
|
||||
return createUDTPathTableField(name, type, table, null, returnType, null, null, null);
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, P extends UDTPathTableField<R, UR, T>> P createUDTPathTableField(
|
||||
public static final <R extends Record, T, P extends UDTPathTableField<R, ?, T>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
Table<R> table,
|
||||
@ -144,7 +144,7 @@ public final class Internal {
|
||||
return createUDTPathTableField(name, type, table, comment, returnType, null, null, null);
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, U, P extends UDTPathTableField<R, UR, U>> P createUDTPathTableField(
|
||||
public static final <R extends Record, T, U, P extends UDTPathTableField<R, ?, U>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
Table<R> table,
|
||||
@ -155,7 +155,7 @@ public final class Internal {
|
||||
return createUDTPathTableField(name, type, table, comment, returnType, converter, null, null);
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, U, P extends UDTPathTableField<R, UR, U>> P createUDTPathTableField(
|
||||
public static final <R extends Record, T, U, P extends UDTPathTableField<R, ?, U>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
Table<R> table,
|
||||
@ -166,7 +166,7 @@ public final class Internal {
|
||||
return createUDTPathTableField(name, type, table, comment, returnType, null, binding, null);
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, X, U, P extends UDTPathTableField<R, UR, U>> P createUDTPathTableField(
|
||||
public static final <R extends Record, T, X, U, P extends UDTPathTableField<R, ?, U>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
Table<R> table,
|
||||
@ -178,7 +178,7 @@ public final class Internal {
|
||||
return createUDTPathTableField(name, type, table, comment, returnType, converter, binding, null);
|
||||
}
|
||||
|
||||
public static final <R extends Record, TR extends Table<R>, UR extends UDTRecord<UR>, T, P extends UDTPathTableField<R, UR, T>> P createUDTPathTableField(
|
||||
public static final <R extends Record, TR extends Table<R>, T, P extends UDTPathTableField<R, ?, T>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
TR table,
|
||||
@ -189,7 +189,7 @@ public final class Internal {
|
||||
return createUDTPathTableField(name, type, table, comment, returnType, null, null, generator);
|
||||
}
|
||||
|
||||
public static final <R extends Record, TR extends Table<R>, UR extends UDTRecord<UR>, T, U, P extends UDTPathTableField<R, UR, U>> P createUDTPathTableField(
|
||||
public static final <R extends Record, TR extends Table<R>, T, U, P extends UDTPathTableField<R, ?, U>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
TR table,
|
||||
@ -201,7 +201,7 @@ public final class Internal {
|
||||
return createUDTPathTableField(name, type, table, comment, returnType, converter, null, generator);
|
||||
}
|
||||
|
||||
public static final <R extends Record, TR extends Table<R>, UR extends UDTRecord<UR>, T, U, P extends UDTPathTableField<R, UR, U>> P createUDTPathTableField(
|
||||
public static final <R extends Record, TR extends Table<R>, T, U, P extends UDTPathTableField<R, ?, U>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
TR table,
|
||||
@ -214,7 +214,7 @@ public final class Internal {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final <R extends Record, TR extends Table<R>, UR extends UDTRecord<UR>, T, X, U, P extends UDTPathTableField<R, UR, U>> P createUDTPathTableField(
|
||||
public static final <R extends Record, TR extends Table<R>, T, X, U, P extends UDTPathTableField<R, ?, U>> P createUDTPathTableField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
TR table,
|
||||
@ -248,29 +248,29 @@ public final class Internal {
|
||||
}
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, P extends UDTField<UR, T>> P createUDTPathField(
|
||||
public static final <T, P extends UDTField<?, T>> P createUDTPathField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
UDTPathField<R, UR, ?> qualifier,
|
||||
UDTPathField<?, ?, ?> qualifier,
|
||||
Class<P> returnType
|
||||
) {
|
||||
return createUDTPathField(name, type, qualifier, null, returnType, null, null);
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, P extends UDTField<UR, T>> P createUDTPathField(
|
||||
public static final <T, P extends UDTField<?, T>> P createUDTPathField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
UDTPathField<R, UR, ?> qualifier,
|
||||
UDTPathField<?, ?, ?> qualifier,
|
||||
String comment,
|
||||
Class<P> returnType
|
||||
) {
|
||||
return createUDTPathField(name, type, qualifier, comment, returnType, null, null);
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, U, P extends UDTField<UR, U>> P createUDTPathField(
|
||||
public static final <T, U, P extends UDTField<?, U>> P createUDTPathField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
UDTPathField<R, UR, ?> qualifier,
|
||||
UDTPathField<?, ?, ?> qualifier,
|
||||
String comment,
|
||||
Class<P> returnType,
|
||||
Converter<T, U> converter
|
||||
@ -278,10 +278,10 @@ public final class Internal {
|
||||
return createUDTPathField(name, type, qualifier, comment, returnType, converter, null);
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, U, P extends UDTField<UR, U>> P createUDTPathField(
|
||||
public static final <T, U, P extends UDTField<?, U>> P createUDTPathField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
UDTPathField<R, UR, ?> qualifier,
|
||||
UDTPathField<?, ?, ?> qualifier,
|
||||
String comment,
|
||||
Class<P> returnType,
|
||||
Binding<T, U> binding
|
||||
@ -289,10 +289,10 @@ public final class Internal {
|
||||
return createUDTPathField(name, type, qualifier, comment, returnType, null, binding);
|
||||
}
|
||||
|
||||
public static final <R extends Record, UR extends UDTRecord<UR>, T, X, U, P extends UDTField<UR, U>> P createUDTPathField(
|
||||
public static final <T, X, U, P extends UDTField<?, U>> P createUDTPathField(
|
||||
Name name,
|
||||
DataType<T> type,
|
||||
UDTPathField<R, UR, ?> qualifier,
|
||||
UDTPathField<?, ?, ?> qualifier,
|
||||
String comment,
|
||||
Class<P> returnType,
|
||||
Converter<X, U> converter,
|
||||
@ -318,10 +318,10 @@ public final class Internal {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <R extends Record, UR extends UDTRecord<UR>, T, X, U, P extends UDTField<UR, U>> P newInstance(
|
||||
private static <T, X, U, P extends UDTField<?, U>> P newInstance(
|
||||
Name name,
|
||||
RecordQualifier<R> qualifier,
|
||||
UDTPathField<R, ?, ?> path,
|
||||
RecordQualifier<?> qualifier,
|
||||
UDTPathField<?, ?, ?> path,
|
||||
String comment,
|
||||
Class<P> returnType,
|
||||
Binding<T, U> actualBinding,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user