Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.expression;
|
||||
|
||||
/**
|
||||
* Super class for exceptions that can occur whilst processing expressions
|
||||
* Super class for exceptions that can occur whilst processing expressions.
|
||||
*
|
||||
* @author Andy Clement
|
||||
* @since 3.0
|
||||
@@ -27,11 +27,11 @@ public class ExpressionException extends RuntimeException {
|
||||
|
||||
protected String expressionString;
|
||||
|
||||
protected int position; // -1 if not known - but should be known in all reasonable cases
|
||||
protected int position; // -1 if not known - but should be known in all reasonable cases
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new expression exception.
|
||||
* Construct a new expression exception.
|
||||
* @param expressionString the expression string
|
||||
* @param message a descriptive message
|
||||
*/
|
||||
@@ -42,7 +42,7 @@ public class ExpressionException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new expression exception.
|
||||
* Construct a new expression exception.
|
||||
* @param expressionString the expression string
|
||||
* @param position the position in the expression string where the problem occurred
|
||||
* @param message a descriptive message
|
||||
@@ -54,7 +54,7 @@ public class ExpressionException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new expression exception.
|
||||
* Construct a new expression exception.
|
||||
* @param position the position in the expression string where the problem occurred
|
||||
* @param message a descriptive message
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ public class ExpressionException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new expression exception.
|
||||
* Construct a new expression exception.
|
||||
* @param position the position in the expression string where the problem occurred
|
||||
* @param message a descriptive message
|
||||
* @param cause the underlying cause of this exception
|
||||
@@ -75,21 +75,40 @@ public class ExpressionException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new expression exception.
|
||||
* Construct a new expression exception.
|
||||
* @param message a descriptive message
|
||||
*/
|
||||
public ExpressionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new expression exception.
|
||||
* @param message a descriptive message
|
||||
* @param cause the underlying cause of this exception
|
||||
*/
|
||||
public ExpressionException(String message, Throwable cause) {
|
||||
super(message,cause);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the exception message. Since Spring 4.0 this method returns the same
|
||||
* result as {@link #toDetailedString()}.
|
||||
* Return the expression string.
|
||||
*/
|
||||
public final String getExpressionString() {
|
||||
return this.expressionString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the position in the expression string where the problem occurred.
|
||||
*/
|
||||
public final int getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the exception message. Since Spring 4.0 this method returns the
|
||||
* same result as {@link #toDetailedString()}.
|
||||
* @see java.lang.Throwable#getMessage()
|
||||
*/
|
||||
@Override
|
||||
@@ -98,35 +117,34 @@ public class ExpressionException extends RuntimeException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the exception simple message without including the expression that caused
|
||||
* the failure.
|
||||
* Return a detailed description of this exception, including the expression
|
||||
* String and position (if available) as well as the actual exception message.
|
||||
*/
|
||||
public String toDetailedString() {
|
||||
if (this.expressionString != null) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("Expression '");
|
||||
output.append(this.expressionString);
|
||||
output.append("'");
|
||||
if (this.position != -1) {
|
||||
output.append(" @ ");
|
||||
output.append(this.position);
|
||||
}
|
||||
output.append(": ");
|
||||
output.append(getSimpleMessage());
|
||||
return output.toString();
|
||||
}
|
||||
else {
|
||||
return getSimpleMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the exception simple message without including the expression
|
||||
* that caused the failure.
|
||||
*/
|
||||
public String getSimpleMessage() {
|
||||
return super.getMessage();
|
||||
}
|
||||
|
||||
public String toDetailedString() {
|
||||
StringBuilder output = new StringBuilder();
|
||||
if (this.expressionString!=null) {
|
||||
output.append("Expression '");
|
||||
output.append(this.expressionString);
|
||||
output.append("'");
|
||||
if (this.position!=-1) {
|
||||
output.append(" @ ");
|
||||
output.append(this.position);
|
||||
}
|
||||
output.append(": ");
|
||||
}
|
||||
output.append(getSimpleMessage());
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
public final String getExpressionString() {
|
||||
return this.expressionString;
|
||||
}
|
||||
|
||||
public final int getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,7 +56,7 @@ public class CodeFlow implements Opcodes {
|
||||
* will be called after the main evaluation function has finished being generated.
|
||||
*/
|
||||
private List<FieldAdder> fieldAdders = null;
|
||||
|
||||
|
||||
/**
|
||||
* As SpEL ast nodes are called to generate code for the main evaluation method
|
||||
* they can register to add code to a static initializer in the class. Any
|
||||
@@ -64,19 +64,19 @@ public class CodeFlow implements Opcodes {
|
||||
* has finished being generated.
|
||||
*/
|
||||
private List<ClinitAdder> clinitAdders = null;
|
||||
|
||||
|
||||
/**
|
||||
* Name of the class being generated. Typically used when generating code
|
||||
* that accesses freshly generated fields on the generated type.
|
||||
*/
|
||||
private String clazzName;
|
||||
|
||||
|
||||
/**
|
||||
* When code generation requires holding a value in a class level field, this
|
||||
* is used to track the next available field id (used as a name suffix).
|
||||
*/
|
||||
private int nextFieldId = 1;
|
||||
|
||||
|
||||
/**
|
||||
* When code generation requires an intermediate variable within a method,
|
||||
* this method records the next available variable (variable 0 is 'this').
|
||||
@@ -211,7 +211,7 @@ public class CodeFlow implements Opcodes {
|
||||
|
||||
/**
|
||||
* Create the JVM signature descriptor for a method. This consists of the descriptors
|
||||
* for the constructor parameters surrounded with parentheses, followed by the
|
||||
* for the method parameters surrounded with parentheses, followed by the
|
||||
* descriptor for the return type. Note the descriptors here are JVM descriptors,
|
||||
* unlike the other descriptor forms the compiler is using which do not include the
|
||||
* trailing semicolon.
|
||||
@@ -232,11 +232,12 @@ public class CodeFlow implements Opcodes {
|
||||
|
||||
/**
|
||||
* Create the JVM signature descriptor for a constructor. This consists of the
|
||||
* descriptors for the constructor parameters surrounded with parentheses. Note the
|
||||
* descriptors for the constructor parameters surrounded with parentheses, followed by
|
||||
* the descriptor for the return type, which is always "V". Note the
|
||||
* descriptors here are JVM descriptors, unlike the other descriptor forms the
|
||||
* compiler is using which do not include the trailing semicolon.
|
||||
* @param ctor the constructor
|
||||
* @return a String signature descriptor (e.g. "(ILjava/lang/String;)")
|
||||
* @return a String signature descriptor (e.g. "(ILjava/lang/String;)V")
|
||||
*/
|
||||
public static String createSignatureDescriptor(Constructor<?> ctor) {
|
||||
Class<?>[] params = ctor.getParameterTypes();
|
||||
@@ -657,7 +658,7 @@ public class CodeFlow implements Opcodes {
|
||||
}
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called after the main expression evaluation method has been generated, this
|
||||
* method will callback any registered FieldAdders or ClinitAdders to add any
|
||||
@@ -695,7 +696,7 @@ public class CodeFlow implements Opcodes {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a ClinitAdder which will add code to the static
|
||||
* Register a ClinitAdder which will add code to the static
|
||||
* initializer in the generated class to support the code
|
||||
* produced by an ast nodes primary generateCode() method.
|
||||
*/
|
||||
@@ -717,11 +718,11 @@ public class CodeFlow implements Opcodes {
|
||||
public String getClassname() {
|
||||
return clazzName;
|
||||
}
|
||||
|
||||
|
||||
public interface FieldAdder {
|
||||
public void generateField(ClassWriter cw, CodeFlow codeflow);
|
||||
}
|
||||
|
||||
|
||||
public interface ClinitAdder {
|
||||
public void generateCode(MethodVisitor mv, CodeFlow codeflow);
|
||||
}
|
||||
@@ -743,11 +744,11 @@ public class CodeFlow implements Opcodes {
|
||||
}
|
||||
else {
|
||||
mv.visitLdcInsn(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce appropriate bytecode to store a stack item in an array. The
|
||||
* Produce appropriate bytecode to store a stack item in an array. The
|
||||
* instruction to use varies depending on whether the type
|
||||
* is a primitive or reference type.
|
||||
* @param mv where to insert the bytecode
|
||||
@@ -781,7 +782,7 @@ public class CodeFlow implements Opcodes {
|
||||
public static int arrayCodeFor(String arraytype) {
|
||||
switch (arraytype.charAt(0)) {
|
||||
case 'I': return T_INT;
|
||||
case 'J': return T_LONG;
|
||||
case 'J': return T_LONG;
|
||||
case 'F': return T_FLOAT;
|
||||
case 'D': return T_DOUBLE;
|
||||
case 'B': return T_BYTE;
|
||||
@@ -805,9 +806,9 @@ public class CodeFlow implements Opcodes {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Produce the correct bytecode to build an array. The opcode to use and the
|
||||
* Produce the correct bytecode to build an array. The opcode to use and the
|
||||
* signature to pass along with the opcode can vary depending on the signature
|
||||
* of the array type.
|
||||
* @param mv the methodvisitor into which code should be inserted
|
||||
@@ -825,7 +826,8 @@ public class CodeFlow implements Opcodes {
|
||||
// is [[I then we want [I and not [I;
|
||||
if (CodeFlow.isReferenceTypeArray(arraytype)) {
|
||||
mv.visitTypeInsn(ANEWARRAY, arraytype+";");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
mv.visitTypeInsn(ANEWARRAY, arraytype);
|
||||
}
|
||||
}
|
||||
@@ -835,5 +837,4 @@ public class CodeFlow implements Opcodes {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user