Skip to content

Commit e71f7c2

Browse files
mp911dechristophstrobl
authored andcommitted
Simplify field and method filter creation.
Update javadoc and reformat aot.factories. Original Pull Request: #2624
1 parent 423edd2 commit e71f7c2

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
/**
3636
* The context in which the AOT processing happens. Grants access to the {@link ConfigurableListableBeanFactory
3737
* beanFactory} and {@link ClassLoader}. Holds a few convenience methods to check if a type
38-
* {@link #isTypePresent(String) is present} and allows resolution of them throug {@link TypeIntrospector} and
39-
* {@link IntrospectedBeanDefinition}.
38+
* {@link TypeIntrospector#isTypePresent() is present} and allows resolution of them through {@link TypeIntrospector}
39+
* and {@link IntrospectedBeanDefinition}.
4040
* <p>
4141
* Mainly for internal use within the framework.
4242
*

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

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public abstract class Predicates {
4444
public static final Predicate<Member> IS_PROTECTED = member -> Modifier.isProtected(member.getModifiers());
4545
public static final Predicate<Member> IS_PUBLIC = member -> Modifier.isPublic(member.getModifiers());
4646
public static final Predicate<Member> IS_SYNTHETIC = Member::isSynthetic;
47+
public static final Predicate<Member> IS_STATIC = member -> Modifier.isStatic(member.getModifiers());
4748

4849
public static final Predicate<Method> IS_BRIDGE_METHOD = Method::isBridge;
4950

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

+33-28
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public class TypeCollector {
5151
private static final Log logger = LogFactory.getLog(TypeCollector.class);
5252

5353
static final Set<String> EXCLUDED_DOMAINS = new HashSet<>(Arrays.asList("java", "sun.", "jdk.", "reactor.",
54-
"kotlinx.", "kotlin.", "org.springframework.core.", "org.springframework.boot."));
54+
"kotlinx.", "kotlin.", "org.springframework.core.", "org.springframework.data.mapping.",
55+
"org.springframework.data.repository.", "org.springframework.boot.", "org.springframework.core."));
5556

5657
private final Predicate<Class<?>> excludedDomainsFilter = type -> {
5758
String packageName = type.getPackageName();
@@ -60,34 +61,9 @@ public class TypeCollector {
6061

6162
private Predicate<Class<?>> typeFilter = excludedDomainsFilter;
6263

63-
private final Predicate<Method> methodFilter = method -> {
64+
private final Predicate<Method> methodFilter = createMethodFilter();
6465

65-
// TODO: Eagerly construct predicate objects to avoid object allocations during test(…)
66-
Predicate<Method> excludedDomainsPredicate = methodToTest -> excludedDomainsFilter
67-
.test(methodToTest.getDeclaringClass());
68-
69-
Predicate<Method> excludedMethodsPredicate = Predicates.IS_BRIDGE_METHOD //
70-
.or(Predicates.IS_OBJECT_MEMBER) //
71-
.or(Predicates.IS_HIBERNATE_MEMBER) //
72-
.or(Predicates.IS_ENUM_MEMBER) //
73-
.or(Predicates.IS_NATIVE) //
74-
.or(Predicates.IS_PRIVATE) //
75-
.or(Predicates.IS_PROTECTED) //
76-
.or(Predicates.IS_SYNTHETIC) //
77-
.or(excludedDomainsPredicate.negate()); //
78-
79-
return !excludedMethodsPredicate.test(method);
80-
};
81-
82-
private Predicate<Field> fieldFilter = field -> {
83-
84-
// TODO: Eagerly construct predicate objects to avoid object allocations during test(…)
85-
Predicate<Member> excludedFieldPredicate = Predicates.IS_HIBERNATE_MEMBER //
86-
.or(Predicates.IS_SYNTHETIC) //
87-
.or(Predicates.IS_JAVA);
88-
89-
return !excludedFieldPredicate.test(field);
90-
};
66+
private Predicate<Field> fieldFilter = createFieldFilter();
9167

9268
public TypeCollector filterFields(Predicate<Field> filter) {
9369
this.fieldFilter = filter.and(filter);
@@ -198,6 +174,35 @@ Set<Type> visitFieldsOfType(ResolvableType type) {
198174
return discoveredTypes;
199175
}
200176

177+
private Predicate<Method> createMethodFilter() {
178+
179+
Predicate<Method> excludedDomainsPredicate = methodToTest -> excludedDomainsFilter
180+
.test(methodToTest.getDeclaringClass());
181+
182+
Predicate<Method> excludedMethodsPredicate = Predicates.IS_BRIDGE_METHOD //
183+
.or(Predicates.IS_STATIC) //
184+
.or(Predicates.IS_SYNTHETIC) //
185+
.or(Predicates.IS_NATIVE) //
186+
.or(Predicates.IS_PRIVATE) //
187+
.or(Predicates.IS_PROTECTED) //
188+
.or(Predicates.IS_OBJECT_MEMBER) //
189+
.or(Predicates.IS_HIBERNATE_MEMBER) //
190+
.or(Predicates.IS_ENUM_MEMBER) //
191+
.or(excludedDomainsPredicate.negate()); //
192+
193+
return excludedMethodsPredicate.negate();
194+
}
195+
196+
@SuppressWarnings("rawtypes")
197+
private Predicate<Field> createFieldFilter() {
198+
199+
Predicate<Member> excludedFieldPredicate = Predicates.IS_HIBERNATE_MEMBER //
200+
.or(Predicates.IS_SYNTHETIC) //
201+
.or(Predicates.IS_JAVA);
202+
203+
return (Predicate) excludedFieldPredicate.negate();
204+
}
205+
201206
public static class ReachableTypes {
202207

203208
private final Iterable<Class<?>> roots;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor=\
22
org.springframework.data.aot.SpringDataBeanFactoryInitializationAotProcessor
3+
34
org.springframework.aot.hint.RuntimeHintsRegistrar=\
45
org.springframework.data.aot.hint.RepositoryRuntimeHints
6+
57
org.springframework.beans.factory.aot.BeanRegistrationAotProcessor=\
68
org.springframework.data.aot.AuditingBeanRegistrationAotProcessor

0 commit comments

Comments
 (0)