Polishing

This commit is contained in:
Juergen Hoeller
2019-02-07 23:57:14 +01:00
parent af920544b4
commit f3326291b1
6 changed files with 40 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -132,8 +132,7 @@ public interface BeanFactory {
* Will ask the parent factory if the bean cannot be found in this factory instance.
* @param name the name of the bean to retrieve
* @return an instance of the bean
* @throws NoSuchBeanDefinitionException if there is no bean definition
* with the specified name
* @throws NoSuchBeanDefinitionException if there is no bean with the specified name
* @throws BeansException if the bean could not be obtained
*/
Object getBean(String name) throws BeansException;
@@ -180,8 +179,7 @@ public interface BeanFactory {
* but may also be translated into a conventional by-name lookup based on the name
* of the given type. For more extensive retrieval operations across sets of beans,
* use {@link ListableBeanFactory} and/or {@link BeanFactoryUtils}.
* @param requiredType type the bean must match; can be an interface or superclass.
* {@code null} is disallowed.
* @param requiredType type the bean must match; can be an interface or superclass
* @return an instance of the single bean matching the required type
* @throws NoSuchBeanDefinitionException if no bean of the given type was found
* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found
@@ -199,8 +197,7 @@ public interface BeanFactory {
* but may also be translated into a conventional by-name lookup based on the name
* of the given type. For more extensive retrieval operations across sets of beans,
* use {@link ListableBeanFactory} and/or {@link BeanFactoryUtils}.
* @param requiredType type the bean must match; can be an interface or superclass.
* {@code null} is disallowed.
* @param requiredType type the bean must match; can be an interface or superclass
* @param args arguments to use when creating a bean instance using explicit arguments
* (only applied when creating a new instance as opposed to retrieving an existing one)
* @return an instance of the bean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,8 @@ import org.springframework.util.Assert;
/**
* A simple descriptor for an injection point, pointing to a method/constructor
* parameter or a field. Exposed by {@link UnsatisfiedDependencyException}.
* Also available as an argument for factory methods, reacting to the
* requesting injection point for building a customized bean instance.
*
* @author Juergen Hoeller
* @since 4.3
@@ -101,10 +103,12 @@ public class InjectionPoint {
*/
public Annotation[] getAnnotations() {
if (this.field != null) {
if (this.fieldAnnotations == null) {
this.fieldAnnotations = this.field.getAnnotations();
Annotation[] fieldAnnotations = this.fieldAnnotations;
if (fieldAnnotations == null) {
fieldAnnotations = this.field.getAnnotations();
this.fieldAnnotations = fieldAnnotations;
}
return this.fieldAnnotations;
return fieldAnnotations;
}
else {
return this.methodParameter.getParameterAnnotations();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -117,7 +117,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* {@link BeanPostProcessor BeanPostProcessors}.
* <p>Note: This is intended for creating a fresh instance, populating annotated
* fields and methods as well as applying all standard bean initialization callbacks.
* It does <i>not</> imply traditional by-name or by-type autowiring of properties;
* It does <i>not</i> imply traditional by-name or by-type autowiring of properties;
* use {@link #createBean(Class, int, boolean)} for those purposes.
* @param beanClass the class of the bean to create
* @return the new bean instance
@@ -273,8 +273,9 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean
* instance, invoking their {@code postProcessBeforeInitialization} methods.
* The returned bean instance may be a wrapper around the original.
* @param existingBean the new bean instance
* @param beanName the name of the bean
* @param existingBean the existing bean instance
* @param beanName the name of the bean, to be passed to it if necessary
* (only passed to {@link BeanPostProcessor BeanPostProcessors})
* @return the bean instance to use, either the original or a wrapped one
* @throws BeansException if any post-processing failed
* @see BeanPostProcessor#postProcessBeforeInitialization
@@ -286,8 +287,9 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* Apply {@link BeanPostProcessor BeanPostProcessors} to the given existing bean
* instance, invoking their {@code postProcessAfterInitialization} methods.
* The returned bean instance may be a wrapper around the original.
* @param existingBean the new bean instance
* @param beanName the name of the bean
* @param existingBean the existing bean instance
* @param beanName the name of the bean, to be passed to it if necessary
* (only passed to {@link BeanPostProcessor BeanPostProcessors})
* @return the bean instance to use, either the original or a wrapped one
* @throws BeansException if any post-processing failed
* @see BeanPostProcessor#postProcessAfterInitialization
@@ -315,8 +317,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory {
* including its bean name.
* <p>This is effectively a variant of {@link #getBean(Class)} which preserves the
* bean name of the matching instance.
* @param requiredType type the bean must match; can be an interface or superclass.
* {@code null} is disallowed.
* @param requiredType type the bean must match; can be an interface or superclass
* @return the bean name plus bean instance
* @throws NoSuchBeanDefinitionException if no matching bean was found
* @throws NoUniqueBeanDefinitionException if more than one matching bean was found

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -478,7 +478,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
this.beanFactoryPostProcessors.add(postProcessor);
}
/**
* Return the list of BeanFactoryPostProcessors that will get applied
* to the internal BeanFactory.
@@ -575,6 +574,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
* active flag as well as performing any initialization of property sources.
*/
protected void prepareRefresh() {
// Switch to active.
this.startupDate = System.currentTimeMillis();
this.closed.set(false);
this.active.set(true);
@@ -583,10 +583,10 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
logger.info("Refreshing " + this);
}
// Initialize any placeholder property sources in the context environment
// Initialize any placeholder property sources in the context environment.
initPropertySources();
// Validate that all properties marked as required are resolvable
// Validate that all properties marked as required are resolvable:
// see ConfigurablePropertyResolver#setRequiredProperties
getEnvironment().validateRequiredProperties();
@@ -979,6 +979,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
* @see #registerShutdownHook()
*/
protected void doClose() {
// Check whether an actual close attempt is necessary...
if (this.active.get() && this.closed.compareAndSet(false, true)) {
if (logger.isInfoEnabled()) {
logger.info("Closing " + this);
@@ -1013,6 +1014,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
// Let subclasses do some final clean-up if they wish...
onClose();
// Switch to inactive.
this.active.set(false);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@ import org.springframework.expression.spel.SpelNode;
public class InlineMap extends SpelNodeImpl {
// If the map is purely literals, it is a constant value and can be computed and cached
private TypedValue constant = null;
private TypedValue constant;
public InlineMap(int pos, SpelNodeImpl... args) {
@@ -44,7 +44,7 @@ public class InlineMap extends SpelNodeImpl {
/**
* If all the components of the list are constants, or lists/maps that themselves
* If all the components of the map are constants, or lists/maps that themselves
* contain constants, then a constant list can be built to represent this node.
* This will speed up later getValue calls and reduce the amount of garbage created.
*/
@@ -67,14 +67,14 @@ public class InlineMap extends SpelNodeImpl {
break;
}
}
else if (!((c%2)==0 && (child instanceof PropertyOrFieldReference))) {
else if (!(c % 2 == 0 && child instanceof PropertyOrFieldReference)) {
isConstant = false;
break;
}
}
}
if (isConstant) {
Map<Object,Object> constantMap = new LinkedHashMap<Object,Object>();
Map<Object, Object> constantMap = new LinkedHashMap<Object, Object>();
int childCount = getChildCount();
for (int c = 0; c < childCount; c++) {
SpelNode keyChild = getChild(c++);
@@ -148,15 +148,15 @@ public class InlineMap extends SpelNodeImpl {
}
/**
* @return whether this list is a constant value
* Return whether this list is a constant value.
*/
public boolean isConstant() {
return this.constant != null;
}
@SuppressWarnings("unchecked")
public Map<Object,Object> getConstantValue() {
return (Map<Object,Object>) this.constant.getValue();
public Map<Object, Object> getConstantValue() {
return (Map<Object, Object>) this.constant.getValue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@ import org.springframework.expression.spel.SpelMessage;
/**
* Represents a reference to a value. With a reference it is possible to get or set the
* value. Passing around value references rather than the values themselves can avoid
* incorrect duplication of operand evaluation. For example in 'list[index++]++' without a
* value reference for 'list[index++]' it would be necessary to evaluate list[index++]
* incorrect duplication of operand evaluation. For example in 'list[index++]++' without
* a value reference for 'list[index++]' it would be necessary to evaluate list[index++]
* twice (once to get the value, once to determine where the value goes) and that would
* double increment index.
*
@@ -102,7 +102,8 @@ public interface ValueRef {
@Override
public void setValue(Object newValue) {
throw new SpelEvaluationException(this.node.pos, SpelMessage.NOT_ASSIGNABLE, this.node.toStringAST());
throw new SpelEvaluationException(
this.node.getStartPosition(), SpelMessage.NOT_ASSIGNABLE, this.node.toStringAST());
}
@Override