Skip to content

Commit 5639eb6

Browse files
committed
Polishing
1 parent 1dc79f7 commit 5639eb6

File tree

7 files changed

+58
-59
lines changed

7 files changed

+58
-59
lines changed

spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public abstract class ScopedProxyUtils {
3838

3939

4040
/**
41-
* Generates a scoped proxy for the supplied target bean, registering the target
41+
* Generate a scoped proxy for the supplied target bean, registering the target
4242
* bean with an internal name and setting 'targetBeanName' on the scoped proxy.
4343
* @param definition the original bean definition
4444
* @param registry the bean definition registry
@@ -63,7 +63,7 @@ public static BeanDefinitionHolder createScopedProxy(BeanDefinitionHolder defini
6363

6464
if (proxyTargetClass) {
6565
targetDefinition.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLASS_ATTRIBUTE, Boolean.TRUE);
66-
// ScopedFactoryBean's "proxyTargetClass" default is TRUE, so we don't need to set it explicitly here.
66+
// ScopedProxyFactoryBean's "proxyTargetClass" default is TRUE, so we don't need to set it explicitly here.
6767
}
6868
else {
6969
proxyDefinition.getPropertyValues().add("proxyTargetClass", Boolean.FALSE);

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@
5050
*/
5151
class ConfigurationClassEnhancer {
5252

53-
private static final Log logger = LogFactory.getLog(ConfigurationClassEnhancer.class);
54-
55-
private static final CallbackFilter CALLBACK_FILTER = new ConfigurationClassCallbackFilter();
56-
5753
private static final Callback DISPOSABLE_BEAN_METHOD_INTERCEPTOR = new DisposableBeanMethodInterceptor();
5854

5955
private static final Class<?>[] CALLBACK_TYPES =
6056
{BeanMethodInterceptor.class, DisposableBeanMethodInterceptor.class, NoOp.class};
6157

58+
private static final CallbackFilter CALLBACK_FILTER = new ConfigurationClassCallbackFilter();
59+
60+
private static final Log logger = LogFactory.getLog(ConfigurationClassEnhancer.class);
61+
6262
private final Callback[] callbackInstances;
6363

6464

@@ -103,7 +103,7 @@ public Class<?> enhance(Class<?> configClass) {
103103
private Enhancer newEnhancer(Class<?> superclass) {
104104
Enhancer enhancer = new Enhancer();
105105
enhancer.setSuperclass(superclass);
106-
enhancer.setInterfaces(new Class[] {EnhancedConfiguration.class});
106+
enhancer.setInterfaces(new Class<?>[] {EnhancedConfiguration.class});
107107
enhancer.setUseFactory(false);
108108
enhancer.setCallbackFilter(CALLBACK_FILTER);
109109
enhancer.setCallbackTypes(CALLBACK_TYPES);
@@ -116,13 +116,13 @@ private Enhancer newEnhancer(Class<?> superclass) {
116116
*/
117117
private Class<?> createClass(Enhancer enhancer) {
118118
Class<?> subclass = enhancer.createClass();
119-
// registering callbacks statically (as opposed to threadlocal) is critical for usage in an OSGi env (SPR-5932)
119+
// Registering callbacks statically (as opposed to thread-local)
120+
// is critical for usage in an OSGi environment (SPR-5932)...
120121
Enhancer.registerStaticCallbacks(subclass, this.callbackInstances);
121122
return subclass;
122123
}
123124

124125

125-
126126
/**
127127
* Marker interface to be implemented by all @Configuration CGLIB subclasses.
128128
* Facilitates idempotent behavior for {@link ConfigurationClassEnhancer#enhance(Class)}
@@ -192,8 +192,8 @@ private static class DisposableBeanMethodInterceptor implements MethodIntercepto
192192

193193
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
194194
Enhancer.registerStaticCallbacks(obj.getClass(), null);
195-
// does the actual (non-CGLIB) superclass actually implement DisposableBean?
196-
// if so, call its dispose() method. If not, just exit.
195+
// Does the actual (non-CGLIB) superclass actually implement DisposableBean?
196+
// If so, call its dispose() method. If not, just exit.
197197
if (DisposableBean.class.isAssignableFrom(obj.getClass().getSuperclass())) {
198198
return proxy.invokeSuper(obj, args);
199199
}
@@ -242,7 +242,7 @@ public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object
242242

243243
String beanName = BeanAnnotationHelper.determineBeanNameFor(beanMethod);
244244

245-
// determine whether this bean is a scoped-proxy
245+
// Determine whether this bean is a scoped-proxy
246246
Scope scope = AnnotationUtils.findAnnotation(beanMethod, Scope.class);
247247
if (scope != null && scope.proxyMode() != ScopedProxyMode.NO) {
248248
String scopedBeanName = ScopedProxyCreator.getTargetBeanName(beanName);
@@ -251,27 +251,27 @@ public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object
251251
}
252252
}
253253

254-
// to handle the case of an inter-bean method reference, we must explicitly check the
255-
// container for already cached instances
254+
// To handle the case of an inter-bean method reference, we must explicitly check the
255+
// container for already cached instances.
256256

257-
// first, check to see if the requested bean is a FactoryBean. If so, create a subclass
257+
// First, check to see if the requested bean is a FactoryBean. If so, create a subclass
258258
// proxy that intercepts calls to getObject() and returns any cached bean instance.
259-
// this ensures that the semantics of calling a FactoryBean from within @Bean methods
259+
// This ensures that the semantics of calling a FactoryBean from within @Bean methods
260260
// is the same as that of referring to a FactoryBean within XML. See SPR-6602.
261261
if (factoryContainsBean(BeanFactory.FACTORY_BEAN_PREFIX + beanName) && factoryContainsBean(beanName)) {
262262
Object factoryBean = this.beanFactory.getBean(BeanFactory.FACTORY_BEAN_PREFIX + beanName);
263263
if (factoryBean instanceof ScopedProxyFactoryBean) {
264-
// pass through - scoped proxy factory beans are a special case and should not
264+
// Pass through - scoped proxy factory beans are a special case and should not
265265
// be further proxied
266266
}
267267
else {
268-
// it is a candidate FactoryBean - go ahead with enhancement
268+
// It is a candidate FactoryBean - go ahead with enhancement
269269
return enhanceFactoryBean(factoryBean.getClass(), beanName);
270270
}
271271
}
272272

273273
if (isCurrentlyInvokedFactoryMethod(beanMethod) && !this.beanFactory.containsSingleton(beanName)) {
274-
// the factory is calling the bean method in order to instantiate and register the bean
274+
// The factory is calling the bean method in order to instantiate and register the bean
275275
// (i.e. via a getBean() call) -> invoke the super implementation of the method to actually
276276
// create the bean instance.
277277
if (BeanFactoryPostProcessor.class.isAssignableFrom(beanMethod.getReturnType())) {
@@ -286,7 +286,7 @@ public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object
286286
return cglibMethodProxy.invokeSuper(enhancedConfigInstance, beanMethodArgs);
287287
}
288288
else {
289-
// the user (i.e. not the factory) is requesting this bean through a
289+
// The user (i.e. not the factory) is requesting this bean through a
290290
// call to the bean method, direct or indirect. The bean may have already been
291291
// marked as 'in creation' in certain autowiring scenarios; if so, temporarily
292292
// set the in-creation status to false in order to avoid an exception.
@@ -303,7 +303,6 @@ public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object
303303
}
304304
}
305305
}
306-
307306
}
308307

309308
/**

spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java

Lines changed: 16 additions & 14 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-2013 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,6 +25,7 @@
2525
import org.springframework.core.annotation.AnnotationAttributes;
2626
import org.springframework.core.type.AnnotationMetadata;
2727
import org.springframework.util.Assert;
28+
import org.springframework.util.CollectionUtils;
2829

2930
/**
3031
* Abstract base {@code Configuration} class providing common structure for enabling
@@ -38,37 +39,38 @@
3839
public abstract class AbstractAsyncConfiguration implements ImportAware {
3940

4041
protected AnnotationAttributes enableAsync;
42+
4143
protected Executor executor;
4244

45+
4346
public void setImportMetadata(AnnotationMetadata importMetadata) {
4447
this.enableAsync = AnnotationAttributes.fromMap(
4548
importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
4649
Assert.notNull(this.enableAsync,
47-
"@EnableAsync is not present on importing class " +
48-
importMetadata.getClassName());
50+
"@EnableAsync is not present on importing class " + importMetadata.getClassName());
4951
}
5052

51-
/**
52-
* The component that will apply async execution advice to beans annotated with
53-
* the async annotation. Subclasses will provide either a BeanPostProcessor in
54-
* the case of proxy-based advice, or an AspectJ aspect if weaving is preferred.
55-
*/
56-
public abstract Object asyncAdvisor();
57-
5853
/**
5954
* Collect any {@link AsyncConfigurer} beans through autowiring.
6055
*/
6156
@Autowired(required = false)
6257
void setConfigurers(Collection<AsyncConfigurer> configurers) {
63-
if (configurers == null || configurers.isEmpty()) {
58+
if (CollectionUtils.isEmpty(configurers)) {
6459
return;
6560
}
66-
6761
if (configurers.size() > 1) {
68-
throw new IllegalStateException("only one AsyncConfigurer may exist");
62+
throw new IllegalStateException("Only one AsyncConfigurer may exist");
6963
}
70-
7164
AsyncConfigurer configurer = configurers.iterator().next();
7265
this.executor = configurer.getAsyncExecutor();
7366
}
67+
68+
69+
/**
70+
* The component that will apply async execution advice to beans annotated with
71+
* the async annotation. Subclasses will provide either a BeanPostProcessor in
72+
* the case of proxy-based advice, or an AspectJ aspect if weaving is preferred.
73+
*/
74+
public abstract Object asyncAdvisor();
75+
7476
}

spring-core/src/main/java/org/springframework/core/env/StandardEnvironment.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2013 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,8 +24,8 @@
2424
* property resolution and profile-related operations, this implementation configures two
2525
* default property sources, to be searched in the following order:
2626
* <ul>
27-
* <li>{@linkplain AbstractEnvironment#getSystemProperties() system properties}
28-
* <li>{@linkplain AbstractEnvironment#getSystemEnvironment() system environment variables}
27+
* <li>{@linkplain AbstractEnvironment#getSystemProperties() system properties}
28+
* <li>{@linkplain AbstractEnvironment#getSystemEnvironment() system environment variables}
2929
* </ul>
3030
*
3131
* That is, if the key "xyz" is present both in the JVM system properties as well as in
@@ -41,7 +41,7 @@
4141
* instance available from {@link #getPropertySources()}. See
4242
* {@link ConfigurableEnvironment} Javadoc for usage examples.
4343
*
44-
* <p>See {@link SystemEnvironmentPropertySource} Javadoc for details on special handling
44+
* <p>See {@link SystemEnvironmentPropertySource} javadoc for details on special handling
4545
* of property names in shell environments (e.g. Bash) that disallow period characters in
4646
* variable names.
4747
*
@@ -61,8 +61,8 @@ public class StandardEnvironment extends AbstractEnvironment {
6161

6262

6363
/**
64-
* Customize the set of property sources with those appropriate for any standard Java
65-
* environment:
64+
* Customize the set of property sources with those appropriate for any standard
65+
* Java environment:
6666
* <ul>
6767
* <li>{@value #SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME}
6868
* <li>{@value #SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME}

spring-test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java

Lines changed: 6 additions & 7 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-2013 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.
@@ -17,12 +17,12 @@
1717
package org.springframework.test.context.support;
1818

1919
import java.util.ArrayList;
20-
import java.util.Collections;
2120
import java.util.List;
2221
import java.util.Set;
2322

2423
import org.apache.commons.logging.Log;
2524
import org.apache.commons.logging.LogFactory;
25+
2626
import org.springframework.beans.BeanUtils;
2727
import org.springframework.context.ApplicationContext;
2828
import org.springframework.context.ApplicationContextInitializer;
@@ -120,12 +120,11 @@ public void processContextConfiguration(ContextConfigurationAttributes configAtt
120120
*/
121121
@SuppressWarnings("unchecked")
122122
protected void prepareContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
123-
124123
context.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles());
125124

126-
Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> initializerClasses = mergedConfig.getContextInitializerClasses();
127-
128-
if (initializerClasses.size() == 0) {
125+
Set<Class<? extends ApplicationContextInitializer<? extends ConfigurableApplicationContext>>> initializerClasses =
126+
mergedConfig.getContextInitializerClasses();
127+
if (initializerClasses.isEmpty()) {
129128
// no ApplicationContextInitializers have been declared -> nothing to do
130129
return;
131130
}
@@ -144,7 +143,7 @@ protected void prepareContext(ConfigurableApplicationContext context, MergedCont
144143
initializerInstances.add((ApplicationContextInitializer<ConfigurableApplicationContext>) BeanUtils.instantiateClass(initializerClass));
145144
}
146145

147-
Collections.sort(initializerInstances, new AnnotationAwareOrderComparator());
146+
AnnotationAwareOrderComparator.sort(initializerInstances);
148147
for (ApplicationContextInitializer<ConfigurableApplicationContext> initializer : initializerInstances) {
149148
initializer.initialize(context);
150149
}

spring-tx/src/main/java/org/springframework/transaction/annotation/AbstractTransactionManagementConfiguration.java

Lines changed: 7 additions & 7 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-2013 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,6 +25,7 @@
2525
import org.springframework.core.type.AnnotationMetadata;
2626
import org.springframework.transaction.PlatformTransactionManager;
2727
import org.springframework.util.Assert;
28+
import org.springframework.util.CollectionUtils;
2829

2930
/**
3031
* Abstract base {@code @Configuration} class providing common structure for enabling
@@ -38,26 +39,25 @@
3839
public abstract class AbstractTransactionManagementConfiguration implements ImportAware {
3940

4041
protected AnnotationAttributes enableTx;
42+
4143
protected PlatformTransactionManager txManager;
4244

45+
4346
public void setImportMetadata(AnnotationMetadata importMetadata) {
4447
this.enableTx = AnnotationAttributes.fromMap(
4548
importMetadata.getAnnotationAttributes(EnableTransactionManagement.class.getName(), false));
4649
Assert.notNull(this.enableTx,
47-
"@EnableTransactionManagement is not present on importing class " +
48-
importMetadata.getClassName());
50+
"@EnableTransactionManagement is not present on importing class " + importMetadata.getClassName());
4951
}
5052

5153
@Autowired(required=false)
5254
void setConfigurers(Collection<TransactionManagementConfigurer> configurers) {
53-
if (configurers == null || configurers.isEmpty()) {
55+
if (CollectionUtils.isEmpty(configurers)) {
5456
return;
5557
}
56-
5758
if (configurers.size() > 1) {
58-
throw new IllegalStateException("only one TransactionManagementConfigurer may exist");
59+
throw new IllegalStateException("Only one TransactionManagementConfigurer may exist");
5960
}
60-
6161
TransactionManagementConfigurer configurer = configurers.iterator().next();
6262
this.txManager = configurer.annotationDrivenTransactionManager();
6363
}

spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionManagementConfigurationSelector.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2013 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.
@@ -45,13 +45,12 @@ public class TransactionManagementConfigurationSelector
4545
protected String[] selectImports(AdviceMode adviceMode) {
4646
switch (adviceMode) {
4747
case PROXY:
48-
return new String[] { AutoProxyRegistrar.class.getName(), ProxyTransactionManagementConfiguration.class.getName() };
48+
return new String[] {AutoProxyRegistrar.class.getName(), ProxyTransactionManagementConfiguration.class.getName()};
4949
case ASPECTJ:
50-
return new String[] { TransactionManagementConfigUtils.TRANSACTION_ASPECT_CONFIGURATION_CLASS_NAME };
50+
return new String[] {TransactionManagementConfigUtils.TRANSACTION_ASPECT_CONFIGURATION_CLASS_NAME};
5151
default:
5252
return null;
5353
}
5454
}
5555

56-
5756
}

0 commit comments

Comments
 (0)