Merge branch '6.0.x'

This commit is contained in:
Brian Clozel
2023-09-15 17:54:06 +02:00
3 changed files with 35 additions and 33 deletions

View File

@@ -408,15 +408,15 @@ class InstrumentedMethodTests {
} }
@Test @Test
void classGetMethodShouldMatchIntrospectDeclaredMethodsHint() { void classGetMethodShouldNotMatchIntrospectDeclaredMethodsHint() {
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_METHODS); hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_DECLARED_METHODS);
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod); assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
} }
@Test @Test
void classGetMethodShouldMatchInvokeDeclaredMethodsHint() { void classGetMethodShouldNotMatchInvokeDeclaredMethodsHint() {
hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_METHODS); hints.reflection().registerType(String.class, MemberCategory.INVOKE_DECLARED_METHODS);
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod); assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETMETHOD, this.stringGetToStringMethod);
} }
@Test @Test
@@ -544,9 +544,9 @@ class InstrumentedMethodTests {
} }
@Test @Test
void classGetFieldShouldMatchDeclaredFieldsHint() { void classGetFieldShouldNotMatchDeclaredFieldsHint() {
hints.reflection().registerType(PublicField.class, MemberCategory.DECLARED_FIELDS); hints.reflection().registerType(PublicField.class, MemberCategory.DECLARED_FIELDS);
assertThatInvocationMatches(InstrumentedMethod.CLASS_GETFIELD, this.getPublicField); assertThatInvocationDoesNotMatch(InstrumentedMethod.CLASS_GETFIELD, this.getPublicField);
} }
@Test @Test

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 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.
@@ -274,19 +274,6 @@ public class ReflectionHintsPredicates {
return this; return this;
} }
@Override
public boolean test(RuntimeHints runtimeHints) {
return (new TypeHintPredicate(TypeReference.of(this.executable.getDeclaringClass()))
.withAnyMemberCategory(getPublicMemberCategories())
.and(hints -> Modifier.isPublic(this.executable.getModifiers())))
.or(new TypeHintPredicate(TypeReference.of(this.executable.getDeclaringClass())).withAnyMemberCategory(getDeclaredMemberCategories()))
.or(exactMatch()).test(runtimeHints);
}
abstract MemberCategory[] getPublicMemberCategories();
abstract MemberCategory[] getDeclaredMemberCategories();
abstract Predicate<RuntimeHints> exactMatch(); abstract Predicate<RuntimeHints> exactMatch();
/** /**
@@ -309,6 +296,14 @@ public class ReflectionHintsPredicates {
} }
@Override @Override
public boolean test(RuntimeHints runtimeHints) {
return (new TypeHintPredicate(TypeReference.of(this.executable.getDeclaringClass()))
.withAnyMemberCategory(getPublicMemberCategories())
.and(hints -> Modifier.isPublic(this.executable.getModifiers())))
.or(new TypeHintPredicate(TypeReference.of(this.executable.getDeclaringClass())).withAnyMemberCategory(getDeclaredMemberCategories()))
.or(exactMatch()).test(runtimeHints);
}
MemberCategory[] getPublicMemberCategories() { MemberCategory[] getPublicMemberCategories() {
if (this.executableMode == ExecutableMode.INTROSPECT) { if (this.executableMode == ExecutableMode.INTROSPECT) {
return new MemberCategory[] { MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS, return new MemberCategory[] { MemberCategory.INTROSPECT_PUBLIC_CONSTRUCTORS,
@@ -317,7 +312,6 @@ public class ReflectionHintsPredicates {
return new MemberCategory[] { MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS }; return new MemberCategory[] { MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS };
} }
@Override
MemberCategory[] getDeclaredMemberCategories() { MemberCategory[] getDeclaredMemberCategories() {
if (this.executableMode == ExecutableMode.INTROSPECT) { if (this.executableMode == ExecutableMode.INTROSPECT) {
return new MemberCategory[] { MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS, return new MemberCategory[] { MemberCategory.INTROSPECT_DECLARED_CONSTRUCTORS,
@@ -344,6 +338,16 @@ public class ReflectionHintsPredicates {
} }
@Override @Override
public boolean test(RuntimeHints runtimeHints) {
return (new TypeHintPredicate(TypeReference.of(this.executable.getDeclaringClass()))
.withAnyMemberCategory(getPublicMemberCategories())
.and(hints -> Modifier.isPublic(this.executable.getModifiers())))
.or(new TypeHintPredicate(TypeReference.of(this.executable.getDeclaringClass()))
.withAnyMemberCategory(getDeclaredMemberCategories())
.and(hints -> !Modifier.isPublic(this.executable.getModifiers())))
.or(exactMatch()).test(runtimeHints);
}
MemberCategory[] getPublicMemberCategories() { MemberCategory[] getPublicMemberCategories() {
if (this.executableMode == ExecutableMode.INTROSPECT) { if (this.executableMode == ExecutableMode.INTROSPECT) {
return new MemberCategory[] { MemberCategory.INTROSPECT_PUBLIC_METHODS, return new MemberCategory[] { MemberCategory.INTROSPECT_PUBLIC_METHODS,
@@ -352,7 +356,6 @@ public class ReflectionHintsPredicates {
return new MemberCategory[] { MemberCategory.INVOKE_PUBLIC_METHODS }; return new MemberCategory[] { MemberCategory.INVOKE_PUBLIC_METHODS };
} }
@Override
MemberCategory[] getDeclaredMemberCategories() { MemberCategory[] getDeclaredMemberCategories() {
if (this.executableMode == ExecutableMode.INTROSPECT) { if (this.executableMode == ExecutableMode.INTROSPECT) {
@@ -392,8 +395,7 @@ public class ReflectionHintsPredicates {
private boolean memberCategoryMatch(TypeHint typeHint) { private boolean memberCategoryMatch(TypeHint typeHint) {
if (Modifier.isPublic(this.field.getModifiers())) { if (Modifier.isPublic(this.field.getModifiers())) {
return typeHint.getMemberCategories().contains(MemberCategory.PUBLIC_FIELDS) || return typeHint.getMemberCategories().contains(MemberCategory.PUBLIC_FIELDS);
typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS);
} }
else { else {
return typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS); return typeHint.getMemberCategories().contains(MemberCategory.DECLARED_FIELDS);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 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.
@@ -329,15 +329,15 @@ class ReflectionHintsPredicatesTests {
} }
@Test @Test
void methodIntrospectionMatchesIntrospectDeclaredMethods() { void methodIntrospectionDoesNotMatchIntrospectDeclaredMethods() {
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_DECLARED_METHODS); runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INTROSPECT_DECLARED_METHODS);
assertPredicateMatches(reflection.onMethod(SampleClass.class, "publicMethod").introspect()); assertPredicateDoesNotMatch(reflection.onMethod(SampleClass.class, "publicMethod").introspect());
} }
@Test @Test
void methodIntrospectionMatchesInvokeDeclaredMethods() { void methodIntrospectionDoesNotMatchInvokeDeclaredMethods() {
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_METHODS); runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_METHODS);
assertPredicateMatches(reflection.onMethod(SampleClass.class, "publicMethod").introspect()); assertPredicateDoesNotMatch(reflection.onMethod(SampleClass.class, "publicMethod").introspect());
} }
@Test @Test
@@ -373,9 +373,9 @@ class ReflectionHintsPredicatesTests {
} }
@Test @Test
void methodInvocationMatchesInvokeDeclaredMethods() { void methodInvocationDoesNotMatchInvokeDeclaredMethods() {
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_METHODS); runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.INVOKE_DECLARED_METHODS);
assertPredicateMatches(reflection.onMethod(SampleClass.class, "publicMethod").invoke()); assertPredicateDoesNotMatch(reflection.onMethod(SampleClass.class, "publicMethod").invoke());
} }
@Test @Test
@@ -482,9 +482,9 @@ class ReflectionHintsPredicatesTests {
} }
@Test @Test
void fieldReflectionMatchesDeclaredFieldsHint() { void fieldReflectionDoesNotMatchDeclaredFieldsHint() {
runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.DECLARED_FIELDS); runtimeHints.reflection().registerType(SampleClass.class, MemberCategory.DECLARED_FIELDS);
assertPredicateMatches(reflection.onField(SampleClass.class, "publicField")); assertPredicateDoesNotMatch(reflection.onField(SampleClass.class, "publicField"));
} }
@Test @Test