2020import java .lang .reflect .Member ;
2121import java .lang .reflect .Method ;
2222import 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 .*;
3324import java .util .function .Consumer ;
3425import java .util .function .Predicate ;
3526
4031import org .springframework .util .ReflectionUtils ;
4132
4233/**
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+ *
4339 * @author Christoph Strobl
4440 * @author Sebastien Deleuze
4541 * @author John Blum
42+ * @since 3.0
4643 */
4744public class TypeCollector {
4845
@@ -122,13 +119,16 @@ private void processType(ResolvableType type, InspectionCache cache, Consumer<Re
122119 }
123120
124121 Set <Type > visitConstructorsOfType (ResolvableType type ) {
122+
125123 if (!typeFilter .test (type .toClass ())) {
126124 return Collections .emptySet ();
127125 }
126+
128127 Set <Type > discoveredTypes = new LinkedHashSet <>();
128+
129129 for (Constructor <?> constructor : type .toClass ().getDeclaredConstructors ()) {
130130
131- if (constructor . isSynthetic ( )) {
131+ if (Predicates . isExcluded ( constructor )) {
132132 continue ;
133133 }
134134 for (Class <?> signatureType : TypeUtils .resolveTypesInSignature (type .toClass (), constructor )) {
@@ -137,10 +137,12 @@ Set<Type> visitConstructorsOfType(ResolvableType type) {
137137 }
138138 }
139139 }
140+
140141 return new HashSet <>(discoveredTypes );
141142 }
142143
143144 Set <Type > visitMethodsOfType (ResolvableType type ) {
145+
144146 if (!typeFilter .test (type .toClass ())) {
145147 return Collections .emptySet ();
146148 }
@@ -160,11 +162,14 @@ Set<Type> visitMethodsOfType(ResolvableType type) {
160162 } catch (Exception cause ) {
161163 logger .warn (cause );
162164 }
165+
163166 return new HashSet <>(discoveredTypes );
164167 }
165168
166169 Set <Type > visitFieldsOfType (ResolvableType type ) {
170+
167171 Set <Type > discoveredTypes = new LinkedHashSet <>();
172+
168173 ReflectionUtils .doWithLocalFields (type .toClass (), field -> {
169174 if (!fieldFilter .test (field )) {
170175 return ;
@@ -175,6 +180,7 @@ Set<Type> visitFieldsOfType(ResolvableType type) {
175180 }
176181 }
177182 });
183+
178184 return discoveredTypes ;
179185 }
180186
0 commit comments