Skip to content

Commit

Permalink
Fix registration of overridden functions, annotation classes and fix …
Browse files Browse the repository at this point in the history
…recursive registration annotations resolving
  • Loading branch information
chippmann committed Oct 13, 2024
1 parent a30b22c commit 7d19352
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 152 deletions.
294 changes: 147 additions & 147 deletions harness/tests/scripts/godot/tests/Invocation.gdj
Original file line number Diff line number Diff line change
Expand Up @@ -7,159 +7,159 @@ relativeSourcePath = src/main/kotlin/godot/tests/Invocation.kt
baseType = Node3D
supertypes = [
godot.Node3D,
godot.Node,
godot.Object,
godot.core.KtObject,
kotlin.Any
godot.Node,
godot.Object,
godot.core.KtObject,
kotlin.Any
]
signals = [

]
properties = [
button,
enum_list,
vector_list,
enum_list_mutable,
register_object,
register_object_nullable,
register_object_nullable_pre_init,
register_object_non_nullable_pre_init,
vector,
x,
y,
z,
custom_name,
invocation,
enum_test,
resource_test,
jvm_id,
test_array_any,
nav_meshes,
nullable_array,
any_to_any_dictionary,
nav_meshes_dictionary,
nullable_dictionary,
color,
rid,
packed_byte_array,
packed_int32_array,
packed_float64_array,
packed_color_array,
packed_string_array,
packed_vector2_array,
packed_vector3_array,
p1,
p1_1,
p2,
p3,
p4,
p5,
p6,
p7,
p8,
p9,
p10,
p11,
p12,
p13,
p14,
p15,
p16,
p17,
stringtemplation,
test_string,
ascii_string,
utf8_string
enum_list,
vector_list,
enum_list_mutable,
register_object,
register_object_nullable,
register_object_nullable_pre_init,
register_object_non_nullable_pre_init,
vector,
x,
y,
z,
custom_name,
invocation,
enum_test,
resource_test,
jvm_id,
test_array_any,
nav_meshes,
nullable_array,
any_to_any_dictionary,
nav_meshes_dictionary,
nullable_dictionary,
color,
rid,
packed_byte_array,
packed_int32_array,
packed_float64_array,
packed_color_array,
packed_string_array,
packed_vector2_array,
packed_vector3_array,
p1,
p1_1,
p2,
p3,
p4,
p5,
p6,
p7,
p8,
p9,
p10,
p11,
p12,
p13,
p14,
p15,
p16,
p17,
stringtemplation,
test_string,
ascii_string,
utf8_string
]
functions = [
int_value,
long_value,
float_value,
double_value,
boolean_value,
string_value,
int_addition,
init_nullables,
_enter_tree,
_ready,
_on_destroy,
get_rid_id,
get_nav_mesh_rid,
append_to_any_dict,
remove_from_any_dict,
get_from_any_dict,
any_dict_size,
append_to_string_nav_mesh_dict,
remove_from_string_nav_mesh_dict,
get_from_string_nav_mesh_dict,
string_nav_mesh_dict_size,
append_to_string_nav_mesh_nullable_dict,
remove_from_string_nav_mesh_nullable_dict,
string_nav_mesh_nullable_dict_size,
append_nullable_standard_nav_mesh,
append_nullable_nav_mesh,
remove_nullable_nav_mesh,
remove_nullable_nav_mesh_with_index,
nullable_nav_meshes_size,
append_standard_nav_mesh,
append_nav_mesh,
remove_nav_mesh,
remove_nav_mesh_with_index,
get_nav_mesh_from_array,
nav_meshes_size,
append_any_to_array,
remove_any_from_array,
get_any_from_array,
array_any_size,
count_namesh_instance,
get_nav_mesh_count,
parent_is_node3_d,
is_object_node3_d,
other_jvm_id,
has_camera_node,
add_byte_to_packed_array,
add_byte_array_to_packed_array,
delete_byte_from_packed_array,
get_byte_from_packed_array,
set_byte_in_packed_array,
resize_byte_packed_array,
add_color_to_packed_array,
add_color_array_to_packed_array,
delete_color_from_packed_array,
get_color_from_packed_array,
set_color_in_packed_array,
resize_color_packed_array,
add_int_to_packed_array,
add_int_array_to_packed_array,
delete_int_from_packed_array,
get_int_from_packed_array,
set_int_in_packed_array,
resize_int_packed_array,
add_real_to_packed_array,
add_real_array_to_packed_array,
read_string_from_byte_array,
delete_real_from_packed_array,
get_real_from_packed_array,
set_real_in_packed_array,
resize_real_packed_array,
add_string_to_packed_array,
add_string_array_to_packed_array,
delete_string_from_packed_array,
get_string_from_packed_array,
set_string_in_packed_array,
resize_string_packed_array,
add_vector2_to_packed_array,
add_vector2_array_to_packed_array,
delete_vector2_from_packed_array,
get_vector2_from_packed_array,
set_vector2_in_packed_array,
resize_vector2_packed_array,
add_vector3_to_packed_array,
add_vector3_array_to_packed_array,
delete_vector3_from_packed_array,
get_vector3_from_packed_array,
set_vector3_in_packed_array,
resize_vector3_packed_array,
is_sent_xr_same_instance_as_jvm_singleton,
create_variant_array_of_user_type
]
long_value,
float_value,
double_value,
boolean_value,
string_value,
int_addition,
init_nullables,
_enter_tree,
_ready,
_on_destroy,
get_rid_id,
get_nav_mesh_rid,
append_to_any_dict,
remove_from_any_dict,
get_from_any_dict,
any_dict_size,
append_to_string_nav_mesh_dict,
remove_from_string_nav_mesh_dict,
get_from_string_nav_mesh_dict,
string_nav_mesh_dict_size,
append_to_string_nav_mesh_nullable_dict,
remove_from_string_nav_mesh_nullable_dict,
string_nav_mesh_nullable_dict_size,
append_nullable_standard_nav_mesh,
append_nullable_nav_mesh,
remove_nullable_nav_mesh,
remove_nullable_nav_mesh_with_index,
nullable_nav_meshes_size,
append_standard_nav_mesh,
append_nav_mesh,
remove_nav_mesh,
remove_nav_mesh_with_index,
get_nav_mesh_from_array,
nav_meshes_size,
append_any_to_array,
remove_any_from_array,
get_any_from_array,
array_any_size,
count_namesh_instance,
get_nav_mesh_count,
parent_is_node3_d,
is_object_node3_d,
other_jvm_id,
has_camera_node,
add_byte_to_packed_array,
add_byte_array_to_packed_array,
delete_byte_from_packed_array,
get_byte_from_packed_array,
set_byte_in_packed_array,
resize_byte_packed_array,
add_color_to_packed_array,
add_color_array_to_packed_array,
delete_color_from_packed_array,
get_color_from_packed_array,
set_color_in_packed_array,
resize_color_packed_array,
add_int_to_packed_array,
add_int_array_to_packed_array,
delete_int_from_packed_array,
get_int_from_packed_array,
set_int_in_packed_array,
resize_int_packed_array,
add_real_to_packed_array,
add_real_array_to_packed_array,
read_string_from_byte_array,
delete_real_from_packed_array,
get_real_from_packed_array,
set_real_in_packed_array,
resize_real_packed_array,
add_string_to_packed_array,
add_string_array_to_packed_array,
delete_string_from_packed_array,
get_string_from_packed_array,
set_string_in_packed_array,
resize_string_packed_array,
add_vector2_to_packed_array,
add_vector2_array_to_packed_array,
delete_vector2_from_packed_array,
get_vector2_from_packed_array,
set_vector2_in_packed_array,
resize_vector2_packed_array,
add_vector3_to_packed_array,
add_vector3_array_to_packed_array,
delete_vector3_from_packed_array,
get_vector3_from_packed_array,
set_vector3_in_packed_array,
resize_vector3_packed_array,
is_sent_xr_same_instance_as_jvm_singleton,
create_variant_array_of_user_type
]
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ fun <T : Annotation> KSAnnotated.hasAnnotation(annotationClass: KClass<T>): Bool
}
}

fun <T : Annotation> KSAnnotation.hasAnnotation(annotationClass: KClass<T>): Boolean {
return this.fqNameUnsafe == annotationClass.qualifiedName || this
fun <T : Annotation> KSAnnotation.hasAnnotation(annotationClass: KClass<T>, alreadyEvaluated: MutableList<KSAnnotation> = mutableListOf()): Boolean {
val annotationsOnAnnotation = this
.annotationType
.resolve()
.declaration
.annotations
.filterNot { alreadyEvaluated.contains(it) }
.toList()
.any { it.hasAnnotation(annotationClass) }

return this.fqNameUnsafe == annotationClass.qualifiedName || annotationsOnAnnotation.any { it.hasAnnotation(annotationClass, alreadyEvaluated.apply { add(this@hasAnnotation) }) }
}

fun KSAnnotated.hasRegistrationAnnotation(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.google.devtools.ksp.getConstructors
import com.google.devtools.ksp.getDeclaredProperties
import com.google.devtools.ksp.isAbstract
import com.google.devtools.ksp.isPublic
import com.google.devtools.ksp.symbol.ClassKind
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
import com.google.devtools.ksp.symbol.KSPropertyDeclaration
Expand Down Expand Up @@ -38,7 +39,7 @@ internal fun KSClassDeclaration.mapToClazz(

val registeredFunctions = getAllFunctions()
.filter { function ->
function.hasAnnotation(GodotMember::class) || function.overridesApiFunction()
function.hasAnnotation(GodotMember::class) || function.overridesApiFunction() || function.overridesRegisteredFunction()
}
.mapNotNull { it.mapToRegisteredFunction(this, settings) }
.toList()
Expand Down Expand Up @@ -67,7 +68,7 @@ internal fun KSClassDeclaration.mapToClazz(
.map { it.mapToRegisteredSignal(declaredProperties.toList(), settings) }
.toList()

val shouldBeRegistered = hasRegistrationAnnotation() ||
val shouldBeRegistered = (classKind != ClassKind.ANNOTATION_CLASS && hasRegistrationAnnotation()) ||
isAbstractAndContainsRegisteredMembers(registeredFunctions, registeredProperties, registeredSignals) ||
isAbstractAndInheritsGodotBaseClass()

Expand Down Expand Up @@ -152,6 +153,10 @@ private fun KSFunctionDeclaration.overridesApiFunction(isOveridee: Boolean = fal
}
}

private fun KSFunctionDeclaration.overridesRegisteredFunction(): Boolean {
return hasAnnotation(GodotMember::class) || (findOverridee() as? KSFunctionDeclaration)?.overridesRegisteredFunction() == true
}

private fun KSPropertyDeclaration.overridesRegisteredProperty(): Boolean {
return hasAnnotation(GodotMember::class) || findOverridee()?.overridesRegisteredProperty() == true
}

0 comments on commit 7d19352

Please sign in to comment.