Apply "instanceof pattern matching" in spring-beans
This commit is contained in:
parent
556863d401
commit
8e2eeb5364
|
|
@ -100,8 +100,8 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
this.delegate = delegate;
|
this.delegate = delegate;
|
||||||
for (PropertyDescriptor pd : delegate.getPropertyDescriptors()) {
|
for (PropertyDescriptor pd : delegate.getPropertyDescriptors()) {
|
||||||
try {
|
try {
|
||||||
this.propertyDescriptors.add(pd instanceof IndexedPropertyDescriptor ?
|
this.propertyDescriptors.add(pd instanceof IndexedPropertyDescriptor indexedPd ?
|
||||||
new SimpleIndexedPropertyDescriptor((IndexedPropertyDescriptor) pd) :
|
new SimpleIndexedPropertyDescriptor(indexedPd) :
|
||||||
new SimplePropertyDescriptor(pd));
|
new SimplePropertyDescriptor(pd));
|
||||||
}
|
}
|
||||||
catch (IntrospectionException ex) {
|
catch (IntrospectionException ex) {
|
||||||
|
|
@ -170,8 +170,8 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
this.propertyDescriptors.add(
|
this.propertyDescriptors.add(
|
||||||
new SimpleIndexedPropertyDescriptor(propertyName, null, null, null, method));
|
new SimpleIndexedPropertyDescriptor(propertyName, null, null, null, method));
|
||||||
}
|
}
|
||||||
else if (existingPd instanceof IndexedPropertyDescriptor) {
|
else if (existingPd instanceof IndexedPropertyDescriptor indexedPd) {
|
||||||
((IndexedPropertyDescriptor) existingPd).setIndexedWriteMethod(method);
|
indexedPd.setIndexedWriteMethod(method);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.propertyDescriptors.remove(existingPd);
|
this.propertyDescriptors.remove(existingPd);
|
||||||
|
|
@ -189,8 +189,8 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
for (PropertyDescriptor pd : this.propertyDescriptors) {
|
for (PropertyDescriptor pd : this.propertyDescriptors) {
|
||||||
final Class<?> candidateType;
|
final Class<?> candidateType;
|
||||||
final String candidateName = pd.getName();
|
final String candidateName = pd.getName();
|
||||||
if (pd instanceof IndexedPropertyDescriptor ipd) {
|
if (pd instanceof IndexedPropertyDescriptor indexedPd) {
|
||||||
candidateType = ipd.getIndexedPropertyType();
|
candidateType = indexedPd.getIndexedPropertyType();
|
||||||
if (candidateName.equals(propertyName) &&
|
if (candidateName.equals(propertyName) &&
|
||||||
(candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
|
(candidateType.equals(propertyType) || candidateType.equals(propertyType.getComponentType()))) {
|
||||||
return pd;
|
return pd;
|
||||||
|
|
@ -338,9 +338,9 @@ class ExtendedBeanInfo implements BeanInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object other) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
return (this == other || (other instanceof PropertyDescriptor &&
|
return (this == obj || (obj instanceof PropertyDescriptor that &&
|
||||||
PropertyDescriptorUtils.equals(this, (PropertyDescriptor) other)));
|
PropertyDescriptorUtils.equals(this, that)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -366,9 +366,9 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object other) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
return (this == other || (other instanceof MutablePropertyValues &&
|
return (this == obj || (obj instanceof MutablePropertyValues that &&
|
||||||
this.propertyValueList.equals(((MutablePropertyValues) other).propertyValueList)));
|
this.propertyValueList.equals(that.propertyValueList)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -135,8 +135,8 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||||
public PropertyValue getOriginalPropertyValue() {
|
public PropertyValue getOriginalPropertyValue() {
|
||||||
PropertyValue original = this;
|
PropertyValue original = this;
|
||||||
Object source = getSource();
|
Object source = getSource();
|
||||||
while (source instanceof PropertyValue && source != original) {
|
while (source instanceof PropertyValue pv && source != original) {
|
||||||
original = (PropertyValue) source;
|
original = pv;
|
||||||
source = original.getSource();
|
source = original.getSource();
|
||||||
}
|
}
|
||||||
return original;
|
return original;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -140,12 +140,12 @@ class TypeConverterDelegate {
|
||||||
// Value not of required type?
|
// Value not of required type?
|
||||||
if (editor != null || (requiredType != null && !ClassUtils.isAssignableValue(requiredType, convertedValue))) {
|
if (editor != null || (requiredType != null && !ClassUtils.isAssignableValue(requiredType, convertedValue))) {
|
||||||
if (typeDescriptor != null && requiredType != null && Collection.class.isAssignableFrom(requiredType) &&
|
if (typeDescriptor != null && requiredType != null && Collection.class.isAssignableFrom(requiredType) &&
|
||||||
convertedValue instanceof String) {
|
convertedValue instanceof String text) {
|
||||||
TypeDescriptor elementTypeDesc = typeDescriptor.getElementTypeDescriptor();
|
TypeDescriptor elementTypeDesc = typeDescriptor.getElementTypeDescriptor();
|
||||||
if (elementTypeDesc != null) {
|
if (elementTypeDesc != null) {
|
||||||
Class<?> elementType = elementTypeDesc.getType();
|
Class<?> elementType = elementTypeDesc.getType();
|
||||||
if (Class.class == elementType || Enum.class.isAssignableFrom(elementType)) {
|
if (Class.class == elementType || Enum.class.isAssignableFrom(elementType)) {
|
||||||
convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue);
|
convertedValue = StringUtils.commaDelimitedListToStringArray(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,21 +166,19 @@ class TypeConverterDelegate {
|
||||||
}
|
}
|
||||||
else if (requiredType.isArray()) {
|
else if (requiredType.isArray()) {
|
||||||
// Array required -> apply appropriate conversion of elements.
|
// Array required -> apply appropriate conversion of elements.
|
||||||
if (convertedValue instanceof String && Enum.class.isAssignableFrom(requiredType.getComponentType())) {
|
if (convertedValue instanceof String text && Enum.class.isAssignableFrom(requiredType.getComponentType())) {
|
||||||
convertedValue = StringUtils.commaDelimitedListToStringArray((String) convertedValue);
|
convertedValue = StringUtils.commaDelimitedListToStringArray(text);
|
||||||
}
|
}
|
||||||
return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType());
|
return (T) convertToTypedArray(convertedValue, propertyName, requiredType.getComponentType());
|
||||||
}
|
}
|
||||||
else if (convertedValue instanceof Collection) {
|
else if (convertedValue instanceof Collection<?> coll) {
|
||||||
// Convert elements to target type, if determined.
|
// Convert elements to target type, if determined.
|
||||||
convertedValue = convertToTypedCollection(
|
convertedValue = convertToTypedCollection(coll, propertyName, requiredType, typeDescriptor);
|
||||||
(Collection<?>) convertedValue, propertyName, requiredType, typeDescriptor);
|
|
||||||
standardConversion = true;
|
standardConversion = true;
|
||||||
}
|
}
|
||||||
else if (convertedValue instanceof Map) {
|
else if (convertedValue instanceof Map<?, ?> map) {
|
||||||
// Convert keys and values to respective target type, if determined.
|
// Convert keys and values to respective target type, if determined.
|
||||||
convertedValue = convertToTypedMap(
|
convertedValue = convertToTypedMap(map, propertyName, requiredType, typeDescriptor);
|
||||||
(Map<?, ?>) convertedValue, propertyName, requiredType, typeDescriptor);
|
|
||||||
standardConversion = true;
|
standardConversion = true;
|
||||||
}
|
}
|
||||||
if (convertedValue.getClass().isArray() && Array.getLength(convertedValue) == 1) {
|
if (convertedValue.getClass().isArray() && Array.getLength(convertedValue) == 1) {
|
||||||
|
|
@ -191,7 +189,7 @@ class TypeConverterDelegate {
|
||||||
// We can stringify any primitive value...
|
// We can stringify any primitive value...
|
||||||
return (T) convertedValue.toString();
|
return (T) convertedValue.toString();
|
||||||
}
|
}
|
||||||
else if (convertedValue instanceof String && !requiredType.isInstance(convertedValue)) {
|
else if (convertedValue instanceof String text && !requiredType.isInstance(convertedValue)) {
|
||||||
if (conversionAttemptEx == null && !requiredType.isInterface() && !requiredType.isEnum()) {
|
if (conversionAttemptEx == null && !requiredType.isInterface() && !requiredType.isEnum()) {
|
||||||
try {
|
try {
|
||||||
Constructor<T> strCtor = requiredType.getConstructor(String.class);
|
Constructor<T> strCtor = requiredType.getConstructor(String.class);
|
||||||
|
|
@ -209,7 +207,7 @@ class TypeConverterDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String trimmedValue = ((String) convertedValue).trim();
|
String trimmedValue = text.trim();
|
||||||
if (requiredType.isEnum() && trimmedValue.isEmpty()) {
|
if (requiredType.isEnum() && trimmedValue.isEmpty()) {
|
||||||
// It's an empty enum identifier: reset the enum value to null.
|
// It's an empty enum identifier: reset the enum value to null.
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -217,9 +215,8 @@ class TypeConverterDelegate {
|
||||||
convertedValue = attemptToConvertStringToEnum(requiredType, trimmedValue, convertedValue);
|
convertedValue = attemptToConvertStringToEnum(requiredType, trimmedValue, convertedValue);
|
||||||
standardConversion = true;
|
standardConversion = true;
|
||||||
}
|
}
|
||||||
else if (convertedValue instanceof Number && Number.class.isAssignableFrom(requiredType)) {
|
else if (convertedValue instanceof Number num && Number.class.isAssignableFrom(requiredType)) {
|
||||||
convertedValue = NumberUtils.convertNumberToTargetClass(
|
convertedValue = NumberUtils.convertNumberToTargetClass(num, (Class<Number>) requiredType);
|
||||||
(Number) convertedValue, (Class<Number>) requiredType);
|
|
||||||
standardConversion = true;
|
standardConversion = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -382,23 +379,22 @@ class TypeConverterDelegate {
|
||||||
|
|
||||||
Object returnValue = convertedValue;
|
Object returnValue = convertedValue;
|
||||||
|
|
||||||
if (requiredType != null && !requiredType.isArray() && convertedValue instanceof String[]) {
|
if (requiredType != null && !requiredType.isArray() && convertedValue instanceof String[] array) {
|
||||||
// Convert String array to a comma-separated String.
|
// Convert String array to a comma-separated String.
|
||||||
// Only applies if no PropertyEditor converted the String array before.
|
// Only applies if no PropertyEditor converted the String array before.
|
||||||
// The CSV String will be passed into a PropertyEditor's setAsText method, if any.
|
// The CSV String will be passed into a PropertyEditor's setAsText method, if any.
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Converting String array to comma-delimited String [" + convertedValue + "]");
|
logger.trace("Converting String array to comma-delimited String [" + convertedValue + "]");
|
||||||
}
|
}
|
||||||
convertedValue = StringUtils.arrayToCommaDelimitedString((String[]) convertedValue);
|
convertedValue = StringUtils.arrayToCommaDelimitedString(array);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convertedValue instanceof String) {
|
if (convertedValue instanceof String newTextValue) {
|
||||||
if (editor != null) {
|
if (editor != null) {
|
||||||
// Use PropertyEditor's setAsText in case of a String value.
|
// Use PropertyEditor's setAsText in case of a String value.
|
||||||
if (logger.isTraceEnabled()) {
|
if (logger.isTraceEnabled()) {
|
||||||
logger.trace("Converting String to [" + requiredType + "] using property editor [" + editor + "]");
|
logger.trace("Converting String to [" + requiredType + "] using property editor [" + editor + "]");
|
||||||
}
|
}
|
||||||
String newTextValue = (String) convertedValue;
|
|
||||||
return doConvertTextValue(oldValue, newTextValue, editor);
|
return doConvertTextValue(oldValue, newTextValue, editor);
|
||||||
}
|
}
|
||||||
else if (String.class == requiredType) {
|
else if (String.class == requiredType) {
|
||||||
|
|
@ -431,9 +427,8 @@ class TypeConverterDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object convertToTypedArray(Object input, @Nullable String propertyName, Class<?> componentType) {
|
private Object convertToTypedArray(Object input, @Nullable String propertyName, Class<?> componentType) {
|
||||||
if (input instanceof Collection) {
|
if (input instanceof Collection<?> coll) {
|
||||||
// Convert Collection elements to array elements.
|
// Convert Collection elements to array elements.
|
||||||
Collection<?> coll = (Collection<?>) input;
|
|
||||||
Object result = Array.newInstance(componentType, coll.size());
|
Object result = Array.newInstance(componentType, coll.size());
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Iterator<?> it = coll.iterator(); it.hasNext(); i++) {
|
for (Iterator<?> it = coll.iterator(); it.hasNext(); i++) {
|
||||||
|
|
|
||||||
|
|
@ -204,8 +204,7 @@ public class BeanCreationException extends FatalBeanException {
|
||||||
}
|
}
|
||||||
if (this.relatedCauses != null) {
|
if (this.relatedCauses != null) {
|
||||||
for (Throwable relatedCause : this.relatedCauses) {
|
for (Throwable relatedCause : this.relatedCauses) {
|
||||||
if (relatedCause instanceof NestedRuntimeException &&
|
if (relatedCause instanceof NestedRuntimeException nested && nested.contains(exClass)) {
|
||||||
((NestedRuntimeException) relatedCause).contains(exClass)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -266,11 +266,11 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) {
|
public void setBeanFactory(BeanFactory beanFactory) {
|
||||||
if (!(beanFactory instanceof ConfigurableListableBeanFactory)) {
|
if (!(beanFactory instanceof ConfigurableListableBeanFactory clbf)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory: " + beanFactory);
|
"AutowiredAnnotationBeanPostProcessor requires a ConfigurableListableBeanFactory: " + beanFactory);
|
||||||
}
|
}
|
||||||
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
|
this.beanFactory = clbf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -281,8 +281,8 @@ public class InjectionMetadata {
|
||||||
this.skip = true;
|
this.skip = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (pvs instanceof MutablePropertyValues) {
|
else if (pvs instanceof MutablePropertyValues mpvs) {
|
||||||
((MutablePropertyValues) pvs).registerProcessedProperty(this.pd.getName());
|
mpvs.registerProcessedProperty(this.pd.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.skip = false;
|
this.skip = false;
|
||||||
|
|
@ -299,8 +299,8 @@ public class InjectionMetadata {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
synchronized (pvs) {
|
synchronized (pvs) {
|
||||||
if (Boolean.FALSE.equals(this.skip) && this.pd != null && pvs instanceof MutablePropertyValues) {
|
if (Boolean.FALSE.equals(this.skip) && this.pd != null && pvs instanceof MutablePropertyValues mpvs) {
|
||||||
((MutablePropertyValues) pvs).clearProcessedProperty(this.pd.getName());
|
mpvs.clearProcessedProperty(this.pd.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -279,7 +279,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa
|
||||||
actualValue = bd.getAttribute(attributeName);
|
actualValue = bd.getAttribute(attributeName);
|
||||||
}
|
}
|
||||||
if (actualValue == null && attributeName.equals(AutowireCandidateQualifier.VALUE_KEY) &&
|
if (actualValue == null && attributeName.equals(AutowireCandidateQualifier.VALUE_KEY) &&
|
||||||
expectedValue instanceof String && bdHolder.matchesName((String) expectedValue)) {
|
expectedValue instanceof String name && bdHolder.matchesName(name)) {
|
||||||
// Fall back on bean name (or alias) match
|
// Fall back on bean name (or alias) match
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -212,11 +212,11 @@ public final class BeanInstanceSupplier<T> extends AutowiredElementResolver impl
|
||||||
}
|
}
|
||||||
|
|
||||||
private T invokeBeanSupplier(Executable executable, ThrowingSupplier<T> beanSupplier) {
|
private T invokeBeanSupplier(Executable executable, ThrowingSupplier<T> beanSupplier) {
|
||||||
if (!(executable instanceof Method)) {
|
if (!(executable instanceof Method method)) {
|
||||||
return beanSupplier.get();
|
return beanSupplier.get();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
SimpleInstantiationStrategy.setCurrentlyInvokedFactoryMethod((Method) executable);
|
SimpleInstantiationStrategy.setCurrentlyInvokedFactoryMethod(method);
|
||||||
return beanSupplier.get();
|
return beanSupplier.get();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,8 @@ public abstract class AbstractFactoryBean<T>
|
||||||
*/
|
*/
|
||||||
protected TypeConverter getBeanTypeConverter() {
|
protected TypeConverter getBeanTypeConverter() {
|
||||||
BeanFactory beanFactory = getBeanFactory();
|
BeanFactory beanFactory = getBeanFactory();
|
||||||
if (beanFactory instanceof ConfigurableBeanFactory) {
|
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||||
return ((ConfigurableBeanFactory) beanFactory).getTypeConverter();
|
return cbf.getTypeConverter();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new SimpleTypeConverter();
|
return new SimpleTypeConverter();
|
||||||
|
|
|
||||||
|
|
@ -172,11 +172,11 @@ public class BeanDefinitionVisitor {
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Nullable
|
@Nullable
|
||||||
protected Object resolveValue(@Nullable Object value) {
|
protected Object resolveValue(@Nullable Object value) {
|
||||||
if (value instanceof BeanDefinition) {
|
if (value instanceof BeanDefinition beanDef) {
|
||||||
visitBeanDefinition((BeanDefinition) value);
|
visitBeanDefinition(beanDef);
|
||||||
}
|
}
|
||||||
else if (value instanceof BeanDefinitionHolder) {
|
else if (value instanceof BeanDefinitionHolder beanDefHolder) {
|
||||||
visitBeanDefinition(((BeanDefinitionHolder) value).getBeanDefinition());
|
visitBeanDefinition(beanDefHolder.getBeanDefinition());
|
||||||
}
|
}
|
||||||
else if (value instanceof RuntimeBeanReference ref) {
|
else if (value instanceof RuntimeBeanReference ref) {
|
||||||
String newBeanName = resolveStringValue(ref.getBeanName());
|
String newBeanName = resolveStringValue(ref.getBeanName());
|
||||||
|
|
@ -196,17 +196,17 @@ public class BeanDefinitionVisitor {
|
||||||
return new RuntimeBeanNameReference(newBeanName);
|
return new RuntimeBeanNameReference(newBeanName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (value instanceof Object[]) {
|
else if (value instanceof Object[] array) {
|
||||||
visitArray((Object[]) value);
|
visitArray(array);
|
||||||
}
|
}
|
||||||
else if (value instanceof List) {
|
else if (value instanceof List list) {
|
||||||
visitList((List) value);
|
visitList(list);
|
||||||
}
|
}
|
||||||
else if (value instanceof Set) {
|
else if (value instanceof Set set) {
|
||||||
visitSet((Set) value);
|
visitSet(set);
|
||||||
}
|
}
|
||||||
else if (value instanceof Map) {
|
else if (value instanceof Map map) {
|
||||||
visitMap((Map) value);
|
visitMap(map);
|
||||||
}
|
}
|
||||||
else if (value instanceof TypedStringValue typedStringValue) {
|
else if (value instanceof TypedStringValue typedStringValue) {
|
||||||
String stringValue = typedStringValue.getValue();
|
String stringValue = typedStringValue.getValue();
|
||||||
|
|
@ -215,8 +215,8 @@ public class BeanDefinitionVisitor {
|
||||||
typedStringValue.setValue(visitedString);
|
typedStringValue.setValue(visitedString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (value instanceof String) {
|
else if (value instanceof String strValue) {
|
||||||
return resolveStringValue((String) value);
|
return resolveStringValue(strValue);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,15 +98,15 @@ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClas
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||||
if (this.scopes != null) {
|
if (this.scopes != null) {
|
||||||
this.scopes.forEach((scopeKey, value) -> {
|
this.scopes.forEach((scopeKey, value) -> {
|
||||||
if (value instanceof Scope) {
|
if (value instanceof Scope scope) {
|
||||||
beanFactory.registerScope(scopeKey, (Scope) value);
|
beanFactory.registerScope(scopeKey, scope);
|
||||||
}
|
}
|
||||||
else if (value instanceof Class<?> scopeClass) {
|
else if (value instanceof Class<?> scopeClass) {
|
||||||
Assert.isAssignable(Scope.class, scopeClass, "Invalid scope class");
|
Assert.isAssignable(Scope.class, scopeClass, "Invalid scope class");
|
||||||
beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
|
beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
|
||||||
}
|
}
|
||||||
else if (value instanceof String) {
|
else if (value instanceof String scopeClassName) {
|
||||||
Class<?> scopeClass = ClassUtils.resolveClassName((String) value, this.beanClassLoader);
|
Class<?> scopeClass = ClassUtils.resolveClassName(scopeClassName, this.beanClassLoader);
|
||||||
Assert.isAssignable(Scope.class, scopeClass, "Invalid scope class");
|
Assert.isAssignable(Scope.class, scopeClass, "Invalid scope class");
|
||||||
beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
|
beanFactory.registerScope(scopeKey, (Scope) BeanUtils.instantiateClass(scopeClass));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,8 @@ public class MethodInvokingBean extends ArgumentConvertingMethodInvoker
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) {
|
public void setBeanFactory(BeanFactory beanFactory) {
|
||||||
if (beanFactory instanceof ConfigurableBeanFactory) {
|
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||||
this.beanFactory = (ConfigurableBeanFactory) beanFactory;
|
this.beanFactory = cbf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,11 +123,11 @@ public class MethodInvokingBean extends ArgumentConvertingMethodInvoker
|
||||||
return invoke();
|
return invoke();
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException ex) {
|
catch (InvocationTargetException ex) {
|
||||||
if (ex.getTargetException() instanceof Exception) {
|
if (ex.getTargetException() instanceof Exception exception) {
|
||||||
throw (Exception) ex.getTargetException();
|
throw exception;
|
||||||
}
|
}
|
||||||
if (ex.getTargetException() instanceof Error) {
|
if (ex.getTargetException() instanceof Error error) {
|
||||||
throw (Error) ex.getTargetException();
|
throw error;
|
||||||
}
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -206,8 +206,8 @@ public class PropertyPathFactoryBean implements FactoryBean<Object>, BeanNameAwa
|
||||||
BeanWrapper target = this.targetBeanWrapper;
|
BeanWrapper target = this.targetBeanWrapper;
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
if (logger.isWarnEnabled() && this.targetBeanName != null &&
|
if (logger.isWarnEnabled() && this.targetBeanName != null &&
|
||||||
this.beanFactory instanceof ConfigurableBeanFactory &&
|
this.beanFactory instanceof ConfigurableBeanFactory cbf &&
|
||||||
((ConfigurableBeanFactory) this.beanFactory).isCurrentlyInCreation(this.targetBeanName)) {
|
cbf.isCurrentlyInCreation(this.targetBeanName)) {
|
||||||
logger.warn("Target bean '" + this.targetBeanName + "' is still in creation due to a circular " +
|
logger.warn("Target bean '" + this.targetBeanName + "' is still in creation due to a circular " +
|
||||||
"reference - obtained value for property '" + this.propertyPath + "' may be outdated!");
|
"reference - obtained value for property '" + this.propertyPath + "' may be outdated!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -250,11 +250,11 @@ public class ServiceLocatorFactoryBean implements FactoryBean<Object>, BeanFacto
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||||
if (!(beanFactory instanceof ListableBeanFactory)) {
|
if (!(beanFactory instanceof ListableBeanFactory lbf)) {
|
||||||
throw new FatalBeanException(
|
throw new FatalBeanException(
|
||||||
"ServiceLocatorFactoryBean needs to run in a BeanFactory that is a ListableBeanFactory");
|
"ServiceLocatorFactoryBean needs to run in a BeanFactory that is a ListableBeanFactory");
|
||||||
}
|
}
|
||||||
this.beanFactory = (ListableBeanFactory) beanFactory;
|
this.beanFactory = lbf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -129,10 +129,9 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean<Map
|
||||||
private void merge(Map<String, Object> output, Map<String, Object> map) {
|
private void merge(Map<String, Object> output, Map<String, Object> map) {
|
||||||
map.forEach((key, value) -> {
|
map.forEach((key, value) -> {
|
||||||
Object existing = output.get(key);
|
Object existing = output.get(key);
|
||||||
if (value instanceof Map && existing instanceof Map) {
|
if (value instanceof Map valueMap && existing instanceof Map existingMap) {
|
||||||
// Inner cast required by Eclipse IDE.
|
Map<String, Object> result = new LinkedHashMap<>(existingMap);
|
||||||
Map<String, Object> result = new LinkedHashMap<>((Map<String, Object>) existing);
|
merge(result, valueMap);
|
||||||
merge(result, (Map) value);
|
|
||||||
output.put(key, result);
|
output.put(key, result);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -226,17 +226,16 @@ public abstract class YamlProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private Map<String, Object> asMap(Object object) {
|
private Map<String, Object> asMap(Object object) {
|
||||||
// YAML can have numbers as keys
|
// YAML can have numbers as keys
|
||||||
Map<String, Object> result = new LinkedHashMap<>();
|
Map<String, Object> result = new LinkedHashMap<>();
|
||||||
if (!(object instanceof Map)) {
|
if (!(object instanceof Map map)) {
|
||||||
// A document can be a text literal
|
// A document can be a text literal
|
||||||
result.put("document", object);
|
result.put("document", object);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Object, Object> map = (Map<Object, Object>) object;
|
|
||||||
map.forEach((key, value) -> {
|
map.forEach((key, value) -> {
|
||||||
if (value instanceof Map) {
|
if (value instanceof Map) {
|
||||||
value = asMap(value);
|
value = asMap(value);
|
||||||
|
|
@ -306,6 +305,7 @@ public abstract class YamlProcessor {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, @Nullable String path) {
|
private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, @Nullable String path) {
|
||||||
source.forEach((key, value) -> {
|
source.forEach((key, value) -> {
|
||||||
if (StringUtils.hasText(path)) {
|
if (StringUtils.hasText(path)) {
|
||||||
|
|
@ -319,16 +319,12 @@ public abstract class YamlProcessor {
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
result.put(key, value);
|
result.put(key, value);
|
||||||
}
|
}
|
||||||
else if (value instanceof Map) {
|
else if (value instanceof Map map) {
|
||||||
// Need a compound key
|
// Need a compound key
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Map<String, Object> map = (Map<String, Object>) value;
|
|
||||||
buildFlattenedMap(result, map, key);
|
buildFlattenedMap(result, map, key);
|
||||||
}
|
}
|
||||||
else if (value instanceof Collection) {
|
else if (value instanceof Collection collection) {
|
||||||
// Need a compound key
|
// Need a compound key
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Collection<Object> collection = (Collection<Object>) value;
|
|
||||||
if (collection.isEmpty()) {
|
if (collection.isEmpty()) {
|
||||||
result.put(key, "");
|
result.put(key, "");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -318,8 +318,8 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||||
if (!ObjectUtils.isEmpty(args)) {
|
if (!ObjectUtils.isEmpty(args)) {
|
||||||
int index = args.length;
|
int index = args.length;
|
||||||
Object lastArg = args[index - 1];
|
Object lastArg = args[index - 1];
|
||||||
if (lastArg instanceof Closure<?>) {
|
if (lastArg instanceof Closure<?> closure) {
|
||||||
callable = (Closure<?>) lastArg;
|
callable = closure;
|
||||||
index--;
|
index--;
|
||||||
}
|
}
|
||||||
constructorArgs = resolveConstructorArguments(args, 0, index);
|
constructorArgs = resolveConstructorArguments(args, 0, index);
|
||||||
|
|
|
||||||
|
|
@ -139,22 +139,22 @@ class GroovyBeanDefinitionWrapper extends GroovyObjectSupport {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
throw new IllegalArgumentException("Parent bean cannot be set to a null runtime bean reference!");
|
throw new IllegalArgumentException("Parent bean cannot be set to a null runtime bean reference!");
|
||||||
}
|
}
|
||||||
if (obj instanceof String) {
|
if (obj instanceof String name) {
|
||||||
this.parentName = (String) obj;
|
this.parentName = name;
|
||||||
}
|
}
|
||||||
else if (obj instanceof RuntimeBeanReference) {
|
else if (obj instanceof RuntimeBeanReference runtimeBeanReference) {
|
||||||
this.parentName = ((RuntimeBeanReference) obj).getBeanName();
|
this.parentName = runtimeBeanReference.getBeanName();
|
||||||
}
|
}
|
||||||
else if (obj instanceof GroovyBeanDefinitionWrapper) {
|
else if (obj instanceof GroovyBeanDefinitionWrapper wrapper) {
|
||||||
this.parentName = ((GroovyBeanDefinitionWrapper) obj).getBeanName();
|
this.parentName = wrapper.getBeanName();
|
||||||
}
|
}
|
||||||
getBeanDefinition().setParentName(this.parentName);
|
getBeanDefinition().setParentName(this.parentName);
|
||||||
getBeanDefinition().setAbstract(false);
|
getBeanDefinition().setAbstract(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GroovyBeanDefinitionWrapper addProperty(String propertyName, Object propertyValue) {
|
public GroovyBeanDefinitionWrapper addProperty(String propertyName, Object propertyValue) {
|
||||||
if (propertyValue instanceof GroovyBeanDefinitionWrapper) {
|
if (propertyValue instanceof GroovyBeanDefinitionWrapper wrapper) {
|
||||||
propertyValue = ((GroovyBeanDefinitionWrapper) propertyValue).getBeanDefinition();
|
propertyValue = wrapper.getBeanDefinition();
|
||||||
}
|
}
|
||||||
getBeanDefinition().getPropertyValues().add(propertyName, propertyValue);
|
getBeanDefinition().getPropertyValues().add(propertyName, propertyValue);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
|
|
@ -73,14 +73,14 @@ public class BeanComponentDefinition extends BeanDefinitionHolder implements Com
|
||||||
PropertyValues propertyValues = beanDefinitionHolder.getBeanDefinition().getPropertyValues();
|
PropertyValues propertyValues = beanDefinitionHolder.getBeanDefinition().getPropertyValues();
|
||||||
for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
|
for (PropertyValue propertyValue : propertyValues.getPropertyValues()) {
|
||||||
Object value = propertyValue.getValue();
|
Object value = propertyValue.getValue();
|
||||||
if (value instanceof BeanDefinitionHolder) {
|
if (value instanceof BeanDefinitionHolder beanDefHolder) {
|
||||||
innerBeans.add(((BeanDefinitionHolder) value).getBeanDefinition());
|
innerBeans.add(beanDefHolder.getBeanDefinition());
|
||||||
}
|
}
|
||||||
else if (value instanceof BeanDefinition) {
|
else if (value instanceof BeanDefinition beanDef) {
|
||||||
innerBeans.add((BeanDefinition) value);
|
innerBeans.add(beanDef);
|
||||||
}
|
}
|
||||||
else if (value instanceof BeanReference) {
|
else if (value instanceof BeanReference beanRef) {
|
||||||
references.add((BeanReference) value);
|
references.add(beanRef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[0]);
|
this.innerBeanDefinitions = innerBeans.toArray(new BeanDefinition[0]);
|
||||||
|
|
|
||||||
|
|
@ -1619,8 +1619,8 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||||
MutablePropertyValues mpvs = null;
|
MutablePropertyValues mpvs = null;
|
||||||
List<PropertyValue> original;
|
List<PropertyValue> original;
|
||||||
|
|
||||||
if (pvs instanceof MutablePropertyValues) {
|
if (pvs instanceof MutablePropertyValues _mpvs) {
|
||||||
mpvs = (MutablePropertyValues) pvs;
|
mpvs = _mpvs;
|
||||||
if (mpvs.isConverted()) {
|
if (mpvs.isConverted()) {
|
||||||
// Shortcut: use the pre-converted values as-is.
|
// Shortcut: use the pre-converted values as-is.
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -86,16 +86,16 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
|
|
||||||
// Determine ResourceLoader to use.
|
// Determine ResourceLoader to use.
|
||||||
if (this.registry instanceof ResourceLoader) {
|
if (this.registry instanceof ResourceLoader _resourceLoader) {
|
||||||
this.resourceLoader = (ResourceLoader) this.registry;
|
this.resourceLoader = _resourceLoader;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.resourceLoader = new PathMatchingResourcePatternResolver();
|
this.resourceLoader = new PathMatchingResourcePatternResolver();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inherit Environment if possible
|
// Inherit Environment if possible
|
||||||
if (this.registry instanceof EnvironmentCapable) {
|
if (this.registry instanceof EnvironmentCapable environmentCapable) {
|
||||||
this.environment = ((EnvironmentCapable) this.registry).getEnvironment();
|
this.environment = environmentCapable.getEnvironment();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.environment = new StandardEnvironment();
|
this.environment = new StandardEnvironment();
|
||||||
|
|
@ -213,10 +213,10 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead
|
||||||
"Cannot load bean definitions from location [" + location + "]: no ResourceLoader available");
|
"Cannot load bean definitions from location [" + location + "]: no ResourceLoader available");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resourceLoader instanceof ResourcePatternResolver) {
|
if (resourceLoader instanceof ResourcePatternResolver resourcePatternResolver) {
|
||||||
// Resource pattern matching available.
|
// Resource pattern matching available.
|
||||||
try {
|
try {
|
||||||
Resource[] resources = ((ResourcePatternResolver) resourceLoader).getResources(location);
|
Resource[] resources = resourcePatternResolver.getResources(location);
|
||||||
int count = loadBeanDefinitions(resources);
|
int count = loadBeanDefinitions(resources);
|
||||||
if (actualResources != null) {
|
if (actualResources != null) {
|
||||||
Collections.addAll(actualResources, resources);
|
Collections.addAll(actualResources, resources);
|
||||||
|
|
|
||||||
|
|
@ -1540,8 +1540,8 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||||
if (evaluated instanceof Class<?> clazz) {
|
if (evaluated instanceof Class<?> clazz) {
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
else if (evaluated instanceof String str) {
|
else if (evaluated instanceof String name) {
|
||||||
className = str;
|
className = name;
|
||||||
freshResolve = true;
|
freshResolve = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -222,13 +222,13 @@ abstract class AutowireUtils {
|
||||||
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
||||||
for (Type typeArg : actualTypeArguments) {
|
for (Type typeArg : actualTypeArguments) {
|
||||||
if (typeArg.equals(genericReturnType)) {
|
if (typeArg.equals(genericReturnType)) {
|
||||||
if (arg instanceof Class) {
|
if (arg instanceof Class<?> clazz) {
|
||||||
return (Class<?>) arg;
|
return clazz;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String className = null;
|
String className = null;
|
||||||
if (arg instanceof String) {
|
if (arg instanceof String name) {
|
||||||
className = (String) arg;
|
className = name;
|
||||||
}
|
}
|
||||||
else if (arg instanceof TypedStringValue typedValue) {
|
else if (arg instanceof TypedStringValue typedValue) {
|
||||||
String targetTypeName = typedValue.getTargetTypeName();
|
String targetTypeName = typedValue.getTargetTypeName();
|
||||||
|
|
|
||||||
|
|
@ -81,9 +81,9 @@ class BeanDefinitionResource extends AbstractResource {
|
||||||
* This implementation compares the underlying BeanDefinition.
|
* This implementation compares the underlying BeanDefinition.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object other) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
return (this == other || (other instanceof BeanDefinitionResource &&
|
return (this == obj || (obj instanceof BeanDefinitionResource that &&
|
||||||
((BeanDefinitionResource) other).beanDefinition.equals(this.beanDefinition)));
|
this.beanDefinition.equals(that.beanDefinition)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -154,8 +154,8 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt
|
||||||
enhancer.setSuperclass(beanDefinition.getBeanClass());
|
enhancer.setSuperclass(beanDefinition.getBeanClass());
|
||||||
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
|
enhancer.setNamingPolicy(SpringNamingPolicy.INSTANCE);
|
||||||
enhancer.setAttemptLoad(true);
|
enhancer.setAttemptLoad(true);
|
||||||
if (this.owner instanceof ConfigurableBeanFactory) {
|
if (this.owner instanceof ConfigurableBeanFactory cbf) {
|
||||||
ClassLoader cl = ((ConfigurableBeanFactory) this.owner).getBeanClassLoader();
|
ClassLoader cl = cbf.getBeanClassLoader();
|
||||||
enhancer.setStrategy(new ClassLoaderAwareGeneratorStrategy(cl));
|
enhancer.setStrategy(new ClassLoaderAwareGeneratorStrategy(cl));
|
||||||
}
|
}
|
||||||
enhancer.setCallbackFilter(new MethodOverrideCallbackFilter(beanDefinition));
|
enhancer.setCallbackFilter(new MethodOverrideCallbackFilter(beanDefinition));
|
||||||
|
|
|
||||||
|
|
@ -766,8 +766,8 @@ class ConstructorResolver {
|
||||||
"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
|
"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
Object sourceHolder = valueHolder.getSource();
|
Object sourceHolder = valueHolder.getSource();
|
||||||
if (sourceHolder instanceof ConstructorArgumentValues.ValueHolder) {
|
if (sourceHolder instanceof ConstructorArgumentValues.ValueHolder constructorValueHolder) {
|
||||||
Object sourceValue = ((ConstructorArgumentValues.ValueHolder) sourceHolder).getValue();
|
Object sourceValue = constructorValueHolder.getValue();
|
||||||
args.resolveNecessary = true;
|
args.resolveNecessary = true;
|
||||||
args.preparedArguments[paramIndex] = sourceValue;
|
args.preparedArguments[paramIndex] = sourceValue;
|
||||||
}
|
}
|
||||||
|
|
@ -834,8 +834,8 @@ class ConstructorResolver {
|
||||||
else if (argValue instanceof BeanMetadataElement) {
|
else if (argValue instanceof BeanMetadataElement) {
|
||||||
argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
|
argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
|
||||||
}
|
}
|
||||||
else if (argValue instanceof String) {
|
else if (argValue instanceof String text) {
|
||||||
argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
|
argValue = this.beanFactory.evaluateBeanDefinitionString(text, mbd);
|
||||||
}
|
}
|
||||||
Class<?> paramType = paramTypes[argIndex];
|
Class<?> paramType = paramTypes[argIndex];
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -188,11 +188,11 @@ public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanReg
|
||||||
* @throws BeansException if the given bean cannot be exposed as a FactoryBean
|
* @throws BeansException if the given bean cannot be exposed as a FactoryBean
|
||||||
*/
|
*/
|
||||||
protected FactoryBean<?> getFactoryBean(String beanName, Object beanInstance) throws BeansException {
|
protected FactoryBean<?> getFactoryBean(String beanName, Object beanInstance) throws BeansException {
|
||||||
if (!(beanInstance instanceof FactoryBean)) {
|
if (!(beanInstance instanceof FactoryBean<?> factoryBean)) {
|
||||||
throw new BeanCreationException(beanName,
|
throw new BeanCreationException(beanName,
|
||||||
"Bean instance of type [" + beanInstance.getClass() + "] is not a FactoryBean");
|
"Bean instance of type [" + beanInstance.getClass() + "] is not a FactoryBean");
|
||||||
}
|
}
|
||||||
return (FactoryBean<?>) beanInstance;
|
return factoryBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,8 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan
|
||||||
ResolvableType targetType = null;
|
ResolvableType targetType = null;
|
||||||
boolean cacheType = false;
|
boolean cacheType = false;
|
||||||
RootBeanDefinition rbd = null;
|
RootBeanDefinition rbd = null;
|
||||||
if (bdHolder.getBeanDefinition() instanceof RootBeanDefinition) {
|
if (bdHolder.getBeanDefinition() instanceof RootBeanDefinition rootBeanDef) {
|
||||||
rbd = (RootBeanDefinition) bdHolder.getBeanDefinition();
|
rbd = rootBeanDef;
|
||||||
}
|
}
|
||||||
if (rbd != null) {
|
if (rbd != null) {
|
||||||
targetType = rbd.targetType;
|
targetType = rbd.targetType;
|
||||||
|
|
@ -161,8 +161,8 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan
|
||||||
if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory clbf) {
|
if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory clbf) {
|
||||||
if (clbf.containsBeanDefinition(decDef.getBeanName())) {
|
if (clbf.containsBeanDefinition(decDef.getBeanName())) {
|
||||||
BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
|
BeanDefinition dbd = clbf.getMergedBeanDefinition(decDef.getBeanName());
|
||||||
if (dbd instanceof RootBeanDefinition) {
|
if (dbd instanceof RootBeanDefinition rootBeanDef) {
|
||||||
return (RootBeanDefinition) dbd;
|
return rootBeanDef;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,11 @@ public class ManagedProperties extends Properties implements Mergeable, BeanMeta
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
if (!(parent instanceof Properties)) {
|
if (!(parent instanceof Properties properties)) {
|
||||||
throw new IllegalArgumentException("Cannot merge with object of type [" + parent.getClass() + "]");
|
throw new IllegalArgumentException("Cannot merge with object of type [" + parent.getClass() + "]");
|
||||||
}
|
}
|
||||||
Properties merged = new ManagedProperties();
|
Properties merged = new ManagedProperties();
|
||||||
merged.putAll((Properties) parent);
|
merged.putAll(properties);
|
||||||
merged.putAll(this);
|
merged.putAll(this);
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -433,10 +433,10 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInstanceSupplier(@Nullable Supplier<?> instanceSupplier) {
|
public void setInstanceSupplier(@Nullable Supplier<?> supplier) {
|
||||||
super.setInstanceSupplier(instanceSupplier);
|
super.setInstanceSupplier(supplier);
|
||||||
Method factoryMethod = (instanceSupplier instanceof InstanceSupplier<?> ?
|
Method factoryMethod = (supplier instanceof InstanceSupplier<?> instanceSupplier ?
|
||||||
((InstanceSupplier<?>) instanceSupplier).getFactoryMethod() : null);
|
instanceSupplier.getFactoryMethod() : null);
|
||||||
if (factoryMethod != null) {
|
if (factoryMethod != null) {
|
||||||
setResolvedFactoryMethod(factoryMethod);
|
setResolvedFactoryMethod(factoryMethod);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,11 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setBeanFactory(BeanFactory beanFactory) {
|
public void setBeanFactory(BeanFactory beanFactory) {
|
||||||
if (!(beanFactory instanceof ConfigurableListableBeanFactory)) {
|
if (!(beanFactory instanceof ConfigurableListableBeanFactory clbf)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Bean configurer aspect needs to run in a ConfigurableListableBeanFactory: " + beanFactory);
|
"Bean configurer aspect needs to run in a ConfigurableListableBeanFactory: " + beanFactory);
|
||||||
}
|
}
|
||||||
this.beanFactory = (ConfigurableListableBeanFactory) beanFactory;
|
this.beanFactory = clbf;
|
||||||
if (this.beanWiringInfoResolver == null) {
|
if (this.beanWiringInfoResolver == null) {
|
||||||
this.beanWiringInfoResolver = createDefaultBeanWiringInfoResolver();
|
this.beanWiringInfoResolver = createDefaultBeanWiringInfoResolver();
|
||||||
}
|
}
|
||||||
|
|
@ -158,8 +158,7 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean
|
||||||
}
|
}
|
||||||
catch (BeanCreationException ex) {
|
catch (BeanCreationException ex) {
|
||||||
Throwable rootCause = ex.getMostSpecificCause();
|
Throwable rootCause = ex.getMostSpecificCause();
|
||||||
if (rootCause instanceof BeanCurrentlyInCreationException) {
|
if (rootCause instanceof BeanCurrentlyInCreationException bce) {
|
||||||
BeanCreationException bce = (BeanCreationException) rootCause;
|
|
||||||
String bceBeanName = bce.getBeanName();
|
String bceBeanName = bce.getBeanName();
|
||||||
if (bceBeanName != null && beanFactory.isCurrentlyInCreation(bceBeanName)) {
|
if (bceBeanName != null && beanFactory.isCurrentlyInCreation(bceBeanName)) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
|
|
|
||||||
|
|
@ -916,14 +916,14 @@ public class BeanDefinitionParserDelegate {
|
||||||
Element subElement = null;
|
Element subElement = null;
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element && !nodeNameEquals(node, DESCRIPTION_ELEMENT) &&
|
if (node instanceof Element currentElement && !nodeNameEquals(node, DESCRIPTION_ELEMENT) &&
|
||||||
!nodeNameEquals(node, META_ELEMENT)) {
|
!nodeNameEquals(node, META_ELEMENT)) {
|
||||||
// Child element is what we're looking for.
|
// Child element is what we're looking for.
|
||||||
if (subElement != null) {
|
if (subElement != null) {
|
||||||
error(elementName + " must not contain more than one sub-element", ele);
|
error(elementName + " must not contain more than one sub-element", ele);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
subElement = (Element) node;
|
subElement = currentElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1158,8 +1158,8 @@ public class BeanDefinitionParserDelegate {
|
||||||
|
|
||||||
for (int i = 0; i < elementNodes.getLength(); i++) {
|
for (int i = 0; i < elementNodes.getLength(); i++) {
|
||||||
Node node = elementNodes.item(i);
|
Node node = elementNodes.item(i);
|
||||||
if (node instanceof Element && !nodeNameEquals(node, DESCRIPTION_ELEMENT)) {
|
if (node instanceof Element currentElement && !nodeNameEquals(node, DESCRIPTION_ELEMENT)) {
|
||||||
target.add(parsePropertySubElement((Element) node, bd, defaultElementType));
|
target.add(parsePropertySubElement(currentElement, bd, defaultElementType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1309,13 +1309,13 @@ public class BeanDefinitionParserDelegate {
|
||||||
Element subElement = null;
|
Element subElement = null;
|
||||||
for (int i = 0; i < nl.getLength(); i++) {
|
for (int i = 0; i < nl.getLength(); i++) {
|
||||||
Node node = nl.item(i);
|
Node node = nl.item(i);
|
||||||
if (node instanceof Element) {
|
if (node instanceof Element currentElement) {
|
||||||
// Child element is what we're looking for.
|
// Child element is what we're looking for.
|
||||||
if (subElement != null) {
|
if (subElement != null) {
|
||||||
error("<key> element must not contain more than one value sub-element", keyEle);
|
error("<key> element must not contain more than one value sub-element", keyEle);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
subElement = (Element) node;
|
subElement = currentElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -120,8 +120,8 @@ public class DefaultNamespaceHandlerResolver implements NamespaceHandlerResolver
|
||||||
if (handlerOrClassName == null) {
|
if (handlerOrClassName == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else if (handlerOrClassName instanceof NamespaceHandler) {
|
else if (handlerOrClassName instanceof NamespaceHandler namespaceHandler) {
|
||||||
return (NamespaceHandler) handlerOrClassName;
|
return namespaceHandler;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String className = (String) handlerOrClassName;
|
String className = (String) handlerOrClassName;
|
||||||
|
|
|
||||||
|
|
@ -52,8 +52,8 @@ public class XmlBeanDefinitionStoreException extends BeanDefinitionStoreExceptio
|
||||||
*/
|
*/
|
||||||
public int getLineNumber() {
|
public int getLineNumber() {
|
||||||
Throwable cause = getCause();
|
Throwable cause = getCause();
|
||||||
if (cause instanceof SAXParseException) {
|
if (cause instanceof SAXParseException parseEx) {
|
||||||
return ((SAXParseException) cause).getLineNumber();
|
return parseEx.getLineNumber();
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -121,8 +121,8 @@ public class CustomNumberEditor extends PropertyEditorSupport {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setValue(@Nullable Object value) {
|
public void setValue(@Nullable Object value) {
|
||||||
if (value instanceof Number) {
|
if (value instanceof Number num) {
|
||||||
super.setValue(NumberUtils.convertNumberToTargetClass((Number) value, this.numberClass));
|
super.setValue(NumberUtils.convertNumberToTargetClass(num, this.numberClass));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
super.setValue(value);
|
super.setValue(value);
|
||||||
|
|
|
||||||
|
|
@ -68,9 +68,9 @@ public class PropertiesEditor extends PropertyEditorSupport {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void setValue(Object value) {
|
public void setValue(Object value) {
|
||||||
if (!(value instanceof Properties) && value instanceof Map) {
|
if (!(value instanceof Properties) && value instanceof Map<?, ?> map) {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.putAll((Map<?, ?>) value);
|
props.putAll(map);
|
||||||
super.setValue(props);
|
super.setValue(props);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -98,11 +98,11 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker {
|
||||||
*/
|
*/
|
||||||
public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) {
|
public void registerCustomEditor(Class<?> requiredType, PropertyEditor propertyEditor) {
|
||||||
TypeConverter converter = getTypeConverter();
|
TypeConverter converter = getTypeConverter();
|
||||||
if (!(converter instanceof PropertyEditorRegistry)) {
|
if (!(converter instanceof PropertyEditorRegistry registry)) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"TypeConverter does not implement PropertyEditorRegistry interface: " + converter);
|
"TypeConverter does not implement PropertyEditorRegistry interface: " + converter);
|
||||||
}
|
}
|
||||||
((PropertyEditorRegistry) converter).registerCustomEditor(requiredType, propertyEditor);
|
registry.registerCustomEditor(requiredType, propertyEditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,9 @@ public class PropertyComparator<T> implements Comparator<T> {
|
||||||
public int compare(T o1, T o2) {
|
public int compare(T o1, T o2) {
|
||||||
Object v1 = getPropertyValue(o1);
|
Object v1 = getPropertyValue(o1);
|
||||||
Object v2 = getPropertyValue(o2);
|
Object v2 = getPropertyValue(o2);
|
||||||
if (this.sortDefinition.isIgnoreCase() && (v1 instanceof String) && (v2 instanceof String)) {
|
if (this.sortDefinition.isIgnoreCase() && (v1 instanceof String text1) && (v2 instanceof String text2)) {
|
||||||
v1 = ((String) v1).toLowerCase();
|
v1 = text1.toLowerCase();
|
||||||
v2 = ((String) v2).toLowerCase();
|
v2 = text2.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 the original author or authors.
|
* Copyright 2002-2023 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -116,9 +116,9 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
|
||||||
doRegisterEditor(registry, Class.class, new ClassEditor(classLoader));
|
doRegisterEditor(registry, Class.class, new ClassEditor(classLoader));
|
||||||
doRegisterEditor(registry, Class[].class, new ClassArrayEditor(classLoader));
|
doRegisterEditor(registry, Class[].class, new ClassArrayEditor(classLoader));
|
||||||
|
|
||||||
if (this.resourceLoader instanceof ResourcePatternResolver) {
|
if (this.resourceLoader instanceof ResourcePatternResolver resourcePatternResolver) {
|
||||||
doRegisterEditor(registry, Resource[].class,
|
doRegisterEditor(registry, Resource[].class,
|
||||||
new ResourceArrayPropertyEditor((ResourcePatternResolver) this.resourceLoader, this.propertyResolver));
|
new ResourceArrayPropertyEditor(resourcePatternResolver, this.propertyResolver));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,8 +127,8 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
|
||||||
* otherwise register as a custom editor.
|
* otherwise register as a custom editor.
|
||||||
*/
|
*/
|
||||||
private void doRegisterEditor(PropertyEditorRegistry registry, Class<?> requiredType, PropertyEditor editor) {
|
private void doRegisterEditor(PropertyEditorRegistry registry, Class<?> requiredType, PropertyEditor editor) {
|
||||||
if (registry instanceof PropertyEditorRegistrySupport) {
|
if (registry instanceof PropertyEditorRegistrySupport registrySupport) {
|
||||||
((PropertyEditorRegistrySupport) registry).overrideDefaultEditor(requiredType, editor);
|
registrySupport.overrideDefaultEditor(requiredType, editor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
registry.registerCustomEditor(requiredType, editor);
|
registry.registerCustomEditor(requiredType, editor);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue