Skip to content

Commit d18bdf6

Browse files
committed
Polishing
(cherry picked from commit d2ef6dc)
1 parent 5da8a16 commit d18bdf6

6 files changed

Lines changed: 78 additions & 84 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
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
@@ -60,7 +60,7 @@ protected boolean isPrototypeBased() {
6060

6161
@Override
6262
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(
63-
Class beanClass, String beanName) {
63+
Class<?> beanClass, String beanName) {
6464

6565
if (getBeanFactory() instanceof ConfigurableListableBeanFactory) {
6666
BeanDefinition definition =

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

Lines changed: 5 additions & 8 deletions
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;
@@ -97,7 +95,7 @@ public String getTargetBeanName() {
9795
* <p>Default is to detect the type automatically, through a {@code getType}
9896
* call on the BeanFactory (or even a full {@code getBean} call as fallback).
9997
*/
100-
public void setTargetClass(Class targetClass) {
98+
public void setTargetClass(Class<?> targetClass) {
10199
this.targetClass = targetClass;
102100
}
103101

@@ -107,7 +105,7 @@ public void setTargetClass(Class targetClass) {
107105
*/
108106
public void setBeanFactory(BeanFactory beanFactory) {
109107
if (this.targetBeanName == null) {
110-
throw new IllegalStateException("Property'targetBeanName' is required");
108+
throw new IllegalStateException("Property 'targetBeanName' is required");
111109
}
112110
this.beanFactory = beanFactory;
113111
}
@@ -181,8 +179,7 @@ public int hashCode() {
181179

182180
@Override
183181
public String toString() {
184-
StringBuilder sb = new StringBuilder();
185-
sb.append(ClassUtils.getShortName(getClass()));
182+
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
186183
sb.append(" for target bean '").append(this.targetBeanName).append("'");
187184
if (this.targetClass != null) {
188185
sb.append(" of type [").append(this.targetClass.getName()).append("]");

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

Lines changed: 30 additions & 32 deletions
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>() {
@@ -428,24 +428,24 @@ public void setPropertyEditorClass(Class<?> propertyEditorClass) {
428428
* See java.beans.IndexedPropertyDescriptor#equals(java.lang.Object)
429429
*/
430430
@Override
431-
public boolean equals(Object obj) {
432-
if (this == obj) {
431+
public boolean equals(Object other) {
432+
if (this == other) {
433433
return true;
434434
}
435-
if (obj != null && obj instanceof IndexedPropertyDescriptor) {
436-
IndexedPropertyDescriptor other = (IndexedPropertyDescriptor) obj;
437-
if (!compareMethods(getIndexedReadMethod(), other.getIndexedReadMethod())) {
438-
return false;
439-
}
440-
if (!compareMethods(getIndexedWriteMethod(), other.getIndexedWriteMethod())) {
441-
return false;
442-
}
443-
if (getIndexedPropertyType() != other.getIndexedPropertyType()) {
444-
return false;
445-
}
446-
return PropertyDescriptorUtils.equals(this, obj);
435+
if (!(other instanceof IndexedPropertyDescriptor)) {
436+
return false;
437+
}
438+
IndexedPropertyDescriptor otherPd = (IndexedPropertyDescriptor) other;
439+
if (!compareMethods(getIndexedReadMethod(), otherPd.getIndexedReadMethod())) {
440+
return false;
441+
}
442+
if (!compareMethods(getIndexedWriteMethod(), otherPd.getIndexedWriteMethod())) {
443+
return false;
447444
}
448-
return false;
445+
if (getIndexedPropertyType() != otherPd.getIndexedPropertyType()) {
446+
return false;
447+
}
448+
return PropertyDescriptorUtils.equals(this, other);
449449
}
450450

451451
@Override
@@ -586,25 +586,23 @@ else if (params[1].isAssignableFrom(indexedPropertyType)) {
586586
* editor and flags are equivalent.
587587
* @see PropertyDescriptor#equals(Object)
588588
*/
589-
public static boolean equals(PropertyDescriptor pd1, Object obj) {
590-
if (pd1 == obj) {
589+
public static boolean equals(PropertyDescriptor pd, Object other) {
590+
if (pd == other) {
591591
return true;
592592
}
593-
if (obj != null && obj instanceof PropertyDescriptor) {
594-
PropertyDescriptor pd2 = (PropertyDescriptor) obj;
595-
if (!compareMethods(pd1.getReadMethod(), pd2.getReadMethod())) {
596-
return false;
597-
}
598-
if (!compareMethods(pd1.getWriteMethod(), pd2.getWriteMethod())) {
599-
return false;
600-
}
601-
if (pd1.getPropertyType() == pd2.getPropertyType() &&
602-
pd1.getPropertyEditorClass() == pd2.getPropertyEditorClass() &&
603-
pd1.isBound() == pd2.isBound() && pd1.isConstrained() == pd2.isConstrained()) {
604-
return true;
605-
}
593+
if (!(other instanceof PropertyDescriptor)) {
594+
return false;
595+
}
596+
PropertyDescriptor otherPd = (PropertyDescriptor) other;
597+
if (!compareMethods(pd.getReadMethod(), otherPd.getReadMethod())) {
598+
return false;
599+
}
600+
if (!compareMethods(pd.getWriteMethod(), otherPd.getWriteMethod())) {
601+
return false;
606602
}
607-
return false;
603+
return (pd.getPropertyType() == otherPd.getPropertyType() &&
604+
pd.getPropertyEditorClass() == otherPd.getPropertyEditorClass() &&
605+
pd.isBound() == otherPd.isBound() && pd.isConstrained() == otherPd.isConstrained());
608606
}
609607

610608
/*

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public class ImportBeanDefinitionRegistrarTests {
4646

4747
@Test
4848
public void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() {
49-
5049
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
5150
context.getBean(MessageSource.class);
5251

@@ -55,19 +54,20 @@ public void shouldInvokeAwareMethodsInImportBeanDefinitionRegistrar() {
5554
assertThat(SampleRegistrar.resourceLoader, is(notNullValue()));
5655
}
5756

57+
5858
@Sample
5959
@Configuration
6060
static class Config {
61-
6261
}
6362

63+
6464
@Target(ElementType.TYPE)
6565
@Retention(RetentionPolicy.RUNTIME)
6666
@Import(SampleRegistrar.class)
6767
public static @interface Sample {
68-
6968
}
7069

70+
7171
static class SampleRegistrar implements ImportBeanDefinitionRegistrar, BeanClassLoaderAware, ResourceLoaderAware,
7272
BeanFactoryAware {
7373

@@ -94,4 +94,5 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
9494
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
9595
}
9696
}
97+
9798
}

src/test/java/org/springframework/core/env/EnvironmentIntegrationTests.java

Lines changed: 34 additions & 37 deletions
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.
@@ -67,7 +67,6 @@
6767
import static org.springframework.context.ConfigurableApplicationContext.*;
6868
import static org.springframework.core.env.EnvironmentIntegrationTests.Constants.*;
6969

70-
7170
/**
7271
* Integration tests for container support of {@link Environment}
7372
* interface.
@@ -84,29 +83,15 @@
8483
*
8584
* @author Chris Beams
8685
*/
86+
@SuppressWarnings("resource")
8787
public class EnvironmentIntegrationTests {
8888

8989
private ConfigurableEnvironment prodEnv;
90-
private ConfigurableEnvironment devEnv;
91-
private ConfigurableEnvironment prodWebEnv;
92-
93-
/**
94-
* Constants used both locally and in scan* sub-packages
95-
*/
96-
public static class Constants {
97-
public static final String XML_PATH = "org/springframework/core/env/EnvironmentIntegrationTests-context.xml";
9890

99-
public static final String ENVIRONMENT_AWARE_BEAN_NAME = "envAwareBean";
91+
private ConfigurableEnvironment devEnv;
10092

101-
public static final String PROD_BEAN_NAME = "prodBean";
102-
public static final String DEV_BEAN_NAME = "devBean";
103-
public static final String DERIVED_DEV_BEAN_NAME = "derivedDevBean";
104-
public static final String TRANSITIVE_BEAN_NAME = "transitiveBean";
93+
private ConfigurableEnvironment prodWebEnv;
10594

106-
public static final String PROD_ENV_NAME = "prod";
107-
public static final String DEV_ENV_NAME = "dev";
108-
public static final String DERIVED_DEV_ENV_NAME = "derivedDev";
109-
}
11095

11196
@Before
11297
public void setUp() {
@@ -122,9 +107,7 @@ public void setUp() {
122107

123108
@Test
124109
public void genericApplicationContext_standardEnv() {
125-
ConfigurableApplicationContext ctx =
126-
new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
127-
110+
ConfigurableApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
128111
ctx.refresh();
129112

130113
assertHasStandardEnvironment(ctx);
@@ -134,8 +117,7 @@ public void genericApplicationContext_standardEnv() {
134117

135118
@Test
136119
public void genericApplicationContext_customEnv() {
137-
GenericApplicationContext ctx =
138-
new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
120+
GenericApplicationContext ctx = new GenericApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
139121
ctx.setEnvironment(prodEnv);
140122
ctx.refresh();
141123

@@ -191,11 +173,8 @@ public void classPathBeanDefinitionScanner_inheritsEnvironmentFromEnvironmentCap
191173
@Test
192174
public void genericXmlApplicationContext() {
193175
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
194-
195176
assertHasStandardEnvironment(ctx);
196-
197177
ctx.setEnvironment(prodEnv);
198-
199178
ctx.load(XML_PATH);
200179
ctx.refresh();
201180

@@ -208,8 +187,7 @@ public void genericXmlApplicationContext() {
208187

209188
@Test
210189
public void classPathXmlApplicationContext() {
211-
ConfigurableApplicationContext ctx =
212-
new ClassPathXmlApplicationContext(new String[] { XML_PATH });
190+
ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(XML_PATH);
213191
ctx.setEnvironment(prodEnv);
214192
ctx.refresh();
215193

@@ -228,7 +206,7 @@ public void fileSystemXmlApplicationContext() throws IOException {
228206

229207
// strange - FSXAC strips leading '/' unless prefixed with 'file:'
230208
ConfigurableApplicationContext ctx =
231-
new FileSystemXmlApplicationContext(new String[] { "file:"+tmpFile.getPath() }, false);
209+
new FileSystemXmlApplicationContext(new String[] {"file:" + tmpFile.getPath()}, false);
232210
ctx.setEnvironment(prodEnv);
233211
ctx.refresh();
234212
assertEnvironmentBeanRegistered(ctx);
@@ -336,11 +314,8 @@ public void mostSpecificDerivedClassDrivesEnvironment_withDevEnvAndDerivedDevCon
336314

337315
@Test
338316
public void webApplicationContext() {
339-
GenericWebApplicationContext ctx =
340-
new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
341-
317+
GenericWebApplicationContext ctx = new GenericWebApplicationContext(newBeanFactoryWithEnvironmentAwareBean());
342318
assertHasStandardServletEnvironment(ctx);
343-
344319
ctx.setEnvironment(prodWebEnv);
345320
ctx.refresh();
346321

@@ -588,7 +563,8 @@ public void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
588563
try {
589564
ctx.refresh();
590565
fail("expected missing property exception");
591-
} catch (MissingRequiredPropertiesException ex) {
566+
}
567+
catch (MissingRequiredPropertiesException ex) {
592568
}
593569
}
594570

@@ -598,7 +574,6 @@ public void abstractApplicationContextValidatesRequiredPropertiesOnRefresh() {
598574
ctx.setEnvironment(new MockEnvironment().withProperty("foo", "fooValue"));
599575
ctx.refresh(); // should succeed
600576
}
601-
602577
}
603578

604579

@@ -652,6 +627,7 @@ private void assertEnvironmentAwareInvoked(ConfigurableApplicationContext ctx, E
652627
assertThat(ctx.getBean(EnvironmentAwareBean.class).environment, is(expectedEnv));
653628
}
654629

630+
655631
private static class EnvironmentAwareBean implements EnvironmentAware {
656632

657633
public Environment environment;
@@ -660,9 +636,9 @@ private static class EnvironmentAwareBean implements EnvironmentAware {
660636
public void setEnvironment(Environment environment) {
661637
this.environment = environment;
662638
}
663-
664639
}
665640

641+
666642
/**
667643
* Mirrors the structure of beans and environment-specific config files
668644
* in EnvironmentIntegrationTests-context.xml
@@ -711,4 +687,25 @@ public Object derivedDevBean() {
711687
return new Object();
712688
}
713689
}
690+
691+
692+
/**
693+
* Constants used both locally and in scan* sub-packages
694+
*/
695+
public static class Constants {
696+
697+
public static final String XML_PATH = "org/springframework/core/env/EnvironmentIntegrationTests-context.xml";
698+
699+
public static final String ENVIRONMENT_AWARE_BEAN_NAME = "envAwareBean";
700+
701+
public static final String PROD_BEAN_NAME = "prodBean";
702+
public static final String DEV_BEAN_NAME = "devBean";
703+
public static final String DERIVED_DEV_BEAN_NAME = "derivedDevBean";
704+
public static final String TRANSITIVE_BEAN_NAME = "transitiveBean";
705+
706+
public static final String PROD_ENV_NAME = "prod";
707+
public static final String DEV_ENV_NAME = "dev";
708+
public static final String DERIVED_DEV_ENV_NAME = "derivedDev";
709+
}
710+
714711
}

0 commit comments

Comments
 (0)