20
20
import java .lang .reflect .Member ;
21
21
import java .lang .reflect .Method ;
22
22
import java .lang .reflect .Type ;
23
- import java .util .ArrayList ;
24
- import java .util .Arrays ;
25
- import java .util .Collection ;
26
- import java .util .Collections ;
27
- import java .util .HashSet ;
28
- import java .util .LinkedHashMap ;
29
- import java .util .LinkedHashSet ;
30
- import java .util .List ;
31
- import java .util .Map ;
32
- import java .util .Set ;
23
+ import java .util .*;
33
24
import java .util .function .Consumer ;
34
25
import java .util .function .Predicate ;
35
26
40
31
import org .springframework .util .ReflectionUtils ;
41
32
42
33
/**
34
+ * Collector to inspect domain types and discover the type graph that is relevant for Spring Data operations.
35
+ * <p>
36
+ * Type inspection walks through all class members (fields, methods, constructors) and introspects those for additional
37
+ * types that are part of the domain model.
38
+ *
43
39
* @author Christoph Strobl
44
40
* @author Sebastien Deleuze
45
41
* @author John Blum
42
+ * @since 3.0
46
43
*/
47
44
public class TypeCollector {
48
45
@@ -122,13 +119,16 @@ private void processType(ResolvableType type, InspectionCache cache, Consumer<Re
122
119
}
123
120
124
121
Set <Type > visitConstructorsOfType (ResolvableType type ) {
122
+
125
123
if (!typeFilter .test (type .toClass ())) {
126
124
return Collections .emptySet ();
127
125
}
126
+
128
127
Set <Type > discoveredTypes = new LinkedHashSet <>();
128
+
129
129
for (Constructor <?> constructor : type .toClass ().getDeclaredConstructors ()) {
130
130
131
- if (constructor . isSynthetic ( )) {
131
+ if (Predicates . isExcluded ( constructor )) {
132
132
continue ;
133
133
}
134
134
for (Class <?> signatureType : TypeUtils .resolveTypesInSignature (type .toClass (), constructor )) {
@@ -137,10 +137,12 @@ Set<Type> visitConstructorsOfType(ResolvableType type) {
137
137
}
138
138
}
139
139
}
140
+
140
141
return new HashSet <>(discoveredTypes );
141
142
}
142
143
143
144
Set <Type > visitMethodsOfType (ResolvableType type ) {
145
+
144
146
if (!typeFilter .test (type .toClass ())) {
145
147
return Collections .emptySet ();
146
148
}
@@ -160,11 +162,14 @@ Set<Type> visitMethodsOfType(ResolvableType type) {
160
162
} catch (Exception cause ) {
161
163
logger .warn (cause );
162
164
}
165
+
163
166
return new HashSet <>(discoveredTypes );
164
167
}
165
168
166
169
Set <Type > visitFieldsOfType (ResolvableType type ) {
170
+
167
171
Set <Type > discoveredTypes = new LinkedHashSet <>();
172
+
168
173
ReflectionUtils .doWithLocalFields (type .toClass (), field -> {
169
174
if (!fieldFilter .test (field )) {
170
175
return ;
@@ -175,6 +180,7 @@ Set<Type> visitFieldsOfType(ResolvableType type) {
175
180
}
176
181
}
177
182
});
183
+
178
184
return discoveredTypes ;
179
185
}
180
186
0 commit comments