Skip to content

Commit f332629

Browse files
committed
Polishing
1 parent af92054 commit f332629

File tree

6 files changed

+40
-35
lines changed

6 files changed

+40
-35
lines changed

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

Lines changed: 4 additions & 7 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.
@@ -132,8 +132,7 @@ public interface BeanFactory {
132132
* Will ask the parent factory if the bean cannot be found in this factory instance.
133133
* @param name the name of the bean to retrieve
134134
* @return an instance of the bean
135-
* @throws NoSuchBeanDefinitionException if there is no bean definition
136-
* with the specified name
135+
* @throws NoSuchBeanDefinitionException if there is no bean with the specified name
137136
* @throws BeansException if the bean could not be obtained
138137
*/
139138
Object getBean(String name) throws BeansException;
@@ -180,8 +179,7 @@ public interface BeanFactory {
180179
* but may also be translated into a conventional by-name lookup based on the name
181180
* of the given type. For more extensive retrieval operations across sets of beans,
182181
* use {@link ListableBeanFactory} and/or {@link BeanFactoryUtils}.
183-
* @param requiredType type the bean must match; can be an interface or superclass.
184-
* {@code null} is disallowed.
182+
* @param requiredType type the bean must match; can be an interface or superclass
185183
* @return an instance of the single bean matching the required type
186184
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
187185
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
@@ -199,8 +197,7 @@ public interface BeanFactory {
199197
* but may also be translated into a conventional by-name lookup based on the name
200198
* of the given type. For more extensive retrieval operations across sets of beans,
201199
* use {@link ListableBeanFactory} and/or {@link BeanFactoryUtils}.
202-
* @param requiredType type the bean must match; can be an interface or superclass.
203-
* {@code null} is disallowed.
200+
* @param requiredType type the bean must match; can be an interface or superclass
204201
* @param args arguments to use when creating a bean instance using explicit arguments
205202
* (only applied when creating a new instance as opposed to retrieving an existing one)
206203
* @return an instance of the bean

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

Lines changed: 8 additions & 4 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.
@@ -27,6 +27,8 @@
2727
/**
2828
* A simple descriptor for an injection point, pointing to a method/constructor
2929
* parameter or a field. Exposed by {@link UnsatisfiedDependencyException}.
30+
* Also available as an argument for factory methods, reacting to the
31+
* requesting injection point for building a customized bean instance.
3032
*
3133
* @author Juergen Hoeller
3234
* @since 4.3
@@ -101,10 +103,12 @@ public Field getField() {
101103
*/
102104
public Annotation[] getAnnotations() {
103105
if (this.field != null) {
104-
if (this.fieldAnnotations == null) {
105-
this.fieldAnnotations = this.field.getAnnotations();
106+
Annotation[] fieldAnnotations = this.fieldAnnotations;
107+
if (fieldAnnotations == null) {
108+
fieldAnnotations = this.field.getAnnotations();
109+
this.fieldAnnotations = fieldAnnotations;
106110
}
107-
return this.fieldAnnotations;
111+
return fieldAnnotations;
108112
}
109113
else {
110114
return this.methodParameter.getParameterAnnotations();

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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,7 +117,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
117117
* {@link BeanPostProcessor BeanPostProcessors}.
118118
* <p>Note: This is intended for creating a fresh instance, populating annotated
119119
* fields and methods as well as applying all standard bean initialization callbacks.
120-
* It does <i>not</> imply traditional by-name or by-type autowiring of properties;
120+
* It does <i>not</i> imply traditional by-name or by-type autowiring of properties;
121121
* use {@link #createBean(Class, int, boolean)} for those purposes.
122122
* @param beanClass the class of the bean to create
123123
* @return the new bean instance
@@ -273,8 +273,9 @@ void autowireBeanProperties(Object existingBean, int autowireMode, boolean depen
273273
* Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean
274274
* instance, invoking their {@code postProcessBeforeInitialization} methods.
275275
* The returned bean instance may be a wrapper around the original.
276-
* @param existingBean the new bean instance
277-
* @param beanName the name of the bean
276+
* @param existingBean the existing bean instance
277+
* @param beanName the name of the bean, to be passed to it if necessary
278+
* (only passed to {@link BeanPostProcessor BeanPostProcessors})
278279
* @return the bean instance to use, either the original or a wrapped one
279280
* @throws BeansException if any post-processing failed
280281
* @see BeanPostProcessor#postProcessBeforeInitialization
@@ -286,8 +287,9 @@ Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String b
286287
* Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean
287288
* instance, invoking their {@code postProcessAfterInitialization} methods.
288289
* The returned bean instance may be a wrapper around the original.
289-
* @param existingBean the new bean instance
290-
* @param beanName the name of the bean
290+
* @param existingBean the existing bean instance
291+
* @param beanName the name of the bean, to be passed to it if necessary
292+
* (only passed to {@link BeanPostProcessor BeanPostProcessors})
291293
* @return the bean instance to use, either the original or a wrapped one
292294
* @throws BeansException if any post-processing failed
293295
* @see BeanPostProcessor#postProcessAfterInitialization
@@ -315,8 +317,7 @@ Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String be
315317
* including its bean name.
316318
* <p>This is effectively a variant of {@link #getBean(Class)} which preserves the
317319
* bean name of the matching instance.
318-
* @param requiredType type the bean must match; can be an interface or superclass.
319-
* {@code null} is disallowed.
320+
* @param requiredType type the bean must match; can be an interface or superclass
320321
* @return the bean name plus bean instance
321322
* @throws NoSuchBeanDefinitionException if no matching bean was found
322323
* @throws NoUniqueBeanDefinitionException if more than one matching bean was found

spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java

Lines changed: 6 additions & 4 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.
@@ -478,7 +478,6 @@ public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor)
478478
this.beanFactoryPostProcessors.add(postProcessor);
479479
}
480480

481-
482481
/**
483482
* Return the list of BeanFactoryPostProcessors that will get applied
484483
* to the internal BeanFactory.
@@ -575,6 +574,7 @@ public void refresh() throws BeansException, IllegalStateException {
575574
* active flag as well as performing any initialization of property sources.
576575
*/
577576
protected void prepareRefresh() {
577+
// Switch to active.
578578
this.startupDate = System.currentTimeMillis();
579579
this.closed.set(false);
580580
this.active.set(true);
@@ -583,10 +583,10 @@ protected void prepareRefresh() {
583583
logger.info("Refreshing " + this);
584584
}
585585

586-
// Initialize any placeholder property sources in the context environment
586+
// Initialize any placeholder property sources in the context environment.
587587
initPropertySources();
588588

589-
// Validate that all properties marked as required are resolvable
589+
// Validate that all properties marked as required are resolvable:
590590
// see ConfigurablePropertyResolver#setRequiredProperties
591591
getEnvironment().validateRequiredProperties();
592592

@@ -979,6 +979,7 @@ public void close() {
979979
* @see #registerShutdownHook()
980980
*/
981981
protected void doClose() {
982+
// Check whether an actual close attempt is necessary...
982983
if (this.active.get() && this.closed.compareAndSet(false, true)) {
983984
if (logger.isInfoEnabled()) {
984985
logger.info("Closing " + this);
@@ -1013,6 +1014,7 @@ protected void doClose() {
10131014
// Let subclasses do some final clean-up if they wish...
10141015
onClose();
10151016

1017+
// Switch to inactive.
10161018
this.active.set(false);
10171019
}
10181020
}

spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineMap.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -34,7 +34,7 @@
3434
public class InlineMap extends SpelNodeImpl {
3535

3636
// If the map is purely literals, it is a constant value and can be computed and cached
37-
private TypedValue constant = null;
37+
private TypedValue constant;
3838

3939

4040
public InlineMap(int pos, SpelNodeImpl... args) {
@@ -44,7 +44,7 @@ public InlineMap(int pos, SpelNodeImpl... args) {
4444

4545

4646
/**
47-
* If all the components of the list are constants, or lists/maps that themselves
47+
* If all the components of the map are constants, or lists/maps that themselves
4848
* contain constants, then a constant list can be built to represent this node.
4949
* This will speed up later getValue calls and reduce the amount of garbage created.
5050
*/
@@ -67,14 +67,14 @@ else if (child instanceof InlineMap) {
6767
break;
6868
}
6969
}
70-
else if (!((c%2)==0 && (child instanceof PropertyOrFieldReference))) {
70+
else if (!(c % 2 == 0 && child instanceof PropertyOrFieldReference)) {
7171
isConstant = false;
7272
break;
7373
}
7474
}
7575
}
7676
if (isConstant) {
77-
Map<Object,Object> constantMap = new LinkedHashMap<Object,Object>();
77+
Map<Object, Object> constantMap = new LinkedHashMap<Object, Object>();
7878
int childCount = getChildCount();
7979
for (int c = 0; c < childCount; c++) {
8080
SpelNode keyChild = getChild(c++);
@@ -148,15 +148,15 @@ public String toStringAST() {
148148
}
149149

150150
/**
151-
* @return whether this list is a constant value
151+
* Return whether this list is a constant value.
152152
*/
153153
public boolean isConstant() {
154154
return this.constant != null;
155155
}
156156

157157
@SuppressWarnings("unchecked")
158-
public Map<Object,Object> getConstantValue() {
159-
return (Map<Object,Object>) this.constant.getValue();
158+
public Map<Object, Object> getConstantValue() {
159+
return (Map<Object, Object>) this.constant.getValue();
160160
}
161161

162162
}

spring-expression/src/main/java/org/springframework/expression/spel/ast/ValueRef.java

Lines changed: 5 additions & 4 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.
@@ -23,8 +23,8 @@
2323
/**
2424
* Represents a reference to a value. With a reference it is possible to get or set the
2525
* value. Passing around value references rather than the values themselves can avoid
26-
* incorrect duplication of operand evaluation. For example in 'list[index++]++' without a
27-
* value reference for 'list[index++]' it would be necessary to evaluate list[index++]
26+
* incorrect duplication of operand evaluation. For example in 'list[index++]++' without
27+
* a value reference for 'list[index++]' it would be necessary to evaluate list[index++]
2828
* twice (once to get the value, once to determine where the value goes) and that would
2929
* double increment index.
3030
*
@@ -102,7 +102,8 @@ public TypedValue getValue() {
102102

103103
@Override
104104
public void setValue(Object newValue) {
105-
throw new SpelEvaluationException(this.node.pos, SpelMessage.NOT_ASSIGNABLE, this.node.toStringAST());
105+
throw new SpelEvaluationException(
106+
this.node.getStartPosition(), SpelMessage.NOT_ASSIGNABLE, this.node.toStringAST());
106107
}
107108

108109
@Override

0 commit comments

Comments
 (0)