Skip to content

Commit 27c2e8c

Browse files
committed
Polishing
1 parent 388bd87 commit 27c2e8c

File tree

8 files changed

+33
-27
lines changed

8 files changed

+33
-27
lines changed

spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ DefaultCacheConfig getDefaultCacheConfig(Class<?> target) {
196196
}
197197

198198
private <A extends Annotation> Collection<A> getAnnotations(AnnotatedElement ae, Class<A> annotationType) {
199-
Collection<A> anns = new ArrayList<A>(2);
199+
Collection<A> anns = new ArrayList<A>(1);
200200

201201
// look at raw annotation
202202
A ann = ae.getAnnotation(annotationType);
@@ -212,7 +212,7 @@ private <A extends Annotation> Collection<A> getAnnotations(AnnotatedElement ae,
212212
}
213213
}
214214

215-
return (anns.isEmpty() ? null : anns);
215+
return (!anns.isEmpty() ? anns : null);
216216
}
217217

218218
/**

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

Lines changed: 6 additions & 5 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-2015 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.
@@ -29,17 +29,18 @@
2929
class BeanAnnotationHelper {
3030

3131
/**
32-
* Return whether the given method is annotated directly or indirectly with @Bean.
32+
* Return whether the given method is directly or indirectly annotated with
33+
* the {@link Bean} annotation.
3334
*/
3435
public static boolean isBeanAnnotated(Method method) {
35-
return AnnotationUtils.findAnnotation(method, Bean.class) != null;
36+
return (AnnotationUtils.findAnnotation(method, Bean.class) != null);
3637
}
3738

3839
public static String determineBeanNameFor(Method beanMethod) {
39-
// by default the bean name is the name of the @Bean-annotated method
40+
// By default, the bean name is the name of the @Bean-annotated method
4041
String beanName = beanMethod.getName();
4142

42-
// check to see if the user has explicitly set the bean name
43+
// Check to see if the user has explicitly set a custom bean name...
4344
Bean bean = AnnotationUtils.findAnnotation(beanMethod, Bean.class);
4445
if (bean != null && bean.name().length > 0) {
4546
beanName = bean.name()[0];

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -44,7 +44,7 @@ public void noop() {
4444

4545
@Configuration
4646
@ComponentScan(
47-
basePackageClasses={TestBean.class},
47+
basePackageClasses = TestBean.class,
4848
nameGenerator = DefaultBeanNameGenerator.class,
4949
scopedProxy = ScopedProxyMode.NO,
5050
scopeResolver = AnnotationScopeMetadataResolver.class,
@@ -61,6 +61,6 @@ public void noop() {
6161
class MyConfig {
6262
}
6363

64-
@ComponentScan(basePackageClasses=example.scannable.NamedComponent.class)
64+
@ComponentScan(basePackageClasses = example.scannable.NamedComponent.class)
6565
class SimpleConfig {
6666
}

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

Lines changed: 3 additions & 4 deletions
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-2015 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.
@@ -122,7 +122,7 @@ public void testAutowireByType() {
122122
context.refresh();
123123
fail("expected exception due to multiple matches for byType autowiring");
124124
}
125-
catch (UnsatisfiedDependencyException e) {
125+
catch (UnsatisfiedDependencyException ex) {
126126
// expected
127127
}
128128
}
@@ -161,7 +161,7 @@ public void testDependencyCheckAll() {
161161
context.refresh();
162162
fail("expected exception due to dependency check");
163163
}
164-
catch (UnsatisfiedDependencyException e) {
164+
catch (UnsatisfiedDependencyException ex) {
165165
// expected
166166
}
167167
}
@@ -230,7 +230,6 @@ private static class DefaultsTestBean {
230230

231231
private boolean destroyed;
232232

233-
234233
public DefaultsTestBean() {
235234
INIT_COUNT++;
236235
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ public class ComponentScanParserScopedProxyTests {
4242
@Rule
4343
public final ExpectedException exception = ExpectedException.none();
4444

45+
4546
@Test
4647
public void testDefaultScopedProxy() {
4748
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
4849
"org/springframework/context/annotation/scopedProxyDefaultTests.xml");
4950
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
51+
5052
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
5153
// should not be a proxy
5254
assertFalse(AopUtils.isAopProxy(bean));
@@ -58,6 +60,7 @@ public void testNoScopedProxy() {
5860
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
5961
"org/springframework/context/annotation/scopedProxyNoTests.xml");
6062
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
63+
6164
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
6265
// should not be a proxy
6366
assertFalse(AopUtils.isAopProxy(bean));
@@ -69,6 +72,7 @@ public void testInterfacesScopedProxy() throws Exception {
6972
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
7073
"org/springframework/context/annotation/scopedProxyInterfacesTests.xml");
7174
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
75+
7276
// should cast to the interface
7377
FooService bean = (FooService) context.getBean("scopedProxyTestBean");
7478
// should be dynamic proxy
@@ -86,6 +90,7 @@ public void testTargetClassScopedProxy() throws Exception {
8690
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
8791
"org/springframework/context/annotation/scopedProxyTargetClassTests.xml");
8892
context.getBeanFactory().registerScope("myScope", new SimpleMapScope());
93+
8994
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
9095
// should be a class-based proxy
9196
assertTrue(AopUtils.isCglibProxy(bean));
@@ -103,6 +108,7 @@ public void testInvalidConfigScopedProxy() throws Exception {
103108
exception.expect(BeanDefinitionParsingException.class);
104109
exception.expectMessage(containsString("Cannot define both 'scope-resolver' and 'scoped-proxy' on <component-scan> tag"));
105110
exception.expectMessage(containsString("Offending resource: class path resource [org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml]"));
111+
106112
new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml");
107113
}
108114

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -145,9 +145,9 @@ public void componentScanRespectsProfileAnnotation() {
145145
}
146146

147147

148-
@Target({ ElementType.TYPE, ElementType.FIELD })
148+
@Target({ElementType.TYPE, ElementType.FIELD})
149149
@Retention(RetentionPolicy.RUNTIME)
150-
public static @interface CustomAnnotation {
150+
public @interface CustomAnnotation {
151151
}
152152

153153

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

Lines changed: 4 additions & 4 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-2015 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.
@@ -53,7 +53,7 @@ public void testInvalidConstructorBeanNameGenerator() {
5353
"org/springframework/context/annotation/invalidConstructorNameGeneratorTests.xml");
5454
fail("should have failed: no-arg constructor is required");
5555
}
56-
catch (BeansException e) {
56+
catch (BeansException ex) {
5757
// expected
5858
}
5959
}
@@ -65,9 +65,9 @@ public void testInvalidClassNameScopeMetadataResolver() {
6565
"org/springframework/context/annotation/invalidClassNameScopeResolverTests.xml");
6666
fail("should have failed: no such class");
6767
}
68-
catch (BeansException e) {
68+
catch (BeansException ex) {
6969
// expected
7070
}
7171
}
7272

73-
}
73+
}

spring-core/src/main/java/org/springframework/core/annotation/SynthesizedAnnotationInvocationHandler.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class SynthesizedAnnotationInvocationHandler implements InvocationHandler {
6060
this.attributeExtractor = attributeExtractor;
6161
}
6262

63+
6364
@Override
6465
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
6566
if (isEqualsMethod(method)) {
@@ -75,8 +76,8 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
7576
return annotationType();
7677
}
7778
if (!isAttributeMethod(method)) {
78-
String msg = String.format("Method [%s] is unsupported for synthesized annotation type [%s]", method,
79-
annotationType());
79+
String msg = String.format("Method [%s] is unsupported for synthesized annotation type [%s]",
80+
method, annotationType());
8081
throw new AnnotationConfigurationException(msg);
8182
}
8283
return getAttributeValue(method);
@@ -92,9 +93,9 @@ private Object getAttributeValue(Method attributeMethod) {
9293
if (value == null) {
9394
value = this.attributeExtractor.getAttributeValue(attributeMethod);
9495
if (value == null) {
95-
throw new IllegalStateException(String.format(
96-
"%s returned null for attribute name [%s] from attribute source [%s]",
97-
this.attributeExtractor.getClass().getName(), attributeName, this.attributeExtractor.getSource()));
96+
String msg = String.format("%s returned null for attribute name [%s] from attribute source [%s]",
97+
this.attributeExtractor.getClass().getName(), attributeName, this.attributeExtractor.getSource());
98+
throw new IllegalStateException(msg);
9899
}
99100

100101
// Synthesize nested annotations before returning them.
@@ -200,7 +201,6 @@ private int annotationHashCode() {
200201
* in Spring's {@link ObjectUtils} because those hash code generation
201202
* algorithms do not comply with the requirements specified in
202203
* {@link Annotation#hashCode()}.
203-
*
204204
* @param array the array to compute the hash code for
205205
*/
206206
private int hashCodeForArray(Object array) {

0 commit comments

Comments
 (0)