Skip to content

Commit 8d5c362

Browse files
committed
Polishing
1 parent bb7096b commit 8d5c362

File tree

31 files changed

+143
-159
lines changed

31 files changed

+143
-159
lines changed

spring-beans/src/main/java/org/springframework/beans/PropertyValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -169,7 +169,7 @@ public synchronized boolean isConverted() {
169169
}
170170

171171
/**
172-
* Set the converted value of the constructor argument,
172+
* Set the converted value of this property value,
173173
* after processed type conversion.
174174
*/
175175
public synchronized void setConvertedValue(@Nullable Object value) {
@@ -178,7 +178,7 @@ public synchronized void setConvertedValue(@Nullable Object value) {
178178
}
179179

180180
/**
181-
* Return the converted value of the constructor argument,
181+
* Return the converted value of this property value,
182182
* after processed type conversion.
183183
*/
184184
@Nullable

spring-beans/src/main/java/org/springframework/beans/factory/InjectionPoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public boolean equals(Object other) {
180180
if (this == other) {
181181
return true;
182182
}
183-
if (getClass() != other.getClass()) {
183+
if (other == null || getClass() != other.getClass()) {
184184
return false;
185185
}
186186
InjectionPoint otherPoint = (InjectionPoint) other;

spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ protected void visitArray(Object[] arrayVal) {
234234
}
235235
}
236236

237-
@SuppressWarnings({"unchecked", "rawtypes"})
237+
@SuppressWarnings({"rawtypes", "unchecked"})
238238
protected void visitList(List listVal) {
239239
for (int i = 0; i < listVal.size(); i++) {
240240
Object elem = listVal.get(i);
@@ -245,7 +245,7 @@ protected void visitList(List listVal) {
245245
}
246246
}
247247

248-
@SuppressWarnings({"unchecked", "rawtypes"})
248+
@SuppressWarnings({"rawtypes", "unchecked"})
249249
protected void visitSet(Set setVal) {
250250
Set newContent = new LinkedHashSet();
251251
boolean entriesModified = false;
@@ -262,7 +262,7 @@ protected void visitSet(Set setVal) {
262262
}
263263
}
264264

265-
@SuppressWarnings({"unchecked", "rawtypes"})
265+
@SuppressWarnings({"rawtypes", "unchecked"})
266266
protected void visitMap(Map<?, ?> mapVal) {
267267
Map newContent = new LinkedHashMap();
268268
boolean entriesModified = false;

spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
2626
* @author Rod Johnson
2727
* @author Juergen Hoeller
2828
* @see BeanDefinition#getPropertyValues()
29-
* @see org.springframework.beans.factory.BeanFactory#getBean
29+
* @see org.springframework.beans.factory.BeanFactory#getBean(String)
3030
*/
3131
public class RuntimeBeanReference implements BeanReference {
3232

@@ -39,9 +39,7 @@ public class RuntimeBeanReference implements BeanReference {
3939

4040

4141
/**
42-
* Create a new RuntimeBeanReference to the given bean name,
43-
* without explicitly marking it as reference to a bean in
44-
* the parent factory.
42+
* Create a new RuntimeBeanReference to the given bean name.
4543
* @param beanName name of the target bean
4644
*/
4745
public RuntimeBeanReference(String beanName) {
@@ -50,11 +48,10 @@ public RuntimeBeanReference(String beanName) {
5048

5149
/**
5250
* Create a new RuntimeBeanReference to the given bean name,
53-
* with the option to mark it as reference to a bean in
54-
* the parent factory.
51+
* with the option to mark it as reference to a bean in the parent factory.
5552
* @param beanName name of the target bean
56-
* @param toParent whether this is an explicit reference to
57-
* a bean in the parent factory
53+
* @param toParent whether this is an explicit reference to a bean in the
54+
* parent factory
5855
*/
5956
public RuntimeBeanReference(String beanName, boolean toParent) {
6057
Assert.hasText(beanName, "'beanName' must not be empty");
@@ -69,8 +66,7 @@ public String getBeanName() {
6966
}
7067

7168
/**
72-
* Return whether this is an explicit reference to a bean
73-
* in the parent factory.
69+
* Return whether this is an explicit reference to a bean in the parent factory.
7470
*/
7571
public boolean isToParent() {
7672
return this.toParent;

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -117,15 +117,15 @@ public Class<?> getObjectType() {
117117
* case of a shared singleton; else, on each {@link #getObject()} call.
118118
* <p>The default implementation returns the merged {@code Map} instance.
119119
* @return the object returned by this factory
120-
* @see #process(java.util.Map, MatchCallback)
120+
* @see #process(MatchCallback)
121121
*/
122122
protected Map<String, Object> createMap() {
123123
Map<String, Object> result = new LinkedHashMap<>();
124124
process((properties, map) -> merge(result, map));
125125
return result;
126126
}
127127

128-
@SuppressWarnings({"unchecked", "rawtypes"})
128+
@SuppressWarnings({"rawtypes", "unchecked"})
129129
private void merge(Map<String, Object> output, Map<String, Object> map) {
130130
map.forEach((key, value) -> {
131131
Object existing = output.get(key);

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -128,7 +128,7 @@ public Class<?> getObjectType() {
128128
* <p>Invoked lazily the first time {@link #getObject()} is invoked in
129129
* case of a shared singleton; else, on each {@link #getObject()} call.
130130
* @return the object returned by this factory
131-
* @see #process(MatchCallback) ()
131+
* @see #process(MatchCallback)
132132
*/
133133
protected Properties createProperties() {
134134
Properties result = CollectionFactory.createStringAdaptingProperties();

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
6565
public static final String SCOPE_DEFAULT = "";
6666

6767
/**
68-
* Constant that indicates no autowiring at all.
68+
* Constant that indicates no external autowiring at all.
6969
* @see #setAutowireMode
7070
*/
7171
public static final int AUTOWIRE_NO = AutowireCapableBeanFactory.AUTOWIRE_NO;

spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractBeanFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1628,7 +1628,7 @@ protected Object getObjectForBeanInstance(
16281628
return beanInstance;
16291629
}
16301630
if (!(beanInstance instanceof FactoryBean)) {
1631-
throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass());
1631+
throw new BeanIsNotAFactoryException(beanName, beanInstance.getClass());
16321632
}
16331633
}
16341634

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ public BeanDefinitionBuilder setFactoryMethod(String factoryMethod) {
180180
/**
181181
* Set the name of a non-static factory method to use for this definition,
182182
* including the bean name of the factory instance to call the method on.
183+
* @param factoryMethod the name of the factory method
184+
* @param factoryBean the name of the bean to call the specified factory method on
183185
* @since 4.3.6
184186
*/
185187
public BeanDefinitionBuilder setFactoryMethodOnBean(String factoryMethod, String factoryBean) {
@@ -209,7 +211,7 @@ public BeanDefinitionBuilder addConstructorArgReference(String beanName) {
209211
}
210212

211213
/**
212-
* Add the supplied property value under the given name.
214+
* Add the supplied property value under the given property name.
213215
*/
214216
public BeanDefinitionBuilder addPropertyValue(String name, @Nullable Object value) {
215217
this.beanDefinition.getPropertyValues().add(name, value);
@@ -278,7 +280,7 @@ public BeanDefinitionBuilder setAutowireMode(int autowireMode) {
278280
}
279281

280282
/**
281-
* Set the depency check mode for this definition.
283+
* Set the dependency check mode for this definition.
282284
*/
283285
public BeanDefinitionBuilder setDependencyCheck(int dependencyCheck) {
284286
this.beanDefinition.setDependencyCheck(dependencyCheck);

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionValueResolver.java

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -281,6 +281,40 @@ protected Class<?> resolveTargetType(TypedStringValue value) throws ClassNotFoun
281281
return value.resolveTargetType(this.beanFactory.getBeanClassLoader());
282282
}
283283

284+
/**
285+
* Resolve a reference to another bean in the factory.
286+
*/
287+
@Nullable
288+
private Object resolveReference(Object argName, RuntimeBeanReference ref) {
289+
try {
290+
Object bean;
291+
String refName = ref.getBeanName();
292+
refName = String.valueOf(doEvaluate(refName));
293+
if (ref.isToParent()) {
294+
if (this.beanFactory.getParentBeanFactory() == null) {
295+
throw new BeanCreationException(
296+
this.beanDefinition.getResourceDescription(), this.beanName,
297+
"Can't resolve reference to bean '" + refName +
298+
"' in parent factory: no parent factory available");
299+
}
300+
bean = this.beanFactory.getParentBeanFactory().getBean(refName);
301+
}
302+
else {
303+
bean = this.beanFactory.getBean(refName);
304+
this.beanFactory.registerDependentBean(refName, this.beanName);
305+
}
306+
if (bean instanceof NullBean) {
307+
bean = null;
308+
}
309+
return bean;
310+
}
311+
catch (BeansException ex) {
312+
throw new BeanCreationException(
313+
this.beanDefinition.getResourceDescription(), this.beanName,
314+
"Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
315+
}
316+
}
317+
284318
/**
285319
* Resolve an inner bean definition.
286320
* @param argName the name of the argument that the inner bean is defined for
@@ -345,48 +379,13 @@ private String adaptInnerBeanName(String innerBeanName) {
345379
return actualInnerBeanName;
346380
}
347381

348-
/**
349-
* Resolve a reference to another bean in the factory.
350-
*/
351-
@Nullable
352-
private Object resolveReference(Object argName, RuntimeBeanReference ref) {
353-
try {
354-
Object bean;
355-
String refName = ref.getBeanName();
356-
refName = String.valueOf(doEvaluate(refName));
357-
if (ref.isToParent()) {
358-
if (this.beanFactory.getParentBeanFactory() == null) {
359-
throw new BeanCreationException(
360-
this.beanDefinition.getResourceDescription(), this.beanName,
361-
"Can't resolve reference to bean '" + refName +
362-
"' in parent factory: no parent factory available");
363-
}
364-
bean = this.beanFactory.getParentBeanFactory().getBean(refName);
365-
}
366-
else {
367-
bean = this.beanFactory.getBean(refName);
368-
this.beanFactory.registerDependentBean(refName, this.beanName);
369-
}
370-
if (bean instanceof NullBean) {
371-
bean = null;
372-
}
373-
return bean;
374-
}
375-
catch (BeansException ex) {
376-
throw new BeanCreationException(
377-
this.beanDefinition.getResourceDescription(), this.beanName,
378-
"Cannot resolve reference to bean '" + ref.getBeanName() + "' while setting " + argName, ex);
379-
}
380-
}
381-
382382
/**
383383
* For each element in the managed array, resolve reference if necessary.
384384
*/
385385
private Object resolveManagedArray(Object argName, List<?> ml, Class<?> elementType) {
386386
Object resolved = Array.newInstance(elementType, ml.size());
387387
for (int i = 0; i < ml.size(); i++) {
388-
Array.set(resolved, i,
389-
resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
388+
Array.set(resolved, i, resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
390389
}
391390
return resolved;
392391
}
@@ -397,8 +396,7 @@ private Object resolveManagedArray(Object argName, List<?> ml, Class<?> elementT
397396
private List<?> resolveManagedList(Object argName, List<?> ml) {
398397
List<Object> resolved = new ArrayList<>(ml.size());
399398
for (int i = 0; i < ml.size(); i++) {
400-
resolved.add(
401-
resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
399+
resolved.add(resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
402400
}
403401
return resolved;
404402
}

0 commit comments

Comments
 (0)