Skip to content

Commit

Permalink
Add Kotlin hints for enclosing class
Browse files Browse the repository at this point in the history
This is needed by Kotlin reflection in order to be able to list
class members on native.

Closes gh-32472
  • Loading branch information
sdeleuze committed Apr 10, 2024
1 parent 019ce44 commit ca2b3c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,6 +66,10 @@ private void registerHints(Class<?> type, RuntimeHints runtimeHints) {
if (superClass != null) {
registerHints(superClass, runtimeHints);
}
Class<?> enclosingClass = type.getEnclosingClass();
if (enclosingClass != null) {
runtimeHints.reflection().registerType(enclosingClass);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,6 +66,17 @@ class KotlinReflectionBeanRegistrationAotProcessorTests {
assertThat(generationContext.runtimeHints.reflection().typeHints()).isEmpty()
}

@Test
fun shouldGenerateOuterClassHints() {
process(OuterBean.NestedBean::class.java)
assertThat(
RuntimeHintsPredicates.reflection()
.onType(OuterBean.NestedBean::class.java)
.withMemberCategory(MemberCategory.INTROSPECT_DECLARED_METHODS)
.and(RuntimeHintsPredicates.reflection().onType(OuterBean::class.java))
).accepts(generationContext.runtimeHints)
}

private fun process(beanClass: Class<*>) {
createContribution(beanClass)?.applyTo(generationContext, Mockito.mock(BeanRegistrationCode::class.java))
}
Expand All @@ -87,4 +98,8 @@ class KotlinReflectionBeanRegistrationAotProcessorTests {
}
}

class OuterBean {
class NestedBean
}

}

0 comments on commit ca2b3c1

Please sign in to comment.