Skip to content

Commit d2ef6dc

Browse files
committed
Polishing
1 parent bff2bf2 commit d2ef6dc

File tree

7 files changed

+140
-90
lines changed

7 files changed

+140
-90
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -25,7 +25,7 @@
2525
* TargetSourceCreator that enforces a LazyInitTargetSource for each bean
2626
* that is defined as "lazy-init". This will lead to a proxy created for
2727
* each of those beans, allowing to fetch a reference to such a bean
28-
* without actually initialized the target bean instance.
28+
* without actually initializing the target bean instance.
2929
*
3030
* <p>To be registered as custom TargetSourceCreator for an auto-proxy creator,
3131
* in combination with custom interceptors for specific beans or for the

spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -24,7 +24,6 @@
2424
import org.springframework.aop.TargetSource;
2525
import org.springframework.beans.factory.BeanFactory;
2626
import org.springframework.beans.factory.BeanFactoryAware;
27-
import org.springframework.util.ClassUtils;
2827
import org.springframework.util.ObjectUtils;
2928

3029
/**
@@ -48,8 +47,7 @@
4847
* @see ThreadLocalTargetSource
4948
* @see CommonsPoolTargetSource
5049
*/
51-
public abstract class AbstractBeanFactoryBasedTargetSource
52-
implements TargetSource, BeanFactoryAware, Serializable {
50+
public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSource, BeanFactoryAware, Serializable {
5351

5452
/** use serialVersionUID from Spring 1.2.7 for interoperability */
5553
private static final long serialVersionUID = -4721607536018568393L;
@@ -108,7 +106,7 @@ public void setTargetClass(Class<?> targetClass) {
108106
@Override
109107
public void setBeanFactory(BeanFactory beanFactory) {
110108
if (this.targetBeanName == null) {
111-
throw new IllegalStateException("Property'targetBeanName' is required");
109+
throw new IllegalStateException("Property 'targetBeanName' is required");
112110
}
113111
this.beanFactory = beanFactory;
114112
}
@@ -185,8 +183,7 @@ public int hashCode() {
185183

186184
@Override
187185
public String toString() {
188-
StringBuilder sb = new StringBuilder();
189-
sb.append(ClassUtils.getShortName(getClass()));
186+
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
190187
sb.append(" for target bean '").append(this.targetBeanName).append("'");
191188
if (this.targetClass != null) {
192189
sb.append(" of type [").append(this.targetClass.getName()).append("]");

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

+30-32
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescript
115115
matches.add(method);
116116
}
117117
}
118-
// sort non-void returning write methods to guard against the ill effects of
118+
// Sort non-void returning write methods to guard against the ill effects of
119119
// non-deterministic sorting of methods returned from Class#getDeclaredMethods
120120
// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
121121
Collections.sort(matches, new Comparator<Method>() {
@@ -437,24 +437,24 @@ public void setPropertyEditorClass(Class<?> propertyEditorClass) {
437437
* See java.beans.IndexedPropertyDescriptor#equals(java.lang.Object)
438438
*/
439439
@Override
440-
public boolean equals(Object obj) {
441-
if (this == obj) {
440+
public boolean equals(Object other) {
441+
if (this == other) {
442442
return true;
443443
}
444-
if (obj != null && obj instanceof IndexedPropertyDescriptor) {
445-
IndexedPropertyDescriptor other = (IndexedPropertyDescriptor) obj;
446-
if (!compareMethods(getIndexedReadMethod(), other.getIndexedReadMethod())) {
447-
return false;
448-
}
449-
if (!compareMethods(getIndexedWriteMethod(), other.getIndexedWriteMethod())) {
450-
return false;
451-
}
452-
if (getIndexedPropertyType() != other.getIndexedPropertyType()) {
453-
return false;
454-
}
455-
return PropertyDescriptorUtils.equals(this, obj);
444+
if (!(other instanceof IndexedPropertyDescriptor)) {
445+
return false;
446+
}
447+
IndexedPropertyDescriptor otherPd = (IndexedPropertyDescriptor) other;
448+
if (!compareMethods(getIndexedReadMethod(), otherPd.getIndexedReadMethod())) {
449+
return false;
450+
}
451+
if (!compareMethods(getIndexedWriteMethod(), otherPd.getIndexedWriteMethod())) {
452+
return false;
456453
}
457-
return false;
454+
if (getIndexedPropertyType() != otherPd.getIndexedPropertyType()) {
455+
return false;
456+
}
457+
return PropertyDescriptorUtils.equals(this, other);
458458
}
459459

460460
@Override
@@ -595,25 +595,23 @@ else if (params[1].isAssignableFrom(indexedPropertyType)) {
595595
* editor and flags are equivalent.
596596
* @see PropertyDescriptor#equals(Object)
597597
*/
598-
public static boolean equals(PropertyDescriptor pd1, Object obj) {
599-
if (pd1 == obj) {
598+
public static boolean equals(PropertyDescriptor pd, Object other) {
599+
if (pd == other) {
600600
return true;
601601
}
602-
if (obj != null && obj instanceof PropertyDescriptor) {
603-
PropertyDescriptor pd2 = (PropertyDescriptor) obj;
604-
if (!compareMethods(pd1.getReadMethod(), pd2.getReadMethod())) {
605-
return false;
606-
}
607-
if (!compareMethods(pd1.getWriteMethod(), pd2.getWriteMethod())) {
608-
return false;
609-
}
610-
if (pd1.getPropertyType() == pd2.getPropertyType() &&
611-
pd1.getPropertyEditorClass() == pd2.getPropertyEditorClass() &&
612-
pd1.isBound() == pd2.isBound() && pd1.isConstrained() == pd2.isConstrained()) {
613-
return true;
614-
}
602+
if (!(other instanceof PropertyDescriptor)) {
603+
return false;
604+
}
605+
PropertyDescriptor otherPd = (PropertyDescriptor) other;
606+
if (!compareMethods(pd.getReadMethod(), otherPd.getReadMethod())) {
607+
return false;
608+
}
609+
if (!compareMethods(pd.getWriteMethod(), otherPd.getWriteMethod())) {
610+
return false;
615611
}
616-
return false;
612+
return (pd.getPropertyType() == otherPd.getPropertyType() &&
613+
pd.getPropertyEditorClass() == otherPd.getPropertyEditorClass() &&
614+
pd.isBound() == otherPd.isBound() && pd.isConstrained() == otherPd.isConstrained());
617615
}
618616

619617
/*

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostConstructAndAutowiringTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 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.
@@ -101,6 +101,7 @@ public TestBean beanMethod() {
101101

102102
@Configuration
103103
static class Config2 {
104+
104105
TestBean testBean;
105106

106107
@Autowired

spring-context/src/test/java/org/springframework/context/annotation/ImportBeanDefinitionRegistrarTests.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.lang.annotation.Target;
2323

2424
import org.junit.Test;
25+
2526
import org.springframework.beans.BeansException;
2627
import org.springframework.beans.factory.BeanClassLoaderAware;
2728
import org.springframework.beans.factory.BeanFactory;
@@ -47,7 +48,6 @@ public class ImportBeanDefinitionRegistrarTests {
4748

4849
@Test
4950
public void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() {
50-
5151
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
5252
context.getBean(MessageSource.class);
5353

@@ -57,19 +57,20 @@ public void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() {
5757
assertThat(SampleRegistrar.environment, is((Environment) context.getEnvironment()));
5858
}
5959

60+
6061
@Sample
6162
@Configuration
6263
static class Config {
63-
6464
}
6565

66+
6667
@Target(ElementType.TYPE)
6768
@Retention(RetentionPolicy.RUNTIME)
6869
@Import(SampleRegistrar.class)
6970
public static @interface Sample {
70-
7171
}
7272

73+
7374
static class SampleRegistrar implements ImportBeanDefinitionRegistrar, BeanClassLoaderAware, ResourceLoaderAware,
7475
BeanFactoryAware, EnvironmentAware {
7576

@@ -102,4 +103,5 @@ public void setEnvironment(Environment environment) {
102103
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
103104
}
104105
}
106+
105107
}

0 commit comments

Comments
 (0)