Skip to content

Commit fd1d8ae

Browse files
committed
Polishing
(cherry picked from commit 91df065)
1 parent 9b2f9e6 commit fd1d8ae

File tree

6 files changed

+72
-61
lines changed

6 files changed

+72
-61
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
247247
BeanDefinition beanDefToRegister = beanDef;
248248
if (proxyMode != ScopedProxyMode.NO) {
249249
BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(
250-
new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLASS);
250+
new BeanDefinitionHolder(beanDef, beanName), this.registry,
251+
proxyMode == ScopedProxyMode.TARGET_CLASS);
251252
beanDefToRegister = new ConfigurationClassBeanDefinition(
252253
(RootBeanDefinition) proxyDef.getBeanDefinition(), configClass, metadata);
253254
}
@@ -272,7 +273,8 @@ protected boolean isOverriddenByExistingDefinition(BeanMethod beanMethod, String
272273
// preserve the existing bean definition.
273274
if (existingBeanDef instanceof ConfigurationClassBeanDefinition) {
274275
ConfigurationClassBeanDefinition ccbd = (ConfigurationClassBeanDefinition) existingBeanDef;
275-
return (ccbd.getMetadata().getClassName().equals(beanMethod.getConfigurationClass().getMetadata().getClassName()));
276+
return ccbd.getMetadata().getClassName().equals(
277+
beanMethod.getConfigurationClass().getMetadata().getClassName());
276278
}
277279

278280
// A bean definition resulting from a component scan can be silently overridden

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ protected void processConfigurationClass(ConfigurationClass configClass) throws
231231
// Explicit bean definition found, probably replacing an import.
232232
// Let's remove the old one and go with the new one.
233233
this.configurationClasses.remove(configClass);
234-
for (Iterator<ConfigurationClass> it = this.knownSuperclasses.values().iterator(); it.hasNext(); ) {
234+
for (Iterator<ConfigurationClass> it = this.knownSuperclasses.values().iterator(); it.hasNext();) {
235235
if (configClass.equals(it.next())) {
236236
it.remove();
237237
}
@@ -257,13 +257,16 @@ protected void processConfigurationClass(ConfigurationClass configClass) throws
257257
* @param sourceClass a source class
258258
* @return the superclass, or {@code null} if none found or previously processed
259259
*/
260-
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass) throws IOException {
260+
protected final SourceClass doProcessConfigurationClass(ConfigurationClass configClass, SourceClass sourceClass)
261+
throws IOException {
262+
261263
// Recursively process any member (nested) classes first
262264
processMemberClasses(configClass, sourceClass);
263265

264266
// Process any @PropertySource annotations
265267
for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable(
266-
sourceClass.getMetadata(), PropertySources.class, org.springframework.context.annotation.PropertySource.class)) {
268+
sourceClass.getMetadata(), PropertySources.class,
269+
org.springframework.context.annotation.PropertySource.class)) {
267270
if (this.environment instanceof ConfigurableEnvironment) {
268271
processPropertySource(propertySource);
269272
}
@@ -276,14 +279,16 @@ protected final SourceClass doProcessConfigurationClass(ConfigurationClass confi
276279
// Process any @ComponentScan annotations
277280
Set<AnnotationAttributes> componentScans = AnnotationConfigUtils.attributesForRepeatable(
278281
sourceClass.getMetadata(), ComponentScans.class, ComponentScan.class);
279-
if (!componentScans.isEmpty() && !this.conditionEvaluator.shouldSkip(sourceClass.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) {
282+
if (!componentScans.isEmpty() &&
283+
!this.conditionEvaluator.shouldSkip(sourceClass.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) {
280284
for (AnnotationAttributes componentScan : componentScans) {
281285
// The config class is annotated with @ComponentScan -> perform the scan immediately
282286
Set<BeanDefinitionHolder> scannedBeanDefinitions =
283287
this.componentScanParser.parse(componentScan, sourceClass.getMetadata().getClassName());
284-
// Check the set of scanned definitions for any further config classes and parse recursively if necessary
288+
// Check the set of scanned definitions for any further config classes and parse recursively if needed
285289
for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
286-
if (ConfigurationClassUtils.checkConfigurationClassCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) {
290+
if (ConfigurationClassUtils.checkConfigurationClassCandidate(
291+
holder.getBeanDefinition(), this.metadataReaderFactory)) {
287292
parse(holder.getBeanDefinition().getBeanClassName(), holder.getBeanName());
288293
}
289294
}
@@ -517,7 +522,9 @@ private Set<SourceClass> getImports(SourceClass sourceClass) throws IOException
517522
* @param visited used to track visited classes to prevent infinite recursion
518523
* @throws IOException if there is any problem reading metadata from the named class
519524
*/
520-
private void collectImports(SourceClass sourceClass, Set<SourceClass> imports, Set<SourceClass> visited) throws IOException {
525+
private void collectImports(SourceClass sourceClass, Set<SourceClass> imports, Set<SourceClass> visited)
526+
throws IOException {
527+
521528
if (visited.add(sourceClass)) {
522529
for (SourceClass annotation : sourceClass.getAnnotations()) {
523530
String annName = annotation.getMetadata().getClassName();
@@ -544,7 +551,8 @@ private void processDeferredImportSelectors() {
544551
throw ex;
545552
}
546553
catch (Throwable ex) {
547-
throw new BeanDefinitionStoreException("Failed to process import candidates for configuration class [" +
554+
throw new BeanDefinitionStoreException(
555+
"Failed to process import candidates for configuration class [" +
548556
configClass.getMetadata().getClassName() + "]", ex);
549557
}
550558
}
@@ -603,7 +611,8 @@ else if (candidate.isAssignable(ImportBeanDefinitionRegistrar.class)) {
603611
throw ex;
604612
}
605613
catch (Throwable ex) {
606-
throw new BeanDefinitionStoreException("Failed to process import candidates for configuration class [" +
614+
throw new BeanDefinitionStoreException(
615+
"Failed to process import candidates for configuration class [" +
607616
configClass.getMetadata().getClassName() + "]", ex);
608617
}
609618
finally {
@@ -742,9 +751,9 @@ private static class DeferredImportSelectorHolder {
742751

743752
private final DeferredImportSelector importSelector;
744753

745-
public DeferredImportSelectorHolder(ConfigurationClass configurationClass, DeferredImportSelector importSelector) {
746-
this.configurationClass = configurationClass;
747-
this.importSelector = importSelector;
754+
public DeferredImportSelectorHolder(ConfigurationClass configClass, DeferredImportSelector selector) {
755+
this.configurationClass = configClass;
756+
this.importSelector = selector;
748757
}
749758

750759
public ConfigurationClass getConfigurationClass() {
@@ -878,8 +887,8 @@ public Set<SourceClass> getAnnotations() throws IOException {
878887
return result;
879888
}
880889

881-
public Collection<SourceClass> getAnnotationAttributes(String annotationType, String attribute) throws IOException {
882-
Map<String, Object> annotationAttributes = this.metadata.getAnnotationAttributes(annotationType, true);
890+
public Collection<SourceClass> getAnnotationAttributes(String annType, String attribute) throws IOException {
891+
Map<String, Object> annotationAttributes = this.metadata.getAnnotationAttributes(annType, true);
883892
if (annotationAttributes == null || !annotationAttributes.containsKey(attribute)) {
884893
return Collections.emptySet();
885894
}

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -287,11 +287,11 @@ public int compare(BeanDefinitionHolder bd1, BeanDefinitionHolder bd2) {
287287
});
288288

289289
// Detect any custom bean name generation strategy supplied through the enclosing application context
290-
SingletonBeanRegistry singletonRegistry = null;
290+
SingletonBeanRegistry sbr = null;
291291
if (registry instanceof SingletonBeanRegistry) {
292-
singletonRegistry = (SingletonBeanRegistry) registry;
293-
if (!this.localBeanNameGeneratorSet && singletonRegistry.containsSingleton(CONFIGURATION_BEAN_NAME_GENERATOR)) {
294-
BeanNameGenerator generator = (BeanNameGenerator) singletonRegistry.getSingleton(CONFIGURATION_BEAN_NAME_GENERATOR);
292+
sbr = (SingletonBeanRegistry) registry;
293+
if (!this.localBeanNameGeneratorSet && sbr.containsSingleton(CONFIGURATION_BEAN_NAME_GENERATOR)) {
294+
BeanNameGenerator generator = (BeanNameGenerator) sbr.getSingleton(CONFIGURATION_BEAN_NAME_GENERATOR);
295295
this.componentScanBeanNameGenerator = generator;
296296
this.importBeanNameGenerator = generator;
297297
}
@@ -330,10 +330,10 @@ public int compare(BeanDefinitionHolder bd1, BeanDefinitionHolder bd2) {
330330
}
331331
for (String candidateName : newCandidateNames) {
332332
if (!oldCandidateNames.contains(candidateName)) {
333-
BeanDefinition beanDef = registry.getBeanDefinition(candidateName);
334-
if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.metadataReaderFactory) &&
335-
!alreadyParsedClasses.contains(beanDef.getBeanClassName())) {
336-
candidates.add(new BeanDefinitionHolder(beanDef, candidateName));
333+
BeanDefinition bd = registry.getBeanDefinition(candidateName);
334+
if (ConfigurationClassUtils.checkConfigurationClassCandidate(bd, this.metadataReaderFactory) &&
335+
!alreadyParsedClasses.contains(bd.getBeanClassName())) {
336+
candidates.add(new BeanDefinitionHolder(bd, candidateName));
337337
}
338338
}
339339
}
@@ -343,9 +343,9 @@ public int compare(BeanDefinitionHolder bd1, BeanDefinitionHolder bd2) {
343343
while (!candidates.isEmpty());
344344

345345
// Register the ImportRegistry as a bean in order to support ImportAware @Configuration classes
346-
if (singletonRegistry != null) {
347-
if (!singletonRegistry.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
348-
singletonRegistry.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
346+
if (sbr != null) {
347+
if (!sbr.containsSingleton(IMPORT_REGISTRY_BEAN_NAME)) {
348+
sbr.registerSingleton(IMPORT_REGISTRY_BEAN_NAME, parser.getImportRegistry());
349349
}
350350
}
351351

@@ -415,7 +415,9 @@ public ImportAwareBeanPostProcessor(BeanFactory beanFactory) {
415415
}
416416

417417
@Override
418-
public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) {
418+
public PropertyValues postProcessPropertyValues(
419+
PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) {
420+
419421
// Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's
420422
// postProcessPropertyValues method attempts to autowire other configuration beans.
421423
if (bean instanceof EnhancedConfiguration) {
@@ -427,8 +429,8 @@ public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDesc
427429
@Override
428430
public Object postProcessBeforeInitialization(Object bean, String beanName) {
429431
if (bean instanceof ImportAware) {
430-
ImportRegistry importRegistry = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class);
431-
AnnotationMetadata importingClass = importRegistry.getImportingClassFor(bean.getClass().getSuperclass().getName());
432+
ImportRegistry ir = this.beanFactory.getBean(IMPORT_REGISTRY_BEAN_NAME, ImportRegistry.class);
433+
AnnotationMetadata importingClass = ir.getImportingClassFor(bean.getClass().getSuperclass().getName());
432434
if (importingClass != null) {
433435
((ImportAware) bean).setImportMetadata(importingClass);
434436
}

spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -270,9 +270,7 @@ public void testWithNoArgConstructor() {
270270
aop.setConstructorArguments(new Object[] {"Rob Harrop", 22}, new Class<?>[] {String.class, int.class});
271271

272272
NoArgCtorTestBean proxy = (NoArgCtorTestBean) aop.getProxy();
273-
proxy = (NoArgCtorTestBean) aop.getProxy();
274-
275-
assertNotNull("Proxy should be null", proxy);
273+
assertNotNull(proxy);
276274
}
277275

278276
@Test

spring-core/src/main/java/org/springframework/util/ClassUtils.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -1078,71 +1078,71 @@ public static Class<?>[] toClassArray(Collection<Class<?>> collection) {
10781078
}
10791079

10801080
/**
1081-
* Return all interfaces that the given instance implements as array,
1081+
* Return all interfaces that the given instance implements as an array,
10821082
* including ones implemented by superclasses.
10831083
* @param instance the instance to analyze for interfaces
1084-
* @return all interfaces that the given instance implements as array
1084+
* @return all interfaces that the given instance implements as an array
10851085
*/
10861086
public static Class<?>[] getAllInterfaces(Object instance) {
10871087
Assert.notNull(instance, "Instance must not be null");
10881088
return getAllInterfacesForClass(instance.getClass());
10891089
}
10901090

10911091
/**
1092-
* Return all interfaces that the given class implements as array,
1092+
* Return all interfaces that the given class implements as an array,
10931093
* including ones implemented by superclasses.
10941094
* <p>If the class itself is an interface, it gets returned as sole interface.
10951095
* @param clazz the class to analyze for interfaces
1096-
* @return all interfaces that the given object implements as array
1096+
* @return all interfaces that the given object implements as an array
10971097
*/
10981098
public static Class<?>[] getAllInterfacesForClass(Class<?> clazz) {
10991099
return getAllInterfacesForClass(clazz, null);
11001100
}
11011101

11021102
/**
1103-
* Return all interfaces that the given class implements as array,
1103+
* Return all interfaces that the given class implements as an array,
11041104
* including ones implemented by superclasses.
11051105
* <p>If the class itself is an interface, it gets returned as sole interface.
11061106
* @param clazz the class to analyze for interfaces
11071107
* @param classLoader the ClassLoader that the interfaces need to be visible in
11081108
* (may be {@code null} when accepting all declared interfaces)
1109-
* @return all interfaces that the given object implements as array
1109+
* @return all interfaces that the given object implements as an array
11101110
*/
11111111
public static Class<?>[] getAllInterfacesForClass(Class<?> clazz, ClassLoader classLoader) {
11121112
Set<Class<?>> ifcs = getAllInterfacesForClassAsSet(clazz, classLoader);
11131113
return ifcs.toArray(new Class<?>[ifcs.size()]);
11141114
}
11151115

11161116
/**
1117-
* Return all interfaces that the given instance implements as Set,
1117+
* Return all interfaces that the given instance implements as a Set,
11181118
* including ones implemented by superclasses.
11191119
* @param instance the instance to analyze for interfaces
1120-
* @return all interfaces that the given instance implements as Set
1120+
* @return all interfaces that the given instance implements as a Set
11211121
*/
11221122
public static Set<Class<?>> getAllInterfacesAsSet(Object instance) {
11231123
Assert.notNull(instance, "Instance must not be null");
11241124
return getAllInterfacesForClassAsSet(instance.getClass());
11251125
}
11261126

11271127
/**
1128-
* Return all interfaces that the given class implements as Set,
1128+
* Return all interfaces that the given class implements as a Set,
11291129
* including ones implemented by superclasses.
11301130
* <p>If the class itself is an interface, it gets returned as sole interface.
11311131
* @param clazz the class to analyze for interfaces
1132-
* @return all interfaces that the given object implements as Set
1132+
* @return all interfaces that the given object implements as a Set
11331133
*/
11341134
public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz) {
11351135
return getAllInterfacesForClassAsSet(clazz, null);
11361136
}
11371137

11381138
/**
1139-
* Return all interfaces that the given class implements as Set,
1139+
* Return all interfaces that the given class implements as a Set,
11401140
* including ones implemented by superclasses.
11411141
* <p>If the class itself is an interface, it gets returned as sole interface.
11421142
* @param clazz the class to analyze for interfaces
11431143
* @param classLoader the ClassLoader that the interfaces need to be visible in
11441144
* (may be {@code null} when accepting all declared interfaces)
1145-
* @return all interfaces that the given object implements as Set
1145+
* @return all interfaces that the given object implements as a Set
11461146
*/
11471147
public static Set<Class<?>> getAllInterfacesForClassAsSet(Class<?> clazz, ClassLoader classLoader) {
11481148
Assert.notNull(clazz, "Class must not be null");

0 commit comments

Comments
 (0)