Skip to content

Commit

Permalink
SpelNodeImpl manages start/end position in separate integer values
Browse files Browse the repository at this point in the history
Fixes gh-22157
  • Loading branch information
jhoeller committed Jan 28, 2019
1 parent 5aed117 commit 7a77e83
Show file tree
Hide file tree
Showing 51 changed files with 280 additions and 298 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -31,8 +31,8 @@
*/
public class Assign extends SpelNodeImpl {

public Assign(int pos, SpelNodeImpl... operands) {
super(pos, operands);
public Assign(int startPos, int endPos, SpelNodeImpl... operands) {
super(startPos, endPos, operands);
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -37,8 +37,8 @@ public class BeanReference extends SpelNodeImpl {
private final String beanName;


public BeanReference(int pos, String beanName) {
super(pos);
public BeanReference(int startPos, int endPos, String beanName) {
super(startPos, endPos);
this.beanName = beanName;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -31,8 +31,8 @@ public class BooleanLiteral extends Literal {
private final BooleanTypedValue value;


public BooleanLiteral(String payload, int pos, boolean value) {
super(payload, pos);
public BooleanLiteral(String payload, int startPos, int endPos, boolean value) {
super(payload, startPos, endPos);
this.value = BooleanTypedValue.forValue(value);
this.exitTypeDescriptor = "Z";
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -33,8 +33,8 @@
*/
public class CompoundExpression extends SpelNodeImpl {

public CompoundExpression(int pos, SpelNodeImpl... expressionComponents) {
super(pos, expressionComponents);
public CompoundExpression(int startPos, int endPos, SpelNodeImpl... expressionComponents) {
super(startPos, endPos, expressionComponents);
if (expressionComponents.length < 2) {
throw new IllegalStateException("Do not build compound expressions with less than two entries: " +
expressionComponents.length);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -72,17 +72,17 @@ public class ConstructorReference extends SpelNodeImpl {
* Create a constructor reference. The first argument is the type, the rest are the parameters to the constructor
* call
*/
public ConstructorReference(int pos, SpelNodeImpl... arguments) {
super(pos, arguments);
public ConstructorReference(int startPos, int endPos, SpelNodeImpl... arguments) {
super(startPos, endPos, arguments);
this.isArrayConstructor = false;
}

/**
* Create a constructor reference. The first argument is the type, the rest are the parameters to the constructor
* call
*/
public ConstructorReference(int pos, SpelNodeImpl[] dimensions, SpelNodeImpl... arguments) {
super(pos, arguments);
public ConstructorReference(int startPos, int endPos, SpelNodeImpl[] dimensions, SpelNodeImpl... arguments) {
super(startPos, endPos, arguments);
this.isArrayConstructor = true;
this.dimensions = dimensions;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -36,8 +36,8 @@
*/
public class Elvis extends SpelNodeImpl {

public Elvis(int pos, SpelNodeImpl... args) {
super(pos, args);
public Elvis(int startPos, int endPos, SpelNodeImpl... args) {
super(startPos, endPos, args);
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -32,8 +32,8 @@ public class FloatLiteral extends Literal {
private final TypedValue value;


public FloatLiteral(String payload, int pos, float value) {
super(payload, pos);
public FloatLiteral(String payload, int startPos, int endPos, float value) {
super(payload, startPos, endPos);
this.value = new TypedValue(value);
this.exitTypeDescriptor = "F";
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -57,8 +57,8 @@ public class FunctionReference extends SpelNodeImpl {
private volatile Method method;


public FunctionReference(String functionName, int pos, SpelNodeImpl... arguments) {
super(pos, arguments);
public FunctionReference(String functionName, int startPos, int endPos, SpelNodeImpl... arguments) {
super(startPos, endPos, arguments);
this.name = functionName;
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -31,8 +31,8 @@ public class Identifier extends SpelNodeImpl {
private final TypedValue id;


public Identifier(String payload, int pos) {
super(pos);
public Identifier(String payload, int startPos, int endPos) {
super(startPos, endPos);
this.id = new TypedValue(payload);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -90,8 +90,8 @@ private enum IndexedType {ARRAY, LIST, MAP, STRING, OBJECT}
private IndexedType indexedType;


public Indexer(int pos, SpelNodeImpl expr) {
super(pos, expr);
public Indexer(int startPos, int endPos, SpelNodeImpl expr) {
super(startPos, endPos, expr);
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -42,8 +42,8 @@ public class InlineList extends SpelNodeImpl {
private TypedValue constant; // TODO must be immutable list


public InlineList(int pos, SpelNodeImpl... args) {
super(pos, args);
public InlineList(int startPos, int endPos, SpelNodeImpl... args) {
super(startPos, endPos, args);
checkIfConstant();
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -40,14 +40,14 @@ public class InlineMap extends SpelNodeImpl {
private TypedValue constant;


public InlineMap(int pos, SpelNodeImpl... args) {
super(pos, args);
public InlineMap(int startPos, int endPos, SpelNodeImpl... args) {
super(startPos, endPos, args);
checkIfConstant();
}


/**
* If all the components of the list are constants, or lists/maps that themselves
* If all the components of the map are constants, or lists/maps that themselves
* contain constants, then a constant list can be built to represent this node.
* This will speed up later getValue calls and reduce the amount of garbage created.
*/
Expand All @@ -70,14 +70,14 @@ else if (child instanceof InlineMap) {
break;
}
}
else if (!((c%2)==0 && (child instanceof PropertyOrFieldReference))) {
else if (!(c % 2 == 0 && child instanceof PropertyOrFieldReference)) {
isConstant = false;
break;
}
}
}
if (isConstant) {
Map<Object,Object> constantMap = new LinkedHashMap<>();
Map<Object, Object> constantMap = new LinkedHashMap<>();
int childCount = getChildCount();
for (int c = 0; c < childCount; c++) {
SpelNode keyChild = getChild(c++);
Expand Down Expand Up @@ -159,9 +159,9 @@ public boolean isConstant() {

@SuppressWarnings("unchecked")
@Nullable
public Map<Object,Object> getConstantValue() {
public Map<Object, Object> getConstantValue() {
Assert.state(this.constant != null, "No constant");
return (Map<Object,Object>) this.constant.getValue();
return (Map<Object, Object>) this.constant.getValue();
}

}
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -32,8 +32,8 @@ public class IntLiteral extends Literal {
private final TypedValue value;


public IntLiteral(String payload, int pos, int value) {
super(payload, pos);
public IntLiteral(String payload, int startPos, int endPos, int value) {
super(payload, startPos, endPos);
this.value = new TypedValue(value);
this.exitTypeDescriptor = "I";
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -36,8 +36,8 @@ public abstract class Literal extends SpelNodeImpl {
private final String originalValue;


public Literal(@Nullable String originalValue, int pos) {
super(pos);
public Literal(@Nullable String originalValue, int startPos, int endPos) {
super(startPos, endPos);
this.originalValue = originalValue;
}

Expand Down Expand Up @@ -74,39 +74,39 @@ public String toStringAST() {
* @param radix the base of number
* @return a subtype of Literal that can represent it
*/
public static Literal getIntLiteral(String numberToken, int pos, int radix) {
public static Literal getIntLiteral(String numberToken, int startPos, int endPos, int radix) {
try {
int value = Integer.parseInt(numberToken, radix);
return new IntLiteral(numberToken, pos, value);
return new IntLiteral(numberToken, startPos, endPos, value);
}
catch (NumberFormatException ex) {
throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_AN_INTEGER, numberToken));
throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_AN_INTEGER, numberToken));
}
}

public static Literal getLongLiteral(String numberToken, int pos, int radix) {
public static Literal getLongLiteral(String numberToken, int startPos, int endPos, int radix) {
try {
long value = Long.parseLong(numberToken, radix);
return new LongLiteral(numberToken, pos, value);
return new LongLiteral(numberToken, startPos, endPos, value);
}
catch (NumberFormatException ex) {
throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_LONG, numberToken));
throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_LONG, numberToken));
}
}

public static Literal getRealLiteral(String numberToken, int pos, boolean isFloat) {
public static Literal getRealLiteral(String numberToken, int startPos, int endPos, boolean isFloat) {
try {
if (isFloat) {
float value = Float.parseFloat(numberToken);
return new FloatLiteral(numberToken, pos, value);
return new FloatLiteral(numberToken, startPos, endPos, value);
}
else {
double value = Double.parseDouble(numberToken);
return new RealLiteral(numberToken, pos, value);
return new RealLiteral(numberToken, startPos, endPos, value);
}
}
catch (NumberFormatException ex) {
throw new InternalParseException(new SpelParseException(pos>>16, ex, SpelMessage.NOT_A_REAL, numberToken));
throw new InternalParseException(new SpelParseException(startPos, ex, SpelMessage.NOT_A_REAL, numberToken));
}
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -31,8 +31,8 @@ public class LongLiteral extends Literal {
private final TypedValue value;


public LongLiteral(String payload, int pos, long value) {
super(payload, pos);
public LongLiteral(String payload, int startPos, int endPos, long value) {
super(payload, startPos, endPos);
this.value = new TypedValue(value);
this.exitTypeDescriptor = "J";
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -64,8 +64,8 @@ public class MethodReference extends SpelNodeImpl {
private volatile CachedMethodExecutor cachedExecutor;


public MethodReference(boolean nullSafe, String methodName, int pos, SpelNodeImpl... arguments) {
super(pos, arguments);
public MethodReference(boolean nullSafe, String methodName, int startPos, int endPos, SpelNodeImpl... arguments) {
super(startPos, endPos, arguments);
this.name = methodName;
this.nullSafe = nullSafe;
}
Expand Down

0 comments on commit 7a77e83

Please sign in to comment.