Simplify field and method filter creation.
Update javadoc and reformat aot.factories. Original Pull Request: #2624
This commit is contained in:
committed by
Christoph Strobl
parent
423edd21ea
commit
e71f7c2bd6
@@ -35,8 +35,8 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* The context in which the AOT processing happens. Grants access to the {@link ConfigurableListableBeanFactory
|
||||
* beanFactory} and {@link ClassLoader}. Holds a few convenience methods to check if a type
|
||||
* {@link #isTypePresent(String) is present} and allows resolution of them throug {@link TypeIntrospector} and
|
||||
* {@link IntrospectedBeanDefinition}.
|
||||
* {@link TypeIntrospector#isTypePresent() is present} and allows resolution of them through {@link TypeIntrospector}
|
||||
* and {@link IntrospectedBeanDefinition}.
|
||||
* <p>
|
||||
* Mainly for internal use within the framework.
|
||||
*
|
||||
|
||||
@@ -44,6 +44,7 @@ public abstract class Predicates {
|
||||
public static final Predicate<Member> IS_PROTECTED = member -> Modifier.isProtected(member.getModifiers());
|
||||
public static final Predicate<Member> IS_PUBLIC = member -> Modifier.isPublic(member.getModifiers());
|
||||
public static final Predicate<Member> IS_SYNTHETIC = Member::isSynthetic;
|
||||
public static final Predicate<Member> IS_STATIC = member -> Modifier.isStatic(member.getModifiers());
|
||||
|
||||
public static final Predicate<Method> IS_BRIDGE_METHOD = Method::isBridge;
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ public class TypeCollector {
|
||||
private static final Log logger = LogFactory.getLog(TypeCollector.class);
|
||||
|
||||
static final Set<String> EXCLUDED_DOMAINS = new HashSet<>(Arrays.asList("java", "sun.", "jdk.", "reactor.",
|
||||
"kotlinx.", "kotlin.", "org.springframework.core.", "org.springframework.boot."));
|
||||
"kotlinx.", "kotlin.", "org.springframework.core.", "org.springframework.data.mapping.",
|
||||
"org.springframework.data.repository.", "org.springframework.boot.", "org.springframework.core."));
|
||||
|
||||
private final Predicate<Class<?>> excludedDomainsFilter = type -> {
|
||||
String packageName = type.getPackageName();
|
||||
@@ -60,34 +61,9 @@ public class TypeCollector {
|
||||
|
||||
private Predicate<Class<?>> typeFilter = excludedDomainsFilter;
|
||||
|
||||
private final Predicate<Method> methodFilter = method -> {
|
||||
private final Predicate<Method> methodFilter = createMethodFilter();
|
||||
|
||||
// TODO: Eagerly construct predicate objects to avoid object allocations during test(…)
|
||||
Predicate<Method> excludedDomainsPredicate = methodToTest -> excludedDomainsFilter
|
||||
.test(methodToTest.getDeclaringClass());
|
||||
|
||||
Predicate<Method> excludedMethodsPredicate = Predicates.IS_BRIDGE_METHOD //
|
||||
.or(Predicates.IS_OBJECT_MEMBER) //
|
||||
.or(Predicates.IS_HIBERNATE_MEMBER) //
|
||||
.or(Predicates.IS_ENUM_MEMBER) //
|
||||
.or(Predicates.IS_NATIVE) //
|
||||
.or(Predicates.IS_PRIVATE) //
|
||||
.or(Predicates.IS_PROTECTED) //
|
||||
.or(Predicates.IS_SYNTHETIC) //
|
||||
.or(excludedDomainsPredicate.negate()); //
|
||||
|
||||
return !excludedMethodsPredicate.test(method);
|
||||
};
|
||||
|
||||
private Predicate<Field> fieldFilter = field -> {
|
||||
|
||||
// TODO: Eagerly construct predicate objects to avoid object allocations during test(…)
|
||||
Predicate<Member> excludedFieldPredicate = Predicates.IS_HIBERNATE_MEMBER //
|
||||
.or(Predicates.IS_SYNTHETIC) //
|
||||
.or(Predicates.IS_JAVA);
|
||||
|
||||
return !excludedFieldPredicate.test(field);
|
||||
};
|
||||
private Predicate<Field> fieldFilter = createFieldFilter();
|
||||
|
||||
public TypeCollector filterFields(Predicate<Field> filter) {
|
||||
this.fieldFilter = filter.and(filter);
|
||||
@@ -198,6 +174,35 @@ public class TypeCollector {
|
||||
return discoveredTypes;
|
||||
}
|
||||
|
||||
private Predicate<Method> createMethodFilter() {
|
||||
|
||||
Predicate<Method> excludedDomainsPredicate = methodToTest -> excludedDomainsFilter
|
||||
.test(methodToTest.getDeclaringClass());
|
||||
|
||||
Predicate<Method> excludedMethodsPredicate = Predicates.IS_BRIDGE_METHOD //
|
||||
.or(Predicates.IS_STATIC) //
|
||||
.or(Predicates.IS_SYNTHETIC) //
|
||||
.or(Predicates.IS_NATIVE) //
|
||||
.or(Predicates.IS_PRIVATE) //
|
||||
.or(Predicates.IS_PROTECTED) //
|
||||
.or(Predicates.IS_OBJECT_MEMBER) //
|
||||
.or(Predicates.IS_HIBERNATE_MEMBER) //
|
||||
.or(Predicates.IS_ENUM_MEMBER) //
|
||||
.or(excludedDomainsPredicate.negate()); //
|
||||
|
||||
return excludedMethodsPredicate.negate();
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Predicate<Field> createFieldFilter() {
|
||||
|
||||
Predicate<Member> excludedFieldPredicate = Predicates.IS_HIBERNATE_MEMBER //
|
||||
.or(Predicates.IS_SYNTHETIC) //
|
||||
.or(Predicates.IS_JAVA);
|
||||
|
||||
return (Predicate) excludedFieldPredicate.negate();
|
||||
}
|
||||
|
||||
public static class ReachableTypes {
|
||||
|
||||
private final Iterable<Class<?>> roots;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=\
|
||||
org.springframework.data.aot.SpringDataBeanFactoryInitializationAotProcessor
|
||||
|
||||
org.springframework.aot.hint.RuntimeHintsRegistrar=\
|
||||
org.springframework.data.aot.hint.RepositoryRuntimeHints
|
||||
|
||||
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
|
||||
org.springframework.data.aot.AuditingBeanRegistrationAotProcessor
|
||||
|
||||
Reference in New Issue
Block a user