Browse Source

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

Closes gh-29017
pull/29113/head
Sébastien Deleuze 3 years ago
parent
commit
08f636b691
  1. 4
      spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java
  2. 12
      spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java
  3. 2
      spring-core/src/test/java/org/springframework/aot/nativex/FileNativeConfigurationWriterTests.java
  4. 2
      spring-core/src/test/java/org/springframework/aot/nativex/ReflectionHintsWriterTests.java
  5. 2
      spring-web/src/main/java/org/springframework/http/codec/CodecConfigurerRuntimeHints.java
  6. 3
      spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java

4
spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java

@ -38,8 +38,6 @@ class SchedulerFactoryBeanRuntimeHints implements RuntimeHintsRegistrar { @@ -38,8 +38,6 @@ class SchedulerFactoryBeanRuntimeHints implements RuntimeHintsRegistrar {
private static final String SCHEDULER_FACTORY_CLASS_NAME = "org.quartz.impl.StdSchedulerFactory";
private static final TypeReference FACTORY_BEAN_TYPE_REFERENCE = TypeReference.of(SchedulerFactoryBean.class);
private final ReflectiveRuntimeHintsRegistrar reflectiveRegistrar = new ReflectiveRuntimeHintsRegistrar();
@Override
@ -49,7 +47,7 @@ class SchedulerFactoryBeanRuntimeHints implements RuntimeHintsRegistrar { @@ -49,7 +47,7 @@ class SchedulerFactoryBeanRuntimeHints implements RuntimeHintsRegistrar {
}
Consumer<Builder> typeHint = type -> type
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)
.onReachableType(FACTORY_BEAN_TYPE_REFERENCE);
.onReachableType(SchedulerFactoryBean.class);
hints.reflection()
.registerType(TypeReference.of(SCHEDULER_FACTORY_CLASS_NAME), typeHint)
.registerTypes(TypeReference.listOf(ResourceLoaderClassLoadHelper.class,

12
spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java

@ -161,6 +161,18 @@ public final class TypeHint implements ConditionalHint { @@ -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

2
spring-core/src/test/java/org/springframework/aot/nativex/FileNativeConfigurationWriterTests.java

@ -99,7 +99,7 @@ public class FileNativeConfigurationWriterTests { @@ -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,

2
spring-core/src/test/java/org/springframework/aot/nativex/ReflectionHintsWriterTests.java

@ -50,7 +50,7 @@ public class ReflectionHintsWriterTests { @@ -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,

2
spring-web/src/main/java/org/springframework/http/codec/CodecConfigurerRuntimeHints.java

@ -38,7 +38,7 @@ import org.springframework.lang.Nullable; @@ -38,7 +38,7 @@ import org.springframework.lang.Nullable;
class CodecConfigurerRuntimeHints implements RuntimeHintsRegistrar {
private static final Consumer<Builder> CODEC_HINT = type -> type
.onReachableType(TypeReference.of(CodecConfigurerFactory.class))
.onReachableType(CodecConfigurerFactory.class)
.withMembers(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
@Override

3
spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java

@ -22,7 +22,6 @@ import org.springframework.aot.hint.MemberCategory; @@ -22,7 +22,6 @@ import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeHint.Builder;
import org.springframework.aot.hint.TypeReference;
/**
* {@link RuntimeHintsRegistrar} implementation that registers reflection entries
@ -35,7 +34,7 @@ import org.springframework.aot.hint.TypeReference; @@ -35,7 +34,7 @@ import org.springframework.aot.hint.TypeReference;
class JacksonModulesRuntimeHints implements RuntimeHintsRegistrar {
private static final Consumer<Builder> asJacksonModule = builder ->
builder.onReachableType(TypeReference.of(Jackson2ObjectMapperBuilder.class))
builder.onReachableType(Jackson2ObjectMapperBuilder.class)
.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
@Override

Loading…
Cancel
Save