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 2052c0f..51d16a5 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 @@ -6,9 +6,9 @@ sealed interface CMType { val path: String } -open class CMField(val name: String, override val path: String) : CMType +open class CMJsonField(val name: String, override val path: String) : CMType -open class CMList(val name: String, override val path: String) : CMType +open class CMJsonList(val name: String, override val path: String) : CMType class CMObject(val element: T, override val path: String) : CMType @@ -18,10 +18,10 @@ class CMConverterField( name: String, path: String, val typeConverter: ITypeConverter -) : CMField(name, path) +) : CMJsonField(name, path) class CMConverterList( name: String, path: String, val typeConverter: ITypeConverter -) : CMList(name, path) +) : CMJsonList(name, path) 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 95052f7..8402976 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 @@ -117,12 +117,12 @@ class SchemaGeneration { val propertyType = typeConvertersByConvertedClass[fieldObject.typeMirror.asTypeName()] val isObject = schemaClassPaths.contains(fieldObject.typeMirror.toString()) val hasProperty = propertyType != null - val outerType = getOuterPropertyType(fieldObject.isIterable, isObject, hasProperty) + val fieldType = getFieldType(fieldObject.isIterable, isObject, hasProperty) return schemaClass.addProperty( if (propertyType != null) { - buildConverterFieldProperty(fieldObject, fieldName, propertyType, outerType) + buildConverterFieldProperty(fieldObject, fieldName, propertyType, fieldType) } else { - buildFieldProperty(fieldObject, fieldName, outerType, isObject) + buildFieldProperty(fieldObject, fieldName, fieldType, isObject) } ) } @@ -133,13 +133,13 @@ class SchemaGeneration { outerType: ClassName, isObject: Boolean ): PropertySpec { - val innerType: TypeName = getInnerPropertyType(fieldObject) + val genericFieldType = getGenericFieldType(fieldObject) return PropertySpec.builder( fieldObject.accessorSuffix(), - outerType.parameterizedBy(innerType) + outerType.parameterizedBy(genericFieldType) ).initializer( - createPropertyFormat(fieldName, innerType, fieldObject.isIterable, isObject), + createPropertyFormat(fieldName, genericFieldType, fieldObject.isIterable, isObject), outerType ).build() } @@ -148,14 +148,14 @@ class SchemaGeneration { fieldObject: CblBaseFieldHolder, fieldName: String, propertyType: TypeConverterHolderForEntityGeneration, - outerType: ClassName + fieldType: ClassName ): PropertySpec { return PropertySpec.builder( fieldObject.accessorSuffix(), - outerType.parameterizedBy(propertyType.domainClassTypeName, propertyType.mapClassTypeName) + fieldType.parameterizedBy(propertyType.domainClassTypeName, propertyType.mapClassTypeName) ).initializer( buildConverterFormat(fieldName, propertyType), - outerType + fieldType ).build() } @@ -194,20 +194,20 @@ class SchemaGeneration { $pathAttributeName, )""" - private fun getOuterPropertyType( + private fun getFieldType( isIterable: Boolean, isObject: Boolean, hasProperty: Boolean ) = when { - hasProperty && isIterable-> CMConverterList::class.asTypeName() + hasProperty && isIterable -> CMConverterList::class.asTypeName() hasProperty -> CMConverterField::class.asTypeName() isIterable && isObject -> CMObjectList::class.asTypeName() - isIterable -> CMList::class.asTypeName() + isIterable -> CMJsonList::class.asTypeName() isObject -> CMObject::class.asTypeName() - else -> CMField::class.asTypeName() + else -> CMJsonField::class.asTypeName() } - private fun getInnerPropertyType(field: CblBaseFieldHolder): TypeName { + private fun getGenericFieldType(field: CblBaseFieldHolder): TypeName { val subEntity = (field as? CblFieldHolder)?.subEntitySimpleName return TypeUtil.parseMetaType(field.typeMirror, false, subEntity) diff --git a/crystal-map-processor/src/test/resources/ExpectedSchema.txt b/crystal-map-processor/src/test/resources/ExpectedSchema.txt index 3e697b1..484dd5f 100644 --- a/crystal-map-processor/src/test/resources/ExpectedSchema.txt +++ b/crystal-map-processor/src/test/resources/ExpectedSchema.txt @@ -7,8 +7,8 @@ package com.kaufland.testModels import com.schwarz.crystalapi.schema.CMConverterField import com.schwarz.crystalapi.schema.CMConverterList -import com.schwarz.crystalapi.schema.CMField -import com.schwarz.crystalapi.schema.CMList +import com.schwarz.crystalapi.schema.CMJsonField +import com.schwarz.crystalapi.schema.CMJsonList import com.schwarz.crystalapi.schema.CMObject import com.schwarz.crystalapi.schema.CMObjectList import com.schwarz.crystalapi.schema.Schema @@ -21,11 +21,11 @@ public open class SubSchema( ) : Schema { public val DEFAULT_TYPE: String = "test" - public val type: CMField = CMField("type", path) + public val type: CMJsonField = CMJsonField("type", path) - public val testTestTest: CMField = CMField("test_test_test", path) + public val testTestTest: CMJsonField = CMJsonField("test_test_test", path) - public val list: CMList = CMList("list", path) + public val list: CMJsonList = CMJsonList("list", path) public val someObject: CMObject = CMObject( com.kaufland.testModels.TestObjectSchema(if (path.isBlank()) "someObject" else