44
44
* <p><strong>WARNING</strong>: implementations are used as a cache key and
45
45
* must implement proper {@code equals()} and {@code hashCode()} methods.
46
46
*
47
- * <p>Specific implementations of metadata can have state to be used during
48
- * override {@linkplain #createOverride(String, BeanDefinition, Object)
49
- * instance creation} — for example, based on further parsing of the
47
+ * <p>Concrete implementations of {@code OverrideMetadata} can store state to use
48
+ * during override {@linkplain #createOverride(String, BeanDefinition, Object)
49
+ * instance creation} — for example, based on further processing of the
50
50
* annotation or the annotated field.
51
51
*
52
52
* @author Simon Baslé
53
53
* @author Stephane Nicoll
54
+ * @author Sam Brannen
54
55
* @since 6.2
55
56
*/
56
57
public abstract class OverrideMetadata {
@@ -67,25 +68,27 @@ public abstract class OverrideMetadata {
67
68
68
69
protected OverrideMetadata (Field field , ResolvableType beanType , @ Nullable String beanName ,
69
70
BeanOverrideStrategy strategy ) {
71
+
70
72
this .field = field ;
71
73
this .beanType = beanType ;
72
74
this .beanName = beanName ;
73
75
this .strategy = strategy ;
74
76
}
75
77
76
78
/**
77
- * Parse the given {@code testClass} and build the corresponding list of
78
- * bean {@code OverrideMetadata}.
79
- * @param testClass the class to parse
79
+ * Process the given {@code testClass} and build the corresponding list of
80
+ * {@code OverrideMetadata} derived from {@link BeanOverride @BeanOverride}
81
+ * fields in the test class and its type hierarchy.
82
+ * @param testClass the test class to process
80
83
* @return a list of {@code OverrideMetadata}
81
84
*/
82
85
public static List <OverrideMetadata > forTestClass (Class <?> testClass ) {
83
86
List <OverrideMetadata > metadata = new LinkedList <>();
84
- ReflectionUtils .doWithFields (testClass , field -> parseField (field , testClass , metadata ));
87
+ ReflectionUtils .doWithFields (testClass , field -> processField (field , testClass , metadata ));
85
88
return metadata ;
86
89
}
87
90
88
- private static void parseField (Field field , Class <?> testClass , List <OverrideMetadata > metadataList ) {
91
+ private static void processField (Field field , Class <?> testClass , List <OverrideMetadata > metadataList ) {
89
92
AtomicBoolean overrideAnnotationFound = new AtomicBoolean ();
90
93
MergedAnnotations .from (field , DIRECT ).stream (BeanOverride .class ).forEach (mergedAnnotation -> {
91
94
MergedAnnotation <?> metaSource = mergedAnnotation .getMetaSource ();
@@ -127,20 +130,20 @@ public final String getBeanName() {
127
130
}
128
131
129
132
/**
130
- * Get the {@link BeanOverrideStrategy} for this instance, as a hint on
131
- * how and when the override instance should be created.
133
+ * Get the {@link BeanOverrideStrategy} for this {@code OverrideMetadata},
134
+ * which influences how and when the bean override instance should be created.
132
135
*/
133
136
public final BeanOverrideStrategy getStrategy () {
134
137
return this .strategy ;
135
138
}
136
139
137
140
/**
138
- * Create an override instance from this {@link OverrideMetadata},
139
- * optionally provided with an existing {@link BeanDefinition} and/or an
141
+ * Create a bean override instance for this {@code OverrideMetadata},
142
+ * optionally based on an existing {@link BeanDefinition} and/or an
140
143
* original instance, that is a singleton or an early wrapped instance.
141
144
* @param beanName the name of the bean being overridden
142
145
* @param existingBeanDefinition an existing bean definition for the supplied
143
- * bean name, or {@code null} if not relevant
146
+ * bean name, or {@code null} if irrelevant
144
147
* @param existingBeanInstance an existing instance for the supplied bean name
145
148
* for wrapping purposes, or {@code null} if irrelevant
146
149
* @return the instance with which to override the bean
@@ -149,8 +152,9 @@ protected abstract Object createOverride(String beanName, @Nullable BeanDefiniti
149
152
@ Nullable Object existingBeanInstance );
150
153
151
154
/**
152
- * Optionally track objects created by this {@link OverrideMetadata}.
153
- * <p>The default is not to track, but this can be overridden in subclasses.
155
+ * Optionally track objects created by this {@code OverrideMetadata}.
156
+ * <p>The default implementation does not track the supplied instance, but
157
+ * this can be overridden in subclasses as appropriate.
154
158
* @param override the bean override instance to track
155
159
* @param trackingBeanRegistry the registry in which trackers can
156
160
* optionally be registered
0 commit comments