Skip to content

Commit 779a6b7

Browse files
committed
Polishing
1 parent 9e20607 commit 779a6b7

File tree

12 files changed

+175
-176
lines changed

12 files changed

+175
-176
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactory.java

Lines changed: 2 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-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.
@@ -19,7 +19,6 @@
1919
import org.aopalliance.intercept.Interceptor;
2020

2121
import org.springframework.aop.TargetSource;
22-
import org.springframework.util.Assert;
2322
import org.springframework.util.ClassUtils;
2423

2524
/**
@@ -47,9 +46,8 @@ public ProxyFactory() {
4746
* @param target the target object to be proxied
4847
*/
4948
public ProxyFactory(Object target) {
50-
Assert.notNull(target, "Target object must not be null");
51-
setInterfaces(ClassUtils.getAllInterfaces(target));
5249
setTarget(target);
50+
setInterfaces(ClassUtils.getAllInterfaces(target));
5351
}
5452

5553
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2009 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.
@@ -239,7 +239,7 @@ else if ("regex".equals(filterType)) {
239239
return new RegexPatternTypeFilter(Pattern.compile(expression));
240240
}
241241
else if ("custom".equals(filterType)) {
242-
Class filterClass = classLoader.loadClass(expression);
242+
Class<?> filterClass = classLoader.loadClass(expression);
243243
if (!TypeFilter.class.isAssignableFrom(filterClass)) {
244244
throw new IllegalArgumentException(
245245
"Class is not assignable to [" + TypeFilter.class.getName() + "]: " + expression);
@@ -256,8 +256,8 @@ else if ("custom".equals(filterType)) {
256256
}
257257

258258
@SuppressWarnings("unchecked")
259-
private Object instantiateUserDefinedStrategy(String className, Class strategyType, ClassLoader classLoader) {
260-
Object result = null;
259+
private Object instantiateUserDefinedStrategy(String className, Class<?> strategyType, ClassLoader classLoader) {
260+
Object result;
261261
try {
262262
result = classLoader.loadClass(className).newInstance();
263263
}
@@ -267,7 +267,7 @@ private Object instantiateUserDefinedStrategy(String className, Class strategyTy
267267
}
268268
catch (Exception ex) {
269269
throw new IllegalArgumentException("Unable to instantiate class [" + className + "] for strategy [" +
270-
strategyType.getName() + "]. A zero-argument constructor is required", ex);
270+
strategyType.getName() + "]: a zero-argument constructor is required", ex);
271271
}
272272

273273
if (!strategyType.isAssignableFrom(result.getClass())) {

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

Lines changed: 2 additions & 2 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-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.
@@ -179,7 +179,7 @@ public void validate(ProblemReporter problemReporter) {
179179
for (BeanMethod beanMethod : this.beanMethods) {
180180
String fqMethodName = beanMethod.getFullyQualifiedMethodName();
181181
Integer currentCount = methodNameCounts.get(fqMethodName);
182-
int newCount = currentCount != null ? currentCount + 1 : 1;
182+
int newCount = (currentCount != null ? currentCount + 1 : 1);
183183
methodNameCounts.put(fqMethodName, newCount);
184184
}
185185
for (String fqMethodName : methodNameCounts.keySet()) {

spring-core/src/main/java/org/springframework/core/LocalVariableTableParameterNameDiscoverer.java

Lines changed: 33 additions & 31 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-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,8 +101,8 @@ private Map<Member, String[]> inspectClass(Class<?> clazz) {
101101
// We couldn't load the class file, which is not fatal as it
102102
// simply means this method of discovering parameter names won't work.
103103
if (logger.isDebugEnabled()) {
104-
logger.debug("Cannot find '.class' file for class [" + clazz
105-
+ "] - unable to determine constructors/methods parameter names");
104+
logger.debug("Cannot find '.class' file for class [" + clazz +
105+
"] - unable to determine constructor/method parameter names");
106106
}
107107
return NO_DEBUG_INFO_MAP;
108108
}
@@ -115,14 +115,14 @@ private Map<Member, String[]> inspectClass(Class<?> clazz) {
115115
catch (IOException ex) {
116116
if (logger.isDebugEnabled()) {
117117
logger.debug("Exception thrown while reading '.class' file for class [" + clazz +
118-
"] - unable to determine constructors/methods parameter names", ex);
118+
"] - unable to determine constructor/method parameter names", ex);
119119
}
120120
}
121121
catch (IllegalArgumentException ex) {
122122
if (logger.isDebugEnabled()) {
123123
logger.debug("ASM ClassReader failed to parse class file [" + clazz +
124124
"], probably due to a new Java class file version that isn't supported yet " +
125-
"- unable to determine constructors/methods parameter names", ex);
125+
"- unable to determine constructor/method parameter names", ex);
126126
}
127127
}
128128
finally {
@@ -146,6 +146,7 @@ private static class ParameterNameDiscoveringVisitor extends ClassVisitor {
146146
private static final String STATIC_CLASS_INIT = "<clinit>";
147147

148148
private final Class<?> clazz;
149+
149150
private final Map<Member, String[]> memberMap;
150151

151152
public ParameterNameDiscoveringVisitor(Class<?> clazz, Map<Member, String[]> memberMap) {
@@ -178,12 +179,17 @@ private static class LocalVariableTableVisitor extends MethodVisitor {
178179
private static final String CONSTRUCTOR = "<init>";
179180

180181
private final Class<?> clazz;
182+
181183
private final Map<Member, String[]> memberMap;
184+
182185
private final String name;
186+
183187
private final Type[] args;
188+
189+
private final String[] parameterNames;
190+
184191
private final boolean isStatic;
185192

186-
private String[] parameterNames;
187193
private boolean hasLvtInfo = false;
188194

189195
/*
@@ -192,25 +198,22 @@ private static class LocalVariableTableVisitor extends MethodVisitor {
192198
*/
193199
private final int[] lvtSlotIndex;
194200

195-
public LocalVariableTableVisitor(Class<?> clazz, Map<Member, String[]> map, String name, String desc,
196-
boolean isStatic) {
201+
public LocalVariableTableVisitor(Class<?> clazz, Map<Member, String[]> map, String name, String desc, boolean isStatic) {
197202
super(SpringAsmInfo.ASM_VERSION);
198203
this.clazz = clazz;
199204
this.memberMap = map;
200205
this.name = name;
201-
// determine args
202-
args = Type.getArgumentTypes(desc);
203-
this.parameterNames = new String[args.length];
206+
this.args = Type.getArgumentTypes(desc);
207+
this.parameterNames = new String[this.args.length];
204208
this.isStatic = isStatic;
205-
this.lvtSlotIndex = computeLvtSlotIndices(isStatic, args);
209+
this.lvtSlotIndex = computeLvtSlotIndices(isStatic, this.args);
206210
}
207211

208212
@Override
209-
public void visitLocalVariable(String name, String description, String signature, Label start, Label end,
210-
int index) {
213+
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
211214
this.hasLvtInfo = true;
212-
for (int i = 0; i < lvtSlotIndex.length; i++) {
213-
if (lvtSlotIndex[i] == index) {
215+
for (int i = 0; i < this.lvtSlotIndex.length; i++) {
216+
if (this.lvtSlotIndex[i] == index) {
214217
this.parameterNames[i] = name;
215218
}
216219
}
@@ -223,27 +226,25 @@ public void visitEnd() {
223226
// which doesn't use any local variables.
224227
// This means that hasLvtInfo could be false for that kind of methods
225228
// even if the class has local variable info.
226-
memberMap.put(resolveMember(), parameterNames);
229+
this.memberMap.put(resolveMember(), this.parameterNames);
227230
}
228231
}
229232

230233
private Member resolveMember() {
231-
ClassLoader loader = clazz.getClassLoader();
232-
Class<?>[] classes = new Class<?>[args.length];
233-
234-
// resolve args
235-
for (int i = 0; i < args.length; i++) {
236-
classes[i] = ClassUtils.resolveClassName(args[i].getClassName(), loader);
234+
ClassLoader loader = this.clazz.getClassLoader();
235+
Class<?>[] argTypes = new Class<?>[this.args.length];
236+
for (int i = 0; i < this.args.length; i++) {
237+
argTypes[i] = ClassUtils.resolveClassName(this.args[i].getClassName(), loader);
237238
}
238239
try {
239-
if (CONSTRUCTOR.equals(name)) {
240-
return clazz.getDeclaredConstructor(classes);
240+
if (CONSTRUCTOR.equals(this.name)) {
241+
return this.clazz.getDeclaredConstructor(argTypes);
241242
}
242-
243-
return clazz.getDeclaredMethod(name, classes);
244-
} catch (NoSuchMethodException ex) {
245-
throw new IllegalStateException("Method [" + name
246-
+ "] was discovered in the .class file but cannot be resolved in the class object", ex);
243+
return this.clazz.getDeclaredMethod(this.name, argTypes);
244+
}
245+
catch (NoSuchMethodException ex) {
246+
throw new IllegalStateException("Method [" + this.name +
247+
"] was discovered in the .class file but cannot be resolved in the class object", ex);
247248
}
248249
}
249250

@@ -254,7 +255,8 @@ private static int[] computeLvtSlotIndices(boolean isStatic, Type[] paramTypes)
254255
lvtIndex[i] = nextIndex;
255256
if (isWideType(paramTypes[i])) {
256257
nextIndex += 2;
257-
} else {
258+
}
259+
else {
258260
nextIndex++;
259261
}
260262
}

spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java

Lines changed: 4 additions & 3 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.
@@ -45,7 +45,7 @@ public class FileSystemResource extends AbstractResource implements WritableReso
4545

4646

4747
/**
48-
* Create a new FileSystemResource from a File handle.
48+
* Create a new {@code FileSystemResource} from a {@link File} handle.
4949
* <p>Note: When building relative resources via {@link #createRelative},
5050
* the relative path will apply <i>at the same directory level</i>:
5151
* e.g. new File("C:/dir1"), relative path "dir2" -> "C:/dir2"!
@@ -62,7 +62,7 @@ public FileSystemResource(File file) {
6262
}
6363

6464
/**
65-
* Create a new FileSystemResource from a file path.
65+
* Create a new {@code FileSystemResource} from a file path.
6666
* <p>Note: When building relative resources via {@link #createRelative},
6767
* it makes a difference whether the specified resource base path here
6868
* ends with a slash or not. In the case of "C:/dir1/", relative paths
@@ -77,6 +77,7 @@ public FileSystemResource(String path) {
7777
this.path = StringUtils.cleanPath(path);
7878
}
7979

80+
8081
/**
8182
* Return the file path for this resource.
8283
*/

spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java

Lines changed: 8 additions & 3 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.
@@ -49,9 +49,14 @@ public StandardMethodMetadata(Method introspectedMethod) {
4949
}
5050

5151
/**
52-
* Create a new StandardMethodMetadata wrapper for the given Method.
52+
* Create a new StandardMethodMetadata wrapper for the given Method,
53+
* providing the option to return any nested annotations or annotation arrays in the
54+
* form of {@link org.springframework.core.annotation.AnnotationAttributes} instead
55+
* of actual {@link java.lang.annotation.Annotation} instances.
5356
* @param introspectedMethod the Method to introspect
54-
* @param nestedAnnotationsAsMap
57+
* @param nestedAnnotationsAsMap return nested annotations and annotation arrays as
58+
* {@link org.springframework.core.annotation.AnnotationAttributes} for compatibility
59+
* with ASM-based {@link AnnotationMetadata} implementations
5560
* @since 3.1.1
5661
*/
5762
public StandardMethodMetadata(Method introspectedMethod, boolean nestedAnnotationsAsMap) {

spring-core/src/main/java/org/springframework/core/type/classreading/MethodMetadataReadingVisitor.java

Lines changed: 1 addition & 2 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-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.
@@ -27,7 +27,6 @@
2727
import org.springframework.asm.Type;
2828
import org.springframework.core.annotation.AnnotationAttributes;
2929
import org.springframework.core.type.MethodMetadata;
30-
import org.springframework.util.MultiValueMap;
3130

3231
/**
3332
* ASM method visitor which looks for the annotations defined on the method,

spring-core/src/main/java/org/springframework/core/type/filter/AbstractTypeHierarchyTraversingFilter.java

Lines changed: 3 additions & 3 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.
@@ -19,8 +19,8 @@
1919
import java.io.IOException;
2020

2121
import org.springframework.core.type.ClassMetadata;
22-
import org.springframework.core.type.classreading.MetadataReaderFactory;
2322
import org.springframework.core.type.classreading.MetadataReader;
23+
import org.springframework.core.type.classreading.MetadataReaderFactory;
2424

2525
/**
2626
* Type filter that is aware of traversing over hierarchy.
@@ -131,7 +131,7 @@ protected Boolean matchSuperClass(String superClassName) {
131131
/**
132132
* Override this to match on interface type name.
133133
*/
134-
protected Boolean matchInterface(String interfaceNames) {
134+
protected Boolean matchInterface(String interfaceName) {
135135
return null;
136136
}
137137

0 commit comments

Comments
 (0)