Skip to content

Commit

Permalink
Restore support for package private ReflectiveProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Aug 18, 2022
1 parent d6afa8d commit eac616a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ private Entry createEntry(AnnotatedElement element) {

private ReflectiveProcessor instantiateClass(Class<? extends ReflectiveProcessor> type) {
try {
return type.getDeclaredConstructor().newInstance();
Constructor<? extends ReflectiveProcessor> constructor = type.getDeclaredConstructor();
ReflectionUtils.makeAccessible(constructor);
return constructor.newInstance();
}
catch (Exception ex) {
throw new IllegalStateException("Failed to instantiate " + type, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;

import org.junit.jupiter.api.Test;

import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.ReflectionHints;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.TypeReference;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
Expand Down Expand Up @@ -121,6 +124,16 @@ void shouldProcessAnnotationOnInheritedClass() {
.satisfies(methodHint -> assertThat(methodHint.getName()).isEqualTo("managed")));
}

@Test
void shouldInvokeCustomProcessor() {
process(SampleCustomProcessor.class);
assertThat(RuntimeHintsPredicates.reflection()
.onMethod(SampleCustomProcessor.class, "managed")).accepts(this.runtimeHints);
assertThat(RuntimeHintsPredicates.reflection().onType(String.class)
.withMemberCategory(MemberCategory.INVOKE_DECLARED_METHODS)).accepts(this.runtimeHints);

}

private void process(Class<?> beanClass) {
this.registrar.registerRuntimeHints(this.runtimeHints, beanClass);
}
Expand Down Expand Up @@ -252,4 +265,24 @@ void managed() {
}
}

static class SampleCustomProcessor {

@Reflective(TestReflectiveProcessor.class)
public String managed() {
return "test";
}

}

private static class TestReflectiveProcessor extends SimpleReflectiveProcessor {

@Override
protected void registerMethodHint(ReflectionHints hints, Method method) {
super.registerMethodHint(hints, method);
hints.registerType(method.getReturnType(), type ->
type.withMembers(MemberCategory.INVOKE_DECLARED_METHODS));
}

}

}

0 comments on commit eac616a

Please sign in to comment.