Polishing

This commit is contained in:
Juergen Hoeller
2018-06-28 14:51:31 +02:00
parent b68e692854
commit 40efcc933c
107 changed files with 510 additions and 624 deletions

View File

@@ -348,14 +348,8 @@ public class MutablePropertyValues implements PropertyValues, Serializable {
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof MutablePropertyValues)) {
return false;
}
MutablePropertyValues that = (MutablePropertyValues) other;
return this.propertyValueList.equals(that.propertyValueList);
return (this == other || (other instanceof MutablePropertyValues &&
this.propertyValueList.equals(((MutablePropertyValues) other).propertyValueList)));
}
@Override

View File

@@ -32,7 +32,6 @@ public class CannotLoadBeanClassException extends FatalBeanException {
@Nullable
private final String resourceDescription;
@Nullable
private final String beanName;
@Nullable
@@ -47,8 +46,8 @@ public class CannotLoadBeanClassException extends FatalBeanException {
* @param beanClassName the name of the bean class
* @param cause the root cause
*/
public CannotLoadBeanClassException(
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, ClassNotFoundException cause) {
public CannotLoadBeanClassException(@Nullable String resourceDescription, String beanName,
@Nullable String beanClassName, ClassNotFoundException cause) {
super("Cannot find class [" + beanClassName + "] for bean with name '" + beanName + "'" +
(resourceDescription != null ? " defined in " + resourceDescription : ""), cause);
@@ -65,8 +64,8 @@ public class CannotLoadBeanClassException extends FatalBeanException {
* @param beanClassName the name of the bean class
* @param cause the root cause
*/
public CannotLoadBeanClassException(
@Nullable String resourceDescription, String beanName, @Nullable String beanClassName, LinkageError cause) {
public CannotLoadBeanClassException(@Nullable String resourceDescription, String beanName,
@Nullable String beanClassName, LinkageError cause) {
super("Error loading class [" + beanClassName + "] for bean with name '" + beanName + "'" +
(resourceDescription != null ? " defined in " + resourceDescription : "") +
@@ -89,7 +88,6 @@ public class CannotLoadBeanClassException extends FatalBeanException {
/**
* Return the name of the bean requested.
*/
@Nullable
public String getBeanName() {
return this.beanName;
}

View File

@@ -203,7 +203,7 @@ public class FieldRetrievingFactoryBean
}
// Try to get the exact method first.
Class<?> targetClass = (this.targetObject != null) ? this.targetObject.getClass() : this.targetClass;
Class<?> targetClass = (this.targetObject != null ? this.targetObject.getClass() : this.targetClass);
this.fieldObject = targetClass.getField(this.targetField);
}

View File

@@ -374,7 +374,6 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
if (args[0] == null) {
throw new IllegalArgumentException("Argument to ref() is not a valid bean or was not found");
}
if (args[0] instanceof RuntimeBeanReference) {
refName = ((RuntimeBeanReference) args[0]).getBeanName();
}
@@ -490,11 +489,11 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
Map.Entry factoryBeanEntry = (Map.Entry) ((Map) args[0]).entrySet().iterator().next();
// If we have a closure body, that will be the last argument.
// In between are the constructor args
int constructorArgsTest = hasClosureArgument?2:1;
int constructorArgsTest = (hasClosureArgument ? 2 : 1);
// If we have more than this number of args, we have constructor args
if (args.length > constructorArgsTest){
// factory-method requires args
int endOfConstructArgs = (hasClosureArgument? args.length - 1 : args.length);
int endOfConstructArgs = (hasClosureArgument ? args.length - 1 : args.length);
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, null,
resolveConstructorArguments(args, 1, endOfConstructArgs));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 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.
@@ -82,7 +82,7 @@ public final class ParseState {
*/
@Nullable
public Entry peek() {
return this.state.isEmpty() ? null : this.state.peek();
return this.state.peek();
}
/**

View File

@@ -1114,39 +1114,38 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
public abstract AbstractBeanDefinition cloneBeanDefinition();
@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(obj instanceof AbstractBeanDefinition)) {
if (!(other instanceof AbstractBeanDefinition)) {
return false;
}
AbstractBeanDefinition other = (AbstractBeanDefinition) obj;
boolean rtn = true;
rtn = rtn &= ObjectUtils.nullSafeEquals(getBeanClassName(), other.getBeanClassName());
rtn = rtn &= ObjectUtils.nullSafeEquals(this.scope, other.scope);
rtn = rtn &= this.abstractFlag == other.abstractFlag;
rtn = rtn &= this.lazyInit == other.lazyInit;
rtn = rtn &= this.autowireMode == other.autowireMode;
rtn = rtn &= this.dependencyCheck == other.dependencyCheck;
rtn = rtn &= Arrays.equals(this.dependsOn, other.dependsOn);
rtn = rtn &= this.autowireCandidate == other.autowireCandidate;
rtn = rtn &= ObjectUtils.nullSafeEquals(this.qualifiers, other.qualifiers);
rtn = rtn &= this.primary == other.primary;
rtn = rtn &= this.nonPublicAccessAllowed == other.nonPublicAccessAllowed;
rtn = rtn &= this.lenientConstructorResolution == other.lenientConstructorResolution;
rtn = rtn &= ObjectUtils.nullSafeEquals(this.constructorArgumentValues, other.constructorArgumentValues);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.propertyValues, other.propertyValues);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.methodOverrides, other.methodOverrides);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.factoryBeanName, other.factoryBeanName);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.factoryMethodName, other.factoryMethodName);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.initMethodName, other.initMethodName);
rtn = rtn &= this.enforceInitMethod == other.enforceInitMethod;
rtn = rtn &= ObjectUtils.nullSafeEquals(this.destroyMethodName, other.destroyMethodName);
rtn = rtn &= this.enforceDestroyMethod == other.enforceDestroyMethod;
rtn = rtn &= this.synthetic == other.synthetic;
rtn = rtn &= this.role == other.role;
return rtn && super.equals(obj);
AbstractBeanDefinition that = (AbstractBeanDefinition) other;
boolean rtn = ObjectUtils.nullSafeEquals(getBeanClassName(), that.getBeanClassName());
rtn = rtn &= ObjectUtils.nullSafeEquals(this.scope, that.scope);
rtn = rtn &= this.abstractFlag == that.abstractFlag;
rtn = rtn &= this.lazyInit == that.lazyInit;
rtn = rtn &= this.autowireMode == that.autowireMode;
rtn = rtn &= this.dependencyCheck == that.dependencyCheck;
rtn = rtn &= Arrays.equals(this.dependsOn, that.dependsOn);
rtn = rtn &= this.autowireCandidate == that.autowireCandidate;
rtn = rtn &= ObjectUtils.nullSafeEquals(this.qualifiers, that.qualifiers);
rtn = rtn &= this.primary == that.primary;
rtn = rtn &= this.nonPublicAccessAllowed == that.nonPublicAccessAllowed;
rtn = rtn &= this.lenientConstructorResolution == that.lenientConstructorResolution;
rtn = rtn &= ObjectUtils.nullSafeEquals(this.constructorArgumentValues, that.constructorArgumentValues);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.propertyValues, that.propertyValues);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.methodOverrides, that.methodOverrides);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.factoryBeanName, that.factoryBeanName);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.factoryMethodName, that.factoryMethodName);
rtn = rtn &= ObjectUtils.nullSafeEquals(this.initMethodName, that.initMethodName);
rtn = rtn &= this.enforceInitMethod == that.enforceInitMethod;
rtn = rtn &= ObjectUtils.nullSafeEquals(this.destroyMethodName, that.destroyMethodName);
rtn = rtn &= this.enforceDestroyMethod == that.enforceDestroyMethod;
rtn = rtn &= this.synthetic == that.synthetic;
rtn = rtn &= this.role == that.role;
return rtn && super.equals(other);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
@@ -80,10 +80,9 @@ class BeanDefinitionResource extends AbstractResource {
* This implementation compares the underlying BeanDefinition.
*/
@Override
public boolean equals(Object obj) {
return (obj == this ||
(obj instanceof BeanDefinitionResource &&
((BeanDefinitionResource) obj).beanDefinition.equals(this.beanDefinition)));
public boolean equals(Object other) {
return (this == other || (other instanceof BeanDefinitionResource &&
((BeanDefinitionResource) other).beanDefinition.equals(this.beanDefinition)));
}
/**

View File

@@ -1521,8 +1521,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
isAutowireCandidate(beanName, mbd, descriptor, getAutowireCandidateResolver())) {
// Probably a proxy interfering with target type match -> throw meaningful exception.
Object beanInstance = getSingleton(beanName, false);
Class<?> beanType = (beanInstance != null && beanInstance.getClass() != NullBean.class) ?
beanInstance.getClass() : predictBeanType(beanName, mbd);
Class<?> beanType = (beanInstance != null && beanInstance.getClass() != NullBean.class ?
beanInstance.getClass() : predictBeanType(beanName, mbd));
if (beanType != null && !type.isAssignableFrom(beanType)) {
throw new BeanNotOfRequiredTypeException(beanName, type, beanType);
}

View File

@@ -900,9 +900,9 @@ public class BeanDefinitionParserDelegate {
*/
@Nullable
public Object parsePropertyValue(Element ele, BeanDefinition bd, @Nullable String propertyName) {
String elementName = (propertyName != null) ?
"<property> element for property '" + propertyName + "'" :
"<constructor-arg> element";
String elementName = (propertyName != null ?
"<property> element for property '" + propertyName + "'" :
"<constructor-arg> element");
// Should only have one child element: ref, value, list, etc.
NodeList nl = ele.getChildNodes();