Update runtime hints predicates after GraalVM changes
As of gh-33847, method and field introspection is included by default when a type is registered for reflection. Many methods in ReflectionHintsPredicates are now mostly useless as their default behavior checks for introspection. This commit deprecates those methods and promotes instead invocation variants. During the upgrade, developers should replace it for an `onType` check if only reflection is required. If they were checking for invocation, they should use the new 'onXInvocation` method. Closes gh-34239
This commit is contained in:
parent
6be811119e
commit
d28c0396c9
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -50,7 +50,7 @@ class AspectJBeanFactoryInitializationAotProcessorTests {
|
||||||
@Test
|
@Test
|
||||||
void shouldProcessAspect() {
|
void shouldProcessAspect() {
|
||||||
process(TestAspect.class);
|
process(TestAspect.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(TestAspect.class, "alterReturnValue").invoke())
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(TestAspect.class, "alterReturnValue"))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -94,7 +94,7 @@ class AutowiredAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PrivateFieldInjectionSample.class);
|
PrivateFieldInjectionSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onField(PrivateFieldInjectionSample.class, "environment"))
|
.onType(PrivateFieldInjectionSample.class))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PrivateFieldInjectionSample instance = new PrivateFieldInjectionSample();
|
PrivateFieldInjectionSample instance = new PrivateFieldInjectionSample();
|
||||||
|
@ -113,7 +113,7 @@ class AutowiredAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PackagePrivateFieldInjectionSample.class);
|
PackagePrivateFieldInjectionSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onField(PackagePrivateFieldInjectionSample.class, "environment"))
|
.onType(PackagePrivateFieldInjectionSample.class))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PackagePrivateFieldInjectionSample instance = new PackagePrivateFieldInjectionSample();
|
PackagePrivateFieldInjectionSample instance = new PackagePrivateFieldInjectionSample();
|
||||||
|
@ -132,7 +132,7 @@ class AutowiredAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PackagePrivateFieldInjectionFromParentSample.class);
|
PackagePrivateFieldInjectionFromParentSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onField(PackagePrivateFieldInjectionSample.class, "environment"))
|
.onType(PackagePrivateFieldInjectionSample.class))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PackagePrivateFieldInjectionFromParentSample instance = new PackagePrivateFieldInjectionFromParentSample();
|
PackagePrivateFieldInjectionFromParentSample instance = new PackagePrivateFieldInjectionFromParentSample();
|
||||||
|
@ -150,7 +150,7 @@ class AutowiredAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PrivateMethodInjectionSample.class);
|
PrivateMethodInjectionSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(PrivateMethodInjectionSample.class, "setTestBean").invoke())
|
.onMethodInvocation(PrivateMethodInjectionSample.class, "setTestBean"))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PrivateMethodInjectionSample instance = new PrivateMethodInjectionSample();
|
PrivateMethodInjectionSample instance = new PrivateMethodInjectionSample();
|
||||||
|
@ -169,7 +169,7 @@ class AutowiredAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PackagePrivateMethodInjectionSample.class);
|
PackagePrivateMethodInjectionSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(PackagePrivateMethodInjectionSample.class, "setTestBean").introspect())
|
.onType(PackagePrivateMethodInjectionSample.class))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PackagePrivateMethodInjectionSample instance = new PackagePrivateMethodInjectionSample();
|
PackagePrivateMethodInjectionSample instance = new PackagePrivateMethodInjectionSample();
|
||||||
|
@ -188,7 +188,7 @@ class AutowiredAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PackagePrivateMethodInjectionFromParentSample.class);
|
PackagePrivateMethodInjectionFromParentSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(PackagePrivateMethodInjectionSample.class, "setTestBean"))
|
.onMethodInvocation(PackagePrivateMethodInjectionSample.class, "setTestBean"))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PackagePrivateMethodInjectionFromParentSample instance = new PackagePrivateMethodInjectionFromParentSample();
|
PackagePrivateMethodInjectionFromParentSample instance = new PackagePrivateMethodInjectionFromParentSample();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -568,7 +568,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
||||||
|
|
||||||
private void assertHasMethodInvokeHints(Class<?> beanType, String... methodNames) {
|
private void assertHasMethodInvokeHints(Class<?> beanType, String... methodNames) {
|
||||||
assertThat(methodNames).allMatch(methodName -> RuntimeHintsPredicates.reflection()
|
assertThat(methodNames).allMatch(methodName -> RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(beanType, methodName).invoke()
|
.onMethodInvocation(beanType, methodName)
|
||||||
.test(this.generationContext.getRuntimeHints()));
|
.test(this.generationContext.getRuntimeHints()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -79,7 +79,7 @@ class CommonAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PrivateFieldResourceSample.class);
|
PrivateFieldResourceSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onField(PrivateFieldResourceSample.class, "one"))
|
.onType(PrivateFieldResourceSample.class))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PrivateFieldResourceSample instance = new PrivateFieldResourceSample();
|
PrivateFieldResourceSample instance = new PrivateFieldResourceSample();
|
||||||
|
@ -98,7 +98,7 @@ class CommonAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PackagePrivateFieldResourceSample.class);
|
PackagePrivateFieldResourceSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onField(PackagePrivateFieldResourceSample.class, "one"))
|
.onType(PackagePrivateFieldResourceSample.class))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PackagePrivateFieldResourceSample instance = new PackagePrivateFieldResourceSample();
|
PackagePrivateFieldResourceSample instance = new PackagePrivateFieldResourceSample();
|
||||||
|
@ -117,7 +117,7 @@ class CommonAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PackagePrivateFieldResourceFromParentSample.class);
|
PackagePrivateFieldResourceFromParentSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onField(PackagePrivateFieldResourceSample.class, "one"))
|
.onType(PackagePrivateFieldResourceSample.class))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PackagePrivateFieldResourceFromParentSample instance = new PackagePrivateFieldResourceFromParentSample();
|
PackagePrivateFieldResourceFromParentSample instance = new PackagePrivateFieldResourceFromParentSample();
|
||||||
|
@ -135,7 +135,7 @@ class CommonAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PrivateMethodResourceSample.class);
|
PrivateMethodResourceSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(PrivateMethodResourceSample.class, "setOne").invoke())
|
.onMethodInvocation(PrivateMethodResourceSample.class, "setOne"))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PrivateMethodResourceSample instance = new PrivateMethodResourceSample();
|
PrivateMethodResourceSample instance = new PrivateMethodResourceSample();
|
||||||
|
@ -153,7 +153,7 @@ class CommonAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PrivateMethodResourceWithCustomNameSample.class);
|
PrivateMethodResourceWithCustomNameSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(PrivateMethodResourceWithCustomNameSample.class, "setText").invoke())
|
.onMethodInvocation(PrivateMethodResourceWithCustomNameSample.class, "setText"))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PrivateMethodResourceWithCustomNameSample instance = new PrivateMethodResourceWithCustomNameSample();
|
PrivateMethodResourceWithCustomNameSample instance = new PrivateMethodResourceWithCustomNameSample();
|
||||||
|
@ -172,7 +172,7 @@ class CommonAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PackagePrivateMethodResourceSample.class);
|
PackagePrivateMethodResourceSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(PackagePrivateMethodResourceSample.class, "setOne").introspect())
|
.onType(PackagePrivateMethodResourceSample.class))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PackagePrivateMethodResourceSample instance = new PackagePrivateMethodResourceSample();
|
PackagePrivateMethodResourceSample instance = new PackagePrivateMethodResourceSample();
|
||||||
|
@ -191,7 +191,7 @@ class CommonAnnotationBeanRegistrationAotContributionTests {
|
||||||
RegisteredBean registeredBean = getAndApplyContribution(
|
RegisteredBean registeredBean = getAndApplyContribution(
|
||||||
PackagePrivateMethodResourceFromParentSample.class);
|
PackagePrivateMethodResourceFromParentSample.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(PackagePrivateMethodResourceSample.class, "setOne"))
|
.onMethodInvocation(PackagePrivateMethodResourceSample.class, "setOne"))
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
compile(registeredBean, (postProcessor, compiled) -> {
|
compile(registeredBean, (postProcessor, compiled) -> {
|
||||||
PackagePrivateMethodResourceFromParentSample instance = new PackagePrivateMethodResourceFromParentSample();
|
PackagePrivateMethodResourceFromParentSample instance = new PackagePrivateMethodResourceFromParentSample();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -17,7 +17,6 @@
|
||||||
package org.springframework.context.aot;
|
package org.springframework.context.aot;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
@ -565,8 +564,7 @@ class ApplicationContextAotGeneratorTests {
|
||||||
GenericApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
GenericApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||||
applicationContext.registerBean(ConfigurableCglibConfiguration.class);
|
applicationContext.registerBean(ConfigurableCglibConfiguration.class);
|
||||||
TestGenerationContext generationContext = processAheadOfTime(applicationContext);
|
TestGenerationContext generationContext = processAheadOfTime(applicationContext);
|
||||||
Constructor<?> userConstructor = ConfigurableCglibConfiguration.class.getDeclaredConstructors()[0];
|
assertThat(RuntimeHintsPredicates.reflection().onType(ConfigurableCglibConfiguration.class))
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onConstructor(userConstructor).introspect())
|
|
||||||
.accepts(generationContext.getRuntimeHints());
|
.accepts(generationContext.getRuntimeHints());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.context.aot;
|
package org.springframework.context.aot;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.aot.generate.GenerationContext;
|
import org.springframework.aot.generate.GenerationContext;
|
||||||
|
@ -69,8 +67,7 @@ class ReflectiveProcessorBeanFactoryInitializationAotProcessorTests {
|
||||||
void shouldProcessAllBeans() throws NoSuchMethodException {
|
void shouldProcessAllBeans() throws NoSuchMethodException {
|
||||||
ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection();
|
ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection();
|
||||||
process(SampleTypeAnnotatedBean.class, SampleConstructorAnnotatedBean.class);
|
process(SampleTypeAnnotatedBean.class, SampleConstructorAnnotatedBean.class);
|
||||||
Constructor<?> constructor = SampleConstructorAnnotatedBean.class.getDeclaredConstructor(String.class);
|
assertThat(reflection.onType(SampleTypeAnnotatedBean.class))
|
||||||
assertThat(reflection.onType(SampleTypeAnnotatedBean.class).and(reflection.onConstructor(constructor)))
|
|
||||||
.accepts(this.generationContext.getRuntimeHints());
|
.accepts(this.generationContext.getRuntimeHints());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -179,8 +179,7 @@ enum InstrumentedMethod {
|
||||||
if (field == null) {
|
if (field == null) {
|
||||||
return runtimeHints -> false;
|
return runtimeHints -> false;
|
||||||
}
|
}
|
||||||
return reflection().onType(field.getDeclaringClass())
|
return reflection().onType(field.getDeclaringClass());
|
||||||
.or(reflection().onField(field));
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -232,25 +231,25 @@ enum InstrumentedMethod {
|
||||||
* {@link Constructor#newInstance(Object...)}.
|
* {@link Constructor#newInstance(Object...)}.
|
||||||
*/
|
*/
|
||||||
CONSTRUCTOR_NEWINSTANCE(Constructor.class, "newInstance", HintType.REFLECTION,
|
CONSTRUCTOR_NEWINSTANCE(Constructor.class, "newInstance", HintType.REFLECTION,
|
||||||
invocation -> reflection().onConstructor(invocation.getInstance()).invoke()),
|
invocation -> reflection().onConstructorInvocation(invocation.getInstance())),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Method#invoke(Object, Object...)}.
|
* {@link Method#invoke(Object, Object...)}.
|
||||||
*/
|
*/
|
||||||
METHOD_INVOKE(Method.class, "invoke", HintType.REFLECTION,
|
METHOD_INVOKE(Method.class, "invoke", HintType.REFLECTION,
|
||||||
invocation -> reflection().onMethod(invocation.getInstance()).invoke()),
|
invocation -> reflection().onMethodInvocation(invocation.getInstance())),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Field#get(Object)}.
|
* {@link Field#get(Object)}.
|
||||||
*/
|
*/
|
||||||
FIELD_GET(Field.class, "get", HintType.REFLECTION,
|
FIELD_GET(Field.class, "get", HintType.REFLECTION,
|
||||||
invocation -> reflection().onField(invocation.getInstance())),
|
invocation -> reflection().onFieldInvocation(invocation.getInstance())),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Field#set(Object, Object)}.
|
* {@link Field#set(Object, Object)}.
|
||||||
*/
|
*/
|
||||||
FIELD_SET(Field.class, "set", HintType.REFLECTION,
|
FIELD_SET(Field.class, "set", HintType.REFLECTION,
|
||||||
invocation -> reflection().onField(invocation.getInstance())),
|
invocation -> reflection().onFieldInvocation(invocation.getInstance())),
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -81,24 +81,52 @@ public class ReflectionHintsPredicates {
|
||||||
* <p>The returned type exposes additional methods that refine the predicate behavior.
|
* <p>The returned type exposes additional methods that refine the predicate behavior.
|
||||||
* @param constructor the constructor
|
* @param constructor the constructor
|
||||||
* @return the {@link RuntimeHints} predicate
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @deprecated since 7.0 in favor of {@link #onConstructorInvocation(Constructor)}
|
||||||
|
* or {@link #onType(Class)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "7.0", forRemoval = true)
|
||||||
public ConstructorHintPredicate onConstructor(Constructor<?> constructor) {
|
public ConstructorHintPredicate onConstructor(Constructor<?> constructor) {
|
||||||
Assert.notNull(constructor, "'constructor' must not be null");
|
Assert.notNull(constructor, "'constructor' must not be null");
|
||||||
return new ConstructorHintPredicate(constructor);
|
return new ConstructorHintPredicate(constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a predicate that checks whether an invocation hint is registered for the given constructor.
|
||||||
|
* @param constructor the constructor
|
||||||
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public Predicate<RuntimeHints> onConstructorInvocation(Constructor<?> constructor) {
|
||||||
|
Assert.notNull(constructor, "'constructor' must not be null");
|
||||||
|
return new ConstructorHintPredicate(constructor).invoke();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a predicate that checks whether a reflection hint is registered for the given method.
|
* Return a predicate that checks whether a reflection hint is registered for the given method.
|
||||||
* By default, both introspection and invocation hints match.
|
* By default, both introspection and invocation hints match.
|
||||||
* <p>The returned type exposes additional methods that refine the predicate behavior.
|
* <p>The returned type exposes additional methods that refine the predicate behavior.
|
||||||
* @param method the method
|
* @param method the method
|
||||||
* @return the {@link RuntimeHints} predicate
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @deprecated since 7.0 in favor of {@link #onMethodInvocation(Method)}
|
||||||
|
* or {@link #onType(Class)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "7.0", forRemoval = true)
|
||||||
public MethodHintPredicate onMethod(Method method) {
|
public MethodHintPredicate onMethod(Method method) {
|
||||||
Assert.notNull(method, "'method' must not be null");
|
Assert.notNull(method, "'method' must not be null");
|
||||||
return new MethodHintPredicate(method);
|
return new MethodHintPredicate(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a predicate that checks whether an invocation hint is registered for the given method.
|
||||||
|
* @param method the method
|
||||||
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public Predicate<RuntimeHints> onMethodInvocation(Method method) {
|
||||||
|
Assert.notNull(method, "'method' must not be null");
|
||||||
|
return new MethodHintPredicate(method).invoke();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a predicate that checks whether a reflection hint is registered for the method that matches the given selector.
|
* Return a predicate that checks whether a reflection hint is registered for the method that matches the given selector.
|
||||||
* This looks up a method on the given type with the expected name, if unique.
|
* This looks up a method on the given type with the expected name, if unique.
|
||||||
|
@ -108,13 +136,31 @@ public class ReflectionHintsPredicates {
|
||||||
* @param methodName the method name
|
* @param methodName the method name
|
||||||
* @return the {@link RuntimeHints} predicate
|
* @return the {@link RuntimeHints} predicate
|
||||||
* @throws IllegalArgumentException if the method cannot be found or if multiple methods are found with the same name.
|
* @throws IllegalArgumentException if the method cannot be found or if multiple methods are found with the same name.
|
||||||
|
* @deprecated since 7.0 in favor of {@link #onMethodInvocation(Class, String)}
|
||||||
|
* or {@link #onType(Class)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "7.0", forRemoval = true)
|
||||||
public MethodHintPredicate onMethod(Class<?> type, String methodName) {
|
public MethodHintPredicate onMethod(Class<?> type, String methodName) {
|
||||||
Assert.notNull(type, "'type' must not be null");
|
Assert.notNull(type, "'type' must not be null");
|
||||||
Assert.hasText(methodName, "'methodName' must not be empty");
|
Assert.hasText(methodName, "'methodName' must not be empty");
|
||||||
return new MethodHintPredicate(getMethod(type, methodName));
|
return new MethodHintPredicate(getMethod(type, methodName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a predicate that checks whether an invocation hint is registered for the method that matches the given selector.
|
||||||
|
* This looks up a method on the given type with the expected name, if unique.
|
||||||
|
* @param type the type holding the method
|
||||||
|
* @param methodName the method name
|
||||||
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @throws IllegalArgumentException if the method cannot be found or if multiple methods are found with the same name.
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public Predicate<RuntimeHints> onMethodInvocation(Class<?> type, String methodName) {
|
||||||
|
Assert.notNull(type, "'type' must not be null");
|
||||||
|
Assert.hasText(methodName, "'methodName' must not be empty");
|
||||||
|
return new MethodHintPredicate(getMethod(type, methodName)).invoke();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a predicate that checks whether a reflection hint is registered for the method that matches the given selector.
|
* Return a predicate that checks whether a reflection hint is registered for the method that matches the given selector.
|
||||||
* This looks up a method on the given type with the expected name, if unique.
|
* This looks up a method on the given type with the expected name, if unique.
|
||||||
|
@ -125,13 +171,32 @@ public class ReflectionHintsPredicates {
|
||||||
* @return the {@link RuntimeHints} predicate
|
* @return the {@link RuntimeHints} predicate
|
||||||
* @throws ClassNotFoundException if the class cannot be resolved.
|
* @throws ClassNotFoundException if the class cannot be resolved.
|
||||||
* @throws IllegalArgumentException if the method cannot be found or if multiple methods are found with the same name.
|
* @throws IllegalArgumentException if the method cannot be found or if multiple methods are found with the same name.
|
||||||
|
* @deprecated since 7.0 in favor of {@link #onMethodInvocation(String, String)}
|
||||||
|
* or {@link #onType(Class)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "7.0", forRemoval = true)
|
||||||
public MethodHintPredicate onMethod(String className, String methodName) throws ClassNotFoundException {
|
public MethodHintPredicate onMethod(String className, String methodName) throws ClassNotFoundException {
|
||||||
Assert.hasText(className, "'className' must not be empty");
|
Assert.hasText(className, "'className' must not be empty");
|
||||||
Assert.hasText(methodName, "'methodName' must not be empty");
|
Assert.hasText(methodName, "'methodName' must not be empty");
|
||||||
return onMethod(Class.forName(className), methodName);
|
return onMethod(Class.forName(className), methodName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a predicate that checks whether an invocation hint is registered for the method that matches the given selector.
|
||||||
|
* This looks up a method on the given type with the expected name, if unique.
|
||||||
|
* @param className the name of the class holding the method
|
||||||
|
* @param methodName the method name
|
||||||
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @throws ClassNotFoundException if the class cannot be resolved.
|
||||||
|
* @throws IllegalArgumentException if the method cannot be found or if multiple methods are found with the same name.
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public Predicate<RuntimeHints> onMethodInvocation(String className, String methodName) throws ClassNotFoundException {
|
||||||
|
Assert.hasText(className, "'className' must not be empty");
|
||||||
|
Assert.hasText(methodName, "'methodName' must not be empty");
|
||||||
|
return onMethod(Class.forName(className), methodName).invoke();
|
||||||
|
}
|
||||||
|
|
||||||
private Method getMethod(Class<?> type, String methodName) {
|
private Method getMethod(Class<?> type, String methodName) {
|
||||||
ReflectionUtils.MethodFilter selector = method -> methodName.equals(method.getName());
|
ReflectionUtils.MethodFilter selector = method -> methodName.equals(method.getName());
|
||||||
Set<Method> methods = MethodIntrospector.selectMethods(type, selector);
|
Set<Method> methods = MethodIntrospector.selectMethods(type, selector);
|
||||||
|
@ -155,7 +220,10 @@ public class ReflectionHintsPredicates {
|
||||||
* @param fieldName the field name
|
* @param fieldName the field name
|
||||||
* @return the {@link RuntimeHints} predicate
|
* @return the {@link RuntimeHints} predicate
|
||||||
* @throws IllegalArgumentException if a field cannot be found with the given name.
|
* @throws IllegalArgumentException if a field cannot be found with the given name.
|
||||||
|
* @deprecated since 7.0 in favor of {@link #onFieldInvocation(Class, String)}
|
||||||
|
* or {@link #onType(Class)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "7.0", forRemoval = true)
|
||||||
public FieldHintPredicate onField(Class<?> type, String fieldName) {
|
public FieldHintPredicate onField(Class<?> type, String fieldName) {
|
||||||
Assert.notNull(type, "'type' must not be null");
|
Assert.notNull(type, "'type' must not be null");
|
||||||
Assert.hasText(fieldName, "'fieldName' must not be empty");
|
Assert.hasText(fieldName, "'fieldName' must not be empty");
|
||||||
|
@ -166,6 +234,25 @@ public class ReflectionHintsPredicates {
|
||||||
return new FieldHintPredicate(field);
|
return new FieldHintPredicate(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a predicate that checks whether an invocation hint is registered for the field that matches the given selector.
|
||||||
|
* This looks up a field on the given type with the expected name, if present.
|
||||||
|
* @param type the type holding the field
|
||||||
|
* @param fieldName the field name
|
||||||
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @throws IllegalArgumentException if a field cannot be found with the given name.
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public Predicate<RuntimeHints> onFieldInvocation(Class<?> type, String fieldName) {
|
||||||
|
Assert.notNull(type, "'type' must not be null");
|
||||||
|
Assert.hasText(fieldName, "'fieldName' must not be empty");
|
||||||
|
Field field = ReflectionUtils.findField(type, fieldName);
|
||||||
|
if (field == null) {
|
||||||
|
throw new IllegalArgumentException("No field named '%s' on class %s".formatted(fieldName, type.getName()));
|
||||||
|
}
|
||||||
|
return new FieldHintPredicate(field).invocation();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a predicate that checks whether a reflection hint is registered for the field that matches the given selector.
|
* Return a predicate that checks whether a reflection hint is registered for the field that matches the given selector.
|
||||||
* This looks up a field on the given type with the expected name, if present.
|
* This looks up a field on the given type with the expected name, if present.
|
||||||
|
@ -176,25 +263,58 @@ public class ReflectionHintsPredicates {
|
||||||
* @return the {@link RuntimeHints} predicate
|
* @return the {@link RuntimeHints} predicate
|
||||||
* @throws ClassNotFoundException if the class cannot be resolved.
|
* @throws ClassNotFoundException if the class cannot be resolved.
|
||||||
* @throws IllegalArgumentException if a field cannot be found with the given name.
|
* @throws IllegalArgumentException if a field cannot be found with the given name.
|
||||||
|
* @deprecated since 7.0 in favor of {@link #onFieldInvocation(String, String)}
|
||||||
|
* or {@link #onType(Class)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "7.0", forRemoval = true)
|
||||||
public FieldHintPredicate onField(String className, String fieldName) throws ClassNotFoundException {
|
public FieldHintPredicate onField(String className, String fieldName) throws ClassNotFoundException {
|
||||||
Assert.hasText(className, "'className' must not be empty");
|
Assert.hasText(className, "'className' must not be empty");
|
||||||
Assert.hasText(fieldName, "'fieldName' must not be empty");
|
Assert.hasText(fieldName, "'fieldName' must not be empty");
|
||||||
return onField(Class.forName(className), fieldName);
|
return onField(Class.forName(className), fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a predicate that checks whether an invocation hint is registered for the field that matches the given selector.
|
||||||
|
* This looks up a field on the given type with the expected name, if present.
|
||||||
|
* @param className the name of the class holding the field
|
||||||
|
* @param fieldName the field name
|
||||||
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @throws ClassNotFoundException if the class cannot be resolved.
|
||||||
|
* @throws IllegalArgumentException if a field cannot be found with the given name.
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public Predicate<RuntimeHints> onFieldInvocation(String className, String fieldName) throws ClassNotFoundException {
|
||||||
|
Assert.hasText(className, "'className' must not be empty");
|
||||||
|
Assert.hasText(fieldName, "'fieldName' must not be empty");
|
||||||
|
return onField(Class.forName(className), fieldName).invocation();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a predicate that checks whether a reflection hint is registered for the given field.
|
* Return a predicate that checks whether a reflection hint is registered for the given field.
|
||||||
* By default, unsafe or write access is not considered.
|
* By default, unsafe or write access is not considered.
|
||||||
* <p>The returned type exposes additional methods that refine the predicate behavior.
|
* <p>The returned type exposes additional methods that refine the predicate behavior.
|
||||||
* @param field the field
|
* @param field the field
|
||||||
* @return the {@link RuntimeHints} predicate
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @deprecated since 7.0 in favor of {@link #onFieldInvocation(Field)}
|
||||||
|
* or {@link #onType(Class)}.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "7.0", forRemoval = true)
|
||||||
public FieldHintPredicate onField(Field field) {
|
public FieldHintPredicate onField(Field field) {
|
||||||
Assert.notNull(field, "'field' must not be null");
|
Assert.notNull(field, "'field' must not be null");
|
||||||
return new FieldHintPredicate(field);
|
return new FieldHintPredicate(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a predicate that checks whether an invocation hint is registered for the given field.
|
||||||
|
* @param field the field
|
||||||
|
* @return the {@link RuntimeHints} predicate
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public Predicate<RuntimeHints> onFieldInvocation(Field field) {
|
||||||
|
Assert.notNull(field, "'field' must not be null");
|
||||||
|
return new FieldHintPredicate(field).invocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static class TypeHintPredicate implements Predicate<RuntimeHints> {
|
public static class TypeHintPredicate implements Predicate<RuntimeHints> {
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -254,7 +254,7 @@ class BindingReflectionHintsRegistrarTests {
|
||||||
@Test
|
@Test
|
||||||
void registerTypeForSerializationWithRecordWithProperty() {
|
void registerTypeForSerializationWithRecordWithProperty() {
|
||||||
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleRecordWithProperty.class);
|
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleRecordWithProperty.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleRecordWithProperty.class, "getNameProperty"))
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleRecordWithProperty.class, "getNameProperty"))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,18 +267,18 @@ class BindingReflectionHintsRegistrarTests {
|
||||||
@Test
|
@Test
|
||||||
void registerTypeForJacksonAnnotations() {
|
void registerTypeForJacksonAnnotations() {
|
||||||
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithJsonProperty.class);
|
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithJsonProperty.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onField(SampleClassWithJsonProperty.class, "privateField"))
|
assertThat(RuntimeHintsPredicates.reflection().onFieldInvocation(SampleClassWithJsonProperty.class, "privateField"))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleClassWithJsonProperty.class, "packagePrivateMethod").invoke())
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleClassWithJsonProperty.class, "packagePrivateMethod"))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void registerTypeForInheritedJacksonAnnotations() {
|
void registerTypeForInheritedJacksonAnnotations() {
|
||||||
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithInheritedJsonProperty.class);
|
bindingRegistrar.registerReflectionHints(this.hints.reflection(), SampleClassWithInheritedJsonProperty.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onField(SampleClassWithJsonProperty.class, "privateField"))
|
assertThat(RuntimeHintsPredicates.reflection().onFieldInvocation(SampleClassWithJsonProperty.class, "privateField"))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleClassWithJsonProperty.class, "packagePrivateMethod").invoke())
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleClassWithJsonProperty.class, "packagePrivateMethod"))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -152,7 +152,7 @@ class ReflectiveRuntimeHintsRegistrarTests {
|
||||||
void shouldInvokeCustomProcessor() {
|
void shouldInvokeCustomProcessor() {
|
||||||
process(SampleCustomProcessor.class);
|
process(SampleCustomProcessor.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(SampleCustomProcessor.class, "managed")).accepts(this.runtimeHints);
|
.onMethodInvocation(SampleCustomProcessor.class, "managed")).accepts(this.runtimeHints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)
|
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)
|
||||||
.withMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.runtimeHints);
|
.withMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.runtimeHints);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -41,7 +41,7 @@ class RegisterReflectionForBindingProcessorTests {
|
||||||
processor.registerReflectionHints(hints.reflection(), ClassLevelAnnotatedBean.class);
|
processor.registerReflectionHints(hints.reflection(), ClassLevelAnnotatedBean.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(SampleClassWithGetter.class)).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onType(SampleClassWithGetter.class)).accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)).accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleClassWithGetter.class, "getName")).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleClassWithGetter.class, "getName")).accepts(hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -49,7 +49,7 @@ class RegisterReflectionForBindingProcessorTests {
|
||||||
processor.registerReflectionHints(hints.reflection(), MethodLevelAnnotatedBean.class.getMethod("method"));
|
processor.registerReflectionHints(hints.reflection(), MethodLevelAnnotatedBean.class.getMethod("method"));
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(SampleClassWithGetter.class)).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onType(SampleClassWithGetter.class)).accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)).accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleClassWithGetter.class, "getName")).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleClassWithGetter.class, "getName")).accepts(hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -57,7 +57,7 @@ class RegisterReflectionForBindingProcessorTests {
|
||||||
processor.registerReflectionHints(hints.reflection(), SampleClassWithoutAnnotationAttribute.class);
|
processor.registerReflectionHints(hints.reflection(), SampleClassWithoutAnnotationAttribute.class);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(SampleClassWithoutAnnotationAttribute.class)).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onType(SampleClassWithoutAnnotationAttribute.class)).accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)).accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleClassWithoutAnnotationAttribute.class, "getName")).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleClassWithoutAnnotationAttribute.class, "getName")).accepts(hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -156,147 +156,80 @@ class ReflectionHintsPredicatesTests {
|
||||||
@Nested
|
@Nested
|
||||||
class ReflectionOnConstructor {
|
class ReflectionOnConstructor {
|
||||||
|
|
||||||
@Test
|
|
||||||
void constructorIntrospectionDoesNotMatchMissingHint() {
|
|
||||||
assertPredicateDoesNotMatch(reflection.onConstructor(publicConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void constructorIntrospectionMatchesTypeHint() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class);
|
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void constructorIntrospectionMatchesConstructorHint() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint ->
|
|
||||||
typeHint.withConstructor(Collections.emptyList(), ExecutableMode.INTROSPECT));
|
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void constructorIntrospectionMatchesIntrospectPublicConstructors() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void constructorIntrospectionMatchesInvokePublicConstructors() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
|
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void constructorIntrospectionMatchesIntrospectDeclaredConstructors() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void constructorIntrospectionMatchesInvokeDeclaredConstructors() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorInvocationDoesNotMatchConstructorHint() {
|
void constructorInvocationDoesNotMatchConstructorHint() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint -> typeHint.
|
runtimeHints.reflection().registerType(SampleClass.class, typeHint -> typeHint.
|
||||||
withConstructor(Collections.emptyList(), ExecutableMode.INTROSPECT));
|
withConstructor(Collections.emptyList(), ExecutableMode.INTROSPECT));
|
||||||
assertPredicateDoesNotMatch(reflection.onConstructor(publicConstructor).invoke());
|
assertPredicateDoesNotMatch(reflection.onConstructorInvocation(publicConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorInvocationMatchesConstructorInvocationHint() {
|
void constructorInvocationMatchesConstructorInvocationHint() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint -> typeHint.
|
runtimeHints.reflection().registerType(SampleClass.class, typeHint -> typeHint.
|
||||||
withConstructor(Collections.emptyList(), ExecutableMode.INVOKE));
|
withConstructor(Collections.emptyList(), ExecutableMode.INVOKE));
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).invoke());
|
assertPredicateMatches(reflection.onConstructorInvocation(publicConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorInvocationDoesNotMatchIntrospectPublicConstructors() {
|
void constructorInvocationDoesNotMatchIntrospectPublicConstructors() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
||||||
assertPredicateDoesNotMatch(reflection.onConstructor(publicConstructor).invoke());
|
assertPredicateDoesNotMatch(reflection.onConstructorInvocation(publicConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorInvocationMatchesInvokePublicConstructors() {
|
void constructorInvocationMatchesInvokePublicConstructors() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
|
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).invoke());
|
assertPredicateMatches(reflection.onConstructorInvocation(publicConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorInvocationDoesNotMatchIntrospectDeclaredConstructors() {
|
void constructorInvocationDoesNotMatchIntrospectDeclaredConstructors() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
||||||
assertPredicateDoesNotMatch(reflection.onConstructor(publicConstructor).invoke());
|
assertPredicateDoesNotMatch(reflection.onConstructorInvocation(publicConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void constructorInvocationMatchesInvokeDeclaredConstructors() {
|
void constructorInvocationMatchesInvokeDeclaredConstructors() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||||
assertPredicateMatches(reflection.onConstructor(publicConstructor).invoke());
|
assertPredicateMatches(reflection.onConstructorInvocation(publicConstructor));
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void privateConstructorIntrospectionMatchesTypeHint() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class);
|
|
||||||
assertPredicateMatches(reflection.onConstructor(privateConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void privateConstructorIntrospectionMatchesConstructorHint() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint ->
|
|
||||||
typeHint.withConstructor(TypeReference.listOf(String.class), ExecutableMode.INTROSPECT));
|
|
||||||
assertPredicateMatches(reflection.onConstructor(privateConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void privateConstructorIntrospectionMatchesIntrospectDeclaredConstructors() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
|
||||||
assertPredicateMatches(reflection.onConstructor(privateConstructor).introspect());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void privateConstructorIntrospectionMatchesInvokeDeclaredConstructors() {
|
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
|
||||||
assertPredicateMatches(reflection.onConstructor(privateConstructor).introspect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void privateConstructorInvocationDoesNotMatchConstructorHint() {
|
void privateConstructorInvocationDoesNotMatchConstructorHint() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint ->
|
runtimeHints.reflection().registerType(SampleClass.class, typeHint ->
|
||||||
typeHint.withConstructor(TypeReference.listOf(String.class), ExecutableMode.INTROSPECT));
|
typeHint.withConstructor(TypeReference.listOf(String.class), ExecutableMode.INTROSPECT));
|
||||||
assertPredicateDoesNotMatch(reflection.onConstructor(privateConstructor).invoke());
|
assertPredicateDoesNotMatch(reflection.onConstructorInvocation(privateConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void privateConstructorInvocationMatchesConstructorInvocationHint() {
|
void privateConstructorInvocationMatchesConstructorInvocationHint() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, typeHint ->
|
runtimeHints.reflection().registerType(SampleClass.class, typeHint ->
|
||||||
typeHint.withConstructor(TypeReference.listOf(String.class), ExecutableMode.INVOKE));
|
typeHint.withConstructor(TypeReference.listOf(String.class), ExecutableMode.INVOKE));
|
||||||
assertPredicateMatches(reflection.onConstructor(privateConstructor).invoke());
|
assertPredicateMatches(reflection.onConstructorInvocation(privateConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void privateConstructorInvocationDoesNotMatchIntrospectPublicConstructors() {
|
void privateConstructorInvocationDoesNotMatchIntrospectPublicConstructors() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS);
|
||||||
assertPredicateDoesNotMatch(reflection.onConstructor(privateConstructor).invoke());
|
assertPredicateDoesNotMatch(reflection.onConstructorInvocation(privateConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void privateConstructorInvocationDoesNotMatchInvokePublicConstructors() {
|
void privateConstructorInvocationDoesNotMatchInvokePublicConstructors() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
|
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
|
||||||
assertPredicateDoesNotMatch(reflection.onConstructor(privateConstructor).invoke());
|
assertPredicateDoesNotMatch(reflection.onConstructorInvocation(privateConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void privateConstructorInvocationDoesNotMatchIntrospectDeclaredConstructors() {
|
void privateConstructorInvocationDoesNotMatchIntrospectDeclaredConstructors() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS);
|
||||||
assertPredicateDoesNotMatch(reflection.onConstructor(privateConstructor).invoke());
|
assertPredicateDoesNotMatch(reflection.onConstructorInvocation(privateConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void privateConstructorInvocationMatchesInvokeDeclaredConstructors() {
|
void privateConstructorInvocationMatchesInvokeDeclaredConstructors() {
|
||||||
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||||
assertPredicateMatches(reflection.onConstructor(privateConstructor).invoke());
|
assertPredicateMatches(reflection.onConstructorInvocation(privateConstructor));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -448,7 +381,7 @@ class ReflectionHintsPredicatesTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldFailForUnknownClass() {
|
void shouldFailForUnknownClass() {
|
||||||
assertThatThrownBy(() -> reflection.onField("com.example.DoesNotExist", "missingField"))
|
assertThatThrownBy(() -> reflection.onFieldInvocation("com.example.DoesNotExist", "missingField"))
|
||||||
.isInstanceOf(ClassNotFoundException.class);
|
.isInstanceOf(ClassNotFoundException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -49,13 +49,13 @@ class ObjectToObjectConverterRuntimeHintsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void javaSqlDateHasHints() throws NoSuchMethodException {
|
void javaSqlDateHasHints() throws NoSuchMethodException {
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(java.sql.Date.class, "toLocalDate")).accepts(this.hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(java.sql.Date.class, "toLocalDate")).accepts(this.hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(java.sql.Date.class.getMethod("valueOf", LocalDate.class))).accepts(this.hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(java.sql.Date.class.getMethod("valueOf", LocalDate.class))).accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void uriHasHints() throws NoSuchMethodException {
|
void uriHasHints() throws NoSuchMethodException {
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onConstructor(URI.class.getConstructor(String.class))).accepts(this.hints);
|
assertThat(RuntimeHintsPredicates.reflection().onType(URI.class)).accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -65,14 +65,14 @@ class BindingReflectionHintsRegistrarKotlinTests {
|
||||||
@Test
|
@Test
|
||||||
fun `Register reflection hints for Kotlin data class`() {
|
fun `Register reflection hints for Kotlin data class`() {
|
||||||
bindingRegistrar.registerReflectionHints(hints.reflection(), SampleDataClass::class.java)
|
bindingRegistrar.registerReflectionHints(hints.reflection(), SampleDataClass::class.java)
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "component1")).accepts(hints)
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleDataClass::class.java, "component1")).accepts(hints)
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "copy")).accepts(hints)
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleDataClass::class.java, "copy")).accepts(hints)
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "getName")).accepts(hints)
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleDataClass::class.java, "getName")).accepts(hints)
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "isNonNullable")).accepts(hints)
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleDataClass::class.java, "isNonNullable")).accepts(hints)
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleDataClass::class.java, "isNullable")).accepts(hints)
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleDataClass::class.java, "isNullable")).accepts(hints)
|
||||||
val copyDefault: Method = SampleDataClass::class.java.getMethod("copy\$default", SampleDataClass::class.java,
|
val copyDefault: Method = SampleDataClass::class.java.getMethod("copy\$default", SampleDataClass::class.java,
|
||||||
String::class.java, Boolean::class.javaPrimitiveType, Boolean::class.javaObjectType, Int::class.java, Object::class.java)
|
String::class.java, Boolean::class.javaPrimitiveType, Boolean::class.javaObjectType, Int::class.java, Object::class.java)
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(copyDefault)).accepts(hints)
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(copyDefault)).accepts(hints)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -47,7 +47,7 @@ class EmbeddedDatabaseFactoryRuntimeHintsTests {
|
||||||
@Test
|
@Test
|
||||||
void embeddedDataSourceProxyTypeHasHint() throws ClassNotFoundException {
|
void embeddedDataSourceProxyTypeHasHint() throws ClassNotFoundException {
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod("org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory$EmbeddedDataSourceProxy", "shutdown"))
|
.onMethodInvocation("org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory$EmbeddedDataSourceProxy", "shutdown"))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -123,14 +123,14 @@ class MessageMappingReflectiveProcessorTests {
|
||||||
void registerReflectiveHintsForMethodWithSubscribeMapping() throws NoSuchMethodException {
|
void registerReflectiveHintsForMethodWithSubscribeMapping() throws NoSuchMethodException {
|
||||||
Method method = SampleController.class.getDeclaredMethod("handleSubscribe");
|
Method method = SampleController.class.getDeclaredMethod("handleSubscribe");
|
||||||
processor.registerReflectionHints(hints.reflection(), method);
|
processor.registerReflectionHints(hints.reflection(), method);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleController.class, "handleSubscribe")).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleController.class, "handleSubscribe")).accepts(hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void registerReflectiveHintsForMethodWithMessageExceptionHandler() throws NoSuchMethodException {
|
void registerReflectiveHintsForMethodWithMessageExceptionHandler() throws NoSuchMethodException {
|
||||||
Method method = SampleController.class.getDeclaredMethod("handleIOException");
|
Method method = SampleController.class.getDeclaredMethod("handleIOException");
|
||||||
processor.registerReflectionHints(hints.reflection(), method);
|
processor.registerReflectionHints(hints.reflection(), method);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(SampleController.class, "handleIOException")).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(SampleController.class, "handleIOException")).accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(IOException.class)).accepts(hints);
|
assertThat(RuntimeHintsPredicates.reflection().onType(IOException.class)).accepts(hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -50,19 +50,19 @@ class RSocketExchangeReflectiveProcessorTests {
|
||||||
processor.registerReflectionHints(hints.reflection(), method);
|
processor.registerReflectionHints(hints.reflection(), method);
|
||||||
|
|
||||||
assertThat(reflection().onType(SampleService.class)).accepts(hints);
|
assertThat(reflection().onType(SampleService.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(SampleService.class, "get")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(SampleService.class, "get")).accepts(hints);
|
||||||
assertThat(reflection().onType(Response.class)).accepts(hints);
|
assertThat(reflection().onType(Response.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Response.class, "getMessage")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Response.class, "getMessage")).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Response.class, "setMessage")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Response.class, "setMessage")).accepts(hints);
|
||||||
assertThat(reflection().onType(Request.class)).accepts(hints);
|
assertThat(reflection().onType(Request.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Request.class, "getMessage")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Request.class, "getMessage")).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Request.class, "setMessage")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Request.class, "setMessage")).accepts(hints);
|
||||||
assertThat(reflection().onType(Variable.class)).accepts(hints);
|
assertThat(reflection().onType(Variable.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Variable.class, "getValue")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Variable.class, "getValue")).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Variable.class, "setValue")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Variable.class, "setValue")).accepts(hints);
|
||||||
assertThat(reflection().onType(Metadata.class)).accepts(hints);
|
assertThat(reflection().onType(Metadata.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Metadata.class, "getValue")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Metadata.class, "getValue")).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Metadata.class, "setValue")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Metadata.class, "setValue")).accepts(hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -60,7 +60,7 @@ class EntityManagerRuntimeHintsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void entityManagerFactoryHasReflectionHints() {
|
void entityManagerFactoryHasReflectionHints() {
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(EntityManagerFactory.class, "getCriteriaBuilder")).accepts(this.hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(EntityManagerFactory.class, "getCriteriaBuilder")).accepts(this.hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(EntityManagerFactory.class, "getMetamodel")).accepts(this.hints);
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(EntityManagerFactory.class, "getMetamodel")).accepts(this.hints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -93,7 +93,7 @@ class PersistenceManagedTypesBeanRegistrationAotProcessorTests {
|
||||||
.accepts(hints);
|
.accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(Employee.class)
|
assertThat(RuntimeHintsPredicates.reflection().onType(Employee.class)
|
||||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_FIELDS)).accepts(hints);
|
.withMemberCategories(MemberCategory.INVOKE_DECLARED_FIELDS)).accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onMethod(Employee.class, "preRemove"))
|
assertThat(RuntimeHintsPredicates.reflection().onMethodInvocation(Employee.class, "preRemove"))
|
||||||
.accepts(hints);
|
.accepts(hints);
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onType(EmployeeId.class)
|
assertThat(RuntimeHintsPredicates.reflection().onType(EmployeeId.class)
|
||||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_FIELDS)).accepts(hints);
|
.withMemberCategories(MemberCategory.INVOKE_DECLARED_FIELDS)).accepts(hints);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -125,7 +125,7 @@ class InjectionCodeGeneratorTests {
|
||||||
Field field = ReflectionUtils.findField(bean.getClass(), "age");
|
Field field = ReflectionUtils.findField(bean.getClass(), "age");
|
||||||
createGenerator(TEST_TARGET).generateInjectionCode(
|
createGenerator(TEST_TARGET).generateInjectionCode(
|
||||||
field, INSTANCE_VARIABLE, CodeBlock.of("$L", 123));
|
field, INSTANCE_VARIABLE, CodeBlock.of("$L", 123));
|
||||||
assertThat(RuntimeHintsPredicates.reflection().onField(TestBean.class, "age"))
|
assertThat(RuntimeHintsPredicates.reflection().onType(TestBean.class))
|
||||||
.accepts(this.hints);
|
.accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ class InjectionCodeGeneratorTests {
|
||||||
createGenerator(TEST_TARGET).generateInjectionCode(
|
createGenerator(TEST_TARGET).generateInjectionCode(
|
||||||
method, INSTANCE_VARIABLE, CodeBlock.of("$L", 123));
|
method, INSTANCE_VARIABLE, CodeBlock.of("$L", 123));
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(TestBeanWithPrivateMethod.class, "setAge").invoke()).accepts(this.hints);
|
.onMethodInvocation(TestBeanWithPrivateMethod.class, "setAge")).accepts(this.hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
private InjectionCodeGenerator createGenerator(ClassName target) {
|
private InjectionCodeGenerator createGenerator(ClassName target) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -56,7 +56,7 @@ class DeclarativeRuntimeHintsTests extends AbstractAotTests {
|
||||||
// @RegisterReflectionForBinding
|
// @RegisterReflectionForBinding
|
||||||
assertReflectionRegistered(SampleClassWithGetter.class);
|
assertReflectionRegistered(SampleClassWithGetter.class);
|
||||||
assertReflectionRegistered(String.class);
|
assertReflectionRegistered(String.class);
|
||||||
assertThat(reflection().onMethod(SampleClassWithGetter.class, "getName")).accepts(this.runtimeHints);
|
assertThat(reflection().onMethodInvocation(SampleClassWithGetter.class, "getName")).accepts(this.runtimeHints);
|
||||||
|
|
||||||
// @ImportRuntimeHints
|
// @ImportRuntimeHints
|
||||||
assertThat(resource().forResource("org/example/config/enigma.txt")).accepts(this.runtimeHints);
|
assertThat(resource().forResource("org/example/config/enigma.txt")).accepts(this.runtimeHints);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2024 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -290,7 +290,7 @@ class TestContextAotGeneratorIntegrationTests extends AbstractAotTests {
|
||||||
).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS));
|
).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_DECLARED_CONSTRUCTORS));
|
||||||
|
|
||||||
// @TestBean(methodName = <fully-qualified method name>)
|
// @TestBean(methodName = <fully-qualified method name>)
|
||||||
assertThat(reflection().onMethod(GreetingServiceFactory.class, "createEnigmaGreetingService"))
|
assertThat(reflection().onMethodInvocation(GreetingServiceFactory.class, "createEnigmaGreetingService"))
|
||||||
.accepts(runtimeHints);
|
.accepts(runtimeHints);
|
||||||
|
|
||||||
// GenericApplicationContext.preDetermineBeanTypes() should have registered proxy
|
// GenericApplicationContext.preDetermineBeanTypes() should have registered proxy
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -53,7 +53,7 @@ class ProblemDetailRuntimeHintsTests {
|
||||||
void getterMethodsShouldHaveReflectionHints() {
|
void getterMethodsShouldHaveReflectionHints() {
|
||||||
for (String methodName : METHOD_NAMES) {
|
for (String methodName : METHOD_NAMES) {
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(ProblemDetail.class, methodName)).accepts(this.hints);
|
.onMethodInvocation(ProblemDetail.class, methodName)).accepts(this.hints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class ProblemDetailRuntimeHintsTests {
|
||||||
void mixinShouldHaveReflectionHints() {
|
void mixinShouldHaveReflectionHints() {
|
||||||
for (String methodName : METHOD_NAMES) {
|
for (String methodName : METHOD_NAMES) {
|
||||||
assertThat(RuntimeHintsPredicates.reflection()
|
assertThat(RuntimeHintsPredicates.reflection()
|
||||||
.onMethod(ProblemDetailJacksonXmlMixin.class, methodName)).accepts(this.hints);
|
.onMethodInvocation(ProblemDetailJacksonXmlMixin.class, methodName)).accepts(this.hints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2025 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -43,10 +43,10 @@ class HttpExchangeReflectiveProcessorTests {
|
||||||
Method method = SampleService.class.getDeclaredMethod("get");
|
Method method = SampleService.class.getDeclaredMethod("get");
|
||||||
processor.registerReflectionHints(hints.reflection(), method);
|
processor.registerReflectionHints(hints.reflection(), method);
|
||||||
assertThat(reflection().onType(SampleService.class)).accepts(hints);
|
assertThat(reflection().onType(SampleService.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(SampleService.class, "get")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(SampleService.class, "get")).accepts(hints);
|
||||||
assertThat(reflection().onType(Response.class)).accepts(hints);
|
assertThat(reflection().onType(Response.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Response.class, "getMessage")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Response.class, "getMessage")).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Response.class, "setMessage")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Response.class, "setMessage")).accepts(hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -54,10 +54,10 @@ class HttpExchangeReflectiveProcessorTests {
|
||||||
Method method = SampleService.class.getDeclaredMethod("post", Request.class);
|
Method method = SampleService.class.getDeclaredMethod("post", Request.class);
|
||||||
processor.registerReflectionHints(hints.reflection(), method);
|
processor.registerReflectionHints(hints.reflection(), method);
|
||||||
assertThat(reflection().onType(SampleService.class)).accepts(hints);
|
assertThat(reflection().onType(SampleService.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(SampleService.class, "post")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(SampleService.class, "post")).accepts(hints);
|
||||||
assertThat(reflection().onType(Request.class)).accepts(hints);
|
assertThat(reflection().onType(Request.class)).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Request.class, "getMessage")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Request.class, "getMessage")).accepts(hints);
|
||||||
assertThat(reflection().onMethod(Request.class, "setMessage")).accepts(hints);
|
assertThat(reflection().onMethodInvocation(Request.class, "setMessage")).accepts(hints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue