Skip to content

Commit

Permalink
renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
jansigi committed Aug 13, 2024
1 parent d08a73c commit f303054
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ sealed interface CMType {
val path: String
}

open class CMField<T>(val name: String, override val path: String) : CMType
open class CMJsonField<T>(val name: String, override val path: String) : CMType

open class CMList<T>(val name: String, override val path: String) : CMType
open class CMJsonList<T>(val name: String, override val path: String) : CMType

class CMObject<out T : Schema>(val element: T, override val path: String) : CMType

Expand All @@ -18,10 +18,10 @@ class CMConverterField<KotlinType, MapType>(
name: String,
path: String,
val typeConverter: ITypeConverter<KotlinType, MapType>
) : CMField<MapType>(name, path)
) : CMJsonField<MapType>(name, path)

class CMConverterList<KotlinType, MapType>(
name: String,
path: String,
val typeConverter: ITypeConverter<KotlinType, MapType>
) : CMList<MapType>(name, path)
) : CMJsonList<MapType>(name, path)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
}
Expand All @@ -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()
}
Expand All @@ -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()
}

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions crystal-map-processor/src/test/resources/ExpectedSchema.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,11 +21,11 @@ public open class SubSchema(
) : Schema {
public val DEFAULT_TYPE: String = "test"

public val type: CMField<String> = CMField("type", path)
public val type: CMJsonField<String> = CMJsonField("type", path)

public val testTestTest: CMField<Number> = CMField("test_test_test", path)
public val testTestTest: CMJsonField<Number> = CMJsonField("test_test_test", path)

public val list: CMList<String> = CMList("list", path)
public val list: CMJsonList<String> = CMJsonList("list", path)

public val someObject: CMObject<TestObjectSchema> = CMObject(
com.kaufland.testModels.TestObjectSchema(if (path.isBlank()) "someObject" else
Expand Down

0 comments on commit f303054

Please sign in to comment.