Skip to content

Commit f31196a

Browse files
committed
Use explicit return types for kotlin poet upgrade
1 parent 5291aa9 commit f31196a

File tree

112 files changed

+623
-519
lines changed

Some content is hidden

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

112 files changed

+623
-519
lines changed

kt/api-generator/src/main/kotlin/godot/codegen/generation/rule/MethodRule.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ interface BaseMethodeRule {
4747
val shouldReturn = method.getTypeName() != UNIT
4848
if (shouldReturn) {
4949
returns(methodTypeName)
50+
} else {
51+
returns(UNIT)
5052
}
5153

5254
generateParameters(method, context)

kt/api-generator/src/main/kotlin/godot/codegen/services/impl/LambdaCallableGenerationService.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,14 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
249249
val typeVariables = typeVariableNames.toMutableList()
250250
var removedTypeVariables = 0
251251
while (typeVariables.isNotEmpty()) {
252-
val bindReturnType =
253-
ClassName(godotCorePackage, "$LAMBDA_CALLABLE_NAME${typeVariableNames.size - typeVariables.size}")
252+
val bindReturnType = ClassName(godotCorePackage, "$LAMBDA_CALLABLE_NAME${typeVariableNames.size - typeVariables.size}")
253+
254+
val returnType = if (removedTypeVariables > 0) {
255+
bindReturnType.parameterizedBy(*typeVariableNames.take(typeVariableNames.size - typeVariables.size).toTypedArray(), returnTypeParameter)
256+
} else {
257+
bindReturnType.parameterizedBy(returnTypeParameter)
258+
}
259+
254260
classBuilder.addFunction(
255261
FunSpec.builder("bind")
256262
.addParameters(
@@ -291,6 +297,7 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
291297
bindReturnType,
292298
*typeVariableNames.take(removedTypeVariables).toTypedArray()
293299
)
300+
.returns(returnType)
294301
.build()
295302
)
296303

@@ -304,6 +311,13 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
304311
callableFileSpec.addType(classBuilder.build())
305312

306313
val variantMapperMember = MemberName(godotCorePackage, "variantMapper")
314+
315+
val returnTypeName = if (argCount > 0) {
316+
ktCallableClassName.parameterizedBy(*typeVariableNames.toTypedArray(), returnTypeParameter)
317+
} else {
318+
ktCallableClassName.parameterizedBy(returnTypeParameter)
319+
}
320+
307321
callableFileSpec.addFunction(
308322
FunSpec.builder(CALLABLE_FUNCTION_NAME + argCount)
309323
.addTypeVariables(typeVariableNames.map { it.copy(reified = true) })
@@ -347,6 +361,7 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
347361
.toTypedArray()
348362
)
349363
)
364+
.returns(returnTypeName)
350365
.build()
351366
)
352367

@@ -366,6 +381,7 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
366381
.build()
367382
)
368383
.addCode("return·$CALLABLE_FUNCTION_NAME$argCount($ON_CANCEL_CALL_ARGUMENT_NAME,·this)")
384+
.returns(returnTypeName)
369385
.build()
370386
)
371387
}
@@ -437,6 +453,7 @@ object LambdaCallableGenerationService : ILambdaCallableGenerationService {
437453
.addMember("\"create\"")
438454
.build()
439455
)
456+
.returns(genericClassNameInfo.className.parameterizedBy(*genericClassNameInfo.genericTypes.toTypedArray(), returnTypeParameter))
440457
.build()
441458
)
442459
.build()

kt/api-generator/src/main/kotlin/godot/codegen/services/impl/SignalGenerationService.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ object SignalGenerationService : ISignalGenerationService {
290290
.addMember("\"create\"")
291291
.build()
292292
)
293+
.returns(genericClassNameInfo.genericClassName)
293294
.build()
294295
)
295296
.build()
@@ -314,6 +315,7 @@ object SignalGenerationService : ISignalGenerationService {
314315
.addMember("\"FUNCTION_NAME\"")
315316
.build()
316317
)
318+
.returns(genericClassNameInfo.genericClassName)
317319
.build()
318320
}
319321

@@ -331,6 +333,7 @@ object SignalGenerationService : ISignalGenerationService {
331333
CodeBlock.of("return·%T.$DELEGATE_PROPERTY_NAME·as·%T", genericClassNameInfo.className, genericReadOnlyPropertyClassName)
332334
}
333335
)
336+
.returns(genericReadOnlyPropertyClassName)
334337
.apply {
335338
if (argCount != 0) {
336339
addAnnotation(

kt/godot-library/godot-api-library/src/main/kotlin/godot/api/AnimatedSprite2D.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ public open class AnimatedSprite2D : Node2D() {
426426
return (TransferContext.readReturnValue(DOUBLE) as Double).toFloat()
427427
}
428428

429-
public final fun setAnimation(name: String) = setAnimation(name.asCachedStringName())
429+
public final fun setAnimation(name: String): Unit = setAnimation(name.asCachedStringName())
430430

431431
/**
432432
* Plays the animation with key [name]. If [customSpeed] is negative and [fromEnd] is `true`, the
@@ -440,15 +440,15 @@ public open class AnimatedSprite2D : Node2D() {
440440
name: String,
441441
customSpeed: Float = 1.0f,
442442
fromEnd: Boolean = false,
443-
) = play(name.asCachedStringName(), customSpeed, fromEnd)
443+
): Unit = play(name.asCachedStringName(), customSpeed, fromEnd)
444444

445445
/**
446446
* Plays the animation with key [name] in reverse.
447447
*
448448
* This method is a shorthand for [play] with `custom_speed = -1.0` and `from_end = true`, so see
449449
* its description for more information.
450450
*/
451-
public final fun playBackwards(name: String) = playBackwards(name.asCachedStringName())
451+
public final fun playBackwards(name: String): Unit = playBackwards(name.asCachedStringName())
452452

453453
public companion object
454454

kt/godot-library/godot-api-library/src/main/kotlin/godot/api/AnimatedSprite3D.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public open class AnimatedSprite3D : SpriteBase3D() {
303303
return (TransferContext.readReturnValue(DOUBLE) as Double).toFloat()
304304
}
305305

306-
public final fun setAnimation(name: String) = setAnimation(name.asCachedStringName())
306+
public final fun setAnimation(name: String): Unit = setAnimation(name.asCachedStringName())
307307

308308
/**
309309
* Plays the animation with key [name]. If [customSpeed] is negative and [fromEnd] is `true`, the
@@ -317,15 +317,15 @@ public open class AnimatedSprite3D : SpriteBase3D() {
317317
name: String,
318318
customSpeed: Float = 1.0f,
319319
fromEnd: Boolean = false,
320-
) = play(name.asCachedStringName(), customSpeed, fromEnd)
320+
): Unit = play(name.asCachedStringName(), customSpeed, fromEnd)
321321

322322
/**
323323
* Plays the animation with key [name] in reverse.
324324
*
325325
* This method is a shorthand for [play] with `custom_speed = -1.0` and `from_end = true`, so see
326326
* its description for more information.
327327
*/
328-
public final fun playBackwards(name: String) = playBackwards(name.asCachedStringName())
328+
public final fun playBackwards(name: String): Unit = playBackwards(name.asCachedStringName())
329329

330330
public companion object
331331

kt/godot-library/godot-api-library/src/main/kotlin/godot/api/Animation.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ public open class Animation : Resource() {
10451045
*
10461046
* For example, `"character/skeleton:ankle"` or `"character/mesh:transform/local"`.
10471047
*/
1048-
public final fun trackSetPath(trackIdx: Int, path: String) =
1048+
public final fun trackSetPath(trackIdx: Int, path: String): Unit =
10491049
trackSetPath(trackIdx, path.asCachedNodePath())
10501050

10511051
/**
@@ -1072,18 +1072,18 @@ public open class Animation : Resource() {
10721072
trackIdx: Int,
10731073
keyIdx: Int,
10741074
animation: String,
1075-
) = animationTrackSetKeyAnimation(trackIdx, keyIdx, animation.asCachedStringName())
1075+
): Unit = animationTrackSetKeyAnimation(trackIdx, keyIdx, animation.asCachedStringName())
10761076

10771077
/**
10781078
* Adds a marker to this Animation.
10791079
*/
1080-
public final fun addMarker(name: String, time: Double) =
1080+
public final fun addMarker(name: String, time: Double): Unit =
10811081
addMarker(name.asCachedStringName(), time)
10821082

10831083
/**
10841084
* Removes the marker with the given name from this Animation.
10851085
*/
1086-
public final fun removeMarker(name: String) = removeMarker(name.asCachedStringName())
1086+
public final fun removeMarker(name: String): Unit = removeMarker(name.asCachedStringName())
10871087

10881088
/**
10891089
* Returns `true` if this Animation contains a marker with the given name.
@@ -1103,7 +1103,7 @@ public open class Animation : Resource() {
11031103
/**
11041104
* Sets the given marker's color.
11051105
*/
1106-
public final fun setMarkerColor(name: String, color: Color) =
1106+
public final fun setMarkerColor(name: String, color: Color): Unit =
11071107
setMarkerColor(name.asCachedStringName(), color)
11081108

11091109
public enum class TrackType(

kt/godot-library/godot-api-library/src/main/kotlin/godot/api/AnimationLibrary.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ public open class AnimationLibrary : Resource() {
133133
/**
134134
* Removes the [Animation] with the key [name].
135135
*/
136-
public final fun removeAnimation(name: String) = removeAnimation(name.asCachedStringName())
136+
public final fun removeAnimation(name: String): Unit = removeAnimation(name.asCachedStringName())
137137

138138
/**
139139
* Changes the key of the [Animation] associated with the key [name] to [newname].
140140
*/
141-
public final fun renameAnimation(name: String, newname: String) =
141+
public final fun renameAnimation(name: String, newname: String): Unit =
142142
renameAnimation(name.asCachedStringName(), newname.asCachedStringName())
143143

144144
/**

kt/godot-library/godot-api-library/src/main/kotlin/godot/api/AnimationMixer.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,13 +761,13 @@ public open class AnimationMixer internal constructor() : Node() {
761761
/**
762762
* Removes the [AnimationLibrary] associated with the key [name].
763763
*/
764-
public final fun removeAnimationLibrary(name: String) =
764+
public final fun removeAnimationLibrary(name: String): Unit =
765765
removeAnimationLibrary(name.asCachedStringName())
766766

767767
/**
768768
* Moves the [AnimationLibrary] associated with the key [name] to the key [newname].
769769
*/
770-
public final fun renameAnimationLibrary(name: String, newname: String) =
770+
public final fun renameAnimationLibrary(name: String, newname: String): Unit =
771771
renameAnimationLibrary(name.asCachedStringName(), newname.asCachedStringName())
772772

773773
/**
@@ -795,9 +795,10 @@ public open class AnimationMixer internal constructor() : Node() {
795795
*/
796796
public final fun getAnimation(name: String): Animation? = getAnimation(name.asCachedStringName())
797797

798-
public final fun setRootNode(path: String) = setRootNode(path.asCachedNodePath())
798+
public final fun setRootNode(path: String): Unit = setRootNode(path.asCachedNodePath())
799799

800-
public final fun setRootMotionTrack(path: String) = setRootMotionTrack(path.asCachedNodePath())
800+
public final fun setRootMotionTrack(path: String): Unit =
801+
setRootMotionTrack(path.asCachedNodePath())
801802

802803
/**
803804
* If the animation track specified by [name] has an option [Animation.UPDATE_CAPTURE], stores
@@ -818,7 +819,7 @@ public open class AnimationMixer internal constructor() : Node() {
818819
duration: Double,
819820
transType: Tween.TransitionType = Tween.TransitionType.LINEAR,
820821
easeType: Tween.EaseType = Tween.EaseType.IN,
821-
) = capture(name.asCachedStringName(), duration, transType, easeType)
822+
): Unit = capture(name.asCachedStringName(), duration, transType, easeType)
822823

823824
public enum class AnimationCallbackModeProcess(
824825
id: Long,

kt/godot-library/godot-api-library/src/main/kotlin/godot/api/AnimationNode.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ public open class AnimationNode : Resource() {
371371
/**
372372
* Adds or removes a path for the filter.
373373
*/
374-
public final fun setFilterPath(path: String, enable: Boolean) =
374+
public final fun setFilterPath(path: String, enable: Boolean): Unit =
375375
setFilterPath(path.asCachedNodePath(), enable)
376376

377377
/**
@@ -395,7 +395,7 @@ public open class AnimationNode : Resource() {
395395
isExternalSeeking: Boolean,
396396
blend: Float,
397397
loopedFlag: Animation.LoopedFlag = Animation.LoopedFlag.NONE,
398-
) =
398+
): Unit =
399399
blendAnimation(animation.asCachedStringName(), time, delta, seeked, isExternalSeeking, blend, loopedFlag)
400400

401401
/**
@@ -421,7 +421,7 @@ public open class AnimationNode : Resource() {
421421
* Sets a custom parameter. These are used as local memory, because resources can be reused across
422422
* the tree or scenes.
423423
*/
424-
public final fun setParameter(name: String, `value`: Any?) =
424+
public final fun setParameter(name: String, `value`: Any?): Unit =
425425
setParameter(name.asCachedStringName(), value)
426426

427427
/**

kt/godot-library/godot-api-library/src/main/kotlin/godot/api/AnimationNodeAnimation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public open class AnimationNodeAnimation : AnimationRootNode() {
229229
return Animation.LoopMode.from(TransferContext.readReturnValue(LONG) as Long)
230230
}
231231

232-
public final fun setAnimation(name: String) = setAnimation(name.asCachedStringName())
232+
public final fun setAnimation(name: String): Unit = setAnimation(name.asCachedStringName())
233233

234234
public enum class PlayMode(
235235
id: Long,

0 commit comments

Comments
 (0)