Skip to content

Commit 679e85f

Browse files
committed
feat: Remove multi args constructor constraints and simplify code according to this modification
1 parent b10e824 commit 679e85f

File tree

323 files changed

+396
-686
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

323 files changed

+396
-686
lines changed

kt/api-generator/src/main/resources/api.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"version_patch": 0,
66
"version_status": "stable",
77
"version_build": "custom_build",
8-
"version_full_name": "Godot Engine v4.3.stable.custom_build"
8+
"version_full_name": "Godot Engine v4.3.stable.jvm.0.11.0.custom_build"
99
},
1010
"builtin_class_sizes": [
1111
{
@@ -137072,10 +137072,10 @@
137072137072
{
137073137073
"name": "new",
137074137074
"is_const": false,
137075-
"is_vararg": true,
137075+
"is_vararg": false,
137076137076
"is_static": false,
137077137077
"is_virtual": false,
137078-
"hash": 1545262638,
137078+
"hash": 1460262497,
137079137079
"return_value": {
137080137080
"type": "Variant"
137081137081
},
@@ -243394,6 +243394,15 @@
243394243394
"brief_description": "Editor-only helper for setting up root motion in [AnimationMixer].",
243395243395
"description": "[i]Root motion[/i] refers to an animation technique where a mesh's skeleton is used to give impulse to a character. When working with 3D animations, a popular technique is for animators to use the root skeleton bone to give motion to the rest of the skeleton. This allows animating characters in a way where steps actually match the floor below. It also allows precise interaction with objects during cinematics. See also [AnimationMixer].\n[b]Note:[/b] [RootMotionView] is only visible in the editor. It will be hidden automatically in the running project."
243396243396
},
243397+
{
243398+
"name": "ScalaScript",
243399+
"is_refcounted": true,
243400+
"is_instantiable": true,
243401+
"inherits": "JvmScript",
243402+
"api_type": "core",
243403+
"brief_description": "",
243404+
"description": ""
243405+
},
243397243406
{
243398243407
"name": "SceneMultiplayer",
243399243408
"is_refcounted": true,

kt/common/src/main/kotlin/godot/common/constants/Constraints.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package godot.common.constants
33
// when changed; also update constraints.h!
44
// Since Godot 4, an unlimited amount of parameters is supported. Limits should be increased when appropriate.
55
object Constraints {
6-
const val MAX_CONSTRUCTOR_ARG_COUNT = 8
76
const val MAX_FUNCTION_ARG_COUNT = 16
87
const val MAX_SIGNAL_ARG_COUNT = 16
98
}

kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/ClassExtentions.kt

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,18 @@ fun ClassInfo.mapToClazz(settings: Settings): Clazz {
4141
}
4242
.map { it.mapFieldToRegisteredSignal(settings, this) }
4343

44-
val duplicateConstructorArgumentCount = constructorInfo
45-
.groupBy { it.parameterInfo.size }
46-
.toList()
47-
.firstOrNull { it.second.size > 1 }
48-
?.first
49-
5044
val shouldBeRegistered = shouldBeRegistered(methods, fields, signals)
5145

52-
if (shouldBeRegistered && duplicateConstructorArgumentCount != null) {
53-
throw Exception(
54-
"Cannot have more than one constructor with $duplicateConstructorArgumentCount arguments in registered class $fqName"
55-
)
56-
}
57-
58-
val constructors = constructorInfo
59-
.filter { constructor ->
60-
constructor.isPublic && constructor.parameterInfo.isEmpty()
46+
return if (shouldBeRegistered) {
47+
require(constructorInfo.any { it.isPublic && it.parameterInfo.isEmpty() }) {
48+
"You should provide a default constructor for class $fqName"
6149
}
62-
.map { it.mapToRegisteredConstructor(settings) }
6350

64-
return if (shouldBeRegistered) {
6551
RegisteredClass(
6652
registeredName = provideRegisteredClassName(settings),
6753
fqName = fqName,
6854
supertypes = supertypes,
6955
annotations = annotations,
70-
constructors = constructors,
7156
functions = methods,
7257
signals = signals,
7358
properties = fields,

kt/entry-generation/godot-class-graph-symbol-processor/src/main/kotlin/godot/annotation/processor/classgraph/extensions/MethodExtensions.kt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package godot.annotation.processor.classgraph.extensions
22

33
import godot.annotation.processor.classgraph.Settings
44
import godot.annotation.processor.classgraph.models.TypeDescriptor
5-
import godot.entrygenerator.model.ConstructorAnnotation
65
import godot.entrygenerator.model.FunctionAnnotation
7-
import godot.entrygenerator.model.RegisteredConstructor
86
import godot.entrygenerator.model.RegisteredFunction
97
import io.github.classgraph.ClassInfo
108
import io.github.classgraph.MethodInfo
@@ -49,14 +47,3 @@ private fun MethodInfo.isOverrideInHierarchyOf(classInfo: ClassInfo): Boolean {
4947

5048
return false
5149
}
52-
53-
fun MethodInfo.mapToRegisteredConstructor(settings: Settings): RegisteredConstructor {
54-
val parameters = parameterInfo.map { it.mapToValueParameter(settings) }
55-
return RegisteredConstructor(
56-
fqName = fqdn,
57-
parameters = parameters,
58-
annotations = annotationInfo
59-
.mapNotNull { it.mapToGodotAnnotation(settings) as? ConstructorAnnotation },
60-
symbolProcessorSource = this
61-
)
62-
}

kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/EntryGenerator.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package godot.entrygenerator
22

3-
import godot.entrygenerator.checks.DefaultConstructorCheck
43
import godot.entrygenerator.checks.FunctionArgCountCheck
54
import godot.entrygenerator.checks.LateinitPropertyCheck
65
import godot.entrygenerator.checks.NullablePropertyCheck
@@ -190,8 +189,6 @@ object EntryGenerator {
190189
registeredClasses: List<RegisteredClass>
191190
): Boolean {
192191
return listOf(
193-
DefaultConstructorCheck(logger, registeredClasses).execute(),
194-
195192
FunctionArgCountCheck(logger, registeredClasses).execute(),
196193

197194
SignalTypeCheck(logger, registeredClasses).execute(),

kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/checks/DefaultConstructorCheck.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/filebuilder/ClassRegistrarFileBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class ClassRegistrarFileBuilder(
9696
)
9797

9898
if (!registeredClass.isAbstract) {
99-
ConstructorRegistrationGenerator.generate(registeredClass, className, registerClassControlFlow)
99+
ConstructorRegistrationGenerator.generate(className, registerClassControlFlow)
100100
FunctionRegistrationGenerator.generate(registeredClass, className, registerClassControlFlow)
101101
SignalRegistrationGenerator.generate(registeredClass, className, registerClassControlFlow)
102102
PropertyRegistrationGenerator.generate(registeredClass, className, registerClassControlFlow)

kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/generator/ConstructorRegistrationGenerator.kt

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,15 @@ package godot.entrygenerator.generator
22

33
import com.squareup.kotlinpoet.ClassName
44
import com.squareup.kotlinpoet.FunSpec
5-
import godot.entrygenerator.ext.toKtVariantType
6-
import godot.entrygenerator.model.RegisteredClass
75
import godot.tools.common.constants.godotCorePackage
86

97
object ConstructorRegistrationGenerator {
108

11-
fun generate(registeredClass: RegisteredClass, className: ClassName, registerClassControlFlow: FunSpec.Builder) {
12-
registeredClass
13-
.constructors
14-
.filter { registeredConstructor ->
15-
registeredConstructor.parameters.isEmpty()
16-
}
17-
.forEach { registeredConstructor ->
18-
val ctorParamsCount = registeredConstructor.parameters.size
19-
20-
if (ctorParamsCount == 0) {
21-
registerClassControlFlow.addStatement(
22-
"constructor(%T(::%T))",
23-
ClassName(godotCorePackage, "KtConstructor$ctorParamsCount"),
24-
className
25-
)
26-
} else {
27-
val templateArgs = mutableListOf<Any>()
28-
val templateString = buildString {
29-
append("::%T")
30-
templateArgs.add(className)
31-
32-
append("")
33-
34-
registeredConstructor.parameters.forEachIndexed { index, valueParameter ->
35-
append("%T")
36-
templateArgs.add(valueParameter.type.toKtVariantType())
37-
38-
if (index != registeredConstructor.parameters.size - 1) {
39-
append("")
40-
}
41-
}
42-
}
43-
44-
registerClassControlFlow.addStatement(
45-
"constructor(%T($templateString))",
46-
ClassName(godotCorePackage, "KtConstructor$ctorParamsCount"),
47-
*templateArgs.toTypedArray()
48-
)
49-
}
50-
}
9+
fun generate(className: ClassName, registerClassControlFlow: FunSpec.Builder) {
10+
registerClassControlFlow.addStatement(
11+
"constructor(%T(::%T))",
12+
ClassName(godotCorePackage, "KtConstructor"),
13+
className
14+
)
5115
}
5216
}

kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/model/RegisteredClass.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ data class RegisteredClass(
88
override val fqName: String,
99
override val supertypes: List<Clazz>,
1010
override val annotations: List<ClassAnnotation> = emptyList(),
11-
val constructors: List<RegisteredConstructor> = emptyList(),
1211
val functions: List<RegisteredFunction> = emptyList(),
1312
val signals: List<RegisteredSignal> = emptyList(),
1413
val properties: List<RegisteredProperty> = emptyList(),

kt/entry-generation/godot-entry-generator/src/main/kotlin/godot/entrygenerator/model/RegisteredConstructor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package godot.entrygenerator.model
22

33
data class RegisteredConstructor(
44
val fqName: String,
5-
val parameters: List<ValueParameter> = emptyList(),
65
val annotations: List<ConstructorAnnotation> = emptyList(),
76
override val symbolProcessorSource: Any
87
) : GodotJvmSourceElement

0 commit comments

Comments
 (0)