Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicate classes #697

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,31 @@ import godot.tools.common.constants.GODOT_CALLABLE
import godot.tools.common.constants.GODOT_CALLABLE_BASE
import godot.tools.common.constants.GODOT_DICTIONARY
import godot.tools.common.constants.GODOT_ERROR
import godot.tools.common.constants.GODOT_VARIANT_TYPE
import godot.tools.common.constants.GodotKotlinJvmTypes
import godot.tools.common.constants.GodotTypes
import godot.tools.common.constants.VARIANT_TYPE_ANY
import godot.tools.common.constants.VARIANT_TYPE_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_BOOL
import godot.tools.common.constants.VARIANT_TYPE_DOUBLE
import godot.tools.common.constants.VARIANT_TYPE_LONG
import godot.tools.common.constants.VARIANT_TYPE_NIL
import godot.tools.common.constants.VARIANT_TYPE_NODE_PATH
import godot.tools.common.constants.VARIANT_TYPE_OBJECT
import godot.tools.common.constants.VARIANT_TYPE_PACKED_BYTE_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_COLOR_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_FLOAT_32_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_FLOAT_64_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_INT_32_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_INT_64_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_STRING_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_VECTOR2_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_VECTOR3_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_STRING_NAME
import godot.tools.common.constants.VARIANT_TYPE__RID
import godot.tools.common.constants.VARIANT_CASTER_ANY
import godot.tools.common.constants.VARIANT_PARSER_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_BOOL
import godot.tools.common.constants.VARIANT_PARSER_DOUBLE
import godot.tools.common.constants.VARIANT_PARSER_LONG
import godot.tools.common.constants.VARIANT_PARSER_NIL
import godot.tools.common.constants.VARIANT_PARSER_NODE_PATH
import godot.tools.common.constants.VARIANT_PARSER_OBJECT
import godot.tools.common.constants.VARIANT_PARSER_PACKED_BYTE_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_COLOR_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_FLOAT_32_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_FLOAT_64_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_INT_32_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_INT_64_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_STRING_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_VECTOR2_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_VECTOR3_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_STRING_NAME
import godot.tools.common.constants.VARIANT_PARSER__RID
import godot.tools.common.constants.godotApiPackage
import godot.tools.common.constants.godotCorePackage
import godot.tools.common.constants.variantTypePackage
import godot.tools.common.constants.variantParserPackage
import java.util.*

const val enumPrefix = "enum::"
Expand Down Expand Up @@ -76,12 +77,7 @@ fun TypedTrait.getTypeClassName(): ClassTypeNameWrapper {
isEnum() -> {
val enumType = type!!.removePrefix(enumPrefix)
if (enumType == GodotTypes.variantType) {
ClassTypeNameWrapper(
ClassName(
godotCorePackage,
GodotKotlinJvmTypes.variantType
)
)
ClassTypeNameWrapper(GODOT_VARIANT_TYPE)
} else {
val containerAndEnum = enumType.split('.')
val packageName = object : TypedTrait {
Expand Down Expand Up @@ -143,28 +139,28 @@ fun TypedTrait.isObjectSubClass() = !(type.isNullOrEmpty() || isEnum() || isPrim
val TypedTrait.jvmVariantTypeValue: ClassName
get() {
return when {
type.isNullOrEmpty() -> VARIANT_TYPE_NIL
isEnum() -> VARIANT_TYPE_LONG
isBitField() -> VARIANT_TYPE_LONG
type == GodotTypes.bool -> VARIANT_TYPE_BOOL
type == GodotTypes.int -> VARIANT_TYPE_LONG
type == GodotTypes.float -> VARIANT_TYPE_DOUBLE
type == GodotTypes.nodePath -> VARIANT_TYPE_NODE_PATH
type == GodotTypes.stringName -> VARIANT_TYPE_STRING_NAME
type == GodotTypes.rid -> VARIANT_TYPE__RID
type == GodotTypes.array || isTypedArray() -> VARIANT_TYPE_ARRAY
type == GodotTypes.packedByteArray -> VARIANT_TYPE_PACKED_BYTE_ARRAY
type == GodotTypes.packedInt32Array -> VARIANT_TYPE_PACKED_INT_32_ARRAY
type == GodotTypes.packedInt64Array -> VARIANT_TYPE_PACKED_INT_64_ARRAY
type == GodotTypes.packedFloat32Array -> VARIANT_TYPE_PACKED_FLOAT_32_ARRAY
type == GodotTypes.packedFloat64Array -> VARIANT_TYPE_PACKED_FLOAT_64_ARRAY
type == GodotTypes.packedStringArray -> VARIANT_TYPE_PACKED_STRING_ARRAY
type == GodotTypes.packedVector2Array -> VARIANT_TYPE_PACKED_VECTOR2_ARRAY
type == GodotTypes.packedVector3Array -> VARIANT_TYPE_PACKED_VECTOR3_ARRAY
type == GodotTypes.packedColorArray -> VARIANT_TYPE_PACKED_COLOR_ARRAY
type == GodotTypes.variant -> VARIANT_TYPE_ANY
isCoreType() || isPrimitive() -> ClassName(variantTypePackage, type!!.uppercase(Locale.US))
else -> VARIANT_TYPE_OBJECT
type.isNullOrEmpty() -> VARIANT_PARSER_NIL
isEnum() -> VARIANT_PARSER_LONG
isBitField() -> VARIANT_PARSER_LONG
type == GodotTypes.bool -> VARIANT_PARSER_BOOL
type == GodotTypes.int -> VARIANT_PARSER_LONG
type == GodotTypes.float -> VARIANT_PARSER_DOUBLE
type == GodotTypes.nodePath -> VARIANT_PARSER_NODE_PATH
type == GodotTypes.stringName -> VARIANT_PARSER_STRING_NAME
type == GodotTypes.rid -> VARIANT_PARSER__RID
type == GodotTypes.array || isTypedArray() -> VARIANT_PARSER_ARRAY
type == GodotTypes.packedByteArray -> VARIANT_PARSER_PACKED_BYTE_ARRAY
type == GodotTypes.packedInt32Array -> VARIANT_PARSER_PACKED_INT_32_ARRAY
type == GodotTypes.packedInt64Array -> VARIANT_PARSER_PACKED_INT_64_ARRAY
type == GodotTypes.packedFloat32Array -> VARIANT_PARSER_PACKED_FLOAT_32_ARRAY
type == GodotTypes.packedFloat64Array -> VARIANT_PARSER_PACKED_FLOAT_64_ARRAY
type == GodotTypes.packedStringArray -> VARIANT_PARSER_PACKED_STRING_ARRAY
type == GodotTypes.packedVector2Array -> VARIANT_PARSER_PACKED_VECTOR2_ARRAY
type == GodotTypes.packedVector3Array -> VARIANT_PARSER_PACKED_VECTOR3_ARRAY
type == GodotTypes.packedColorArray -> VARIANT_PARSER_PACKED_COLOR_ARRAY
type == GodotTypes.variant -> VARIANT_CASTER_ANY
isCoreType() || isPrimitive() -> ClassName(variantParserPackage, type!!.uppercase(Locale.US))
else -> VARIANT_PARSER_OBJECT
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ import godot.tools.common.constants.GodotTypes
import godot.tools.common.constants.KT_OBJECT
import godot.tools.common.constants.TRANSFER_CONTEXT
import godot.tools.common.constants.TYPE_MANAGER
import godot.tools.common.constants.VARIANT_TYPE_ANY
import godot.tools.common.constants.VARIANT_TYPE_LONG
import godot.tools.common.constants.VARIANT_CASTER_ANY
import godot.tools.common.constants.VARIANT_PARSER_LONG
import godot.tools.common.constants.godotApiPackage
import godot.tools.common.constants.godotCorePackage
import java.util.*
Expand Down Expand Up @@ -829,7 +829,7 @@ class GenerationService(
"%T.writeArguments($callArgumentsAsString·*__var_args.map·{·%T·to·it·}.toTypedArray())",
TRANSFER_CONTEXT,
*ktVariantClassNames,
VARIANT_TYPE_ANY
VARIANT_CASTER_ANY
)
} else {
addStatement(
Expand Down Expand Up @@ -862,7 +862,7 @@ class GenerationService(
addStatement(
"return·${methodReturnType.className.simpleNames.joinToString(".")}.from(%T.readReturnValue(%T)·as·%T)",
TRANSFER_CONTEXT,
VARIANT_TYPE_LONG,
VARIANT_PARSER_LONG,
LONG
)
} else if (callable.isBitField()) {
Expand All @@ -874,7 +874,7 @@ class GenerationService(
"${callable.getTypeClassName().className.simpleName}Value"
),
TRANSFER_CONTEXT,
VARIANT_TYPE_LONG,
VARIANT_PARSER_LONG,
LONG
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.squareup.kotlinpoet.TypeVariableName
import godot.codegen.services.IKtCallableGenerationService
import godot.tools.common.constants.GodotFunctions
import godot.tools.common.constants.GodotKotlinJvmTypes
import godot.tools.common.constants.VARIANT_TYPE_NIL
import godot.tools.common.constants.VARIANT_PARSER_NIL
import godot.tools.common.constants.godotCorePackage

class KtCallableGenerationService : IKtCallableGenerationService {
Expand Down Expand Up @@ -293,7 +293,7 @@ class KtCallableGenerationService : IKtCallableGenerationService {
},
variantMapperMember,
returnTypeParameter,
VARIANT_TYPE_NIL,
VARIANT_PARSER_NIL,
*typeVariableNames
.flatMap {
listOf(variantMapperMember, it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,78 @@ import com.squareup.kotlinpoet.TypeName
import godot.entrygenerator.model.Type
import godot.tools.common.constants.GodotKotlinJvmTypes
import godot.tools.common.constants.GodotTypes
import godot.tools.common.constants.VARIANT_CASTER_ANY
import godot.tools.common.constants.VARIANT_CASTER_BYTE
import godot.tools.common.constants.VARIANT_CASTER_FLOAT
import godot.tools.common.constants.VARIANT_CASTER_INT
import godot.tools.common.constants.VARIANT_TYPE_AABB
import godot.tools.common.constants.VARIANT_TYPE_ANY
import godot.tools.common.constants.VARIANT_TYPE_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_BOOL
import godot.tools.common.constants.VARIANT_TYPE_DOUBLE
import godot.tools.common.constants.VARIANT_TYPE_LONG
import godot.tools.common.constants.VARIANT_TYPE_NIL
import godot.tools.common.constants.VARIANT_TYPE_NODE_PATH
import godot.tools.common.constants.VARIANT_TYPE_OBJECT
import godot.tools.common.constants.VARIANT_TYPE_PACKED_BYTE_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_CALLABLE
import godot.tools.common.constants.VARIANT_TYPE_PACKED_COLOR_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_FLOAT_32_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_FLOAT_64_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_INT_32_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_INT_64_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_STRING_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_VECTOR2_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_PACKED_VECTOR3_ARRAY
import godot.tools.common.constants.VARIANT_TYPE_STRING
import godot.tools.common.constants.VARIANT_TYPE_STRING_NAME
import godot.tools.common.constants.VARIANT_TYPE_TRANSFORM2D
import godot.tools.common.constants.VARIANT_TYPE_TRANSFORM3D
import godot.tools.common.constants.VARIANT_TYPE__RID
import godot.tools.common.constants.VARIANT_PARSER_AABB
import godot.tools.common.constants.VARIANT_PARSER_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_BOOL
import godot.tools.common.constants.VARIANT_PARSER_DOUBLE
import godot.tools.common.constants.VARIANT_PARSER_LONG
import godot.tools.common.constants.VARIANT_PARSER_NIL
import godot.tools.common.constants.VARIANT_PARSER_NODE_PATH
import godot.tools.common.constants.VARIANT_PARSER_OBJECT
import godot.tools.common.constants.VARIANT_PARSER_PACKED_BYTE_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_CALLABLE
import godot.tools.common.constants.VARIANT_PARSER_PACKED_COLOR_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_FLOAT_32_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_FLOAT_64_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_INT_32_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_INT_64_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_STRING_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_VECTOR2_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_PACKED_VECTOR3_ARRAY
import godot.tools.common.constants.VARIANT_PARSER_STRING
import godot.tools.common.constants.VARIANT_PARSER_STRING_NAME
import godot.tools.common.constants.VARIANT_PARSER_TRANSFORM2D
import godot.tools.common.constants.VARIANT_PARSER_TRANSFORM3D
import godot.tools.common.constants.VARIANT_PARSER__RID
import godot.tools.common.constants.godotApiPackage
import godot.tools.common.constants.godotCorePackage
import godot.tools.common.constants.godotUtilPackage
import godot.tools.common.constants.variantTypePackage
import godot.tools.common.constants.variantParserPackage
import godot.tools.common.extensions.convertToCamelCase
import java.util.*

//TODO: make compatible with other languages
fun Type?.toKtVariantType(): ClassName = when {
this == null || fqName == Unit::class.qualifiedName -> VARIANT_TYPE_NIL
this == null || fqName == Unit::class.qualifiedName -> VARIANT_PARSER_NIL
fqName == Byte::class.qualifiedName -> VARIANT_CASTER_BYTE
fqName == Int::class.qualifiedName -> VARIANT_CASTER_INT
fqName == "$godotUtilPackage.${GodotKotlinJvmTypes.naturalT}" ||
fqName == Long::class.qualifiedName -> VARIANT_TYPE_LONG
fqName == Long::class.qualifiedName -> VARIANT_PARSER_LONG

fqName == Float::class.qualifiedName -> VARIANT_CASTER_FLOAT
fqName == "$godotUtilPackage.${GodotKotlinJvmTypes.realT}" ||
fqName == Double::class.qualifiedName -> VARIANT_TYPE_DOUBLE

fqName == String::class.qualifiedName -> VARIANT_TYPE_STRING
fqName == Boolean::class.qualifiedName -> VARIANT_TYPE_BOOL
fqName == "$godotCorePackage.${GodotKotlinJvmTypes.variantArray}" -> VARIANT_TYPE_ARRAY
fqName == "$godotCorePackage.${GodotTypes.stringName}" -> VARIANT_TYPE_STRING_NAME
fqName == "$godotCorePackage.${GodotTypes.rid}" -> VARIANT_TYPE__RID
fqName == "$godotCorePackage.${GodotTypes.aabb}" -> VARIANT_TYPE_AABB
fqName == "$godotCorePackage.${GodotTypes.nodePath}" -> VARIANT_TYPE_NODE_PATH
fqName == "$godotCorePackage.${GodotTypes.transform2D}" -> VARIANT_TYPE_TRANSFORM2D
fqName == "$godotCorePackage.${GodotTypes.transform3D}" -> VARIANT_TYPE_TRANSFORM3D
fqName == "$godotCorePackage.${GodotTypes.packedByteArray}" -> VARIANT_TYPE_PACKED_BYTE_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedInt32Array}" -> VARIANT_TYPE_PACKED_INT_32_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedInt64Array}" -> VARIANT_TYPE_PACKED_INT_64_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedFloat32Array}" -> VARIANT_TYPE_PACKED_FLOAT_32_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedFloat64Array}" -> VARIANT_TYPE_PACKED_FLOAT_64_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedStringArray}" -> VARIANT_TYPE_PACKED_STRING_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedVector2Array}" -> VARIANT_TYPE_PACKED_VECTOR2_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedVector3Array}" -> VARIANT_TYPE_PACKED_VECTOR3_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedColorArray}" -> VARIANT_TYPE_PACKED_COLOR_ARRAY
fqName.startsWith("$godotCorePackage.${GodotTypes.ktCallable}") -> VARIANT_TYPE_PACKED_CALLABLE
fqName == Double::class.qualifiedName -> VARIANT_PARSER_DOUBLE

fqName == String::class.qualifiedName -> VARIANT_PARSER_STRING
fqName == Boolean::class.qualifiedName -> VARIANT_PARSER_BOOL
fqName == "$godotCorePackage.${GodotKotlinJvmTypes.variantArray}" -> VARIANT_PARSER_ARRAY
fqName == "$godotCorePackage.${GodotTypes.stringName}" -> VARIANT_PARSER_STRING_NAME
fqName == "$godotCorePackage.${GodotTypes.rid}" -> VARIANT_PARSER__RID
fqName == "$godotCorePackage.${GodotTypes.aabb}" -> VARIANT_PARSER_AABB
fqName == "$godotCorePackage.${GodotTypes.nodePath}" -> VARIANT_PARSER_NODE_PATH
fqName == "$godotCorePackage.${GodotTypes.transform2D}" -> VARIANT_PARSER_TRANSFORM2D
fqName == "$godotCorePackage.${GodotTypes.transform3D}" -> VARIANT_PARSER_TRANSFORM3D
fqName == "$godotCorePackage.${GodotTypes.packedByteArray}" -> VARIANT_PARSER_PACKED_BYTE_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedInt32Array}" -> VARIANT_PARSER_PACKED_INT_32_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedInt64Array}" -> VARIANT_PARSER_PACKED_INT_64_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedFloat32Array}" -> VARIANT_PARSER_PACKED_FLOAT_32_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedFloat64Array}" -> VARIANT_PARSER_PACKED_FLOAT_64_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedStringArray}" -> VARIANT_PARSER_PACKED_STRING_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedVector2Array}" -> VARIANT_PARSER_PACKED_VECTOR2_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedVector3Array}" -> VARIANT_PARSER_PACKED_VECTOR3_ARRAY
fqName == "$godotCorePackage.${GodotTypes.packedColorArray}" -> VARIANT_PARSER_PACKED_COLOR_ARRAY
fqName.startsWith("$godotCorePackage.${GodotTypes.ktCallable}") -> VARIANT_PARSER_PACKED_CALLABLE
isCoreType() -> ClassName(
variantTypePackage,
variantParserPackage,
fqName.substringAfterLast(".").convertToCamelCase().uppercase(Locale.getDefault())
)

fqName == Any::class.qualifiedName -> VARIANT_TYPE_ANY
else -> VARIANT_TYPE_OBJECT
fqName == Any::class.qualifiedName -> VARIANT_CASTER_ANY
else -> VARIANT_PARSER_OBJECT
}

/**
Expand All @@ -86,8 +86,8 @@ fun Type?.toKtVariantType(): ClassName = when {
*/
fun Type?.toGodotVariantType(): ClassName = this?.let {
when (it.fqName) {
Byte::class.qualifiedName, Int::class.qualifiedName -> VARIANT_TYPE_LONG
Float::class.qualifiedName -> VARIANT_TYPE_DOUBLE
Byte::class.qualifiedName, Int::class.qualifiedName -> VARIANT_PARSER_LONG
Float::class.qualifiedName -> VARIANT_PARSER_DOUBLE
else -> toKtVariantType()
}
} ?: toKtVariantType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import godot.tools.common.constants.GodotFunctions
import godot.tools.common.constants.GodotKotlinJvmTypes
import godot.tools.common.constants.GodotTypes
import godot.tools.common.constants.KOTLIN_LIST_OF
import godot.tools.common.constants.VARIANT_PARSER_NIL
import godot.tools.common.constants.godotApiPackage
import godot.tools.common.constants.godotCorePackage
import godot.tools.common.constants.godotRegistrationPackage
Expand Down Expand Up @@ -95,7 +96,7 @@ object FunctionRegistrationGenerator {

return buildList {
add(getFunctionReference(registeredFunction, className))
add(registeredFunction.returnType?.toKtVariantType() ?: ClassName("$godotCorePackage.${GodotKotlinJvmTypes.variantType}", "NIL"))
add(registeredFunction.returnType?.toKtVariantType() ?: VARIANT_PARSER_NIL)

if (registeredFunction.parameters.isNotEmpty()) {
registeredFunction.parameters.forEach { parameter ->
Expand Down
Loading