use of org.mybatis.generator.api.dom.kotlin.KotlinProperty in project generator by mybatis.
the class KotlinDynamicSqlSupportClassGenerator method handleColumn.
private void handleColumn(KotlinFile kotlinFile, KotlinType outerObject, KotlinType innerClass, String tableFieldName, IntrospectedColumn column) {
FullyQualifiedKotlinType kt = JavaToKotlinTypeConverter.convert(column.getFullyQualifiedJavaType());
kotlinFile.addImports(kt.getImportList());
String fieldName = column.getJavaProperty();
// outer object
if (fieldName.equals(tableFieldName)) {
// name collision, skip the shortcut field
warnings.add(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"Warning.29", fieldName, getSupportObjectImport()));
} else {
KotlinProperty prop = KotlinProperty.newVal(fieldName).withInitializationString(tableFieldName + "." + fieldName).build();
outerObject.addNamedItem(prop);
}
// inner class
KotlinProperty property = KotlinProperty.newVal(fieldName).withInitializationString(calculateInnerInitializationString(column, kt)).build();
innerClass.addNamedItem(property);
}
use of org.mybatis.generator.api.dom.kotlin.KotlinProperty in project generator by mybatis.
the class KotlinDataClassGenerator method getKotlinFiles.
@Override
public List<KotlinFile> getKotlinFiles() {
FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
// $NON-NLS-1$
progressCallback.startTask(getString("Progress.8", table.toString()));
CommentGenerator commentGenerator = context.getCommentGenerator();
FullyQualifiedKotlinType type = new FullyQualifiedKotlinType(introspectedTable.getKotlinRecordType());
KotlinFile kf = new KotlinFile(type.getShortNameWithoutTypeArguments());
kf.setPackage(type.getPackageName());
KotlinType dataClass = KotlinType.newClass(type.getShortNameWithoutTypeArguments()).withModifier(KotlinModifier.DATA).build();
kf.addNamedItem(dataClass);
commentGenerator.addFileComment(kf);
commentGenerator.addModelClassComment(dataClass, introspectedTable);
List<IntrospectedColumn> introspectedColumns = introspectedTable.getAllColumns();
for (IntrospectedColumn introspectedColumn : introspectedColumns) {
FullyQualifiedKotlinType kotlinType = JavaToKotlinTypeConverter.convert(introspectedColumn.getFullyQualifiedJavaType());
KotlinProperty kp = KotlinProperty.newVar(introspectedColumn.getJavaProperty()).withDataType(// $NON-NLS-1$
kotlinType.getShortNameWithTypeArguments() + "?").withInitializationString(// $NON-NLS-1$
"null").build();
dataClass.addConstructorProperty(kp);
kf.addImports(kotlinType.getImportList());
}
if (context.getPlugins().kotlinDataClassGenerated(kf, dataClass, introspectedTable)) {
return listOf(kf);
} else {
return Collections.emptyList();
}
}
Aggregations