Skip to content

Commit 5b06c23

Browse files
committed
Consistent javadoc within SpelCompiler
1 parent 7881329 commit 5b06c23

File tree

1 file changed

+23
-15
lines changed
  • spring-expression/src/main/java/org/springframework/expression/spel/standard

1 file changed

+23
-15
lines changed

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

Lines changed: 23 additions & 15 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,7 +189,7 @@ 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.
193195
* @param name the name of the class
@@ -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)