Browse Source

Polishing.

Rename TypeCollectorPredicateProvider -> TypeCollectorFilters
Update javadoc and deprecate jpa specific predicate.

Original Pull Request: #3363
pull/3368/head
Christoph Strobl 3 months ago
parent
commit
a5da12ffad
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 2
      src/main/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessor.java
  2. 8
      src/main/java/org/springframework/data/util/Predicates.java
  3. 16
      src/main/java/org/springframework/data/util/TypeCollector.java
  4. 5
      src/main/resources/META-INF/spring/aot.factories

2
src/main/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessor.java

@ -135,6 +135,7 @@ public class ManagedTypesBeanRegistrationAotProcessor implements BeanRegistratio @@ -135,6 +135,7 @@ public class ManagedTypesBeanRegistrationAotProcessor implements BeanRegistratio
* Customization hook to configure {@link TypeCollector}.
*
* @return a {@link Consumer} to customize the {@link TypeCollector}, must not be {@literal null}.
* @since 4.0
*/
protected Consumer<TypeCollector> typeCollectorCustomizer() {
return typeCollector -> {};
@ -168,6 +169,7 @@ public class ManagedTypesBeanRegistrationAotProcessor implements BeanRegistratio @@ -168,6 +169,7 @@ public class ManagedTypesBeanRegistrationAotProcessor implements BeanRegistratio
*
* @param type the class to configure the contribution for.
* @param aotContext AOT context for type configuration.
* @since 4.0
*/
protected void configureTypeContribution(Class<?> type, AotContext aotContext) {
aotContext.typeConfiguration(type, config -> config.forDataBinding().contributeAccessors().forQuerydsl());

8
src/main/java/org/springframework/data/util/Predicates.java

@ -33,11 +33,9 @@ import org.springframework.util.Assert; @@ -33,11 +33,9 @@ import org.springframework.util.Assert;
public interface Predicates {
Predicate<Member> IS_ENUM_MEMBER = member -> member.getDeclaringClass().isEnum();
Predicate<Member> IS_HIBERNATE_MEMBER = member -> member.getName().startsWith("$$_hibernate"); // this
// should
// go
// into
// JPA
@Deprecated(since = "4.0", forRemoval = true)
Predicate<Member> IS_HIBERNATE_MEMBER = member -> member.getName().startsWith("$$_hibernate");
Predicate<Member> IS_OBJECT_MEMBER = member -> Object.class.equals(member.getDeclaringClass());
Predicate<Member> IS_JAVA = member -> member.getDeclaringClass().getPackageName().startsWith("java.");
Predicate<Member> IS_NATIVE = member -> Modifier.isNative(member.getModifiers());

16
src/main/java/org/springframework/data/util/TypeCollector.java

@ -52,7 +52,7 @@ import org.springframework.util.ReflectionUtils; @@ -52,7 +52,7 @@ import org.springframework.util.ReflectionUtils;
* that returns {@code false}. Filters are {@link Predicate#and(Predicate) combined} so that multiple filters can be
* taken into account. A type/field/method must pass all filters to be considered for further inspection.
* <p>
* The collector uses {@link AotServices} to discover implementations of {@link TypeCollectorPredicateProvider} so that
* The collector uses {@link AotServices} to discover implementations of {@link TypeCollectorFilters} so that
* components using {@link TypeCollector} can contribute their own filtering logic to exclude types, fields, and methods
* from being inspected.
*
@ -66,8 +66,8 @@ public class TypeCollector { @@ -66,8 +66,8 @@ public class TypeCollector {
private static final Log logger = LogFactory.getLog(TypeCollector.class);
private static final AotServices<TypeCollectorPredicateProvider> providers = AotServices.factories()
.load(TypeCollectorPredicateProvider.class);
private static final AotServices<TypeCollectorFilters> providers = AotServices.factories()
.load(TypeCollectorFilters.class);
private Predicate<Class<?>> typeFilter = Predicates.isTrue();
@ -76,7 +76,7 @@ public class TypeCollector { @@ -76,7 +76,7 @@ public class TypeCollector {
private Predicate<Field> fieldFilter = Predicates.isTrue();
/**
* Create a new {@link TypeCollector} applying all {@link TypeCollectorPredicateProvider} discovered through
* Create a new {@link TypeCollector} applying all {@link TypeCollectorFilters} discovered through
* {@link AotServices}.
*/
public TypeCollector() {
@ -105,6 +105,7 @@ public class TypeCollector { @@ -105,6 +105,7 @@ public class TypeCollector {
*
* @param filter filter predicate matching a {@link Class}.
* @return {@code this} TypeCollector instance.
* @since 4.0
*/
@Contract("_ -> this")
public TypeCollector filterMethods(Predicate<Method> filter) {
@ -117,6 +118,7 @@ public class TypeCollector { @@ -117,6 +118,7 @@ public class TypeCollector {
*
* @param filter filter predicate matching a {@link Class}.
* @return {@code this} TypeCollector instance.
* @since 4.0
*/
@Contract("_ -> this")
public TypeCollector filterFields(Predicate<Field> filter) {
@ -351,7 +353,7 @@ public class TypeCollector { @@ -351,7 +353,7 @@ public class TypeCollector {
* @author Mark Paluch
* @since 4.0
*/
public interface TypeCollectorPredicateProvider {
public interface TypeCollectorFilters {
/**
* Return a predicate to filter types.
@ -383,12 +385,12 @@ public class TypeCollector { @@ -383,12 +385,12 @@ public class TypeCollector {
}
/**
* Default implementation of {@link TypeCollectorPredicateProvider} that excludes types from certain packages and
* Default implementation of {@link TypeCollectorFilters} that excludes types from certain packages and
* filters out unwanted fields and methods.
*
* @since 4.0
*/
private static class DefaultTypeCollectorPredicateProvider implements TypeCollectorPredicateProvider {
private static class DefaultTypeCollectorFilters implements TypeCollectorFilters {
private static final Set<String> EXCLUDED_DOMAINS = Set.of("java", "sun.", "jdk.", "reactor.", "kotlinx.",
"kotlin.", "org.springframework.core.", "org.springframework.data.mapping.",

5
src/main/resources/META-INF/spring/aot.factories

@ -8,5 +8,6 @@ org.springframework.aot.hint.RuntimeHintsRegistrar=\ @@ -8,5 +8,6 @@ org.springframework.aot.hint.RuntimeHintsRegistrar=\
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
org.springframework.data.aot.AuditingBeanRegistrationAotProcessor
org.springframework.data.util.TypeCollector$TypeCollectorPredicateProvider=\
org.springframework.data.util.TypeCollector$DefaultTypeCollectorPredicateProvider
org.springframework.data.util.TypeCollector$TypeCollectorFilters=\
org.springframework.data.util.TypeCollector$DefaultTypeCollectorFilters

Loading…
Cancel
Save