Introduce TypeHint.Builder#onReachableType(Class<?>)

Closes gh-29017
This commit is contained in:
Sébastien Deleuze
2022-08-26 08:30:25 +02:00
parent 7671d29899
commit 08f636b691
6 changed files with 17 additions and 8 deletions

View File

@@ -161,6 +161,18 @@ public final class TypeHint implements ConditionalHint {
return this;
}
/**
* Make this hint conditional on the fact that the specified type
* can be resolved.
* @param reachableType the type that should be reachable for this
* hint to apply
* @return {@code this}, to facilitate method chaining
*/
public Builder onReachableType(Class<?> reachableType) {
this.reachableType = TypeReference.of(reachableType);
return this;
}
/**
* Register the need for reflection on the field with the specified name.
* @param name the name of the field

View File

@@ -99,7 +99,7 @@ public class FileNativeConfigurationWriterTests {
ReflectionHints reflectionHints = hints.reflection();
reflectionHints.registerType(StringDecoder.class, builder -> {
builder
.onReachableType(TypeReference.of(String.class))
.onReachableType(String.class)
.withMembers(MemberCategory.PUBLIC_FIELDS, MemberCategory.DECLARED_FIELDS,
MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,

View File

@@ -50,7 +50,7 @@ public class ReflectionHintsWriterTests {
void one() throws JSONException {
ReflectionHints hints = new ReflectionHints();
hints.registerType(StringDecoder.class, builder -> builder
.onReachableType(TypeReference.of(String.class))
.onReachableType(String.class)
.withMembers(MemberCategory.PUBLIC_FIELDS, MemberCategory.DECLARED_FIELDS,
MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS,
MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,