From 7103f67edb5f2928dff36d52222724cb22228022 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Thu, 14 Mar 2024 14:00:55 +0100 Subject: [PATCH 01/18] added SchemaClass generation --- .../com/schwarz/crystalapi/SchemaClass.kt | 5 + .../com/schwarz/crystalapi/schema/CMField.kt | 13 ++ .../CoachBaseBinderProcessor.kt | 30 ++- .../generation/model/SchemaGeneration.kt | 184 ++++++++++++++++++ .../crystalprocessor/model/EntityFactory.kt | 59 ++++-- .../model/entity/SchemaClassHolder.kt | 9 + .../model/field/CblFieldHolder.kt | 6 +- .../processing/model/ModelWorkSet.kt | 40 +++- .../processing/model/ModelWorker.kt | 15 +- .../CouchbaseBaseBinderProcessorKotlinTest.kt | 21 ++ .../com/schwarz/crystaldemo/entity/Product.kt | 2 + 11 files changed, 344 insertions(+), 40 deletions(-) create mode 100644 crystal-map-api/src/main/java/com/schwarz/crystalapi/SchemaClass.kt create mode 100644 crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMField.kt create mode 100644 crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt create mode 100644 crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/entity/SchemaClassHolder.kt diff --git a/crystal-map-api/src/main/java/com/schwarz/crystalapi/SchemaClass.kt b/crystal-map-api/src/main/java/com/schwarz/crystalapi/SchemaClass.kt new file mode 100644 index 00000000..bd8da5be --- /dev/null +++ b/crystal-map-api/src/main/java/com/schwarz/crystalapi/SchemaClass.kt @@ -0,0 +1,5 @@ +package com.schwarz.crystalapi + +@Retention(AnnotationRetention.BINARY) +@Target(AnnotationTarget.CLASS) +annotation class SchemaClass diff --git a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMField.kt b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMField.kt new file mode 100644 index 00000000..a7b56a4b --- /dev/null +++ b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMField.kt @@ -0,0 +1,13 @@ +package com.schwarz.crystalapi.schema + +interface Schema + +interface DatabaseRecord + +class CMField(val name: String, val path: String) : DatabaseRecord + +class CMList(val name: String, val path: String) : DatabaseRecord + +class CMObject(val element: T, val path: String) : DatabaseRecord + +class CMObjectList(val element: T, val name: String, val path: String) : DatabaseRecord diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/CoachBaseBinderProcessor.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/CoachBaseBinderProcessor.kt index 2e707cb4..1965d1ca 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/CoachBaseBinderProcessor.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/CoachBaseBinderProcessor.kt @@ -1,6 +1,10 @@ package com.schwarz.crystalprocessor import com.google.auto.service.AutoService +import com.schwarz.crystalapi.* +import com.schwarz.crystalapi.mapify.Mapper +import com.schwarz.crystalapi.query.Queries +import com.schwarz.crystalapi.query.Query import com.schwarz.crystalprocessor.CoachBaseBinderProcessor.Companion.FRAMEWORK_DOCUMENTATION_FILENAME_OPTION_NAME import com.schwarz.crystalprocessor.CoachBaseBinderProcessor.Companion.FRAMEWORK_DOCUMENTATION_PATH_OPTION_NAME import com.schwarz.crystalprocessor.CoachBaseBinderProcessor.Companion.FRAMEWORK_SCHEMA_FILENAME_OPTION_NAME @@ -11,17 +15,20 @@ import com.schwarz.crystalprocessor.generation.CodeGenerator import com.schwarz.crystalprocessor.processing.Worker import com.schwarz.crystalprocessor.processing.mapper.MapperWorker import com.schwarz.crystalprocessor.processing.model.ModelWorker -import com.schwarz.crystalapi.* -import com.schwarz.crystalapi.mapify.Mapper -import com.schwarz.crystalapi.query.Queries -import com.schwarz.crystalapi.query.Query import javax.annotation.processing.* import javax.lang.model.SourceVersion import javax.lang.model.element.TypeElement @SupportedSourceVersion(SourceVersion.RELEASE_17) @AutoService(Processor::class) -@SupportedOptions(KAPT_KOTLIN_GENERATED_OPTION_NAME, FRAMEWORK_USE_SUSPEND_OPTION_NAME, FRAMEWORK_DOCUMENTATION_PATH_OPTION_NAME, FRAMEWORK_DOCUMENTATION_FILENAME_OPTION_NAME, FRAMEWORK_SCHEMA_PATH_OPTION_NAME, FRAMEWORK_SCHEMA_FILENAME_OPTION_NAME) +@SupportedOptions( + KAPT_KOTLIN_GENERATED_OPTION_NAME, + FRAMEWORK_USE_SUSPEND_OPTION_NAME, + FRAMEWORK_DOCUMENTATION_PATH_OPTION_NAME, + FRAMEWORK_DOCUMENTATION_FILENAME_OPTION_NAME, + FRAMEWORK_SCHEMA_PATH_OPTION_NAME, + FRAMEWORK_SCHEMA_FILENAME_OPTION_NAME +) class CoachBaseBinderProcessor : AbstractProcessor() { private lateinit var mLogger: Logger @@ -81,6 +88,17 @@ class CoachBaseBinderProcessor : AbstractProcessor() { } override fun getSupportedAnnotationTypes(): MutableSet { - return setOf(Field::class.java.canonicalName, Entity::class.java.canonicalName, MapWrapper::class.java.canonicalName, Queries::class.java.canonicalName, Query::class.java.canonicalName, GenerateAccessor::class.java.canonicalName, Mapper::class.java.canonicalName, Reduces::class.java.canonicalName, Reduce::class.java.canonicalName).toMutableSet() + return setOf( + Field::class.java.canonicalName, + Entity::class.java.canonicalName, + MapWrapper::class.java.canonicalName, + SchemaClass::class.java.canonicalName, + Queries::class.java.canonicalName, + Query::class.java.canonicalName, + GenerateAccessor::class.java.canonicalName, + Mapper::class.java.canonicalName, + Reduces::class.java.canonicalName, + Reduce::class.java.canonicalName + ).toMutableSet() } } diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt new file mode 100644 index 00000000..2ee881f5 --- /dev/null +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -0,0 +1,184 @@ +package com.schwarz.crystalprocessor.generation.model + +import com.schwarz.crystalapi.schema.* +import com.schwarz.crystalprocessor.model.entity.SchemaClassHolder +import com.schwarz.crystalprocessor.model.field.CblBaseFieldHolder +import com.schwarz.crystalprocessor.model.field.CblFieldHolder +import com.schwarz.crystalprocessor.util.ConversionUtil +import com.schwarz.crystalprocessor.util.TypeUtil +import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy + +/** + * This class for generation of the Schema classes. + * + * To generate a SchemaClass add the + * ``` + * @SchemaClass + * ``` + * annotation to your Class and all the Fields will be generated into a new File. + */ +class SchemaGeneration { + private val pathAttributeName = "path" + fun generateModel(holder: SchemaClassHolder, schemaClassPaths: List): FileSpec { + val packageName = holder.sourcePackage + val schemaClassName = holder.entitySimpleName + + val schemaClass: TypeSpec.Builder = buildSchemaClass(schemaClassName) + + buildAndAddFieldProperties(holder, schemaClass, schemaClassPaths) + + return FileSpec.builder(packageName, schemaClassName).addType(schemaClass.build()).build() + } + + private fun buildSchemaClass(className: String): TypeSpec.Builder { + val pathParameter = ParameterSpec.builder(pathAttributeName, String::class).defaultValue("%S", "").build() + + return TypeSpec.classBuilder(className) + .addModifiers(KModifier.OPEN) + .addSuperinterface(Schema::class) + .primaryConstructor( + FunSpec.constructorBuilder() + .addParameter(pathParameter) + .build() + ) + } + + private fun buildAndAddFieldProperties( + holder: SchemaClassHolder, + schemaClass: TypeSpec.Builder, + schemaClassPaths: List, + ) { + buildAndAddConstantFieldProperties(holder, schemaClass, schemaClassPaths) + buildAndAddNormalFieldProperties(holder, schemaClass, schemaClassPaths) + } + + private fun buildAndAddConstantFieldProperties( + holder: SchemaClassHolder, + schemaClass: TypeSpec.Builder, + schemaClassPaths: List + ) { + holder.fieldConstants.forEach { (fieldName, fieldObject) -> + val defaultVariableName = "DEFAULT_${fieldObject.constantName}" + + val constantProperty = PropertySpec.builder( + defaultVariableName, + fieldObject.fieldType + ).initializer( + ConversionUtil.convertStringToDesiredFormat( + fieldObject.typeMirror, + fieldObject.constantValue + ) + ) + + schemaClass.addProperty(constantProperty.build()) + + buildAndAddFieldProperty( + schemaClass = schemaClass, + fieldName = fieldName, + fieldObject = fieldObject, + schemaClassPaths = schemaClassPaths + ) + } + } + + private fun buildAndAddNormalFieldProperties( + holder: SchemaClassHolder, + schemaClass: TypeSpec.Builder, + schemaClassPaths: List + ) { + holder.fields.forEach { (fieldName, fieldObject) -> + buildAndAddFieldProperty( + schemaClass = schemaClass, + fieldName = fieldName, + fieldObject = fieldObject, + schemaClassPaths = schemaClassPaths, + ) + } + } + + private fun buildAndAddFieldProperty( + schemaClass: TypeSpec.Builder, + fieldName: String, + fieldObject: CblBaseFieldHolder, + schemaClassPaths: List, + ): TypeSpec.Builder { + return schemaClass.addProperty( + buildFieldProperty(fieldObject, fieldName, schemaClassPaths) + ) + } + + private fun buildFieldProperty( + fieldObject: CblBaseFieldHolder, + fieldName: String, + schemaClassPaths: List, + ): PropertySpec { + val isObject = schemaClassPaths.contains(fieldObject.typeMirror.toString()) + + val outerType = getOuterPropertyType(fieldObject.isIterable, isObject) + + val innerType: TypeName = getInnerPropertyType(fieldObject) + + return PropertySpec.builder( + fieldName, + outerType.parameterizedBy(innerType) + ).initializer( + createPropertyFormat(fieldName, innerType, fieldObject.isIterable, isObject), + outerType, + ).build() + } + + private fun createPropertyFormat( + fieldName: String, + propertyType: TypeName, + isIterable: Boolean, + isObject: Boolean + ): String { + val propertyAccessPath = + "if ($pathAttributeName.isBlank()) \"$fieldName\" else \"\$$pathAttributeName.$fieldName\"" + + return when { + isIterable && isObject -> buildObjectListFormat(propertyType, fieldName, propertyAccessPath) + isObject -> buildObjectFormat(propertyType, propertyAccessPath) + else -> buildSimpleFormat(fieldName) + } + } + + private fun buildObjectListFormat(propertyType: TypeName, fieldName: String, propertyAccessPath: String): String = + """%T( + $propertyType($propertyAccessPath), + "$fieldName", + $pathAttributeName, + )""" + + private fun buildSimpleFormat(fieldName: String): String = + """%T("$fieldName", $pathAttributeName)""" + + private fun buildObjectFormat(propertyType: TypeName, propertyAccessPath: String): String = + """%T( + $propertyType($propertyAccessPath), + $pathAttributeName, + )""" + + private fun getOuterPropertyType( + isIterable: Boolean, + isObject: Boolean + ) = if (isIterable && isObject) { + CMObjectList::class.asTypeName() + } else if (isIterable) { + CMList::class.asTypeName() + } else if (isObject) { + CMObject::class.asTypeName() + } else { + CMField::class.asTypeName() + } + + private fun getInnerPropertyType(fieldObject: CblBaseFieldHolder): TypeName { + val name: String? = when (fieldObject) { + is CblFieldHolder -> fieldObject.subEntitySimpleName + else -> null + } + + return TypeUtil.parseMetaType(fieldObject.typeMirror, false, name) + } +} diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt index 36e5dbc1..e7c9cefb 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt @@ -7,6 +7,7 @@ import com.schwarz.crystalprocessor.model.entity.BaseModelHolder import com.schwarz.crystalprocessor.model.entity.EntityHolder import com.schwarz.crystalprocessor.model.entity.ReducedModelHolder import com.schwarz.crystalprocessor.model.entity.WrapperEntityHolder +import com.schwarz.crystalprocessor.model.entity.SchemaClassHolder import com.schwarz.crystalprocessor.model.field.CblConstantHolder import com.schwarz.crystalprocessor.model.field.CblFieldHolder import com.schwarz.crystalprocessor.model.id.DocIdHolder @@ -16,10 +17,12 @@ import com.schwarz.crystalprocessor.model.source.ISourceModel import com.schwarz.crystalprocessor.util.FieldExtractionUtil object EntityFactory { + private const val WRAPPER_SUB_ENTITY_POST_FIX = "Wrapper" + private const val SCHEMA_SUB_ENTITY_POST_FIX = "Schema" fun createEntityHolder( sourceModel: ISourceModel, - allWrappers: List, + allWrapperPaths: List, allBaseModels: Map ): EntityHolder { val annotation = sourceModel.entityAnnotation!! @@ -29,46 +32,64 @@ object EntityFactory { annotation.database, annotation.modifierOpen, annotation.type, - sourceModel + sourceModel, ), - allWrappers, - allBaseModels + allWrapperPaths, + allBaseModels, + WRAPPER_SUB_ENTITY_POST_FIX, ) as EntityHolder } fun createBaseModelHolder( sourceModel: ISourceModel, - allWrappers: List + allWrapperPaths: List ): BaseModelHolder { return create( sourceModel, BaseModelHolder(sourceModel), - allWrappers, - emptyMap() + allWrapperPaths, + emptyMap(), + WRAPPER_SUB_ENTITY_POST_FIX, ) as BaseModelHolder } fun createChildEntityHolder( sourceModel: ISourceModel, - allWrappers: List, + allWrapperPaths: List, allBaseModels: Map ): WrapperEntityHolder { val annotation = sourceModel.mapWrapperAnnotation!! return create( sourceModel, WrapperEntityHolder(annotation.modifierOpen, sourceModel), - allWrappers, - allBaseModels + allWrapperPaths, + allBaseModels, + WRAPPER_SUB_ENTITY_POST_FIX, ) as WrapperEntityHolder } + fun createSchemaEntityHolder( + sourceModel: ISourceModel, + allSchemaClassPaths: List, + allBaseModels: Map + ): SchemaClassHolder { + return create( + sourceModel, + SchemaClassHolder(sourceModel), + allSchemaClassPaths, + allBaseModels, + SCHEMA_SUB_ENTITY_POST_FIX, + ) as SchemaClassHolder + } + private fun create( sourceModel: ISourceModel, content: BaseEntityHolder, - allWrappers: List, - allBaseModels: Map + classPaths: List, + allBaseModels: Map, + subEntityNamePostFix: String, ): BaseEntityHolder { - content.reducesModels = createReduceModels(sourceModel, content, allWrappers, allBaseModels) + content.reducesModels = createReduceModels(sourceModel, content) content.abstractParts = sourceModel.abstractParts content.comment = sourceModel.commentAnnotation?.comment ?: arrayOf() content.deprecated = sourceModel.deprecatedAnnotation?.let { DeprecatedModel(it) } @@ -76,7 +97,7 @@ object EntityFactory { addBasedOn(sourceModel, allBaseModels, content) parseQueries(sourceModel, content) - parseFields(sourceModel, content, allWrappers, allBaseModels) + parseFields(sourceModel, content, classPaths, subEntityNamePostFix) val docId = sourceModel.docIdAnnotation val docIdSegments: MutableList = mutableListOf() @@ -116,9 +137,7 @@ object EntityFactory { private fun createReduceModels( sourceModel: ISourceModel, - content: BaseEntityHolder, - allWrappers: List, - allBaseModels: Map + content: BaseEntityHolder ): List { sourceModel.reduceAnnotations.let { reduce -> return reduce.map { @@ -169,14 +188,14 @@ object EntityFactory { private fun parseFields( sourceModel: ISourceModel, content: BaseEntityHolder, - allWrappers: List, - allBaseModels: Map + classPaths: List, + subEntityNamePostFix: String ) { for (cblField in sourceModel.fieldAnnotations) { if (cblField.readonly) { content.fieldConstants[cblField.name] = CblConstantHolder(cblField) } else { - val cblFieldHolder = CblFieldHolder(cblField, allWrappers) + val cblFieldHolder = CblFieldHolder(cblField, classPaths, subEntityNamePostFix) content.fields[cblField.name] = cblFieldHolder } } diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/entity/SchemaClassHolder.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/entity/SchemaClassHolder.kt new file mode 100644 index 00000000..ee999cf8 --- /dev/null +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/entity/SchemaClassHolder.kt @@ -0,0 +1,9 @@ +package com.schwarz.crystalprocessor.model.entity + +import com.schwarz.crystalprocessor.model.source.ISourceModel + +class SchemaClassHolder(sourceModel: ISourceModel) : BaseEntityHolder(sourceModel) { + + override val entitySimpleName: String + get() = sourceClazzSimpleName + "Schema" +} \ No newline at end of file diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/field/CblFieldHolder.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/field/CblFieldHolder.kt index de7a0540..29ee5d38 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/field/CblFieldHolder.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/field/CblFieldHolder.kt @@ -12,7 +12,7 @@ import com.schwarz.crystalapi.Field import com.schwarz.crystalapi.util.CrystalWrap import org.apache.commons.lang3.StringUtils -class CblFieldHolder(field: Field, allWrappers: List) : +class CblFieldHolder(field: Field, classPaths: List, subEntityNamePostFix: String) : CblBaseFieldHolder(field.name, field) { private var subEntityPackage: String? = null @@ -35,9 +35,9 @@ class CblFieldHolder(field: Field, allWrappers: List) : TypeUtil.parseMetaType(typeMirror, isIterable, subEntitySimpleName) init { - if (allWrappers.contains(typeMirror.toString())) { + if (classPaths.contains(typeMirror.toString())) { - subEntitySimpleName = TypeUtil.getSimpleName(typeMirror) + "Wrapper" + subEntitySimpleName = TypeUtil.getSimpleName(typeMirror) + subEntityNamePostFix subEntityPackage = TypeUtil.getPackage(typeMirror) isSubEntityIsTypeParam = field.list } diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt index aafe9066..a974e550 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt @@ -4,6 +4,7 @@ import com.schwarz.crystalprocessor.Logger import com.schwarz.crystalprocessor.model.EntityFactory import com.schwarz.crystalprocessor.model.entity.BaseModelHolder import com.schwarz.crystalprocessor.model.entity.EntityHolder +import com.schwarz.crystalprocessor.model.entity.SchemaClassHolder import com.schwarz.crystalprocessor.model.entity.WrapperEntityHolder import com.schwarz.crystalprocessor.model.source.ReducedSourceModel import com.schwarz.crystalprocessor.model.source.SourceModel @@ -13,13 +14,20 @@ import com.schwarz.crystalprocessor.validation.model.PreModelValidation import javax.annotation.processing.ProcessingEnvironment import javax.lang.model.element.Element -class ModelWorkSet(val allEntityElements: Set, val allWrapperElements: Set, val allBaseModelElements: Set) : +class ModelWorkSet( + val allEntityElements: Set, + val allWrapperElements: Set, + val allSchemaClassElements: Set, + val allBaseModelElements: Set +) : WorkSet { private val entityModels: MutableMap = HashMap() private val wrapperModels: MutableMap = HashMap() + private val schemaModels: MutableMap = HashMap() + private val baseModels: MutableMap = HashMap() override fun preValidate(logger: Logger) { @@ -29,10 +37,10 @@ class ModelWorkSet(val allEntityElements: Set, val allWrapperElements: } override fun loadModels(logger: Logger, env: ProcessingEnvironment) { - val allWrapperStrings = allWrapperElements.map { element -> element.toString() } + val allWrapperPaths = allWrapperElements.map { element -> element.toString() } for (element in allBaseModelElements) { - val baseModel = EntityFactory.createBaseModelHolder(SourceModel(element), allWrapperStrings) + val baseModel = EntityFactory.createBaseModelHolder(SourceModel(element), allWrapperPaths) baseModels[element.toString()] = baseModel } @@ -42,22 +50,34 @@ class ModelWorkSet(val allEntityElements: Set, val allWrapperElements: } for (element in allEntityElements) { - val entityModel = EntityFactory.createEntityHolder(SourceModel(element), allWrapperStrings, baseModels) + val entityModel = EntityFactory.createEntityHolder(SourceModel(element), allWrapperPaths, baseModels) entityModels[element.toString()] = entityModel entityModel.reducesModels.forEach { - val reduced = EntityFactory.createEntityHolder(ReducedSourceModel(entityModel.sourceElement, it), allWrapperStrings, baseModels) + val reduced = EntityFactory.createEntityHolder(ReducedSourceModel(entityModel.sourceElement, it), allWrapperPaths, baseModels) reduced.isReduced = true entityModels[reduced.entitySimpleName] = reduced } } for (element in allWrapperElements) { - val wrapperModel = EntityFactory.createChildEntityHolder(SourceModel(element), allWrapperStrings, baseModels) + val wrapperModel = EntityFactory.createChildEntityHolder(SourceModel(element), allWrapperPaths, baseModels) wrapperModels[element.toString()] = wrapperModel wrapperModel.reducesModels.forEach { - val reduced = EntityFactory.createEntityHolder(ReducedSourceModel(wrapperModel.sourceElement, it), allWrapperStrings, baseModels) + val reduced = EntityFactory.createEntityHolder(ReducedSourceModel(wrapperModel.sourceElement, it), allWrapperPaths, baseModels) + reduced.isReduced = true + entityModels[reduced.entitySimpleName] = reduced + } + } + + val allSchemaClassPaths = allSchemaClassElements.map { element -> element.toString() } + for (element in allSchemaClassElements) { + val schemaModel = EntityFactory.createSchemaEntityHolder(SourceModel(element), allSchemaClassPaths, baseModels) + schemaModels[element.toString()] = schemaModel + + schemaModel.reducesModels.forEach { + val reduced = EntityFactory.createEntityHolder(ReducedSourceModel(schemaModel.sourceElement, it), allSchemaClassPaths, baseModels) reduced.isReduced = true entityModels[reduced.entitySimpleName] = reduced } @@ -72,6 +92,12 @@ class ModelWorkSet(val allEntityElements: Set, val allWrapperElements: val wrappers: List get() = wrapperModels.values.toList() + val schemas: List + get() = schemaModels.values.toList() + + val schemaClassPaths: List + get() = schemaModels.keys.toList() + val bases: List get() = baseModels.values.toList() } diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt index 5d3addde..f6ed39a6 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt @@ -1,5 +1,9 @@ package com.schwarz.crystalprocessor.processing.model +import com.schwarz.crystalapi.BaseModel +import com.schwarz.crystalapi.Entity +import com.schwarz.crystalapi.SchemaClass +import com.schwarz.crystalapi.MapWrapper import com.schwarz.crystalprocessor.CoachBaseBinderProcessor import com.schwarz.crystalprocessor.Logger import com.schwarz.crystalprocessor.documentation.DocumentationGenerator @@ -7,14 +11,12 @@ import com.schwarz.crystalprocessor.documentation.EntityRelationshipGenerator import com.schwarz.crystalprocessor.generation.CodeGenerator import com.schwarz.crystalprocessor.generation.model.CommonInterfaceGeneration import com.schwarz.crystalprocessor.generation.model.EntityGeneration +import com.schwarz.crystalprocessor.generation.model.SchemaGeneration import com.schwarz.crystalprocessor.generation.model.WrapperGeneration import com.schwarz.crystalprocessor.meta.SchemaGenerator import com.schwarz.crystalprocessor.model.entity.BaseEntityHolder import com.schwarz.crystalprocessor.processing.Worker import com.squareup.kotlinpoet.FileSpec -import com.schwarz.crystalapi.BaseModel -import com.schwarz.crystalapi.Entity -import com.schwarz.crystalapi.MapWrapper import javax.annotation.processing.ProcessingEnvironment import javax.annotation.processing.RoundEnvironment @@ -45,7 +47,7 @@ class ModelWorker(override val logger: Logger, override val codeGenerator: CodeG } override fun doWork(workSet: ModelWorkSet, useSuspend: Boolean) { - var generatedInterfaces = mutableSetOf() + val generatedInterfaces = mutableSetOf() for (baseModelHolder in workSet.bases) { generateInterface(generatedInterfaces, baseModelHolder, useSuspend) @@ -59,6 +61,10 @@ class ModelWorker(override val logger: Logger, override val codeGenerator: CodeG WrapperGeneration().generateModel(it, useSuspend) } + process(workSet.schemas, generatedInterfaces, useSuspend) { + SchemaGeneration().generateModel(it, workSet.schemaClassPaths) + } + documentationGenerator?.generate() entityRelationshipGenerator?.generate() schemaGenerator?.generate() @@ -90,6 +96,7 @@ class ModelWorker(override val logger: Logger, override val codeGenerator: CodeG override fun evaluateWorkSet(roundEnv: RoundEnvironment): ModelWorkSet = ModelWorkSet( allEntityElements = roundEnv.getElementsAnnotatedWith(Entity::class.java), allWrapperElements = roundEnv.getElementsAnnotatedWith(MapWrapper::class.java), + allSchemaClassElements = roundEnv.getElementsAnnotatedWith(SchemaClass::class.java), allBaseModelElements = roundEnv.getElementsAnnotatedWith(BaseModel::class.java) ) } diff --git a/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt b/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt index 2eec978c..33089cbe 100644 --- a/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt +++ b/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt @@ -168,6 +168,27 @@ class CouchbaseBaseBinderProcessorKotlinTest { Assert.assertEquals(KotlinCompilation.ExitCode.OK, compilation.exitCode) } + @Test + fun testKotlinFieldsGeneration() { + val subSchema = SourceFile.kotlin( + "Sub.kt", + "package com.kaufland.testModels\n" + + "import com.schwarz.crystalapi.Field\n" + + "import com.schwarz.crystalapi.Fields\n" + + "import com.schwarz.crystalapi.SchemaClass\n" + + "@SchemaClass\n" + + "@Fields(\n" + + "Field(name = \"test_test_test\", type = Number::class),\n" + + "Field(name = \"type\", type = String::class, defaultValue = \"test\", readonly = true)\n" + + ")\n" + + "class Sub" + ) + + val compilation = compileKotlin(subSchema) + + Assert.assertEquals(KotlinCompilation.ExitCode.OK, compilation.exitCode) + } + @Test fun testKotlinPrivateGeneration() { val subEntity = SourceFile.kotlin( diff --git a/demo/src/main/java/com/schwarz/crystaldemo/entity/Product.kt b/demo/src/main/java/com/schwarz/crystaldemo/entity/Product.kt index d792daff..16106e9c 100644 --- a/demo/src/main/java/com/schwarz/crystaldemo/entity/Product.kt +++ b/demo/src/main/java/com/schwarz/crystaldemo/entity/Product.kt @@ -8,6 +8,7 @@ import com.schwarz.crystalapi.Entity import com.schwarz.crystalapi.Field import com.schwarz.crystalapi.Fields import com.schwarz.crystalapi.MapWrapper +import com.schwarz.crystalapi.SchemaClass import com.schwarz.crystalapi.Reduce import com.schwarz.crystalapi.Reduces import com.schwarz.crystalapi.query.Queries @@ -16,6 +17,7 @@ import com.schwarz.crystalapi.query.Query @Entity(database = "mydb_db") @MapWrapper @Comment(["Hey, I just met you and this is crazy", "But here's my documentation, so read it maybe"]) +@SchemaClass @Fields( Field( name = "type", From fffc60bd0c7031ec7437540fe6c9fd46e2e2412c Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 20 Mar 2024 16:35:48 +0100 Subject: [PATCH 02/18] fixed reducer generation --- .../schwarz/crystalprocessor/processing/model/ModelWorkSet.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt index a974e550..feddf724 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt @@ -77,7 +77,7 @@ class ModelWorkSet( schemaModels[element.toString()] = schemaModel schemaModel.reducesModels.forEach { - val reduced = EntityFactory.createEntityHolder(ReducedSourceModel(schemaModel.sourceElement, it), allSchemaClassPaths, baseModels) + val reduced = EntityFactory.createEntityHolder(ReducedSourceModel(schemaModel.sourceElement, it), allWrapperPaths, baseModels) reduced.isReduced = true entityModels[reduced.entitySimpleName] = reduced } From 366d3545ae1f1eae7e3c7ecb9da775e22eb2e19a Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 20 Mar 2024 16:39:48 +0100 Subject: [PATCH 03/18] code clean up --- .../generation/model/SchemaGeneration.kt | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt index 2ee881f5..6c66b8bb 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -163,22 +163,16 @@ class SchemaGeneration { private fun getOuterPropertyType( isIterable: Boolean, isObject: Boolean - ) = if (isIterable && isObject) { - CMObjectList::class.asTypeName() - } else if (isIterable) { - CMList::class.asTypeName() - } else if (isObject) { - CMObject::class.asTypeName() - } else { - CMField::class.asTypeName() + ) = when { + isIterable && isObject -> CMObjectList::class.asTypeName() + isIterable -> CMList::class.asTypeName() + isObject -> CMObject::class.asTypeName() + else -> CMField::class.asTypeName() } - private fun getInnerPropertyType(fieldObject: CblBaseFieldHolder): TypeName { - val name: String? = when (fieldObject) { - is CblFieldHolder -> fieldObject.subEntitySimpleName - else -> null - } + private fun getInnerPropertyType(field: CblBaseFieldHolder): TypeName { + val name: String? = if (field is CblFieldHolder) field.subEntitySimpleName else null - return TypeUtil.parseMetaType(fieldObject.typeMirror, false, name) + return TypeUtil.parseMetaType(field.typeMirror, false, name) } } From 47110eaccc831220add84190ae1c4aad6360f183 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 20 Mar 2024 16:40:24 +0100 Subject: [PATCH 04/18] made function to expression --- .../crystalprocessor/model/EntityFactory.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt index e7c9cefb..68cd212b 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt @@ -72,15 +72,13 @@ object EntityFactory { sourceModel: ISourceModel, allSchemaClassPaths: List, allBaseModels: Map - ): SchemaClassHolder { - return create( - sourceModel, - SchemaClassHolder(sourceModel), - allSchemaClassPaths, - allBaseModels, - SCHEMA_SUB_ENTITY_POST_FIX, - ) as SchemaClassHolder - } + ): SchemaClassHolder = create( + sourceModel, + SchemaClassHolder(sourceModel), + allSchemaClassPaths, + allBaseModels, + SCHEMA_SUB_ENTITY_POST_FIX, + ) as SchemaClassHolder private fun create( sourceModel: ISourceModel, From 45e4b4c0d64b84d4283511f60be2d749b3a09eaf Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 20 Mar 2024 16:43:23 +0100 Subject: [PATCH 05/18] renamed postfix to suffix --- .../crystalprocessor/model/EntityFactory.kt | 20 +++++++++---------- .../model/field/CblFieldHolder.kt | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt index 68cd212b..d8e3ef4e 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt @@ -17,8 +17,8 @@ import com.schwarz.crystalprocessor.model.source.ISourceModel import com.schwarz.crystalprocessor.util.FieldExtractionUtil object EntityFactory { - private const val WRAPPER_SUB_ENTITY_POST_FIX = "Wrapper" - private const val SCHEMA_SUB_ENTITY_POST_FIX = "Schema" + private const val WRAPPER_SUB_ENTITY_SUFFIX = "Wrapper" + private const val SCHEMA_SUB_ENTITY_SUFFIX = "Schema" fun createEntityHolder( sourceModel: ISourceModel, @@ -36,7 +36,7 @@ object EntityFactory { ), allWrapperPaths, allBaseModels, - WRAPPER_SUB_ENTITY_POST_FIX, + WRAPPER_SUB_ENTITY_SUFFIX, ) as EntityHolder } @@ -49,7 +49,7 @@ object EntityFactory { BaseModelHolder(sourceModel), allWrapperPaths, emptyMap(), - WRAPPER_SUB_ENTITY_POST_FIX, + WRAPPER_SUB_ENTITY_SUFFIX, ) as BaseModelHolder } @@ -64,7 +64,7 @@ object EntityFactory { WrapperEntityHolder(annotation.modifierOpen, sourceModel), allWrapperPaths, allBaseModels, - WRAPPER_SUB_ENTITY_POST_FIX, + WRAPPER_SUB_ENTITY_SUFFIX, ) as WrapperEntityHolder } @@ -77,7 +77,7 @@ object EntityFactory { SchemaClassHolder(sourceModel), allSchemaClassPaths, allBaseModels, - SCHEMA_SUB_ENTITY_POST_FIX, + SCHEMA_SUB_ENTITY_SUFFIX, ) as SchemaClassHolder private fun create( @@ -85,7 +85,7 @@ object EntityFactory { content: BaseEntityHolder, classPaths: List, allBaseModels: Map, - subEntityNamePostFix: String, + subEntityNameSuffix: String, ): BaseEntityHolder { content.reducesModels = createReduceModels(sourceModel, content) content.abstractParts = sourceModel.abstractParts @@ -95,7 +95,7 @@ object EntityFactory { addBasedOn(sourceModel, allBaseModels, content) parseQueries(sourceModel, content) - parseFields(sourceModel, content, classPaths, subEntityNamePostFix) + parseFields(sourceModel, content, classPaths, subEntityNameSuffix) val docId = sourceModel.docIdAnnotation val docIdSegments: MutableList = mutableListOf() @@ -187,13 +187,13 @@ object EntityFactory { sourceModel: ISourceModel, content: BaseEntityHolder, classPaths: List, - subEntityNamePostFix: String + subEntityNameSuffix: String ) { for (cblField in sourceModel.fieldAnnotations) { if (cblField.readonly) { content.fieldConstants[cblField.name] = CblConstantHolder(cblField) } else { - val cblFieldHolder = CblFieldHolder(cblField, classPaths, subEntityNamePostFix) + val cblFieldHolder = CblFieldHolder(cblField, classPaths, subEntityNameSuffix) content.fields[cblField.name] = cblFieldHolder } } diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/field/CblFieldHolder.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/field/CblFieldHolder.kt index 29ee5d38..c1bb3e9e 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/field/CblFieldHolder.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/field/CblFieldHolder.kt @@ -12,7 +12,7 @@ import com.schwarz.crystalapi.Field import com.schwarz.crystalapi.util.CrystalWrap import org.apache.commons.lang3.StringUtils -class CblFieldHolder(field: Field, classPaths: List, subEntityNamePostFix: String) : +class CblFieldHolder(field: Field, classPaths: List, subEntityNameSuffix: String) : CblBaseFieldHolder(field.name, field) { private var subEntityPackage: String? = null @@ -37,7 +37,7 @@ class CblFieldHolder(field: Field, classPaths: List, subEntityNamePostFi init { if (classPaths.contains(typeMirror.toString())) { - subEntitySimpleName = TypeUtil.getSimpleName(typeMirror) + subEntityNamePostFix + subEntitySimpleName = TypeUtil.getSimpleName(typeMirror) + subEntityNameSuffix subEntityPackage = TypeUtil.getPackage(typeMirror) isSubEntityIsTypeParam = field.list } From 6296609123ea6c280d9f37ac4102a0c606a71659 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 20 Mar 2024 16:43:58 +0100 Subject: [PATCH 06/18] converted function to expression body --- .../crystalprocessor/generation/model/SchemaGeneration.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt index 6c66b8bb..37b1bda9 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -102,11 +102,9 @@ class SchemaGeneration { fieldName: String, fieldObject: CblBaseFieldHolder, schemaClassPaths: List, - ): TypeSpec.Builder { - return schemaClass.addProperty( - buildFieldProperty(fieldObject, fieldName, schemaClassPaths) - ) - } + ): TypeSpec.Builder = schemaClass.addProperty( + buildFieldProperty(fieldObject, fieldName, schemaClassPaths) + ) private fun buildFieldProperty( fieldObject: CblBaseFieldHolder, From 07744d9cc5c80578137801e9ba943b6ae89c4413 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 20 Mar 2024 16:45:27 +0100 Subject: [PATCH 07/18] removed obvious named arguments --- .../generation/model/SchemaGeneration.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt index 37b1bda9..27c54afd 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -74,10 +74,10 @@ class SchemaGeneration { schemaClass.addProperty(constantProperty.build()) buildAndAddFieldProperty( - schemaClass = schemaClass, - fieldName = fieldName, - fieldObject = fieldObject, - schemaClassPaths = schemaClassPaths + schemaClass, + fieldName, + fieldObject, + schemaClassPaths ) } } @@ -89,10 +89,10 @@ class SchemaGeneration { ) { holder.fields.forEach { (fieldName, fieldObject) -> buildAndAddFieldProperty( - schemaClass = schemaClass, - fieldName = fieldName, - fieldObject = fieldObject, - schemaClassPaths = schemaClassPaths, + schemaClass, + fieldName, + fieldObject, + schemaClassPaths, ) } } From 773debaf8de4c1ad503d349a6ff06c910003e85c Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 20 Mar 2024 16:47:55 +0100 Subject: [PATCH 08/18] updated class documentation --- .../crystalprocessor/generation/model/SchemaGeneration.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt index 27c54afd..40646db3 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -10,13 +10,13 @@ import com.squareup.kotlinpoet.* import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy /** - * This class for generation of the Schema classes. + * This class is responsible for generating the Schema classes. * - * To generate a SchemaClass add the + * To generate a SchemaClass, add the following annotation to your Class: * ``` * @SchemaClass * ``` - * annotation to your Class and all the Fields will be generated into a new File. + * All the fields will then be generated into a new file. */ class SchemaGeneration { private val pathAttributeName = "path" From 6a25bfaf46c4d54911c5a7bd087f364f0d35f63a Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Fri, 22 Mar 2024 14:49:24 +0100 Subject: [PATCH 09/18] made subEntity clearer --- .../crystalprocessor/generation/model/SchemaGeneration.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt index 40646db3..7172d987 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -169,8 +169,8 @@ class SchemaGeneration { } private fun getInnerPropertyType(field: CblBaseFieldHolder): TypeName { - val name: String? = if (field is CblFieldHolder) field.subEntitySimpleName else null + val subEntity = (field as? CblFieldHolder)?.subEntitySimpleName - return TypeUtil.parseMetaType(field.typeMirror, false, name) + return TypeUtil.parseMetaType(field.typeMirror, false, subEntity) } } From 2515d486851fff9dc23ec2ec11ce06102caf881a Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 27 Mar 2024 09:52:38 +0100 Subject: [PATCH 10/18] extracted file for Schema and renamed File to DatabaseRecord --- .../schema/{CMField.kt => DatabaseRecord.kt} | 2 -- .../java/com/schwarz/crystalapi/schema/Schema.kt | 3 +++ .../generation/model/SchemaGeneration.kt | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) rename crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/{CMField.kt => DatabaseRecord.kt} (95%) create mode 100644 crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/Schema.kt diff --git a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMField.kt b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/DatabaseRecord.kt similarity index 95% rename from crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMField.kt rename to crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/DatabaseRecord.kt index a7b56a4b..2453e932 100644 --- a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMField.kt +++ b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/DatabaseRecord.kt @@ -1,7 +1,5 @@ package com.schwarz.crystalapi.schema -interface Schema - interface DatabaseRecord class CMField(val name: String, val path: String) : DatabaseRecord diff --git a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/Schema.kt b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/Schema.kt new file mode 100644 index 00000000..0af7b78f --- /dev/null +++ b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/Schema.kt @@ -0,0 +1,3 @@ +package com.schwarz.crystalapi.schema + +interface Schema diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt index 7172d987..8c57a21c 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -1,13 +1,24 @@ package com.schwarz.crystalprocessor.generation.model -import com.schwarz.crystalapi.schema.* +import com.schwarz.crystalapi.schema.CMField +import com.schwarz.crystalapi.schema.CMList +import com.schwarz.crystalapi.schema.CMObject +import com.schwarz.crystalapi.schema.CMObjectList +import com.schwarz.crystalapi.schema.Schema import com.schwarz.crystalprocessor.model.entity.SchemaClassHolder import com.schwarz.crystalprocessor.model.field.CblBaseFieldHolder import com.schwarz.crystalprocessor.model.field.CblFieldHolder import com.schwarz.crystalprocessor.util.ConversionUtil import com.schwarz.crystalprocessor.util.TypeUtil -import com.squareup.kotlinpoet.* +import com.squareup.kotlinpoet.FileSpec +import com.squareup.kotlinpoet.FunSpec +import com.squareup.kotlinpoet.KModifier +import com.squareup.kotlinpoet.ParameterSpec import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy +import com.squareup.kotlinpoet.PropertySpec +import com.squareup.kotlinpoet.TypeName +import com.squareup.kotlinpoet.TypeSpec +import com.squareup.kotlinpoet.asTypeName /** * This class is responsible for generating the Schema classes. From 88025c1caa24a45ce67948c8f8f22ba32d5c6a60 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Thu, 4 Apr 2024 08:46:57 +0200 Subject: [PATCH 11/18] removed reduced models for SchemaClasses --- .../crystalprocessor/processing/model/ModelWorkSet.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt index feddf724..de66f5cc 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorkSet.kt @@ -75,12 +75,6 @@ class ModelWorkSet( for (element in allSchemaClassElements) { val schemaModel = EntityFactory.createSchemaEntityHolder(SourceModel(element), allSchemaClassPaths, baseModels) schemaModels[element.toString()] = schemaModel - - schemaModel.reducesModels.forEach { - val reduced = EntityFactory.createEntityHolder(ReducedSourceModel(schemaModel.sourceElement, it), allWrapperPaths, baseModels) - reduced.isReduced = true - entityModels[reduced.entitySimpleName] = reduced - } } ModelValidation(logger, baseModels, wrapperModels, entityModels).postValidate() From 7ecefaf98762b5835c74fc6875af88848a7aaac4 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Thu, 4 Apr 2024 09:15:28 +0200 Subject: [PATCH 12/18] renamed to CMType and removed Generic --- .../main/java/com/schwarz/crystalapi/schema/CMType.kt | 11 +++++++++++ .../com/schwarz/crystalapi/schema/DatabaseRecord.kt | 11 ----------- 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt delete mode 100644 crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/DatabaseRecord.kt diff --git a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt new file mode 100644 index 00000000..f231a1ef --- /dev/null +++ b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt @@ -0,0 +1,11 @@ +package com.schwarz.crystalapi.schema + +interface CMType + +class CMField(val name: String, val path: String) : CMType + +class CMList(val name: String, val path: String) : CMType + +class CMObject(val element: T, val path: String) : CMType + +class CMObjectList(val element: T, val name: String, val path: String) : CMType diff --git a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/DatabaseRecord.kt b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/DatabaseRecord.kt deleted file mode 100644 index 2453e932..00000000 --- a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/DatabaseRecord.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.schwarz.crystalapi.schema - -interface DatabaseRecord - -class CMField(val name: String, val path: String) : DatabaseRecord - -class CMList(val name: String, val path: String) : DatabaseRecord - -class CMObject(val element: T, val path: String) : DatabaseRecord - -class CMObjectList(val element: T, val name: String, val path: String) : DatabaseRecord From 5424de4b4ebba5247e599e5b9455273762444b05 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Thu, 4 Apr 2024 09:31:04 +0200 Subject: [PATCH 13/18] moved path into CMType --- .../java/com/schwarz/crystalapi/schema/CMType.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt index f231a1ef..e307d8a6 100644 --- a/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt +++ b/crystal-map-api/src/main/java/com/schwarz/crystalapi/schema/CMType.kt @@ -1,11 +1,13 @@ package com.schwarz.crystalapi.schema -interface CMType +interface CMType { + val path: String +} -class CMField(val name: String, val path: String) : CMType +class CMField(val name: String, override val path: String) : CMType -class CMList(val name: String, val path: String) : CMType +class CMList(val name: String, override val path: String) : CMType -class CMObject(val element: T, val path: String) : CMType +class CMObject(val element: T, override val path: String) : CMType -class CMObjectList(val element: T, val name: String, val path: String) : CMType +class CMObjectList(val element: T, val name: String, override val path: String) : CMType From 44caf9509e3206f557cc3a860666c95af968279c Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Thu, 4 Apr 2024 14:02:13 +0200 Subject: [PATCH 14/18] extended test to assert generated file --- .../CouchbaseBaseBinderProcessorKotlinTest.kt | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt b/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt index 33089cbe..e6e6954f 100644 --- a/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt +++ b/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt @@ -8,6 +8,7 @@ import com.tschuchort.compiletesting.SourceFile import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import org.junit.Assert import org.junit.Test +import java.io.File @OptIn(ExperimentalCompilerApi::class) class CouchbaseBaseBinderProcessorKotlinTest { @@ -169,24 +170,40 @@ class CouchbaseBaseBinderProcessorKotlinTest { } @Test - fun testKotlinFieldsGeneration() { - val subSchema = SourceFile.kotlin( + fun testKotlinSchemaGeneration() { + val expected = File("src\\test\\resources\\ExpectedSchema.txt").readLines() + val testObject = SourceFile.kotlin( + "TestObject.kt", + "package com.kaufland.testModels\n" + + "import com.schwarz.crystalapi.Field\n" + + "import com.schwarz.crystalapi.Fields\n" + + "import com.schwarz.crystalapi.SchemaClass\n" + + "@SchemaClass\n" + + "class TestObject" + ) + val sub = SourceFile.kotlin( "Sub.kt", "package com.kaufland.testModels\n" + + "import com.kaufland.testModels.TestObject\n" + "import com.schwarz.crystalapi.Field\n" + "import com.schwarz.crystalapi.Fields\n" + "import com.schwarz.crystalapi.SchemaClass\n" + "@SchemaClass\n" + "@Fields(\n" + "Field(name = \"test_test_test\", type = Number::class),\n" + - "Field(name = \"type\", type = String::class, defaultValue = \"test\", readonly = true)\n" + + "Field(name = \"type\", type = String::class, defaultValue = \"test\", readonly = true),\n" + + "Field(name = \"list\", type = String::class, list = true),\n" + + "Field(name = \"someObject\", type = TestObject::class),\n" + + "Field(name = \"objects\", type = TestObject::class, list = true),\n" + ")\n" + "class Sub" ) + val compilation = compileKotlin(testObject, sub) - val compilation = compileKotlin(subSchema) + val actual = compilation.generatedFiles.find { it.name == "SubSchema.kt" }!!.readLines() Assert.assertEquals(KotlinCompilation.ExitCode.OK, compilation.exitCode) + Assert.assertEquals(expected, actual) } @Test From 0594fa4f70368a6dfdb792b1aa2bcf2caa6a44df Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Thu, 4 Apr 2024 14:21:52 +0200 Subject: [PATCH 15/18] add ExpectedSchema File for testing --- .../src/test/resources/ExpectedSchema.txt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 crystal-map-processor/src/test/resources/ExpectedSchema.txt diff --git a/crystal-map-processor/src/test/resources/ExpectedSchema.txt b/crystal-map-processor/src/test/resources/ExpectedSchema.txt new file mode 100644 index 00000000..5e0eb2d7 --- /dev/null +++ b/crystal-map-processor/src/test/resources/ExpectedSchema.txt @@ -0,0 +1,39 @@ +// DO NOT EDIT THIS FILE. +// Generated using Crystal-Map +// +// Do not edit this class!!!!. +// +package com.kaufland.testModels + +import com.schwarz.crystalapi.schema.CMField +import com.schwarz.crystalapi.schema.CMList +import com.schwarz.crystalapi.schema.CMObject +import com.schwarz.crystalapi.schema.CMObjectList +import com.schwarz.crystalapi.schema.Schema +import kotlin.Number +import kotlin.String + +open class SubSchema( + path: String = "" +) : Schema { + val DEFAULT_TYPE: String = "test" + + val type: CMField = CMField("type", path) + + val test_test_test: CMField = CMField("test_test_test", path) + + val list: CMList = CMList("list", path) + + val someObject: CMObject = CMObject( + com.kaufland.testModels.TestObjectSchema(if (path.isBlank()) "someObject" else + "$path.someObject"), + path, + ) + + val objects: CMObjectList = CMObjectList( + com.kaufland.testModels.TestObjectSchema(if (path.isBlank()) "objects" else + "$path.objects"), + "objects", + path, + ) +} \ No newline at end of file From ee0162bb2c5d4cb9e1fb330ff08fd27c06190e76 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 10 Apr 2024 08:44:39 +0200 Subject: [PATCH 16/18] fixed linter --- .../CoachBaseBinderProcessor.kt | 15 ++++++-- .../generation/model/SchemaGeneration.kt | 10 +++--- .../crystalprocessor/model/EntityFactory.kt | 12 +++---- .../model/entity/SchemaClassHolder.kt | 2 +- .../processing/model/ModelWorker.kt | 6 ++-- .../CouchbaseBaseBinderProcessorKotlinTest.kt | 36 +++++++++---------- 6 files changed, 47 insertions(+), 34 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/CoachBaseBinderProcessor.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/CoachBaseBinderProcessor.kt index 1965d1ca..dcf6ad02 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/CoachBaseBinderProcessor.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/CoachBaseBinderProcessor.kt @@ -1,7 +1,13 @@ package com.schwarz.crystalprocessor import com.google.auto.service.AutoService -import com.schwarz.crystalapi.* +import com.schwarz.crystalapi.Entity +import com.schwarz.crystalapi.Field +import com.schwarz.crystalapi.GenerateAccessor +import com.schwarz.crystalapi.MapWrapper +import com.schwarz.crystalapi.Reduce +import com.schwarz.crystalapi.Reduces +import com.schwarz.crystalapi.SchemaClass import com.schwarz.crystalapi.mapify.Mapper import com.schwarz.crystalapi.query.Queries import com.schwarz.crystalapi.query.Query @@ -15,7 +21,12 @@ import com.schwarz.crystalprocessor.generation.CodeGenerator import com.schwarz.crystalprocessor.processing.Worker import com.schwarz.crystalprocessor.processing.mapper.MapperWorker import com.schwarz.crystalprocessor.processing.model.ModelWorker -import javax.annotation.processing.* +import javax.annotation.processing.AbstractProcessor +import javax.annotation.processing.ProcessingEnvironment +import javax.annotation.processing.Processor +import javax.annotation.processing.RoundEnvironment +import javax.annotation.processing.SupportedOptions +import javax.annotation.processing.SupportedSourceVersion import javax.lang.model.SourceVersion import javax.lang.model.element.TypeElement diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt index 8c57a21c..a3b803d5 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/generation/model/SchemaGeneration.kt @@ -58,7 +58,7 @@ class SchemaGeneration { private fun buildAndAddFieldProperties( holder: SchemaClassHolder, schemaClass: TypeSpec.Builder, - schemaClassPaths: List, + schemaClassPaths: List ) { buildAndAddConstantFieldProperties(holder, schemaClass, schemaClassPaths) buildAndAddNormalFieldProperties(holder, schemaClass, schemaClassPaths) @@ -103,7 +103,7 @@ class SchemaGeneration { schemaClass, fieldName, fieldObject, - schemaClassPaths, + schemaClassPaths ) } } @@ -112,7 +112,7 @@ class SchemaGeneration { schemaClass: TypeSpec.Builder, fieldName: String, fieldObject: CblBaseFieldHolder, - schemaClassPaths: List, + schemaClassPaths: List ): TypeSpec.Builder = schemaClass.addProperty( buildFieldProperty(fieldObject, fieldName, schemaClassPaths) ) @@ -120,7 +120,7 @@ class SchemaGeneration { private fun buildFieldProperty( fieldObject: CblBaseFieldHolder, fieldName: String, - schemaClassPaths: List, + schemaClassPaths: List ): PropertySpec { val isObject = schemaClassPaths.contains(fieldObject.typeMirror.toString()) @@ -133,7 +133,7 @@ class SchemaGeneration { outerType.parameterizedBy(innerType) ).initializer( createPropertyFormat(fieldName, innerType, fieldObject.isIterable, isObject), - outerType, + outerType ).build() } diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt index d8e3ef4e..adee8697 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/EntityFactory.kt @@ -32,11 +32,11 @@ object EntityFactory { annotation.database, annotation.modifierOpen, annotation.type, - sourceModel, + sourceModel ), allWrapperPaths, allBaseModels, - WRAPPER_SUB_ENTITY_SUFFIX, + WRAPPER_SUB_ENTITY_SUFFIX ) as EntityHolder } @@ -49,7 +49,7 @@ object EntityFactory { BaseModelHolder(sourceModel), allWrapperPaths, emptyMap(), - WRAPPER_SUB_ENTITY_SUFFIX, + WRAPPER_SUB_ENTITY_SUFFIX ) as BaseModelHolder } @@ -64,7 +64,7 @@ object EntityFactory { WrapperEntityHolder(annotation.modifierOpen, sourceModel), allWrapperPaths, allBaseModels, - WRAPPER_SUB_ENTITY_SUFFIX, + WRAPPER_SUB_ENTITY_SUFFIX ) as WrapperEntityHolder } @@ -77,7 +77,7 @@ object EntityFactory { SchemaClassHolder(sourceModel), allSchemaClassPaths, allBaseModels, - SCHEMA_SUB_ENTITY_SUFFIX, + SCHEMA_SUB_ENTITY_SUFFIX ) as SchemaClassHolder private fun create( @@ -85,7 +85,7 @@ object EntityFactory { content: BaseEntityHolder, classPaths: List, allBaseModels: Map, - subEntityNameSuffix: String, + subEntityNameSuffix: String ): BaseEntityHolder { content.reducesModels = createReduceModels(sourceModel, content) content.abstractParts = sourceModel.abstractParts diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/entity/SchemaClassHolder.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/entity/SchemaClassHolder.kt index ee999cf8..7c6339d2 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/entity/SchemaClassHolder.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/model/entity/SchemaClassHolder.kt @@ -6,4 +6,4 @@ class SchemaClassHolder(sourceModel: ISourceModel) : BaseEntityHolder(sourceMode override val entitySimpleName: String get() = sourceClazzSimpleName + "Schema" -} \ No newline at end of file +} diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt index f6ed39a6..46952623 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt @@ -61,8 +61,10 @@ class ModelWorker(override val logger: Logger, override val codeGenerator: CodeG WrapperGeneration().generateModel(it, useSuspend) } - process(workSet.schemas, generatedInterfaces, useSuspend) { - SchemaGeneration().generateModel(it, workSet.schemaClassPaths) + if (processingEnv.options?.getOrDefault(CoachBaseBinderProcessor.FRAMEWORK_GENERATE_SCHEMAS, "true")?.toBoolean() == true) { + process(workSet.schemas, generatedInterfaces, useSuspend) { + SchemaGeneration().generateModel(it, workSet.schemaClassPaths) + } } documentationGenerator?.generate() diff --git a/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt b/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt index e6e6954f..2523b516 100644 --- a/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt +++ b/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt @@ -175,28 +175,28 @@ class CouchbaseBaseBinderProcessorKotlinTest { val testObject = SourceFile.kotlin( "TestObject.kt", "package com.kaufland.testModels\n" + - "import com.schwarz.crystalapi.Field\n" + - "import com.schwarz.crystalapi.Fields\n" + - "import com.schwarz.crystalapi.SchemaClass\n" + - "@SchemaClass\n" + - "class TestObject" + "import com.schwarz.crystalapi.Field\n" + + "import com.schwarz.crystalapi.Fields\n" + + "import com.schwarz.crystalapi.SchemaClass\n" + + "@SchemaClass\n" + + "class TestObject" ) val sub = SourceFile.kotlin( "Sub.kt", "package com.kaufland.testModels\n" + - "import com.kaufland.testModels.TestObject\n" + - "import com.schwarz.crystalapi.Field\n" + - "import com.schwarz.crystalapi.Fields\n" + - "import com.schwarz.crystalapi.SchemaClass\n" + - "@SchemaClass\n" + - "@Fields(\n" + - "Field(name = \"test_test_test\", type = Number::class),\n" + - "Field(name = \"type\", type = String::class, defaultValue = \"test\", readonly = true),\n" + - "Field(name = \"list\", type = String::class, list = true),\n" + - "Field(name = \"someObject\", type = TestObject::class),\n" + - "Field(name = \"objects\", type = TestObject::class, list = true),\n" + - ")\n" + - "class Sub" + "import com.kaufland.testModels.TestObject\n" + + "import com.schwarz.crystalapi.Field\n" + + "import com.schwarz.crystalapi.Fields\n" + + "import com.schwarz.crystalapi.SchemaClass\n" + + "@SchemaClass\n" + + "@Fields(\n" + + "Field(name = \"test_test_test\", type = Number::class),\n" + + "Field(name = \"type\", type = String::class, defaultValue = \"test\", readonly = true),\n" + + "Field(name = \"list\", type = String::class, list = true),\n" + + "Field(name = \"someObject\", type = TestObject::class),\n" + + "Field(name = \"objects\", type = TestObject::class, list = true),\n" + + ")\n" + + "class Sub" ) val compilation = compileKotlin(testObject, sub) From c70859b1e9e5091fdea110609e5b5e6863daa0ea Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 10 Apr 2024 09:07:49 +0200 Subject: [PATCH 17/18] fixed unresolved --- .../crystalprocessor/processing/model/ModelWorker.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt index 46952623..f6ed39a6 100644 --- a/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt +++ b/crystal-map-processor/src/main/java/com/schwarz/crystalprocessor/processing/model/ModelWorker.kt @@ -61,10 +61,8 @@ class ModelWorker(override val logger: Logger, override val codeGenerator: CodeG WrapperGeneration().generateModel(it, useSuspend) } - if (processingEnv.options?.getOrDefault(CoachBaseBinderProcessor.FRAMEWORK_GENERATE_SCHEMAS, "true")?.toBoolean() == true) { - process(workSet.schemas, generatedInterfaces, useSuspend) { - SchemaGeneration().generateModel(it, workSet.schemaClassPaths) - } + process(workSet.schemas, generatedInterfaces, useSuspend) { + SchemaGeneration().generateModel(it, workSet.schemaClassPaths) } documentationGenerator?.generate() From 1e8b16fdee94d2a462e590c4121d5be398edda4f Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Wed, 10 Apr 2024 09:28:56 +0200 Subject: [PATCH 18/18] fixed path --- .../java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt b/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt index 2523b516..cbbc7857 100644 --- a/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt +++ b/crystal-map-processor/src/test/java/com/schwarz/CouchbaseBaseBinderProcessorKotlinTest.kt @@ -171,7 +171,7 @@ class CouchbaseBaseBinderProcessorKotlinTest { @Test fun testKotlinSchemaGeneration() { - val expected = File("src\\test\\resources\\ExpectedSchema.txt").readLines() + val expected = File("src/test/resources/ExpectedSchema.txt").readLines() val testObject = SourceFile.kotlin( "TestObject.kt", "package com.kaufland.testModels\n" +