Skip to content

Commit b95a95f

Browse files
committed
Polishing
1 parent 6614b99 commit b95a95f

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.
@@ -62,18 +62,20 @@
6262
* <p>Individual expressions can be compiled by calling {@code SpelCompiler.compile(expression)}.
6363
*
6464
* @author Andy Clement
65+
* @author Juergen Hoeller
6566
* @since 4.1
6667
*/
6768
public class SpelCompiler implements Opcodes {
6869

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

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

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

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

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

155157
CodeFlow cf = new CodeFlow(className, cw);
@@ -186,11 +188,11 @@ private Class<? extends CompiledExpression> createExpressionClass(SpelNodeImpl e
186188

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

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

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

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

269274

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

272280
public ExpressionClassWriter() {

0 commit comments

Comments
 (0)