Consistent bracket alignment
This commit is contained in:
@@ -219,47 +219,48 @@ public class CodeFlow implements Opcodes {
|
||||
* @return the JVM descriptor for the class
|
||||
*/
|
||||
public static String toJVMDescriptor(Class<?> clazz) {
|
||||
StringBuilder s= new StringBuilder();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (clazz.isArray()) {
|
||||
while (clazz.isArray()) {
|
||||
s.append("[");
|
||||
sb.append("[");
|
||||
clazz = clazz.getComponentType();
|
||||
}
|
||||
}
|
||||
if (clazz.isPrimitive()) {
|
||||
if (clazz == Void.TYPE) {
|
||||
s.append('V');
|
||||
sb.append('V');
|
||||
}
|
||||
else if (clazz == Integer.TYPE) {
|
||||
s.append('I');
|
||||
sb.append('I');
|
||||
}
|
||||
else if (clazz == Boolean.TYPE) {
|
||||
s.append('Z');
|
||||
sb.append('Z');
|
||||
}
|
||||
else if (clazz == Character.TYPE) {
|
||||
s.append('C');
|
||||
sb.append('C');
|
||||
}
|
||||
else if (clazz == Long.TYPE) {
|
||||
s.append('J');
|
||||
sb.append('J');
|
||||
}
|
||||
else if (clazz == Double.TYPE) {
|
||||
s.append('D');
|
||||
sb.append('D');
|
||||
}
|
||||
else if (clazz == Float.TYPE) {
|
||||
s.append('F');
|
||||
sb.append('F');
|
||||
}
|
||||
else if (clazz == Byte.TYPE) {
|
||||
s.append('B');
|
||||
sb.append('B');
|
||||
}
|
||||
else if (clazz == Short.TYPE) {
|
||||
s.append('S');
|
||||
sb.append('S');
|
||||
}
|
||||
} else {
|
||||
s.append("L");
|
||||
s.append(clazz.getName().replace('.', '/'));
|
||||
s.append(";");
|
||||
}
|
||||
return s.toString();
|
||||
else {
|
||||
sb.append("L");
|
||||
sb.append(clazz.getName().replace('.', '/'));
|
||||
sb.append(";");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -283,7 +283,8 @@ public class Indexer extends SpelNodeImpl {
|
||||
}
|
||||
if (member instanceof Field) {
|
||||
mv.visitFieldInsn(isStatic?GETSTATIC:GETFIELD,memberDeclaringClassSlashedDescriptor,member.getName(),CodeFlow.toJVMDescriptor(((Field) member).getType()));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
mv.visitMethodInsn(isStatic?INVOKESTATIC:INVOKEVIRTUAL, memberDeclaringClassSlashedDescriptor, member.getName(),CodeFlow.createSignatureDescriptor((Method)member),false);
|
||||
}
|
||||
}
|
||||
@@ -556,12 +557,12 @@ public class Indexer extends SpelNodeImpl {
|
||||
Member member = optimalAccessor.member;
|
||||
if (member instanceof Field) {
|
||||
Indexer.this.exitTypeDescriptor = CodeFlow.toDescriptor(((Field)member).getType());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Indexer.this.exitTypeDescriptor = CodeFlow.toDescriptor(((Method)member).getReturnType());
|
||||
}
|
||||
}
|
||||
TypedValue value = accessor.read(this.evaluationContext, this.targetObject, this.name);
|
||||
return value;
|
||||
return accessor.read(this.evaluationContext, this.targetObject, this.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -679,7 +680,7 @@ public class Indexer extends SpelNodeImpl {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS,
|
||||
this.collection.size(), this.index);
|
||||
}
|
||||
if(this.index >= this.maximumSize) {
|
||||
if (this.index >= this.maximumSize) {
|
||||
throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION);
|
||||
}
|
||||
if (this.collectionEntryDescriptor.getElementTypeDescriptor() == null) {
|
||||
|
||||
@@ -105,7 +105,8 @@ public class OpEQ extends Operator {
|
||||
else {
|
||||
throw new IllegalStateException("Unexpected descriptor "+leftDesc);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
getLeftOperand().generateCode(mv, codeflow);
|
||||
getRightOperand().generateCode(mv, codeflow);
|
||||
Label leftNotNull = new Label();
|
||||
|
||||
@@ -193,7 +193,8 @@ public class OpMinus extends Operator {
|
||||
default:
|
||||
throw new IllegalStateException("Unrecognized exit descriptor: '"+this.exitTypeDescriptor+"'");
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
switch (this.exitTypeDescriptor.charAt(0)) {
|
||||
case 'I':
|
||||
mv.visitInsn(INEG);
|
||||
|
||||
@@ -105,7 +105,8 @@ public class OpNE extends Operator {
|
||||
else {
|
||||
throw new IllegalStateException("Unexpected descriptor "+leftDesc);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
getLeftOperand().generateCode(mv, codeflow);
|
||||
getRightOperand().generateCode(mv, codeflow);
|
||||
mv.visitJumpInsn(IF_ACMPEQ, elseTarget);
|
||||
|
||||
@@ -66,7 +66,8 @@ public class OperatorInstanceof extends Operator {
|
||||
Class<?> rightClass = (Class<?>) rightValue;
|
||||
if (leftValue == null) {
|
||||
result = BooleanTypedValue.FALSE; // null is not an instanceof anything
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result = BooleanTypedValue.forValue(rightClass.isAssignableFrom(leftValue.getClass()));
|
||||
}
|
||||
this.type = rightClass;
|
||||
@@ -76,7 +77,7 @@ public class OperatorInstanceof extends Operator {
|
||||
|
||||
@Override
|
||||
public boolean isCompilable() {
|
||||
return this.exitTypeDescriptor != null && getLeftOperand().isCompilable();
|
||||
return (this.exitTypeDescriptor != null && getLeftOperand().isCompilable());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,4 +86,5 @@ public class OperatorInstanceof extends Operator {
|
||||
mv.visitTypeInsn(INSTANCEOF,Type.getInternalName(this.type));
|
||||
codeflow.pushDescriptor(getExitDescriptor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public class TypeReference extends SpelNodeImpl {
|
||||
|
||||
private transient Class<?> type;
|
||||
|
||||
|
||||
public TypeReference(int pos, SpelNodeImpl qualifiedId) {
|
||||
this(pos,qualifiedId,0);
|
||||
}
|
||||
@@ -50,7 +51,7 @@ public class TypeReference extends SpelNodeImpl {
|
||||
public TypedValue getValueInternal(ExpressionState state) throws EvaluationException {
|
||||
// TODO possible optimization here if we cache the discovered type reference, but can we do that?
|
||||
String typename = (String) this.children[0].getValueInternal(state).getValue();
|
||||
if (typename.indexOf(".") == -1 && Character.isLowerCase(typename.charAt(0))) {
|
||||
if (typename.indexOf('.') == -1 && Character.isLowerCase(typename.charAt(0))) {
|
||||
TypeCode tc = TypeCode.valueOf(typename.toUpperCase());
|
||||
if (tc != TypeCode.OBJECT) {
|
||||
// it is a primitive type
|
||||
@@ -69,10 +70,10 @@ public class TypeReference extends SpelNodeImpl {
|
||||
}
|
||||
|
||||
private Class<?> makeArrayIfNecessary(Class<?> clazz) {
|
||||
if (this.dimensions!=0) {
|
||||
for (int i=0;i<this.dimensions;i++) {
|
||||
Object o = Array.newInstance(clazz, 0);
|
||||
clazz = o.getClass();
|
||||
if (this.dimensions != 0) {
|
||||
for (int i = 0; i < this.dimensions; i++) {
|
||||
Object array = Array.newInstance(clazz, 0);
|
||||
clazz = array.getClass();
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
@@ -92,7 +93,7 @@ public class TypeReference extends SpelNodeImpl {
|
||||
|
||||
@Override
|
||||
public boolean isCompilable() {
|
||||
return this.exitTypeDescriptor != null;
|
||||
return (this.exitTypeDescriptor != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,21 +102,29 @@ public class TypeReference extends SpelNodeImpl {
|
||||
if (type.isPrimitive()) {
|
||||
if (type == Integer.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Integer", "TYPE", "Ljava/lang/Class;");
|
||||
} else if (type == Boolean.TYPE) {
|
||||
}
|
||||
else if (type == Boolean.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
|
||||
} else if (type == Byte.TYPE) {
|
||||
}
|
||||
else if (type == Byte.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Byte", "TYPE", "Ljava/lang/Class;");
|
||||
} else if (type == Short.TYPE) {
|
||||
}
|
||||
else if (type == Short.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Short", "TYPE", "Ljava/lang/Class;");
|
||||
} else if (type == Double.TYPE) {
|
||||
}
|
||||
else if (type == Double.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Double", "TYPE", "Ljava/lang/Class;");
|
||||
} else if (type == Character.TYPE) {
|
||||
}
|
||||
else if (type == Character.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Character", "TYPE", "Ljava/lang/Class;");
|
||||
} else if (type == Float.TYPE) {
|
||||
}
|
||||
else if (type == Float.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Float", "TYPE", "Ljava/lang/Class;");
|
||||
} else if (type == Long.TYPE) {
|
||||
}
|
||||
else if (type == Long.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Long", "TYPE", "Ljava/lang/Class;");
|
||||
} else if (type == Boolean.TYPE) {
|
||||
}
|
||||
else if (type == Boolean.TYPE) {
|
||||
mv.visitFieldInsn(GETSTATIC, "java/lang/Boolean", "TYPE", "Ljava/lang/Class;");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,8 @@ public class VariableReference extends SpelNodeImpl {
|
||||
public void generateCode(MethodVisitor mv, CodeFlow codeflow) {
|
||||
if (this.name.equals(ROOT)) {
|
||||
mv.visitVarInsn(ALOAD,1);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(name);
|
||||
mv.visitMethodInsn(INVOKEINTERFACE, "org/springframework/expression/EvaluationContext", "lookupVariable", "(Ljava/lang/String;)Ljava/lang/Object;",true);
|
||||
|
||||
@@ -357,13 +357,15 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
SpelNodeImpl expr = null;
|
||||
if (peekToken(TokenKind.DOT,TokenKind.SAFE_NAVI)) {
|
||||
expr = eatDottedNode();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
expr = maybeEatNonDottedNode();
|
||||
}
|
||||
|
||||
if (expr==null) {
|
||||
return false;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
push(expr);
|
||||
return true;
|
||||
}
|
||||
@@ -613,7 +615,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
List<SpelNodeImpl> listElements = new ArrayList<SpelNodeImpl>();
|
||||
do {
|
||||
listElements.add(eatExpression());
|
||||
} while (peekToken(TokenKind.COMMA,true));
|
||||
}
|
||||
while (peekToken(TokenKind.COMMA,true));
|
||||
|
||||
closingCurly = eatToken(TokenKind.RCURLY);
|
||||
expr = new InlineList(toPos(t.startpos,closingCurly.endpos),listElements.toArray(new SpelNodeImpl[listElements.size()]));
|
||||
@@ -640,7 +643,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
}
|
||||
nextToken();
|
||||
SpelNodeImpl expr = eatExpression();
|
||||
if(expr == null) {
|
||||
if (expr == null) {
|
||||
raiseInternalException(toPos(t), SpelMessage.MISSING_SELECTION_EXPRESSION);
|
||||
}
|
||||
eatToken(TokenKind.RSQUARE);
|
||||
@@ -665,13 +668,13 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
Token node = peekToken();
|
||||
while (isValidQualifiedId(node)) {
|
||||
nextToken();
|
||||
if(node.kind != TokenKind.DOT) {
|
||||
if (node.kind != TokenKind.DOT) {
|
||||
qualifiedIdPieces.add(new Identifier(node.stringValue(),toPos(node)));
|
||||
}
|
||||
node = peekToken();
|
||||
}
|
||||
if(qualifiedIdPieces.isEmpty()) {
|
||||
if(node == null) {
|
||||
if (qualifiedIdPieces.isEmpty()) {
|
||||
if (node == null) {
|
||||
raiseInternalException( this.expressionString.length(), SpelMessage.OOD);
|
||||
}
|
||||
raiseInternalException(node.startpos, SpelMessage.NOT_EXPECTED_TOKEN,
|
||||
@@ -682,10 +685,10 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
}
|
||||
|
||||
private boolean isValidQualifiedId(Token node) {
|
||||
if(node == null || node.kind == TokenKind.LITERAL_STRING) {
|
||||
if (node == null || node.kind == TokenKind.LITERAL_STRING) {
|
||||
return false;
|
||||
}
|
||||
if(node.kind == TokenKind.DOT || node.kind == TokenKind.IDENTIFIER) {
|
||||
if (node.kind == TokenKind.DOT || node.kind == TokenKind.IDENTIFIER) {
|
||||
return true;
|
||||
}
|
||||
String value = node.stringValue();
|
||||
@@ -708,9 +711,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
// TODO what is the end position for a method reference? the name or the last arg?
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
//constructor
|
||||
@@ -825,7 +826,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
// | GREATER_THAN_OR_EQUAL | INSTANCEOF | BETWEEN | MATCHES
|
||||
private Token maybeEatRelationalOperator() {
|
||||
Token t = peekToken();
|
||||
if (t==null) {
|
||||
if (t == null) {
|
||||
return null;
|
||||
}
|
||||
if (t.isNumericRelationalOperator()) {
|
||||
@@ -848,10 +849,10 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
|
||||
private Token eatToken(TokenKind expectedKind) {
|
||||
Token t = nextToken();
|
||||
if (t==null) {
|
||||
if (t == null) {
|
||||
raiseInternalException( this.expressionString.length(), SpelMessage.OOD);
|
||||
}
|
||||
if (t.kind!=expectedKind) {
|
||||
if (t.kind != expectedKind) {
|
||||
raiseInternalException(t.startpos,SpelMessage.NOT_EXPECTED_TOKEN, expectedKind.toString().toLowerCase(),t.getKind().toString().toLowerCase());
|
||||
}
|
||||
return t;
|
||||
@@ -866,7 +867,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
return false;
|
||||
}
|
||||
Token t = peekToken();
|
||||
if (t.kind==desiredTokenKind) {
|
||||
if (t.kind == desiredTokenKind) {
|
||||
if (consumeIfMatched) {
|
||||
this.tokenStreamPointer++;
|
||||
}
|
||||
@@ -876,7 +877,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
if (desiredTokenKind == TokenKind.IDENTIFIER) {
|
||||
// might be one of the textual forms of the operators (e.g. NE for != ) - in which case we can treat it as an identifier
|
||||
// The list is represented here: Tokenizer.alternativeOperatorNames and those ones are in order in the TokenKind enum
|
||||
if (t.kind.ordinal()>=TokenKind.DIV.ordinal() && t.kind.ordinal()<=TokenKind.NOT.ordinal() && t.data!=null) {
|
||||
if (t.kind.ordinal() >= TokenKind.DIV.ordinal() && t.kind.ordinal() <= TokenKind.NOT.ordinal() && t.data != null) {
|
||||
// if t.data were null, we'd know it wasn't the textual form, it was the symbol form
|
||||
return true;
|
||||
}
|
||||
@@ -889,7 +890,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
return false;
|
||||
}
|
||||
Token t = peekToken();
|
||||
return t.kind == possible1 || t.kind == possible2;
|
||||
return (t.kind == possible1 || t.kind == possible2);
|
||||
}
|
||||
|
||||
private boolean peekToken(TokenKind possible1,TokenKind possible2, TokenKind possible3) {
|
||||
@@ -965,14 +966,14 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress the start and end of a token into a single int
|
||||
* Compress the start and end of a token into a single int.
|
||||
*/
|
||||
private int toPos(Token t) {
|
||||
return (t.startpos<<16)+t.endpos;
|
||||
return (t.startpos<<16) + t.endpos;
|
||||
}
|
||||
|
||||
private int toPos(int start,int end) {
|
||||
return (start<<16)+end;
|
||||
return (start<<16) + end;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user