Skip to content

Commit 103f57a

Browse files
committed
Polishing
1 parent a2a1a70 commit 103f57a

File tree

3 files changed

+35
-26
lines changed

3 files changed

+35
-26
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -219,10 +219,12 @@ public Class<?>[] getParameterTypes() {
219219
@Override
220220
@Nullable
221221
public String[] getParameterNames() {
222-
if (this.parameterNames == null) {
223-
this.parameterNames = parameterNameDiscoverer.getParameterNames(getMethod());
222+
String[] parameterNames = this.parameterNames;
223+
if (parameterNames == null) {
224+
parameterNames = parameterNameDiscoverer.getParameterNames(getMethod());
225+
this.parameterNames = parameterNames;
224226
}
225-
return this.parameterNames;
227+
return parameterNames;
226228
}
227229

228230
@Override

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -52,7 +52,7 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor {
5252

5353
/**
5454
* Create a new DirectFieldAccessor for the given object.
55-
* @param object object wrapped by this DirectFieldAccessor
55+
* @param object the object wrapped by this DirectFieldAccessor
5656
*/
5757
public DirectFieldAccessor(Object object) {
5858
super(object);
@@ -61,7 +61,7 @@ public DirectFieldAccessor(Object object) {
6161
/**
6262
* Create a new DirectFieldAccessor for the given object,
6363
* registering a nested path that the object is in.
64-
* @param object object wrapped by this DirectFieldAccessor
64+
* @param object the object wrapped by this DirectFieldAccessor
6565
* @param nestedPath the nested path of the object
6666
* @param parent the containing DirectFieldAccessor (must not be {@code null})
6767
*/
@@ -92,8 +92,7 @@ protected DirectFieldAccessor newNestedPropertyAccessor(Object object, String ne
9292
@Override
9393
protected NotWritablePropertyException createNotWritablePropertyException(String propertyName) {
9494
PropertyMatches matches = PropertyMatches.forField(propertyName, getRootClass());
95-
throw new NotWritablePropertyException(
96-
getRootClass(), getNestedPath() + propertyName,
95+
throw new NotWritablePropertyException(getRootClass(), getNestedPath() + propertyName,
9796
matches.buildErrorMessage(), matches.getPossibleMatches());
9897
}
9998

spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -63,18 +63,20 @@
6363
* <p>Individual expressions can be compiled by calling {@code SpelCompiler.compile(expression)}.
6464
*
6565
* @author Andy Clement
66+
* @author Juergen Hoeller
6667
* @since 4.1
6768
*/
6869
public final class SpelCompiler implements Opcodes {
6970

70-
private static final Log logger = LogFactory.getLog(SpelCompiler.class);
71-
7271
private static final int CLASSES_DEFINED_LIMIT = 100;
7372

73+
private static final Log logger = LogFactory.getLog(SpelCompiler.class);
74+
7475
// A compiler is created for each classloader, it manages a child class loader of that
7576
// classloader and the child is used to load the compiled expressions.
7677
private static final Map<ClassLoader, SpelCompiler> compilers = new ConcurrentReferenceHashMap<>();
7778

79+
7880
// The child ClassLoader used to load the compiled expression classes
7981
private ChildClassLoader ccl;
8082

@@ -90,7 +92,7 @@ private SpelCompiler(@Nullable ClassLoader classloader) {
9092
/**
9193
* Attempt compilation of the supplied expression. A check is made to see
9294
* if it is compilable before compilation proceeds. The check involves
93-
* visiting all the nodes in the expression Ast and ensuring enough state
95+
* visiting all the nodes in the expression AST and ensuring enough state
9496
* is known about them that bytecode can be generated for them.
9597
* @param expression the expression to compile
9698
* @return an instance of the class implementing the compiled expression,
@@ -125,7 +127,7 @@ private int getNextSuffix() {
125127

126128
/**
127129
* Generate the class that encapsulates the compiled expression and define it.
128-
* The generated class will be a subtype of CompiledExpression.
130+
* The generated class will be a subtype of CompiledExpression.
129131
* @param expressionToCompile the expression to be compiled
130132
* @return the expression call, or {@code null} if the decision was to opt out of
131133
* compilation during code generation
@@ -150,7 +152,7 @@ private Class<? extends CompiledExpression> createExpressionClass(SpelNodeImpl e
150152
// Create getValue() method
151153
mv = cw.visitMethod(ACC_PUBLIC, "getValue",
152154
"(Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;", null,
153-
new String[ ]{"org/springframework/expression/EvaluationException"});
155+
new String[] {"org/springframework/expression/EvaluationException"});
154156
mv.visitCode();
155157

156158
CodeFlow cf = new CodeFlow(className, cw);
@@ -187,11 +189,11 @@ private Class<? extends CompiledExpression> createExpressionClass(SpelNodeImpl e
187189

188190
/**
189191
* Load a compiled expression class. Makes sure the classloaders aren't used too much
190-
* because they anchor compiled classes in memory and prevent GC. If you have expressions
192+
* because they anchor compiled classes in memory and prevent GC. If you have expressions
191193
* continually recompiling over time then by replacing the classloader periodically
192194
* at least some of the older variants can be garbage collected.
193-
* @param name name of the class
194-
* @param bytes bytecode for the class
195+
* @param name the name of the class
196+
* @param bytes the bytecode for the class
195197
* @return the Class object for the compiled expression
196198
*/
197199
@SuppressWarnings("unchecked")
@@ -202,6 +204,7 @@ private Class<? extends CompiledExpression> loadClass(String name, byte[] bytes)
202204
return (Class<? extends CompiledExpression>) this.ccl.defineClass(name, bytes);
203205
}
204206

207+
205208
/**
206209
* Factory method for compiler instances. The returned SpelCompiler will
207210
* attach a class loader as the child of the given class loader and this
@@ -222,10 +225,12 @@ public static SpelCompiler getCompiler(@Nullable ClassLoader classLoader) {
222225
}
223226

224227
/**
225-
* Request that an attempt is made to compile the specified expression. It may fail if
226-
* components of the expression are not suitable for compilation or the data types
227-
* involved are not suitable for compilation. Used for testing.
228-
* @return true if the expression was successfully compiled
228+
* Request that an attempt is made to compile the specified expression.
229+
* It may fail if components of the expression are not suitable for compilation
230+
* or the data types involved are not suitable for compilation. Used for testing.
231+
* @param expression the expression to compile
232+
* @return {@code true} if the expression was successfully compiled,
233+
* {@code false} otherwise
229234
*/
230235
public static boolean compile(Expression expression) {
231236
return (expression instanceof SpelExpression && ((SpelExpression) expression).compileExpression());
@@ -256,18 +261,21 @@ public ChildClassLoader(@Nullable ClassLoader classLoader) {
256261
super(NO_URLS, classLoader);
257262
}
258263

259-
int getClassesDefinedCount() {
260-
return this.classesDefinedCount;
261-
}
262-
263264
public Class<?> defineClass(String name, byte[] bytes) {
264265
Class<?> clazz = super.defineClass(name, bytes, 0, bytes.length);
265266
this.classesDefinedCount++;
266267
return clazz;
267268
}
269+
270+
public int getClassesDefinedCount() {
271+
return this.classesDefinedCount;
272+
}
268273
}
269274

270275

276+
/**
277+
* An ASM ClassWriter extension bound to the SpelCompiler's ClassLoader.
278+
*/
271279
private class ExpressionClassWriter extends ClassWriter {
272280

273281
public ExpressionClassWriter() {

0 commit comments

Comments
 (0)