Skip to content

Commit

Permalink
Update checks
Browse files Browse the repository at this point in the history
  • Loading branch information
chippmann committed Oct 12, 2024
1 parent 7c3b35c commit c03b3eb
Show file tree
Hide file tree
Showing 33 changed files with 349 additions and 384 deletions.
1 change: 0 additions & 1 deletion harness/tests/src/main/java/godot/tests/JavaTestClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public String greeting() {

public NativeCallable methodCallable = Callable.create(this, StringNames.asStringName("DummyName"));

@GodotMember
@Override
public void _ready() {
// Check if Singletons have the correct syntax, without Single.INSTANCE
Expand Down
2 changes: 0 additions & 2 deletions harness/tests/src/main/kotlin/godot/tests/Invocation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ class Invocation : Node3D() {
hasInitializedLateInits = true
}

@GodotMember
override fun _enterTree() {
//TODO: uncomment once https://github.com/utopia-rise/godot-kotlin-jvm/issues/86 is fixed
// GD.print("Hello", "Hello")
Expand All @@ -307,7 +306,6 @@ class Invocation : Node3D() {
println("CustomName is $customName")
}

@GodotMember
override fun _ready() {
val formerName = name
println("Name is: $name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,37 @@ internal val KSAnnotation.rpcTransferModeEnum: TransferMode
internal val KSAnnotation.rpcChannel: Int
get() = (arguments.firstOrNull { it.name?.asString() == "transferChannel" }?.value ?: arguments[3].value) as Int

internal fun KSAnnotation.mapToAnnotation(parentDeclaration: KSDeclaration): GodotAnnotation? {
internal fun KSAnnotation.mapToAnnotation(parentDeclaration: KSDeclaration): List<GodotAnnotation> {
return when (fqNameUnsafe) {
GodotScript::class.qualifiedName -> GodotScriptAnnotation(
customName = arguments.first().value as? String,
symbolProcessorSource = this
GodotScript::class.qualifiedName -> listOf(
GodotScriptAnnotation(
customName = arguments.first().value as? String,
symbolProcessorSource = this
)
)
GodotMember::class.qualifiedName -> listOf(
GodotMemberAnnotation(this)
)
Tool::class.qualifiedName -> listOf(
ToolAnnotation(this)
)
Export::class.qualifiedName -> listOf(
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
Rpc::class.qualifiedName -> listOf(
RpcAnnotation(
rpcMode = rpcModeEnum,
sync = rpcSyncEnum,
transferMode = rpcTransferModeEnum,
transferChannel = rpcChannel,
symbolProcessorSource = this
),
GodotMemberAnnotation(this),
)
GodotMember::class.qualifiedName -> GodotMemberAnnotation(this)
Tool::class.qualifiedName -> ToolAnnotation(this)
Export::class.qualifiedName -> ExportAnnotation(this)
Rpc::class.qualifiedName -> RpcAnnotation(
rpcMode = rpcModeEnum,
sync = rpcSyncEnum,
transferMode = rpcTransferModeEnum,
transferChannel = rpcChannel,
symbolProcessorSource = this
"godot.annotation.GodotBaseType" -> listOf(
GodotBaseTypeAnnotation(this) //is internal
)
"godot.annotation.GodotBaseType" -> GodotBaseTypeAnnotation(this) //is internal
EnumFlag::class.qualifiedName -> {
val setType = (parentDeclaration as KSPropertyDeclaration).type.resolve()
require(setType.declaration.qualifiedName?.asString()?.matches(Regex("^kotlin\\.collections\\..*Set\$")) ?: false) {
Expand All @@ -120,48 +134,100 @@ internal fun KSAnnotation.mapToAnnotation(parentDeclaration: KSDeclaration): God
.map { it.simpleName.asString() }
.toList()

EnumFlagHintStringAnnotation(enumValueNames = enumValueNames, source = this)
listOf(
EnumFlagHintStringAnnotation(enumValueNames = enumValueNames, source = this),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
}
IntFlag::class.qualifiedName -> IntFlagHintAnnotation(
@Suppress("UNCHECKED_CAST")
(arguments.firstOrNull()?.value as? ArrayList<String>)?.toList() ?: emptyList(),
this
IntFlag::class.qualifiedName -> listOf(
IntFlagHintAnnotation(
@Suppress("UNCHECKED_CAST")
(arguments.firstOrNull()?.value as? ArrayList<String>)?.toList() ?: emptyList(),
this
),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
MultilineText::class.qualifiedName -> listOf(
MultilineTextHintAnnotation(this),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
PlaceHolderText::class.qualifiedName -> listOf(
PlaceHolderTextHintAnnotation(this),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
MultilineText::class.qualifiedName -> MultilineTextHintAnnotation(this)
PlaceHolderText::class.qualifiedName -> PlaceHolderTextHintAnnotation(this)
ColorNoAlpha::class.qualifiedName -> ColorNoAlphaHintAnnotation(this)
godot.annotation.IntRange::class.qualifiedName -> provideRangeHintAnnotation(-1)
godot.annotation.LongRange::class.qualifiedName -> provideRangeHintAnnotation(-1L)
godot.annotation.FloatRange::class.qualifiedName -> provideRangeHintAnnotation(-1f)
godot.annotation.DoubleRange::class.qualifiedName -> provideRangeHintAnnotation(-1.0)
EnumTypeHint::class.qualifiedName -> null
ColorNoAlpha::class.qualifiedName -> listOf(
ColorNoAlphaHintAnnotation(this),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
godot.annotation.IntRange::class.qualifiedName -> listOf(
provideRangeHintAnnotation(-1),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
godot.annotation.LongRange::class.qualifiedName -> listOf(
provideRangeHintAnnotation(-1L),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
godot.annotation.FloatRange::class.qualifiedName -> listOf(
provideRangeHintAnnotation(-1f),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
godot.annotation.DoubleRange::class.qualifiedName -> listOf(
provideRangeHintAnnotation(-1.0),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
EnumTypeHint::class.qualifiedName -> emptyList()
ExpEasing::class.qualifiedName -> {
val attenuation = ((arguments.firstOrNull { it.name?.asString() == "attenuation" }?.value ?: arguments.firstOrNull()?.value) as? Boolean) ?: false
val isPositiveOnly = ((arguments.firstOrNull { it.name?.asString() == "isPositiveOnly" }?.value ?: arguments[1].value) as? Boolean) ?: false
ExpEasingHintAnnotation(
attenuation = attenuation,
isPositiveOnly = isPositiveOnly,
source = this

listOf(
ExpEasingHintAnnotation(
attenuation = attenuation,
isPositiveOnly = isPositiveOnly,
source = this
),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
}
godot.annotation.File::class.qualifiedName -> {
@Suppress("UNCHECKED_CAST")
val extensions = ((arguments.firstOrNull { it.name?.asString() == "extensions" }?.value ?: arguments.firstOrNull()?.value) as? ArrayList<String>)?.toList() ?: emptyList()
val global = ((arguments.firstOrNull { it.name?.asString() == "global" }?.value ?: arguments[1].value) as? Boolean) ?: false
FileHintAnnotation(
extensions = extensions,
global = global,
source = this

listOf(
FileHintAnnotation(
extensions = extensions,
global = global,
source = this
),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
}
Dir::class.qualifiedName -> {
val global = ((arguments.firstOrNull { it.name?.asString() == "global" }?.value ?: arguments.firstOrNull()?.value) as? Boolean) ?: false
DirHintAnnotation(
global = global,
source = this
val global =
((arguments.firstOrNull { it.name?.asString() == "global" }?.value ?: arguments.firstOrNull()?.value) as? Boolean) ?: false

listOf(
DirHintAnnotation(
global = global,
source = this
),
ExportAnnotation(this),
GodotMemberAnnotation(this),
)
}
else -> null
else -> emptyList()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ internal fun KSClassDeclaration.mapToClazz(
.map { it.mapToClazz(settings) }
.toList()
val mappedAnnotations = annotations
.mapNotNull { it.mapToAnnotation(this) as? ClassAnnotation }
.flatMap { it.mapToAnnotation(this) }
.filterIsInstance<ClassAnnotation>()
.toList()

val registeredFunctions = getAllFunctions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ internal fun KSFunctionDeclaration.mapToRegisteredConstructor(
ksValueParameter.mapToValueParameter(settings)
},
annotations = annotations
.mapNotNull { it.mapToAnnotation(this) as? ConstructorAnnotation }
.flatMap { it.mapToAnnotation(this) }
.filterIsInstance<ConstructorAnnotation>()
.toList(),
symbolProcessorSource = this
)
Expand All @@ -33,7 +34,9 @@ internal fun KSFunctionDeclaration.mapToRegisteredFunction(
): RegisteredFunction? {
val fqName = qualifiedName?.asString() ?: return null
val parameters = parameters.map { it.mapToValueParameter(settings) }
val annotations = annotations.mapNotNull { it.mapToAnnotation(this) as? FunctionAnnotation }
val annotations = annotations
.flatMap { it.mapToAnnotation(this) }
.filterIsInstance<FunctionAnnotation>()
return RegisteredFunction(
fqName = fqName,
isOverridee = this.modifiers.contains(Modifier.OVERRIDE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ internal fun KSPropertyDeclaration.mapToRegisteredProperty(
"Qualified name for a registered property declaration cannot be null"
}
val annotations = annotations
.mapNotNull { it.mapToAnnotation(this) as? PropertyAnnotation }
.flatMap { it.mapToAnnotation(this) }
.filterIsInstance<PropertyAnnotation>()
.toMutableList()
.also { declaredAnnotations ->
declaredAnnotations.addAll(
findOverridee()
?.let { overridee ->
overridee
.annotations
.mapNotNull { it.mapToAnnotation(overridee) as? PropertyAnnotation }
.flatMap { it.mapToAnnotation(overridee) }
.filterIsInstance<PropertyAnnotation>()
}
?: emptySequence()
)
Expand Down Expand Up @@ -96,7 +98,8 @@ internal fun KSPropertyDeclaration.mapToRegisteredSignal(
"Qualified name for a registered property declaration cannot be null"
}
val annotations = annotations
.mapNotNull { it.mapToAnnotation(this) as? PropertyAnnotation }
.flatMap { it.mapToAnnotation(this) }
.filterIsInstance<PropertyAnnotation>()

val mappedType = requireNotNull(type.mapToType(settings)) {
"type of property $fqName cannot be null"
Expand Down
6 changes: 5 additions & 1 deletion kt/godot-library/src/main/kotlin/godot/annotation/Export.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ package godot.annotation
*
* The property needs to have the @[RegisterProperty] annotation added as well
*/
@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD)
@Target(
AnnotationTarget.PROPERTY,
AnnotationTarget.FIELD,
AnnotationTarget.ANNOTATION_CLASS,
)
@Retention(AnnotationRetention.RUNTIME)
@GodotMember
annotation class Export
Loading

0 comments on commit c03b3eb

Please sign in to comment.