Browse Source

Simplify field and method filter creation.

Update javadoc and reformat aot.factories.

Original Pull Request: #2624
pull/2652/head
Mark Paluch 4 years ago committed by Christoph Strobl
parent
commit
e71f7c2bd6
No known key found for this signature in database
GPG Key ID: 8CC1AB53391458C8
  1. 4
      src/main/java/org/springframework/data/aot/AotContext.java
  2. 1
      src/main/java/org/springframework/data/aot/Predicates.java
  3. 61
      src/main/java/org/springframework/data/aot/TypeCollector.java
  4. 2
      src/main/resources/META-INF/spring/aot.factories

4
src/main/java/org/springframework/data/aot/AotContext.java

@ -35,8 +35,8 @@ import org.springframework.util.Assert; @@ -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.
*

1
src/main/java/org/springframework/data/aot/Predicates.java

@ -44,6 +44,7 @@ public abstract class Predicates { @@ -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;

61
src/main/java/org/springframework/data/aot/TypeCollector.java

@ -51,7 +51,8 @@ public class TypeCollector { @@ -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 { @@ -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 { @@ -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;

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

@ -1,6 +1,8 @@ @@ -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

Loading…
Cancel
Save