Skip to content

Commit

Permalink
chore: Move signals parameter names to annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
piiertho committed Jan 15, 2025
1 parent baba396 commit 211fdad
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 764 deletions.
4 changes: 2 additions & 2 deletions harness/tests/src/main/java/godot/tests/JavaTestClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class JavaTestClass extends Node {
@RegisterSignal
public Signal0 testSignal = Signal0.create(this, "test_signal");

@RegisterSignal
public Signal2<String, String> testSignal2 = Signal2.create(this, "test_signal_2", "param1", "param2");
@RegisterSignal(parameters = {"param1", "param2"})
public Signal2<String, String> testSignal2 = Signal2.create(this, "test_signal_2");

// The following should NOT work as we cannot extract parameter names. The compiler checks should catch that and throw a build error
// @RegisterSignal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class LambdaCallableTest : Node() {
@RegisterProperty
var hasSignalNoParamBeenTriggered = false

@RegisterSignal
val signalWithParams: Signal3<String, Long, Node> by signal3("str", "long", "node")
@RegisterSignal("str", "long", "node")
val signalWithParams: Signal3<String, Long, Node> by signal3()

@RegisterProperty
var signalString: String = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class CoroutineTest : Object() {
@RegisterSignal
val signalWithoutParameter by signal0()

@RegisterSignal
val signalWithOneParameter by signal1<Int>("int")
@RegisterSignal("int")
val signalWithOneParameter by signal1<Int>()

@RegisterSignal
val signalWithManyParameters by signal4<Int, Float, Vector2, String>("int", "float", "vector2", "string")
@RegisterSignal("int", "float", "vector2", "string")
val signalWithManyParameters by signal4<Int, Float, Vector2, String>()

@RegisterProperty
var step: Int = 0
Expand Down Expand Up @@ -79,8 +79,8 @@ class CoroutineTest : Object() {
}
}

@RegisterSignal
val runOnMainThreadFromBackgroundThreadFinished by signal1<Boolean>("is_test_successful")
@RegisterSignal("is_test_successful")
val runOnMainThreadFromBackgroundThreadFinished by signal1<Boolean>()

@RegisterFunction
fun runOnMainThreadFromBackgroundThread() {
Expand Down Expand Up @@ -109,8 +109,8 @@ class CoroutineTest : Object() {
}
}

@RegisterSignal
val asyncLoadResourceFinished by signal1<Boolean>("is_test_successful")
@RegisterSignal("is_test_successful")
val asyncLoadResourceFinished by signal1<Boolean>()

@RegisterFunction
fun asyncLoadResource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import godot.core.signal2
@RegisterClass
class AbstractClassInheritanceChild : AbstractClassInheritanceParent() {

@RegisterSignal
override val testOverridden by signal2<String, Int>("blubb", "habbalubbb")
@RegisterSignal("blubb", "habbalubbb")
override val testOverridden by signal2<String, Int>()

//---------------- Here to check ------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ abstract class AbstractClassInheritanceParent : Node() {
@RegisterProperty
var registeredExportedPropertyInParent = false

@RegisterSignal
val testNotOverridden by signal1<String>("blubb")
@RegisterSignal("blubb")
val testNotOverridden by signal1<String>()

@RegisterSignal
open val testOverridden by signal2<String, Int>("blubb", "habbalubb")
@RegisterSignal("blubb", "habbalubb")
open val testOverridden by signal2<String, Int>()

//---------------- Here to check ------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import godot.global.GD
@RegisterClass
class ClassInheritanceChild : ClassInheritanceParent() {

@RegisterSignal
override val testOverridden by signal2<String, Int>("blubb", "habbalubbb")
@RegisterSignal("blubb", "habbalubbb")
override val testOverridden by signal2<String, Int>()

//---------------- Here to check ------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import godot.global.GD
@RegisterClass
open class ClassInheritanceParent : Node() {

@RegisterSignal
val testNotOverridden by signal1<String>("blubb")
@RegisterSignal("blubb")
val testNotOverridden by signal1<String>()

@RegisterSignal
open val testOverridden by signal2<String, Int>("blubb", "habbalubb")
@RegisterSignal("blubb", "habbalubb")
open val testOverridden by signal2<String, Int>()

//---------------- Here to check ------------------

Expand Down
22 changes: 11 additions & 11 deletions harness/tests/src/main/kotlin/godot/tests/signal/SignalTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ class SignalTest : Node() {
@RegisterSignal
val noParamSignalDelegate by signal0()

@RegisterSignal
val oneParamSignalDelegate by signal1<Boolean>("refresh")
@RegisterSignal("refresh")
val oneParamSignalDelegate by signal1<Boolean>()

@RegisterSignal
val twoParamSignalDelegate by signal2<String, SignalTest>("str", "inv")
@RegisterSignal("str", "inv")
val twoParamSignalDelegate by signal2<String, SignalTest>()


@RegisterSignal
@RegisterSignal()
val noParamSignalField = Signal0("noParamSignalField")

@RegisterSignal
val oneParamSignalField = Signal1<Boolean>("oneParamSignalField","refresh")
@RegisterSignal("refresh")
val oneParamSignalField = Signal1<Boolean>("oneParamSignalField")

@RegisterSignal
val twoParamSignalField = Signal2<String, SignalTest>("twoParamSignalField","str", "inv")
@RegisterSignal("str", "inv")
val twoParamSignalField = Signal2<String, SignalTest>("twoParamSignalField")

@RegisterProperty
var otherScript = OtherScript()
Expand Down Expand Up @@ -76,8 +76,8 @@ class SignalTest : Node() {
}


@RegisterSignal
val signalWithMultipleTargets by signal1<Vector2>("vector2")
@RegisterSignal("vector2")
val signalWithMultipleTargets by signal1<Vector2>()

//To store values emitted by signals
@RegisterProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ class SignalGenerationService : ISignalGenerationService {
.toFunSpecBuilder(JAVA_CREATE_METHOD_NAME)
.addParameter(ParameterSpec.builder("`object`", GODOT_OBJECT).build())
.addParameter(ParameterSpec.builder("signalName", STRING).build())
.addParameters(
(0..<argCount)
.map {
ParameterSpec.builder("p$it", STRING).build()
}
)
.returns(genericClassNameInfo.genericClassName)
.addCode(
"return·%T(`object`,·signalName)",
Expand All @@ -243,12 +237,6 @@ class SignalGenerationService : ISignalGenerationService {
.addModifiers(KModifier.INLINE)
.addTypeVariables(genericClassNameInfo.genericTypes)
.addParameter(ParameterSpec.builder("signalName", STRING).build())
.addParameters(
(0..<argCount)
.map {
ParameterSpec.builder("p$it", STRING).build()
}
)
.addCode(
CodeBlock.of(
"return·%T(this,·signalName)",
Expand All @@ -271,12 +259,6 @@ class SignalGenerationService : ISignalGenerationService {
.toFunSpecBuilder(SIGNAL_METHOD_NAME + argCount)
.addModifiers(KModifier.INLINE)
.receiver(GODOT_OBJECT)
.addParameters(
(0..<argCount)
.map {
ParameterSpec.builder("p$it", STRING).build()
}
)
.addCode(
if (argCount == 0) {
CodeBlock.of("return·%T.$DELEGATE_PROPERTY_NAME", genericClassNameInfo.className)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object SignalRegistrationGenerator {
add(ClassName(godotRegistrationPackage, GodotKotlinJvmTypes.ktFunctionArgument))
add(argumentType.toKtVariantType())
add(argumentType.fqName)
add(argumentName)
add("\"$argumentName\"")
}
} else {
registeredSignal.parameterNames.forEachIndexed { index, argumentName ->
Expand All @@ -60,7 +60,7 @@ object SignalRegistrationGenerator {
add(ClassName(godotRegistrationPackage, GodotKotlinJvmTypes.ktFunctionArgument))
add(argumentTypeVariantType)
add(argumentTypeFqName)
add(argumentName)
add("\"$argumentName\"")
}
}
}.toTypedArray()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.google.devtools.ksp.symbol.ClassKind
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
import com.google.devtools.ksp.symbol.Modifier
import godot.annotation.RegisterSignal
import godot.annotation.processor.Settings
import godot.annotation.processor.compiler.PsiProvider
import godot.entrygenerator.ext.hasAnnotation
import godot.entrygenerator.model.EnumAnnotation
import godot.entrygenerator.model.EnumHintStringAnnotation
Expand Down Expand Up @@ -102,14 +102,11 @@ internal fun KSPropertyDeclaration.mapToRegisteredSignal(
"type of property $fqName cannot be null"
}

val isInheritedButNotOverridden = !declaredProperties.map { it.qualifiedName?.asString() }.contains(fqName)

val signalParameterNames = PsiProvider.provideSignalArgumentNames(
this,
if (isInheritedButNotOverridden) {
"${findOverridee()?.qualifiedName?.asString()}"
} else fqName
)
val signalParameterNames = (this.annotations.first { it.fqNameUnsafe == RegisterSignal::class.qualifiedName }
.arguments
.firstOrNull()
?.value as? List<*>)
?.filterIsInstance<String>() ?: listOf()

return RegisteredSignal(
fqName = fqName,
Expand Down
Loading

0 comments on commit 211fdad

Please sign in to comment.