Use final.
diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
index f23b427..2ecb270 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
@@ -94,7 +94,7 @@
*
* @param astrict whether this arithmetic is strict or lenient
*/
- public JexlArithmetic(boolean astrict) {
+ public JexlArithmetic(final boolean astrict) {
this(astrict, null, Integer.MIN_VALUE);
}
@@ -106,14 +106,14 @@
* @param bigdContext the math context instance to use for +,-,/,*,% operations on big decimals.
* @param bigdScale the scale used for big decimals.
*/
- public JexlArithmetic(boolean astrict, MathContext bigdContext, int bigdScale) {
+ public JexlArithmetic(final boolean astrict, final MathContext bigdContext, final int bigdScale) {
this.strict = astrict;
this.mathContext = bigdContext == null ? MathContext.DECIMAL128 : bigdContext;
this.mathScale = bigdScale == Integer.MIN_VALUE ? BIGD_SCALE : bigdScale;
Constructor<? extends JexlArithmetic> actor = null;
try {
actor = getClass().getConstructor(boolean.class, MathContext.class, int.class);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
// ignore
}
this.ctor = actor;
@@ -126,9 +126,9 @@
* @param options the {@link JexlEngine.Options} to use
* @return an arithmetic with those options set
*/
- public JexlArithmetic options(JexlOptions options) {
+ public JexlArithmetic options(final JexlOptions options) {
if (options != null) {
- boolean ostrict = options.isStrictArithmetic();
+ final boolean ostrict = options.isStrictArithmetic();
MathContext bigdContext = options.getMathContext();
if (bigdContext == null) {
bigdContext = getMathContext();
@@ -155,7 +155,7 @@
* @deprecated 3.2
*/
@Deprecated
- public JexlArithmetic options(JexlEngine.Options options) {
+ public JexlArithmetic options(final JexlEngine.Options options) {
if (options != null) {
Boolean ostrict = options.isStrictArithmetic();
if (ostrict == null) {
@@ -186,7 +186,7 @@
* @return a new arithmetic instance or this
* @since 3.1
*/
- public JexlArithmetic options(JexlContext context) {
+ public JexlArithmetic options(final JexlContext context) {
if (context instanceof JexlContext.OptionsHandle) {
return options(((JexlContext.OptionsHandle) context).getEngineOptions());
}
@@ -207,7 +207,7 @@
* @return default is a new JexlArithmetic instance
* @since 3.1
*/
- protected JexlArithmetic createWithOptions(boolean astrict, MathContext bigdContext, int bigdScale) {
+ protected JexlArithmetic createWithOptions(final boolean astrict, final MathContext bigdContext, final int bigdScale) {
if (ctor != null) {
try {
return ctor.newInstance(astrict, bigdContext, bigdScale);
@@ -278,7 +278,7 @@
* @param size the number of elements in the array
* @return the array builder
*/
- public ArrayBuilder arrayBuilder(int size) {
+ public ArrayBuilder arrayBuilder(final int size) {
return new org.apache.commons.jexl3.internal.ArrayBuilder(size);
}
@@ -308,7 +308,7 @@
* @param size the number of elements in the set
* @return the array builder
*/
- public SetBuilder setBuilder(int size) {
+ public SetBuilder setBuilder(final int size) {
return new org.apache.commons.jexl3.internal.SetBuilder(size);
}
@@ -339,7 +339,7 @@
* @param size the number of elements in the map
* @return the map builder
*/
- public MapBuilder mapBuilder(int size) {
+ public MapBuilder mapBuilder(final int size) {
return new org.apache.commons.jexl3.internal.MapBuilder(size);
}
@@ -352,7 +352,7 @@
* @return the range as an iterable
* @throws ArithmeticException as an option if creation fails
*/
- public Iterable<?> createRange(Object from, Object to) throws ArithmeticException {
+ public Iterable<?> createRange(final Object from, final Object to) throws ArithmeticException {
final long lfrom = toLong(from);
final long lto = toLong(to);
if ((lfrom >= Integer.MIN_VALUE && lfrom <= Integer.MAX_VALUE)
@@ -398,7 +398,7 @@
* @return the rounded big decimal
*/
protected BigDecimal roundBigDecimal(final BigDecimal number) {
- int mscale = getMathScale();
+ final int mscale = getMathScale();
if (mscale >= 0) {
return number.setScale(mscale, getMathContext().getRoundingMode());
} else {
@@ -445,7 +445,7 @@
* @param val the object to be tested
* @return true if it is, false otherwise.
*/
- protected boolean isFloatingPointNumber(Object val) {
+ protected boolean isFloatingPointNumber(final Object val) {
if (val instanceof Float || val instanceof Double) {
return true;
}
@@ -493,7 +493,7 @@
* @param original the original number.
* @return a value of the smallest type the original number will fit into.
*/
- public Number narrow(Number original) {
+ public Number narrow(final Number original) {
return narrowNumber(original, null);
}
@@ -504,7 +504,7 @@
* @param source the orginal source class
* @return true if attempt to narrow source to target is accepted
*/
- protected boolean narrowAccept(Class<?> narrow, Class<?> source) {
+ protected boolean narrowAccept(final Class<?> narrow, final Class<?> source) {
return narrow == null || narrow.equals(source);
}
@@ -515,20 +515,20 @@
* @param narrow the attempted target class
* @return the narrowed number or the source if no narrowing was possible
*/
- public Number narrowNumber(Number original, Class<?> narrow) {
+ public Number narrowNumber(final Number original, final Class<?> narrow) {
if (original == null) {
return null;
}
Number result = original;
if (original instanceof BigDecimal) {
- BigDecimal bigd = (BigDecimal) original;
+ final BigDecimal bigd = (BigDecimal) original;
// if it's bigger than a double it can't be narrowed
if (bigd.compareTo(BIGD_DOUBLE_MAX_VALUE) > 0
|| bigd.compareTo(BIGD_DOUBLE_MIN_VALUE) < 0) {
return original;
} else {
try {
- long l = bigd.longValueExact();
+ final long l = bigd.longValueExact();
// coerce to int when possible (int being so often used in method parms)
if (narrowAccept(narrow, Integer.class)
&& l <= Integer.MAX_VALUE
@@ -537,13 +537,13 @@
} else if (narrowAccept(narrow, Long.class)) {
return l;
}
- } catch (ArithmeticException xa) {
+ } catch (final ArithmeticException xa) {
// ignore, no exact value possible
}
}
}
if (original instanceof Double || original instanceof Float) {
- double value = original.doubleValue();
+ final double value = original.doubleValue();
if (narrowAccept(narrow, Float.class)
&& value <= Float.MAX_VALUE
&& value >= Float.MIN_VALUE) {
@@ -552,14 +552,14 @@
// else it fits in a double only
} else {
if (original instanceof BigInteger) {
- BigInteger bigi = (BigInteger) original;
+ final BigInteger bigi = (BigInteger) original;
// if it's bigger than a Long it can't be narrowed
if (bigi.compareTo(BIGI_LONG_MAX_VALUE) > 0
|| bigi.compareTo(BIGI_LONG_MIN_VALUE) < 0) {
return original;
}
}
- long value = original.longValue();
+ final long value = original.longValue();
if (narrowAccept(narrow, Byte.class)
&& value <= Byte.MAX_VALUE
&& value >= Byte.MIN_VALUE) {
@@ -593,13 +593,13 @@
* @param bigi the BigInteger to narrow
* @return an Integer or Long if narrowing is possible, the original BigInteger otherwise
*/
- protected Number narrowBigInteger(Object lhs, Object rhs, BigInteger bigi) {
+ protected Number narrowBigInteger(final Object lhs, final Object rhs, final BigInteger bigi) {
//coerce to long if possible
if (!(lhs instanceof BigInteger || rhs instanceof BigInteger)
&& bigi.compareTo(BIGI_LONG_MAX_VALUE) <= 0
&& bigi.compareTo(BIGI_LONG_MIN_VALUE) >= 0) {
// coerce to int if possible
- long l = bigi.longValue();
+ final long l = bigi.longValue();
// coerce to int when possible (int being so often used in method parms)
if (!(lhs instanceof Long || rhs instanceof Long)
&& l <= Integer.MAX_VALUE
@@ -620,17 +620,17 @@
* @param bigd the BigDecimal to narrow
* @return an Integer or Long if narrowing is possible, the original BigInteger otherwise
*/
- protected Number narrowBigDecimal(Object lhs, Object rhs, BigDecimal bigd) {
+ protected Number narrowBigDecimal(final Object lhs, final Object rhs, final BigDecimal bigd) {
if (isNumberable(lhs) || isNumberable(rhs)) {
try {
- long l = bigd.longValueExact();
+ final long l = bigd.longValueExact();
// coerce to int when possible (int being so often used in method parms)
if (l <= Integer.MAX_VALUE && l >= Integer.MIN_VALUE) {
return (int) l;
} else {
return l;
}
- } catch (ArithmeticException xa) {
+ } catch (final ArithmeticException xa) {
// ignore, no exact value possible
}
}
@@ -644,14 +644,14 @@
* @return true if some arguments were narrowed and args array is modified,
* false if no narrowing occurred and args array has not been modified
*/
- public boolean narrowArguments(Object[] args) {
+ public boolean narrowArguments(final Object[] args) {
boolean narrowed = false;
if (args != null) {
for (int a = 0; a < args.length; ++a) {
- Object arg = args[a];
+ final Object arg = args[a];
if (arg instanceof Number) {
- Number narg = (Number) arg;
- Number narrow = narrow(narg);
+ final Number narg = (Number) arg;
+ final Number narrow = narrow(narg);
if (!narg.equals(narrow)) {
args[a] = narrow;
narrowed = true;
@@ -670,7 +670,7 @@
* @param r the long to narrow
* @return an Integer if narrowing is possible, the original Long otherwise
*/
- protected Number narrowLong(Object lhs, Object rhs, long r) {
+ protected Number narrowLong(final Object lhs, final Object rhs, final long r) {
if (!(lhs instanceof Long || rhs instanceof Long) && (int) r == r) {
return (int) r;
} else {
@@ -684,7 +684,7 @@
* @param value argument
* @return true if argument can be represented by a long
*/
- protected Number asLongNumber(Object value) {
+ protected Number asLongNumber(final Object value) {
return value instanceof Long
|| value instanceof Integer
|| value instanceof Short
@@ -704,22 +704,22 @@
* @param right right argument
* @return left + right.
*/
- public Object add(Object left, Object right) {
+ public Object add(final Object left, final Object right) {
if (left == null && right == null) {
return controlNullNullOperands();
}
- boolean strconcat = strict
+ final boolean strconcat = strict
? left instanceof String || right instanceof String
: left instanceof String && right instanceof String;
if (!strconcat) {
try {
// if both (non null) args fit as long
- Number ln = asLongNumber(left);
- Number rn = asLongNumber(right);
+ final Number ln = asLongNumber(left);
+ final Number rn = asLongNumber(right);
if (ln != null && rn != null) {
- long x = ln.longValue();
- long y = rn.longValue();
- long result = x + y;
+ final long x = ln.longValue();
+ final long y = rn.longValue();
+ final long result = x + y;
// detect overflow, see java8 Math.addExact
if (((x ^ result) & (y ^ result)) < 0) {
return BigInteger.valueOf(x).add(BigInteger.valueOf(y));
@@ -728,23 +728,23 @@
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
- BigDecimal l = toBigDecimal(left);
- BigDecimal r = toBigDecimal(right);
- BigDecimal result = l.add(r, getMathContext());
+ final BigDecimal l = toBigDecimal(left);
+ final BigDecimal r = toBigDecimal(right);
+ final BigDecimal result = l.add(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
- double l = toDouble(left);
- double r = toDouble(right);
+ final double l = toDouble(left);
+ final double r = toDouble(right);
return l + r;
}
// otherwise treat as (big) integers
- BigInteger l = toBigInteger(left);
- BigInteger r = toBigInteger(right);
- BigInteger result = l.add(r);
+ final BigInteger l = toBigInteger(left);
+ final BigInteger r = toBigInteger(right);
+ final BigInteger result = l.add(r);
return narrowBigInteger(left, right, result);
- } catch (java.lang.NumberFormatException nfe) {
+ } catch (final java.lang.NumberFormatException nfe) {
if (left == null || right == null) {
controlNullOperand();
}
@@ -761,48 +761,48 @@
* @return left / right
* @throws ArithmeticException if right == 0
*/
- public Object divide(Object left, Object right) {
+ public Object divide(final Object left, final Object right) {
if (left == null && right == null) {
return controlNullNullOperands();
}
// if both (non null) args fit as long
- Number ln = asLongNumber(left);
- Number rn = asLongNumber(right);
+ final Number ln = asLongNumber(left);
+ final Number rn = asLongNumber(right);
if (ln != null && rn != null) {
- long x = ln.longValue();
- long y = rn.longValue();
+ final long x = ln.longValue();
+ final long y = rn.longValue();
if (y == 0L) {
throw new ArithmeticException("/");
}
- long result = x / y;
+ final long result = x / y;
return narrowLong(left, right, result);
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
- BigDecimal l = toBigDecimal(left);
- BigDecimal r = toBigDecimal(right);
+ final BigDecimal l = toBigDecimal(left);
+ final BigDecimal r = toBigDecimal(right);
if (BigDecimal.ZERO.equals(r)) {
throw new ArithmeticException("/");
}
- BigDecimal result = l.divide(r, getMathContext());
+ final BigDecimal result = l.divide(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
- double l = toDouble(left);
- double r = toDouble(right);
+ final double l = toDouble(left);
+ final double r = toDouble(right);
if (r == 0.0) {
throw new ArithmeticException("/");
}
return l / r;
}
// otherwise treat as integers
- BigInteger l = toBigInteger(left);
- BigInteger r = toBigInteger(right);
+ final BigInteger l = toBigInteger(left);
+ final BigInteger r = toBigInteger(right);
if (BigInteger.ZERO.equals(r)) {
throw new ArithmeticException("/");
}
- BigInteger result = l.divide(r);
+ final BigInteger result = l.divide(r);
return narrowBigInteger(left, right, result);
}
@@ -814,48 +814,48 @@
* @return left % right
* @throws ArithmeticException if right == 0.0
*/
- public Object mod(Object left, Object right) {
+ public Object mod(final Object left, final Object right) {
if (left == null && right == null) {
return controlNullNullOperands();
}
// if both (non null) args fit as long
- Number ln = asLongNumber(left);
- Number rn = asLongNumber(right);
+ final Number ln = asLongNumber(left);
+ final Number rn = asLongNumber(right);
if (ln != null && rn != null) {
- long x = ln.longValue();
- long y = rn.longValue();
+ final long x = ln.longValue();
+ final long y = rn.longValue();
if (y == 0L) {
throw new ArithmeticException("%");
}
- long result = x % y;
+ final long result = x % y;
return narrowLong(left, right, result);
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
- BigDecimal l = toBigDecimal(left);
- BigDecimal r = toBigDecimal(right);
+ final BigDecimal l = toBigDecimal(left);
+ final BigDecimal r = toBigDecimal(right);
if (BigDecimal.ZERO.equals(r)) {
throw new ArithmeticException("%");
}
- BigDecimal remainder = l.remainder(r, getMathContext());
+ final BigDecimal remainder = l.remainder(r, getMathContext());
return narrowBigDecimal(left, right, remainder);
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
- double l = toDouble(left);
- double r = toDouble(right);
+ final double l = toDouble(left);
+ final double r = toDouble(right);
if (r == 0.0) {
throw new ArithmeticException("%");
}
return l % r;
}
// otherwise treat as integers
- BigInteger l = toBigInteger(left);
- BigInteger r = toBigInteger(right);
+ final BigInteger l = toBigInteger(left);
+ final BigInteger r = toBigInteger(right);
if (BigInteger.ZERO.equals(r)) {
throw new ArithmeticException("%");
}
- BigInteger result = l.mod(r);
+ final BigInteger result = l.mod(r);
return narrowBigInteger(left, right, result);
}
@@ -868,9 +868,9 @@
* @return true if product fits a long, false if it overflows
*/
@SuppressWarnings("MagicNumber")
- private static boolean isMultiplyExact(long x, long y, long r) {
- long ax = Math.abs(x);
- long ay = Math.abs(y);
+ private static boolean isMultiplyExact(final long x, final long y, final long r) {
+ final long ax = Math.abs(x);
+ final long ay = Math.abs(y);
return !(((ax | ay) >>> (Integer.SIZE - 1) != 0)
&& (((y != 0) && (r / y != x))
|| (x == Long.MIN_VALUE && y == -1)));
@@ -883,17 +883,17 @@
* @param right right argument
* @return left * right.
*/
- public Object multiply(Object left, Object right) {
+ public Object multiply(final Object left, final Object right) {
if (left == null && right == null) {
return controlNullNullOperands();
}
// if both (non null) args fit as int
- Number ln = asLongNumber(left);
- Number rn = asLongNumber(right);
+ final Number ln = asLongNumber(left);
+ final Number rn = asLongNumber(right);
if (ln != null && rn != null) {
- long x = ln.longValue();
- long y = rn.longValue();
- long result = x * y;
+ final long x = ln.longValue();
+ final long y = rn.longValue();
+ final long result = x * y;
// detect overflow
if (!isMultiplyExact(x, y, result)) {
return BigInteger.valueOf(x).multiply(BigInteger.valueOf(y));
@@ -902,21 +902,21 @@
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
- BigDecimal l = toBigDecimal(left);
- BigDecimal r = toBigDecimal(right);
- BigDecimal result = l.multiply(r, getMathContext());
+ final BigDecimal l = toBigDecimal(left);
+ final BigDecimal r = toBigDecimal(right);
+ final BigDecimal result = l.multiply(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
- double l = toDouble(left);
- double r = toDouble(right);
+ final double l = toDouble(left);
+ final double r = toDouble(right);
return l * r;
}
// otherwise treat as integers
- BigInteger l = toBigInteger(left);
- BigInteger r = toBigInteger(right);
- BigInteger result = l.multiply(r);
+ final BigInteger l = toBigInteger(left);
+ final BigInteger r = toBigInteger(right);
+ final BigInteger result = l.multiply(r);
return narrowBigInteger(left, right, result);
}
@@ -927,17 +927,17 @@
* @param right right argument
* @return left - right.
*/
- public Object subtract(Object left, Object right) {
+ public Object subtract(final Object left, final Object right) {
if (left == null && right == null) {
return controlNullNullOperands();
}
// if both (non null) args fit as long
- Number ln = asLongNumber(left);
- Number rn = asLongNumber(right);
+ final Number ln = asLongNumber(left);
+ final Number rn = asLongNumber(right);
if (ln != null && rn != null) {
- long x = ln.longValue();
- long y = rn.longValue();
- long result = x - y;
+ final long x = ln.longValue();
+ final long y = rn.longValue();
+ final long result = x - y;
// detect overflow, see java8 Math.subtractExact
if (((x ^ y) & (x ^ result)) < 0) {
return BigInteger.valueOf(x).subtract(BigInteger.valueOf(y));
@@ -946,21 +946,21 @@
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
- BigDecimal l = toBigDecimal(left);
- BigDecimal r = toBigDecimal(right);
- BigDecimal result = l.subtract(r, getMathContext());
+ final BigDecimal l = toBigDecimal(left);
+ final BigDecimal r = toBigDecimal(right);
+ final BigDecimal result = l.subtract(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
- double l = toDouble(left);
- double r = toDouble(right);
+ final double l = toDouble(left);
+ final double r = toDouble(right);
return l - r;
}
// otherwise treat as integers
- BigInteger l = toBigInteger(left);
- BigInteger r = toBigInteger(right);
- BigInteger result = l.subtract(r);
+ final BigInteger l = toBigInteger(left);
+ final BigInteger r = toBigInteger(right);
+ final BigInteger result = l.subtract(r);
return narrowBigInteger(left, right, result);
}
@@ -970,7 +970,7 @@
* @param val the value to negate
* @return the negated value
*/
- public Object negate(Object val) {
+ public Object negate(final Object val) {
if (val == null) {
controlNullOperand();
return null;
@@ -1018,7 +1018,7 @@
* @param val the value to positivize
* @return the positive value
*/
- public Object positivize(Object val) {
+ public Object positivize(final Object val) {
if (val == null) {
controlNullOperand();
return null;
@@ -1064,7 +1064,7 @@
* @param value the value
* @return test result or null if there is no arithmetic solution
*/
- public Boolean contains(Object container, Object value) {
+ public Boolean contains(final Object container, final Object value) {
if (value == null && container == null) {
//if both are null L == R
return true;
@@ -1105,7 +1105,7 @@
* @param right right argument
* @return left $= right if there is no arithmetic solution
*/
- public Boolean endsWith(Object left, Object right) {
+ public Boolean endsWith(final Object left, final Object right) {
if (left == null && right == null) {
//if both are null L == R
return true;
@@ -1127,7 +1127,7 @@
* @param right right argument
* @return left ^= right or null if there is no arithmetic solution
*/
- public Boolean startsWith(Object left, Object right) {
+ public Boolean startsWith(final Object left, final Object right) {
if (left == null && right == null) {
//if both are null L == R
return true;
@@ -1149,7 +1149,7 @@
* @return the boolean or false if object is not null
* @since 3.2
*/
- public Boolean empty(Object object) {
+ public Boolean empty(final Object object) {
return object == null || isEmpty(object, false);
}
@@ -1159,7 +1159,7 @@
* @param object the object to check the emptiness of
* @return the boolean or null if there is no arithmetic solution
*/
- public Boolean isEmpty(Object object) {
+ public Boolean isEmpty(final Object object) {
return isEmpty(object, object == null);
}
@@ -1170,9 +1170,9 @@
* @param def the default value if object emptyness can not be determined
* @return the boolean or null if there is no arithmetic solution
*/
- public Boolean isEmpty(Object object, Boolean def) {
+ public Boolean isEmpty(final Object object, final Boolean def) {
if (object instanceof Number) {
- double d = ((Number) object).doubleValue();
+ final double d = ((Number) object).doubleValue();
return Double.isNaN(d) || d == 0.d ? Boolean.TRUE : Boolean.FALSE;
}
if (object instanceof CharSequence) {
@@ -1197,7 +1197,7 @@
* @param object the object to get the size of
* @return the <i>size</i> of object, 0 if null, 1 if there is no <i>better</i> solution
*/
- public Integer size(Object object) {
+ public Integer size(final Object object) {
return size(object, object == null? 0 : 1);
}
@@ -1208,7 +1208,7 @@
* @param def the default value if object size can not be determined
* @return the size of object or null if there is no arithmetic solution
*/
- public Integer size(Object object, Integer def) {
+ public Integer size(final Object object, final Integer def) {
if (object instanceof CharSequence) {
return ((CharSequence) object).length();
}
@@ -1231,9 +1231,9 @@
* @param right the right operator
* @return left & right
*/
- public Object and(Object left, Object right) {
- long l = toLong(left);
- long r = toLong(right);
+ public Object and(final Object left, final Object right) {
+ final long l = toLong(left);
+ final long r = toLong(right);
return l & r;
}
@@ -1244,9 +1244,9 @@
* @param right the right operator
* @return left | right
*/
- public Object or(Object left, Object right) {
- long l = toLong(left);
- long r = toLong(right);
+ public Object or(final Object left, final Object right) {
+ final long l = toLong(left);
+ final long r = toLong(right);
return l | r;
}
@@ -1257,9 +1257,9 @@
* @param right the right operator
* @return left ^ right
*/
- public Object xor(Object left, Object right) {
- long l = toLong(left);
- long r = toLong(right);
+ public Object xor(final Object left, final Object right) {
+ final long l = toLong(left);
+ final long r = toLong(right);
return l ^ r;
}
@@ -1269,8 +1269,8 @@
* @param val the operand
* @return ~val
*/
- public Object complement(Object val) {
- long l = toLong(val);
+ public Object complement(final Object val) {
+ final long l = toLong(val);
return ~l;
}
@@ -1280,7 +1280,7 @@
* @param val the operand
* @return !val
*/
- public Object not(Object val) {
+ public Object not(final Object val) {
return toBoolean(val) ? Boolean.FALSE : Boolean.TRUE;
}
@@ -1293,19 +1293,19 @@
* @return -1 if left < right; +1 if left > right; 0 if left == right
* @throws ArithmeticException if either left or right is null
*/
- protected int compare(Object left, Object right, String operator) {
+ protected int compare(final Object left, final Object right, final String operator) {
if (left != null && right != null) {
if (left instanceof BigDecimal || right instanceof BigDecimal) {
- BigDecimal l = toBigDecimal(left);
- BigDecimal r = toBigDecimal(right);
+ final BigDecimal l = toBigDecimal(left);
+ final BigDecimal r = toBigDecimal(right);
return l.compareTo(r);
} else if (left instanceof BigInteger || right instanceof BigInteger) {
- BigInteger l = toBigInteger(left);
- BigInteger r = toBigInteger(right);
+ final BigInteger l = toBigInteger(left);
+ final BigInteger r = toBigInteger(right);
return l.compareTo(r);
} else if (isFloatingPoint(left) || isFloatingPoint(right)) {
- double lhs = toDouble(left);
- double rhs = toDouble(right);
+ final double lhs = toDouble(left);
+ final double rhs = toDouble(right);
if (Double.isNaN(lhs)) {
if (Double.isNaN(rhs)) {
return 0;
@@ -1323,8 +1323,8 @@
return 0;
}
} else if (isNumberable(left) || isNumberable(right)) {
- long lhs = toLong(left);
- long rhs = toLong(right);
+ final long lhs = toLong(left);
+ final long rhs = toLong(right);
if (lhs < rhs) {
return -1;
} else if (lhs > rhs) {
@@ -1356,7 +1356,7 @@
* @param right right argument
* @return the test result
*/
- public boolean equals(Object left, Object right) {
+ public boolean equals(final Object left, final Object right) {
if (left == right) {
return true;
} else if (left == null || right == null) {
@@ -1375,7 +1375,7 @@
* @param right right argument
* @return the test result
*/
- public boolean lessThan(Object left, Object right) {
+ public boolean lessThan(final Object left, final Object right) {
if ((left == right) || (left == null) || (right == null)) {
return false;
} else {
@@ -1391,7 +1391,7 @@
* @param right right argument
* @return the test result
*/
- public boolean greaterThan(Object left, Object right) {
+ public boolean greaterThan(final Object left, final Object right) {
if ((left == right) || left == null || right == null) {
return false;
} else {
@@ -1406,7 +1406,7 @@
* @param right right argument
* @return the test result
*/
- public boolean lessThanOrEqual(Object left, Object right) {
+ public boolean lessThanOrEqual(final Object left, final Object right) {
if (left == right) {
return true;
} else if (left == null || right == null) {
@@ -1423,7 +1423,7 @@
* @param right right argument
* @return the test result
*/
- public boolean greaterThanOrEqual(Object left, Object right) {
+ public boolean greaterThanOrEqual(final Object left, final Object right) {
if (left == right) {
return true;
} else if (left == null || right == null) {
@@ -1440,19 +1440,19 @@
* @param val value to coerce
* @return the boolean value if coercion is possible, true if value was not null.
*/
- public boolean toBoolean(Object val) {
+ public boolean toBoolean(final Object val) {
if (val == null) {
controlNullOperand();
return false;
} else if (val instanceof Boolean) {
return ((Boolean) val);
} else if (val instanceof Number) {
- double number = toDouble(val);
+ final double number = toDouble(val);
return !Double.isNaN(number) && number != 0.d;
} else if (val instanceof AtomicBoolean) {
return ((AtomicBoolean) val).get();
} else if (val instanceof String) {
- String strval = val.toString();
+ final String strval = val.toString();
return strval.length() > 0 && !"false".equals(strval);
} else {
// non null value is true
@@ -1469,12 +1469,12 @@
* @return the value coerced to int
* @throws ArithmeticException if val is null and mode is strict or if coercion is not possible
*/
- public int toInteger(Object val) {
+ public int toInteger(final Object val) {
if (val == null) {
controlNullOperand();
return 0;
} else if (val instanceof Double) {
- Double dval = (Double) val;
+ final Double dval = (Double) val;
if (Double.isNaN(dval)) {
return 0;
} else {
@@ -1508,12 +1508,12 @@
* @return the value coerced to long
* @throws ArithmeticException if value is null and mode is strict or if coercion is not possible
*/
- public long toLong(Object val) {
+ public long toLong(final Object val) {
if (val == null) {
controlNullOperand();
return 0L;
} else if (val instanceof Double) {
- Double dval = (Double) val;
+ final Double dval = (Double) val;
if (Double.isNaN(dval)) {
return 0L;
} else {
@@ -1548,14 +1548,14 @@
* @return a BigDecimal
* @throws ArithmeticException if val is null and mode is strict or if coercion is not possible
*/
- public BigInteger toBigInteger(Object val) {
+ public BigInteger toBigInteger(final Object val) {
if (val == null) {
controlNullOperand();
return BigInteger.ZERO;
} else if (val instanceof BigInteger) {
return (BigInteger) val;
} else if (val instanceof Double) {
- Double dval = (Double) val;
+ final Double dval = (Double) val;
if (Double.isNaN(dval)) {
return BigInteger.ZERO;
} else {
@@ -1570,14 +1570,14 @@
} else if (val instanceof AtomicBoolean) {
return BigInteger.valueOf(((AtomicBoolean) val).get() ? 1L : 0L);
} else if (val instanceof String) {
- String string = (String) val;
+ final String string = (String) val;
if ("".equals(string)) {
return BigInteger.ZERO;
} else {
return new BigInteger(string);
}
} else if (val instanceof Character) {
- int i = ((Character) val);
+ final int i = ((Character) val);
return BigInteger.valueOf(i);
}
@@ -1594,7 +1594,7 @@
* @return a BigDecimal.
* @throws ArithmeticException if val is null and mode is strict or if coercion is not possible
*/
- public BigDecimal toBigDecimal(Object val) {
+ public BigDecimal toBigDecimal(final Object val) {
if (val instanceof BigDecimal) {
return roundBigDecimal((BigDecimal) val);
} else if (val == null) {
@@ -1613,13 +1613,13 @@
} else if (val instanceof AtomicBoolean) {
return BigDecimal.valueOf(((AtomicBoolean) val).get() ? 1L : 0L);
} else if (val instanceof String) {
- String string = (String) val;
+ final String string = (String) val;
if ("".equals(string)) {
return BigDecimal.ZERO;
}
return roundBigDecimal(new BigDecimal(string, getMathContext()));
} else if (val instanceof Character) {
- int i = ((Character) val);
+ final int i = ((Character) val);
return new BigDecimal(i);
}
throw new ArithmeticException("BigDecimal coercion: "
@@ -1635,7 +1635,7 @@
* @return The double coerced value.
* @throws ArithmeticException if val is null and mode is strict or if coercion is not possible
*/
- public double toDouble(Object val) {
+ public double toDouble(final Object val) {
if (val == null) {
controlNullOperand();
return 0;
@@ -1650,7 +1650,7 @@
} else if (val instanceof AtomicBoolean) {
return ((AtomicBoolean) val).get() ? 1. : 0.;
} else if (val instanceof String) {
- String string = (String) val;
+ final String string = (String) val;
if ("".equals(string)) {
return Double.NaN;
} else {
@@ -1658,7 +1658,7 @@
return Double.parseDouble(string);
}
} else if (val instanceof Character) {
- int i = ((Character) val);
+ final int i = ((Character) val);
return i;
}
throw new ArithmeticException("Double coercion: "
@@ -1673,12 +1673,12 @@
* @return The String coerced value.
* @throws ArithmeticException if val is null and mode is strict or if coercion is not possible
*/
- public String toString(Object val) {
+ public String toString(final Object val) {
if (val == null) {
controlNullOperand();
return "";
} else if (val instanceof Double) {
- Double dval = (Double) val;
+ final Double dval = (Double) val;
if (Double.isNaN(dval)) {
return "";
} else {
@@ -1698,7 +1698,7 @@
* @deprecated
*/
@Deprecated
- public final Object bitwiseAnd(Object lhs, Object rhs) {
+ public final Object bitwiseAnd(final Object lhs, final Object rhs) {
return and(lhs, rhs);
}
@@ -1712,7 +1712,7 @@
* @deprecated
*/
@Deprecated
- public final Object bitwiseOr(Object lhs, Object rhs) {
+ public final Object bitwiseOr(final Object lhs, final Object rhs) {
return or(lhs, rhs);
}
@@ -1726,7 +1726,7 @@
* @deprecated
*/
@Deprecated
- public final Object bitwiseXor(Object lhs, Object rhs) {
+ public final Object bitwiseXor(final Object lhs, final Object rhs) {
return xor(lhs, rhs);
}
@@ -1739,7 +1739,7 @@
* @deprecated
*/
@Deprecated
- public final Object logicalNot(Object arg) {
+ public final Object logicalNot(final Object arg) {
return not(arg);
}
@@ -1753,7 +1753,7 @@
* @deprecated
*/
@Deprecated
- public final Object matches(Object lhs, Object rhs) {
+ public final Object matches(final Object lhs, final Object rhs) {
return contains(rhs, lhs);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/JexlBuilder.java b/src/main/java/org/apache/commons/jexl3/JexlBuilder.java
index 2a5b006..cd018c1 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlBuilder.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlBuilder.java
@@ -112,7 +112,7 @@
* @param u the uberspect
* @return this builder
*/
- public JexlBuilder uberspect(JexlUberspect u) {
+ public JexlBuilder uberspect(final JexlUberspect u) {
this.uberspect = u;
return this;
}
@@ -129,7 +129,7 @@
* @param rs the strategy
* @return this builder
*/
- public JexlBuilder strategy(JexlUberspect.ResolverStrategy rs) {
+ public JexlBuilder strategy(final JexlUberspect.ResolverStrategy rs) {
this.strategy = rs;
return this;
}
@@ -150,7 +150,7 @@
* @param a the arithmetic
* @return this builder
*/
- public JexlBuilder arithmetic(JexlArithmetic a) {
+ public JexlBuilder arithmetic(final JexlArithmetic a) {
this.arithmetic = a;
options.setStrictArithmetic(a.isStrict());
options.setMathContext(a.getMathContext());
@@ -169,7 +169,7 @@
* @param box the sandbox
* @return this builder
*/
- public JexlBuilder sandbox(JexlSandbox box) {
+ public JexlBuilder sandbox(final JexlSandbox box) {
this.sandbox = box;
return this;
}
@@ -188,7 +188,7 @@
* @param f the features
* @return this builder
*/
- public JexlBuilder features(JexlFeatures f) {
+ public JexlBuilder features(final JexlFeatures f) {
this.features = f;
if (features != null) {
if (features.isLexical()) {
@@ -212,7 +212,7 @@
* @param log the logger
* @return this builder
*/
- public JexlBuilder logger(Log log) {
+ public JexlBuilder logger(final Log log) {
this.logger = log;
return this;
}
@@ -228,7 +228,7 @@
* @param l the class loader
* @return this builder
*/
- public JexlBuilder loader(ClassLoader l) {
+ public JexlBuilder loader(final ClassLoader l) {
this.loader = l;
return this;
}
@@ -246,7 +246,7 @@
* @deprecated since 3.1 use {@link #charset(Charset)} instead
*/
@Deprecated
- public JexlBuilder loader(Charset arg) {
+ public JexlBuilder loader(final Charset arg) {
return charset(arg);
}
@@ -257,7 +257,7 @@
* @return this builder
* @since 3.1
*/
- public JexlBuilder charset(Charset arg) {
+ public JexlBuilder charset(final Charset arg) {
this.charset = arg;
return this;
}
@@ -273,7 +273,7 @@
* @param flag true means antish resolution is enabled, false disables it
* @return this builder
*/
- public JexlBuilder antish(boolean flag) {
+ public JexlBuilder antish(final boolean flag) {
options.setAntish(flag);
return this;
}
@@ -290,7 +290,7 @@
* @return this builder
* @since 3.2
*/
- public JexlBuilder lexical(boolean flag) {
+ public JexlBuilder lexical(final boolean flag) {
options.setLexical(flag);
return this;
}
@@ -307,7 +307,7 @@
* @return this builder
* @since 3.2
*/
- public JexlBuilder lexicalShade(boolean flag) {
+ public JexlBuilder lexicalShade(final boolean flag) {
options.setLexicalShade(flag);
return this;
}
@@ -323,7 +323,7 @@
* @param flag true means no JexlException will occur, false allows them
* @return this builder
*/
- public JexlBuilder silent(boolean flag) {
+ public JexlBuilder silent(final boolean flag) {
options.setSilent(flag);
return this;
}
@@ -340,7 +340,7 @@
* @param flag true means strict error reporting, false allows them to be evaluated as null
* @return this builder
*/
- public JexlBuilder strict(boolean flag) {
+ public JexlBuilder strict(final boolean flag) {
options.setStrict(flag);
return this;
}
@@ -359,7 +359,7 @@
* @param flag true means safe navigation, false throws exception when dereferencing null
* @return this builder
*/
- public JexlBuilder safe(boolean flag) {
+ public JexlBuilder safe(final boolean flag) {
options.setSafe(flag);
return this;
}
@@ -375,7 +375,7 @@
* @param flag true implies debug is on, false implies debug is off.
* @return this builder
*/
- public JexlBuilder debug(boolean flag) {
+ public JexlBuilder debug(final boolean flag) {
this.debug = flag;
return this;
}
@@ -393,7 +393,7 @@
* @return this builder
* @since 3.1
*/
- public JexlBuilder cancellable(boolean flag) {
+ public JexlBuilder cancellable(final boolean flag) {
this.cancellable = flag;
options.setCancellable(flag);
return this;
@@ -414,7 +414,7 @@
* @return this builder
* @since 3.2
*/
- public JexlBuilder collectAll(boolean flag) {
+ public JexlBuilder collectAll(final boolean flag) {
return collectMode(flag? 1 : 0);
}
@@ -425,7 +425,7 @@
* @return this builder
* @since 3.2
*/
- public JexlBuilder collectMode(int mode) {
+ public JexlBuilder collectMode(final int mode) {
this.collectMode = mode;
return this;
}
@@ -471,7 +471,7 @@
* @param ns the map of namespaces
* @return this builder
*/
- public JexlBuilder namespaces(Map<String, Object> ns) {
+ public JexlBuilder namespaces(final Map<String, Object> ns) {
options.setNamespaces(ns);
return this;
}
@@ -491,7 +491,7 @@
* @param size if not strictly positive, no cache is used.
* @return this builder
*/
- public JexlBuilder cache(int size) {
+ public JexlBuilder cache(final int size) {
this.cache = size;
return this;
}
@@ -513,7 +513,7 @@
* @param length if not strictly positive, the value is silently replaced by the default value (64).
* @return this builder
*/
- public JexlBuilder cacheThreshold(int length) {
+ public JexlBuilder cacheThreshold(final int length) {
this.cacheThreshold = length > 0? length : CACHE_THRESHOLD;
return this;
}
@@ -530,7 +530,7 @@
* @param size if not strictly positive, limit is reached when java StackOverflow is thrown.
* @return this builder
*/
- public JexlBuilder stackOverflow(int size) {
+ public JexlBuilder stackOverflow(final int size) {
this.stackOverflow = size;
return this;
}
diff --git a/src/main/java/org/apache/commons/jexl3/JexlEngine.java b/src/main/java/org/apache/commons/jexl3/JexlEngine.java
index 30348c6..951b89a 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlEngine.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlEngine.java
@@ -100,7 +100,7 @@
*
* @param tls the thread local context to set
*/
- public static void setThreadContext(JexlContext.ThreadLocal tls) {
+ public static void setThreadContext(final JexlContext.ThreadLocal tls) {
CONTEXT.set(tls);
}
@@ -180,17 +180,17 @@
private EmptyContext() {}
@Override
- public Object get(String name) {
+ public Object get(final String name) {
return null;
}
@Override
- public boolean has(String name) {
+ public boolean has(final String name) {
return false;
}
@Override
- public void set(String name, Object value) {
+ public void set(final String name, final Object value) {
throw new UnsupportedOperationException("Not supported in void context.");
}
};
@@ -210,7 +210,7 @@
private EmptyNamespaceResolver() {}
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
return null;
}
};
@@ -292,7 +292,7 @@
* @param noScript whether the JxltEngine only allows Jexl expressions or scripts
* @return a JEXL Template engine
*/
- public JxltEngine createJxltEngine(boolean noScript) {
+ public JxltEngine createJxltEngine(final boolean noScript) {
return createJxltEngine(noScript, JXLT_CACHE_SIZE, '$', '#');
}
@@ -331,7 +331,7 @@
* @return An {@link JexlExpression} which can be evaluated using a {@link JexlContext}
* @throws JexlException if there is a problem parsing the script
*/
- public final JexlExpression createExpression(String expression) {
+ public final JexlExpression createExpression(final String expression) {
return createExpression(null, expression);
}
/**
@@ -359,7 +359,7 @@
* @return A {@link JexlScript} which can be executed using a {@link JexlContext}
* @throws JexlException if there is a problem parsing the script
*/
- public final JexlScript createScript(JexlInfo info, String source, String... names) {
+ public final JexlScript createScript(final JexlInfo info, final String source, final String... names) {
return createScript(null, info, source, names);
}
@@ -371,7 +371,7 @@
* @return A {@link JexlScript} which can be executed using a {@link JexlContext}
* @throws JexlException if there is a problem parsing the script.
*/
- public final JexlScript createScript(String scriptText) {
+ public final JexlScript createScript(final String scriptText) {
return createScript(null, null, scriptText, (String[]) null);
}
@@ -385,7 +385,7 @@
* @return A {@link JexlScript} which can be executed using a {@link JexlContext}
* @throws JexlException if there is a problem parsing the script
*/
- public final JexlScript createScript(String source, String... names) {
+ public final JexlScript createScript(final String source, final String... names) {
return createScript(null, null, source, names);
}
@@ -397,7 +397,7 @@
* @return A {@link JexlScript} which can be executed with a {@link JexlContext}.
* @throws JexlException if there is a problem reading or parsing the script.
*/
- public final JexlScript createScript(File scriptFile) {
+ public final JexlScript createScript(final File scriptFile) {
return createScript(null, null, readSource(scriptFile), (String[]) null);
}
@@ -411,7 +411,7 @@
* @return A {@link JexlScript} which can be executed with a {@link JexlContext}.
* @throws JexlException if there is a problem reading or parsing the script.
*/
- public final JexlScript createScript(File scriptFile, String... names) {
+ public final JexlScript createScript(final File scriptFile, final String... names) {
return createScript(null, null, readSource(scriptFile), names);
}
@@ -426,7 +426,7 @@
* @return A {@link JexlScript} which can be executed with a {@link JexlContext}.
* @throws JexlException if there is a problem reading or parsing the script.
*/
- public final JexlScript createScript(JexlInfo info, File scriptFile, String... names) {
+ public final JexlScript createScript(final JexlInfo info, final File scriptFile, final String... names) {
return createScript(null, info, readSource(scriptFile), names);
}
@@ -438,7 +438,7 @@
* @return A {@link JexlScript} which can be executed with a {@link JexlContext}.
* @throws JexlException if there is a problem reading or parsing the script.
*/
- public final JexlScript createScript(URL scriptUrl) {
+ public final JexlScript createScript(final URL scriptUrl) {
return createScript(null, readSource(scriptUrl), (String[]) null);
}
@@ -452,7 +452,7 @@
* @return A {@link JexlScript} which can be executed with a {@link JexlContext}.
* @throws JexlException if there is a problem reading or parsing the script.
*/
- public final JexlScript createScript(URL scriptUrl, String... names) {
+ public final JexlScript createScript(final URL scriptUrl, final String... names) {
return createScript(null, null, readSource(scriptUrl), names);
}
@@ -467,7 +467,7 @@
* @return A {@link JexlScript} which can be executed with a {@link JexlContext}.
* @throws JexlException if there is a problem reading or parsing the script.
*/
- public final JexlScript createScript(JexlInfo info, URL scriptUrl, String... names) {
+ public final JexlScript createScript(final JexlInfo info, final URL scriptUrl, final String... names) {
return createScript(null, info, readSource(scriptUrl), names);
}
@@ -569,7 +569,7 @@
* @param c column number
* @return a JexlInfo instance
*/
- public JexlInfo createInfo(String fn, int l, int c) {
+ public JexlInfo createInfo(final String fn, final int l, final int c) {
return new JexlInfo(fn, l, c);
}
@@ -591,8 +591,8 @@
* @return the contents of the reader as a String.
* @throws IOException on any error reading the reader.
*/
- protected static String toString(BufferedReader reader) throws IOException {
- StringBuilder buffer = new StringBuilder();
+ protected static String toString(final BufferedReader reader) throws IOException {
+ final StringBuilder buffer = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line).append('\n');
@@ -613,7 +613,7 @@
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
getCharset()))) {
return toString(reader);
- } catch (IOException xio) {
+ } catch (final IOException xio) {
throw new JexlException(createInfo(file.toString(), 1, 1), "could not read source File", xio);
}
}
@@ -630,7 +630,7 @@
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), getCharset()))) {
return toString(reader);
- } catch (IOException xio) {
+ } catch (final IOException xio) {
throw new JexlException(createInfo(url.toString(), 1, 1), "could not read source URL", xio);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/JexlException.java b/src/main/java/org/apache/commons/jexl3/JexlException.java
index 5ed8a6e..ee5901d 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlException.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlException.java
@@ -54,7 +54,7 @@
* @param node the node causing the error
* @param msg the error message
*/
- public JexlException(JexlNode node, String msg) {
+ public JexlException(final JexlNode node, final String msg) {
this(node, msg, null);
}
@@ -65,7 +65,7 @@
* @param msg the error message
* @param cause the exception causing the error
*/
- public JexlException(JexlNode node, String msg, Throwable cause) {
+ public JexlException(final JexlNode node, final String msg, final Throwable cause) {
super(msg != null ? msg : "", unwrap(cause));
if (node != null) {
mark = node;
@@ -83,7 +83,7 @@
* @param msg the error message
* @param cause the exception causing the error
*/
- public JexlException(JexlInfo jinfo, String msg, Throwable cause) {
+ public JexlException(final JexlInfo jinfo, final String msg, final Throwable cause) {
super(msg != null ? msg : "", unwrap(cause));
mark = null;
info = jinfo;
@@ -104,9 +104,9 @@
* @param node the node
* @return a string builder
*/
- private static StringBuilder errorAt(JexlNode node) {
- JexlInfo info = node != null? detailedInfo(node, node.jexlInfo()) : null;
- StringBuilder msg = new StringBuilder();
+ private static StringBuilder errorAt(final JexlNode node) {
+ final JexlInfo info = node != null? detailedInfo(node, node.jexlInfo()) : null;
+ final StringBuilder msg = new StringBuilder();
if (info != null) {
msg.append(info.toString());
} else {
@@ -125,7 +125,7 @@
* @deprecated 3.2
*/
@Deprecated
- public static JexlInfo getInfo(JexlNode node, JexlInfo info) {
+ public static JexlInfo getInfo(final JexlNode node, final JexlInfo info) {
return detailedInfo(node, info);
}
@@ -136,7 +136,7 @@
* @param info the information
* @return the information or null
*/
- private static JexlInfo detailedInfo(JexlNode node, JexlInfo info) {
+ private static JexlInfo detailedInfo(final JexlNode node, final JexlInfo info) {
if (info != null && node != null) {
final Debugger dbg = new Debugger();
if (dbg.debug(node)) {
@@ -167,11 +167,11 @@
* @param xthrow the thowable
* @return the throwable
*/
- private static <X extends Throwable> X clean(X xthrow) {
+ private static <X extends Throwable> X clean(final X xthrow) {
if (xthrow != null) {
- List<StackTraceElement> stackJexl = new ArrayList<StackTraceElement>();
- for (StackTraceElement se : xthrow.getStackTrace()) {
- String className = se.getClassName();
+ final List<StackTraceElement> stackJexl = new ArrayList<StackTraceElement>();
+ for (final StackTraceElement se : xthrow.getStackTrace()) {
+ final String className = se.getClassName();
if (!className.startsWith("org.apache.commons.jexl3.internal")
&& !className.startsWith("org.apache.commons.jexl3.parser")) {
stackJexl.add(se);
@@ -188,7 +188,7 @@
* @param xthrow the throwable
* @return the cause
*/
- private static Throwable unwrap(Throwable xthrow) {
+ private static Throwable unwrap(final Throwable xthrow) {
if (xthrow instanceof TryFailed
|| xthrow instanceof InvocationTargetException
|| xthrow instanceof UndeclaredThrowableException) {
@@ -204,8 +204,8 @@
* @param cause the cause
* @return the info to use
*/
- private static JexlInfo merge(JexlInfo info, JavaccError cause) {
- JexlInfo dbgn = info;
+ private static JexlInfo merge(final JexlInfo info, final JavaccError cause) {
+ final JexlInfo dbgn = info;
if (cause == null || cause.getLine() < 0) {
return dbgn;
} else if (dbgn == null) {
@@ -231,12 +231,12 @@
* @param expr the expression in error
* @return the formatted message
*/
- protected String parserError(String prefix, String expr) {
- int length = expr.length();
+ protected String parserError(final String prefix, final String expr) {
+ final int length = expr.length();
if (length < MAX_EXCHARLOC) {
return prefix + " error in '" + expr + "'";
} else {
- int me = MAX_EXCHARLOC / 2;
+ final int me = MAX_EXCHARLOC / 2;
int begin = info.getColumn() - me;
if (begin < 0 || length < me) {
begin = 0;
@@ -271,7 +271,7 @@
* @param info the location info
* @param cause the javacc cause
*/
- public Tokenization(JexlInfo info, TokenMgrError cause) {
+ public Tokenization(final JexlInfo info, final TokenMgrError cause) {
super(merge(info, cause), cause.getAfter(), null);
}
@@ -300,7 +300,7 @@
* @param info the location information
* @param cause the javacc cause
*/
- public Parsing(JexlInfo info, ParseException cause) {
+ public Parsing(final JexlInfo info, final ParseException cause) {
super(merge(info, cause), cause.getAfter(), null);
}
@@ -310,7 +310,7 @@
* @param info the location information
* @param msg the message
*/
- public Parsing(JexlInfo info, String msg) {
+ public Parsing(final JexlInfo info, final String msg) {
super(info, msg, null);
}
@@ -340,7 +340,7 @@
* @param info the location information
* @param expr the source expression line
*/
- public Ambiguous(JexlInfo info, String expr) {
+ public Ambiguous(final JexlInfo info, final String expr) {
this(info, null, expr);
}
@@ -350,7 +350,7 @@
* @param end the end location information
* @param expr the source expression line
*/
- public Ambiguous(JexlInfo begin, JexlInfo end, String expr) {
+ public Ambiguous(final JexlInfo begin, final JexlInfo end, final String expr) {
super(begin, expr);
recover = end;
}
@@ -366,8 +366,8 @@
* @return the source with the ambiguous statement removed
* or null if no recovery was possible
*/
- public String tryCleanSource(String src) {
- JexlInfo ji = info();
+ public String tryCleanSource(final String src) {
+ final JexlInfo ji = info();
return ji == null || recover == null
? src
: sliceSource(src, ji.getLine(), ji.getColumn(), recover.getLine(), recover.getColumn());
@@ -383,9 +383,9 @@
* @param toc the to column
* @return the source with the (begin) to (to) zone removed
*/
- public static String sliceSource(String src, int froml, int fromc, int tol, int toc) {
- BufferedReader reader = new BufferedReader(new StringReader(src));
- StringBuilder buffer = new StringBuilder();
+ public static String sliceSource(final String src, final int froml, final int fromc, final int tol, final int toc) {
+ final BufferedReader reader = new BufferedReader(new StringReader(src));
+ final StringBuilder buffer = new StringBuilder();
String line;
int cl = 1;
try {
@@ -402,7 +402,7 @@
} // else ignore line
cl += 1;
}
- } catch (IOException xignore) {
+ } catch (final IOException xignore) {
//damn the checked exceptions :-)
}
return buffer.toString();
@@ -421,7 +421,7 @@
* @param name the unknown method
* @param cause the exception causing the error
*/
- public StackOverflow(JexlInfo info, String name, Throwable cause) {
+ public StackOverflow(final JexlInfo info, final String name, final Throwable cause) {
super(info, name, cause);
}
@@ -450,7 +450,7 @@
* @param info the location information
* @param expr the source expression line
*/
- public Assignment(JexlInfo info, String expr) {
+ public Assignment(final JexlInfo info, final String expr) {
super(info, expr);
}
@@ -474,7 +474,7 @@
* @param feature the feature code
* @param expr the source expression line
*/
- public Feature(JexlInfo info, int feature, String expr) {
+ public Feature(final JexlInfo info, final int feature, final String expr) {
super(info, expr);
this.code = feature;
}
@@ -501,7 +501,7 @@
* @param var the variable name
* @return the issue message
*/
- public String message(String var) {
+ public String message(final String var) {
switch(this) {
case NULLVALUE : return "variable '" + var + "' is null";
case REDEFINED : return "variable '" + var + "' is already defined";
@@ -529,7 +529,7 @@
* @param var the unknown variable
* @param vi the variable issue
*/
- public Variable(JexlNode node, String var, VariableIssue vi) {
+ public Variable(final JexlNode node, final String var, final VariableIssue vi) {
super(node, var, null);
issue = vi;
}
@@ -541,7 +541,7 @@
* @param var the unknown variable
* @param undef whether the variable is undefined or evaluated as null
*/
- public Variable(JexlNode node, String var, boolean undef) {
+ public Variable(final JexlNode node, final String var, final boolean undef) {
this(node, var, undef ? VariableIssue.UNDEFINED : VariableIssue.NULLVALUE);
}
@@ -576,7 +576,7 @@
* @return the error message
*/
@Deprecated
- public static String variableError(JexlNode node, String variable, boolean undef) {
+ public static String variableError(final JexlNode node, final String variable, final boolean undef) {
return variableError(node, variable, undef? VariableIssue.UNDEFINED : VariableIssue.NULLVALUE);
}
@@ -588,8 +588,8 @@
* @param issue the variable kind of issue
* @return the error message
*/
- public static String variableError(JexlNode node, String variable, VariableIssue issue) {
- StringBuilder msg = errorAt(node);
+ public static String variableError(final JexlNode node, final String variable, final VariableIssue issue) {
+ final StringBuilder msg = errorAt(node);
msg.append(issue.message(variable));
return msg.toString();
}
@@ -613,7 +613,7 @@
* @deprecated 3.2
*/
@Deprecated
- public Property(JexlNode node, String pty) {
+ public Property(final JexlNode node, final String pty) {
this(node, pty, true, null);
}
/**
@@ -625,7 +625,7 @@
* @deprecated 3.2
*/
@Deprecated
- public Property(JexlNode node, String pty, Throwable cause) {
+ public Property(final JexlNode node, final String pty, final Throwable cause) {
this(node, pty, true, cause);
}
@@ -637,7 +637,7 @@
* @param undef whether the variable is null or undefined
* @param cause the exception causing the error
*/
- public Property(JexlNode node, String pty, boolean undef, Throwable cause) {
+ public Property(final JexlNode node, final String pty, final boolean undef, final Throwable cause) {
super(node, pty, cause);
undefined = undef;
}
@@ -672,8 +672,8 @@
* @param undef whether the property is null or undefined
* @return the error message
*/
- public static String propertyError(JexlNode node, String pty, boolean undef) {
- StringBuilder msg = errorAt(node);
+ public static String propertyError(final JexlNode node, final String pty, final boolean undef) {
+ final StringBuilder msg = errorAt(node);
if (undef) {
msg.append("unsolvable");
} else {
@@ -694,7 +694,7 @@
* @deprecated 3.2
*/
@Deprecated
- public static String propertyError(JexlNode node, String var) {
+ public static String propertyError(final JexlNode node, final String var) {
return propertyError(node, var, true);
}
@@ -712,7 +712,7 @@
* @deprecated as of 3.2, use call with method arguments
*/
@Deprecated
- public Method(JexlNode node, String name) {
+ public Method(final JexlNode node, final String name) {
this(node, name, null);
}
@@ -725,7 +725,7 @@
* @deprecated as of 3.2, use call with method arguments
*/
@Deprecated
- public Method(JexlInfo info, String name, Throwable cause) {
+ public Method(final JexlInfo info, final String name, final Throwable cause) {
this(info, name, null, cause);
}
@@ -737,7 +737,7 @@
* @param args the method arguments
* @since 3.2
*/
- public Method(JexlNode node, String name, Object[] args) {
+ public Method(final JexlNode node, final String name, final Object[] args) {
super(node, methodSignature(name, args));
}
@@ -749,7 +749,7 @@
* @param args the method arguments
* @since 3.2
*/
- public Method(JexlInfo info, String name, Object[] args) {
+ public Method(final JexlInfo info, final String name, final Object[] args) {
this(info, name, args, null);
}
@@ -763,7 +763,7 @@
* @param args the method arguments
* @since 3.2
*/
- public Method(JexlInfo info, String name, Object[] args, Throwable cause) {
+ public Method(final JexlInfo info, final String name, final Object[] args, final Throwable cause) {
super(info, methodSignature(name, args), cause);
}
@@ -771,8 +771,8 @@
* @return the method name
*/
public String getMethod() {
- String signature = getMethodSignature();
- int lparen = signature.indexOf('(');
+ final String signature = getMethodSignature();
+ final int lparen = signature.indexOf('(');
return lparen > 0? signature.substring(0, lparen) : signature;
}
@@ -796,15 +796,15 @@
* @param args the method arguments
* @return a suitable signed name
*/
- private static String methodSignature(String name, Object[] args) {
+ private static String methodSignature(final String name, final Object[] args) {
if (args != null && args.length > 0) {
- StringBuilder strb = new StringBuilder(name);
+ final StringBuilder strb = new StringBuilder(name);
strb.append('(');
for (int a = 0; a < args.length; ++a) {
if (a > 0) {
strb.append(", ");
}
- Class<?> clazz = args[a] == null ? Object.class : args[a].getClass();
+ final Class<?> clazz = args[a] == null ? Object.class : args[a].getClass();
strb.append(clazz.getSimpleName());
}
strb.append(')');
@@ -820,7 +820,7 @@
* @param method the method name
* @return the error message
*/
- public static String methodError(JexlNode node, String method) {
+ public static String methodError(final JexlNode node, final String method) {
return methodError(node, method, null);
}
@@ -832,8 +832,8 @@
* @param args the method arguments
* @return the error message
*/
- public static String methodError(JexlNode node, String method, Object[] args) {
- StringBuilder msg = errorAt(node);
+ public static String methodError(final JexlNode node, final String method, final Object[] args) {
+ final StringBuilder msg = errorAt(node);
msg.append("unsolvable function/method '");
msg.append(methodSignature(method, args));
msg.append('\'');
@@ -853,7 +853,7 @@
* @param symbol the operator name
* @param cause the exception causing the error
*/
- public Operator(JexlNode node, String symbol, Throwable cause) {
+ public Operator(final JexlNode node, final String symbol, final Throwable cause) {
super(node, symbol, cause);
}
@@ -877,8 +877,8 @@
* @param symbol the operator name
* @return the error message
*/
- public static String operatorError(JexlNode node, String symbol) {
- StringBuilder msg = errorAt(node);
+ public static String operatorError(final JexlNode node, final String symbol) {
+ final StringBuilder msg = errorAt(node);
msg.append("error calling operator '");
msg.append(symbol);
msg.append('\'');
@@ -898,7 +898,7 @@
* @param name the annotation name
* @param cause the exception causing the error
*/
- public Annotation(JexlNode node, String name, Throwable cause) {
+ public Annotation(final JexlNode node, final String name, final Throwable cause) {
super(node, name, cause);
}
@@ -923,8 +923,8 @@
* @return the error message
* @since 3.1
*/
- public static String annotationError(JexlNode node, String annotation) {
- StringBuilder msg = errorAt(node);
+ public static String annotationError(final JexlNode node, final String annotation) {
+ final StringBuilder msg = errorAt(node);
msg.append("error processing annotation '");
msg.append(annotation);
msg.append('\'');
@@ -948,7 +948,7 @@
* @param msg the message
* @param value the returned value
*/
- public Return(JexlNode node, String msg, Object value) {
+ public Return(final JexlNode node, final String msg, final Object value) {
super(node, msg, null);
this.result = value;
}
@@ -972,7 +972,7 @@
*
* @param node the node where the interruption was detected
*/
- public Cancel(JexlNode node) {
+ public Cancel(final JexlNode node) {
super(node, "execution cancelled", null);
}
}
@@ -988,7 +988,7 @@
*
* @param node the break
*/
- public Break(JexlNode node) {
+ public Break(final JexlNode node) {
super(node, "break loop", null);
}
}
@@ -1004,7 +1004,7 @@
*
* @param node the continue
*/
- public Continue(JexlNode node) {
+ public Continue(final JexlNode node) {
super(node, "continue loop", null);
}
}
@@ -1020,7 +1020,7 @@
* Creates a new instance.
* @param xany the original invocation target exception
*/
- private TryFailed(InvocationTargetException xany) {
+ private TryFailed(final InvocationTargetException xany) {
super((JexlInfo) null, "tryFailed", xany.getCause());
}
}
@@ -1031,8 +1031,8 @@
* @param xinvoke the invocation exception
* @return a JexlException
*/
- public static JexlException tryFailed(InvocationTargetException xinvoke) {
- Throwable cause = xinvoke.getCause();
+ public static JexlException tryFailed(final InvocationTargetException xinvoke) {
+ final Throwable cause = xinvoke.getCause();
return cause instanceof JexlException
? (JexlException) cause
: new JexlException.TryFailed(xinvoke); // fail
@@ -1052,7 +1052,7 @@
*/
@Override
public String getMessage() {
- StringBuilder msg = new StringBuilder();
+ final StringBuilder msg = new StringBuilder();
if (info != null) {
msg.append(info.toString());
} else {
@@ -1060,7 +1060,7 @@
}
msg.append(' ');
msg.append(detailedMessage());
- Throwable cause = getCause();
+ final Throwable cause = getCause();
if (cause instanceof JexlArithmetic.NullOperand) {
msg.append(" caused by null operand");
}
diff --git a/src/main/java/org/apache/commons/jexl3/JexlFeatures.java b/src/main/java/org/apache/commons/jexl3/JexlFeatures.java
index 2c8dd29..ecceca4 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlFeatures.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlFeatures.java
@@ -112,7 +112,7 @@
* Copy constructor.
* @param features the feature to copy from
*/
- public JexlFeatures(JexlFeatures features) {
+ public JexlFeatures(final JexlFeatures features) {
this.flags = features.flags;
this.reservedNames = features.reservedNames;
}
@@ -126,7 +126,7 @@
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
@@ -151,7 +151,7 @@
* @param feature the feature number
* @return the feature name
*/
- public static String stringify(int feature) {
+ public static String stringify(final int feature) {
return feature >= 0 && feature < F_NAMES.length ? F_NAMES[feature] : "unsupported feature";
}
@@ -160,7 +160,7 @@
* @param names the names to reserve
* @return this features instance
*/
- public JexlFeatures reservedNames(Collection<String> names) {
+ public JexlFeatures reservedNames(final Collection<String> names) {
if (names == null || names.isEmpty()) {
reservedNames = Collections.emptySet();
} else {
@@ -182,7 +182,7 @@
* @param name the name to check
* @return true if reserved, false otherwise
*/
- public boolean isReservedName(String name) {
+ public boolean isReservedName(final String name) {
return name != null && reservedNames.contains(name);
}
@@ -191,7 +191,7 @@
* @param feature the feature ordinal
* @param flag turn-on, turn off
*/
- private void setFeature(int feature, boolean flag) {
+ private void setFeature(final int feature, final boolean flag) {
if (flag) {
flags |= (1 << feature);
} else {
@@ -204,7 +204,7 @@
* @param feature feature ordinal
* @return true if on, false if off
*/
- private boolean getFeature(int feature) {
+ private boolean getFeature(final int feature) {
return (flags & (1L << feature)) != 0L;
}
@@ -217,7 +217,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures register(boolean flag) {
+ public JexlFeatures register(final boolean flag) {
setFeature(REGISTER, flag);
return this;
}
@@ -237,7 +237,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures localVar(boolean flag) {
+ public JexlFeatures localVar(final boolean flag) {
setFeature(LOCAL_VAR, flag);
return this;
}
@@ -257,7 +257,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures sideEffectGlobal(boolean flag) {
+ public JexlFeatures sideEffectGlobal(final boolean flag) {
setFeature(SIDE_EFFECT_GLOBAL, flag);
return this;
}
@@ -277,7 +277,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures sideEffect(boolean flag) {
+ public JexlFeatures sideEffect(final boolean flag) {
setFeature(SIDE_EFFECT, flag);
return this;
}
@@ -297,7 +297,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures arrayReferenceExpr(boolean flag) {
+ public JexlFeatures arrayReferenceExpr(final boolean flag) {
setFeature(ARRAY_REF_EXPR, flag);
return this;
}
@@ -317,7 +317,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures methodCall(boolean flag) {
+ public JexlFeatures methodCall(final boolean flag) {
setFeature(METHOD_CALL, flag);
return this;
}
@@ -337,7 +337,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures structuredLiteral(boolean flag) {
+ public JexlFeatures structuredLiteral(final boolean flag) {
setFeature(STRUCTURED_LITERAL, flag);
return this;
}
@@ -357,7 +357,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures newInstance(boolean flag) {
+ public JexlFeatures newInstance(final boolean flag) {
setFeature(NEW_INSTANCE, flag);
return this;
}
@@ -377,7 +377,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures loops(boolean flag) {
+ public JexlFeatures loops(final boolean flag) {
setFeature(LOOP, flag);
return this;
}
@@ -397,7 +397,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures lambda(boolean flag) {
+ public JexlFeatures lambda(final boolean flag) {
setFeature(LAMBDA, flag);
return this;
}
@@ -417,7 +417,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures pragma(boolean flag) {
+ public JexlFeatures pragma(final boolean flag) {
setFeature(PRAGMA, flag);
return this;
}
@@ -437,7 +437,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures annotation(boolean flag) {
+ public JexlFeatures annotation(final boolean flag) {
setFeature(ANNOTATION, flag);
return this;
}
@@ -457,7 +457,7 @@
* @param flag true to enable, false to disable
* @return this features instance
*/
- public JexlFeatures script(boolean flag) {
+ public JexlFeatures script(final boolean flag) {
setFeature(SCRIPT, flag);
return this;
}
@@ -483,7 +483,7 @@
* @param flag true means syntactic lexical function scope is in effect, false implies non-lexical scoping
* @return this features instance
*/
- public JexlFeatures lexical(boolean flag) {
+ public JexlFeatures lexical(final boolean flag) {
setFeature(LEXICAL, flag);
return this;
}
@@ -500,7 +500,7 @@
* @param flag true means syntactic lexical shade is in effect and implies lexical scope
* @return this features instance
*/
- public JexlFeatures lexicalShade(boolean flag) {
+ public JexlFeatures lexicalShade(final boolean flag) {
setFeature(LEXICAL_SHADE, flag);
if (flag) {
setFeature(LEXICAL, true);
diff --git a/src/main/java/org/apache/commons/jexl3/JexlInfo.java b/src/main/java/org/apache/commons/jexl3/JexlInfo.java
index b454159..58b97c3 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlInfo.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlInfo.java
@@ -70,7 +70,7 @@
* @param l line number
* @param c column number
*/
- public JexlInfo(String source, int l, int c) {
+ public JexlInfo(final String source, final int l, final int c) {
name = source;
line = l;
column = c;
@@ -82,13 +82,13 @@
* outside of o.a.c.jexl3.</p>
*/
public JexlInfo() {
- StackTraceElement[] stack = new Throwable().getStackTrace();
+ final StackTraceElement[] stack = new Throwable().getStackTrace();
String cname = getClass().getName();
- String pkgname = getClass().getPackage().getName();
+ final String pkgname = getClass().getPackage().getName();
StackTraceElement se = null;
for (int s = 1; s < stack.length; ++s) {
se = stack[s];
- String className = se.getClassName();
+ final String className = se.getClassName();
if (!className.equals(cname)) {
// go deeper if called from jexl implementation classes
if (className.startsWith(pkgname + ".internal.")
@@ -114,7 +114,7 @@
* @param c the column
* @return a new info instance
*/
- public JexlInfo at(int l, int c) {
+ public JexlInfo at(final int l, final int c) {
return new JexlInfo(name, l, c);
}
@@ -123,7 +123,7 @@
*
* @param copy the instance to copy
*/
- protected JexlInfo(JexlInfo copy) {
+ protected JexlInfo(final JexlInfo copy) {
name = copy.getName();
line = copy.getLine();
column = copy.getColumn();
@@ -136,7 +136,7 @@
*/
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(name != null? name : "");
+ final StringBuilder sb = new StringBuilder(name != null? name : "");
if (line > 0) {
sb.append("@");
sb.append(line);
@@ -145,7 +145,7 @@
sb.append(column);
}
}
- JexlInfo.Detail dbg = getDetail();
+ final JexlInfo.Detail dbg = getDetail();
if (dbg!= null) {
sb.append("![");
sb.append(dbg.start());
@@ -197,7 +197,7 @@
* @param script the script
* @return the info
*/
- public static JexlInfo from(JexlScript script) {
+ public static JexlInfo from(final JexlScript script) {
return script instanceof Script? ((Script) script).getInfo() : null;
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/JexlOperator.java b/src/main/java/org/apache/commons/jexl3/JexlOperator.java
index 7cbaaba..6f21e41 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlOperator.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlOperator.java
@@ -343,7 +343,7 @@
* @param m the method name associated to this operator in a JexlArithmetic
* @param argc the number of parameters for the method
*/
- JexlOperator(String o, String m, int argc) {
+ JexlOperator(final String o, final String m, final int argc) {
this.operator = o;
this.methodName = m;
this.arity = argc;
@@ -357,7 +357,7 @@
* @param m the method name associated to this operator in a JexlArithmetic
* @param b the base operator, ie + for +=
*/
- JexlOperator(String o, String m, JexlOperator b) {
+ JexlOperator(final String o, final String m, final JexlOperator b) {
this.operator = o;
this.methodName = m;
this.arity = 2;
diff --git a/src/main/java/org/apache/commons/jexl3/JexlOptions.java b/src/main/java/org/apache/commons/jexl3/JexlOptions.java
index e54985e..62666b9 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlOptions.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlOptions.java
@@ -80,7 +80,7 @@
* @param value true or false
* @return the new flags mask value
*/
- private static int set(int ordinal, int mask, boolean value) {
+ private static int set(final int ordinal, final int mask, final boolean value) {
return value? mask | (1 << ordinal) : mask & ~(1 << ordinal);
}
@@ -90,7 +90,7 @@
* @param mask the flags mask
* @return the mask value with this flag or-ed in
*/
- private static boolean isSet(int ordinal, int mask) {
+ private static boolean isSet(final int ordinal, final int mask) {
return (mask & 1 << ordinal) != 0;
}
@@ -111,7 +111,7 @@
* may ease validating JEXL3.2 in your environment.
* @param flags the flags to set
*/
- public static void setDefaultFlags(String...flags) {
+ public static void setDefaultFlags(final String...flags) {
DEFAULT = parseFlags(DEFAULT, flags);
}
@@ -124,7 +124,7 @@
* @param flags the flags to set
* @return the flag mask updated
*/
- public static int parseFlags(int mask, String...flags) {
+ public static int parseFlags(int mask, final String...flags) {
for(String name : flags) {
boolean b = true;
if (name.charAt(0) == '+') {
@@ -151,7 +151,7 @@
* Sets this option flags using the +/- syntax.
* @param opts the option flags
*/
- public void setFlags(String[] opts) {
+ public void setFlags(final String[] opts) {
flags = parseFlags(flags, opts);
}
@@ -253,7 +253,7 @@
* context.
* @param flag true if antish variables are solved, false otherwise
*/
- public void setAntish(boolean flag) {
+ public void setAntish(final boolean flag) {
flags = set(ANTISH, flags, flag);
}
@@ -262,7 +262,7 @@
* null (false) when interrupted during evaluation.
* @param flag true when cancellable, false otherwise
*/
- public void setCancellable(boolean flag) {
+ public void setCancellable(final boolean flag) {
flags = set(CANCELLABLE, flags, flag);
}
@@ -271,7 +271,7 @@
* evaluation.
* @param flag true if lexical scope is used, false otherwise
*/
- public void setLexical(boolean flag) {
+ public void setLexical(final boolean flag) {
flags = set(LEXICAL, flags, flag);
}
@@ -282,7 +282,7 @@
* If setting to lexical shade, lexical scope is also set.
* @param flag true if creation is allowed, false otherwise
*/
- public void setLexicalShade(boolean flag) {
+ public void setLexicalShade(final boolean flag) {
flags = set(SHADE, flags, flag);
if (flag) {
flags = set(LEXICAL, flags, true);
@@ -293,7 +293,7 @@
* Sets the arithmetic math context.
* @param mcontext the context
*/
- public void setMathContext(MathContext mcontext) {
+ public void setMathContext(final MathContext mcontext) {
this.mathContext = mcontext;
}
@@ -301,7 +301,7 @@
* Sets the arithmetic math scale.
* @param mscale the scale
*/
- public void setMathScale(int mscale) {
+ public void setMathScale(final int mscale) {
this.mathScale = mscale;
}
@@ -310,7 +310,7 @@
* during evaluation.
* @param flag true if safe, false otherwise
*/
- public void setSafe(boolean flag) {
+ public void setSafe(final boolean flag) {
flags = set(SAFE, flags, flag);
}
@@ -319,7 +319,7 @@
* is encountered during evaluation.
* @param flag true if silent, false otherwise
*/
- public void setSilent(boolean flag) {
+ public void setSilent(final boolean flag) {
flags = set(SILENT, flags, flag);
}
@@ -328,7 +328,7 @@
* constructors as errors during evaluation.
* @param flag true if strict, false otherwise
*/
- public void setStrict(boolean flag) {
+ public void setStrict(final boolean flag) {
flags = set(STRICT, flags, flag);
}
@@ -336,7 +336,7 @@
* Sets the strict arithmetic flag.
* @param stricta true or false
*/
- public void setStrictArithmetic(boolean stricta) {
+ public void setStrictArithmetic(final boolean stricta) {
this.strictArithmetic = stricta;
}
@@ -346,7 +346,7 @@
* instead of copied.
* @param flag true if shared, false if not
*/
- public void setSharedInstance(boolean flag) {
+ public void setSharedInstance(final boolean flag) {
flags = set(SHARED, flags, flag);
}
@@ -363,7 +363,7 @@
* @param jexl the engine
* @return this instance
*/
- public JexlOptions set(JexlEngine jexl) {
+ public JexlOptions set(final JexlEngine jexl) {
if (jexl instanceof Engine) {
((Engine) jexl).optionsSet(this);
}
@@ -375,7 +375,7 @@
* @param src the options
* @return this instance
*/
- public JexlOptions set(JexlOptions src) {
+ public JexlOptions set(final JexlOptions src) {
mathContext = src.mathContext;
mathScale = src.mathScale;
strictArithmetic = src.strictArithmetic;
@@ -396,7 +396,7 @@
* Sets the optional map of namespaces.
* @param ns a namespaces map
*/
- public void setNamespaces(Map<String, Object> ns) {
+ public void setNamespaces(final Map<String, Object> ns) {
this.namespaces = ns == null? Collections.emptyMap() : ns;
}
diff --git a/src/main/java/org/apache/commons/jexl3/JxltEngine.java b/src/main/java/org/apache/commons/jexl3/JxltEngine.java
index f32b551f..e16f83b 100644
--- a/src/main/java/org/apache/commons/jexl3/JxltEngine.java
+++ b/src/main/java/org/apache/commons/jexl3/JxltEngine.java
@@ -55,7 +55,7 @@
* @param msg the exception message
* @param cause the exception cause
*/
- public Exception(JexlInfo info, String msg, Throwable cause) {
+ public Exception(final JexlInfo info, final String msg, final Throwable cause) {
super(info, msg, cause);
}
}
@@ -213,7 +213,7 @@
* @return the {@link Expression}, null if silent and an error occurred
* @throws Exception if an error occurs and the {@link JexlEngine} is not silent
*/
- public Expression createExpression(String expression) {
+ public Expression createExpression(final String expression) {
return createExpression(null, expression);
}
@@ -355,7 +355,7 @@
* @param source the source
* @return the template
*/
- public Template createTemplate(JexlInfo info, String source, String... parms) {
+ public Template createTemplate(final JexlInfo info, final String source, final String... parms) {
return createTemplate(info, "$$", new StringReader(source), parms);
}
@@ -366,7 +366,7 @@
* @param source the source
* @return the template
*/
- public Template createTemplate(JexlInfo info, String source) {
+ public Template createTemplate(final JexlInfo info, final String source) {
return createTemplate(info, "$$", new StringReader(source), (String[]) null);
}
@@ -378,7 +378,7 @@
* @param parms the parameter names
* @return the template
*/
- public Template createTemplate(String prefix, Reader source, String... parms) {
+ public Template createTemplate(final String prefix, final Reader source, final String... parms) {
return createTemplate(null, prefix, source, parms);
}
@@ -389,7 +389,7 @@
* @param parms the parameter names
* @return the template
*/
- public Template createTemplate(String source, String... parms) {
+ public Template createTemplate(final String source, final String... parms) {
return createTemplate(null, source, parms);
}
@@ -399,7 +399,7 @@
* @param source the source
* @return the template
*/
- public Template createTemplate(String source) {
+ public Template createTemplate(final String source) {
return createTemplate(null, source);
}
diff --git a/src/main/java/org/apache/commons/jexl3/MapContext.java b/src/main/java/org/apache/commons/jexl3/MapContext.java
index dbaaf8a..c3bbccc 100644
--- a/src/main/java/org/apache/commons/jexl3/MapContext.java
+++ b/src/main/java/org/apache/commons/jexl3/MapContext.java
@@ -43,22 +43,22 @@
*
* @param vars the variable map
*/
- public MapContext(Map<String, Object> vars) {
+ public MapContext(final Map<String, Object> vars) {
map = vars == null ? new HashMap<String, Object>() : vars;
}
@Override
- public boolean has(String name) {
+ public boolean has(final String name) {
return map.containsKey(name);
}
@Override
- public Object get(String name) {
+ public Object get(final String name) {
return map.get(name);
}
@Override
- public void set(String name, Object value) {
+ public void set(final String name, final Object value) {
map.put(name, value);
}
diff --git a/src/main/java/org/apache/commons/jexl3/ObjectContext.java b/src/main/java/org/apache/commons/jexl3/ObjectContext.java
index 9217935..b378659 100644
--- a/src/main/java/org/apache/commons/jexl3/ObjectContext.java
+++ b/src/main/java/org/apache/commons/jexl3/ObjectContext.java
@@ -53,18 +53,18 @@
* @param engine the jexl engine to use to solve properties
* @param wrapped the object to wrap in this context
*/
- public ObjectContext(JexlEngine engine, T wrapped) {
+ public ObjectContext(final JexlEngine engine, final T wrapped) {
this.jexl = engine;
this.object = wrapped;
}
@Override
- public Object get(String name) {
- JexlPropertyGet jget = jexl.getUberspect().getPropertyGet(object, name);
+ public Object get(final String name) {
+ final JexlPropertyGet jget = jexl.getUberspect().getPropertyGet(object, name);
if (jget != null) {
try {
return jget.invoke(object);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
if (jexl.isStrict()) {
throw new JexlException.Property(null, name, true, xany);
}
@@ -74,12 +74,12 @@
}
@Override
- public void set(String name, Object value) {
- JexlPropertySet jset = jexl.getUberspect().getPropertySet(object, name, value);
+ public void set(final String name, final Object value) {
+ final JexlPropertySet jset = jexl.getUberspect().getPropertySet(object, name, value);
if (jset != null) {
try {
jset.invoke(object, value);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
// ignore
if (jexl.isStrict()) {
throw new JexlException.Property(null, name, true, xany);
@@ -89,17 +89,17 @@
}
@Override
- public boolean has(String name) {
- JexlPropertyGet jget = jexl.getUberspect().getPropertyGet(object, name);
+ public boolean has(final String name) {
+ final JexlPropertyGet jget = jexl.getUberspect().getPropertyGet(object, name);
try {
return jget != null && jget.invoke(object) != null;
- } catch (Exception xany) {
+ } catch (final Exception xany) {
return false;
}
}
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
if (name == null || name.isEmpty()) {
return object;
} else {
diff --git a/src/main/java/org/apache/commons/jexl3/internal/ArrayBuilder.java b/src/main/java/org/apache/commons/jexl3/internal/ArrayBuilder.java
index da1ffbb..5ad472c 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/ArrayBuilder.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/ArrayBuilder.java
@@ -50,8 +50,8 @@
* @param parm a class
* @return the primitive type or null it the argument is not unboxable
*/
- protected static Class<?> unboxingClass(Class<?> parm) {
- Class<?> prim = BOXING_CLASSES.get(parm);
+ protected static Class<?> unboxingClass(final Class<?> parm) {
+ final Class<?> prim = BOXING_CLASSES.get(parm);
return prim == null ? parm : prim;
}
@@ -70,12 +70,12 @@
* Creates a new builder.
* @param size the exact array size
*/
- public ArrayBuilder(int size) {
+ public ArrayBuilder(final int size) {
untyped = new Object[size];
}
@Override
- public void add(Object value) {
+ public void add(final Object value) {
// for all children after first...
if (!Object.class.equals(commonClass)) {
if (value == null) {
@@ -111,10 +111,10 @@
}
@Override
- public Object create(boolean extended) {
+ public Object create(final boolean extended) {
if (untyped != null) {
if (extended) {
- List<Object> list = new ArrayList<Object>(added);
+ final List<Object> list = new ArrayList<Object>(added);
list.addAll(Arrays.asList(untyped).subList(0, added));
return list;
}
@@ -126,7 +126,7 @@
commonClass = unboxingClass(commonClass);
}
// allocate and fill up the typed array
- Object typed = Array.newInstance(commonClass, size);
+ final Object typed = Array.newInstance(commonClass, size);
for (int i = 0; i < size; ++i) {
Array.set(typed, i, untyped[i]);
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Closure.java b/src/main/java/org/apache/commons/jexl3/internal/Closure.java
index 091129b..18ae8e1 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Closure.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Closure.java
@@ -33,7 +33,7 @@
* @param theCaller the calling interpreter
* @param lambda the lambda
*/
- protected Closure(Interpreter theCaller, ASTJexlLambda lambda) {
+ protected Closure(final Interpreter theCaller, final ASTJexlLambda lambda) {
super(theCaller.jexl, null, lambda);
frame = lambda.createFrame(theCaller.frame);
}
@@ -43,9 +43,9 @@
* @param base the base script
* @param args the script arguments
*/
- protected Closure(Script base, Object[] args) {
+ protected Closure(final Script base, final Object[] args) {
super(base.jexl, base.source, base.script);
- Frame sf = (base instanceof Closure) ? ((Closure) base).frame : null;
+ final Frame sf = (base instanceof Closure) ? ((Closure) base).frame : null;
frame = sf == null
? script.createFrame(args)
: sf.assign(args);
@@ -63,7 +63,7 @@
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
@@ -97,12 +97,12 @@
* @param symbol the symbol index (in the caller of this closure)
* @param value the value to set in the local frame
*/
- public void setCaptured(int symbol, Object value) {
+ public void setCaptured(final int symbol, final Object value) {
if (script instanceof ASTJexlLambda) {
- ASTJexlLambda lambda = (ASTJexlLambda) script;
- Scope scope = lambda.getScope();
+ final ASTJexlLambda lambda = (ASTJexlLambda) script;
+ final Scope scope = lambda.getScope();
if (scope != null) {
- Integer reg = scope.getCaptured(symbol);
+ final Integer reg = scope.getCaptured(symbol);
if (reg != null) {
frame.set(reg, value);
}
@@ -111,25 +111,25 @@
}
@Override
- public Object evaluate(JexlContext context) {
+ public Object evaluate(final JexlContext context) {
return execute(context, (Object[])null);
}
@Override
- public Object execute(JexlContext context) {
+ public Object execute(final JexlContext context) {
return execute(context, (Object[])null);
}
@Override
- public Object execute(JexlContext context, Object... args) {
- Frame local = frame != null? frame.assign(args) : null;
- Interpreter interpreter = createInterpreter(context, local);
+ public Object execute(final JexlContext context, final Object... args) {
+ final Frame local = frame != null? frame.assign(args) : null;
+ final Interpreter interpreter = createInterpreter(context, local);
return interpreter.runClosure(this, null);
}
@Override
- public Callable callable(JexlContext context, Object... args) {
- Frame local = frame != null? frame.assign(args) : null;
+ public Callable callable(final JexlContext context, final Object... args) {
+ final Frame local = frame != null? frame.assign(args) : null;
return new Callable(createInterpreter(context, local)) {
@Override
public Object interpret() {
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Debugger.java b/src/main/java/org/apache/commons/jexl3/internal/Debugger.java
index 28ef4b6..4a024e0 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Debugger.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Debugger.java
@@ -149,7 +149,7 @@
* @param jscript the expression
* @return true if the expression was a {@link Script} instance, false otherwise
*/
- public boolean debug(JexlExpression jscript) {
+ public boolean debug(final JexlExpression jscript) {
if (jscript instanceof Script) {
return debug(((Script) jscript).script);
} else {
@@ -162,7 +162,7 @@
* @param jscript the script
* @return true if the script was a {@link Script} instance, false otherwise
*/
- public boolean debug(JexlScript jscript) {
+ public boolean debug(final JexlScript jscript) {
if (jscript instanceof Script) {
return debug(((Script) jscript).script);
} else {
@@ -175,7 +175,7 @@
* @param node the node to debug
* @return true if the cause was located, false otherwise
*/
- public boolean debug(JexlNode node) {
+ public boolean debug(final JexlNode node) {
return debug(node, true);
}
@@ -185,7 +185,7 @@
* @param r whether we should actively find the root node of the debugged node
* @return true if the cause was located, false otherwise
*/
- public boolean debug(JexlNode node, boolean r) {
+ public boolean debug(final JexlNode node, final boolean r) {
start = 0;
end = 0;
indentLevel = 0;
@@ -218,7 +218,7 @@
* @return the rebuilt expression
* @since 3.0
*/
- public String data(JexlNode node) {
+ public String data(final JexlNode node) {
start = 0;
end = 0;
indentLevel = 0;
@@ -250,7 +250,7 @@
* Sets the indentation level.
* @param level the number of spaces for indentation, none if less or equal to zero
*/
- public void setIndentation(int level) {
+ public void setIndentation(final int level) {
indentation(level);
}
@@ -259,7 +259,7 @@
* @param level the number of spaces for indentation, none if less or equal to zero
* @return this debugger instance
*/
- public Debugger indentation(int level) {
+ public Debugger indentation(final int level) {
indent = Math.max(level, 0);
indentLevel = 0;
return this;
@@ -270,7 +270,7 @@
* @param rdepth the maximum relative depth from the debugged node
* @return this debugger instance
*/
- public Debugger depth(int rdepth) {
+ public Debugger depth(final int rdepth) {
this.depth = rdepth;
return this;
}
@@ -281,7 +281,7 @@
* @param data visitor pattern argument
* @return visitor pattern value
*/
- protected Object accept(JexlNode node, Object data) {
+ protected Object accept(final JexlNode node, final Object data) {
if (depth <= 0) {
builder.append("...");
return data;
@@ -290,7 +290,7 @@
start = builder.length();
}
depth -= 1;
- Object value = node.jjtAccept(this, data);
+ final Object value = node.jjtAccept(this, data);
depth += 1;
if (node == cause) {
end = builder.length();
@@ -304,8 +304,8 @@
* @param data visitor pattern argument
* @return visitor pattern value
*/
- protected Object acceptStatement(JexlNode child, Object data) {
- JexlNode parent = child.jjtGetParent();
+ protected Object acceptStatement(final JexlNode child, final Object data) {
+ final JexlNode parent = child.jjtGetParent();
if (indent > 0 && (parent instanceof ASTBlock || parent instanceof ASTJexlScript)) {
for (int i = 0; i < indentLevel; ++i) {
for(int s = 0; s < indent; ++s) {
@@ -314,7 +314,7 @@
}
}
depth -= 1;
- Object value = accept(child, data);
+ final Object value = accept(child, data);
depth += 1;
// blocks, if, for & while dont need a ';' at end
if (!(child instanceof ASTJexlScript
@@ -341,7 +341,7 @@
* @param data visitor pattern argument
* @return visitor pattern value
*/
- protected Object check(JexlNode node, String image, Object data) {
+ protected Object check(final JexlNode node, final String image, final Object data) {
if (node == cause) {
start = builder.length();
}
@@ -365,8 +365,8 @@
* @param data visitor pattern argument
* @return visitor pattern value
*/
- protected Object infixChildren(JexlNode node, String infix, boolean paren, Object data) {
- int num = node.jjtGetNumChildren(); //child.jjtGetNumChildren() > 1;
+ protected Object infixChildren(final JexlNode node, final String infix, final boolean paren, final Object data) {
+ final int num = node.jjtGetNumChildren(); //child.jjtGetNumChildren() > 1;
if (paren) {
builder.append('(');
}
@@ -390,8 +390,8 @@
* @param data visitor pattern argument
* @return visitor pattern value
*/
- protected Object prefixChild(JexlNode node, String prefix, Object data) {
- boolean paren = node.jjtGetChild(0).jjtGetNumChildren() > 1;
+ protected Object prefixChild(final JexlNode node, final String prefix, final Object data) {
+ final boolean paren = node.jjtGetChild(0).jjtGetNumChildren() > 1;
builder.append(prefix);
if (paren) {
builder.append('(');
@@ -404,12 +404,12 @@
}
@Override
- protected Object visit(ASTAddNode node, Object data) {
+ protected Object visit(final ASTAddNode node, final Object data) {
return additiveNode(node, " + ", data);
}
@Override
- protected Object visit(ASTSubNode node, Object data) {
+ protected Object visit(final ASTSubNode node, final Object data) {
return additiveNode(node, " - ", data);
}
@@ -420,12 +420,12 @@
* @param data visitor pattern argument
* @return visitor pattern value
*/
- protected Object additiveNode(JexlNode node, String op, Object data) {
+ protected Object additiveNode(final JexlNode node, final String op, final Object data) {
// need parenthesis if not in operator precedence order
- boolean paren = node.jjtGetParent() instanceof ASTMulNode
+ final boolean paren = node.jjtGetParent() instanceof ASTMulNode
|| node.jjtGetParent() instanceof ASTDivNode
|| node.jjtGetParent() instanceof ASTModNode;
- int num = node.jjtGetNumChildren();
+ final int num = node.jjtGetNumChildren();
if (paren) {
builder.append('(');
}
@@ -441,13 +441,13 @@
}
@Override
- protected Object visit(ASTAndNode node, Object data) {
+ protected Object visit(final ASTAndNode node, final Object data) {
return infixChildren(node, " && ", false, data);
}
@Override
- protected Object visit(ASTArrayAccess node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTArrayAccess node, final Object data) {
+ final int num = node.jjtGetNumChildren();
for (int i = 0; i < num; ++i) {
builder.append('[');
accept(node.jjtGetChild(i), data);
@@ -457,14 +457,14 @@
}
@Override
- protected Object visit(ASTExtendedLiteral node, Object data) {
+ protected Object visit(final ASTExtendedLiteral node, final Object data) {
builder.append("...");
return data;
}
@Override
- protected Object visit(ASTArrayLiteral node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTArrayLiteral node, final Object data) {
+ final int num = node.jjtGetNumChildren();
builder.append("[ ");
if (num > 0) {
accept(node.jjtGetChild(0), data);
@@ -478,39 +478,39 @@
}
@Override
- protected Object visit(ASTRangeNode node, Object data) {
+ protected Object visit(final ASTRangeNode node, final Object data) {
return infixChildren(node, " .. ", false, data);
}
@Override
- protected Object visit(ASTAssignment node, Object data) {
+ protected Object visit(final ASTAssignment node, final Object data) {
return infixChildren(node, " = ", false, data);
}
@Override
- protected Object visit(ASTBitwiseAndNode node, Object data) {
+ protected Object visit(final ASTBitwiseAndNode node, final Object data) {
return infixChildren(node, " & ", false, data);
}
@Override
- protected Object visit(ASTBitwiseComplNode node, Object data) {
+ protected Object visit(final ASTBitwiseComplNode node, final Object data) {
return prefixChild(node, "~", data);
}
@Override
- protected Object visit(ASTBitwiseOrNode node, Object data) {
- boolean paren = node.jjtGetParent() instanceof ASTBitwiseAndNode;
+ protected Object visit(final ASTBitwiseOrNode node, final Object data) {
+ final boolean paren = node.jjtGetParent() instanceof ASTBitwiseAndNode;
return infixChildren(node, " | ", paren, data);
}
@Override
- protected Object visit(ASTBitwiseXorNode node, Object data) {
- boolean paren = node.jjtGetParent() instanceof ASTBitwiseAndNode;
+ protected Object visit(final ASTBitwiseXorNode node, final Object data) {
+ final boolean paren = node.jjtGetParent() instanceof ASTBitwiseAndNode;
return infixChildren(node, " ^ ", paren, data);
}
@Override
- protected Object visit(ASTBlock node, Object data) {
+ protected Object visit(final ASTBlock node, final Object data) {
builder.append('{');
if (indent > 0) {
indentLevel += 1;
@@ -518,9 +518,9 @@
} else {
builder.append(' ');
}
- int num = node.jjtGetNumChildren();
+ final int num = node.jjtGetNumChildren();
for (int i = 0; i < num; ++i) {
- JexlNode child = node.jjtGetChild(i);
+ final JexlNode child = node.jjtGetChild(i);
acceptStatement(child, data);
}
if (indent > 0) {
@@ -536,64 +536,64 @@
}
@Override
- protected Object visit(ASTDivNode node, Object data) {
+ protected Object visit(final ASTDivNode node, final Object data) {
return infixChildren(node, " / ", false, data);
}
@Override
- protected Object visit(ASTEmptyFunction node, Object data) {
+ protected Object visit(final ASTEmptyFunction node, final Object data) {
builder.append("empty ");
accept(node.jjtGetChild(0), data);
return data;
}
@Override
- protected Object visit(ASTEQNode node, Object data) {
+ protected Object visit(final ASTEQNode node, final Object data) {
return infixChildren(node, " == ", false, data);
}
@Override
- protected Object visit(ASTERNode node, Object data) {
+ protected Object visit(final ASTERNode node, final Object data) {
return infixChildren(node, " =~ ", false, data);
}
@Override
- protected Object visit(ASTSWNode node, Object data) {
+ protected Object visit(final ASTSWNode node, final Object data) {
return infixChildren(node, " =^ ", false, data);
}
@Override
- protected Object visit(ASTEWNode node, Object data) {
+ protected Object visit(final ASTEWNode node, final Object data) {
return infixChildren(node, " =$ ", false, data);
}
@Override
- protected Object visit(ASTNSWNode node, Object data) {
+ protected Object visit(final ASTNSWNode node, final Object data) {
return infixChildren(node, " !^ ", false, data);
}
@Override
- protected Object visit(ASTNEWNode node, Object data) {
+ protected Object visit(final ASTNEWNode node, final Object data) {
return infixChildren(node, " !$ ", false, data);
}
@Override
- protected Object visit(ASTFalseNode node, Object data) {
+ protected Object visit(final ASTFalseNode node, final Object data) {
return check(node, "false", data);
}
@Override
- protected Object visit(ASTContinue node, Object data) {
+ protected Object visit(final ASTContinue node, final Object data) {
return check(node, "continue", data);
}
@Override
- protected Object visit(ASTBreak node, Object data) {
+ protected Object visit(final ASTBreak node, final Object data) {
return check(node, "break", data);
}
@Override
- protected Object visit(ASTForeachStatement node, Object data) {
+ protected Object visit(final ASTForeachStatement node, final Object data) {
builder.append("for(");
accept(node.jjtGetChild(0), data);
builder.append(" : ");
@@ -608,12 +608,12 @@
}
@Override
- protected Object visit(ASTGENode node, Object data) {
+ protected Object visit(final ASTGENode node, final Object data) {
return infixChildren(node, " >= ", false, data);
}
@Override
- protected Object visit(ASTGTNode node, Object data) {
+ protected Object visit(final ASTGTNode node, final Object data) {
return infixChildren(node, " > ", false, data);
}
@@ -628,28 +628,28 @@
* @param str the identifier
* @return true if needing quotes, false otherwise
*/
- protected boolean needQuotes(String str) {
+ protected boolean needQuotes(final String str) {
return QUOTED_IDENTIFIER.matcher(str).find()
|| "size".equals(str)
|| "empty".equals(str);
}
@Override
- protected Object visit(ASTIdentifier node, Object data) {
- String ns = node.getNamespace();
- String image = StringParser.escapeIdentifier(node.getName());
+ protected Object visit(final ASTIdentifier node, final Object data) {
+ final String ns = node.getNamespace();
+ final String image = StringParser.escapeIdentifier(node.getName());
if (ns == null) {
return check(node, image, data);
} else {
- String nsid = StringParser.escapeIdentifier(ns) + ":" + image;
+ final String nsid = StringParser.escapeIdentifier(ns) + ":" + image;
return check(node, nsid, data);
}
}
@Override
- protected Object visit(ASTIdentifierAccess node, Object data) {
+ protected Object visit(final ASTIdentifierAccess node, final Object data) {
builder.append(node.isSafe() ? "?." : ".");
- String image = node.getName();
+ final String image = node.getName();
if (node.isExpression()) {
builder.append('`');
builder.append(image.replace("`", "\\`"));
@@ -666,7 +666,7 @@
}
@Override
- protected Object visit(ASTIfStatement node, Object data) {
+ protected Object visit(final ASTIfStatement node, final Object data) {
final int numChildren = node.jjtGetNumChildren();
// if (...) ...
builder.append("if (");
@@ -689,7 +689,7 @@
}
@Override
- protected Object visit(ASTNumberLiteral node, Object data) {
+ protected Object visit(final ASTNumberLiteral node, final Object data) {
return check(node, node.toString(), data);
}
@@ -699,22 +699,22 @@
* @param data the visitor argument
* @return the parameter name to use
*/
- protected String visitParameter(String p, Object data) {
+ protected String visitParameter(final String p, final Object data) {
return p;
}
@Override
- protected Object visit(ASTJexlScript node, Object data) {
+ protected Object visit(final ASTJexlScript node, Object data) {
// if lambda, produce parameters
if (node instanceof ASTJexlLambda) {
- JexlNode parent = node.jjtGetParent();
+ final JexlNode parent = node.jjtGetParent();
// use lambda syntax if not assigned
- boolean named = parent instanceof ASTAssignment;
+ final boolean named = parent instanceof ASTAssignment;
if (named) {
builder.append("function");
}
builder.append('(');
- String[] params = node.getParameters();
+ final String[] params = node.getParameters();
if (params != null && params.length > 0) {
builder.append(visitParameter(params[0], data));
for (int p = 1; p < params.length; ++p) {
@@ -731,12 +731,12 @@
// we will need a block...
}
// no parameters or done with them
- int num = node.jjtGetNumChildren();
+ final int num = node.jjtGetNumChildren();
if (num == 1 && !(node instanceof ASTJexlLambda)) {
data = accept(node.jjtGetChild(0), data);
} else {
for (int i = 0; i < num; ++i) {
- JexlNode child = node.jjtGetChild(i);
+ final JexlNode child = node.jjtGetChild(i);
acceptStatement(child, data);
}
}
@@ -744,17 +744,17 @@
}
@Override
- protected Object visit(ASTLENode node, Object data) {
+ protected Object visit(final ASTLENode node, final Object data) {
return infixChildren(node, " <= ", false, data);
}
@Override
- protected Object visit(ASTLTNode node, Object data) {
+ protected Object visit(final ASTLTNode node, final Object data) {
return infixChildren(node, " < ", false, data);
}
@Override
- protected Object visit(ASTMapEntry node, Object data) {
+ protected Object visit(final ASTMapEntry node, final Object data) {
accept(node.jjtGetChild(0), data);
builder.append(" : ");
accept(node.jjtGetChild(1), data);
@@ -762,8 +762,8 @@
}
@Override
- protected Object visit(ASTSetLiteral node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTSetLiteral node, final Object data) {
+ final int num = node.jjtGetNumChildren();
builder.append("{ ");
if (num > 0) {
accept(node.jjtGetChild(0), data);
@@ -777,8 +777,8 @@
}
@Override
- protected Object visit(ASTMapLiteral node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTMapLiteral node, final Object data) {
+ final int num = node.jjtGetNumChildren();
builder.append("{ ");
if (num > 0) {
accept(node.jjtGetChild(0), data);
@@ -794,8 +794,8 @@
}
@Override
- protected Object visit(ASTConstructorNode node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTConstructorNode node, final Object data) {
+ final int num = node.jjtGetNumChildren();
builder.append("new(");
if (num > 0) {
accept(node.jjtGetChild(0), data);
@@ -809,8 +809,8 @@
}
@Override
- protected Object visit(ASTFunctionNode node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTFunctionNode node, final Object data) {
+ final int num = node.jjtGetNumChildren();
if (num == 3) {
accept(node.jjtGetChild(0), data);
builder.append(":");
@@ -824,8 +824,8 @@
}
@Override
- protected Object visit(ASTMethodNode node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTMethodNode node, final Object data) {
+ final int num = node.jjtGetNumChildren();
if (num == 2) {
accept(node.jjtGetChild(0), data);
accept(node.jjtGetChild(1), data);
@@ -834,8 +834,8 @@
}
@Override
- protected Object visit(ASTArguments node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTArguments node, final Object data) {
+ final int num = node.jjtGetNumChildren();
builder.append("(");
if (num > 0) {
accept(node.jjtGetChild(0), data);
@@ -849,48 +849,48 @@
}
@Override
- protected Object visit(ASTModNode node, Object data) {
+ protected Object visit(final ASTModNode node, final Object data) {
return infixChildren(node, " % ", false, data);
}
@Override
- protected Object visit(ASTMulNode node, Object data) {
+ protected Object visit(final ASTMulNode node, final Object data) {
return infixChildren(node, " * ", false, data);
}
@Override
- protected Object visit(ASTNENode node, Object data) {
+ protected Object visit(final ASTNENode node, final Object data) {
return infixChildren(node, " != ", false, data);
}
@Override
- protected Object visit(ASTNRNode node, Object data) {
+ protected Object visit(final ASTNRNode node, final Object data) {
return infixChildren(node, " !~ ", false, data);
}
@Override
- protected Object visit(ASTNotNode node, Object data) {
+ protected Object visit(final ASTNotNode node, final Object data) {
builder.append("!");
accept(node.jjtGetChild(0), data);
return data;
}
@Override
- protected Object visit(ASTNullLiteral node, Object data) {
+ protected Object visit(final ASTNullLiteral node, final Object data) {
check(node, "null", data);
return data;
}
@Override
- protected Object visit(ASTOrNode node, Object data) {
+ protected Object visit(final ASTOrNode node, final Object data) {
// need parenthesis if not in operator precedence order
- boolean paren = node.jjtGetParent() instanceof ASTAndNode;
+ final boolean paren = node.jjtGetParent() instanceof ASTAndNode;
return infixChildren(node, " || ", paren, data);
}
@Override
- protected Object visit(ASTReference node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTReference node, final Object data) {
+ final int num = node.jjtGetNumChildren();
for (int i = 0; i < num; ++i) {
accept(node.jjtGetChild(i), data);
}
@@ -898,12 +898,12 @@
}
@Override
- protected Object visit(ASTReferenceExpression node, Object data) {
- JexlNode first = node.jjtGetChild(0);
+ protected Object visit(final ASTReferenceExpression node, final Object data) {
+ final JexlNode first = node.jjtGetChild(0);
builder.append('(');
accept(first, data);
builder.append(')');
- int num = node.jjtGetNumChildren();
+ final int num = node.jjtGetNumChildren();
for (int i = 1; i < num; ++i) {
builder.append("[");
accept(node.jjtGetChild(i), data);
@@ -913,33 +913,33 @@
}
@Override
- protected Object visit(ASTReturnStatement node, Object data) {
+ protected Object visit(final ASTReturnStatement node, final Object data) {
builder.append("return ");
accept(node.jjtGetChild(0), data);
return data;
}
@Override
- protected Object visit(ASTSizeFunction node, Object data) {
+ protected Object visit(final ASTSizeFunction node, final Object data) {
builder.append("size ");
accept(node.jjtGetChild(0), data);
return data;
}
@Override
- protected Object visit(ASTStringLiteral node, Object data) {
- String img = node.getLiteral().replace("'", "\\'");
+ protected Object visit(final ASTStringLiteral node, final Object data) {
+ final String img = node.getLiteral().replace("'", "\\'");
return check(node, "'" + img + "'", data);
}
@Override
- protected Object visit(ASTRegexLiteral node, Object data) {
- String img = node.toString().replace("/", "\\/");
+ protected Object visit(final ASTRegexLiteral node, final Object data) {
+ final String img = node.toString().replace("/", "\\/");
return check(node, "~/" + img + "/", data);
}
@Override
- protected Object visit(ASTTernaryNode node, Object data) {
+ protected Object visit(final ASTTernaryNode node, final Object data) {
accept(node.jjtGetChild(0), data);
if (node.jjtGetNumChildren() > 2) {
builder.append("? ");
@@ -955,7 +955,7 @@
}
@Override
- protected Object visit(ASTNullpNode node, Object data) {
+ protected Object visit(final ASTNullpNode node, final Object data) {
accept(node.jjtGetChild(0), data);
builder.append("??");
accept(node.jjtGetChild(1), data);
@@ -963,30 +963,30 @@
}
@Override
- protected Object visit(ASTTrueNode node, Object data) {
+ protected Object visit(final ASTTrueNode node, final Object data) {
check(node, "true", data);
return data;
}
@Override
- protected Object visit(ASTUnaryMinusNode node, Object data) {
+ protected Object visit(final ASTUnaryMinusNode node, final Object data) {
return prefixChild(node, "-", data);
}
@Override
- protected Object visit(ASTUnaryPlusNode node, Object data) {
+ protected Object visit(final ASTUnaryPlusNode node, final Object data) {
return prefixChild(node, "+", data);
}
@Override
- protected Object visit(ASTVar node, Object data) {
+ protected Object visit(final ASTVar node, final Object data) {
builder.append("var ");
check(node, node.getName(), data);
return data;
}
@Override
- protected Object visit(ASTWhileStatement node, Object data) {
+ protected Object visit(final ASTWhileStatement node, final Object data) {
builder.append("while (");
accept(node.jjtGetChild(0), data);
builder.append(") ");
@@ -999,9 +999,9 @@
}
@Override
- protected Object visit(ASTDoWhileStatement node, Object data) {
+ protected Object visit(final ASTDoWhileStatement node, final Object data) {
builder.append("do ");
- int nc = node.jjtGetNumChildren();
+ final int nc = node.jjtGetNumChildren();
if (nc > 1) {
acceptStatement(node.jjtGetChild(0), data);
} else {
@@ -1014,54 +1014,54 @@
}
@Override
- protected Object visit(ASTSetAddNode node, Object data) {
+ protected Object visit(final ASTSetAddNode node, final Object data) {
return infixChildren(node, " += ", false, data);
}
@Override
- protected Object visit(ASTSetSubNode node, Object data) {
+ protected Object visit(final ASTSetSubNode node, final Object data) {
return infixChildren(node, " -= ", false, data);
}
@Override
- protected Object visit(ASTSetMultNode node, Object data) {
+ protected Object visit(final ASTSetMultNode node, final Object data) {
return infixChildren(node, " *= ", false, data);
}
@Override
- protected Object visit(ASTSetDivNode node, Object data) {
+ protected Object visit(final ASTSetDivNode node, final Object data) {
return infixChildren(node, " /= ", false, data);
}
@Override
- protected Object visit(ASTSetModNode node, Object data) {
+ protected Object visit(final ASTSetModNode node, final Object data) {
return infixChildren(node, " %= ", false, data);
}
@Override
- protected Object visit(ASTSetAndNode node, Object data) {
+ protected Object visit(final ASTSetAndNode node, final Object data) {
return infixChildren(node, " &= ", false, data);
}
@Override
- protected Object visit(ASTSetOrNode node, Object data) {
+ protected Object visit(final ASTSetOrNode node, final Object data) {
return infixChildren(node, " |= ", false, data);
}
@Override
- protected Object visit(ASTSetXorNode node, Object data) {
+ protected Object visit(final ASTSetXorNode node, final Object data) {
return infixChildren(node, " ^= ", false, data);
}
@Override
- protected Object visit(ASTJxltLiteral node, Object data) {
- String img = node.getLiteral().replace("`", "\\`");
+ protected Object visit(final ASTJxltLiteral node, final Object data) {
+ final String img = node.getLiteral().replace("`", "\\`");
return check(node, "`" + img + "`", data);
}
@Override
- protected Object visit(ASTAnnotation node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTAnnotation node, final Object data) {
+ final int num = node.jjtGetNumChildren();
builder.append('@');
builder.append(node.getName());
if (num > 0) {
@@ -1071,13 +1071,13 @@
}
@Override
- protected Object visit(ASTAnnotatedStatement node, Object data) {
- int num = node.jjtGetNumChildren();
+ protected Object visit(final ASTAnnotatedStatement node, final Object data) {
+ final int num = node.jjtGetNumChildren();
for (int i = 0; i < num; ++i) {
if (i > 0) {// && child instanceof ASTBlock) {
builder.append(' ');
}
- JexlNode child = node.jjtGetChild(i);
+ final JexlNode child = node.jjtGetChild(i);
acceptStatement(child, data);
}
return data;
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Engine.java b/src/main/java/org/apache/commons/jexl3/internal/Engine.java
index ec2e58b..7a2dd3c 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Engine.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Engine.java
@@ -181,7 +181,7 @@
* Creates a JEXL engine using the provided {@link JexlBuilder}.
* @param conf the builder
*/
- public Engine(JexlBuilder conf) {
+ public Engine(final JexlBuilder conf) {
// options:
this.options = conf.options().copy();
this.strict = options.isStrict();
@@ -193,12 +193,12 @@
this.collectMode = conf.collectMode();
this.stackOverflow = conf.stackOverflow() > 0? conf.stackOverflow() : Integer.MAX_VALUE;
// core properties:
- JexlUberspect uber = conf.uberspect() == null ? getUberspect(conf.logger(), conf.strategy()) : conf.uberspect();
- ClassLoader loader = conf.loader();
+ final JexlUberspect uber = conf.uberspect() == null ? getUberspect(conf.logger(), conf.strategy()) : conf.uberspect();
+ final ClassLoader loader = conf.loader();
if (loader != null) {
uber.setClassLoader(loader);
}
- JexlSandbox sandbox = conf.sandbox();
+ final JexlSandbox sandbox = conf.sandbox();
if (sandbox == null) {
this.uberspect = uber;
} else {
@@ -211,7 +211,7 @@
options.setStrictArithmetic(arithmetic.isStrict());
this.functions = conf.namespaces() == null ? Collections.<String, Object>emptyMap() : conf.namespaces();
// parsing & features:
- JexlFeatures features = conf.features() == null? DEFAULT_FEATURES : conf.features();
+ final JexlFeatures features = conf.features() == null? DEFAULT_FEATURES : conf.features();
this.expressionFeatures = new JexlFeatures(features).script(false);
this.scriptFeatures = new JexlFeatures(features).script(true);
this.charset = conf.charset();
@@ -234,7 +234,7 @@
* @param strategy the property resolver strategy
* @return Uberspect the default uberspector instance.
*/
- public static Uberspect getUberspect(Log logger, JexlUberspect.ResolverStrategy strategy) {
+ public static Uberspect getUberspect(final Log logger, final JexlUberspect.ResolverStrategy strategy) {
if ((logger == null || logger.equals(LogFactory.getLog(JexlEngine.class)))
&& (strategy == null || strategy == JexlUberspect.JEXL_STRATEGY)) {
return UberspectHolder.UBERSPECT;
@@ -273,21 +273,21 @@
}
@Override
- public void setClassLoader(ClassLoader loader) {
+ public void setClassLoader(final ClassLoader loader) {
jxlt = null;
uberspect.setClassLoader(loader);
if (functions != null) {
- List<String> names = new ArrayList<String>(functions.keySet());
- for(String name : names) {
- Object functor = functions.get(name);
+ final List<String> names = new ArrayList<String>(functions.keySet());
+ for(final String name : names) {
+ final Object functor = functions.get(name);
if (functor instanceof Class<?>) {
- Class<?> fclass = ((Class<?>) functor);
+ final Class<?> fclass = ((Class<?>) functor);
try {
- Class<?> nclass = loader.loadClass(fclass.getName());
+ final Class<?> nclass = loader.loadClass(fclass.getName());
if (nclass != fclass) {
functions.put(name, nclass);
}
- } catch (ClassNotFoundException xany) {
+ } catch (final ClassNotFoundException xany) {
functions.put(name, fclass.getName());
}
}
@@ -310,7 +310,7 @@
* @param <T> the option type
* @return conf or def
*/
- private static <T> T option(T conf, T def) {
+ private static <T> T option(final T conf, final T def) {
return conf == null? def : conf;
}
@@ -322,22 +322,22 @@
* @param context the context
* @return the options if any
*/
- protected JexlOptions options(JexlContext context) {
+ protected JexlOptions options(final JexlContext context) {
// Make a copy of the handled options if any
if (context instanceof JexlContext.OptionsHandle) {
- JexlOptions jexlo = ((JexlContext.OptionsHandle) context).getEngineOptions();
+ final JexlOptions jexlo = ((JexlContext.OptionsHandle) context).getEngineOptions();
if (jexlo != null) {
return jexlo.isSharedInstance()? jexlo : jexlo.copy();
}
} else if (context instanceof JexlEngine.Options) {
// This condition and block for compatibility between 3.1 and 3.2
- JexlOptions jexlo = options.copy();
- JexlEngine jexl = this;
- JexlEngine.Options opts = (JexlEngine.Options) context;
+ final JexlOptions jexlo = options.copy();
+ final JexlEngine jexl = this;
+ final JexlEngine.Options opts = (JexlEngine.Options) context;
jexlo.setCancellable(option(opts.isCancellable(), jexl.isCancellable()));
jexlo.setSilent(option(opts.isSilent(), jexl.isSilent()));
jexlo.setStrict(option(opts.isStrict(), jexl.isStrict()));
- JexlArithmetic jexla = jexl.getArithmetic();
+ final JexlArithmetic jexla = jexl.getArithmetic();
jexlo.setStrictArithmetic(option(opts.isStrictArithmetic(), jexla.isStrict()));
jexlo.setMathContext(opts.getArithmeticMathContext());
jexlo.setMathScale(opts.getArithmeticMathScale());
@@ -353,7 +353,7 @@
* @param context the context
* @return the options
*/
- protected JexlOptions options(ASTJexlScript script, JexlContext context) {
+ protected JexlOptions options(final ASTJexlScript script, final JexlContext context) {
final JexlOptions opts = options(context);
if (opts != options) {
// when feature lexical, try hard to run lexical
@@ -378,33 +378,33 @@
* @param context the context
* @param opts the options
*/
- protected void processPragmas(ASTJexlScript script, JexlContext context, JexlOptions opts) {
- Map<String, Object> pragmas = script.getPragmas();
+ protected void processPragmas(final ASTJexlScript script, final JexlContext context, final JexlOptions opts) {
+ final Map<String, Object> pragmas = script.getPragmas();
if (pragmas != null && !pragmas.isEmpty()) {
- JexlContext.PragmaProcessor processor =
+ final JexlContext.PragmaProcessor processor =
context instanceof JexlContext.PragmaProcessor
? (JexlContext.PragmaProcessor) context
: null;
Map<String, Object> ns = null;
- for(Map.Entry<String, Object> pragma : pragmas.entrySet()) {
- String key = pragma.getKey();
- Object value = pragma.getValue();
+ for(final Map.Entry<String, Object> pragma : pragmas.entrySet()) {
+ final String key = pragma.getKey();
+ final Object value = pragma.getValue();
if (value instanceof String) {
if (PRAGMA_OPTIONS.equals(key)) {
// jexl.options
- String[] vs = value.toString().split(" ");
+ final String[] vs = value.toString().split(" ");
opts.setFlags(vs);
} else if (key.startsWith(PRAGMA_JEXLNS)) {
// jexl.namespace.***
- String nsname = key.substring(PRAGMA_JEXLNS.length());
+ final String nsname = key.substring(PRAGMA_JEXLNS.length());
if (nsname != null && !nsname.isEmpty()) {
if (ns == null) {
ns = new HashMap<>(functions);
}
- String nsclass = value.toString();
+ final String nsclass = value.toString();
try {
ns.put(nsname, uberspect.getClassLoader().loadClass(nsclass));
- } catch (ClassNotFoundException e) {
+ } catch (final ClassNotFoundException e) {
ns.put(nsname, nsclass);
}
}
@@ -425,7 +425,7 @@
* @param opts the options to set
* @return the options
*/
- public JexlOptions optionsSet(JexlOptions opts) {
+ public JexlOptions optionsSet(final JexlOptions opts) {
if (opts != null) {
opts.set(options);
}
@@ -433,7 +433,7 @@
}
@Override
- public TemplateEngine createJxltEngine(boolean noScript, int cacheSize, char immediate, char deferred) {
+ public TemplateEngine createJxltEngine(final boolean noScript, final int cacheSize, final char immediate, final char deferred) {
return new TemplateEngine(this, noScript, cacheSize, immediate, deferred);
}
@@ -451,25 +451,25 @@
* @param opts the evaluation options
* @return an Interpreter
*/
- protected Interpreter createInterpreter(JexlContext context, Frame frame, JexlOptions opts) {
+ protected Interpreter createInterpreter(final JexlContext context, final Frame frame, final JexlOptions opts) {
return new Interpreter(this, opts, context, frame);
}
@Override
- public Script createExpression(JexlInfo info, String expression) {
+ public Script createExpression(final JexlInfo info, final String expression) {
return createScript(expressionFeatures, info, expression, null);
}
@Override
- public Script createScript(JexlFeatures features, JexlInfo info, String scriptText, String[] names) {
+ public Script createScript(final JexlFeatures features, final JexlInfo info, final String scriptText, final String[] names) {
if (scriptText == null) {
throw new NullPointerException("source is null");
}
- String source = trimSource(scriptText);
- Scope scope = names == null || names.length == 0? null : new Scope(null, names);
- JexlFeatures ftrs = features == null? scriptFeatures : features;
- ASTJexlScript tree = parse(info, ftrs, source, scope);
+ final String source = trimSource(scriptText);
+ final Scope scope = names == null || names.length == 0? null : new Scope(null, names);
+ final JexlFeatures ftrs = features == null? scriptFeatures : features;
+ final ASTJexlScript tree = parse(info, ftrs, source, scope);
return new Script(this, source, tree);
}
@@ -486,12 +486,12 @@
.register(true);
@Override
- public Object getProperty(Object bean, String expr) {
+ public Object getProperty(final Object bean, final String expr) {
return getProperty(null, bean, expr);
}
@Override
- public Object getProperty(JexlContext context, Object bean, String expr) {
+ public Object getProperty(JexlContext context, final Object bean, final String expr) {
if (context == null) {
context = EMPTY_CONTEXT;
}
@@ -505,7 +505,7 @@
final Frame frame = script.createFrame(bean);
final Interpreter interpreter = createInterpreter(context, frame, options);
return interpreter.visitLexicalNode(node, null);
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
if (silent) {
logger.warn(xjexl.getMessage(), xjexl.getCause());
return null;
@@ -515,12 +515,12 @@
}
@Override
- public void setProperty(Object bean, String expr, Object value) {
+ public void setProperty(final Object bean, final String expr, final Object value) {
setProperty(null, bean, expr, value);
}
@Override
- public void setProperty(JexlContext context, Object bean, String expr, Object value) {
+ public void setProperty(JexlContext context, final Object bean, final String expr, final Object value) {
if (context == null) {
context = EMPTY_CONTEXT;
}
@@ -534,7 +534,7 @@
final Frame frame = script.createFrame(bean, value);
final Interpreter interpreter = createInterpreter(context, frame, options);
interpreter.visitLexicalNode(node, null);
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
if (silent) {
logger.warn(xjexl.getMessage(), xjexl.getCause());
return;
@@ -544,7 +544,7 @@
}
@Override
- public Object invokeMethod(Object obj, String meth, Object... args) {
+ public Object invokeMethod(final Object obj, final String meth, final Object... args) {
JexlException xjexl = null;
Object result = null;
final JexlInfo info = debug ? createInfo() : null;
@@ -558,9 +558,9 @@
} else {
xjexl = new JexlException.Method(info, meth, args);
}
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
xjexl = xany;
- } catch (Exception xany) {
+ } catch (final Exception xany) {
xjexl = new JexlException.Method(info, meth, args, xany);
}
if (xjexl != null) {
@@ -575,12 +575,12 @@
}
@Override
- public <T> T newInstance(Class<? extends T> clazz, Object... args) {
+ public <T> T newInstance(final Class<? extends T> clazz, final Object... args) {
return clazz.cast(doCreateInstance(clazz, args));
}
@Override
- public Object newInstance(String clazz, Object... args) {
+ public Object newInstance(final String clazz, final Object... args) {
return doCreateInstance(clazz, args);
}
@@ -591,7 +591,7 @@
* @param args the constructor arguments
* @return the created object instance or null on failure when silent
*/
- protected Object doCreateInstance(Object clazz, Object... args) {
+ protected Object doCreateInstance(final Object clazz, final Object... args) {
JexlException xjexl = null;
Object result = null;
final JexlInfo info = debug ? createInfo() : null;
@@ -605,9 +605,9 @@
} else {
xjexl = new JexlException.Method(info, clazz.toString(), args);
}
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
xjexl = xany;
- } catch (Exception xany) {
+ } catch (final Exception xany) {
xjexl = new JexlException.Method(info, clazz.toString(), args, xany);
}
if (xjexl != null) {
@@ -625,8 +625,8 @@
* @param tls the context or null
* @return the previous thread local context
*/
- protected JexlContext.ThreadLocal putThreadLocal(JexlContext.ThreadLocal tls) {
- JexlContext.ThreadLocal local = CONTEXT.get();
+ protected JexlContext.ThreadLocal putThreadLocal(final JexlContext.ThreadLocal tls) {
+ final JexlContext.ThreadLocal local = CONTEXT.get();
CONTEXT.set(tls);
return local;
}
@@ -636,8 +636,8 @@
* @param jexl the engine or null
* @return the previous thread local engine
*/
- protected JexlEngine putThreadEngine(JexlEngine jexl) {
- JexlEngine pjexl = ENGINE.get();
+ protected JexlEngine putThreadEngine(final JexlEngine jexl) {
+ final JexlEngine pjexl = ENGINE.get();
ENGINE.set(jexl);
return pjexl;
}
@@ -650,8 +650,8 @@
* @return the set of variables, each as a list of strings (ant-ish variables use more than 1 string)
* or the empty set if no variables are used
*/
- protected Set<List<String>> getVariables(ASTJexlScript script) {
- VarCollector collector = varCollector();
+ protected Set<List<String>> getVariables(final ASTJexlScript script) {
+ final VarCollector collector = varCollector();
getVariables(script, script, collector);
return collector.collected();
}
@@ -691,7 +691,7 @@
* Constructor.
* @param constaa whether constant array-access is considered equivalent to dot-access
*/
- protected VarCollector(int constaa) {
+ protected VarCollector(final int constaa) {
mode = constaa;
}
@@ -699,7 +699,7 @@
* Starts/stops a variable collect.
* @param node starts if not null, stop if null
*/
- public void collect(JexlNode node) {
+ public void collect(final JexlNode node) {
if (!ref.isEmpty()) {
refs.add(ref);
ref = new ArrayList<String>();
@@ -718,7 +718,7 @@
* Adds a 'segment' to the variable being collected.
* @param name the name
*/
- public void add(String name) {
+ public void add(final String name) {
ref.add(name);
}
@@ -736,16 +736,16 @@
* @param node the node
* @param collector the variable collector
*/
- protected void getVariables(final ASTJexlScript script, JexlNode node, VarCollector collector) {
+ protected void getVariables(final ASTJexlScript script, final JexlNode node, final VarCollector collector) {
if (node instanceof ASTIdentifier) {
- JexlNode parent = node.jjtGetParent();
+ final JexlNode parent = node.jjtGetParent();
if (parent instanceof ASTMethodNode || parent instanceof ASTFunctionNode) {
// skip identifiers for methods and functions
collector.collect(null);
return;
}
- ASTIdentifier identifier = (ASTIdentifier) node;
- int symbol = identifier.getSymbol();
+ final ASTIdentifier identifier = (ASTIdentifier) node;
+ final int symbol = identifier.getSymbol();
// symbols that are captured are considered "global" variables
if (symbol >= 0 && script != null && !script.isCapturedSymbol(symbol)) {
collector.collect(null);
@@ -755,7 +755,7 @@
collector.add(identifier.getName());
}
} else if (node instanceof ASTIdentifierAccess) {
- JexlNode parent = node.jjtGetParent();
+ final JexlNode parent = node.jjtGetParent();
if (parent instanceof ASTMethodNode || parent instanceof ASTFunctionNode) {
// skip identifiers for methods and functions
collector.collect(null);
@@ -766,17 +766,17 @@
collector.add(((ASTIdentifierAccess) node).getName());
}
} else if (node instanceof ASTArrayAccess && collector.mode > 0) {
- int num = node.jjtGetNumChildren();
+ final int num = node.jjtGetNumChildren();
// collect only if array access is const and follows an identifier
boolean collecting = collector.isCollecting();
for (int i = 0; i < num; ++i) {
- JexlNode child = node.jjtGetChild(i);
+ final JexlNode child = node.jjtGetChild(i);
if (collecting && child.isConstant()) {
// collect all constants or only string and number literals
- boolean collect = collector.mode > 1
+ final boolean collect = collector.mode > 1
|| (child instanceof ASTStringLiteral || child instanceof ASTNumberLiteral);
if (collect) {
- String image = child.toString();
+ final String image = child.toString();
collector.add(image);
}
} else {
@@ -787,7 +787,7 @@
}
}
} else {
- int num = node.jjtGetNumChildren();
+ final int num = node.jjtGetNumChildren();
for (int i = 0; i < num; ++i) {
getVariables(script, node.jjtGetChild(i), collector);
}
@@ -801,7 +801,7 @@
* @return the parameters which may be empty (but not null) if no parameters were defined
* @since 3.0
*/
- protected String[] getParameters(JexlScript script) {
+ protected String[] getParameters(final JexlScript script) {
return script.getParameters();
}
@@ -811,7 +811,7 @@
* @return the local variables array which may be empty (but not null) if no local variables were defined
* @since 3.0
*/
- protected String[] getLocalVariables(JexlScript script) {
+ protected String[] getLocalVariables(final JexlScript script) {
return script.getLocalVariables();
}
@@ -825,7 +825,7 @@
* @return the parsed tree
* @throws JexlException if any error occurred during parsing
*/
- protected ASTJexlScript parse(JexlInfo info, boolean expr, String src, Scope scope) {
+ protected ASTJexlScript parse(final JexlInfo info, final boolean expr, final String src, final Scope scope) {
return parse(info, expr? this.expressionFeatures : this.scriptFeatures, src, scope);
}
@@ -839,7 +839,7 @@
* @return the parsed tree
* @throws JexlException if any error occurred during parsing
*/
- protected ASTJexlScript parse(JexlInfo info, JexlFeatures parsingf, String src, Scope scope) {
+ protected ASTJexlScript parse(final JexlInfo info, final JexlFeatures parsingf, final String src, final Scope scope) {
final boolean cached = src.length() < cacheThreshold && cache != null;
final JexlFeatures features = parsingf != null? parsingf : DEFAULT_FEATURES;
final Source source = cached? new Source(features, src) : null;
@@ -847,7 +847,7 @@
if (source != null) {
script = cache.get(source);
if (script != null) {
- Scope f = script.getScope();
+ final Scope f = script.getScope();
if ((f == null && scope == null) || (f != null && f.equals(scope))) {
return script;
}
@@ -865,7 +865,7 @@
}
} else {
// ...otherwise parser was in use, create a new temporary one
- Parser lparser = new Parser(new StringReader(";"));
+ final Parser lparser = new Parser(new StringReader(";"));
script = lparser.parse(ninfo, features, src, scope);
}
if (source != null) {
@@ -879,7 +879,7 @@
* @param str expression to clean
* @return trimmed expression ending in a semi-colon
*/
- protected String trimSource(CharSequence str) {
+ protected String trimSource(final CharSequence str) {
if (str != null) {
int start = 0;
int end = str.length();
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Frame.java b/src/main/java/org/apache/commons/jexl3/internal/Frame.java
index 9fe9ac8..3dfbe4d 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Frame.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Frame.java
@@ -36,7 +36,7 @@
* @param r the stack frame
* @param c the number of curried parameters
*/
- public Frame(Scope s, Object[] r, int c) {
+ public Frame(final Scope s, final Object[] r, final int c) {
scope = s;
stack = r;
curried = c;
@@ -64,7 +64,7 @@
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
@@ -80,7 +80,7 @@
* @param s the offset in this frame
* @return the stacked value
*/
- Object get(int s) {
+ Object get(final int s) {
return stack[s];
}
@@ -89,7 +89,7 @@
* @param s the offset in this frame
* @return true if this symbol has been assigned a value, false otherwise
*/
- boolean has(int s) {
+ boolean has(final int s) {
return s >= 0 && s < stack.length && stack[s] != Scope.UNDECLARED;
}
@@ -98,7 +98,7 @@
* @param r the offset in this frame
* @param value the value to set in this frame
*/
- void set(int r, Object value) {
+ void set(final int r, final Object value) {
stack[r] = value;
}
@@ -107,10 +107,10 @@
* @param values the values
* @return this frame
*/
- Frame assign(Object... values) {
+ Frame assign(final Object... values) {
if (stack != null) {
- int nparm = scope.getArgCount();
- Object[] copy = stack.clone();
+ final int nparm = scope.getArgCount();
+ final Object[] copy = stack.clone();
int ncopy = 0;
if (values != null && values.length > 0) {
ncopy = Math.min(nparm - curried, Math.min(nparm, values.length));
diff --git a/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java b/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
index 29dbbff..e04bd66 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/IntegerRange.java
@@ -36,7 +36,7 @@
* @param to the higher inclusive boundary
* @return a range
*/
- public static IntegerRange create(int from, int to) {
+ public static IntegerRange create(final int from, final int to) {
if (from <= to) {
return new IntegerRange.Ascending(from, to);
} else {
@@ -48,7 +48,7 @@
* @param from the lower inclusive boundary
* @param to the higher inclusive boundary
*/
- public IntegerRange(int from, int to) {
+ public IntegerRange(final int from, final int to) {
min = from;
max = to;
}
@@ -81,7 +81,7 @@
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
@@ -112,9 +112,9 @@
}
@Override
- public boolean contains(Object o) {
+ public boolean contains(final Object o) {
if (o instanceof Number) {
- long v = ((Number) o).intValue();
+ final long v = ((Number) o).intValue();
return min <= v && v <= max;
} else {
return false;
@@ -124,7 +124,7 @@
@Override
public Object[] toArray() {
final int size = size();
- Object[] array = new Object[size];
+ final Object[] array = new Object[size];
for(int a = 0; a < size; ++a) {
array[a] = min + a;
}
@@ -133,7 +133,7 @@
@Override
@SuppressWarnings("unchecked")
- public <T> T[] toArray(T[] array) {
+ public <T> T[] toArray(final T[] array) {
final Class<?> ct = array.getClass().getComponentType();
final int length = size();
T[] copy = array;
@@ -153,8 +153,8 @@
}
@Override
- public boolean containsAll(Collection<?> c) {
- for(Object cc : c) {
+ public boolean containsAll(final Collection<?> c) {
+ for(final Object cc : c) {
if (!contains(cc)) {
return false;
}
@@ -163,27 +163,27 @@
}
@Override
- public boolean add(Integer e) {
+ public boolean add(final Integer e) {
throw new UnsupportedOperationException();
}
@Override
- public boolean remove(Object o) {
+ public boolean remove(final Object o) {
throw new UnsupportedOperationException();
}
@Override
- public boolean addAll(Collection<? extends Integer> c) {
+ public boolean addAll(final Collection<? extends Integer> c) {
throw new UnsupportedOperationException();
}
@Override
- public boolean removeAll(Collection<?> c) {
+ public boolean removeAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
- public boolean retainAll(Collection<?> c) {
+ public boolean retainAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@@ -201,7 +201,7 @@
* @param from lower boundary
* @param to upper boundary
*/
- protected Ascending(int from, int to) {
+ protected Ascending(final int from, final int to) {
super(from, to);
}
@@ -220,7 +220,7 @@
* @param from upper boundary
* @param to lower boundary
*/
- protected Descending(int from, int to) {
+ protected Descending(final int from, final int to) {
super(from, to);
}
@@ -246,7 +246,7 @@
* @param l low boundary
* @param h high boundary
*/
- public AscIntegerIterator(int l, int h) {
+ public AscIntegerIterator(final int l, final int h) {
min = l;
max = h;
cursor = min;
@@ -286,7 +286,7 @@
* @param l low boundary
* @param h high boundary
*/
- public DescIntegerIterator(int l, int h) {
+ public DescIntegerIterator(final int l, final int h) {
min = l;
max = h;
cursor = max;
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
index 5b31987..d37120f 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
@@ -137,7 +137,7 @@
* @param opts the evaluation options, flags modifying evaluation behavior
* @param eFrame the evaluation frame, arguments and local variables
*/
- protected Interpreter(Engine engine, JexlOptions opts, JexlContext aContext, Frame eFrame) {
+ protected Interpreter(final Engine engine, final JexlOptions opts, final JexlContext aContext, final Frame eFrame) {
super(engine, opts, aContext);
this.frame = eFrame;
}
@@ -147,7 +147,7 @@
* @param ii the interpreter to copy
* @param jexla the arithmetic instance to use (or null)
*/
- protected Interpreter(Interpreter ii, JexlArithmetic jexla) {
+ protected Interpreter(final Interpreter ii, final JexlArithmetic jexla) {
super(ii, jexla);
frame = ii.frame;
block = ii.block != null? new LexicalFrame(ii.block) : null;
@@ -158,8 +158,8 @@
* @param inter the interpreter or null
* @return the previous thread local interpreter
*/
- protected Interpreter putThreadInterpreter(Interpreter inter) {
- Interpreter pinter = INTER.get();
+ protected Interpreter putThreadInterpreter(final Interpreter inter) {
+ final Interpreter pinter = INTER.get();
INTER.set(inter);
return pinter;
}
@@ -173,7 +173,7 @@
* @return the result of the interpretation.
* @throws JexlException if any error occurs during interpretation.
*/
- public Object interpret(JexlNode node) {
+ public Object interpret(final JexlNode node) {
JexlContext.ThreadLocal tcontext = null;
JexlEngine tjexl = null;
Interpreter tinter = null;
@@ -191,23 +191,23 @@
}
cancelCheck(node);
return node.jjtAccept(this, null);
- } catch(StackOverflowError xstack) {
- JexlException xjexl = new JexlException.StackOverflow(node.jexlInfo(), "jvm", xstack);
+ } catch(final StackOverflowError xstack) {
+ final JexlException xjexl = new JexlException.StackOverflow(node.jexlInfo(), "jvm", xstack);
if (!isSilent()) {
throw xjexl.clean();
}
if (logger.isWarnEnabled()) {
logger.warn(xjexl.getMessage(), xjexl.getCause());
}
- } catch (JexlException.Return xreturn) {
+ } catch (final JexlException.Return xreturn) {
return xreturn.getValue();
- } catch (JexlException.Cancel xcancel) {
+ } catch (final JexlException.Cancel xcancel) {
// cancelled |= Thread.interrupted();
cancelled.weakCompareAndSet(false, Thread.interrupted());
if (isCancellable()) {
throw xcancel.clean();
}
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
if (!isSilent()) {
throw xjexl.clean();
}
@@ -217,7 +217,7 @@
} finally {
synchronized(this) {
if (functors != null) {
- for (Object functor : functors.values()) {
+ for (final Object functor : functors.values()) {
closeIfSupported(functor);
}
functors.clear();
@@ -243,7 +243,7 @@
* @param attribute the attribute of the object, e.g. an index (1, 0, 2) or key for a map
* @return the attribute value
*/
- public Object getAttribute(Object object, Object attribute) {
+ public Object getAttribute(final Object object, final Object attribute) {
return getAttribute(object, attribute, null);
}
/**
@@ -253,265 +253,265 @@
* @param attribute the attribute of the object, e.g. an index (1, 0, 2) or key for a map
* @param value the value to assign to the object's attribute
*/
- public void setAttribute(Object object, Object attribute, Object value) {
+ public void setAttribute(final Object object, final Object attribute, final Object value) {
setAttribute(object, attribute, value, null);
}
@Override
- protected Object visit(ASTAddNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTAddNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.ADD, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.ADD, left, right);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.add(left, right);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "+ error", xrt);
}
}
@Override
- protected Object visit(ASTSubNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTSubNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.SUBTRACT, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.SUBTRACT, left, right);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.subtract(left, right);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "- error", xrt);
}
}
@Override
- protected Object visit(ASTMulNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTMulNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.MULTIPLY, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.MULTIPLY, left, right);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.multiply(left, right);
- } catch (ArithmeticException xrt) {
- JexlNode xnode = findNullOperand(xrt, node, left, right);
+ } catch (final ArithmeticException xrt) {
+ final JexlNode xnode = findNullOperand(xrt, node, left, right);
throw new JexlException(xnode, "* error", xrt);
}
}
@Override
- protected Object visit(ASTDivNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTDivNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.DIVIDE, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.DIVIDE, left, right);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.divide(left, right);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
if (!arithmetic.isStrict()) {
return 0.0d;
}
- JexlNode xnode = findNullOperand(xrt, node, left, right);
+ final JexlNode xnode = findNullOperand(xrt, node, left, right);
throw new JexlException(xnode, "/ error", xrt);
}
}
@Override
- protected Object visit(ASTModNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTModNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.MOD, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.MOD, left, right);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.mod(left, right);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
if (!arithmetic.isStrict()) {
return 0.0d;
}
- JexlNode xnode = findNullOperand(xrt, node, left, right);
+ final JexlNode xnode = findNullOperand(xrt, node, left, right);
throw new JexlException(xnode, "% error", xrt);
}
}
@Override
- protected Object visit(ASTBitwiseAndNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTBitwiseAndNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.AND, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.AND, left, right);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.and(left, right);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "& error", xrt);
}
}
@Override
- protected Object visit(ASTBitwiseOrNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTBitwiseOrNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.OR, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.OR, left, right);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.or(left, right);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "| error", xrt);
}
}
@Override
- protected Object visit(ASTBitwiseXorNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTBitwiseXorNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.XOR, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.XOR, left, right);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.xor(left, right);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "^ error", xrt);
}
}
@Override
- protected Object visit(ASTEQNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTEQNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.EQ, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.EQ, left, right);
return result != JexlEngine.TRY_FAILED
? result
: arithmetic.equals(left, right) ? Boolean.TRUE : Boolean.FALSE;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "== error", xrt);
}
}
@Override
- protected Object visit(ASTNENode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTNENode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.EQ, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.EQ, left, right);
return result != JexlEngine.TRY_FAILED
? arithmetic.toBoolean(result) ? Boolean.FALSE : Boolean.TRUE
: arithmetic.equals(left, right) ? Boolean.FALSE : Boolean.TRUE;
- } catch (ArithmeticException xrt) {
- JexlNode xnode = findNullOperand(xrt, node, left, right);
+ } catch (final ArithmeticException xrt) {
+ final JexlNode xnode = findNullOperand(xrt, node, left, right);
throw new JexlException(xnode, "!= error", xrt);
}
}
@Override
- protected Object visit(ASTGENode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTGENode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.GTE, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.GTE, left, right);
return result != JexlEngine.TRY_FAILED
? result
: arithmetic.greaterThanOrEqual(left, right) ? Boolean.TRUE : Boolean.FALSE;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, ">= error", xrt);
}
}
@Override
- protected Object visit(ASTGTNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTGTNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.GT, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.GT, left, right);
return result != JexlEngine.TRY_FAILED
? result
: arithmetic.greaterThan(left, right) ? Boolean.TRUE : Boolean.FALSE;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "> error", xrt);
}
}
@Override
- protected Object visit(ASTLENode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTLENode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.LTE, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.LTE, left, right);
return result != JexlEngine.TRY_FAILED
? result
: arithmetic.lessThanOrEqual(left, right) ? Boolean.TRUE : Boolean.FALSE;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "<= error", xrt);
}
}
@Override
- protected Object visit(ASTLTNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTLTNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.LT, left, right);
+ final Object result = operators.tryOverload(node, JexlOperator.LT, left, right);
return result != JexlEngine.TRY_FAILED
? result
: arithmetic.lessThan(left, right) ? Boolean.TRUE : Boolean.FALSE;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "< error", xrt);
}
}
@Override
- protected Object visit(ASTSWNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTSWNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
return operators.startsWith(node, "^=", left, right) ? Boolean.TRUE : Boolean.FALSE;
}
@Override
- protected Object visit(ASTNSWNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTNSWNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
return operators.startsWith(node, "^!", left, right) ? Boolean.FALSE : Boolean.TRUE;
}
@Override
- protected Object visit(ASTEWNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTEWNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
return operators.endsWith(node, "$=", left, right) ? Boolean.TRUE : Boolean.FALSE;
}
@Override
- protected Object visit(ASTNEWNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTNEWNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
return operators.endsWith(node, "$!", left, right) ? Boolean.FALSE : Boolean.TRUE;
}
@Override
- protected Object visit(ASTERNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTERNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
return operators.contains(node, "=~", right, left) ? Boolean.TRUE : Boolean.FALSE;
}
@Override
- protected Object visit(ASTNRNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTNRNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
return operators.contains(node, "!~", right, left) ? Boolean.FALSE : Boolean.TRUE;
}
@Override
- protected Object visit(ASTRangeNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTRangeNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
return arithmetic.createRange(left, right);
- } catch (ArithmeticException xrt) {
- JexlNode xnode = findNullOperand(xrt, node, left, right);
+ } catch (final ArithmeticException xrt) {
+ final JexlNode xnode = findNullOperand(xrt, node, left, right);
throw new JexlException(xnode, ".. error", xrt);
}
}
@Override
- protected Object visit(ASTUnaryMinusNode node, Object data) {
+ protected Object visit(final ASTUnaryMinusNode node, final Object data) {
// use cached value if literal
- Object value = node.jjtGetValue();
+ final Object value = node.jjtGetValue();
if (value != null && !(value instanceof JexlMethod)) {
return value;
}
- JexlNode valNode = node.jjtGetChild(0);
- Object val = valNode.jjtAccept(this, data);
+ final JexlNode valNode = node.jjtGetChild(0);
+ final Object val = valNode.jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.NEGATE, val);
+ final Object result = operators.tryOverload(node, JexlOperator.NEGATE, val);
if (result != JexlEngine.TRY_FAILED) {
return result;
}
@@ -527,68 +527,68 @@
}
}
return number;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(valNode, "- error", xrt);
}
}
@Override
- protected Object visit(ASTUnaryPlusNode node, Object data) {
+ protected Object visit(final ASTUnaryPlusNode node, final Object data) {
// use cached value if literal
- Object value = node.jjtGetValue();
+ final Object value = node.jjtGetValue();
if (value != null && !(value instanceof JexlMethod)) {
return value;
}
- JexlNode valNode = node.jjtGetChild(0);
- Object val = valNode.jjtAccept(this, data);
+ final JexlNode valNode = node.jjtGetChild(0);
+ final Object val = valNode.jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.POSITIVIZE, val);
+ final Object result = operators.tryOverload(node, JexlOperator.POSITIVIZE, val);
if (result != JexlEngine.TRY_FAILED) {
return result;
}
- Object number = arithmetic.positivize(val);
+ final Object number = arithmetic.positivize(val);
if (valNode instanceof ASTNumberLiteral
&& number instanceof Number
&& arithmetic.isPositivizeStable()) {
node.jjtSetValue(number);
}
return number;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(valNode, "- error", xrt);
}
}
@Override
- protected Object visit(ASTBitwiseComplNode node, Object data) {
- Object arg = node.jjtGetChild(0).jjtAccept(this, data);
+ protected Object visit(final ASTBitwiseComplNode node, final Object data) {
+ final Object arg = node.jjtGetChild(0).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.COMPLEMENT, arg);
+ final Object result = operators.tryOverload(node, JexlOperator.COMPLEMENT, arg);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.complement(arg);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "~ error", xrt);
}
}
@Override
- protected Object visit(ASTNotNode node, Object data) {
- Object val = node.jjtGetChild(0).jjtAccept(this, data);
+ protected Object visit(final ASTNotNode node, final Object data) {
+ final Object val = node.jjtGetChild(0).jjtAccept(this, data);
try {
- Object result = operators.tryOverload(node, JexlOperator.NOT, val);
+ final Object result = operators.tryOverload(node, JexlOperator.NOT, val);
return result != JexlEngine.TRY_FAILED ? result : arithmetic.not(val);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, "! error", xrt);
}
}
@Override
- protected Object visit(ASTIfStatement node, Object data) {
- int n = 0;
+ protected Object visit(final ASTIfStatement node, final Object data) {
+ final int n = 0;
final int numChildren = node.jjtGetNumChildren();
try {
Object result = null;
// pairs of { conditions , 'then' statement }
for(int ifElse = 0; ifElse < (numChildren - 1); ifElse += 2) {
- Object condition = node.jjtGetChild(ifElse).jjtAccept(this, null);
+ final Object condition = node.jjtGetChild(ifElse).jjtAccept(this, null);
if (arithmetic.toBoolean(condition)) {
// first objectNode is true statement
return node.jjtGetChild(ifElse + 1).jjtAccept(this, null);
@@ -601,14 +601,14 @@
result = node.jjtGetChild(numChildren - 1).jjtAccept(this, null);
}
return result;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node.jjtGetChild(n), "if error", xrt);
}
}
@Override
- protected Object visit(ASTVar node, Object data) {
- int symbol = node.getSymbol();
+ protected Object visit(final ASTVar node, final Object data) {
+ final int symbol = node.getSymbol();
// if we have a var, we have a scope thus a frame
if (!options.isLexical()) {
if (frame.has(symbol)) {
@@ -622,8 +622,8 @@
}
@Override
- protected Object visit(ASTBlock node, Object data) {
- int cnt = node.getSymbolCount();
+ protected Object visit(final ASTBlock node, final Object data) {
+ final int cnt = node.getSymbolCount();
if (!options.isLexical() || cnt <= 0) {
return visitBlock(node, data);
}
@@ -641,8 +641,8 @@
* @param data the usual data
* @return the result of the last expression evaluation
*/
- private Object visitBlock(ASTBlock node, Object data) {
- int numChildren = node.jjtGetNumChildren();
+ private Object visitBlock(final ASTBlock node, final Object data) {
+ final int numChildren = node.jjtGetNumChildren();
Object result = null;
for (int i = 0; i < numChildren; i++) {
cancelCheck(node);
@@ -652,28 +652,28 @@
}
@Override
- protected Object visit(ASTReturnStatement node, Object data) {
- Object val = node.jjtGetChild(0).jjtAccept(this, data);
+ protected Object visit(final ASTReturnStatement node, final Object data) {
+ final Object val = node.jjtGetChild(0).jjtAccept(this, data);
cancelCheck(node);
throw new JexlException.Return(node, null, val);
}
@Override
- protected Object visit(ASTContinue node, Object data) {
+ protected Object visit(final ASTContinue node, final Object data) {
throw new JexlException.Continue(node);
}
@Override
- protected Object visit(ASTBreak node, Object data) {
+ protected Object visit(final ASTBreak node, final Object data) {
throw new JexlException.Break(node);
}
@Override
- protected Object visit(ASTForeachStatement node, Object data) {
+ protected Object visit(final ASTForeachStatement node, final Object data) {
Object result = null;
/* first objectNode is the loop variable */
- ASTReference loopReference = (ASTReference) node.jjtGetChild(0);
- ASTIdentifier loopVariable = (ASTIdentifier) loopReference.jjtGetChild(0);
+ final ASTReference loopReference = (ASTReference) node.jjtGetChild(0);
+ final ASTIdentifier loopVariable = (ASTIdentifier) loopReference.jjtGetChild(0);
final int symbol = loopVariable.getSymbol();
final boolean lexical = options.isLexical();// && node.getSymbolCount() > 0;
final LexicalFrame locals = lexical? new LexicalFrame(frame, block) : null;
@@ -689,14 +689,14 @@
Object forEach = null;
try {
/* second objectNode is the variable to iterate */
- Object iterableValue = node.jjtGetChild(1).jjtAccept(this, data);
+ final Object iterableValue = node.jjtGetChild(1).jjtAccept(this, data);
// make sure there is a value to iterate upon
if (iterableValue != null) {
/* third objectNode is the statement to execute */
- JexlNode statement = node.jjtGetNumChildren() >= 3 ? node.jjtGetChild(2) : null;
+ final JexlNode statement = node.jjtGetNumChildren() >= 3 ? node.jjtGetChild(2) : null;
// get an iterator for the collection/array etc via the introspector.
forEach = operators.tryOverload(node, JexlOperator.FOR_EACH, iterableValue);
- Iterator<?> itemsIterator = forEach instanceof Iterator
+ final Iterator<?> itemsIterator = forEach instanceof Iterator
? (Iterator<?>) forEach
: uberspect.getIterator(iterableValue);
if (itemsIterator != null) {
@@ -713,7 +713,7 @@
}
}
// set loopVariable to value of iterator
- Object value = itemsIterator.next();
+ final Object value = itemsIterator.next();
if (symbol < 0) {
setContextVariable(node, loopVariable.getName(), value);
} else {
@@ -723,9 +723,9 @@
try {
// execute statement
result = statement.jjtAccept(this, data);
- } catch (JexlException.Break stmtBreak) {
+ } catch (final JexlException.Break stmtBreak) {
break;
- } catch (JexlException.Continue stmtContinue) {
+ } catch (final JexlException.Continue stmtContinue) {
//continue;
}
}
@@ -744,19 +744,19 @@
}
@Override
- protected Object visit(ASTWhileStatement node, Object data) {
+ protected Object visit(final ASTWhileStatement node, final Object data) {
Object result = null;
/* first objectNode is the condition */
- Node condition = node.jjtGetChild(0);
+ final Node condition = node.jjtGetChild(0);
while (arithmetic.toBoolean(condition.jjtAccept(this, data))) {
cancelCheck(node);
if (node.jjtGetNumChildren() > 1) {
try {
// execute statement
result = node.jjtGetChild(1).jjtAccept(this, data);
- } catch (JexlException.Break stmtBreak) {
+ } catch (final JexlException.Break stmtBreak) {
break;
- } catch (JexlException.Continue stmtContinue) {
+ } catch (final JexlException.Continue stmtContinue) {
//continue;
}
}
@@ -765,20 +765,20 @@
}
@Override
- protected Object visit(ASTDoWhileStatement node, Object data) {
+ protected Object visit(final ASTDoWhileStatement node, final Object data) {
Object result = null;
- int nc = node.jjtGetNumChildren();
+ final int nc = node.jjtGetNumChildren();
/* last objectNode is the condition */
- Node condition = node.jjtGetChild(nc - 1);
+ final Node condition = node.jjtGetChild(nc - 1);
do {
cancelCheck(node);
if (nc > 1) {
try {
// execute statement
result = node.jjtGetChild(0).jjtAccept(this, data);
- } catch (JexlException.Break stmtBreak) {
+ } catch (final JexlException.Break stmtBreak) {
break;
- } catch (JexlException.Continue stmtContinue) {
+ } catch (final JexlException.Continue stmtContinue) {
//continue;
}
}
@@ -787,73 +787,73 @@
}
@Override
- protected Object visit(ASTAndNode node, Object data) {
+ protected Object visit(final ASTAndNode node, final Object data) {
/*
* The pattern for exception mgmt is to let the child*.jjtAccept out of the try/catch loop so that if one fails,
* the ex will traverse up to the interpreter. In cases where this is not convenient/possible, JexlException
* must be caught explicitly and rethrown.
*/
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
try {
- boolean leftValue = arithmetic.toBoolean(left);
+ final boolean leftValue = arithmetic.toBoolean(left);
if (!leftValue) {
return Boolean.FALSE;
}
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node.jjtGetChild(0), "boolean coercion error", xrt);
}
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- boolean rightValue = arithmetic.toBoolean(right);
+ final boolean rightValue = arithmetic.toBoolean(right);
if (!rightValue) {
return Boolean.FALSE;
}
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node.jjtGetChild(1), "boolean coercion error", xrt);
}
return Boolean.TRUE;
}
@Override
- protected Object visit(ASTOrNode node, Object data) {
- Object left = node.jjtGetChild(0).jjtAccept(this, data);
+ protected Object visit(final ASTOrNode node, final Object data) {
+ final Object left = node.jjtGetChild(0).jjtAccept(this, data);
try {
- boolean leftValue = arithmetic.toBoolean(left);
+ final boolean leftValue = arithmetic.toBoolean(left);
if (leftValue) {
return Boolean.TRUE;
}
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node.jjtGetChild(0), "boolean coercion error", xrt);
}
- Object right = node.jjtGetChild(1).jjtAccept(this, data);
+ final Object right = node.jjtGetChild(1).jjtAccept(this, data);
try {
- boolean rightValue = arithmetic.toBoolean(right);
+ final boolean rightValue = arithmetic.toBoolean(right);
if (rightValue) {
return Boolean.TRUE;
}
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node.jjtGetChild(1), "boolean coercion error", xrt);
}
return Boolean.FALSE;
}
@Override
- protected Object visit(ASTNullLiteral node, Object data) {
+ protected Object visit(final ASTNullLiteral node, final Object data) {
return null;
}
@Override
- protected Object visit(ASTTrueNode node, Object data) {
+ protected Object visit(final ASTTrueNode node, final Object data) {
return Boolean.TRUE;
}
@Override
- protected Object visit(ASTFalseNode node, Object data) {
+ protected Object visit(final ASTFalseNode node, final Object data) {
return Boolean.FALSE;
}
@Override
- protected Object visit(ASTNumberLiteral node, Object data) {
+ protected Object visit(final ASTNumberLiteral node, final Object data) {
if (data != null && node.isInteger()) {
return getAttribute(data, node.getLiteral(), node);
}
@@ -861,7 +861,7 @@
}
@Override
- protected Object visit(ASTStringLiteral node, Object data) {
+ protected Object visit(final ASTStringLiteral node, final Object data) {
if (data != null) {
return getAttribute(data, node.getLiteral(), node);
}
@@ -869,22 +869,22 @@
}
@Override
- protected Object visit(ASTRegexLiteral node, Object data) {
+ protected Object visit(final ASTRegexLiteral node, final Object data) {
return node.getLiteral();
}
@Override
- protected Object visit(ASTArrayLiteral node, Object data) {
- int childCount = node.jjtGetNumChildren();
- JexlArithmetic.ArrayBuilder ab = arithmetic.arrayBuilder(childCount);
+ protected Object visit(final ASTArrayLiteral node, final Object data) {
+ final int childCount = node.jjtGetNumChildren();
+ final JexlArithmetic.ArrayBuilder ab = arithmetic.arrayBuilder(childCount);
boolean extended = false;
for (int i = 0; i < childCount; i++) {
cancelCheck(node);
- JexlNode child = node.jjtGetChild(i);
+ final JexlNode child = node.jjtGetChild(i);
if (child instanceof ASTExtendedLiteral) {
extended = true;
} else {
- Object entry = node.jjtGetChild(i).jjtAccept(this, data);
+ final Object entry = node.jjtGetChild(i).jjtAccept(this, data);
ab.add(entry);
}
}
@@ -892,47 +892,47 @@
}
@Override
- protected Object visit(ASTExtendedLiteral node, Object data) {
+ protected Object visit(final ASTExtendedLiteral node, final Object data) {
return node;
}
@Override
- protected Object visit(ASTSetLiteral node, Object data) {
- int childCount = node.jjtGetNumChildren();
- JexlArithmetic.SetBuilder mb = arithmetic.setBuilder(childCount);
+ protected Object visit(final ASTSetLiteral node, final Object data) {
+ final int childCount = node.jjtGetNumChildren();
+ final JexlArithmetic.SetBuilder mb = arithmetic.setBuilder(childCount);
for (int i = 0; i < childCount; i++) {
cancelCheck(node);
- Object entry = node.jjtGetChild(i).jjtAccept(this, data);
+ final Object entry = node.jjtGetChild(i).jjtAccept(this, data);
mb.add(entry);
}
return mb.create();
}
@Override
- protected Object visit(ASTMapLiteral node, Object data) {
- int childCount = node.jjtGetNumChildren();
- JexlArithmetic.MapBuilder mb = arithmetic.mapBuilder(childCount);
+ protected Object visit(final ASTMapLiteral node, final Object data) {
+ final int childCount = node.jjtGetNumChildren();
+ final JexlArithmetic.MapBuilder mb = arithmetic.mapBuilder(childCount);
for (int i = 0; i < childCount; i++) {
cancelCheck(node);
- Object[] entry = (Object[]) (node.jjtGetChild(i)).jjtAccept(this, data);
+ final Object[] entry = (Object[]) (node.jjtGetChild(i)).jjtAccept(this, data);
mb.put(entry[0], entry[1]);
}
return mb.create();
}
@Override
- protected Object visit(ASTMapEntry node, Object data) {
- Object key = node.jjtGetChild(0).jjtAccept(this, data);
- Object value = node.jjtGetChild(1).jjtAccept(this, data);
+ protected Object visit(final ASTMapEntry node, final Object data) {
+ final Object key = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object value = node.jjtGetChild(1).jjtAccept(this, data);
return new Object[]{key, value};
}
@Override
- protected Object visit(ASTTernaryNode node, Object data) {
+ protected Object visit(final ASTTernaryNode node, final Object data) {
Object condition;
try {
condition = node.jjtGetChild(0).jjtAccept(this, data);
- } catch(JexlException xany) {
+ } catch(final JexlException xany) {
if (!(xany.getCause() instanceof JexlArithmetic.NullOperand)) {
throw xany;
}
@@ -955,11 +955,11 @@
}
@Override
- protected Object visit(ASTNullpNode node, Object data) {
+ protected Object visit(final ASTNullpNode node, final Object data) {
Object lhs;
try {
lhs = node.jjtGetChild(0).jjtAccept(this, data);
- } catch(JexlException xany) {
+ } catch(final JexlException xany) {
if (!(xany.getCause() instanceof JexlArithmetic.NullOperand)) {
throw xany;
}
@@ -970,21 +970,21 @@
}
@Override
- protected Object visit(ASTSizeFunction node, Object data) {
+ protected Object visit(final ASTSizeFunction node, final Object data) {
try {
- Object val = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object val = node.jjtGetChild(0).jjtAccept(this, data);
return operators.size(node, val);
- } catch(JexlException xany) {
+ } catch(final JexlException xany) {
return 0;
}
}
@Override
- protected Object visit(ASTEmptyFunction node, Object data) {
+ protected Object visit(final ASTEmptyFunction node, final Object data) {
try {
- Object value = node.jjtGetChild(0).jjtAccept(this, data);
+ final Object value = node.jjtGetChild(0).jjtAccept(this, data);
return operators.empty(node, value);
- } catch(JexlException xany) {
+ } catch(final JexlException xany) {
return true;
}
}
@@ -995,7 +995,7 @@
* @param data the usual data
* @return the return value
*/
- protected Object visitLexicalNode(JexlNode node, Object data) {
+ protected Object visitLexicalNode(final JexlNode node, final Object data) {
block = new LexicalFrame(frame, null);
try {
return node.jjtAccept(this, data);
@@ -1010,11 +1010,11 @@
* @param data the usual data
* @return the closure return value
*/
- protected Object runClosure(Closure closure, Object data) {
- ASTJexlScript script = closure.getScript();
+ protected Object runClosure(final Closure closure, final Object data) {
+ final ASTJexlScript script = closure.getScript();
block = new LexicalFrame(frame, block).defineArgs();
try {
- JexlNode body = script.jjtGetChild(script.jjtGetNumChildren() - 1);
+ final JexlNode body = script.jjtGetChild(script.jjtGetNumChildren() - 1);
return interpret(body);
} finally {
block = block.pop();
@@ -1022,7 +1022,7 @@
}
@Override
- protected Object visit(ASTJexlScript script, Object data) {
+ protected Object visit(final ASTJexlScript script, final Object data) {
if (script instanceof ASTJexlLambda && !((ASTJexlLambda) script).isTopLevel()) {
return new Closure(this, (ASTJexlLambda) script);
} else {
@@ -1031,7 +1031,7 @@
final int numChildren = script.jjtGetNumChildren();
Object result = null;
for (int i = 0; i < numChildren; i++) {
- JexlNode child = script.jjtGetChild(i);
+ final JexlNode child = script.jjtGetChild(i);
result = child.jjtAccept(this, data);
cancelCheck(child);
}
@@ -1043,12 +1043,12 @@
}
@Override
- protected Object visit(ASTReferenceExpression node, Object data) {
+ protected Object visit(final ASTReferenceExpression node, final Object data) {
return node.jjtGetChild(0).jjtAccept(this, data);
}
@Override
- protected Object visit(ASTIdentifier identifier, Object data) {
+ protected Object visit(final ASTIdentifier identifier, final Object data) {
cancelCheck(identifier);
return data != null
? getAttribute(data, identifier.getName(), identifier)
@@ -1056,17 +1056,17 @@
}
@Override
- protected Object visit(ASTArrayAccess node, Object data) {
+ protected Object visit(final ASTArrayAccess node, final Object data) {
// first objectNode is the identifier
Object object = data;
// can have multiple nodes - either an expression, integer literal or reference
- int numChildren = node.jjtGetNumChildren();
+ final int numChildren = node.jjtGetNumChildren();
for (int i = 0; i < numChildren; i++) {
- JexlNode nindex = node.jjtGetChild(i);
+ final JexlNode nindex = node.jjtGetChild(i);
if (object == null) {
return unsolvableProperty(nindex, stringifyProperty(nindex), false, null);
}
- Object index = nindex.jjtAccept(this, null);
+ final Object index = nindex.jjtAccept(this, null);
cancelCheck(node);
object = getAttribute(object, index, nindex);
}
@@ -1079,7 +1079,7 @@
* @param node the identifier access node
* @return the evaluated identifier
*/
- private Object evalIdentifier(ASTIdentifierAccess node) {
+ private Object evalIdentifier(final ASTIdentifierAccess node) {
if (node instanceof ASTIdentifierAccessJxlt) {
final ASTIdentifierAccessJxlt accessJxlt = (ASTIdentifierAccessJxlt) node;
final String src = node.getName();
@@ -1087,18 +1087,18 @@
TemplateEngine.TemplateExpression expr = (TemplateEngine.TemplateExpression) accessJxlt.getExpression();
try {
if (expr == null) {
- TemplateEngine jxlt = jexl.jxlt();
+ final TemplateEngine jxlt = jexl.jxlt();
expr = jxlt.parseExpression(node.jexlInfo(), src, frame != null ? frame.getScope() : null);
accessJxlt.setExpression(expr);
}
if (expr != null) {
- Object name = expr.evaluate(frame, context);
+ final Object name = expr.evaluate(frame, context);
if (name != null) {
- Integer id = ASTIdentifierAccess.parseIdentifier(name.toString());
+ final Integer id = ASTIdentifierAccess.parseIdentifier(name.toString());
return id != null ? id : name;
}
}
- } catch (JxltEngine.Exception xjxlt) {
+ } catch (final JxltEngine.Exception xjxlt) {
cause = xjxlt;
}
return node.isSafe() ? null : unsolvableProperty(node, src, true, cause);
@@ -1108,16 +1108,16 @@
}
@Override
- protected Object visit(ASTIdentifierAccess node, Object data) {
+ protected Object visit(final ASTIdentifierAccess node, final Object data) {
if (data == null) {
return null;
}
- Object id = evalIdentifier(node);
+ final Object id = evalIdentifier(node);
return getAttribute(data, id, node);
}
@Override
- protected Object visit(final ASTReference node, Object data) {
+ protected Object visit(final ASTReference node, final Object data) {
cancelCheck(node);
final int numChildren = node.jjtGetNumChildren();
final JexlNode parent = node.jjtGetParent();
@@ -1136,9 +1136,9 @@
if (object == null) {
// we may be performing a method call on an antish var
if (ant != null) {
- JexlNode child = objectNode.jjtGetChild(0);
+ final JexlNode child = objectNode.jjtGetChild(0);
if (child instanceof ASTIdentifierAccess) {
- int alen = ant.length();
+ final int alen = ant.length();
ant.append('.');
ant.append(((ASTIdentifierAccess) child).getName());
object = context.get(ant.toString());
@@ -1171,9 +1171,9 @@
// create first from first node
if (ant == null) {
// if we still have a null object, check for an antish variable
- JexlNode first = node.jjtGetChild(0);
+ final JexlNode first = node.jjtGetChild(0);
if (first instanceof ASTIdentifier) {
- ASTIdentifier afirst = (ASTIdentifier) first;
+ final ASTIdentifier afirst = (ASTIdentifier) first;
ant = new StringBuilder(afirst.getName());
// skip the else...*
} else {
@@ -1193,9 +1193,9 @@
}
// catch up to current node
for (; v <= c; ++v) {
- JexlNode child = node.jjtGetChild(v);
+ final JexlNode child = node.jjtGetChild(v);
if (child instanceof ASTIdentifierAccess) {
- ASTIdentifierAccess achild = (ASTIdentifierAccess) child;
+ final ASTIdentifierAccess achild = (ASTIdentifierAccess) child;
if (achild.isSafe() || achild.isExpression()) {
break main;
}
@@ -1222,8 +1222,8 @@
return null;
}
if (ant != null) {
- String aname = ant.toString();
- boolean defined = isVariableDefined(frame, block, aname);
+ final String aname = ant.toString();
+ final boolean defined = isVariableDefined(frame, block, aname);
return unsolvableVariable(node, aname, !defined);
}
return unsolvableProperty(node,
@@ -1233,8 +1233,8 @@
if (node.isSafeLhs(isSafe())) {
return null;
}
- String aname = ant != null ? ant.toString() : "?";
- boolean defined = isVariableDefined(frame, block, aname);
+ final String aname = ant != null ? ant.toString() : "?";
+ final boolean defined = isVariableDefined(frame, block, aname);
if (defined && !arithmetic.isStrict()) {
return null;
}
@@ -1247,47 +1247,47 @@
}
@Override
- protected Object visit(ASTAssignment node, Object data) {
+ protected Object visit(final ASTAssignment node, final Object data) {
return executeAssign(node, null, data);
}
@Override
- protected Object visit(ASTSetAddNode node, Object data) {
+ protected Object visit(final ASTSetAddNode node, final Object data) {
return executeAssign(node, JexlOperator.SELF_ADD, data);
}
@Override
- protected Object visit(ASTSetSubNode node, Object data) {
+ protected Object visit(final ASTSetSubNode node, final Object data) {
return executeAssign(node, JexlOperator.SELF_SUBTRACT, data);
}
@Override
- protected Object visit(ASTSetMultNode node, Object data) {
+ protected Object visit(final ASTSetMultNode node, final Object data) {
return executeAssign(node, JexlOperator.SELF_MULTIPLY, data);
}
@Override
- protected Object visit(ASTSetDivNode node, Object data) {
+ protected Object visit(final ASTSetDivNode node, final Object data) {
return executeAssign(node, JexlOperator.SELF_DIVIDE, data);
}
@Override
- protected Object visit(ASTSetModNode node, Object data) {
+ protected Object visit(final ASTSetModNode node, final Object data) {
return executeAssign(node, JexlOperator.SELF_MOD, data);
}
@Override
- protected Object visit(ASTSetAndNode node, Object data) {
+ protected Object visit(final ASTSetAndNode node, final Object data) {
return executeAssign(node, JexlOperator.SELF_AND, data);
}
@Override
- protected Object visit(ASTSetOrNode node, Object data) {
+ protected Object visit(final ASTSetOrNode node, final Object data) {
return executeAssign(node, JexlOperator.SELF_OR, data);
}
@Override
- protected Object visit(ASTSetXorNode node, Object data) {
+ protected Object visit(final ASTSetXorNode node, final Object data) {
return executeAssign(node, JexlOperator.SELF_XOR, data);
}
@@ -1298,7 +1298,7 @@
* @param data the data
* @return the left hand side
*/
- protected Object executeAssign(JexlNode node, JexlOperator assignop, Object data) { // CSOFF: MethodLength
+ protected Object executeAssign(final JexlNode node, final JexlOperator assignop, final Object data) { // CSOFF: MethodLength
cancelCheck(node);
// left contains the reference to assign to
final JexlNode left = node.jjtGetChild(0);
@@ -1330,7 +1330,7 @@
// check we are not assigning a symbol itself
if (last < 0) {
if (assignop != null) {
- Object self = getVariable(frame, block, var);
+ final Object self = getVariable(frame, block, var);
right = operators.tryAssignOverload(node, assignop, self, right);
if (right == JexlOperator.ASSIGN) {
return self;
@@ -1350,7 +1350,7 @@
// check we are not assigning direct global
if (last < 0) {
if (assignop != null) {
- Object self = context.get(var.getName());
+ final Object self = context.get(var.getName());
right = operators.tryAssignOverload(node, assignop, self, right);
if (right == JexlOperator.ASSIGN) {
return self;
@@ -1382,8 +1382,8 @@
} else if (antish) {
// initialize if first time
if (ant == null) {
- JexlNode first = left.jjtGetChild(0);
- ASTIdentifier firstId = first instanceof ASTIdentifier
+ final JexlNode first = left.jjtGetChild(0);
+ final ASTIdentifier firstId = first instanceof ASTIdentifier
? (ASTIdentifier) first
: null;
if (firstId != null && firstId.getSymbol() < 0) {
@@ -1396,8 +1396,8 @@
}
// catch up to current child
for (; v <= c; ++v) {
- JexlNode child = left.jjtGetChild(v);
- ASTIdentifierAccess aid = child instanceof ASTIdentifierAccess
+ final JexlNode child = left.jjtGetChild(v);
+ final ASTIdentifierAccess aid = child instanceof ASTIdentifierAccess
? (ASTIdentifierAccess) child
: null;
// remain antish only if unsafe navigation
@@ -1418,7 +1418,7 @@
// 2: last objectNode will perform assignement in all cases
Object property = null;
JexlNode propertyNode = left.jjtGetChild(last);
- ASTIdentifierAccess propertyId = propertyNode instanceof ASTIdentifierAccess
+ final ASTIdentifierAccess propertyId = propertyNode instanceof ASTIdentifierAccess
? (ASTIdentifierAccess) propertyNode
: null;
if (propertyId != null) {
@@ -1429,7 +1429,7 @@
}
ant.append(propertyId.getName());
if (assignop != null) {
- Object self = context.get(ant.toString());
+ final Object self = context.get(ant.toString());
right = operators.tryAssignOverload(node, assignop, self, right);
if (right == JexlOperator.ASSIGN) {
return self;
@@ -1442,10 +1442,10 @@
property = evalIdentifier(propertyId);
} else if (propertyNode instanceof ASTArrayAccess) {
// can have multiple nodes - either an expression, integer literal or reference
- int numChildren = propertyNode.jjtGetNumChildren() - 1;
+ final int numChildren = propertyNode.jjtGetNumChildren() - 1;
for (int i = 0; i < numChildren; i++) {
- JexlNode nindex = propertyNode.jjtGetChild(i);
- Object index = nindex.jjtAccept(this, null);
+ final JexlNode nindex = propertyNode.jjtGetChild(i);
+ final Object index = nindex.jjtAccept(this, null);
object = getAttribute(object, index, nindex);
}
propertyNode = propertyNode.jjtGetChild(numChildren);
@@ -1461,7 +1461,7 @@
}
// 3: one before last, assign
if (assignop != null) {
- Object self = getAttribute(object, property, propertyNode);
+ final Object self = getAttribute(object, property, propertyNode);
right = operators.tryAssignOverload(node, assignop, self, right);
if (right == JexlOperator.ASSIGN) {
return self;
@@ -1472,7 +1472,7 @@
}
@Override
- protected Object[] visit(ASTArguments node, Object data) {
+ protected Object[] visit(final ASTArguments node, final Object data) {
final int argc = node.jjtGetNumChildren();
final Object[] argv = new Object[argc];
for (int i = 0; i < argc; i++) {
@@ -1482,7 +1482,7 @@
}
@Override
- protected Object visit(final ASTMethodNode node, Object data) {
+ protected Object visit(final ASTMethodNode node, final Object data) {
return visit(node, null, data);
}
@@ -1493,7 +1493,7 @@
* @param data the context
* @return the method call result
*/
- private Object visit(final ASTMethodNode node, Object object, Object data) {
+ private Object visit(final ASTMethodNode node, Object object, final Object data) {
// left contains the reference to the method
final JexlNode methodNode = node.jjtGetChild(0);
Object method;
@@ -1523,7 +1523,7 @@
? null
: unsolvableMethod(methodNode, "<?>.<null>(...)");
}
- ASTArguments argNode = (ASTArguments) node.jjtGetChild(a);
+ final ASTArguments argNode = (ASTArguments) node.jjtGetChild(a);
result = call(node, object, result, argNode);
object = result;
}
@@ -1531,11 +1531,11 @@
}
@Override
- protected Object visit(ASTFunctionNode node, Object data) {
- ASTIdentifier functionNode = (ASTIdentifier) node.jjtGetChild(0);
- String nsid = functionNode.getNamespace();
- Object namespace = (nsid != null)? resolveNamespace(nsid, node) : context;
- ASTArguments argNode = (ASTArguments) node.jjtGetChild(1);
+ protected Object visit(final ASTFunctionNode node, final Object data) {
+ final ASTIdentifier functionNode = (ASTIdentifier) node.jjtGetChild(0);
+ final String nsid = functionNode.getNamespace();
+ final Object namespace = (nsid != null)? resolveNamespace(nsid, node) : context;
+ final ASTArguments argNode = (ASTArguments) node.jjtGetChild(1);
return call(node, namespace, functionNode, argNode);
}
@@ -1556,7 +1556,7 @@
* @param argNode the node carrying the arguments
* @return the result of the method invocation
*/
- protected Object call(final JexlNode node, Object target, Object functor, final ASTArguments argNode) {
+ protected Object call(final JexlNode node, final Object target, Object functor, final ASTArguments argNode) {
cancelCheck(node);
// evaluate the arguments
final Object[] argv = visit(argNode, null);
@@ -1567,7 +1567,7 @@
boolean isavar = false;
if (functor instanceof ASTIdentifier) {
// function call, target is context or namespace (if there was one)
- ASTIdentifier methodIdentifier = (ASTIdentifier) functor;
+ final ASTIdentifier methodIdentifier = (ASTIdentifier) functor;
symbol = methodIdentifier.getSymbol();
methodName = methodIdentifier.getName();
functor = null;
@@ -1602,10 +1602,10 @@
}
// solving the call site
- CallDispatcher call = new CallDispatcher(node, cacheable);
+ final CallDispatcher call = new CallDispatcher(node, cacheable);
try {
// do we have a cached version method/function name ?
- Object eval = call.tryEval(target, methodName, argv);
+ final Object eval = call.tryEval(target, methodName, argv);
if (JexlEngine.TRY_FAILED != eval) {
return eval;
}
@@ -1622,7 +1622,7 @@
}
if (target == context) {
// solve 'null' namespace
- Object namespace = resolveNamespace(null, node);
+ final Object namespace = resolveNamespace(null, node);
if (namespace != null
&& namespace != context
&& call.isTargetMethod(namespace, methodName, argv)) {
@@ -1637,7 +1637,7 @@
} else {
// try prepending target to arguments and look for
// applicable method in context...
- Object[] pargv = functionArguments(target, narrow, argv);
+ final Object[] pargv = functionArguments(target, narrow, argv);
if (call.isContextMethod(methodName, pargv)) {
return call.eval(methodName);
}
@@ -1647,7 +1647,7 @@
}
// the method may also be a functor stored in a property of the target
if (!narrow) {
- JexlPropertyGet get = uberspect.getPropertyGet(target, methodName);
+ final JexlPropertyGet get = uberspect.getPropertyGet(target, methodName);
if (get != null) {
functor = get.tryInvoke(target, methodName);
functorp = functor != null;
@@ -1681,7 +1681,7 @@
}
// try prepending functor to arguments and look for
// context or arithmetic function called 'call'
- Object[] pargv = functionArguments(functor, narrow, argv);
+ final Object[] pargv = functionArguments(functor, narrow, argv);
if (call.isContextMethod(mCALL, pargv)) {
return call.eval(mCALL);
}
@@ -1702,36 +1702,36 @@
return node.isSafeLhs(isSafe())
? null
: unsolvableMethod(node, methodName, argv);
- } catch (JexlException.TryFailed xany) {
+ } catch (final JexlException.TryFailed xany) {
throw invocationException(node, methodName, xany);
- } catch (JexlException xthru) {
+ } catch (final JexlException xthru) {
throw xthru;
- } catch (Exception xany) {
+ } catch (final Exception xany) {
throw invocationException(node, methodName, xany);
}
}
@Override
- protected Object visit(ASTConstructorNode node, Object data) {
+ protected Object visit(final ASTConstructorNode node, final Object data) {
if (isCancelled()) {
throw new JexlException.Cancel(node);
}
// first child is class or class name
final Object target = node.jjtGetChild(0).jjtAccept(this, data);
// get the ctor args
- int argc = node.jjtGetNumChildren() - 1;
+ final int argc = node.jjtGetNumChildren() - 1;
Object[] argv = new Object[argc];
for (int i = 0; i < argc; i++) {
argv[i] = node.jjtGetChild(i + 1).jjtAccept(this, data);
}
try {
- boolean cacheable = cache;
+ final boolean cacheable = cache;
// attempt to reuse last funcall cached in volatile JexlNode.value
if (cacheable) {
- Object cached = node.jjtGetValue();
+ final Object cached = node.jjtGetValue();
if (cached instanceof Funcall) {
- Object eval = ((Funcall) cached).tryInvoke(this, null, target, argv);
+ final Object eval = ((Funcall) cached).tryInvoke(this, null, target, argv);
if (JexlEngine.TRY_FAILED != eval) {
return eval;
}
@@ -1750,7 +1750,7 @@
break;
}
// try with prepending context as first argument
- Object[] nargv = callArguments(context, narrow, argv);
+ final Object[] nargv = callArguments(context, narrow, argv);
ctor = uberspect.getConstructor(target, nargv);
if (ctor != null) {
if (cacheable && ctor.isCacheable()) {
@@ -1770,28 +1770,28 @@
}
// we have either evaluated and returned or might have found a ctor
if (ctor != null) {
- Object eval = ctor.invoke(target, argv);
+ final Object eval = ctor.invoke(target, argv);
// cache executor in volatile JexlNode.value
if (funcall != null) {
node.jjtSetValue(funcall);
}
return eval;
}
- String tstr = target != null ? target.toString() : "?";
+ final String tstr = target != null ? target.toString() : "?";
return unsolvableMethod(node, tstr, argv);
- } catch (JexlException.Method xmethod) {
+ } catch (final JexlException.Method xmethod) {
throw xmethod;
- } catch (Exception xany) {
- String tstr = target != null ? target.toString() : "?";
+ } catch (final Exception xany) {
+ final String tstr = target != null ? target.toString() : "?";
throw invocationException(node, tstr, xany);
}
}
@Override
- protected Object visit(ASTJxltLiteral node, Object data) {
+ protected Object visit(final ASTJxltLiteral node, final Object data) {
TemplateEngine.TemplateExpression tp = (TemplateEngine.TemplateExpression) node.jjtGetValue();
if (tp == null) {
- TemplateEngine jxlt = jexl.jxlt();
+ final TemplateEngine jxlt = jexl.jxlt();
JexlInfo info = node.jexlInfo();
if (this.block != null) {
info = new JexlNode.Info(node, info);
@@ -1806,12 +1806,12 @@
}
@Override
- protected Object visit(ASTAnnotation node, Object data) {
+ protected Object visit(final ASTAnnotation node, final Object data) {
throw new UnsupportedOperationException(ASTAnnotation.class.getName() + ": Not supported.");
}
@Override
- protected Object visit(ASTAnnotatedStatement node, Object data) {
+ protected Object visit(final ASTAnnotatedStatement node, final Object data) {
return processAnnotation(node, 0, data);
}
@@ -1877,7 +1877,7 @@
// are we evaluating the block ?
final int last = stmt.jjtGetNumChildren() - 1;
if (index == last) {
- JexlNode cblock = stmt.jjtGetChild(last);
+ final JexlNode cblock = stmt.jjtGetChild(last);
// if the context has changed, might need a new interpreter
final JexlArithmetic jexla = arithmetic.options(context);
if (jexla != arithmetic) {
@@ -1886,8 +1886,8 @@
+ ", got " + jexla.getClass().getSimpleName()
);
}
- Interpreter ii = new Interpreter(Interpreter.this, jexla);
- Object r = cblock.jjtAccept(ii, data);
+ final Interpreter ii = new Interpreter(Interpreter.this, jexla);
+ final Object r = cblock.jjtAccept(ii, data);
if (ii.isCancelled()) {
Interpreter.this.cancel();
}
@@ -1902,7 +1902,7 @@
final ASTAnnotation anode = (ASTAnnotation) stmt.jjtGetChild(index);
final String aname = anode.getName();
// evaluate the arguments
- Object[] argv = anode.jjtGetNumChildren() > 0
+ final Object[] argv = anode.jjtGetNumChildren() > 0
? visit((ASTArguments) anode.jjtGetChild(0), null) : null;
// wrap the future, will recurse through annotation processor
Object result;
@@ -1912,9 +1912,9 @@
if (!jstmt.isProcessed()) {
return annotationError(anode, aname, null);
}
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
throw xany;
- } catch (Exception xany) {
+ } catch (final Exception xany) {
return annotationError(anode, aname, xany);
}
// the caller may return a return, break or continue
@@ -1932,7 +1932,7 @@
* @return the result of statement.call()
* @throws Exception if anything goes wrong
*/
- protected Object processAnnotation(String annotation, Object[] args, Callable<Object> stmt) throws Exception {
+ protected Object processAnnotation(final String annotation, final Object[] args, final Callable<Object> stmt) throws Exception {
return context instanceof JexlContext.AnnotationProcessor
? ((JexlContext.AnnotationProcessor) context).processAnnotation(annotation, args, stmt)
: stmt.call();
diff --git a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
index 16402e3..29e12f4 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
@@ -84,13 +84,13 @@
* @param opts the evaluation options
* @param aContext the evaluation context
*/
- protected InterpreterBase(Engine engine, JexlOptions opts, JexlContext aContext) {
+ protected InterpreterBase(final Engine engine, final JexlOptions opts, final JexlContext aContext) {
this.jexl = engine;
this.logger = jexl.logger;
this.uberspect = jexl.uberspect;
this.context = aContext != null ? aContext : Engine.EMPTY_CONTEXT;
this.cache = engine.cache != null;
- JexlArithmetic jexla = jexl.arithmetic;
+ final JexlArithmetic jexla = jexl.arithmetic;
this.options = opts == null? engine.options(aContext) : opts;
this.arithmetic = jexla.options(options);
if (arithmetic != jexla && !arithmetic.getClass().equals(jexla.getClass())) {
@@ -108,7 +108,7 @@
acancel = ((JexlContext.CancellationHandle) context).getCancellation();
}
this.cancelled = acancel != null? acancel : new AtomicBoolean(false);
- Map<String,Object> ons = options.getNamespaces();
+ final Map<String,Object> ons = options.getNamespaces();
this.functions = ons.isEmpty()? jexl.functions : ons;
this.functors = null;
this.operators = new Operators(this);
@@ -119,7 +119,7 @@
* @param ii the base to copy
* @param jexla the arithmetic instance to use (or null)
*/
- protected InterpreterBase(InterpreterBase ii, JexlArithmetic jexla) {
+ protected InterpreterBase(final InterpreterBase ii, final JexlArithmetic jexla) {
jexl = ii.jexl;
logger = ii.logger;
uberspect = ii.uberspect;
@@ -139,13 +139,13 @@
* <p>This is used when dealing with auto-closeable (duck-like) objects
* @param closeable the object we'd like to close
*/
- protected void closeIfSupported(Object closeable) {
+ protected void closeIfSupported(final Object closeable) {
if (closeable != null) {
- JexlMethod mclose = uberspect.getMethod(closeable, "close", EMPTY_PARAMS);
+ final JexlMethod mclose = uberspect.getMethod(closeable, "close", EMPTY_PARAMS);
if (mclose != null) {
try {
mclose.invoke(closeable, EMPTY_PARAMS);
- } catch (Exception xignore) {
+ } catch (final Exception xignore) {
logger.warn(xignore);
}
}
@@ -160,7 +160,7 @@
* @param node the AST node
* @return the namespace instance
*/
- protected Object resolveNamespace(String prefix, JexlNode node) {
+ protected Object resolveNamespace(final String prefix, final JexlNode node) {
Object namespace;
// check whether this namespace is a functor
synchronized (this) {
@@ -181,7 +181,7 @@
}
// shortcut if ns is known to be not-a-functor
final boolean cacheable = cache;
- Object cached = cacheable ? node.jjtGetValue() : null;
+ final Object cached = cacheable ? node.jjtGetValue() : null;
if (cached != JexlContext.NamespaceFunctor.class) {
// allow namespace to instantiate a functor with context if possible, not an error otherwise
Object functor = null;
@@ -191,11 +191,11 @@
// attempt to reuse last ctor cached in volatile JexlNode.value
if (cached instanceof JexlMethod) {
try {
- Object eval = ((JexlMethod) cached).tryInvoke(null, context);
+ final Object eval = ((JexlMethod) cached).tryInvoke(null, context);
if (JexlEngine.TRY_FAILED != eval) {
functor = eval;
}
- } catch (JexlException.TryFailed xtry) {
+ } catch (final JexlException.TryFailed xtry) {
throw new JexlException(node, "unable to instantiate namespace " + prefix, xtry.getCause());
}
}
@@ -208,7 +208,7 @@
if (cacheable && ctor.isCacheable()) {
node.jjtSetValue(ctor);
}
- } catch (Exception xinst) {
+ } catch (final Exception xinst) {
throw new JexlException(node, "unable to instantiate namespace " + prefix, xinst);
}
}
@@ -218,7 +218,7 @@
if (ctor != null) {
try {
functor = ctor.invoke(namespace);
- } catch (Exception xinst) {
+ } catch (final Exception xinst) {
throw new JexlException(node, "unable to instantiate namespace " + prefix, xinst);
}
}
@@ -228,7 +228,7 @@
if (namespace instanceof String) {
try {
namespace = uberspect.getClassLoader().loadClass((String) namespace);
- } catch (ClassNotFoundException xignore) {
+ } catch (final ClassNotFoundException xignore) {
// not a class
namespace = null;
}
@@ -260,8 +260,8 @@
* @param frame the frame in which it will be defined
* @return true if definition succeeded, false otherwise
*/
- protected boolean defineVariable(ASTVar var, LexicalFrame frame) {
- int symbol = var.getSymbol();
+ protected boolean defineVariable(final ASTVar var, final LexicalFrame frame) {
+ final int symbol = var.getSymbol();
if (symbol < 0) {
return false;
}
@@ -280,12 +280,12 @@
* @param name the variable name
* @return true if variable is defined, false otherwise
*/
- protected boolean isVariableDefined(Frame frame, LexicalScope block, String name) {
+ protected boolean isVariableDefined(final Frame frame, final LexicalScope block, final String name) {
if (frame != null && block != null) {
- Integer ref = frame.getScope().getSymbol(name);
- int symbol = ref != null? ref : -1;
+ final Integer ref = frame.getScope().getSymbol(name);
+ final int symbol = ref != null? ref : -1;
if (symbol >= 0 && block.hasSymbol(symbol)) {
- Object value = frame.get(symbol);
+ final Object value = frame.get(symbol);
return value != Scope.UNDEFINED && value != Scope.UNDECLARED;
}
}
@@ -299,24 +299,24 @@
* @param identifier the variable node
* @return the value
*/
- protected Object getVariable(Frame frame, LexicalScope block, ASTIdentifier identifier) {
- int symbol = identifier.getSymbol();
+ protected Object getVariable(final Frame frame, final LexicalScope block, final ASTIdentifier identifier) {
+ final int symbol = identifier.getSymbol();
// if we have a symbol, we have a scope thus a frame
if (options.isLexicalShade() && identifier.isShaded()) {
return undefinedVariable(identifier, identifier.getName());
}
if (symbol >= 0) {
if (frame.has(symbol)) {
- Object value = frame.get(symbol);
+ final Object value = frame.get(symbol);
if (value != Scope.UNDEFINED) {
return value;
}
}
}
- String name = identifier.getName();
- Object value = context.get(name);
+ final String name = identifier.getName();
+ final Object value = context.get(name);
if (value == null && !context.has(name)) {
- boolean ignore = (isSafe()
+ final boolean ignore = (isSafe()
&& (symbol >= 0
|| identifier.jjtGetParent() instanceof ASTAssignment))
|| (identifier.jjtGetParent() instanceof ASTReference);
@@ -335,13 +335,13 @@
* @param name the variable name
* @param value the variable value
*/
- protected void setContextVariable(JexlNode node, String name, Object value) {
+ protected void setContextVariable(final JexlNode node, final String name, final Object value) {
if (options.isLexicalShade() && !context.has(name)) {
throw new JexlException.Variable(node, name, true);
}
try {
context.set(name, value);
- } catch (UnsupportedOperationException xsupport) {
+ } catch (final UnsupportedOperationException xsupport) {
throw new JexlException(node, "context is readonly", xsupport);
}
}
@@ -385,7 +385,7 @@
* @param right the right argument
* @return the left, right or parent node
*/
- protected JexlNode findNullOperand(RuntimeException xrt, JexlNode node, Object left, Object right) {
+ protected JexlNode findNullOperand(final RuntimeException xrt, final JexlNode node, final Object left, final Object right) {
if (xrt instanceof JexlArithmetic.NullOperand) {
if (left == null) {
return node.jjtGetChild(0);
@@ -404,7 +404,7 @@
* @param undef whether the variable is undefined or null
* @return throws JexlException if strict and not silent, null otherwise
*/
- protected Object unsolvableVariable(JexlNode node, String var, boolean undef) {
+ protected Object unsolvableVariable(final JexlNode node, final String var, final boolean undef) {
return variableError(node, var, undef? VariableIssue.UNDEFINED : VariableIssue.NULLVALUE);
}
@@ -414,7 +414,7 @@
* @param var the variable name
* @return throws JexlException if strict and not silent, null otherwise
*/
- protected Object undefinedVariable(JexlNode node, String var) {
+ protected Object undefinedVariable(final JexlNode node, final String var) {
return variableError(node, var, VariableIssue.UNDEFINED);
}
@@ -424,7 +424,7 @@
* @param var the variable name
* @return throws JexlException if strict and not silent, null otherwise
*/
- protected Object redefinedVariable(JexlNode node, String var) {
+ protected Object redefinedVariable(final JexlNode node, final String var) {
return variableError(node, var, VariableIssue.REDEFINED);
}
@@ -435,7 +435,7 @@
* @param issue the issue type
* @return throws JexlException if strict and not silent, null otherwise
*/
- protected Object variableError(JexlNode node, String var, VariableIssue issue) {
+ protected Object variableError(final JexlNode node, final String var, final VariableIssue issue) {
if (isStrictEngine() && !node.isTernaryProtected()) {
throw new JexlException.Variable(node, var, issue);
} else if (logger.isDebugEnabled()) {
@@ -449,7 +449,7 @@
* @param method the method name
* @return throws JexlException if strict and not silent, null otherwise
*/
- protected Object unsolvableMethod(JexlNode node, String method) {
+ protected Object unsolvableMethod(final JexlNode node, final String method) {
return unsolvableMethod(node, method, null);
}
@@ -460,7 +460,7 @@
* @param args the method arguments
* @return throws JexlException if strict and not silent, null otherwise
*/
- protected Object unsolvableMethod(JexlNode node, String method, Object[] args) {
+ protected Object unsolvableMethod(final JexlNode node, final String method, final Object[] args) {
if (isStrictEngine()) {
throw new JexlException.Method(node, method, args);
} else if (logger.isDebugEnabled()) {
@@ -477,7 +477,7 @@
* @param undef whether the property is undefined or null
* @return throws JexlException if strict and not silent, null otherwise
*/
- protected Object unsolvableProperty(JexlNode node, String property, boolean undef, Throwable cause) {
+ protected Object unsolvableProperty(final JexlNode node, final String property, final boolean undef, final Throwable cause) {
if (isStrictEngine() && !node.isTernaryProtected()) {
throw new JexlException.Property(node, property, undef, cause);
} else if (logger.isDebugEnabled()) {
@@ -492,7 +492,7 @@
* @param which the child we are checking
* @return true if child is local variable, false otherwise
*/
- protected boolean isLocalVariable(ASTReference node, int which) {
+ protected boolean isLocalVariable(final ASTReference node, final int which) {
return (node.jjtGetNumChildren() > which
&& node.jjtGetChild(which) instanceof ASTIdentifier
&& ((ASTIdentifier) node.jjtGetChild(which)).getSymbol() >= 0);
@@ -503,7 +503,7 @@
* @param node the reference node
* @return true if child is function call, false otherwise
*/
- protected boolean isFunctionCall(ASTReference node) {
+ protected boolean isFunctionCall(final ASTReference node) {
return (node.jjtGetNumChildren() > 0
&& node.jjtGetChild(0) instanceof ASTFunctionNode);
}
@@ -514,7 +514,7 @@
* @param node the property node
* @return the (pretty) string
*/
- protected String stringifyProperty(JexlNode node) {
+ protected String stringifyProperty(final JexlNode node) {
if (node instanceof ASTArrayAccess) {
return "["
+ stringifyPropertyValue(node.jjtGetChild(0))
@@ -541,7 +541,7 @@
* @param node the property node
* @return the (pretty) string value
*/
- protected static String stringifyPropertyValue(JexlNode node) {
+ protected static String stringifyPropertyValue(final JexlNode node) {
return node != null? new Debugger().depth(1).data(node) : "???";
}
@@ -552,7 +552,7 @@
* @param cause the cause of error (if any)
* @return throws JexlException if strict and not silent, null otherwise
*/
- protected Object operatorError(JexlNode node, JexlOperator operator, Throwable cause) {
+ protected Object operatorError(final JexlNode node, final JexlOperator operator, final Throwable cause) {
if (isStrictEngine()) {
throw new JexlException.Operator(node, operator.getOperatorSymbol(), cause);
} else if (logger.isDebugEnabled()) {
@@ -568,7 +568,7 @@
* @param cause the cause of error (if any)
* @return throws a JexlException if strict and not silent, null otherwise
*/
- protected Object annotationError(JexlNode node, String annotation, Throwable cause) {
+ protected Object annotationError(final JexlNode node, final String annotation, final Throwable cause) {
if (isStrictEngine()) {
throw new JexlException.Annotation(node, annotation, cause);
} else if (logger.isDebugEnabled()) {
@@ -584,8 +584,8 @@
* @param xany the cause
* @return a JexlException that will be thrown
*/
- protected JexlException invocationException(JexlNode node, String methodName, Throwable xany) {
- Throwable cause = xany.getCause();
+ protected JexlException invocationException(final JexlNode node, final String methodName, final Throwable xany) {
+ final Throwable cause = xany.getCause();
if (cause instanceof JexlException) {
return (JexlException) cause;
}
@@ -615,7 +615,7 @@
* Throws a JexlException.Cancel if script execution was cancelled.
* @param node the node being evaluated
*/
- protected void cancelCheck(JexlNode node) {
+ protected void cancelCheck(final JexlNode node) {
if (isCancelled()) {
throw new JexlException.Cancel(node);
}
@@ -629,7 +629,7 @@
* @param args the other (non null) arguments
* @return the arguments array
*/
- protected Object[] functionArguments(Object target, boolean narrow, Object[] args) {
+ protected Object[] functionArguments(final Object target, final boolean narrow, final Object[] args) {
// when target == context, we are dealing with the null namespace
if (target == null || target == context) {
if (narrow) {
@@ -638,7 +638,7 @@
return args;
}
// makes target 1st args, copy others - optionally narrow numbers
- Object[] nargv = new Object[args.length + 1];
+ final Object[] nargv = new Object[args.length + 1];
if (narrow) {
nargv[0] = functionArgument(true, target);
for (int a = 1; a <= args.length; ++a) {
@@ -658,9 +658,9 @@
* @param args the other (non null) arguments
* @return the arguments array
*/
- protected Object[] callArguments(Object target, boolean narrow, Object[] args) {
+ protected Object[] callArguments(final Object target, final boolean narrow, final Object[] args) {
// makes target 1st args, copy others - optionally narrow numbers
- Object[] nargv = new Object[args.length + 1];
+ final Object[] nargv = new Object[args.length + 1];
if (narrow) {
nargv[0] = functionArgument(true, target);
for (int a = 1; a <= args.length; ++a) {
@@ -679,7 +679,7 @@
* @param arg the argument
* @return the narrowed argument
*/
- protected Object functionArgument(boolean narrow, Object arg) {
+ protected Object functionArgument(final boolean narrow, final Object arg) {
return narrow && arg instanceof Number ? arithmetic.narrow((Number) arg) : arg;
}
@@ -696,7 +696,7 @@
* @param jme the method
* @param flag the narrow flag
*/
- protected Funcall(JexlMethod jme, boolean flag) {
+ protected Funcall(final JexlMethod jme, final boolean flag) {
this.me = jme;
this.narrow = flag;
}
@@ -709,7 +709,7 @@
* @param args the method arguments
* @return the method invocation result (or JexlEngine.TRY_FAILED)
*/
- protected Object tryInvoke(InterpreterBase ii, String name, Object target, Object[] args) {
+ protected Object tryInvoke(final InterpreterBase ii, final String name, final Object target, final Object[] args) {
return me.tryInvoke(name, target, ii.functionArguments(null, narrow, args));
}
}
@@ -723,12 +723,12 @@
* @param jme the method
* @param flag the narrow flag
*/
- protected ArithmeticFuncall(JexlMethod jme, boolean flag) {
+ protected ArithmeticFuncall(final JexlMethod jme, final boolean flag) {
super(jme, flag);
}
@Override
- protected Object tryInvoke(InterpreterBase ii, String name, Object target, Object[] args) {
+ protected Object tryInvoke(final InterpreterBase ii, final String name, final Object target, final Object[] args) {
return me.tryInvoke(name, ii.arithmetic, ii.functionArguments(target, narrow, args));
}
}
@@ -742,12 +742,12 @@
* @param jme the method
* @param flag the narrow flag
*/
- protected ContextFuncall(JexlMethod jme, boolean flag) {
+ protected ContextFuncall(final JexlMethod jme, final boolean flag) {
super(jme, flag);
}
@Override
- protected Object tryInvoke(InterpreterBase ii, String name, Object target, Object[] args) {
+ protected Object tryInvoke(final InterpreterBase ii, final String name, final Object target, final Object[] args) {
return me.tryInvoke(name, ii.context, ii.functionArguments(target, narrow, args));
}
}
@@ -761,12 +761,12 @@
* @param jme the method
* @param flag the narrow flag
*/
- protected ContextualCtor(JexlMethod jme, boolean flag) {
+ protected ContextualCtor(final JexlMethod jme, final boolean flag) {
super(jme, flag);
}
@Override
- protected Object tryInvoke(InterpreterBase ii, String name, Object target, Object[] args) {
+ protected Object tryInvoke(final InterpreterBase ii, final String name, final Object target, final Object[] args) {
return me.tryInvoke(name, target, ii.callArguments(ii.context, narrow, args));
}
}
@@ -810,7 +810,7 @@
* @param anode the syntactic node.
* @param acacheable whether resolution can be cached
*/
- CallDispatcher(JexlNode anode, boolean acacheable) {
+ CallDispatcher(final JexlNode anode, final boolean acacheable) {
this.node = anode;
this.cacheable = acacheable;
}
@@ -823,7 +823,7 @@
* @param arguments the method arguments
* @return true if arithmetic, false otherwise
*/
- protected boolean isTargetMethod(Object ntarget, String mname, final Object[] arguments) {
+ protected boolean isTargetMethod(final Object ntarget, final String mname, final Object[] arguments) {
// try a method
vm = uberspect.getMethod(ntarget, mname, arguments);
if (vm != null) {
@@ -844,7 +844,7 @@
* @param arguments the method arguments
* @return true if arithmetic, false otherwise
*/
- protected boolean isContextMethod(String mname, final Object[] arguments) {
+ protected boolean isContextMethod(final String mname, final Object[] arguments) {
vm = uberspect.getMethod(context, mname, arguments);
if (vm != null) {
argv = arguments;
@@ -864,7 +864,7 @@
* @param arguments the method arguments
* @return true if arithmetic, false otherwise
*/
- protected boolean isArithmeticMethod(String mname, final Object[] arguments) {
+ protected boolean isArithmeticMethod(final String mname, final Object[] arguments) {
vm = uberspect.getMethod(arithmetic, mname, arguments);
if (vm != null) {
argv = arguments;
@@ -891,7 +891,7 @@
// do we have a method/function name ?
// attempt to reuse last funcall cached in volatile JexlNode.value (if it was not a variable)
if (mname != null && cacheable && ntarget != null) {
- Object cached = node.jjtGetValue();
+ final Object cached = node.jjtGetValue();
if (cached instanceof Funcall) {
return ((Funcall) cached).tryInvoke(InterpreterBase.this, mname, ntarget, arguments);
}
@@ -906,11 +906,11 @@
* @return the method invocation result
* @throws Exception when invocation fails
*/
- protected Object eval(String mname) throws Exception {
+ protected Object eval(final String mname) throws Exception {
// we have either evaluated and returned or might have found a method
if (vm != null) {
// vm cannot be null if xjexl is null
- Object eval = vm.invoke(target, argv);
+ final Object eval = vm.invoke(target, argv);
// cache executor in volatile JexlNode.value
if (funcall != null) {
node.jjtSetValue(funcall);
@@ -929,14 +929,14 @@
* @param node the node that evaluated as the object
* @return the attribute value
*/
- protected Object getAttribute(Object object, Object attribute, JexlNode node) {
+ protected Object getAttribute(final Object object, final Object attribute, final JexlNode node) {
if (object == null) {
throw new JexlException(node, "object is null");
}
cancelCheck(node);
final JexlOperator operator = node != null && node.jjtGetParent() instanceof ASTArrayAccess
? JexlOperator.ARRAY_GET : JexlOperator.PROPERTY_GET;
- Object result = operators.tryOverload(node, operator, object, attribute);
+ final Object result = operators.tryOverload(node, operator, object, attribute);
if (result != JexlEngine.TRY_FAILED) {
return result;
}
@@ -944,41 +944,41 @@
try {
// attempt to reuse last executor cached in volatile JexlNode.value
if (node != null && cache) {
- Object cached = node.jjtGetValue();
+ final Object cached = node.jjtGetValue();
if (cached instanceof JexlPropertyGet) {
- JexlPropertyGet vg = (JexlPropertyGet) cached;
- Object value = vg.tryInvoke(object, attribute);
+ final JexlPropertyGet vg = (JexlPropertyGet) cached;
+ final Object value = vg.tryInvoke(object, attribute);
if (!vg.tryFailed(value)) {
return value;
}
}
}
// resolve that property
- List<JexlUberspect.PropertyResolver> resolvers = uberspect.getResolvers(operator, object);
- JexlPropertyGet vg = uberspect.getPropertyGet(resolvers, object, attribute);
+ final List<JexlUberspect.PropertyResolver> resolvers = uberspect.getResolvers(operator, object);
+ final JexlPropertyGet vg = uberspect.getPropertyGet(resolvers, object, attribute);
if (vg != null) {
- Object value = vg.invoke(object);
+ final Object value = vg.invoke(object);
// cache executor in volatile JexlNode.value
if (node != null && cache && vg.isCacheable()) {
node.jjtSetValue(vg);
}
return value;
}
- } catch (Exception xany) {
+ } catch (final Exception xany) {
xcause = xany;
}
// lets fail
if (node != null) {
- boolean safe = (node instanceof ASTIdentifierAccess) && ((ASTIdentifierAccess) node).isSafe();
+ final boolean safe = (node instanceof ASTIdentifierAccess) && ((ASTIdentifierAccess) node).isSafe();
if (safe) {
return null;
} else {
- String attrStr = attribute != null ? attribute.toString() : null;
+ final String attrStr = attribute != null ? attribute.toString() : null;
return unsolvableProperty(node, attrStr, true, xcause);
}
} else {
// direct call
- String error = "unable to get object property"
+ final String error = "unable to get object property"
+ ", class: " + object.getClass().getName()
+ ", property: " + attribute;
throw new UnsupportedOperationException(error, xcause);
@@ -993,11 +993,11 @@
* @param value the value to assign to the object's attribute
* @param node the node that evaluated as the object
*/
- protected void setAttribute(Object object, Object attribute, Object value, JexlNode node) {
+ protected void setAttribute(final Object object, final Object attribute, final Object value, final JexlNode node) {
cancelCheck(node);
final JexlOperator operator = node != null && node.jjtGetParent() instanceof ASTArrayAccess
? JexlOperator.ARRAY_SET : JexlOperator.PROPERTY_SET;
- Object result = operators.tryOverload(node, operator, object, attribute, value);
+ final Object result = operators.tryOverload(node, operator, object, attribute, value);
if (result != JexlEngine.TRY_FAILED) {
return;
}
@@ -1005,21 +1005,21 @@
try {
// attempt to reuse last executor cached in volatile JexlNode.value
if (node != null && cache) {
- Object cached = node.jjtGetValue();
+ final Object cached = node.jjtGetValue();
if (cached instanceof JexlPropertySet) {
- JexlPropertySet setter = (JexlPropertySet) cached;
- Object eval = setter.tryInvoke(object, attribute, value);
+ final JexlPropertySet setter = (JexlPropertySet) cached;
+ final Object eval = setter.tryInvoke(object, attribute, value);
if (!setter.tryFailed(eval)) {
return;
}
}
}
- List<JexlUberspect.PropertyResolver> resolvers = uberspect.getResolvers(operator, object);
+ final List<JexlUberspect.PropertyResolver> resolvers = uberspect.getResolvers(operator, object);
JexlPropertySet vs = uberspect.getPropertySet(resolvers, object, attribute, value);
// if we can't find an exact match, narrow the value argument and try again
if (vs == null) {
// replace all numbers with the smallest type that will fit
- Object[] narrow = {value};
+ final Object[] narrow = {value};
if (arithmetic.narrowArguments(narrow)) {
vs = uberspect.getPropertySet(resolvers, object, attribute, narrow[0]);
}
@@ -1032,16 +1032,16 @@
}
return;
}
- } catch (Exception xany) {
+ } catch (final Exception xany) {
xcause = xany;
}
// lets fail
if (node != null) {
- String attrStr = attribute != null ? attribute.toString() : null;
+ final String attrStr = attribute != null ? attribute.toString() : null;
unsolvableProperty(node, attrStr, true, xcause);
} else {
// direct call
- String error = "unable to set object property"
+ final String error = "unable to set object property"
+ ", class: " + object.getClass().getName()
+ ", property: " + attribute
+ ", argument: " + value.getClass().getSimpleName();
diff --git a/src/main/java/org/apache/commons/jexl3/internal/LexicalFrame.java b/src/main/java/org/apache/commons/jexl3/internal/LexicalFrame.java
index 9318da5..077517b 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/LexicalFrame.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/LexicalFrame.java
@@ -43,7 +43,7 @@
* @param scriptf the script frame
* @param outerf the previous lexical frame
*/
- public LexicalFrame(Frame scriptf, LexicalFrame outerf) {
+ public LexicalFrame(final Frame scriptf, final LexicalFrame outerf) {
this.previous = outerf;
this.frame = scriptf;
}
@@ -53,7 +53,7 @@
*
* @param src the frame to copy
*/
- public LexicalFrame(LexicalFrame src) {
+ public LexicalFrame(final LexicalFrame src) {
super(src.symbols, src.moreSymbols);
frame = src.frame;
previous = src.previous;
@@ -67,7 +67,7 @@
*/
public LexicalFrame defineArgs() {
if (frame != null) {
- int argc = frame.getScope().getArgCount();
+ final int argc = frame.getScope().getArgCount();
for (int a = 0; a < argc; ++a) {
super.addSymbol(a);
}
@@ -82,8 +82,8 @@
* @param capture whether this redefines a captured symbol
* @return true if symbol is defined, false otherwise
*/
- public boolean defineSymbol(int symbol, boolean capture) {
- boolean declared = addSymbol(symbol);
+ public boolean defineSymbol(final int symbol, final boolean capture) {
+ final boolean declared = addSymbol(symbol);
if (declared && capture) {
if (stack == null) {
stack = new ArrayDeque<>();
@@ -115,7 +115,7 @@
} else if (value == this) {
value = null;
}
- int symbol = (Integer) stack.pop();
+ final int symbol = (Integer) stack.pop();
frame.set(symbol, value);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java b/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java
index 1a10e47..43f9173 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java
@@ -48,7 +48,7 @@
* @param s the symbols mask
* @param ms the more symbols bitset
*/
- protected LexicalScope(long s, BitSet ms) {
+ protected LexicalScope(final long s, final BitSet ms) {
symbols = s;
moreSymbols = ms != null ? (BitSet) ms.clone() : null;
}
@@ -71,7 +71,7 @@
* @param symbol the symbol
* @return true if declared, false otherwise
*/
- public boolean hasSymbol(int symbol) {
+ public boolean hasSymbol(final int symbol) {
if (symbol < LONGBITS) {
return (symbols & (1L << symbol)) != 0L;
} else {
@@ -85,15 +85,15 @@
* @param symbol the symbol
* @return true if registered, false if symbol was already registered
*/
- public boolean addSymbol(int symbol) {
+ public boolean addSymbol(final int symbol) {
if (symbol < LONGBITS) {
if ((symbols & (1L << symbol)) != 0L) {
return false;
}
symbols |= (1L << symbol);
} else {
- int s = symbol - LONGBITS;
- BitSet ms = moreSymbols();
+ final int s = symbol - LONGBITS;
+ final BitSet ms = moreSymbols();
if (ms.get(s)) {
return false;
}
@@ -107,12 +107,12 @@
*
* @param cleanSymbol a (optional, may be null) functor to call for each cleaned symbol
*/
- public final void clearSymbols(java.util.function.IntConsumer cleanSymbol) {
+ public final void clearSymbols(final java.util.function.IntConsumer cleanSymbol) {
// undefine symbols getting out of scope
if (cleanSymbol != null) {
long clean = symbols;
while (clean != 0L) {
- int s = Long.numberOfTrailingZeros(clean);
+ final int s = Long.numberOfTrailingZeros(clean);
clean &= ~(1L << s);
cleanSymbol.accept(s);
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/LongRange.java b/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
index 4de4035..03be0bb 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/LongRange.java
@@ -38,7 +38,7 @@
* @param to the higher inclusive boundary
* @return a range
*/
- public static LongRange create(long from, long to) {
+ public static LongRange create(final long from, final long to) {
if (from <= to) {
return new LongRange.Ascending(from, to);
} else {
@@ -51,7 +51,7 @@
* @param from the lower inclusive boundary
* @param to the higher inclusive boundary
*/
- protected LongRange(long from, long to) {
+ protected LongRange(final long from, final long to) {
min = from;
max = to;
}
@@ -83,7 +83,7 @@
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
@@ -114,9 +114,9 @@
}
@Override
- public boolean contains(Object o) {
+ public boolean contains(final Object o) {
if (o instanceof Number) {
- long v = ((Number) o).longValue();
+ final long v = ((Number) o).longValue();
return min <= v && v <= max;
} else {
return false;
@@ -126,7 +126,7 @@
@Override
public Object[] toArray() {
final int size = size();
- Object[] array = new Object[size];
+ final Object[] array = new Object[size];
for (int a = 0; a < size; ++a) {
array[a] = min + a;
}
@@ -135,7 +135,7 @@
@Override
@SuppressWarnings("unchecked")
- public <T> T[] toArray(T[] array) {
+ public <T> T[] toArray(final T[] array) {
final Class<?> ct = array.getClass().getComponentType();
final int length = size();
T[] copy = array;
@@ -155,8 +155,8 @@
}
@Override
- public boolean containsAll(Collection<?> c) {
- for (Object cc : c) {
+ public boolean containsAll(final Collection<?> c) {
+ for (final Object cc : c) {
if (!contains(cc)) {
return false;
}
@@ -165,27 +165,27 @@
}
@Override
- public boolean add(Long e) {
+ public boolean add(final Long e) {
throw new UnsupportedOperationException();
}
@Override
- public boolean remove(Object o) {
+ public boolean remove(final Object o) {
throw new UnsupportedOperationException();
}
@Override
- public boolean addAll(Collection<? extends Long> c) {
+ public boolean addAll(final Collection<? extends Long> c) {
throw new UnsupportedOperationException();
}
@Override
- public boolean removeAll(Collection<?> c) {
+ public boolean removeAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@Override
- public boolean retainAll(Collection<?> c) {
+ public boolean retainAll(final Collection<?> c) {
throw new UnsupportedOperationException();
}
@@ -203,7 +203,7 @@
* @param from lower boundary
* @param to upper boundary
*/
- protected Ascending(long from, long to) {
+ protected Ascending(final long from, final long to) {
super(from, to);
}
@@ -222,7 +222,7 @@
* @param from upper boundary
* @param to lower boundary
*/
- protected Descending(long from, long to) {
+ protected Descending(final long from, final long to) {
super(from, to);
}
@@ -249,7 +249,7 @@
* @param l low boundary
* @param h high boundary
*/
- AscLongIterator(long l, long h) {
+ AscLongIterator(final long l, final long h) {
min = l;
max = h;
cursor = min;
@@ -290,7 +290,7 @@
* @param l low boundary
* @param h high boundary
*/
- DescLongIterator(long l, long h) {
+ DescLongIterator(final long l, final long h) {
min = l;
max = h;
cursor = max;
diff --git a/src/main/java/org/apache/commons/jexl3/internal/MapBuilder.java b/src/main/java/org/apache/commons/jexl3/internal/MapBuilder.java
index 66e7668..b6aac4e 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/MapBuilder.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/MapBuilder.java
@@ -31,12 +31,12 @@
* Creates a new builder.
* @param size the expected map size
*/
- public MapBuilder(int size) {
+ public MapBuilder(final int size) {
map = new HashMap<Object, Object>(size);
}
@Override
- public void put(Object key, Object value) {
+ public void put(final Object key, final Object value) {
map.put(key, value);
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Operators.java b/src/main/java/org/apache/commons/jexl3/internal/Operators.java
index 7698cb0..c81fc0e 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Operators.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Operators.java
@@ -40,7 +40,7 @@
* Constructor.
* @param owner the owning interpreter
*/
- protected Operators(InterpreterBase owner) {
+ protected Operators(final InterpreterBase owner) {
final JexlArithmetic arithmetic = owner.arithmetic;
final JexlUberspect uberspect = owner.uberspect;
this.interpreter = owner;
@@ -52,9 +52,9 @@
* @param vm the JexlMethod (may be null)
* @return true of false
*/
- private boolean returnsBoolean(JexlMethod vm) {
+ private boolean returnsBoolean(final JexlMethod vm) {
if (vm !=null) {
- Class<?> rc = vm.getReturnType();
+ final Class<?> rc = vm.getReturnType();
return Boolean.TYPE.equals(rc) || Boolean.class.equals(rc);
}
return false;
@@ -65,9 +65,9 @@
* @param vm the JexlMethod (may be null)
* @return true of false
*/
- private boolean returnsInteger(JexlMethod vm) {
+ private boolean returnsInteger(final JexlMethod vm) {
if (vm !=null) {
- Class<?> rc = vm.getReturnType();
+ final Class<?> rc = vm.getReturnType();
return Integer.TYPE.equals(rc) || Integer.class.equals(rc);
}
return false;
@@ -78,9 +78,9 @@
* @param vm the JexlMethod (may be null)
* @return true of false
*/
- private boolean isArithmetic(JexlMethod vm) {
+ private boolean isArithmetic(final JexlMethod vm) {
if (vm instanceof MethodExecutor) {
- Method method = ((MethodExecutor) vm).getMethod();
+ final Method method = ((MethodExecutor) vm).getMethod();
return JexlArithmetic.class.equals(method.getDeclaringClass());
}
return false;
@@ -95,30 +95,30 @@
* @param args the arguments
* @return the result of the operator evaluation or TRY_FAILED
*/
- protected Object tryOverload(JexlNode node, JexlOperator operator, Object... args) {
+ protected Object tryOverload(final JexlNode node, final JexlOperator operator, final Object... args) {
if (operators != null && operators.overloads(operator)) {
final JexlArithmetic arithmetic = interpreter.arithmetic;
final boolean cache = interpreter.cache;
try {
if (cache) {
- Object cached = node.jjtGetValue();
+ final Object cached = node.jjtGetValue();
if (cached instanceof JexlMethod) {
- JexlMethod me = (JexlMethod) cached;
- Object eval = me.tryInvoke(operator.getMethodName(), arithmetic, args);
+ final JexlMethod me = (JexlMethod) cached;
+ final Object eval = me.tryInvoke(operator.getMethodName(), arithmetic, args);
if (!me.tryFailed(eval)) {
return eval;
}
}
}
- JexlMethod vm = operators.getOperator(operator, args);
+ final JexlMethod vm = operators.getOperator(operator, args);
if (vm != null && !isArithmetic(vm)) {
- Object result = vm.invoke(arithmetic, args);
+ final Object result = vm.invoke(arithmetic, args);
if (cache) {
node.jjtSetValue(vm);
}
return result;
}
- } catch (Exception xany) {
+ } catch (final Exception xany) {
return interpreter.operatorError(node, operator, xany);
}
}
@@ -139,7 +139,7 @@
* JexlEngine.TRY_FAILED if no operation was performed,
* the value to use as the side effect argument otherwise
*/
- protected Object tryAssignOverload(JexlNode node, JexlOperator operator, Object...args) {
+ protected Object tryAssignOverload(final JexlNode node, final JexlOperator operator, final Object...args) {
final JexlArithmetic arithmetic = interpreter.arithmetic;
if (args.length != operator.getArity()) {
return JexlEngine.TRY_FAILED;
@@ -150,21 +150,21 @@
return result;
}
// call base operator
- JexlOperator base = operator.getBaseOperator();
+ final JexlOperator base = operator.getBaseOperator();
if (base == null) {
throw new IllegalArgumentException("must be called with a side-effect operator");
}
if (operators != null && operators.overloads(base)) {
// in case there is an overload on the base operator
try {
- JexlMethod vm = operators.getOperator(base, args);
+ final JexlMethod vm = operators.getOperator(base, args);
if (vm != null) {
result = vm.invoke(arithmetic, args);
if (result != JexlEngine.TRY_FAILED) {
return result;
}
}
- } catch (Exception xany) {
+ } catch (final Exception xany) {
interpreter.operatorError(node, base, xany);
}
}
@@ -191,7 +191,7 @@
// unexpected, new operator added?
throw new UnsupportedOperationException(operator.getOperatorSymbol());
}
- } catch (Exception xany) {
+ } catch (final Exception xany) {
interpreter.operatorError(node, base, xany);
}
return JexlEngine.TRY_FAILED;
@@ -205,23 +205,23 @@
* @param right the right operand
* @return true if left starts with right, false otherwise
*/
- protected boolean startsWith(JexlNode node, String operator, Object left, Object right) {
+ protected boolean startsWith(final JexlNode node, final String operator, final Object left, final Object right) {
final JexlArithmetic arithmetic = interpreter.arithmetic;
final JexlUberspect uberspect = interpreter.uberspect;
try {
// try operator overload
- Object result = tryOverload(node, JexlOperator.STARTSWITH, left, right);
+ final Object result = tryOverload(node, JexlOperator.STARTSWITH, left, right);
if (result instanceof Boolean) {
return (Boolean) result;
}
// use arithmetic / pattern matching ?
- Boolean matched = arithmetic.startsWith(left, right);
+ final Boolean matched = arithmetic.startsWith(left, right);
if (matched != null) {
return matched;
}
// try a startsWith method (duck type)
try {
- Object[] argv = {right};
+ final Object[] argv = {right};
JexlMethod vm = uberspect.getMethod(left, "startsWith", argv);
if (returnsBoolean(vm)) {
return (Boolean) vm.invoke(left, argv);
@@ -231,12 +231,12 @@
return (Boolean) vm.invoke(left, argv);
}
}
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new JexlException(node, operator + " error", e);
}
// defaults to equal
return arithmetic.equals(left, right) ? Boolean.TRUE : Boolean.FALSE;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, operator + " error", xrt);
}
}
@@ -249,23 +249,23 @@
* @param right the right operand
* @return true if left ends with right, false otherwise
*/
- protected boolean endsWith(JexlNode node, String operator, Object left, Object right) {
+ protected boolean endsWith(final JexlNode node, final String operator, final Object left, final Object right) {
final JexlArithmetic arithmetic = interpreter.arithmetic;
final JexlUberspect uberspect = interpreter.uberspect;
try {
// try operator overload
- Object result = tryOverload(node, JexlOperator.ENDSWITH, left, right);
+ final Object result = tryOverload(node, JexlOperator.ENDSWITH, left, right);
if (result instanceof Boolean) {
return (Boolean) result;
}
// use arithmetic / pattern matching ?
- Boolean matched = arithmetic.endsWith(left, right);
+ final Boolean matched = arithmetic.endsWith(left, right);
if (matched != null) {
return matched;
}
// try a endsWith method (duck type)
try {
- Object[] argv = {right};
+ final Object[] argv = {right};
JexlMethod vm = uberspect.getMethod(left, "endsWith", argv);
if (returnsBoolean(vm)) {
return (Boolean) vm.invoke(left, argv);
@@ -275,12 +275,12 @@
return (Boolean) vm.invoke(left, argv);
}
}
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new JexlException(node, operator + " error", e);
}
// defaults to equal
return arithmetic.equals(left, right) ? Boolean.TRUE : Boolean.FALSE;
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, operator + " error", xrt);
}
}
@@ -297,23 +297,23 @@
* @param left the right operand
* @return true if left matches right, false otherwise
*/
- protected boolean contains(JexlNode node, String op, Object left, Object right) {
+ protected boolean contains(final JexlNode node, final String op, final Object left, final Object right) {
final JexlArithmetic arithmetic = interpreter.arithmetic;
final JexlUberspect uberspect = interpreter.uberspect;
try {
// try operator overload
- Object result = tryOverload(node, JexlOperator.CONTAINS, left, right);
+ final Object result = tryOverload(node, JexlOperator.CONTAINS, left, right);
if (result instanceof Boolean) {
return (Boolean) result;
}
// use arithmetic / pattern matching ?
- Boolean matched = arithmetic.contains(left, right);
+ final Boolean matched = arithmetic.contains(left, right);
if (matched != null) {
return matched;
}
// try a contains method (duck type set)
try {
- Object[] argv = {right};
+ final Object[] argv = {right};
JexlMethod vm = uberspect.getMethod(left, "contains", argv);
if (returnsBoolean(vm)) {
return (Boolean) vm.invoke(left, argv);
@@ -323,12 +323,12 @@
return (Boolean) vm.invoke(left, argv);
}
}
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new JexlException(node, op + " error", e);
}
// defaults to equal
return arithmetic.equals(left, right);
- } catch (ArithmeticException xrt) {
+ } catch (final ArithmeticException xrt) {
throw new JexlException(node, op + " error", xrt);
}
}
@@ -342,7 +342,7 @@
* @param object the object to check the emptyness of
* @return the evaluation result
*/
- protected Object empty(JexlNode node, Object object) {
+ protected Object empty(final JexlNode node, final Object object) {
if (object == null) {
return true;
}
@@ -357,11 +357,11 @@
result = false;
// check if there is an isEmpty method on the object that returns a
// boolean and if so, just use it
- JexlMethod vm = uberspect.getMethod(object, "isEmpty", Interpreter.EMPTY_PARAMS);
+ final JexlMethod vm = uberspect.getMethod(object, "isEmpty", Interpreter.EMPTY_PARAMS);
if (returnsBoolean(vm)) {
try {
result = vm.invoke(object, Interpreter.EMPTY_PARAMS);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
interpreter.operatorError(node, JexlOperator.EMPTY, xany);
}
}
@@ -378,7 +378,7 @@
* @param object the object to get the size of
* @return the evaluation result
*/
- protected Object size(JexlNode node, Object object) {
+ protected Object size(final JexlNode node, final Object object) {
if (object == null) {
return 0;
}
@@ -392,11 +392,11 @@
final JexlUberspect uberspect = interpreter.uberspect;
// check if there is a size method on the object that returns an
// integer and if so, just use it
- JexlMethod vm = uberspect.getMethod(object, "size", Interpreter.EMPTY_PARAMS);
+ final JexlMethod vm = uberspect.getMethod(object, "size", Interpreter.EMPTY_PARAMS);
if (returnsInteger(vm)) {
try {
result = vm.invoke(object, Interpreter.EMPTY_PARAMS);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
interpreter.operatorError(node, JexlOperator.SIZE, xany);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Scope.java b/src/main/java/org/apache/commons/jexl3/internal/Scope.java
index 0434de2..3b231df 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Scope.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Scope.java
@@ -76,7 +76,7 @@
* @param scope the parent scope if any
* @param parameters the list of parameters
*/
- public Scope(Scope scope, String... parameters) {
+ public Scope(final Scope scope, final String... parameters) {
if (parameters != null) {
parms = parameters.length;
namedVariables = new LinkedHashMap<String, Integer>();
@@ -96,14 +96,14 @@
}
@Override
- public boolean equals(Object o) {
+ public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Scope)) {
return false;
}
- Scope scope = (Scope) o;
+ final Scope scope = (Scope) o;
if (parms != scope.parms) {
return false;
}
@@ -119,7 +119,7 @@
* @param name the symbol name
* @return the symbol index
*/
- public Integer getSymbol(String name) {
+ public Integer getSymbol(final String name) {
return getSymbol(name, true);
}
@@ -129,10 +129,10 @@
* @param capture whether solving by capturing a parent symbol is allowed
* @return the symbol index
*/
- private Integer getSymbol(String name, boolean capture) {
+ private Integer getSymbol(final String name, final boolean capture) {
Integer register = namedVariables != null ? namedVariables.get(name) : null;
if (register == null && capture && parent != null) {
- Integer pr = parent.getSymbol(name, true);
+ final Integer pr = parent.getSymbol(name, true);
if (pr != null) {
if (capturedVariables == null) {
capturedVariables = new LinkedHashMap<Integer, Integer>();
@@ -153,7 +153,7 @@
* @param symbol the symbol number
* @return true if captured, false otherwise
*/
- public boolean isCapturedSymbol(int symbol) {
+ public boolean isCapturedSymbol(final int symbol) {
return capturedVariables != null && capturedVariables.containsKey(symbol);
}
@@ -165,7 +165,7 @@
* @param name the parameter name
* @return the register index storing this variable
*/
- public int declareParameter(String name) {
+ public int declareParameter(final String name) {
if (namedVariables == null) {
namedVariables = new LinkedHashMap<String, Integer>();
} else if (vars > 0) {
@@ -188,7 +188,7 @@
* @param name the variable name
* @return the register index storing this variable
*/
- public int declareVariable(String name) {
+ public int declareVariable(final String name) {
if (namedVariables == null) {
namedVariables = new LinkedHashMap<String, Integer>();
}
@@ -199,7 +199,7 @@
vars += 1;
// check if local is redefining captured
if (parent != null) {
- Integer pr = parent.getSymbol(name, true);
+ final Integer pr = parent.getSymbol(name, true);
if (pr != null) {
if (capturedVariables == null) {
capturedVariables = new LinkedHashMap<Integer, Integer>();
@@ -218,15 +218,15 @@
* @param args the arguments
* @return the arguments array
*/
- public Frame createFrame(Frame frame, Object...args) {
+ public Frame createFrame(final Frame frame, final Object...args) {
if (namedVariables != null) {
- Object[] arguments = new Object[namedVariables.size()];
+ final Object[] arguments = new Object[namedVariables.size()];
Arrays.fill(arguments, UNDECLARED);
if (frame != null && capturedVariables != null && parent != null) {
- for (Map.Entry<Integer, Integer> capture : capturedVariables.entrySet()) {
- Integer target = capture.getKey();
- Integer source = capture.getValue();
- Object arg = frame.get(source);
+ for (final Map.Entry<Integer, Integer> capture : capturedVariables.entrySet()) {
+ final Integer target = capture.getKey();
+ final Integer source = capture.getValue();
+ final Object arg = frame.get(source);
arguments[target] = arg;
}
}
@@ -241,10 +241,10 @@
* @param symbol the symbol index
* @return the target symbol index or null if the symbol is not captured
*/
- public Integer getCaptured(int symbol) {
+ public Integer getCaptured(final int symbol) {
if (capturedVariables != null) {
- for (Map.Entry<Integer, Integer> capture : capturedVariables.entrySet()) {
- Integer source = capture.getValue();
+ for (final Map.Entry<Integer, Integer> capture : capturedVariables.entrySet()) {
+ final Integer source = capture.getValue();
if (source == symbol) {
return capture.getKey();
}
@@ -282,13 +282,13 @@
* @param bound number of known bound parameters (curry)
* @return the parameter names
*/
- protected String[] getParameters(int bound) {
- int unbound = parms - bound;
+ protected String[] getParameters(final int bound) {
+ final int unbound = parms - bound;
if (namedVariables != null && unbound > 0) {
- String[] pa = new String[unbound];
+ final String[] pa = new String[unbound];
int p = 0;
- for (Map.Entry<String, Integer> entry : namedVariables.entrySet()) {
- int argn = entry.getValue();
+ for (final Map.Entry<String, Integer> entry : namedVariables.entrySet()) {
+ final int argn = entry.getValue();
if (argn >= bound && argn < parms) {
pa[p++] = entry.getKey();
}
@@ -305,9 +305,9 @@
*/
public String[] getLocalVariables() {
if (namedVariables != null && vars > 0) {
- List<String> locals = new ArrayList<String>(vars);
- for (Map.Entry<String, Integer> entry : namedVariables.entrySet()) {
- int symnum = entry.getValue();
+ final List<String> locals = new ArrayList<String>(vars);
+ for (final Map.Entry<String, Integer> entry : namedVariables.entrySet()) {
+ final int symnum = entry.getValue();
if (symnum >= parms && (capturedVariables == null || !capturedVariables.containsKey(symnum))) {
locals.add(entry.getKey());
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Script.java b/src/main/java/org/apache/commons/jexl3/internal/Script.java
index 086b6b2..129a033 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Script.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Script.java
@@ -65,7 +65,7 @@
* @param expr the expression source.
* @param ref the parsed expression.
*/
- protected Script(Engine engine, String expr, ASTJexlScript ref) {
+ protected Script(final Engine engine, final String expr, final ASTJexlScript ref) {
jexl = engine;
source = expr;
script = ref;
@@ -81,7 +81,7 @@
* </p>
*/
protected void checkCacheVersion() {
- int uberVersion = jexl.getUberspect().getVersion();
+ final int uberVersion = jexl.getUberspect().getVersion();
if (version != uberVersion) {
// version 0 of the uberSpect is an illusion due to order of construction; no need to clear cache
if (version > 0) {
@@ -96,7 +96,7 @@
* @param args the arguments to bind to parameters
* @return the frame (may be null)
*/
- protected Frame createFrame(Object[] args) {
+ protected Frame createFrame(final Object[] args) {
return script.createFrame(args);
}
@@ -106,8 +106,8 @@
* @param frame the calling frame
* @return the interpreter
*/
- protected Interpreter createInterpreter(JexlContext context, Frame frame) {
- JexlOptions opts = jexl.options(script, context);
+ protected Interpreter createInterpreter(final JexlContext context, final Frame frame) {
+ final JexlOptions opts = jexl.options(script, context);
return jexl.createInterpreter(context, frame, opts);
}
@@ -129,8 +129,8 @@
}
@Override
- public String getParsedText(int indent) {
- Debugger debug = new Debugger();
+ public String getParsedText(final int indent) {
+ final Debugger debug = new Debugger();
debug.setIndentation(indent);
debug.debug(script, false);
return debug.toString();
@@ -140,7 +140,7 @@
public String toString() {
CharSequence src = source;
if (src == null) {
- Debugger debug = new Debugger();
+ final Debugger debug = new Debugger();
debug.debug(script, false);
src = debug.toString();
}
@@ -158,7 +158,7 @@
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (obj == null) {
return false;
}
@@ -176,29 +176,29 @@
}
@Override
- public Object evaluate(JexlContext context) {
+ public Object evaluate(final JexlContext context) {
return execute(context);
}
@Override
- public Object execute(JexlContext context) {
+ public Object execute(final JexlContext context) {
checkCacheVersion();
- Frame frame = createFrame(null);
- Interpreter interpreter = createInterpreter(context, frame);
+ final Frame frame = createFrame(null);
+ final Interpreter interpreter = createInterpreter(context, frame);
return interpreter.interpret(script);
}
@Override
- public Object execute(JexlContext context, Object... args) {
+ public Object execute(final JexlContext context, final Object... args) {
checkCacheVersion();
- Frame frame = createFrame(args != null && args.length > 0 ? args : null);
- Interpreter interpreter = createInterpreter(context, frame);
+ final Frame frame = createFrame(args != null && args.length > 0 ? args : null);
+ final Interpreter interpreter = createInterpreter(context, frame);
return interpreter.interpret(script);
}
@Override
- public JexlScript curry(Object... args) {
- String[] parms = script.getParameters();
+ public JexlScript curry(final Object... args) {
+ final String[] parms = script.getParameters();
if (parms == null || parms.length == 0) {
return this;
}
@@ -263,7 +263,7 @@
* @return the callable
*/
@Override
- public Callable callable(JexlContext context) {
+ public Callable callable(final JexlContext context) {
return callable(context, (Object[]) null);
}
@@ -276,7 +276,7 @@
* @return the callable
*/
@Override
- public Callable callable(JexlContext context, Object... args) {
+ public Callable callable(final JexlContext context, final Object... args) {
return new Callable(createInterpreter(context, script.createFrame(args)));
}
@@ -293,7 +293,7 @@
* The base constructor.
* @param intrprtr the interpreter to use
*/
- protected Callable(Interpreter intrprtr) {
+ protected Callable(final Interpreter intrprtr) {
this.interpreter = intrprtr;
this.result = intrprtr;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/ScriptVisitor.java b/src/main/java/org/apache/commons/jexl3/internal/ScriptVisitor.java
index 94e946a..19afd27 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/ScriptVisitor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/ScriptVisitor.java
@@ -104,7 +104,7 @@
* @param data some data context
* @return the visit result or null if jscript was not a Script implementation
*/
- public Object visitExpression (JexlExpression jscript, Object data) {
+ public Object visitExpression (final JexlExpression jscript, final Object data) {
if (jscript instanceof Script) {
return ((Script) jscript).getScript().jjtAccept(this, data);
}
@@ -117,7 +117,7 @@
* @param data some data context
* @return the visit result or null if jscript was not a Script implementation
*/
- public Object visitScript(JexlScript jscript, Object data) {
+ public Object visitScript(final JexlScript jscript, final Object data) {
if (jscript instanceof Script) {
return ((Script) jscript).getScript().jjtAccept(this, data);
}
@@ -131,372 +131,372 @@
* @param data visitor pattern argument
* @return visitor pattern value
*/
- protected Object visitNode(JexlNode node, Object data) {
+ protected Object visitNode(final JexlNode node, final Object data) {
return node.childrenAccept(this, data);
}
@Override
- protected Object visit(ASTJexlScript node, Object data) {
+ protected Object visit(final ASTJexlScript node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTBlock node, Object data) {
+ protected Object visit(final ASTBlock node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTIfStatement node, Object data) {
+ protected Object visit(final ASTIfStatement node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTWhileStatement node, Object data) {
+ protected Object visit(final ASTWhileStatement node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTDoWhileStatement node, Object data) {
+ protected Object visit(final ASTDoWhileStatement node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTContinue node, Object data) {
+ protected Object visit(final ASTContinue node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTBreak node, Object data) {
+ protected Object visit(final ASTBreak node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTForeachStatement node, Object data) {
+ protected Object visit(final ASTForeachStatement node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTReturnStatement node, Object data) {
+ protected Object visit(final ASTReturnStatement node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTAssignment node, Object data) {
+ protected Object visit(final ASTAssignment node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTVar node, Object data) {
+ protected Object visit(final ASTVar node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTReference node, Object data) {
+ protected Object visit(final ASTReference node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTTernaryNode node, Object data) {
+ protected Object visit(final ASTTernaryNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTNullpNode node, Object data) {
+ protected Object visit(final ASTNullpNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTOrNode node, Object data) {
+ protected Object visit(final ASTOrNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTAndNode node, Object data) {
+ protected Object visit(final ASTAndNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTBitwiseOrNode node, Object data) {
+ protected Object visit(final ASTBitwiseOrNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTBitwiseXorNode node, Object data) {
+ protected Object visit(final ASTBitwiseXorNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTBitwiseAndNode node, Object data) {
+ protected Object visit(final ASTBitwiseAndNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTEQNode node, Object data) {
+ protected Object visit(final ASTEQNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTNENode node, Object data) {
+ protected Object visit(final ASTNENode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTLTNode node, Object data) {
+ protected Object visit(final ASTLTNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTGTNode node, Object data) {
+ protected Object visit(final ASTGTNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTLENode node, Object data) {
+ protected Object visit(final ASTLENode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTGENode node, Object data) {
+ protected Object visit(final ASTGENode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTERNode node, Object data) {
+ protected Object visit(final ASTERNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTNRNode node, Object data) {
+ protected Object visit(final ASTNRNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSWNode node, Object data) {
+ protected Object visit(final ASTSWNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTNSWNode node, Object data) {
+ protected Object visit(final ASTNSWNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTEWNode node, Object data) {
+ protected Object visit(final ASTEWNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTNEWNode node, Object data) {
+ protected Object visit(final ASTNEWNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTAddNode node, Object data) {
+ protected Object visit(final ASTAddNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSubNode node, Object data) {
+ protected Object visit(final ASTSubNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTMulNode node, Object data) {
+ protected Object visit(final ASTMulNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTDivNode node, Object data) {
+ protected Object visit(final ASTDivNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTModNode node, Object data) {
+ protected Object visit(final ASTModNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTUnaryMinusNode node, Object data) {
+ protected Object visit(final ASTUnaryMinusNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTUnaryPlusNode node, Object data) {
+ protected Object visit(final ASTUnaryPlusNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTBitwiseComplNode node, Object data) {
+ protected Object visit(final ASTBitwiseComplNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTNotNode node, Object data) {
+ protected Object visit(final ASTNotNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTIdentifier node, Object data) {
+ protected Object visit(final ASTIdentifier node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTNullLiteral node, Object data) {
+ protected Object visit(final ASTNullLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTTrueNode node, Object data) {
+ protected Object visit(final ASTTrueNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTFalseNode node, Object data) {
+ protected Object visit(final ASTFalseNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTNumberLiteral node, Object data) {
+ protected Object visit(final ASTNumberLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTStringLiteral node, Object data) {
+ protected Object visit(final ASTStringLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTRegexLiteral node, Object data) {
+ protected Object visit(final ASTRegexLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetLiteral node, Object data) {
+ protected Object visit(final ASTSetLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTExtendedLiteral node, Object data) {
+ protected Object visit(final ASTExtendedLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTArrayLiteral node, Object data) {
+ protected Object visit(final ASTArrayLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTRangeNode node, Object data) {
+ protected Object visit(final ASTRangeNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTMapLiteral node, Object data) {
+ protected Object visit(final ASTMapLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTMapEntry node, Object data) {
+ protected Object visit(final ASTMapEntry node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTEmptyFunction node, Object data) {
+ protected Object visit(final ASTEmptyFunction node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSizeFunction node, Object data) {
+ protected Object visit(final ASTSizeFunction node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTFunctionNode node, Object data) {
+ protected Object visit(final ASTFunctionNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTMethodNode node, Object data) {
+ protected Object visit(final ASTMethodNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTConstructorNode node, Object data) {
+ protected Object visit(final ASTConstructorNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTArrayAccess node, Object data) {
+ protected Object visit(final ASTArrayAccess node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTIdentifierAccess node, Object data) {
+ protected Object visit(final ASTIdentifierAccess node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTArguments node, Object data) {
+ protected Object visit(final ASTArguments node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTReferenceExpression node, Object data) {
+ protected Object visit(final ASTReferenceExpression node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetAddNode node, Object data) {
+ protected Object visit(final ASTSetAddNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetSubNode node, Object data) {
+ protected Object visit(final ASTSetSubNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetMultNode node, Object data) {
+ protected Object visit(final ASTSetMultNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetDivNode node, Object data) {
+ protected Object visit(final ASTSetDivNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetModNode node, Object data) {
+ protected Object visit(final ASTSetModNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetAndNode node, Object data) {
+ protected Object visit(final ASTSetAndNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetOrNode node, Object data) {
+ protected Object visit(final ASTSetOrNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTSetXorNode node, Object data) {
+ protected Object visit(final ASTSetXorNode node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTJxltLiteral node, Object data) {
+ protected Object visit(final ASTJxltLiteral node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTAnnotation node, Object data) {
+ protected Object visit(final ASTAnnotation node, final Object data) {
return visitNode(node, data);
}
@Override
- protected Object visit(ASTAnnotatedStatement node, Object data) {
+ protected Object visit(final ASTAnnotatedStatement node, final Object data) {
return visitNode(node, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/SetBuilder.java b/src/main/java/org/apache/commons/jexl3/internal/SetBuilder.java
index cdb0a36..bb33ff2 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/SetBuilder.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/SetBuilder.java
@@ -31,12 +31,12 @@
* Creates a new builder.
* @param size the expected set size
*/
- public SetBuilder(int size) {
+ public SetBuilder(final int size) {
set = new HashSet<Object>(size);
}
@Override
- public void add(Object value) {
+ public void add(final Object value) {
set.add(value);
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/SoftCache.java b/src/main/java/org/apache/commons/jexl3/internal/SoftCache.java
index 5328cab..3028e8a 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/SoftCache.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/SoftCache.java
@@ -57,7 +57,7 @@
*
* @param theSize the cache size
*/
- SoftCache(int theSize) {
+ SoftCache(final int theSize) {
size = theSize;
lock = new ReentrantReadWriteLock();
}
@@ -89,7 +89,7 @@
* @param key the cache entry key
* @return the cache entry value
*/
- public V get(K key) {
+ public V get(final K key) {
lock.readLock().lock();
try {
final Map<K, V> map = ref != null ? ref.get() : null;
@@ -105,7 +105,7 @@
* @param key the cache entry key
* @param script the cache entry value
*/
- public void put(K key, V script) {
+ public void put(final K key, final V script) {
lock.writeLock().lock();
try {
Map<K, V> map = ref != null ? ref.get() : null;
@@ -129,13 +129,13 @@
public List<Map.Entry<K, V>> entries() {
lock.readLock().lock();
try {
- Map<K, V> map = ref != null ? ref.get() : null;
+ final Map<K, V> map = ref != null ? ref.get() : null;
if (map == null) {
return Collections.emptyList();
}
final Set<Map.Entry<K, V>> set = map.entrySet();
final List<Map.Entry<K, V>> entries = new ArrayList<Map.Entry<K, V>>(set.size());
- for (Map.Entry<K, V> e : set) {
+ for (final Map.Entry<K, V> e : set) {
entries.add(new SoftCacheEntry<K, V>(e));
}
return entries;
@@ -160,7 +160,7 @@
private static final long serialVersionUID = 1L;
@Override
- protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
+ protected boolean removeEldestEntry(final Map.Entry<K, V> eldest) {
return super.size() > cacheSize;
}
};
@@ -188,7 +188,7 @@
*
* @param e the entry to clone
*/
- SoftCacheEntry(Map.Entry<K, V> e) {
+ SoftCacheEntry(final Map.Entry<K, V> e) {
key = e.getKey();
value = e.getValue();
}
@@ -204,7 +204,7 @@
}
@Override
- public V setValue(V v) {
+ public V setValue(final V v) {
throw new UnsupportedOperationException("Not supported.");
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Source.java b/src/main/java/org/apache/commons/jexl3/internal/Source.java
index c7dd2e6..a9d16f2 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Source.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Source.java
@@ -38,7 +38,7 @@
* @param theFeatures the features
* @param theStr the script source
*/
- Source(JexlFeatures theFeatures, String theStr) { // CSOFF: MagicNumber
+ Source(final JexlFeatures theFeatures, final String theStr) { // CSOFF: MagicNumber
this.features = theFeatures;
this.str = theStr;
int hash = 3;
@@ -60,7 +60,7 @@
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/TemplateDebugger.java b/src/main/java/org/apache/commons/jexl3/internal/TemplateDebugger.java
index aa45923..6008aa8 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/TemplateDebugger.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateDebugger.java
@@ -60,9 +60,9 @@
* @param je the expression
* @return true if the expression was a {@link TemplateExpression} instance, false otherwise
*/
- public boolean debug(JxltEngine.Expression je) {
+ public boolean debug(final JxltEngine.Expression je) {
if (je instanceof TemplateExpression) {
- TemplateEngine.TemplateExpression te = (TemplateEngine.TemplateExpression) je;
+ final TemplateEngine.TemplateExpression te = (TemplateEngine.TemplateExpression) je;
return visit(te, this) != null;
} else {
return false;
@@ -74,9 +74,9 @@
* @param jt the template
* @return true if the template was a {@link TemplateScript} instance, false otherwise
*/
- public boolean debug(JxltEngine.Template jt) {
+ public boolean debug(final JxltEngine.Template jt) {
if (jt instanceof TemplateScript) {
- TemplateScript ts = (TemplateScript) jt;
+ final TemplateScript ts = (TemplateScript) jt;
// ensure expr is not null for templates
this.exprs = ts.getExpressions() == null? new TemplateExpression[0] : ts.getExpressions();
this.script = ts.getScript();
@@ -85,9 +85,9 @@
indentLevel = 0;
builder.setLength(0);
cause = script;
- int num = script.jjtGetNumChildren();
+ final int num = script.jjtGetNumChildren();
for (int i = 0; i < num; ++i) {
- JexlNode child = script.jjtGetChild(i);
+ final JexlNode child = script.jjtGetChild(i);
acceptStatement(child, null);
}
// the last line
@@ -103,7 +103,7 @@
@Override
- protected Object visit(ASTBlock node, Object data) {
+ protected Object visit(final ASTBlock node, final Object data) {
// if not really a template, must use super impl
if (exprs == null) {
return super.visit(node, data);
@@ -116,9 +116,9 @@
} else {
builder.append(' ');
}
- int num = node.jjtGetNumChildren();
+ final int num = node.jjtGetNumChildren();
for (int i = 0; i < num; ++i) {
- JexlNode child = node.jjtGetChild(i);
+ final JexlNode child = node.jjtGetChild(i);
acceptStatement(child, data);
}
// before we close this block node, $$ might be needed
@@ -137,12 +137,12 @@
}
@Override
- protected Object acceptStatement(JexlNode child, Object data) {
+ protected Object acceptStatement(final JexlNode child, final Object data) {
// if not really a template, must use super impl
if (exprs == null) {
return super.acceptStatement(child, data);
}
- TemplateExpression te = getPrintStatement(child);
+ final TemplateExpression te = getPrintStatement(child);
if (te != null) {
// if statement is a jexl:print(...), may need to prepend '\n'
newJxltLine();
@@ -159,17 +159,17 @@
* @param child the node to check
* @return the expression number or -1 if the node is not a jexl:print
*/
- private TemplateExpression getPrintStatement(JexlNode child) {
+ private TemplateExpression getPrintStatement(final JexlNode child) {
if (exprs != null && child instanceof ASTFunctionNode) {
- ASTFunctionNode node = (ASTFunctionNode) child;
- ASTIdentifier ns = (ASTIdentifier) node.jjtGetChild(0);
- JexlNode args = node.jjtGetChild(1);
+ final ASTFunctionNode node = (ASTFunctionNode) child;
+ final ASTIdentifier ns = (ASTIdentifier) node.jjtGetChild(0);
+ final JexlNode args = node.jjtGetChild(1);
if ("jexl".equals(ns.getNamespace())
&& "print".equals(ns.getName())
&& args.jjtGetNumChildren() == 1
&& args.jjtGetChild(0) instanceof ASTNumberLiteral) {
- ASTNumberLiteral exprn = (ASTNumberLiteral) args.jjtGetChild(0);
- int n = exprn.getLiteral().intValue();
+ final ASTNumberLiteral exprn = (ASTNumberLiteral) args.jjtGetChild(0);
+ final int n = exprn.getLiteral().intValue();
if (n >= 0 && n < exprs.length) {
return exprs[n];
}
@@ -182,12 +182,12 @@
* Insert $$ and \n when needed.
*/
private void newJexlLine() {
- int length = builder.length();
+ final int length = builder.length();
if (length == 0) {
builder.append("$$ ");
} else {
for (int i = length - 1; i >= 0; --i) {
- char c = builder.charAt(i);
+ final char c = builder.charAt(i);
switch (c) {
case '\n':
builder.append("$$ ");
@@ -208,9 +208,9 @@
* Insert \n when needed.
*/
private void newJxltLine() {
- int length = builder.length();
+ final int length = builder.length();
for (int i = length - 1; i >= 0; --i) {
- char c = builder.charAt(i);
+ final char c = builder.charAt(i);
switch (c) {
case '\n':
case ';':
@@ -229,7 +229,7 @@
* @param data the visitor argument
* @return the visitor argument
*/
- private Object visit(TemplateExpression expr, Object data) {
+ private Object visit(final TemplateExpression expr, final Object data) {
Object r;
switch (expr.getType()) {
case CONSTANT:
@@ -259,7 +259,7 @@
* @param data the visitor argument
* @return the visitor argument
*/
- private Object visit(ConstantExpression expr, Object data) {
+ private Object visit(final ConstantExpression expr, final Object data) {
expr.asString(builder);
return data;
}
@@ -270,7 +270,7 @@
* @param data the visitor argument
* @return the visitor argument
*/
- private Object visit(ImmediateExpression expr, Object data) {
+ private Object visit(final ImmediateExpression expr, final Object data) {
builder.append(expr.isImmediate() ? '$' : '#');
builder.append('{');
super.accept(expr.node, data);
@@ -284,7 +284,7 @@
* @param data the visitor argument
* @return the visitor argument
*/
- private Object visit(DeferredExpression expr, Object data) {
+ private Object visit(final DeferredExpression expr, final Object data) {
builder.append(expr.isImmediate() ? '$' : '#');
builder.append('{');
super.accept(expr.node, data);
@@ -298,7 +298,7 @@
* @param data the visitor argument
* @return the visitor argument
*/
- private Object visit(NestedExpression expr, Object data) {
+ private Object visit(final NestedExpression expr, final Object data) {
super.accept(expr.node, data);
return data;
}
@@ -308,8 +308,8 @@
* @param data the visitor argument
* @return the visitor argument
*/
- private Object visit(CompositeExpression expr, Object data) {
- for (TemplateExpression ce : expr.exprs) {
+ private Object visit(final CompositeExpression expr, final Object data) {
+ for (final TemplateExpression ce : expr.exprs) {
visit(ce, data);
}
return data;
diff --git a/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java b/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
index 72a081a..33a49db 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateEngine.java
@@ -60,7 +60,7 @@
* @param immediate the immediate template expression character, default is '$'
* @param deferred the deferred template expression character, default is '#'
*/
- public TemplateEngine(Engine aJexl, boolean noScript, int cacheSize, char immediate, char deferred) {
+ public TemplateEngine(final Engine aJexl, final boolean noScript, final int cacheSize, final char immediate, final char deferred) {
this.jexl = aJexl;
this.cache = new SoftCache<>(cacheSize);
immediateChar = immediate;
@@ -106,7 +106,7 @@
* Creates an ExpressionType.
* @param idx the index for this type in counters arrays.
*/
- ExpressionType(int idx) {
+ ExpressionType(final int idx) {
this.index = idx;
}
}
@@ -125,7 +125,7 @@
* Creates a builder.
* @param size the initial TemplateExpression array size
*/
- private ExpressionBuilder(int size) {
+ private ExpressionBuilder(final int size) {
counts = new int[]{0, 0, 0};
expressions = new ArrayList<>(size <= 0 ? 3 : size);
}
@@ -134,7 +134,7 @@
* Adds an TemplateExpression to the list of expressions, maintain per-type counts.
* @param expr the TemplateExpression to add
*/
- private void add(TemplateExpression expr) {
+ private void add(final TemplateExpression expr) {
counts[expr.getType().index] += 1;
expressions.add(expr);
}
@@ -149,7 +149,7 @@
* @param error the builder to fill
* @return the builder
*/
- private StringBuilder toString(StringBuilder error) {
+ private StringBuilder toString(final StringBuilder error) {
error.append("exprs{");
error.append(expressions.size());
error.append(", constant:");
@@ -168,13 +168,13 @@
* @param source the source TemplateExpression
* @return an TemplateExpression
*/
- private TemplateExpression build(TemplateEngine el, TemplateExpression source) {
+ private TemplateExpression build(final TemplateEngine el, final TemplateExpression source) {
int sum = 0;
- for (int count : counts) {
+ for (final int count : counts) {
sum += count;
}
if (expressions.size() != sum) {
- StringBuilder error = new StringBuilder("parsing algorithm error: ");
+ final StringBuilder error = new StringBuilder("parsing algorithm error: ");
throw new IllegalStateException(toString(error).toString());
}
// if only one sub-expr, no need to create a composite
@@ -216,7 +216,7 @@
* Creates an TemplateExpression.
* @param src the source TemplateExpression if any
*/
- TemplateExpression(TemplateExpression src) {
+ TemplateExpression(final TemplateExpression src) {
this.source = src != null ? src : this;
}
@@ -243,7 +243,7 @@
@Override
public final String toString() {
- StringBuilder strb = new StringBuilder();
+ final StringBuilder strb = new StringBuilder();
asString(strb);
if (source != this) {
strb.append(" /*= ");
@@ -255,7 +255,7 @@
@Override
public String asString() {
- StringBuilder strb = new StringBuilder();
+ final StringBuilder strb = new StringBuilder();
asString(strb);
return strb.toString();
}
@@ -274,12 +274,12 @@
* Fills up the list of variables accessed by this unified expression.
* @param collector the variable collector
*/
- protected void getVariables(Engine.VarCollector collector) {
+ protected void getVariables(final Engine.VarCollector collector) {
// nothing to do
}
@Override
- public final TemplateExpression prepare(JexlContext context) {
+ public final TemplateExpression prepare(final JexlContext context) {
return prepare(null, context);
}
@@ -290,12 +290,12 @@
* @return the expression value
* @throws JexlException
*/
- protected final TemplateExpression prepare(Frame frame, JexlContext context) {
+ protected final TemplateExpression prepare(final Frame frame, final JexlContext context) {
try {
- Interpreter interpreter = jexl.createInterpreter(context, frame, jexl.options(context));
+ final Interpreter interpreter = jexl.createInterpreter(context, frame, jexl.options(context));
return prepare(interpreter);
- } catch (JexlException xjexl) {
- JexlException xuel = createException(xjexl.getInfo(), "prepare", this, xjexl);
+ } catch (final JexlException xjexl) {
+ final JexlException xuel = createException(xjexl.getInfo(), "prepare", this, xjexl);
if (jexl.isSilent()) {
jexl.logger.warn(xuel.getMessage(), xuel.getCause());
return null;
@@ -310,12 +310,12 @@
* @return a prepared unified expression
* @throws JexlException (only for nested and composite)
*/
- protected TemplateExpression prepare(Interpreter interpreter) {
+ protected TemplateExpression prepare(final Interpreter interpreter) {
return this;
}
@Override
- public final Object evaluate(JexlContext context) {
+ public final Object evaluate(final JexlContext context) {
return evaluate(null, context);
}
@@ -324,7 +324,7 @@
* @param context the context
* @return the options
*/
- protected JexlOptions options(JexlContext context) {
+ protected JexlOptions options(final JexlContext context) {
return jexl.options(null, context);
}
@@ -335,18 +335,18 @@
* @return the expression value
* @throws JexlException
*/
- protected final Object evaluate(Frame frame, JexlContext context) {
+ protected final Object evaluate(final Frame frame, final JexlContext context) {
try {
- JexlOptions options = options(context);
- TemplateInterpreter.Arguments args = new TemplateInterpreter
+ final JexlOptions options = options(context);
+ final TemplateInterpreter.Arguments args = new TemplateInterpreter
.Arguments(jexl)
.context(context)
.options(options)
.frame(frame);
- Interpreter interpreter = new TemplateInterpreter(args);
+ final Interpreter interpreter = new TemplateInterpreter(args);
return evaluate(interpreter);
- } catch (JexlException xjexl) {
- JexlException xuel = createException(xjexl.getInfo(), "evaluate", this, xjexl);
+ } catch (final JexlException xjexl) {
+ final JexlException xuel = createException(xjexl.getInfo(), "evaluate", this, xjexl);
if (jexl.isSilent()) {
jexl.logger.warn(xuel.getMessage(), xuel.getCause());
return null;
@@ -379,7 +379,7 @@
* @param val the constant value
* @param source the source TemplateExpression if any
*/
- ConstantExpression(Object val, TemplateExpression source) {
+ ConstantExpression(Object val, final TemplateExpression source) {
super(source);
if (val == null) {
throw new NullPointerException("constant can not be null");
@@ -396,7 +396,7 @@
}
@Override
- public StringBuilder asString(StringBuilder strb) {
+ public StringBuilder asString(final StringBuilder strb) {
if (value != null) {
strb.append(value.toString());
}
@@ -404,7 +404,7 @@
}
@Override
- protected Object evaluate(Interpreter interpreter) {
+ protected Object evaluate(final Interpreter interpreter) {
return value;
}
}
@@ -422,14 +422,14 @@
* @param theNode the unified expression as an AST
* @param theSource the source unified expression if any
*/
- protected JexlBasedExpression(CharSequence theExpr, JexlNode theNode, TemplateExpression theSource) {
+ protected JexlBasedExpression(final CharSequence theExpr, final JexlNode theNode, final TemplateExpression theSource) {
super(theSource);
this.expr = theExpr;
this.node = theNode;
}
@Override
- public StringBuilder asString(StringBuilder strb) {
+ public StringBuilder asString(final StringBuilder strb) {
strb.append(isImmediate() ? immediateChar : deferredChar);
strb.append("{");
strb.append(expr);
@@ -438,24 +438,24 @@
}
@Override
- protected JexlOptions options(JexlContext context) {
+ protected JexlOptions options(final JexlContext context) {
return jexl.options(node instanceof ASTJexlScript? (ASTJexlScript) node : null, context);
}
@Override
- protected Object evaluate(Interpreter interpreter) {
+ protected Object evaluate(final Interpreter interpreter) {
return interpreter.interpret(node);
}
@Override
public Set<List<String>> getVariables() {
- Engine.VarCollector collector = jexl.varCollector();
+ final Engine.VarCollector collector = jexl.varCollector();
getVariables(collector);
return collector.collected();
}
@Override
- protected void getVariables(Engine.VarCollector collector) {
+ protected void getVariables(final Engine.VarCollector collector) {
jexl.getVariables(node instanceof ASTJexlScript? (ASTJexlScript) node : null, node, collector);
}
@@ -473,7 +473,7 @@
* @param node the unified expression as an AST
* @param source the source unified expression if any
*/
- ImmediateExpression(CharSequence expr, JexlNode node, TemplateExpression source) {
+ ImmediateExpression(final CharSequence expr, final JexlNode node, final TemplateExpression source) {
super(expr, node, source);
}
@@ -483,9 +483,9 @@
}
@Override
- protected TemplateExpression prepare(Interpreter interpreter) {
+ protected TemplateExpression prepare(final Interpreter interpreter) {
// evaluate immediate as constant
- Object value = evaluate(interpreter);
+ final Object value = evaluate(interpreter);
return value != null ? new ConstantExpression(value, source) : null;
}
}
@@ -498,7 +498,7 @@
* @param node the unified expression as an AST
* @param source the source unified expression if any
*/
- DeferredExpression(CharSequence expr, JexlNode node, TemplateExpression source) {
+ DeferredExpression(final CharSequence expr, final JexlNode node, final TemplateExpression source) {
super(expr, node, source);
}
@@ -513,12 +513,12 @@
}
@Override
- protected TemplateExpression prepare(Interpreter interpreter) {
+ protected TemplateExpression prepare(final Interpreter interpreter) {
return new ImmediateExpression(expr, node, source);
}
@Override
- protected void getVariables(Engine.VarCollector collector) {
+ protected void getVariables(final Engine.VarCollector collector) {
// noop
}
}
@@ -535,7 +535,7 @@
* @param node the unified expression as an AST
* @param source the source unified expression if any
*/
- NestedExpression(CharSequence expr, JexlNode node, TemplateExpression source) {
+ NestedExpression(final CharSequence expr, final JexlNode node, final TemplateExpression source) {
super(expr, node, source);
if (this.source != this) {
throw new IllegalArgumentException("Nested TemplateExpression can not have a source");
@@ -543,7 +543,7 @@
}
@Override
- public StringBuilder asString(StringBuilder strb) {
+ public StringBuilder asString(final StringBuilder strb) {
strb.append(expr);
return strb;
}
@@ -559,14 +559,14 @@
}
@Override
- protected TemplateExpression prepare(Interpreter interpreter) {
- String value = interpreter.interpret(node).toString();
- JexlNode dnode = jexl.parse(node.jexlInfo(), noscript, value, null);
+ protected TemplateExpression prepare(final Interpreter interpreter) {
+ final String value = interpreter.interpret(node).toString();
+ final JexlNode dnode = jexl.parse(node.jexlInfo(), noscript, value, null);
return new ImmediateExpression(value, dnode, this);
}
@Override
- protected Object evaluate(Interpreter interpreter) {
+ protected Object evaluate(final Interpreter interpreter) {
return prepare(interpreter).evaluate(interpreter);
}
}
@@ -584,7 +584,7 @@
* @param list the sub-expressions
* @param src the source for this expresion if any
*/
- CompositeExpression(int[] counters, ArrayList<TemplateExpression> list, TemplateExpression src) {
+ CompositeExpression(final int[] counters, final ArrayList<TemplateExpression> list, final TemplateExpression src) {
super(src);
this.exprs = list.toArray(new TemplateExpression[list.size()]);
this.meta = (counters[ExpressionType.DEFERRED.index] > 0 ? 2 : 0)
@@ -603,8 +603,8 @@
}
@Override
- public StringBuilder asString(StringBuilder strb) {
- for (TemplateExpression e : exprs) {
+ public StringBuilder asString(final StringBuilder strb) {
+ for (final TemplateExpression e : exprs) {
e.asString(strb);
}
return strb;
@@ -612,8 +612,8 @@
@Override
public Set<List<String>> getVariables() {
- Engine.VarCollector collector = jexl.varCollector();
- for (TemplateExpression expr : exprs) {
+ final Engine.VarCollector collector = jexl.varCollector();
+ for (final TemplateExpression expr : exprs) {
expr.getVariables(collector);
}
return collector.collected();
@@ -624,14 +624,14 @@
* @param collector the variable collector
*/
@Override
- protected void getVariables(Engine.VarCollector collector) {
- for (TemplateExpression expr : exprs) {
+ protected void getVariables(final Engine.VarCollector collector) {
+ for (final TemplateExpression expr : exprs) {
expr.getVariables(collector);
}
}
@Override
- protected TemplateExpression prepare(Interpreter interpreter) {
+ protected TemplateExpression prepare(final Interpreter interpreter) {
// if this composite is not its own source, it is already prepared
if (source != this) {
return this;
@@ -641,8 +641,8 @@
final ExpressionBuilder builder = new ExpressionBuilder(size);
// tracking whether prepare will return a different expression
boolean eq = true;
- for (TemplateExpression expr : exprs) {
- TemplateExpression prepared = expr.prepare(interpreter);
+ for (final TemplateExpression expr : exprs) {
+ final TemplateExpression prepared = expr.prepare(interpreter);
// add it if not null
if (prepared != null) {
builder.add(prepared);
@@ -654,11 +654,11 @@
}
@Override
- protected Object evaluate(Interpreter interpreter) {
+ protected Object evaluate(final Interpreter interpreter) {
Object value;
// common case: evaluate all expressions & concatenate them as a string
- StringBuilder strb = new StringBuilder();
- for (TemplateExpression expr : exprs) {
+ final StringBuilder strb = new StringBuilder();
+ for (final TemplateExpression expr : exprs) {
value = expr.evaluate(interpreter);
if (value != null) {
strb.append(value.toString());
@@ -671,7 +671,7 @@
@Override
- public JxltEngine.Expression createExpression(JexlInfo info, String expression) {
+ public JxltEngine.Expression createExpression(JexlInfo info, final String expression) {
if (info == null) {
info = jexl.createInfo();
}
@@ -683,7 +683,7 @@
stmt = parseExpression(info, expression, null);
cache.put(expression, stmt);
}
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
xuel = new Exception(xjexl.getInfo(), "failed to parse '" + expression + "'", xjexl);
}
if (xuel != null) {
@@ -705,17 +705,17 @@
* @param xany the exception
* @return an exception containing an explicit error message
*/
- static Exception createException(JexlInfo info, String action, TemplateExpression expr, java.lang.Exception xany) {
- StringBuilder strb = new StringBuilder("failed to ");
+ static Exception createException(final JexlInfo info, final String action, final TemplateExpression expr, final java.lang.Exception xany) {
+ final StringBuilder strb = new StringBuilder("failed to ");
strb.append(action);
if (expr != null) {
strb.append(" '");
strb.append(expr.toString());
strb.append("'");
}
- Throwable cause = xany.getCause();
+ final Throwable cause = xany.getCause();
if (cause != null) {
- String causeMsg = cause.getMessage();
+ final String causeMsg = cause.getMessage();
if (causeMsg != null) {
strb.append(", ");
strb.append(causeMsg);
@@ -748,17 +748,17 @@
* @param c the separator character
* @return the new position to read the source from
*/
- private static int append(StringBuilder strb, CharSequence expr, int position, char c) {
+ private static int append(final StringBuilder strb, final CharSequence expr, final int position, final char c) {
strb.append(c);
if (c != '"' && c != '\'') {
return position;
}
// read thru strings
- int end = expr.length();
+ final int end = expr.length();
boolean escape= false;
int index = position + 1;
for (; index < end; ++index) {
- char ec = expr.charAt(index);
+ final char ec = expr.charAt(index);
strb.append(ec);
if (ec == '\\') {
escape = !escape;
@@ -779,7 +779,7 @@
* @return the unified expression instance
* @throws JexlException if an error occur during parsing
*/
- TemplateExpression parseExpression(JexlInfo info, String expr, Scope scope) { // CSOFF: MethodLength
+ TemplateExpression parseExpression(final JexlInfo info, final String expr, final Scope scope) { // CSOFF: MethodLength
final int size = expr.length();
final ExpressionBuilder builder = new ExpressionBuilder(0);
final StringBuilder strb = new StringBuilder(size);
@@ -791,7 +791,7 @@
int inested = -1;
int lineno = info.getLine();
for (int column = 0; column < size; ++column) {
- char c = expr.charAt(column);
+ final char c = expr.charAt(column);
switch (state) {
default: // in case we ever add new unified expresssion type
throw new UnsupportedOperationException("unexpected unified expression type");
@@ -813,7 +813,7 @@
state = ParseState.IMMEDIATE1;
// if chars in buffer, create constant
if (strb.length() > 0) {
- TemplateExpression cexpr = new ConstantExpression(strb.toString(), null);
+ final TemplateExpression cexpr = new ConstantExpression(strb.toString(), null);
builder.add(cexpr);
strb.delete(0, Integer.MAX_VALUE);
}
@@ -829,7 +829,7 @@
state = ParseState.DEFERRED1;
// if chars in buffer, create constant
if (strb.length() > 0) {
- TemplateExpression cexpr = new ConstantExpression(strb.toString(), null);
+ final TemplateExpression cexpr = new ConstantExpression(strb.toString(), null);
builder.add(cexpr);
strb.delete(0, Integer.MAX_VALUE);
}
@@ -847,8 +847,8 @@
strb.append(c);
} else {
// materialize the immediate expr
- String src = strb.toString();
- TemplateExpression iexpr = new ImmediateExpression(
+ final String src = strb.toString();
+ final TemplateExpression iexpr = new ImmediateExpression(
src,
jexl.parse(info.at(lineno, column), noscript, src, scope),
null);
@@ -893,7 +893,7 @@
inner1 -= 1;
} else {
// materialize the nested/deferred expr
- String src = strb.toString();
+ final String src = strb.toString();
TemplateExpression dexpr;
if (nested) {
dexpr = new NestedExpression(
@@ -951,7 +951,7 @@
}
// if any chars were buffered, add them as a constant
if (strb.length() > 0) {
- TemplateExpression cexpr = new ConstantExpression(strb.toString(), null);
+ final TemplateExpression cexpr = new ConstantExpression(strb.toString(), null);
builder.add(cexpr);
}
return builder.build(this, null);
@@ -984,7 +984,7 @@
* @param theLine the line number
* @param theBlock the content
*/
- Block(BlockType theType, int theLine, String theBlock) {
+ Block(final BlockType theType, final int theLine, final String theBlock) {
type = theType;
line = theLine;
body = theBlock;
@@ -1017,9 +1017,9 @@
return body;
} else {
// CHECKSTYLE:OFF
- StringBuilder strb = new StringBuilder(64); // CSOFF: MagicNumber
+ final StringBuilder strb = new StringBuilder(64); // CSOFF: MagicNumber
// CHECKSTYLE:ON
- Iterator<CharSequence> lines = readLines(new StringReader(body));
+ final Iterator<CharSequence> lines = readLines(new StringReader(body));
while (lines.hasNext()) {
strb.append("$$").append(lines.next());
}
@@ -1032,11 +1032,11 @@
* @param strb the string builder to append to
* @param prefix the line prefix (immediate or deferred)
*/
- protected void toString(StringBuilder strb, String prefix) {
+ protected void toString(final StringBuilder strb, final String prefix) {
if (BlockType.VERBATIM.equals(type)) {
strb.append(body);
} else {
- Iterator<CharSequence> lines = readLines(new StringReader(body));
+ final Iterator<CharSequence> lines = readLines(new StringReader(body));
while (lines.hasNext()) {
strb.append(prefix).append(lines.next());
}
@@ -1051,8 +1051,8 @@
* @param pattern the pattern to match at start of sequence
* @return the first position after end of pattern if it matches, -1 otherwise
*/
- protected int startsWith(CharSequence sequence, CharSequence pattern) {
- int length = sequence.length();
+ protected int startsWith(CharSequence sequence, final CharSequence pattern) {
+ final int length = sequence.length();
int s = 0;
while (s < length && Character.isSpaceChar(sequence.charAt(s))) {
s += 1;
@@ -1079,7 +1079,7 @@
private CharSequence next = doNext();
private CharSequence doNext() {
- StringBuffer strb = new StringBuffer(64); // CSOFF: MagicNumber
+ final StringBuffer strb = new StringBuffer(64); // CSOFF: MagicNumber
int c;
boolean eol = false;
try {
@@ -1094,7 +1094,7 @@
strb.append((char) c);
reader.mark(1);
}
- } catch (IOException xio) {
+ } catch (final IOException xio) {
return null;
}
return strb.length() > 0 ? strb : null;
@@ -1107,7 +1107,7 @@
@Override
public CharSequence next() {
- CharSequence current = next;
+ final CharSequence current = next;
if (current != null) {
next = doNext();
}
@@ -1127,7 +1127,7 @@
* @param source the source reader
* @return the list of blocks
*/
- protected List<Block> readTemplate(final String prefix, Reader source) {
+ protected List<Block> readTemplate(final String prefix, final Reader source) {
final ArrayList<Block> blocks = new ArrayList<Block>();
final BufferedReader reader;
if (source instanceof BufferedReader) {
@@ -1138,11 +1138,11 @@
final StringBuilder strb = new StringBuilder();
BlockType type = null;
int prefixLen;
- Iterator<CharSequence> lines = readLines(reader);
+ final Iterator<CharSequence> lines = readLines(reader);
int lineno = 1;
int start = 0;
while (lines.hasNext()) {
- CharSequence line = lines.next();
+ final CharSequence line = lines.next();
if (line == null) {
break;
} else if (type == null) {
@@ -1160,7 +1160,7 @@
// switch to verbatim if necessary
prefixLen = startsWith(line, prefix);
if (prefixLen < 0) {
- Block directive = new Block(BlockType.DIRECTIVE, start, strb.toString());
+ final Block directive = new Block(BlockType.DIRECTIVE, start, strb.toString());
strb.delete(0, Integer.MAX_VALUE);
blocks.add(directive);
type = BlockType.VERBATIM;
@@ -1174,7 +1174,7 @@
// switch to directive if necessary
prefixLen = startsWith(line, prefix);
if (prefixLen >= 0) {
- Block verbatim = new Block(BlockType.VERBATIM, start, strb.toString());
+ final Block verbatim = new Block(BlockType.VERBATIM, start, strb.toString());
strb.delete(0, Integer.MAX_VALUE);
blocks.add(verbatim);
type = BlockType.DIRECTIVE;
@@ -1188,7 +1188,7 @@
}
// input may be null
if (type != null && strb.length() > 0) {
- Block block = new Block(type, start, strb.toString());
+ final Block block = new Block(type, start, strb.toString());
blocks.add(block);
}
blocks.trimToSize();
@@ -1196,7 +1196,7 @@
}
@Override
- public TemplateScript createTemplate(JexlInfo info, String prefix, Reader source, String... parms) {
+ public TemplateScript createTemplate(final JexlInfo info, final String prefix, final Reader source, final String... parms) {
return new TemplateScript(this, info, prefix, source, parms);
}
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java b/src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java
index 865469e..c3ecc27 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateInterpreter.java
@@ -62,7 +62,7 @@
* Sole ctor.
* @param e the JEXL engine
*/
- Arguments(Engine e) {
+ Arguments(final Engine e) {
this.jexl = e;
}
/**
@@ -70,7 +70,7 @@
* @param o the options
* @return this instance
*/
- Arguments options(JexlOptions o) {
+ Arguments options(final JexlOptions o) {
this.options = o;
return this;
}
@@ -79,7 +79,7 @@
* @param j the context
* @return this instance
*/
- Arguments context(JexlContext j) {
+ Arguments context(final JexlContext j) {
this.jcontext = j;
return this;
}
@@ -88,7 +88,7 @@
* @param f the frame
* @return this instance
*/
- Arguments frame(Frame f) {
+ Arguments frame(final Frame f) {
this.jframe = f;
return this;
}
@@ -97,7 +97,7 @@
* @param e the expressions
* @return this instance
*/
- Arguments expressions(TemplateExpression[] e) {
+ Arguments expressions(final TemplateExpression[] e) {
this.expressions = e;
return this;
}
@@ -106,7 +106,7 @@
* @param o the writer
* @return this instance
*/
- Arguments writer(Writer o) {
+ Arguments writer(final Writer o) {
this.out = o;
return this;
}
@@ -116,7 +116,7 @@
* Creates a template interpreter instance.
* @param args the template interpreter arguments
*/
- TemplateInterpreter(Arguments args) {
+ TemplateInterpreter(final Arguments args) {
super(args.jexl, args.options, args.jcontext, args.jframe);
exprs = args.expressions;
writer = args.out;
@@ -130,7 +130,7 @@
* @param script the TemplateScript to evaluate
* @param args the arguments
*/
- public void include(TemplateScript script, Object... args) {
+ public void include(final TemplateScript script, final Object... args) {
script.evaluate(context, writer, args);
}
@@ -138,7 +138,7 @@
* Prints a unified expression evaluation result.
* @param e the expression number
*/
- public void print(int e) {
+ public void print(final int e) {
if (e < 0 || e >= exprs.length) {
return;
}
@@ -157,10 +157,10 @@
* Prints a composite expression.
* @param composite the composite expression
*/
- private void printComposite(TemplateEngine.CompositeExpression composite) {
- TemplateEngine.TemplateExpression[] cexprs = composite.exprs;
+ private void printComposite(final TemplateEngine.CompositeExpression composite) {
+ final TemplateEngine.TemplateExpression[] cexprs = composite.exprs;
Object value;
- for (TemplateExpression cexpr : cexprs) {
+ for (final TemplateExpression cexpr : cexprs) {
value = cexpr.evaluate(this);
doPrint(cexpr.getInfo(), value);
}
@@ -175,15 +175,15 @@
* @param info the source info
* @param arg the argument to print out
*/
- private void doPrint(JexlInfo info, Object arg) {
+ private void doPrint(final JexlInfo info, final Object arg) {
try {
if (writer != null) {
if (arg instanceof CharSequence) {
writer.write(arg.toString());
} else if (arg != null) {
- Object[] value = {arg};
- JexlUberspect uber = jexl.getUberspect();
- JexlMethod method = uber.getMethod(writer, "print", value);
+ final Object[] value = {arg};
+ final JexlUberspect uber = jexl.getUberspect();
+ final JexlMethod method = uber.getMethod(writer, "print", value);
if (method != null) {
method.invoke(writer, value);
} else {
@@ -191,21 +191,21 @@
}
}
}
- } catch (java.io.IOException xio) {
+ } catch (final java.io.IOException xio) {
throw TemplateEngine.createException(info, "call print", null, xio);
- } catch (java.lang.Exception xany) {
+ } catch (final java.lang.Exception xany) {
throw TemplateEngine.createException(info, "invoke print", null, xany);
}
}
@Override
- protected Object resolveNamespace(String prefix, JexlNode node) {
+ protected Object resolveNamespace(final String prefix, final JexlNode node) {
return "jexl".equals(prefix)? this : super.resolveNamespace(prefix, node);
}
@Override
- protected Object visit(ASTIdentifier node, Object data) {
- String name = node.getName();
+ protected Object visit(final ASTIdentifier node, final Object data) {
+ final String name = node.getName();
if ("$jexl".equals(name)) {
return writer;
}
@@ -213,13 +213,13 @@
}
@Override
- protected Object visit(ASTJexlScript script, Object data) {
+ protected Object visit(final ASTJexlScript script, final Object data) {
if (script instanceof ASTJexlLambda && !((ASTJexlLambda) script).isTopLevel()) {
return new Closure(this, (ASTJexlLambda) script) {
@Override
- protected Interpreter createInterpreter(JexlContext context, Frame local) {
- JexlOptions opts = jexl.options(script, context);
- TemplateInterpreter.Arguments targs = new TemplateInterpreter.Arguments(jexl)
+ protected Interpreter createInterpreter(final JexlContext context, final Frame local) {
+ final JexlOptions opts = jexl.options(script, context);
+ final TemplateInterpreter.Arguments targs = new TemplateInterpreter.Arguments(jexl)
.context(context)
.options(opts)
.frame(local)
@@ -233,7 +233,7 @@
final int numChildren = script.jjtGetNumChildren();
Object result = null;
for (int i = 0; i < numChildren; i++) {
- JexlNode child = script.jjtGetChild(i);
+ final JexlNode child = script.jjtGetChild(i);
result = child.jjtAccept(this, data);
cancelCheck(child);
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/TemplateScript.java b/src/main/java/org/apache/commons/jexl3/internal/TemplateScript.java
index 12fa01e..129bc59 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/TemplateScript.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateScript.java
@@ -65,7 +65,7 @@
* @throws NullPointerException if either the directive prefix or input is null
* @throws IllegalArgumentException if the directive prefix is invalid
*/
- public TemplateScript(TemplateEngine engine, JexlInfo info, String directive, Reader reader, String... parms) {
+ public TemplateScript(final TemplateEngine engine, JexlInfo info, final String directive, final Reader reader, final String... parms) {
if (directive == null) {
throw new NullPointerException("null prefix");
}
@@ -83,15 +83,15 @@
}
this.jxlt = engine;
this.prefix = directive;
- List<Block> blocks = jxlt.readTemplate(prefix, reader);
- List<TemplateExpression> uexprs = new ArrayList<>();
- StringBuilder strb = new StringBuilder();
+ final List<Block> blocks = jxlt.readTemplate(prefix, reader);
+ final List<TemplateExpression> uexprs = new ArrayList<>();
+ final StringBuilder strb = new StringBuilder();
int nuexpr = 0;
int codeStart = -1;
int line = 1;
for (int b = 0; b < blocks.size(); ++b) {
- Block block = blocks.get(b);
- int bl = block.getLine();
+ final Block block = blocks.get(b);
+ final int bl = block.getLine();
while(line < bl) {
strb.append("//\n");
line += 1;
@@ -106,7 +106,7 @@
if (codeStart < 0) {
codeStart = b;
}
- String body = block.getBody();
+ final String body = block.getBody();
strb.append(body);
for(int c = 0; c < body.length(); ++c) {
if (body.charAt(c) == '\n') {
@@ -120,18 +120,18 @@
info = jxlt.getEngine().createInfo();
}
// allow lambda defining params
- Scope scope = parms == null ? null : new Scope(null, parms);
+ final Scope scope = parms == null ? null : new Scope(null, parms);
script = jxlt.getEngine().parse(info.at(1, 1), false, strb.toString(), scope).script();
// seek the map of expression number to scope so we can parse Unified
// expression blocks with the appropriate symbols
- Map<Integer, JexlNode.Info> minfo = new TreeMap<>();
+ final Map<Integer, JexlNode.Info> minfo = new TreeMap<>();
collectPrintScope(script.script(), minfo);
// jexl:print(...) expression counter
int jpe = 0;
// create the exprs using the intended scopes
- for (Block block : blocks) {
+ for (final Block block : blocks) {
if (block.getType() == BlockType.VERBATIM) {
- JexlNode.Info ji = minfo.get(jpe);
+ final JexlNode.Info ji = minfo.get(jpe);
TemplateExpression te;
// no node info means this verbatim is surrounded by comments markers;
// expr at this index is never called
@@ -156,11 +156,11 @@
* @param theScript the script
* @param theExprs the expressions
*/
- TemplateScript(TemplateEngine engine,
- String thePrefix,
- Block[] theSource,
- ASTJexlScript theScript,
- TemplateExpression[] theExprs) {
+ TemplateScript(final TemplateEngine engine,
+ final String thePrefix,
+ final Block[] theSource,
+ final ASTJexlScript theScript,
+ final TemplateExpression[] theExprs) {
jxlt = engine;
prefix = thePrefix;
source = theSource;
@@ -173,7 +173,7 @@
* @param info the node info
* @return the scope
*/
- private static Scope scopeOf(JexlNode.Info info) {
+ private static Scope scopeOf(final JexlNode.Info info) {
JexlNode walk = info.getNode();
while(walk != null) {
if (walk instanceof ASTJexlScript) {
@@ -191,19 +191,19 @@
* @param node the visited node
* @param minfo the map of printed expression number to node info
*/
- private static void collectPrintScope(JexlNode node, Map<Integer, JexlNode.Info> minfo) {
- int nc = node.jjtGetNumChildren();
+ private static void collectPrintScope(final JexlNode node, final Map<Integer, JexlNode.Info> minfo) {
+ final int nc = node.jjtGetNumChildren();
if (node instanceof ASTFunctionNode) {
if (nc == 2) {
// 0 must be the prefix jexl:
- ASTIdentifier nameNode = (ASTIdentifier) node.jjtGetChild(0);
+ final ASTIdentifier nameNode = (ASTIdentifier) node.jjtGetChild(0);
if ("print".equals(nameNode.getName()) && "jexl".equals(nameNode.getNamespace())) {
- ASTArguments argNode = (ASTArguments) node.jjtGetChild(1);
+ final ASTArguments argNode = (ASTArguments) node.jjtGetChild(1);
if (argNode.jjtGetNumChildren() == 1) {
// seek the epression number
- JexlNode arg0 = argNode.jjtGetChild(0);
+ final JexlNode arg0 = argNode.jjtGetChild(0);
if (arg0 instanceof ASTNumberLiteral) {
- int exprNumber = ((ASTNumberLiteral) arg0).getLiteral().intValue();
+ final int exprNumber = ((ASTNumberLiteral) arg0).getLiteral().intValue();
minfo.put(exprNumber, new JexlNode.Info(nameNode));
return;
}
@@ -232,8 +232,8 @@
@Override
public String toString() {
- StringBuilder strb = new StringBuilder();
- for (Block block : source) {
+ final StringBuilder strb = new StringBuilder();
+ for (final Block block : source) {
block.toString(strb, prefix);
}
return strb.toString();
@@ -241,9 +241,9 @@
@Override
public String asString() {
- StringBuilder strb = new StringBuilder();
+ final StringBuilder strb = new StringBuilder();
int e = 0;
- for (Block block : source) {
+ for (final Block block : source) {
if (block.getType() == BlockType.DIRECTIVE) {
strb.append(prefix);
strb.append(block.getBody());
@@ -255,22 +255,22 @@
}
@Override
- public TemplateScript prepare(JexlContext context) {
+ public TemplateScript prepare(final JexlContext context) {
final Engine jexl = jxlt.getEngine();
- JexlOptions options = jexl.options(script, context);
- Frame frame = script.createFrame((Object[]) null);
- TemplateInterpreter.Arguments targs = new TemplateInterpreter
+ final JexlOptions options = jexl.options(script, context);
+ final Frame frame = script.createFrame((Object[]) null);
+ final TemplateInterpreter.Arguments targs = new TemplateInterpreter
.Arguments(jxlt.getEngine())
.context(context)
.options(options)
.frame(frame);
- Interpreter interpreter = new TemplateInterpreter(targs);
- TemplateExpression[] immediates = new TemplateExpression[exprs.length];
+ final Interpreter interpreter = new TemplateInterpreter(targs);
+ final TemplateExpression[] immediates = new TemplateExpression[exprs.length];
for (int e = 0; e < exprs.length; ++e) {
try {
immediates[e] = exprs[e].prepare(interpreter);
- } catch (JexlException xjexl) {
- JexlException xuel = TemplateEngine.createException(xjexl.getInfo(), "prepare", exprs[e], xjexl);
+ } catch (final JexlException xjexl) {
+ final JexlException xuel = TemplateEngine.createException(xjexl.getInfo(), "prepare", exprs[e], xjexl);
if (jexl.isSilent()) {
jexl.logger.warn(xuel.getMessage(), xuel.getCause());
return null;
@@ -282,30 +282,30 @@
}
@Override
- public void evaluate(JexlContext context, Writer writer) {
+ public void evaluate(final JexlContext context, final Writer writer) {
evaluate(context, writer, (Object[]) null);
}
@Override
- public void evaluate(JexlContext context, Writer writer, Object... args) {
+ public void evaluate(final JexlContext context, final Writer writer, final Object... args) {
final Engine jexl = jxlt.getEngine();
- JexlOptions options = jexl.options(script, context);
- Frame frame = script.createFrame(args);
- TemplateInterpreter.Arguments targs = new TemplateInterpreter
+ final JexlOptions options = jexl.options(script, context);
+ final Frame frame = script.createFrame(args);
+ final TemplateInterpreter.Arguments targs = new TemplateInterpreter
.Arguments(jexl)
.context(context)
.options(options)
.frame(frame)
.expressions(exprs)
.writer(writer);
- Interpreter interpreter = new TemplateInterpreter(targs);
+ final Interpreter interpreter = new TemplateInterpreter(targs);
interpreter.interpret(script);
}
@Override
public Set<List<String>> getVariables() {
- Engine.VarCollector collector = jxlt.getEngine().varCollector();
- for (TemplateExpression expr : exprs) {
+ final Engine.VarCollector collector = jxlt.getEngine().varCollector();
+ for (final TemplateExpression expr : exprs) {
expr.getVariables(collector);
}
return collector.collected();
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/AbstractExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/AbstractExecutor.java
index 1cbbc64..06f660b 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/AbstractExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/AbstractExecutor.java
@@ -39,10 +39,10 @@
* @param parms the parameters
* @return the method
*/
- static java.lang.reflect.Method initMarker(Class<?> clazz, String name, Class<?>... parms) {
+ static java.lang.reflect.Method initMarker(final Class<?> clazz, final String name, final Class<?>... parms) {
try {
return clazz.getMethod(name, parms);
- } catch (Exception xnever) {
+ } catch (final Exception xnever) {
throw new Error(xnever);
}
}
@@ -52,7 +52,7 @@
* @param arg the Object to coerce
* @return an Integer if it can be converted, null otherwise
*/
- static Integer castInteger(Object arg) {
+ static Integer castInteger(final Object arg) {
return arg instanceof Number? ((Number) arg).intValue() : null;
}
@@ -61,7 +61,7 @@
* @param arg the Object to coerce
* @return a String if it can be converted, null otherwise
*/
- static String castString(Object arg) {
+ static String castString(final Object arg) {
return arg instanceof CharSequence || arg instanceof Integer ? arg.toString() : null;
}
@@ -70,7 +70,7 @@
* @param args the list of arguments
* @return the arguments array
*/
- static Object[] makeArgs(Object... args) {
+ static Object[] makeArgs(final Object... args) {
return args;
}
@@ -79,7 +79,7 @@
* @param instance the instance
* @return the class
*/
- static Class<?> classOf(Object instance) {
+ static Class<?> classOf(final Object instance) {
return instance == null? Object.class : instance.getClass();
}
@@ -93,13 +93,13 @@
* @param theClass the class this executor applies to
* @param theMethod the method held by this executor
*/
- protected AbstractExecutor(Class<?> theClass, java.lang.reflect.Method theMethod) {
+ protected AbstractExecutor(final Class<?> theClass, final java.lang.reflect.Method theMethod) {
objectClass = theClass;
method = theMethod;
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
return this == obj || (obj instanceof AbstractExecutor && equals((AbstractExecutor) obj));
}
@@ -113,7 +113,7 @@
* @param arg the other executor to check
* @return true if both executors are equivalent, false otherwise
*/
- public boolean equals(AbstractExecutor arg) {
+ public boolean equals(final AbstractExecutor arg) {
// common equality check
if (!this.getClass().equals(arg.getClass())) {
return false;
@@ -125,8 +125,8 @@
return false;
}
// specific equality check
- Object lhsp = this.getTargetProperty();
- Object rhsp = arg.getTargetProperty();
+ final Object lhsp = this.getTargetProperty();
+ final Object rhsp = arg.getTargetProperty();
if (lhsp == null && rhsp == null) {
return true;
}
@@ -193,7 +193,7 @@
* @param exec the value returned by tryExecute
* @return true if tryExecute failed, false otherwise
*/
- public final boolean tryFailed(Object exec) {
+ public final boolean tryFailed(final Object exec) {
return exec == JexlEngine.TRY_FAILED;
}
@@ -206,7 +206,7 @@
* @param theClass the class this executor applies to
* @param theMethod the method held by this executor
*/
- protected Get(Class<?> theClass, java.lang.reflect.Method theMethod) {
+ protected Get(final Class<?> theClass, final java.lang.reflect.Method theMethod) {
super(theClass, theMethod);
}
}
@@ -220,7 +220,7 @@
* @param theClass the class this executor applies to
* @param theMethod the method held by this executor
*/
- protected Set(Class<?> theClass, java.lang.reflect.Method theMethod) {
+ protected Set(final Class<?> theClass, final java.lang.reflect.Method theMethod) {
super(theClass, theMethod);
}
}
@@ -238,7 +238,7 @@
* @param m the method
* @param k the MethodKey
*/
- protected Method(Class<?> c, java.lang.reflect.Method m, MethodKey k) {
+ protected Method(final Class<?> c, final java.lang.reflect.Method m, final MethodKey k) {
super(c, m);
key = k;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayIterator.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayIterator.java
index e65e12d..d86d43a 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayIterator.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayIterator.java
@@ -49,7 +49,7 @@
* Creates a new iterator instance for the specified array.
* @param arr The array for which an iterator is desired.
*/
- public ArrayIterator(Object arr) {
+ public ArrayIterator(final Object arr) {
if (arr == null) {
array = null;
pos = 0;
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java
index 6bc5167..fb31742 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/ArrayListWrapper.java
@@ -36,7 +36,7 @@
* Create the wrapper.
* @param anArray {@link #array}
*/
- public ArrayListWrapper(Object anArray) {
+ public ArrayListWrapper(final Object anArray) {
if (!anArray.getClass().isArray()) {
throw new IllegalArgumentException(anArray.getClass() + " is not an array");
}
@@ -44,13 +44,13 @@
}
@Override
- public Object get(int index) {
+ public Object get(final int index) {
return Array.get(array, index);
}
@Override
- public Object set(int index, Object element) {
- Object old = Array.get(array, index);
+ public Object set(final int index, final Object element) {
+ final Object old = Array.get(array, index);
Array.set(array, index, element);
return old;
}
@@ -61,7 +61,7 @@
}
@Override
- public int indexOf(Object o) {
+ public int indexOf(final Object o) {
final int size = size();
if (o == null) {
for (int i = 0; i < size; i++) {
@@ -80,7 +80,7 @@
}
@Override
- public boolean contains(Object o) {
+ public boolean contains(final Object o) {
return indexOf(o) != -1;
}
}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/BooleanGetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/BooleanGetExecutor.java
index 76d1c93..111f91f 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/BooleanGetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/BooleanGetExecutor.java
@@ -35,9 +35,9 @@
* @param property the the property name
* @return the executor if found, null otherwise
*/
- public static BooleanGetExecutor discover(Introspector is, final Class<?> clazz, String property) {
+ public static BooleanGetExecutor discover(final Introspector is, final Class<?> clazz, final String property) {
if (property != null && !property.isEmpty()) {
- java.lang.reflect.Method m = PropertyGetExecutor.discoverGet(is, "is", clazz, property);
+ final java.lang.reflect.Method m = PropertyGetExecutor.discoverGet(is, "is", clazz, property);
if (m != null && (m.getReturnType() == Boolean.TYPE || m.getReturnType() == Boolean.class)) {
return new BooleanGetExecutor(clazz, m, property);
}
@@ -51,7 +51,7 @@
* @param method the method held by this executor
* @param key the property to get
*/
- private BooleanGetExecutor(Class<?> clazz, java.lang.reflect.Method method, String key) {
+ private BooleanGetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final String key) {
super(clazz, method);
property = key;
}
@@ -62,21 +62,21 @@
}
@Override
- public Object invoke(Object obj) throws IllegalAccessException, InvocationTargetException {
+ public Object invoke(final Object obj) throws IllegalAccessException, InvocationTargetException {
return method == null ? null : method.invoke(obj, (Object[]) null);
}
@Override
- public Object tryInvoke(Object obj, Object key) {
+ public Object tryInvoke(final Object obj, final Object key) {
if (obj != null && method != null
// ensure method name matches the property name
&& property.equals(key)
&& objectClass.equals(obj.getClass())) {
try {
return method.invoke(obj, (Object[]) null);
- } catch (IllegalAccessException xill) {
+ } catch (final IllegalAccessException xill) {
return TRY_FAILED;// fail
- } catch (InvocationTargetException xinvoke) {
+ } catch (final InvocationTargetException xinvoke) {
throw JexlException.tryFailed(xinvoke); // throw
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/ClassMap.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/ClassMap.java
index 002366f..e0dae57 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/ClassMap.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/ClassMap.java
@@ -53,7 +53,7 @@
public static Method cacheMiss() {
try {
return ClassMap.class.getMethod("cacheMiss");
- } catch (Exception xio) {
+ } catch (final Exception xio) {
// this really cant make an error...
return null;
}
@@ -95,14 +95,14 @@
* @param log the logger.
*/
@SuppressWarnings("LeakingThisInConstructor")
- ClassMap(Class<?> aClass, Permissions permissions, Log log) {
+ ClassMap(final Class<?> aClass, final Permissions permissions, final Log log) {
// eagerly cache methods
create(this, permissions, aClass, log);
// eagerly cache public fields
- Field[] fields = aClass.getFields();
+ final Field[] fields = aClass.getFields();
if (fields.length > 0) {
- Map<String, Field> cache = new HashMap<>();
- for (Field field : fields) {
+ final Map<String, Field> cache = new HashMap<>();
+ for (final Field field : fields) {
if (permissions.allow(field)) {
cache.put(field.getName(), field);
}
@@ -148,7 +148,7 @@
* @return the array of methods (null or non-empty)
*/
Method[] getMethods(final String methodName) {
- Method[] lm = byName.get(methodName);
+ final Method[] lm = byName.get(methodName);
if (lm != null && lm.length > 0) {
return lm.clone();
} else {
@@ -182,7 +182,7 @@
} else if (cacheEntry == null) {
try {
// That one is expensive...
- Method[] methodList = byName.get(methodKey.getMethod());
+ final Method[] methodList = byName.get(methodKey.getMethod());
if (methodList != null) {
cacheEntry = methodKey.getMostSpecificMethod(methodList);
}
@@ -191,7 +191,7 @@
} else {
byKey.put(methodKey, cacheEntry);
}
- } catch (MethodKey.AmbiguousException ae) {
+ } catch (final MethodKey.AmbiguousException ae) {
// that's a miss :-)
byKey.put(methodKey, CACHE_MISS);
throw ae;
@@ -211,7 +211,7 @@
* @param classToReflect the class to cache
* @param log the Log
*/
- private static void create(ClassMap cache, Permissions permissions, Class<?> classToReflect, Log log) {
+ private static void create(final ClassMap cache, final Permissions permissions, Class<?> classToReflect, final Log log) {
//
// Build a list of all elements in the class hierarchy. This one is bottom-first (i.e. we start
// with the actual declaring class and its interfaces and then move up (superclass etc.) until we
@@ -224,31 +224,31 @@
if (Modifier.isPublic(classToReflect.getModifiers())) {
populateWithClass(cache, permissions, classToReflect, log);
}
- Class<?>[] interfaces = classToReflect.getInterfaces();
- for (Class<?> anInterface : interfaces) {
+ final Class<?>[] interfaces = classToReflect.getInterfaces();
+ for (final Class<?> anInterface : interfaces) {
populateWithInterface(cache, permissions, anInterface, log);
}
}
// now that we've got all methods keyed in, lets organize them by name
if (!cache.byKey.isEmpty()) {
- List<Method> lm = new ArrayList<>(cache.byKey.size());
+ final List<Method> lm = new ArrayList<>(cache.byKey.size());
lm.addAll(cache.byKey.values());
// sort all methods by name
lm.sort(Comparator.comparing(Method::getName));
// put all lists of methods with same name in byName cache
int start = 0;
while (start < lm.size()) {
- String name = lm.get(start).getName();
+ final String name = lm.get(start).getName();
int end = start + 1;
while (end < lm.size()) {
- String walk = lm.get(end).getName();
+ final String walk = lm.get(end).getName();
if (walk.equals(name)) {
end += 1;
} else {
break;
}
}
- Method[] lmn = lm.subList(start, end).toArray(new Method[end - start]);
+ final Method[] lmn = lm.subList(start, end).toArray(new Method[end - start]);
cache.byName.put(name, lmn);
start = end;
}
@@ -263,11 +263,11 @@
* @param iface the interface to populate the cache from
* @param log the Log
*/
- private static void populateWithInterface(ClassMap cache, Permissions permissions, Class<?> iface, Log log) {
+ private static void populateWithInterface(final ClassMap cache, final Permissions permissions, final Class<?> iface, final Log log) {
if (Modifier.isPublic(iface.getModifiers())) {
populateWithClass(cache, permissions, iface, log);
- Class<?>[] supers = iface.getInterfaces();
- for (Class<?> aSuper : supers) {
+ final Class<?>[] supers = iface.getInterfaces();
+ for (final Class<?> aSuper : supers) {
populateWithInterface(cache, permissions, aSuper, log);
}
}
@@ -281,19 +281,19 @@
* @param clazz the class to populate the cache from
* @param log the Log
*/
- private static void populateWithClass(ClassMap cache, Permissions permissions, Class<?> clazz, Log log) {
+ private static void populateWithClass(final ClassMap cache, final Permissions permissions, final Class<?> clazz, final Log log) {
try {
- Method[] methods = clazz.getDeclaredMethods();
- for (Method mi : methods) {
+ final Method[] methods = clazz.getDeclaredMethods();
+ for (final Method mi : methods) {
// add method to byKey cache; do not override
- MethodKey key = new MethodKey(mi);
- Method pmi = cache.byKey.putIfAbsent(key, permissions.allow(mi) ? mi : CACHE_MISS);
+ final MethodKey key = new MethodKey(mi);
+ final Method pmi = cache.byKey.putIfAbsent(key, permissions.allow(mi) ? mi : CACHE_MISS);
if (pmi != null && pmi != CACHE_MISS && log.isDebugEnabled() && !key.equals(new MethodKey(pmi))) {
// foo(int) and foo(Integer) have the same signature for JEXL
log.debug("Method " + pmi + " is already registered, key: " + key.debugString());
}
}
- } catch (SecurityException se) {
+ } catch (final SecurityException se) {
// Everybody feels better with...
if (log.isDebugEnabled()) {
log.debug("While accessing methods of " + clazz + ": ", se);
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/ConstructorMethod.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/ConstructorMethod.java
index 0e17ef3..16bc4c3 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/ConstructorMethod.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/ConstructorMethod.java
@@ -36,7 +36,7 @@
* @param args constructor arguments
* @return a {@link JexlMethod}
*/
- public static ConstructorMethod discover(Introspector is, Object ctorHandle, Object... args) {
+ public static ConstructorMethod discover(final Introspector is, final Object ctorHandle, final Object... args) {
String className;
Class<?> clazz = null;
if (ctorHandle instanceof Class<?>) {
@@ -47,7 +47,7 @@
} else {
return null;
}
- Constructor<?> ctor = is.getConstructor(clazz, new MethodKey(className, args));
+ final Constructor<?> ctor = is.getConstructor(clazz, new MethodKey(className, args));
if (ctor != null) {
return new ConstructorMethod(ctor);
} else {
@@ -58,13 +58,13 @@
* Creates a constructor method.
* @param theCtor the constructor to wrap
*/
- ConstructorMethod(Constructor<?> theCtor) {
+ ConstructorMethod(final Constructor<?> theCtor) {
this.ctor = theCtor;
}
@Override
- public Object invoke(Object obj, Object... params) throws Exception {
- Class<?> ctorClass = ctor.getDeclaringClass();
+ public Object invoke(final Object obj, final Object... params) throws Exception {
+ final Class<?> ctorClass = ctor.getDeclaringClass();
boolean invoke = true;
if (obj != null) {
if (obj instanceof Class<?>) {
@@ -80,9 +80,9 @@
}
@Override
- public Object tryInvoke(String name, Object obj, Object... params) {
+ public Object tryInvoke(final String name, final Object obj, final Object... params) {
try {
- Class<?> ctorClass = ctor.getDeclaringClass();
+ final Class<?> ctorClass = ctor.getDeclaringClass();
boolean invoke = true;
if (obj != null) {
if (obj instanceof Class<?>) {
@@ -97,14 +97,14 @@
}
} catch (InstantiationException | IllegalArgumentException | IllegalAccessException xinstance) {
return Uberspect.TRY_FAILED;
- } catch (InvocationTargetException xinvoke) {
+ } catch (final InvocationTargetException xinvoke) {
throw JexlException.tryFailed(xinvoke); // throw
}
return Uberspect.TRY_FAILED;
}
@Override
- public boolean tryFailed(Object rval) {
+ public boolean tryFailed(final Object rval) {
return rval == Uberspect.TRY_FAILED;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckGetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckGetExecutor.java
index 8ec3836..c1e067a 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckGetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckGetExecutor.java
@@ -41,8 +41,8 @@
* @param identifier the key to use as an argument to the get method
* @return the executor if found, null otherwise
*/
- public static DuckGetExecutor discover(Introspector is, Class<?> clazz, Object identifier) {
- java.lang.reflect.Method method = is.getMethod(clazz, "get", makeArgs(identifier));
+ public static DuckGetExecutor discover(final Introspector is, final Class<?> clazz, final Object identifier) {
+ final java.lang.reflect.Method method = is.getMethod(clazz, "get", makeArgs(identifier));
return method == null? null : new DuckGetExecutor(clazz, method, identifier);
}
@@ -52,7 +52,7 @@
* @param method the method held by this executor
* @param identifier the property to get
*/
- private DuckGetExecutor(Class<?> clazz, java.lang.reflect.Method method, Object identifier) {
+ private DuckGetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final Object identifier) {
super(clazz, method);
property = identifier;
}
@@ -63,13 +63,13 @@
}
@Override
- public Object invoke(Object obj) throws IllegalAccessException, InvocationTargetException {
- Object[] args = {property};
+ public Object invoke(final Object obj) throws IllegalAccessException, InvocationTargetException {
+ final Object[] args = {property};
return method == null ? null : method.invoke(obj, args);
}
@Override
- public Object tryInvoke(Object obj, Object key) {
+ public Object tryInvoke(final Object obj, final Object key) {
if (obj != null
&& objectClass.equals(obj.getClass())
// ensure method name matches the property name
@@ -77,11 +77,11 @@
&& ((property == null && key == null)
|| (property != null && property.equals(key)))) {
try {
- Object[] args = {property};
+ final Object[] args = {property};
return method.invoke(obj, args);
} catch (IllegalAccessException | IllegalArgumentException xill) {
return TRY_FAILED;// fail
- } catch (InvocationTargetException xinvoke) {
+ } catch (final InvocationTargetException xinvoke) {
throw JexlException.tryFailed(xinvoke); // throw
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckSetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckSetExecutor.java
index 146f947..b7f32d3 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckSetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/DuckSetExecutor.java
@@ -51,7 +51,7 @@
* @param value the value to use as 2nd argument to the set method
* @return the executor if found, null otherwise
*/
- public static DuckSetExecutor discover(Introspector is, Class<?> clazz, Object key, Object value) {
+ public static DuckSetExecutor discover(final Introspector is, final Class<?> clazz, final Object key, final Object value) {
java.lang.reflect.Method method = is.getMethod(clazz, "set", makeArgs(key, value));
if (method == null) {
method = is.getMethod(clazz, "put", makeArgs(key, value));
@@ -66,7 +66,7 @@
* @param key the key to use as 1st argument to the set method
* @param value the value to use as 2nd argument to the set method
*/
- private DuckSetExecutor(Class<?> clazz, java.lang.reflect.Method method, Object key, Object value) {
+ private DuckSetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final Object key, final Object value) {
super(clazz, method);
property = key;
valueClass = classOf(value);
@@ -78,8 +78,8 @@
}
@Override
- public Object invoke(Object obj, Object value) throws IllegalAccessException, InvocationTargetException {
- Object[] pargs = {property, value};
+ public Object invoke(final Object obj, final Object value) throws IllegalAccessException, InvocationTargetException {
+ final Object[] pargs = {property, value};
if (method != null) {
method.invoke(obj, pargs);
}
@@ -87,7 +87,7 @@
}
@Override
- public Object tryInvoke(Object obj, Object key, Object value) {
+ public Object tryInvoke(final Object obj, final Object key, final Object value) {
if (obj != null
&& objectClass.equals(obj.getClass())
&& method != null
@@ -95,12 +95,12 @@
|| (property == null && key == null))
&& valueClass.equals(classOf(value))) {
try {
- Object[] args = {property, value};
+ final Object[] args = {property, value};
method.invoke(obj, args);
return value;
} catch (IllegalAccessException | IllegalArgumentException xill) {
return TRY_FAILED;// fail
- } catch (InvocationTargetException xinvoke) {
+ } catch (final InvocationTargetException xinvoke) {
throw JexlException.tryFailed(xinvoke); // throw
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/EnumerationIterator.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/EnumerationIterator.java
index 88e03cc..12e9931 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/EnumerationIterator.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/EnumerationIterator.java
@@ -38,7 +38,7 @@
*
* @param enumer The Enumeration to wrap.
*/
- public EnumerationIterator(Enumeration<T> enumer) {
+ public EnumerationIterator(final Enumeration<T> enumer) {
enumeration = enumer;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/FieldGetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/FieldGetExecutor.java
index 48871ba..c431a6b 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/FieldGetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/FieldGetExecutor.java
@@ -37,9 +37,9 @@
* @param identifier the key to use as an argument to the get method
* @return the executor if found, null otherwise
*/
- public static JexlPropertyGet discover(Introspector is, Class<?> clazz, String identifier) {
+ public static JexlPropertyGet discover(final Introspector is, final Class<?> clazz, final String identifier) {
if (identifier != null) {
- Field field = is.getField(clazz, identifier);
+ final Field field = is.getField(clazz, identifier);
if (field != null) {
return new FieldGetExecutor(field);
}
@@ -50,21 +50,21 @@
* Creates a new instance of FieldPropertyGet.
* @param theField the class public field
*/
- private FieldGetExecutor(Field theField) {
+ private FieldGetExecutor(final Field theField) {
field = theField;
}
@Override
- public Object invoke(Object obj) throws Exception {
+ public Object invoke(final Object obj) throws Exception {
return field.get(obj);
}
@Override
- public Object tryInvoke(Object obj, Object key) {
+ public Object tryInvoke(final Object obj, final Object key) {
if (obj.getClass().equals(field.getDeclaringClass()) && key.equals(field.getName())) {
try {
return field.get(obj);
- } catch (IllegalAccessException xill) {
+ } catch (final IllegalAccessException xill) {
return Uberspect.TRY_FAILED;
}
}
@@ -72,7 +72,7 @@
}
@Override
- public boolean tryFailed(Object rval) {
+ public boolean tryFailed(final Object rval) {
return rval == Uberspect.TRY_FAILED;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/FieldSetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/FieldSetExecutor.java
index 001f4b8..75f6b81 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/FieldSetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/FieldSetExecutor.java
@@ -39,9 +39,9 @@
* @param value the value to set the field to
* @return the executor if found, null otherwise
*/
- public static JexlPropertySet discover(Introspector is, Class<?> clazz, String identifier, Object value) {
+ public static JexlPropertySet discover(final Introspector is, final Class<?> clazz, final String identifier, final Object value) {
if (identifier != null) {
- Field field = is.getField(clazz, identifier);
+ final Field field = is.getField(clazz, identifier);
if (field != null
&& !Modifier.isFinal(field.getModifiers())
&& (value == null || MethodKey.isInvocationConvertible(field.getType(), value.getClass(), false))) {
@@ -55,25 +55,25 @@
* Creates a new instance of FieldPropertySet.
* @param theField the class public field
*/
- private FieldSetExecutor(Field theField) {
+ private FieldSetExecutor(final Field theField) {
field = theField;
}
@Override
- public Object invoke(Object obj, Object arg) throws Exception {
+ public Object invoke(final Object obj, final Object arg) throws Exception {
field.set(obj, arg);
return arg;
}
@Override
- public Object tryInvoke(Object obj, Object key, Object value) {
+ public Object tryInvoke(final Object obj, final Object key, final Object value) {
if (obj.getClass().equals(field.getDeclaringClass())
&& key.equals(field.getName())
&& (value == null || MethodKey.isInvocationConvertible(field.getType(), value.getClass(), false))) {
try {
field.set(obj, value);
return value;
- } catch (IllegalAccessException xill) {
+ } catch (final IllegalAccessException xill) {
return Uberspect.TRY_FAILED;
}
}
@@ -81,7 +81,7 @@
}
@Override
- public boolean tryFailed(Object rval) {
+ public boolean tryFailed(final Object rval) {
return rval == Uberspect.TRY_FAILED;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/IndexedType.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/IndexedType.java
index 5efda28..1245451 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/IndexedType.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/IndexedType.java
@@ -53,9 +53,9 @@
* @param name the container name
* @return a JexlPropertyGet is successful, null otherwise
*/
- public static JexlPropertyGet discover(Introspector is, Object object, String name) {
+ public static JexlPropertyGet discover(final Introspector is, final Object object, final String name) {
if (object != null && name != null && !name.isEmpty()) {
- String base = name.substring(0, 1).toUpperCase() + name.substring(1);
+ final String base = name.substring(0, 1).toUpperCase() + name.substring(1);
final String container = name;
final Class<?> clazz = object.getClass();
final Method[] getters = is.getMethods(object.getClass(), "get" + base);
@@ -83,7 +83,7 @@
* @param theType the container type
* @param theContainer the container instance
*/
- private IndexedContainer(IndexedType theType, Object theContainer) {
+ private IndexedContainer(final IndexedType theType, final Object theContainer) {
this.type = theType;
this.container = theContainer;
}
@@ -110,7 +110,7 @@
* @return the property value
* @throws Exception if inner invocation fails
*/
- public Object get(Object key) throws Exception {
+ public Object get(final Object key) throws Exception {
return type.invokeGet(container, key);
}
@@ -121,7 +121,7 @@
* @return the invocation result (frequently null)
* @throws Exception if inner invocation fails
*/
- public Object set(Object key, Object value) throws Exception {
+ public Object set(final Object key, final Object value) throws Exception {
return type.invokeSet(container, key, value);
}
}
@@ -133,7 +133,7 @@
* @param gets the array of getter methods
* @param sets the array of setter methods
*/
- private IndexedType(String name, Class<?> c, Method[] gets, Method[] sets) {
+ private IndexedType(final String name, final Class<?> c, final Method[] gets, final Method[] sets) {
this.container = name;
this.clazz = c;
this.getters = gets;
@@ -141,7 +141,7 @@
}
@Override
- public Object invoke(Object obj) throws Exception {
+ public Object invoke(final Object obj) throws Exception {
if (obj != null && clazz.equals(obj.getClass())) {
return new IndexedContainer(this, obj);
} else {
@@ -150,7 +150,7 @@
}
@Override
- public Object tryInvoke(Object obj, Object key) {
+ public Object tryInvoke(final Object obj, final Object key) {
if (obj != null && key != null
&& clazz.equals(obj.getClass())
&& container.equals(key.toString())) {
@@ -161,7 +161,7 @@
}
@Override
- public boolean tryFailed(Object rval) {
+ public boolean tryFailed(final Object rval) {
return rval == Uberspect.TRY_FAILED;
}
@@ -178,7 +178,7 @@
* @throws Exception if invocation failed;
* IntrospectionException if a property getter could not be found
*/
- private Object invokeGet(Object object, Object key) throws Exception {
+ private Object invokeGet(final Object object, final Object key) throws Exception {
if (getters != null && getters.length > 0) {
Method jm = get;
if (jm != null) {
@@ -192,7 +192,7 @@
final MethodKey km = new MethodKey(mname, args);
jm = km.getMostSpecificMethod(getters);
if (jm != null) {
- Object invoked = jm.invoke(object, args);
+ final Object invoked = jm.invoke(object, args);
get = jm;
return invoked;
}
@@ -211,7 +211,7 @@
* @throws Exception if invocation failed;
* IntrospectionException if a property setter could not be found
*/
- private Object invokeSet(Object object, Object key, Object value) throws Exception {
+ private Object invokeSet(final Object object, final Object key, final Object value) throws Exception {
if (setters != null && setters.length > 0) {
Method jm = set;
if (jm != null) {
@@ -227,7 +227,7 @@
final MethodKey km = new MethodKey(mname, args);
jm = km.getMostSpecificMethod(setters);
if (jm != null) {
- Object invoked = jm.invoke(object, args);
+ final Object invoked = jm.invoke(object, args);
set = jm;
return invoked;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/Introspector.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/Introspector.java
index 88c460a..d190fe7 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/Introspector.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/Introspector.java
@@ -92,7 +92,7 @@
* @param log the logger to use
* @param cloader the class loader
*/
- public Introspector(Log log, ClassLoader cloader) {
+ public Introspector(final Log log, final ClassLoader cloader) {
this(log, cloader, null);
}
@@ -102,7 +102,7 @@
* @param cloader the class loader
* @param perms the permissions
*/
- public Introspector(Log log, ClassLoader cloader, Permissions perms) {
+ public Introspector(final Log log, final ClassLoader cloader, final Permissions perms) {
this.logger = log;
this.loader = cloader;
this.permissions = perms != null? perms : Permissions.DEFAULT;
@@ -113,10 +113,10 @@
* @param className the class name
* @return the class instance or null if it could not be found
*/
- public Class<?> getClassByName(String className) {
+ public Class<?> getClassByName(final String className) {
try {
return Class.forName(className, false, loader);
- } catch (ClassNotFoundException xignore) {
+ } catch (final ClassNotFoundException xignore) {
return null;
}
}
@@ -129,7 +129,7 @@
* @return the desired method object
* @throws MethodKey.AmbiguousException if no unambiguous method could be found through introspection
*/
- public Method getMethod(Class<?> c, String name, Object[] params) {
+ public Method getMethod(final Class<?> c, final String name, final Object[] params) {
return getMethod(c, new MethodKey(name, params));
}
@@ -141,10 +141,10 @@
* @return The desired method object
* @throws MethodKey.AmbiguousException if no unambiguous method could be found through introspection
*/
- public Method getMethod(Class<?> c, MethodKey key) {
+ public Method getMethod(final Class<?> c, final MethodKey key) {
try {
return getMap(c).getMethod(key);
- } catch (MethodKey.AmbiguousException xambiguous) {
+ } catch (final MethodKey.AmbiguousException xambiguous) {
// whoops. Ambiguous and not benign. Make a nice log message and return null...
if (logger != null && xambiguous.isSevere() && logger.isInfoEnabled()) {
logger.info("ambiguous method invocation: "
@@ -162,7 +162,7 @@
* @param key Name of the field being searched for
* @return the desired field or null if it does not exist or is not accessible
* */
- public Field getField(Class<?> c, String key) {
+ public Field getField(final Class<?> c, final String key) {
return getMap(c).getField(key);
}
@@ -171,11 +171,11 @@
* @param c the class
* @return the class field names
*/
- public String[] getFieldNames(Class<?> c) {
+ public String[] getFieldNames(final Class<?> c) {
if (c == null) {
return new String[0];
}
- ClassMap classMap = getMap(c);
+ final ClassMap classMap = getMap(c);
return classMap.getFieldNames();
}
@@ -184,11 +184,11 @@
* @param c the class
* @return the class method names
*/
- public String[] getMethodNames(Class<?> c) {
+ public String[] getMethodNames(final Class<?> c) {
if (c == null) {
return new String[0];
}
- ClassMap classMap = getMap(c);
+ final ClassMap classMap = getMap(c);
return classMap.getMethodNames();
}
@@ -198,11 +198,11 @@
* @param methodName the method name
* @return the array of methods (null or not empty)
*/
- public Method[] getMethods(Class<?> c, String methodName) {
+ public Method[] getMethods(final Class<?> c, final String methodName) {
if (c == null) {
return null;
}
- ClassMap classMap = getMap(c);
+ final ClassMap classMap = getMap(c);
return classMap.getMethods(methodName);
}
@@ -259,8 +259,8 @@
// add it to list of known loaded classes
constructibleClasses.put(cname, clazz);
}
- List<Constructor<?>> l = new ArrayList<>();
- for (Constructor<?> ictor : clazz.getConstructors()) {
+ final List<Constructor<?>> l = new ArrayList<>();
+ for (final Constructor<?> ictor : clazz.getConstructors()) {
if (permissions.allow(ictor)) {
l.add(ictor);
}
@@ -272,14 +272,14 @@
} else {
constructorsMap.put(key, CTOR_MISS);
}
- } catch (ClassNotFoundException xnotfound) {
+ } catch (final ClassNotFoundException xnotfound) {
if (logger != null && logger.isDebugEnabled()) {
logger.debug("unable to find class: "
+ cname + "."
+ key.debugString(), xnotfound);
}
ctor = null;
- } catch (MethodKey.AmbiguousException xambiguous) {
+ } catch (final MethodKey.AmbiguousException xambiguous) {
if (logger != null && xambiguous.isSevere() && logger.isInfoEnabled()) {
logger.info("ambiguous constructor invocation: "
+ cname + "."
@@ -298,7 +298,7 @@
* @param c the class
* @return the class map
*/
- private ClassMap getMap(Class<?> c) {
+ private ClassMap getMap(final Class<?> c) {
ClassMap classMap;
try {
lock.readLock().lock();
@@ -329,7 +329,7 @@
* @param cloader the class loader; if null, use this instance class loader
*/
public void setLoader(ClassLoader cloader) {
- ClassLoader previous = loader;
+ final ClassLoader previous = loader;
if (cloader == null) {
cloader = getClass().getClassLoader();
}
@@ -337,10 +337,10 @@
try {
lock.writeLock().lock();
// clean up constructor and class maps
- Iterator<Map.Entry<MethodKey, Constructor<?>>> mentries = constructorsMap.entrySet().iterator();
+ final Iterator<Map.Entry<MethodKey, Constructor<?>>> mentries = constructorsMap.entrySet().iterator();
while (mentries.hasNext()) {
- Map.Entry<MethodKey, Constructor<?>> entry = mentries.next();
- Class<?> clazz = entry.getValue().getDeclaringClass();
+ final Map.Entry<MethodKey, Constructor<?>> entry = mentries.next();
+ final Class<?> clazz = entry.getValue().getDeclaringClass();
if (isLoadedBy(previous, clazz)) {
mentries.remove();
// the method name is the name of the class
@@ -348,10 +348,10 @@
}
}
// clean up method maps
- Iterator<Map.Entry<Class<?>, ClassMap>> centries = classMethodMaps.entrySet().iterator();
+ final Iterator<Map.Entry<Class<?>, ClassMap>> centries = classMethodMaps.entrySet().iterator();
while (centries.hasNext()) {
- Map.Entry<Class<?>, ClassMap> entry = centries.next();
- Class<?> clazz = entry.getKey();
+ final Map.Entry<Class<?>, ClassMap> entry = centries.next();
+ final Class<?> clazz = entry.getKey();
if (isLoadedBy(previous, clazz)) {
centries.remove();
}
@@ -377,7 +377,7 @@
* @param clazz the class to check
* @return true if clazz was loaded through the loader, false otherwise
*/
- private static boolean isLoadedBy(ClassLoader loader, Class<?> clazz) {
+ private static boolean isLoadedBy(final ClassLoader loader, final Class<?> clazz) {
if (loader != null) {
ClassLoader cloader = clazz.getClassLoader();
while (cloader != null) {
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/ListGetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/ListGetExecutor.java
index d1a00c2..adb8765 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/ListGetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/ListGetExecutor.java
@@ -41,7 +41,7 @@
* @param index the index to use as an argument to the get method
* @return the executor if found, null otherwise
*/
- public static ListGetExecutor discover(Introspector is, Class<?> clazz, Integer index) {
+ public static ListGetExecutor discover(final Introspector is, final Class<?> clazz, final Integer index) {
if (index != null) {
if (clazz.isArray()) {
return new ListGetExecutor(clazz, ARRAY_GET, index);
@@ -59,7 +59,7 @@
* @param method the method held by this executor
* @param index the index to use as an argument to the get method
*/
- private ListGetExecutor(Class<?> clazz, java.lang.reflect.Method method, Integer index) {
+ private ListGetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final Integer index) {
super(clazz, method);
property = index;
}
@@ -79,8 +79,8 @@
}
@Override
- public Object tryInvoke(final Object obj, Object identifier) {
- Integer index = castInteger(identifier);
+ public Object tryInvoke(final Object obj, final Object identifier) {
+ final Integer index = castInteger(identifier);
if (obj != null && method != null
&& objectClass.equals(obj.getClass())
&& index != null) {
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/ListSetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/ListSetExecutor.java
index 7aebb5b..14c2f7d 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/ListSetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/ListSetExecutor.java
@@ -42,8 +42,8 @@
* @param value the value to use as argument in list.put(key,value)
* @return the executor if found, null otherwise
*/
- public static ListSetExecutor discover(Introspector is, Class<?> clazz, Object identifier, Object value) {
- Integer index = castInteger(identifier);
+ public static ListSetExecutor discover(final Introspector is, final Class<?> clazz, final Object identifier, final Object value) {
+ final Integer index = castInteger(identifier);
if (index != null) {
if (clazz.isArray()) {
// we could verify if the call can be performed but it does not change
@@ -68,7 +68,7 @@
* @param method the method called through this executor
* @param key the key to use as 1st argument to the set method
*/
- private ListSetExecutor(Class<?> clazz, java.lang.reflect.Method method, Integer key) {
+ private ListSetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final Integer key) {
super(clazz, method);
property = key;
}
@@ -79,7 +79,7 @@
}
@Override
- public Object invoke(final Object obj, Object value) {
+ public Object invoke(final Object obj, final Object value) {
if (method == ARRAY_SET) {
Array.set(obj, property, value);
} else {
@@ -91,8 +91,8 @@
}
@Override
- public Object tryInvoke(final Object obj, Object key, Object value) {
- Integer index = castInteger(key);
+ public Object tryInvoke(final Object obj, final Object key, final Object value) {
+ final Integer index = castInteger(key);
if (obj != null && method != null
&& objectClass.equals(obj.getClass())
&& index != null) {
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java
index 1799fe5..07611b0 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MapGetExecutor.java
@@ -38,7 +38,7 @@
* @param identifier the key to use as an argument to the get method
* @return the executor if found, null otherwise
*/
- public static MapGetExecutor discover(Introspector is, Class<?> clazz, Object identifier) {
+ public static MapGetExecutor discover(final Introspector is, final Class<?> clazz, final Object identifier) {
if (Map.class.isAssignableFrom(clazz)) {
return new MapGetExecutor(clazz, MAP_GET, identifier);
} else {
@@ -52,7 +52,7 @@
* @param method the method held by this executor
* @param key the property to get
*/
- private MapGetExecutor(Class<?> clazz, java.lang.reflect.Method method, Object key) {
+ private MapGetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final Object key) {
super(clazz, method);
property = key;
}
@@ -70,7 +70,7 @@
}
@Override
- public Object tryInvoke(final Object obj, Object key) {
+ public Object tryInvoke(final Object obj, final Object key) {
if (obj != null
&& method != null
&& objectClass.equals(obj.getClass())
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java
index abaa081..7acbd47 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MapSetExecutor.java
@@ -39,7 +39,7 @@
* @param value the value to use as argument in map.put(key,value)
* @return the executor if found, null otherwise
*/
- public static MapSetExecutor discover(Introspector is, Class<?> clazz, Object identifier, Object value) {
+ public static MapSetExecutor discover(final Introspector is, final Class<?> clazz, final Object identifier, final Object value) {
if (Map.class.isAssignableFrom(clazz)) {
return new MapSetExecutor(clazz, MAP_SET, identifier, value);
} else {
@@ -54,7 +54,7 @@
* @param key the key to use as 1st argument to the set method
* @param value the value to use as 2nd argument to the set method
*/
- private MapSetExecutor(Class<?> clazz, java.lang.reflect.Method method, Object key, Object value) {
+ private MapSetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final Object key, final Object value) {
super(clazz, method);
property = key;
valueClass = classOf(value);
@@ -66,7 +66,7 @@
}
@Override
- public Object invoke(final Object obj, Object value) {
+ public Object invoke(final Object obj, final Object value) {
@SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method
final Map<Object,Object> map = ((Map<Object, Object>) obj);
map.put(property, value);
@@ -74,7 +74,7 @@
}
@Override
- public Object tryInvoke(final Object obj, Object key, Object value) {
+ public Object tryInvoke(final Object obj, final Object key, final Object value) {
if (obj != null
&& method != null
&& objectClass.equals(obj.getClass())
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
index 61247c9..021b7a6 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodExecutor.java
@@ -47,7 +47,7 @@
* @param args the method arguments
* @return a filled up parameter (may contain a null method)
*/
- public static MethodExecutor discover(Introspector is, Object obj, String method, Object[] args) {
+ public static MethodExecutor discover(final Introspector is, final Object obj, final String method, final Object[] args) {
final Class<?> clazz = obj.getClass();
final MethodKey key = new MethodKey(method, args);
java.lang.reflect.Method m = is.getMethod(clazz, key);
@@ -67,13 +67,13 @@
* @param m the method
* @param k the MethodKey
*/
- private MethodExecutor(Class<?> c, java.lang.reflect.Method m, MethodKey k) {
+ private MethodExecutor(final Class<?> c, final java.lang.reflect.Method m, final MethodKey k) {
super(c, m, k);
int vastart = -1;
Class<?> vaclass = null;
if (MethodKey.isVarArgs(method)) {
// if the last parameter is an array, the method is considered as vararg
- Class<?>[] formal = method.getParameterTypes();
+ final Class<?>[] formal = method.getParameterTypes();
vastart = formal.length - 1;
vaclass = formal[vastart].getComponentType();
}
@@ -82,7 +82,7 @@
}
@Override
- public Object invoke(Object o, Object... args) throws IllegalAccessException, InvocationTargetException {
+ public Object invoke(final Object o, Object... args) throws IllegalAccessException, InvocationTargetException {
if (vaClass != null && args != null) {
args = handleVarArg(args);
}
@@ -94,8 +94,8 @@
}
@Override
- public Object tryInvoke(String name, Object obj, Object... args) {
- MethodKey tkey = new MethodKey(name, args);
+ public Object tryInvoke(final String name, final Object obj, final Object... args) {
+ final MethodKey tkey = new MethodKey(name, args);
// let's assume that invocation will fly if the declaring class is the
// same and arguments have the same type
if (objectClass.equals(obj.getClass()) && tkey.equals(key)) {
@@ -103,7 +103,7 @@
return invoke(obj, args);
} catch (IllegalAccessException | IllegalArgumentException xill) {
return TRY_FAILED;// fail
- } catch (InvocationTargetException xinvoke) {
+ } catch (final InvocationTargetException xinvoke) {
throw JexlException.tryFailed(xinvoke); // throw
}
}
@@ -129,10 +129,10 @@
// and that arg is not the sole argument and not an array of the expected type,
// make the last arg an array of the expected type
if (actual[vastart] != null) {
- Class<?> aclazz = actual[vastart].getClass();
+ final Class<?> aclazz = actual[vastart].getClass();
if (!aclazz.isArray() || !vaclass.isAssignableFrom(aclazz.getComponentType())) {
// create a 1-length array to hold and replace the last argument
- Object lastActual = Array.newInstance(vaclass, 1);
+ final Object lastActual = Array.newInstance(vaclass, 1);
Array.set(lastActual, 0, actual[vastart]);
actual[vastart] = lastActual;
}
@@ -141,10 +141,10 @@
} else {
// if no or multiple values are being passed into the vararg,
// put them in an array of the expected type
- Object varargs = Array.newInstance(vaclass, varargc);
+ final Object varargs = Array.newInstance(vaclass, varargc);
System.arraycopy(actual, vastart, varargs, 0, varargc);
// put all arguments into a new actual array of the appropriate size
- Object[] newActual = new Object[vastart + 1];
+ final Object[] newActual = new Object[vastart + 1];
System.arraycopy(actual, 0, newActual, 0, vastart);
newActual[vastart] = varargs;
// replace the old actual array
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java
index 3700a99..3571fc2 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/MethodKey.java
@@ -64,7 +64,7 @@
* @param aMethod the method to generate the key from
* @param args the intended method arguments
*/
- public MethodKey(String aMethod, Object[] args) {
+ public MethodKey(final String aMethod, final Object[] args) {
// !! keep this in sync with the other ctor (hash code) !!
this.method = aMethod;
int hash = this.method.hashCode();
@@ -73,9 +73,9 @@
if (args != null && (size = args.length) > 0) {
this.params = new Class<?>[size];
for (int p = 0; p < size; ++p) {
- Object arg = args[p];
+ final Object arg = args[p];
// null arguments use void as Void.class as marker
- Class<?> parm = arg == null ? Void.class : arg.getClass();
+ final Class<?> parm = arg == null ? Void.class : arg.getClass();
hash = (HASH * hash) + parm.hashCode();
this.params[p] = parm;
}
@@ -89,7 +89,7 @@
* Creates a key from a method.
* @param aMethod the method to generate the key from.
*/
- MethodKey(Method aMethod) {
+ MethodKey(final Method aMethod) {
this(aMethod.getName(), aMethod.getParameterTypes());
}
@@ -97,7 +97,7 @@
* Creates a key from a constructor.
* @param aCtor the constructor to generate the key from.
*/
- MethodKey(Constructor<?> aCtor) {
+ MethodKey(final Constructor<?> aCtor) {
this(aCtor.getDeclaringClass().getName(), aCtor.getParameterTypes());
}
@@ -106,7 +106,7 @@
* @param aMethod the method to generate the key from
* @param args the intended method parameters
*/
- MethodKey(String aMethod, Class<?>[] args) {
+ MethodKey(final String aMethod, final Class<?>[] args) {
// !! keep this in sync with the other ctor (hash code) !!
this.method = aMethod.intern();
int hash = this.method.hashCode();
@@ -115,7 +115,7 @@
if (args != null && (size = args.length) > 0) {
this.params = new Class<?>[size];
for (int p = 0; p < size; ++p) {
- Class<?> parm = primitiveClass(args[p]);
+ final Class<?> parm = primitiveClass(args[p]);
hash = (HASH * hash) + parm.hashCode();
this.params[p] = parm;
}
@@ -147,9 +147,9 @@
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (obj instanceof MethodKey) {
- MethodKey key = (MethodKey) obj;
+ final MethodKey key = (MethodKey) obj;
return method.equals(key.method) && Arrays.equals(params, key.params);
}
return false;
@@ -157,8 +157,8 @@
@Override
public String toString() {
- StringBuilder builder = new StringBuilder(method);
- for (Class<?> c : params) {
+ final StringBuilder builder = new StringBuilder(method);
+ for (final Class<?> c : params) {
builder.append(c == Void.class ? "null" : c.getName());
}
return builder.toString();
@@ -169,7 +169,7 @@
* @return method(p0, p1, ...)
*/
public String debugString() {
- StringBuilder builder = new StringBuilder(method);
+ final StringBuilder builder = new StringBuilder(method);
builder.append('(');
for (int i = 0; i < params.length; i++) {
if (i > 0) {
@@ -207,11 +207,11 @@
Class<?> clazz = method.getDeclaringClass();
do {
try {
- Method m = clazz.getMethod(mname, ptypes);
+ final Method m = clazz.getMethod(mname, ptypes);
if (m.isVarArgs()) {
return true;
}
- } catch (NoSuchMethodException xignore) {
+ } catch (final NoSuchMethodException xignore) {
// this should not happen...
}
clazz = clazz.getSuperclass();
@@ -225,7 +225,7 @@
* @return the most specific method.
* @throws MethodKey.AmbiguousException if there is more than one.
*/
- public Method getMostSpecificMethod(Method[] methods) {
+ public Method getMostSpecificMethod(final Method[] methods) {
return METHODS.getMostSpecific(this, methods);
}
@@ -235,7 +235,7 @@
* @return the most specific constructor.
* @throws MethodKey.AmbiguousException if there is more than one.
*/
- public Constructor<?> getMostSpecificConstructor(Constructor<?>[] methods) {
+ public Constructor<?> getMostSpecificConstructor(final Constructor<?>[] methods) {
return CONSTRUCTORS.getMostSpecific(this, methods);
}
@@ -259,7 +259,7 @@
* type or an object type of a primitive type that can be converted to
* the formal type.
*/
- public static boolean isInvocationConvertible(Class<?> formal, Class<?> actual, boolean possibleVarArg) {
+ public static boolean isInvocationConvertible(final Class<?> formal, final Class<?> actual, final boolean possibleVarArg) {
return isInvocationConvertible(formal, actual, false, possibleVarArg);
}
@@ -279,7 +279,7 @@
* or formal and actual are both primitive types and actual can be
* subject to widening conversion to formal.
*/
- public static boolean isStrictInvocationConvertible(Class<?> formal, Class<?> actual, boolean possibleVarArg) {
+ public static boolean isStrictInvocationConvertible(final Class<?> formal, final Class<?> actual, final boolean possibleVarArg) {
return isInvocationConvertible(formal, actual, true, possibleVarArg);
}
@@ -293,10 +293,10 @@
* @param parm a may-be primitive type class
* @return the equivalent object class
*/
- static Class<?> primitiveClass(Class<?> parm) {
+ static Class<?> primitiveClass(final Class<?> parm) {
// it was marginally faster to get from the map than call isPrimitive...
//if (!parm.isPrimitive()) return parm;
- Class<?>[] prim = CONVERTIBLES.get(parm);
+ final Class<?>[] prim = CONVERTIBLES.get(parm);
return prim == null ? parm : prim[0];
}
@@ -305,7 +305,7 @@
* @param args the classes
* @return the array
*/
- private static Class<?>[] asArray(Class<?>... args) {
+ private static Class<?>[] asArray(final Class<?>... args) {
return args;
}
@@ -365,7 +365,7 @@
* @return true if compatible, false otherwise
*/
private static boolean isInvocationConvertible(
- Class<?> formal, Class<?> actual, boolean strict, boolean possibleVarArg) {
+ final Class<?> formal, Class<?> actual, final boolean strict, final boolean possibleVarArg) {
/* if it's a null, it means the arg was null */
if (actual == null && !formal.isPrimitive()) {
return true;
@@ -380,9 +380,9 @@
}
/* Primitive conversion check. */
if (formal.isPrimitive()) {
- Class<?>[] clist = strict ? STRICT_CONVERTIBLES.get(formal) : CONVERTIBLES.get(formal);
+ final Class<?>[] clist = strict ? STRICT_CONVERTIBLES.get(formal) : CONVERTIBLES.get(formal);
if (clist != null) {
- for (Class<?> aClass : clist) {
+ for (final Class<?> aClass : clist) {
if (actual == aClass) {
return true;
}
@@ -428,7 +428,7 @@
* A severe or not ambiguous exception.
* @param flag logging flag
*/
- AmbiguousException(boolean flag) {
+ AmbiguousException(final boolean flag) {
this.severe = flag;
}
@@ -482,9 +482,9 @@
* @return the most specific method.
* @throws MethodKey.AmbiguousException if there is more than one.
*/
- private T getMostSpecific(MethodKey key, T[] methods) {
+ private T getMostSpecific(final MethodKey key, final T[] methods) {
final Class<?>[] args = key.params;
- LinkedList<T> applicables = getApplicables(methods, args);
+ final LinkedList<T> applicables = getApplicables(methods, args);
if (applicables.isEmpty()) {
return null;
}
@@ -498,13 +498,13 @@
* the end of the below loop, the list will contain exactly one method,
* (the most specific method) otherwise we have ambiguity.
*/
- LinkedList<T> maximals = new LinkedList<T>();
- for (T app : applicables) {
+ final LinkedList<T> maximals = new LinkedList<T>();
+ for (final T app : applicables) {
final Class<?>[] parms = getParameterTypes(app);
boolean lessSpecific = false;
- Iterator<T> maximal = maximals.iterator();
+ final Iterator<T> maximal = maximals.iterator();
while(!lessSpecific && maximal.hasNext()) {
- T max = maximal.next();
+ final T max = maximal.next();
switch (moreSpecific(args, parms, getParameterTypes(max))) {
case MORE_SPECIFIC:
/*
@@ -560,17 +560,17 @@
* @param applicables the list of applicable methods or constructors
* @return an ambiguous exception
*/
- private AmbiguousException ambiguousException (Class<?>[] classes, List<T> applicables) {
+ private AmbiguousException ambiguousException (final Class<?>[] classes, final List<T> applicables) {
boolean severe = false;
int instanceArgCount = 0; // count the number of valid instances, aka not null
for(int c = 0; c < classes.length; ++c) {
- Class<?> argClazz = classes[c];
+ final Class<?> argClazz = classes[c];
if (Void.class.equals(argClazz)) {
// count the number of methods for which the current arg maps to an Object parameter
int objectParmCount = 0;
- for (T app : applicables) {
- Class<?>[] parmClasses = getParameterTypes(app);
- Class<?> parmClass = parmClasses[c];
+ for (final T app : applicables) {
+ final Class<?>[] parmClasses = getParameterTypes(app);
+ final Class<?> parmClass = parmClasses[c];
if (Object.class.equals(parmClass)) {
if (objectParmCount++ == 2) {
severe = true;
@@ -618,7 +618,7 @@
// ok, move on and compare those of equal lengths
for (int i = 0; i < length; ++i) {
if (c1[i] != c2[i]) {
- boolean last = (i == ultimate);
+ final boolean last = (i == ultimate);
// argument is null, prefer an Object param
if (a[i] == Void.class) {
if (c1[i] == Object.class && c2[i] != Object.class) {
@@ -653,12 +653,12 @@
* @param possibleVarArg true if this is the last parameter which can be a primitive array (vararg call)
* @return true if primitive, false otherwise
*/
- private boolean isPrimitive(Class<?> c, boolean possibleVarArg) {
+ private boolean isPrimitive(final Class<?> c, final boolean possibleVarArg) {
if (c != null) {
if (c.isPrimitive()) {
return true;
} else if (possibleVarArg) {
- Class<?> t = c.getComponentType();
+ final Class<?> t = c.getComponentType();
return t != null && t.isPrimitive();
}
}
@@ -674,9 +674,9 @@
* formal and actual arguments matches, and argument types are assignable
* to formal types through a method invocation conversion).
*/
- private LinkedList<T> getApplicables(T[] methods, Class<?>[] classes) {
- LinkedList<T> list = new LinkedList<T>();
- for (T method : methods) {
+ private LinkedList<T> getApplicables(final T[] methods, final Class<?>[] classes) {
+ final LinkedList<T> list = new LinkedList<T>();
+ for (final T method : methods) {
if (isApplicable(method, classes)) {
list.add(method);
}
@@ -692,8 +692,8 @@
* @param actuals arguments signature for method
* @return true if method is applicable to arguments
*/
- private boolean isApplicable(T method, Class<?>[] actuals) {
- Class<?>[] formals = getParameterTypes(method);
+ private boolean isApplicable(final T method, final Class<?>[] actuals) {
+ final Class<?>[] formals = getParameterTypes(method);
// if same number or args or
// there's just one more methodArg than class arg
// and the last methodArg is an array, then treat it as a vararg
@@ -745,7 +745,7 @@
}
// check that all remaining arguments are convertible to the vararg type
// (last parm is an array since method is vararg)
- Class<?> vararg = formals[formals.length - 1].getComponentType();
+ final Class<?> vararg = formals[formals.length - 1].getComponentType();
for (int i = formals.length - 1; i < actuals.length; ++i) {
if (!isConvertible(vararg, actuals[i], false)) {
return false;
@@ -766,7 +766,7 @@
* in the method declaration
* @return see isMethodInvocationConvertible.
*/
- private boolean isConvertible(Class<?> formal, Class<?> actual, boolean possibleVarArg) {
+ private boolean isConvertible(final Class<?> formal, final Class<?> actual, final boolean possibleVarArg) {
// if we see Void.class, the argument was null
return isInvocationConvertible(formal, actual.equals(Void.class) ? null : actual, possibleVarArg);
}
@@ -780,8 +780,8 @@
* in the method declaration
* @return see isStrictMethodInvocationConvertible.
*/
- private boolean isStrictConvertible(Class<?> formal, Class<?> actual,
- boolean possibleVarArg) {
+ private boolean isStrictConvertible(final Class<?> formal, final Class<?> actual,
+ final boolean possibleVarArg) {
// if we see Void.class, the argument was null
return isStrictInvocationConvertible(formal, actual.equals(Void.class) ? null : actual, possibleVarArg);
}
@@ -792,12 +792,12 @@
*/
private static final Parameters<Method> METHODS = new Parameters<Method>() {
@Override
- protected Class<?>[] getParameterTypes(Method app) {
+ protected Class<?>[] getParameterTypes(final Method app) {
return app.getParameterTypes();
}
@Override
- public boolean isVarArgs(Method app) {
+ public boolean isVarArgs(final Method app) {
return MethodKey.isVarArgs(app);
}
@@ -808,12 +808,12 @@
*/
private static final Parameters<Constructor<?>> CONSTRUCTORS = new Parameters<Constructor<?>>() {
@Override
- protected Class<?>[] getParameterTypes(Constructor<?> app) {
+ protected Class<?>[] getParameterTypes(final Constructor<?> app) {
return app.getParameterTypes();
}
@Override
- public boolean isVarArgs(Constructor<?> app) {
+ public boolean isVarArgs(final Constructor<?> app) {
return app.isVarArgs();
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/Permissions.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/Permissions.java
index 3a94f9b..aac052e 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/Permissions.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/Permissions.java
@@ -41,7 +41,7 @@
* @param pack the package
* @return true if JEXL is allowed to introspect, false otherwise
*/
- public boolean allow(Package pack) {
+ public boolean allow(final Package pack) {
if (pack != null && pack.getAnnotation(NoJexl.class) != null) {
return false;
}
@@ -54,7 +54,7 @@
* @param clazz the class to check
* @return true if JEXL is allowed to introspect, false otherwise
*/
- public boolean allow(Class<?> clazz) {
+ public boolean allow(final Class<?> clazz) {
return clazz != null && allow(clazz.getPackage()) && allow(clazz, true);
}
@@ -63,19 +63,19 @@
* @param ctor the constructor to check
* @return true if JEXL is allowed to introspect, false otherwise
*/
- public boolean allow(Constructor<?> ctor) {
+ public boolean allow(final Constructor<?> ctor) {
if (ctor == null) {
return false;
}
if (!Modifier.isPublic(ctor.getModifiers())) {
return false;
}
- Class<?> clazz = ctor.getDeclaringClass();
+ final Class<?> clazz = ctor.getDeclaringClass();
if (!allow(clazz, false)) {
return false;
}
// is ctor annotated with nojexl ?
- NoJexl nojexl = ctor.getAnnotation(NoJexl.class);
+ final NoJexl nojexl = ctor.getAnnotation(NoJexl.class);
if (nojexl != null) {
return false;
}
@@ -87,19 +87,19 @@
* @param field the field to check
* @return true if JEXL is allowed to introspect, false otherwise
*/
- public boolean allow(Field field) {
+ public boolean allow(final Field field) {
if (field == null) {
return false;
}
if (!Modifier.isPublic(field.getModifiers())) {
return false;
}
- Class<?> clazz = field.getDeclaringClass();
+ final Class<?> clazz = field.getDeclaringClass();
if (!allow(clazz, false)) {
return false;
}
// is field annotated with nojexl ?
- NoJexl nojexl = field.getAnnotation(NoJexl.class);
+ final NoJexl nojexl = field.getAnnotation(NoJexl.class);
if (nojexl != null) {
return false;
}
@@ -113,7 +113,7 @@
* @param method the method to check
* @return true if JEXL is allowed to introspect, false otherwise
*/
- public boolean allow(Method method) {
+ public boolean allow(final Method method) {
if (method == null) {
return false;
}
@@ -132,7 +132,7 @@
return false;
}
// lets walk all interfaces
- for (Class<?> inter : clazz.getInterfaces()) {
+ for (final Class<?> inter : clazz.getInterfaces()) {
if (!allow(inter, method)) {
return false;
}
@@ -156,7 +156,7 @@
* @param interf whether interfaces should be checked as well
* @return true if JEXL is allowed to introspect, false otherwise
*/
- protected boolean allow(Class<?> clazz, boolean interf) {
+ protected boolean allow(Class<?> clazz, final boolean interf) {
if (clazz == null) {
return false;
}
@@ -165,9 +165,9 @@
}
// lets walk all interfaces
if (interf) {
- for (Class<?> inter : clazz.getInterfaces()) {
+ for (final Class<?> inter : clazz.getInterfaces()) {
// is clazz annotated with nojexl ?
- NoJexl nojexl = inter.getAnnotation(NoJexl.class);
+ final NoJexl nojexl = inter.getAnnotation(NoJexl.class);
if (nojexl != null) {
return false;
}
@@ -178,7 +178,7 @@
// walk all superclasses
while (clazz != null) {
// is clazz annotated with nojexl ?
- NoJexl nojexl = clazz.getAnnotation(NoJexl.class);
+ final NoJexl nojexl = clazz.getAnnotation(NoJexl.class);
if (nojexl != null) {
return false;
}
@@ -194,11 +194,11 @@
* @param method the method
* @return true if JEXL is allowed to introspect, false otherwise
*/
- protected boolean allow(Class<?> clazz, Method method) {
+ protected boolean allow(final Class<?> clazz, final Method method) {
if (clazz != null) {
try {
// check if method in that class is different from the method argument
- Method wmethod = clazz.getMethod(method.getName(), method.getParameterTypes());
+ final Method wmethod = clazz.getMethod(method.getName(), method.getParameterTypes());
if (wmethod != null) {
NoJexl nojexl = clazz.getAnnotation(NoJexl.class);
if (nojexl != null) {
@@ -210,10 +210,10 @@
return false;
}
}
- } catch (NoSuchMethodException ex) {
+ } catch (final NoSuchMethodException ex) {
// unexpected, return no
return true;
- } catch (SecurityException ex) {
+ } catch (final SecurityException ex) {
// unexpected, cant do much
return false;
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertyGetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertyGetExecutor.java
index a3fc6d9..a1329ce 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertyGetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertyGetExecutor.java
@@ -38,8 +38,8 @@
* @param property the property name to find
* @return the executor if found, null otherwise
*/
- public static PropertyGetExecutor discover(Introspector is, Class<?> clazz, String property) {
- java.lang.reflect.Method method = discoverGet(is, "get", clazz, property);
+ public static PropertyGetExecutor discover(final Introspector is, final Class<?> clazz, final String property) {
+ final java.lang.reflect.Method method = discoverGet(is, "get", clazz, property);
return method == null? null : new PropertyGetExecutor(clazz, method, property);
}
@@ -49,7 +49,7 @@
* @param method the method held by this executor
* @param identifier the property to get
*/
- private PropertyGetExecutor(Class<?> clazz, java.lang.reflect.Method method, String identifier) {
+ private PropertyGetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final String identifier) {
super(clazz, method);
property = identifier;
}
@@ -60,12 +60,12 @@
}
@Override
- public Object invoke(Object o) throws IllegalAccessException, InvocationTargetException {
+ public Object invoke(final Object o) throws IllegalAccessException, InvocationTargetException {
return method == null ? null : method.invoke(o, (Object[]) null);
}
@Override
- public Object tryInvoke(Object o, Object identifier) {
+ public Object tryInvoke(final Object o, final Object identifier) {
if (o != null && method != null
&& property.equals(castString(identifier))
&& objectClass.equals(o.getClass())) {
@@ -73,7 +73,7 @@
return method.invoke(o, (Object[]) null);
} catch (IllegalAccessException | IllegalArgumentException xill) {
return TRY_FAILED;// fail
- } catch (InvocationTargetException xinvoke) {
+ } catch (final InvocationTargetException xinvoke) {
throw JexlException.tryFailed(xinvoke); // throw
}
}
@@ -88,7 +88,7 @@
* @param property The property being addressed.
* @return The {get,is}{p,P}roperty method if one exists, null otherwise.
*/
- static java.lang.reflect.Method discoverGet(Introspector is, String which, Class<?> clazz, String property) {
+ static java.lang.reflect.Method discoverGet(final Introspector is, final String which, final Class<?> clazz, final String property) {
if (property == null || property.isEmpty()) {
return null;
}
@@ -96,10 +96,10 @@
java.lang.reflect.Method method;
final int start = which.length(); // "get" or "is" so 3 or 2 for char case switch
// start with get<Property>
- StringBuilder sb = new StringBuilder(which);
+ final StringBuilder sb = new StringBuilder(which);
sb.append(property);
// uppercase nth char
- char c = sb.charAt(start);
+ final char c = sb.charAt(start);
sb.setCharAt(start, Character.toUpperCase(c));
method = is.getMethod(clazz, sb.toString(), EMPTY_PARAMS);
//lowercase nth char
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java
index f8d2004..6a09383 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/PropertySetExecutor.java
@@ -42,11 +42,11 @@
* @param value the value to assign to the property
* @return the executor if found, null otherwise
*/
- public static PropertySetExecutor discover(Introspector is, Class<?> clazz, String property, Object value) {
+ public static PropertySetExecutor discover(final Introspector is, final Class<?> clazz, final String property, final Object value) {
if (property == null || property.isEmpty()) {
return null;
}
- java.lang.reflect.Method method = discoverSet(is, clazz, property, value);
+ final java.lang.reflect.Method method = discoverSet(is, clazz, property, value);
return method != null? new PropertySetExecutor(clazz, method, property, value) : null;
}
@@ -57,7 +57,7 @@
* @param key the key to use as 1st argument to the set method
* @param value the value
*/
- protected PropertySetExecutor(Class<?> clazz, java.lang.reflect.Method method, String key, Object value) {
+ protected PropertySetExecutor(final Class<?> clazz, final java.lang.reflect.Method method, final String key, final Object value) {
super(clazz, method);
property = key;
valueClass = classOf(value);
@@ -69,13 +69,13 @@
}
@Override
- public Object invoke(Object o, Object arg) throws IllegalAccessException, InvocationTargetException {
+ public Object invoke(final Object o, Object arg) throws IllegalAccessException, InvocationTargetException {
if (method != null) {
// handle the empty array case
if (isEmptyArray(arg)) {
// if array is empty but its component type is different from the method first parameter component type,
// replace argument with a new empty array instance (of the method first parameter component type)
- Class<?> componentType = method.getParameterTypes()[0].getComponentType();
+ final Class<?> componentType = method.getParameterTypes()[0].getComponentType();
if (componentType != null && !componentType.equals(arg.getClass().getComponentType())) {
arg = Array.newInstance(componentType, 0);
}
@@ -86,7 +86,7 @@
}
@Override
- public Object tryInvoke(Object o, Object identifier, Object value) {
+ public Object tryInvoke(final Object o, final Object identifier, final Object value) {
if (o != null && method != null
// ensure method name matches the property name
&& property.equals(castString(identifier))
@@ -98,7 +98,7 @@
return invoke(o, value);
} catch (IllegalAccessException | IllegalArgumentException xill) {
return TRY_FAILED;// fail
- } catch (InvocationTargetException xinvoke) {
+ } catch (final InvocationTargetException xinvoke) {
throw JexlException.tryFailed(xinvoke); // throw
}
}
@@ -110,7 +110,7 @@
* @param arg the argument
* @return true if <code>arg</code> is an empty array
*/
- private static boolean isEmptyArray(Object arg) {
+ private static boolean isEmptyArray(final Object arg) {
return (arg != null && arg.getClass().isArray() && Array.getLength(arg) == 0);
}
@@ -125,13 +125,13 @@
* @param arg the value to assign to the property
* @return the method if found, null otherwise
*/
- private static java.lang.reflect.Method discoverSet(Introspector is, Class<?> clazz, String property, Object arg) {
+ private static java.lang.reflect.Method discoverSet(final Introspector is, final Class<?> clazz, final String property, final Object arg) {
// first, we introspect for the set<identifier> setter method
- Object[] params = {arg};
- StringBuilder sb = new StringBuilder("set");
+ final Object[] params = {arg};
+ final StringBuilder sb = new StringBuilder("set");
sb.append(property);
// uppercase nth char
- char c = sb.charAt(SET_START_INDEX);
+ final char c = sb.charAt(SET_START_INDEX);
sb.setCharAt(SET_START_INDEX, Character.toUpperCase(c));
java.lang.reflect.Method method = is.getMethod(clazz, sb.toString(), params);
// lowercase nth char
@@ -160,12 +160,12 @@
* @param mname the method name to find
* @return the sole method that accepts an array as parameter
*/
- private static java.lang.reflect.Method lookupSetEmptyArray(Introspector is, final Class<?> clazz, String mname) {
+ private static java.lang.reflect.Method lookupSetEmptyArray(final Introspector is, final Class<?> clazz, final String mname) {
java.lang.reflect.Method candidate = null;
- java.lang.reflect.Method[] methods = is.getMethods(clazz, mname);
+ final java.lang.reflect.Method[] methods = is.getMethods(clazz, mname);
if (methods != null) {
- for (java.lang.reflect.Method method : methods) {
- Class<?>[] paramTypes = method.getParameterTypes();
+ for (final java.lang.reflect.Method method : methods) {
+ final Class<?>[] paramTypes = method.getParameterTypes();
if (paramTypes.length == 1 && paramTypes[0].isArray()) {
if (candidate != null) {
// because the setter method is overloaded for different parameter type,
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java
index 5fe8582..afb94a8 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/SandboxUberspect.java
@@ -54,7 +54,7 @@
}
@Override
- public void setClassLoader(ClassLoader loader) {
+ public void setClassLoader(final ClassLoader loader) {
uberspect.setClassLoader(loader);
}
@@ -84,8 +84,8 @@
@Override
public JexlMethod getMethod(final Object obj, final String method, final Object... args) {
if (obj != null && method != null) {
- Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
- String actual = sandbox.execute(clazz, method);
+ final Class<?> clazz = (obj instanceof Class) ? (Class<?>) obj : obj.getClass();
+ final String actual = sandbox.execute(clazz, method);
if (actual != null) {
return uberspect.getMethod(obj, actual, args);
}
@@ -94,7 +94,7 @@
}
@Override
- public List<PropertyResolver> getResolvers(JexlOperator op, Object obj) {
+ public List<PropertyResolver> getResolvers(final JexlOperator op, final Object obj) {
return uberspect.getResolvers(op, obj);
}
@@ -108,11 +108,11 @@
final Object obj,
final Object identifier) {
if (obj != null && identifier != null) {
- String property = identifier.toString();
- String actual = sandbox.read(obj.getClass(), property);
+ final String property = identifier.toString();
+ final String actual = sandbox.read(obj.getClass(), property);
if (actual != null) {
// no transformation, strict equality: use identifier before string conversion
- Object pty = actual == property? identifier : actual;
+ final Object pty = actual == property? identifier : actual;
return uberspect.getPropertyGet(resolvers, obj, pty);
}
}
@@ -130,11 +130,11 @@
final Object identifier,
final Object arg) {
if (obj != null && identifier != null) {
- String property = identifier.toString();
- String actual = sandbox.write(obj.getClass(), property);
+ final String property = identifier.toString();
+ final String actual = sandbox.write(obj.getClass(), property);
if (actual != null) {
// no transformation, strict equality: use identifier before string conversion
- Object pty = actual == property? identifier : actual;
+ final Object pty = actual == property? identifier : actual;
return uberspect.getPropertySet(resolvers, obj, pty, arg);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java b/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java
index 7c674d6..e5a7c9a 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/introspection/Uberspect.java
@@ -77,7 +77,7 @@
* @param runtimeLogger the logger used for all logging needs
* @param sty the resolver strategy
*/
- public Uberspect(Log runtimeLogger, JexlUberspect.ResolverStrategy sty) {
+ public Uberspect(final Log runtimeLogger, final JexlUberspect.ResolverStrategy sty) {
this(runtimeLogger, sty, null);
}
@@ -87,7 +87,7 @@
* @param sty the resolver strategy
* @param perms the introspector permissions
*/
- public Uberspect(Log runtimeLogger, JexlUberspect.ResolverStrategy sty, Permissions perms) {
+ public Uberspect(final Log runtimeLogger, final JexlUberspect.ResolverStrategy sty, final Permissions perms) {
logger = runtimeLogger;
strategy = sty == null? JexlUberspect.JEXL_STRATEGY : sty;
permissions = perms;
@@ -123,7 +123,7 @@
// CSON: DoubleCheckedLocking
@Override
- public void setClassLoader(ClassLoader nloader) {
+ public void setClassLoader(final ClassLoader nloader) {
synchronized (this) {
Introspector intro = ref.get();
if (intro != null) {
@@ -153,7 +153,7 @@
* @param className the class name
* @return the class instance or null if it could not be found
*/
- public final Class<?> getClassByName(String className) {
+ public final Class<?> getClassByName(final String className) {
return base().getClassByName(className);
}
@@ -166,7 +166,7 @@
* @param key Name of the field being searched for
* @return a {@link java.lang.reflect.Field} or null if it does not exist or is not accessible
* */
- public final Field getField(Class<?> c, String key) {
+ public final Field getField(final Class<?> c, final String key) {
return base().getField(c, key);
}
@@ -175,7 +175,7 @@
* @param c the class
* @return the class field names
*/
- public final String[] getFieldNames(Class<?> c) {
+ public final String[] getFieldNames(final Class<?> c) {
return base().getFieldNames(c);
}
@@ -193,7 +193,7 @@
* @return a {@link java.lang.reflect.Method}
* or null if no unambiguous method could be found through introspection.
*/
- public final Method getMethod(Class<?> c, String name, Object[] params) {
+ public final Method getMethod(final Class<?> c, final String name, final Object[] params) {
return base().getMethod(c, new MethodKey(name, params));
}
@@ -208,7 +208,7 @@
* @return a {@link java.lang.reflect.Method}
* or null if no unambiguous method could be found through introspection.
*/
- public final Method getMethod(Class<?> c, MethodKey key) {
+ public final Method getMethod(final Class<?> c, final MethodKey key) {
return base().getMethod(c, key);
}
@@ -217,7 +217,7 @@
* @param c the class
* @return the class method names
*/
- public final String[] getMethodNames(Class<?> c) {
+ public final String[] getMethodNames(final Class<?> c) {
return base().getMethodNames(c);
}
@@ -227,22 +227,22 @@
* @param methodName the seeked methods name
* @return the array of methods
*/
- public final Method[] getMethods(Class<?> c, final String methodName) {
+ public final Method[] getMethods(final Class<?> c, final String methodName) {
return base().getMethods(c, methodName);
}
@Override
- public JexlMethod getMethod(Object obj, String method, Object... args) {
+ public JexlMethod getMethod(final Object obj, final String method, final Object... args) {
return MethodExecutor.discover(base(), obj, method, args);
}
@Override
- public List<PropertyResolver> getResolvers(JexlOperator op, Object obj) {
+ public List<PropertyResolver> getResolvers(final JexlOperator op, final Object obj) {
return strategy.apply(op, obj);
}
@Override
- public JexlPropertyGet getPropertyGet(Object obj, Object identifier) {
+ public JexlPropertyGet getPropertyGet(final Object obj, final Object identifier) {
return getPropertyGet(null, obj, identifier);
}
@@ -255,7 +255,7 @@
final Introspector is = base();
final List<PropertyResolver> r = resolvers == null? strategy.apply(null, obj) : resolvers;
JexlPropertyGet executor = null;
- for (PropertyResolver resolver : r) {
+ for (final PropertyResolver resolver : r) {
if (resolver instanceof JexlResolver) {
switch ((JexlResolver) resolver) {
case PROPERTY:
@@ -271,7 +271,7 @@
break;
case LIST:
// let's see if this is a list or array
- Integer index = AbstractExecutor.castInteger(identifier);
+ final Integer index = AbstractExecutor.castInteger(identifier);
if (index != null) {
executor = ListGetExecutor.discover(is, claz, index);
}
@@ -323,7 +323,7 @@
final Introspector is = base();
final List<PropertyResolver> actual = resolvers == null? strategy.apply(null, obj) : resolvers;
JexlPropertySet executor = null;
- for (PropertyResolver resolver : actual) {
+ for (final PropertyResolver resolver : actual) {
if (resolver instanceof JexlResolver) {
switch ((JexlResolver) resolver) {
case PROPERTY:
@@ -337,7 +337,7 @@
case LIST:
// let's see if we can convert the identifier to an int,
// if obj is an array or a list, we can still do something
- Integer index = AbstractExecutor.castInteger(identifier);
+ final Integer index = AbstractExecutor.castInteger(identifier);
if (index != null) {
executor = ListSetExecutor.discover(is, claz, identifier, arg);
}
@@ -369,7 +369,7 @@
@Override
@SuppressWarnings("unchecked")
- public Iterator<?> getIterator(Object obj) {
+ public Iterator<?> getIterator(final Object obj) {
if (obj instanceof Iterator<?>) {
return ((Iterator<?>) obj);
}
@@ -389,11 +389,11 @@
// look for an iterator() method to support the JDK5 Iterable
// interface or any user tools/DTOs that want to work in
// foreach without implementing the Collection interface
- JexlMethod it = getMethod(obj, "iterator", (Object[]) null);
+ final JexlMethod it = getMethod(obj, "iterator", (Object[]) null);
if (it != null && Iterator.class.isAssignableFrom(it.getReturnType())) {
return (Iterator<Object>) it.invoke(obj, (Object[]) null);
}
- } catch (Exception xany) {
+ } catch (final Exception xany) {
if (logger != null && logger.isDebugEnabled()) {
logger.info("unable to solve iterator()", xany);
}
@@ -402,7 +402,7 @@
}
@Override
- public JexlMethod getConstructor(Object ctorHandle, Object... args) {
+ public JexlMethod getConstructor(final Object ctorHandle, final Object... args) {
return ConstructorMethod.discover(base(), ctorHandle, args);
}
@@ -420,26 +420,26 @@
* @param theArithmetic the arithmetic instance
* @param theOverloads the overloaded operators
*/
- private ArithmeticUberspect(JexlArithmetic theArithmetic, Set<JexlOperator> theOverloads) {
+ private ArithmeticUberspect(final JexlArithmetic theArithmetic, final Set<JexlOperator> theOverloads) {
this.arithmetic = theArithmetic;
this.overloads = theOverloads;
}
@Override
- public JexlMethod getOperator(JexlOperator operator, Object... args) {
+ public JexlMethod getOperator(final JexlOperator operator, final Object... args) {
return overloads.contains(operator) && args != null
? getMethod(arithmetic, operator.getMethodName(), args)
: null;
}
@Override
- public boolean overloads(JexlOperator operator) {
+ public boolean overloads(final JexlOperator operator) {
return overloads.contains(operator);
}
}
@Override
- public JexlArithmetic.Uberspect getArithmetic(JexlArithmetic arithmetic) {
+ public JexlArithmetic.Uberspect getArithmetic(final JexlArithmetic arithmetic) {
JexlArithmetic.Uberspect jau = null;
if (arithmetic != null) {
final Class<? extends JexlArithmetic> aclass = arithmetic.getClass();
@@ -448,12 +448,12 @@
ops = EnumSet.noneOf(JexlOperator.class);
// deal only with derived classes
if (!JexlArithmetic.class.equals(aclass)) {
- for (JexlOperator op : JexlOperator.values()) {
- Method[] methods = getMethods(arithmetic.getClass(), op.getMethodName());
+ for (final JexlOperator op : JexlOperator.values()) {
+ final Method[] methods = getMethods(arithmetic.getClass(), op.getMethodName());
if (methods != null) {
mloop:
- for (Method method : methods) {
- Class<?>[] parms = method.getParameterTypes();
+ for (final Method method : methods) {
+ final Class<?>[] parms = method.getParameterTypes();
if (parms.length != op.getArity()) {
continue;
}
@@ -463,7 +463,7 @@
if (!JexlArithmetic.class.equals(method.getDeclaringClass())) {
try {
JexlArithmetic.class.getMethod(method.getName(), method.getParameterTypes());
- } catch (NoSuchMethodException xmethod) {
+ } catch (final NoSuchMethodException xmethod) {
// method was not found in JexlArithmetic; this is an operator definition
ops.add(op);
}
diff --git a/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java b/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java
index 8fd8198..5b9f6dd 100644
--- a/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java
+++ b/src/main/java/org/apache/commons/jexl3/introspection/JexlSandbox.java
@@ -96,7 +96,7 @@
* if no permission is explicitly defined for a class.
* @since 3.1
*/
- public JexlSandbox(boolean ab) {
+ public JexlSandbox(final boolean ab) {
this(ab, false, null);
}
@@ -106,7 +106,7 @@
* @param inh whether permissions on interfaces and classes are inherited (true) or not (false)
* @since 3.2
*/
- public JexlSandbox(boolean ab, boolean inh) {
+ public JexlSandbox(final boolean ab, final boolean inh) {
this(ab, inh, null);
}
@@ -115,7 +115,7 @@
* @param map the permissions map
*/
@Deprecated
- protected JexlSandbox(Map<String, Permissions> map) {
+ protected JexlSandbox(final Map<String, Permissions> map) {
this(true, false, map);
}
@@ -126,7 +126,7 @@
* @since 3.1
*/
@Deprecated
- protected JexlSandbox(boolean ab, Map<String, Permissions> map) {
+ protected JexlSandbox(final boolean ab, final Map<String, Permissions> map) {
this(ab, false, map);
}
@@ -137,7 +137,7 @@
* @param map the permissions map
* @since 3.2
*/
- protected JexlSandbox(boolean ab, boolean inh, Map<String, Permissions> map) {
+ protected JexlSandbox(final boolean ab, final boolean inh, final Map<String, Permissions> map) {
allow = ab;
inherit = inh;
sandbox = map != null? map : new HashMap<>();
@@ -148,8 +148,8 @@
*/
public JexlSandbox copy() {
// modified concurently at runtime so...
- Map<String, Permissions> map = new ConcurrentHashMap<>();
- for (Map.Entry<String, Permissions> entry : sandbox.entrySet()) {
+ final Map<String, Permissions> map = new ConcurrentHashMap<>();
+ for (final Map.Entry<String, Permissions> entry : sandbox.entrySet()) {
map.put(entry.getKey(), entry.getValue().copy());
}
return new JexlSandbox(allow, inherit, map);
@@ -160,10 +160,10 @@
* @param cname the class name
* @return the class
*/
- static Class<?> forName(String cname) {
+ static Class<?> forName(final String cname) {
try {
return Class.forName(cname);
- } catch(Exception xany) {
+ } catch(final Exception xany) {
return null;
}
}
@@ -175,7 +175,7 @@
* @param name the property name
* @return null if not allowed, the name of the property to use otherwise
*/
- public String read(Class<?> clazz, String name) {
+ public String read(final Class<?> clazz, final String name) {
return get(clazz).read().get(name);
}
@@ -187,7 +187,7 @@
* @return null if not allowed, the name of the property to use otherwise
*/
@Deprecated
- public String read(String clazz, String name) {
+ public String read(final String clazz, final String name) {
return get(clazz).read().get(name);
}
@@ -198,7 +198,7 @@
* @param name the property name
* @return null if not allowed, the name of the property to use otherwise
*/
- public String write(Class<?> clazz, String name) {
+ public String write(final Class<?> clazz, final String name) {
return get(clazz).write().get(name);
}
@@ -210,7 +210,7 @@
* @return null if not allowed, the name of the property to use otherwise
*/
@Deprecated
- public String write(String clazz, String name) {
+ public String write(final String clazz, final String name) {
return get(clazz).write().get(name);
}
@@ -221,8 +221,8 @@
* @param name the method name
* @return null if not allowed, the name of the method to use otherwise
*/
- public String execute(Class<?> clazz, String name) {
- String m = get(clazz).execute().get(name);
+ public String execute(final Class<?> clazz, final String name) {
+ final String m = get(clazz).execute().get(name);
return "".equals(name) && m != null? clazz.getName() : m;
}
@@ -234,8 +234,8 @@
* @return null if not allowed, the name of the method to use otherwise
*/
@Deprecated
- public String execute(String clazz, String name) {
- String m = get(clazz).execute().get(name);
+ public String execute(final String clazz, final String name) {
+ final String m = get(clazz).execute().get(name);
return "".equals(name) && m != null? clazz : m;
}
@@ -260,7 +260,7 @@
* @param alias the alias
* @return true if the alias was added, false if it was already present
*/
- public boolean alias(String name, String alias) {
+ public boolean alias(final String name, final String alias) {
return false;
}
@@ -270,7 +270,7 @@
* @param name the method/property name to check
* @return null if not allowed, the actual name to use otherwise
*/
- public String get(String name) {
+ public String get(final String name) {
return name;
}
@@ -287,7 +287,7 @@
*/
private static final Names ALLOW_NAMES = new Names() {
@Override
- public boolean add(String name) {
+ public boolean add(final String name) {
return false;
}
@@ -302,7 +302,7 @@
*/
private static final Names BLOCK_NAMES = new Names() {
@Override
- public boolean add(String name) {
+ public boolean add(final String name) {
return false;
}
@@ -312,7 +312,7 @@
}
@Override
- public String get(String name) {
+ public String get(final String name) {
return null;
}
};
@@ -326,13 +326,13 @@
@Override
protected Names copy() {
- AllowSet copy = new AllowSet();
+ final AllowSet copy = new AllowSet();
copy.names = names == null ? null : new HashMap<>(names);
return copy;
}
@Override
- public boolean add(String name) {
+ public boolean add(final String name) {
if (names == null) {
names = new HashMap<>();
}
@@ -340,7 +340,7 @@
}
@Override
- public boolean alias(String name, String alias) {
+ public boolean alias(final String name, final String alias) {
if (names == null) {
names = new HashMap<>();
}
@@ -348,7 +348,7 @@
}
@Override
- public String get(String name) {
+ public String get(final String name) {
return names == null ? name : names.get(name);
}
}
@@ -362,13 +362,13 @@
@Override
protected Names copy() {
- BlockSet copy = new BlockSet();
+ final BlockSet copy = new BlockSet();
copy.names = names == null ? null : new HashSet<>(names);
return copy;
}
@Override
- public boolean add(String name) {
+ public boolean add(final String name) {
if (names == null) {
names = new HashSet<>();
}
@@ -376,7 +376,7 @@
}
@Override
- public String get(String name) {
+ public String get(final String name) {
return names != null && !names.contains(name) ? name : null;
}
}
@@ -414,7 +414,7 @@
* @param writeFlag whether the write property list is allow or block
* @param executeFlag whether the method list is allow of block
*/
- Permissions(boolean inherit, boolean readFlag, boolean writeFlag, boolean executeFlag) {
+ Permissions(final boolean inherit, final boolean readFlag, final boolean writeFlag, final boolean executeFlag) {
this(inherit,
readFlag ? new AllowSet() : new BlockSet(),
writeFlag ? new AllowSet() : new BlockSet(),
@@ -429,7 +429,7 @@
* @param nwrite the write set
* @param nexecute the method set
*/
- Permissions(boolean inherit, Names nread, Names nwrite, Names nexecute) {
+ Permissions(final boolean inherit, final Names nread, final Names nwrite, final Names nexecute) {
this.read = nread != null ? nread : ALLOW_NAMES;
this.write = nwrite != null ? nwrite : ALLOW_NAMES;
this.execute = nexecute != null ? nexecute : ALLOW_NAMES;
@@ -456,8 +456,8 @@
* @param pnames the property names
* @return this instance of permissions
*/
- public Permissions read(String... pnames) {
- for (String pname : pnames) {
+ public Permissions read(final String... pnames) {
+ for (final String pname : pnames) {
read.add(pname);
}
return this;
@@ -469,8 +469,8 @@
* @param pnames the property names
* @return this instance of permissions
*/
- public Permissions write(String... pnames) {
- for (String pname : pnames) {
+ public Permissions write(final String... pnames) {
+ for (final String pname : pnames) {
write.add(pname);
}
return this;
@@ -483,8 +483,8 @@
* @param mnames the method names
* @return this instance of permissions
*/
- public Permissions execute(String... mnames) {
- for (String mname : mnames) {
+ public Permissions execute(final String... mnames) {
+ for (final String mname : mnames) {
execute.add(mname);
}
return this;
@@ -537,7 +537,7 @@
* @param executeFlag whether the executable method list is allow allow - true - or block - false -
* @return the set of permissions
*/
- public Permissions permissions(String clazz, boolean readFlag, boolean writeFlag, boolean executeFlag) {
+ public Permissions permissions(final String clazz, final boolean readFlag, final boolean writeFlag, final boolean executeFlag) {
return permissions(clazz, inherit, readFlag, writeFlag, executeFlag);
}
@@ -551,8 +551,8 @@
* @param execf whether the executable method list is allow allow - true - or block - false -
* @return the set of permissions
*/
- public Permissions permissions(String clazz, boolean inhf, boolean readf, boolean writef, boolean execf) {
- Permissions box = new Permissions(inhf, readf, writef, execf);
+ public Permissions permissions(final String clazz, final boolean inhf, final boolean readf, final boolean writef, final boolean execf) {
+ final Permissions box = new Permissions(inhf, readf, writef, execf);
sandbox.put(clazz, box);
return box;
}
@@ -564,7 +564,7 @@
* @param clazz the allowed class name
* @return the permissions instance
*/
- public Permissions allow(String clazz) {
+ public Permissions allow(final String clazz) {
return permissions(clazz, true, true, true);
}
/**
@@ -573,7 +573,7 @@
* @return the permissions instance
*/
@Deprecated
- public Permissions white(String clazz) {
+ public Permissions white(final String clazz) {
return allow(clazz);
}
@@ -584,7 +584,7 @@
* @param clazz the blocked class name
* @return the permissions instance
*/
- public Permissions block(String clazz) {
+ public Permissions block(final String clazz) {
return permissions(clazz, false, false, false);
}
@@ -594,7 +594,7 @@
* @return the permissions instance
*/
@Deprecated
- public Permissions black(String clazz) {
+ public Permissions black(final String clazz) {
return block(clazz);
}
@@ -604,11 +604,11 @@
* @param clazz the class name
* @return the defined permissions or an all-allow permission instance if none were defined
*/
- public Permissions get(String clazz) {
+ public Permissions get(final String clazz) {
if (inherit) {
return get(forName(clazz));
}
- Permissions permissions = sandbox.get(clazz);
+ final Permissions permissions = sandbox.get(clazz);
if (permissions == null) {
return allow ? ALLOW_ALL : BLOCK_ALL;
} else {
@@ -622,12 +622,12 @@
* @return the permissions
*/
@SuppressWarnings("null") // clazz can not be null since permissions would be not null and block;
- public Permissions get(Class<?> clazz) {
+ public Permissions get(final Class<?> clazz) {
Permissions permissions = clazz == null ? BLOCK_ALL : sandbox.get(clazz.getName());
if (permissions == null) {
if (inherit) {
// find first inherited interface that defines permissions
- for (Class<?> inter : clazz.getInterfaces()) {
+ for (final Class<?> inter : clazz.getInterfaces()) {
permissions = sandbox.get(inter.getName());
if (permissions != null && permissions.isInheritable()) {
break;
diff --git a/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java b/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java
index 362fca8..63d1307 100644
--- a/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java
+++ b/src/main/java/org/apache/commons/jexl3/introspection/JexlUberspect.java
@@ -97,12 +97,12 @@
CONTAINER;
@Override
- public final JexlPropertyGet getPropertyGet(JexlUberspect uber, Object obj, Object identifier) {
+ public final JexlPropertyGet getPropertyGet(final JexlUberspect uber, final Object obj, final Object identifier) {
return uber.getPropertyGet(Collections.singletonList(this), obj, identifier);
}
@Override
- public final JexlPropertySet getPropertySet(JexlUberspect uber, Object obj, Object identifier, Object arg) {
+ public final JexlPropertySet getPropertySet(final JexlUberspect uber, final Object obj, final Object identifier, final Object arg) {
return uber.getPropertySet(Collections.singletonList(this), obj, identifier, arg);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTAmbiguous.java b/src/main/java/org/apache/commons/jexl3/parser/ASTAmbiguous.java
index 7bbbb54..f5699f8 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTAmbiguous.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTAmbiguous.java
@@ -18,16 +18,16 @@
public final class ASTAmbiguous extends JexlNode {
- ASTAmbiguous(int id) {
+ ASTAmbiguous(final int id) {
super(id);
}
- ASTAmbiguous(Parser p, int id) {
+ ASTAmbiguous(final Parser p, final int id) {
super(p, id);
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTAnnotation.java b/src/main/java/org/apache/commons/jexl3/parser/ASTAnnotation.java
index be79544..a7dc457 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTAnnotation.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTAnnotation.java
@@ -22,11 +22,11 @@
public class ASTAnnotation extends JexlNode {
private String name = null;
- ASTAnnotation(int id) {
+ ASTAnnotation(final int id) {
super(id);
}
- ASTAnnotation(Parser p, int id) {
+ ASTAnnotation(final Parser p, final int id) {
super(p, id);
}
@@ -35,7 +35,7 @@
return name;
}
- void setName(String identifier) {
+ void setName(final String identifier) {
if (identifier.charAt(0) == '@') {
name = identifier.substring(1);
} else {
@@ -48,7 +48,7 @@
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTArrayLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTArrayLiteral.java
index e0d550e..abe9b34 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTArrayLiteral.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTArrayLiteral.java
@@ -25,22 +25,22 @@
/** Whether this array is constant or not. */
private boolean constant = false;
- ASTArrayLiteral(int id) {
+ ASTArrayLiteral(final int id) {
super(id);
}
- ASTArrayLiteral(Parser p, int id) {
+ ASTArrayLiteral(final Parser p, final int id) {
super(p, id);
}
@Override
public String toString() {
- Debugger dbg = new Debugger();
+ final Debugger dbg = new Debugger();
return dbg.data(this);
}
@Override
- protected boolean isConstant(boolean literal) {
+ protected boolean isConstant(final boolean literal) {
return constant;
}
@@ -48,7 +48,7 @@
public void jjtClose() {
constant = true;
for (int c = 0; c < jjtGetNumChildren() && constant; ++c) {
- JexlNode child = jjtGetChild(c);
+ final JexlNode child = jjtGetChild(c);
if (child instanceof ASTReference) {
constant = child.isConstant(true);
} else if (!child.isConstant()) {
@@ -58,7 +58,7 @@
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTBlock.java b/src/main/java/org/apache/commons/jexl3/parser/ASTBlock.java
index 2aebbce..428495c 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTBlock.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTBlock.java
@@ -21,16 +21,16 @@
*/
public class ASTBlock extends JexlLexicalNode {
- public ASTBlock(int id) {
+ public ASTBlock(final int id) {
super(id);
}
- public ASTBlock(Parser p, int id) {
+ public ASTBlock(final Parser p, final int id) {
super(p, id);
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTForeachStatement.java b/src/main/java/org/apache/commons/jexl3/parser/ASTForeachStatement.java
index d9683e9..4520a81 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTForeachStatement.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTForeachStatement.java
@@ -21,16 +21,16 @@
*/
public class ASTForeachStatement extends JexlLexicalNode {
- public ASTForeachStatement(int id) {
+ public ASTForeachStatement(final int id) {
super(id);
}
- public ASTForeachStatement(Parser p, int id) {
+ public ASTForeachStatement(final Parser p, final int id) {
super(p, id);
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifier.java b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifier.java
index 0848306..2d03d3c 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifier.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifier.java
@@ -31,11 +31,11 @@
/** The captured variable flag. */
private static final int CAPTURED = 2;
- ASTIdentifier(int id) {
+ ASTIdentifier(final int id) {
super(id);
}
- ASTIdentifier(Parser p, int id) {
+ ASTIdentifier(final Parser p, final int id) {
super(p, id);
}
@@ -44,14 +44,14 @@
return name;
}
- void setSymbol(String identifier) {
+ void setSymbol(final String identifier) {
if (identifier.charAt(0) == '#') {
symbol = Integer.parseInt(identifier.substring(1));
}
name = identifier;
}
- void setSymbol(int r, String identifier) {
+ void setSymbol(final int r, final String identifier) {
symbol = r;
name = identifier;
}
@@ -67,7 +67,7 @@
* @param value true or false
* @return the new flags mask value
*/
- private static int set(int ordinal, int mask, boolean value) {
+ private static int set(final int ordinal, final int mask, final boolean value) {
return value? mask | (1 << ordinal) : mask & ~(1 << ordinal);
}
@@ -77,11 +77,11 @@
* @param mask the flags mask
* @return the mask value with this flag or-ed in
*/
- private static boolean isSet(int ordinal, int mask) {
+ private static boolean isSet(final int ordinal, final int mask) {
return (mask & 1 << ordinal) != 0;
}
- public void setRedefined(boolean f) {
+ public void setRedefined(final boolean f) {
flags = set(REDEFINED, flags, f);
}
@@ -89,7 +89,7 @@
return isSet(REDEFINED, flags);
}
- public void setShaded(boolean f) {
+ public void setShaded(final boolean f) {
flags = set(SHADED, flags, f);
}
@@ -97,7 +97,7 @@
return isSet(SHADED, flags);
}
- public void setCaptured(boolean f) {
+ public void setCaptured(final boolean f) {
flags = set(CAPTURED, flags, f);
}
@@ -114,7 +114,7 @@
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccess.java b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccess.java
index 9a105f5..8f8c0a2 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccess.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccess.java
@@ -24,15 +24,15 @@
private String name = null;
private Integer identifier = null;
- ASTIdentifierAccess(int id) {
+ ASTIdentifierAccess(final int id) {
super(id);
}
- ASTIdentifierAccess(Parser p, int id) {
+ ASTIdentifierAccess(final Parser p, final int id) {
super(p, id);
}
- void setIdentifier(String id) {
+ void setIdentifier(final String id) {
name = id;
identifier = parseIdentifier(id);
}
@@ -64,13 +64,13 @@
* @param id the identifier
* @return an integer or null
*/
- public static Integer parseIdentifier(String id) {
+ public static Integer parseIdentifier(final String id) {
// hand coded because the was no way to fail on leading '0's using NumberFormat
if (id != null) {
final int length = id.length();
int val = 0;
for (int i = 0; i < length; ++i) {
- char c = id.charAt(i);
+ final char c = id.charAt(i);
// leading 0s but no just 0, NaN
if (c == '0') {
if (length == 1) {
@@ -99,7 +99,7 @@
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessJxlt.java b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessJxlt.java
index e3f767d..73af177 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessJxlt.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessJxlt.java
@@ -25,11 +25,11 @@
public class ASTIdentifierAccessJxlt extends ASTIdentifierAccess {
protected JxltEngine.Expression jxltExpr;
- ASTIdentifierAccessJxlt(int id) {
+ ASTIdentifierAccessJxlt(final int id) {
super(id);
}
- ASTIdentifierAccessJxlt(Parser p, int id) {
+ ASTIdentifierAccessJxlt(final Parser p, final int id) {
super(p, id);
}
@@ -38,7 +38,7 @@
return true;
}
- public void setExpression(JxltEngine.Expression tp) {
+ public void setExpression(final JxltEngine.Expression tp) {
jxltExpr = tp;
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessSafe.java b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessSafe.java
index bd5ee34..151a14c 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessSafe.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessSafe.java
@@ -21,11 +21,11 @@
* x?.identifier .
*/
public class ASTIdentifierAccessSafe extends ASTIdentifierAccess {
- ASTIdentifierAccessSafe(int id) {
+ ASTIdentifierAccessSafe(final int id) {
super(id);
}
- ASTIdentifierAccessSafe(Parser p, int id) {
+ ASTIdentifierAccessSafe(final Parser p, final int id) {
super(p, id);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessSafeJxlt.java b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessSafeJxlt.java
index 7661981..912021d 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessSafeJxlt.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessSafeJxlt.java
@@ -21,11 +21,11 @@
* x?.`expr` .
*/
public class ASTIdentifierAccessSafeJxlt extends ASTIdentifierAccessJxlt {
- ASTIdentifierAccessSafeJxlt(int id) {
+ ASTIdentifierAccessSafeJxlt(final int id) {
super(id);
}
- ASTIdentifierAccessSafeJxlt(Parser p, int id) {
+ ASTIdentifierAccessSafeJxlt(final Parser p, final int id) {
super(p, id);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java b/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java
index e57f586..95d8cb9 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTJexlLambda.java
@@ -20,11 +20,11 @@
* Lambda (function).
*/
public final class ASTJexlLambda extends ASTJexlScript {
- ASTJexlLambda(int id) {
+ ASTJexlLambda(final int id) {
super(id);
}
- ASTJexlLambda(Parser p, int id) {
+ ASTJexlLambda(final Parser p, final int id) {
super(p, id);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java b/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java
index 7c07bff..38beed6 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTJexlScript.java
@@ -32,11 +32,11 @@
/** The script scope. */
private Scope scope = null;
- public ASTJexlScript(int id) {
+ public ASTJexlScript(final int id) {
super(id);
}
- public ASTJexlScript(Parser p, int id) {
+ public ASTJexlScript(final Parser p, final int id) {
super(p, id);
}
@@ -46,7 +46,7 @@
*/
public ASTJexlScript script() {
if (scope == null && jjtGetNumChildren() == 1 && jjtGetChild(0) instanceof ASTJexlLambda) {
- ASTJexlLambda lambda = (ASTJexlLambda) jjtGetChild(0);
+ final ASTJexlLambda lambda = (ASTJexlLambda) jjtGetChild(0);
lambda.jjtSetParent(null);
return lambda;
} else {
@@ -55,7 +55,7 @@
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
@@ -63,7 +63,7 @@
* Sets this script pragmas.
* @param thePragmas the pragmas
*/
- public void setPragmas(Map<String, Object> thePragmas) {
+ public void setPragmas(final Map<String, Object> thePragmas) {
this.pragmas = thePragmas;
}
@@ -78,7 +78,7 @@
* Sets this script features.
* @param theFeatures the features
*/
- public void setFeatures(JexlFeatures theFeatures) {
+ public void setFeatures(final JexlFeatures theFeatures) {
this.features = theFeatures;
}
@@ -93,7 +93,7 @@
* Sets this script scope.
* @param theScope the scope
*/
- public void setScope(Scope theScope) {
+ public void setScope(final Scope theScope) {
this.scope = theScope;
if (theScope != null) {
for(int a = 0; a < theScope.getArgCount(); ++a) {
@@ -115,7 +115,7 @@
* @param values the argument values
* @return the arguments array
*/
- public Frame createFrame(Frame caller, Object... values) {
+ public Frame createFrame(final Frame caller, final Object... values) {
return scope != null? scope.createFrame(caller, values) : null;
}
@@ -124,7 +124,7 @@
* @param values the argument values
* @return the arguments array
*/
- public Frame createFrame(Object... values) {
+ public Frame createFrame(final Object... values) {
return createFrame(null, values);
}
@@ -165,7 +165,7 @@
* @param symbol the symbol number
* @return true if captured, false otherwise
*/
- public boolean isCapturedSymbol(int symbol) {
+ public boolean isCapturedSymbol(final int symbol) {
return scope != null && scope.isCapturedSymbol(symbol);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java
index 93a14b6..0632a57 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java
@@ -20,15 +20,15 @@
/** The actual literal value; the inherited 'value' member may host a cached template expression. */
private String literal = null;
- ASTJxltLiteral(int id) {
+ ASTJxltLiteral(final int id) {
super(id);
}
- ASTJxltLiteral(Parser p, int id) {
+ ASTJxltLiteral(final Parser p, final int id) {
super(p, id);
}
- void setLiteral(String literal) {
+ void setLiteral(final String literal) {
this.literal = literal;
}
@@ -46,7 +46,7 @@
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTMapLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTMapLiteral.java
index 5650dbf..796e2aa 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTMapLiteral.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTMapLiteral.java
@@ -22,22 +22,22 @@
/** Whether this array is constant or not. */
private boolean constant = false;
- ASTMapLiteral(int id) {
+ ASTMapLiteral(final int id) {
super(id);
}
- ASTMapLiteral(Parser p, int id) {
+ ASTMapLiteral(final Parser p, final int id) {
super(p, id);
}
@Override
public String toString() {
- Debugger dbg = new Debugger();
+ final Debugger dbg = new Debugger();
return dbg.data(this);
}
@Override
- protected boolean isConstant(boolean literal) {
+ protected boolean isConstant(final boolean literal) {
return constant;
}
@@ -45,7 +45,7 @@
public void jjtClose() {
constant = true;
for (int c = 0; c < jjtGetNumChildren() && constant; ++c) {
- JexlNode child = jjtGetChild(c);
+ final JexlNode child = jjtGetChild(c);
if (child instanceof ASTMapEntry) {
constant = child.isConstant(true);
} else if (!child.isConstant()) {
@@ -55,7 +55,7 @@
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTNamespaceIdentifier.java b/src/main/java/org/apache/commons/jexl3/parser/ASTNamespaceIdentifier.java
index 698fbd9..7809774 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTNamespaceIdentifier.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTNamespaceIdentifier.java
@@ -22,7 +22,7 @@
public class ASTNamespaceIdentifier extends ASTIdentifier {
private String namespace;
- public ASTNamespaceIdentifier(int id) {
+ public ASTNamespaceIdentifier(final int id) {
super(id);
}
@@ -37,7 +37,7 @@
* @param ns the namespace
* @param id the names
*/
- public void setNamespace(String ns, String id) {
+ public void setNamespace(final String ns, final String id) {
this.namespace = ns;
this.name = id;
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTNumberLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTNumberLiteral.java
index d5b614d..6c8b981 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTNumberLiteral.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTNumberLiteral.java
@@ -19,12 +19,12 @@
public final class ASTNumberLiteral extends JexlNode implements JexlNode.Constant<Number> {
private final NumberParser nlp;
- ASTNumberLiteral(int id) {
+ ASTNumberLiteral(final int id) {
super(id);
nlp = new NumberParser();
}
- ASTNumberLiteral(Parser p, int id) {
+ ASTNumberLiteral(final Parser p, final int id) {
super(p, id);
nlp = new NumberParser();
}
@@ -40,7 +40,7 @@
}
@Override
- protected boolean isConstant(boolean literal) {
+ protected boolean isConstant(final boolean literal) {
return true;
}
@@ -57,7 +57,7 @@
* Originally from OGNL.
* @param s the natural as string
*/
- void setNatural(String s) {
+ void setNatural(final String s) {
nlp.setNatural(s);
}
@@ -66,12 +66,12 @@
* Originally from OGNL.
* @param s the real as string
*/
- void setReal(String s) {
+ void setReal(final String s) {
nlp.setReal(s);
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTReferenceExpression.java b/src/main/java/org/apache/commons/jexl3/parser/ASTReferenceExpression.java
index 608b179..3822c5a 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTReferenceExpression.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTReferenceExpression.java
@@ -17,17 +17,17 @@
package org.apache.commons.jexl3.parser;
public final class ASTReferenceExpression extends JexlNode {
- ASTReferenceExpression(int id) {
+ ASTReferenceExpression(final int id) {
super(id);
}
- ASTReferenceExpression(Parser p, int id) {
+ ASTReferenceExpression(final Parser p, final int id) {
super(p, id);
}
/** Accept the visitor. **/
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTRegexLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTRegexLiteral.java
index 75ce44f..f592f25 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTRegexLiteral.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTRegexLiteral.java
@@ -24,11 +24,11 @@
private Pattern literal = null;
- ASTRegexLiteral(int id) {
+ ASTRegexLiteral(final int id) {
super(id);
}
- ASTRegexLiteral(Parser p, int id) {
+ ASTRegexLiteral(final Parser p, final int id) {
super(p, id);
}
@@ -47,16 +47,16 @@
}
@Override
- protected boolean isConstant(boolean literal) {
+ protected boolean isConstant(final boolean literal) {
return true;
}
- void setLiteral(String literal) {
+ void setLiteral(final String literal) {
this.literal = Pattern.compile(literal);
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTSetLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTSetLiteral.java
index 4db2395..64ff0f2 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTSetLiteral.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTSetLiteral.java
@@ -22,22 +22,22 @@
/** Whether this set is constant or not. */
private boolean constant = false;
- ASTSetLiteral(int id) {
+ ASTSetLiteral(final int id) {
super(id);
}
- ASTSetLiteral(Parser p, int id) {
+ ASTSetLiteral(final Parser p, final int id) {
super(p, id);
}
@Override
public String toString() {
- Debugger dbg = new Debugger();
+ final Debugger dbg = new Debugger();
return dbg.data(this);
}
@Override
- protected boolean isConstant(boolean literal) {
+ protected boolean isConstant(final boolean literal) {
return constant;
}
@@ -45,7 +45,7 @@
public void jjtClose() {
constant = true;
for (int c = 0; c < jjtGetNumChildren() && constant; ++c) {
- JexlNode child = jjtGetChild(c);
+ final JexlNode child = jjtGetChild(c);
if (!child.isConstant()) {
constant = false;
}
@@ -53,7 +53,7 @@
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTStringLiteral.java b/src/main/java/org/apache/commons/jexl3/parser/ASTStringLiteral.java
index 4898dbe..048bbdb 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTStringLiteral.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTStringLiteral.java
@@ -20,11 +20,11 @@
/** The actual literal value; the inherited 'value' member may host a cached getter. */
private String literal = null;
- ASTStringLiteral(int id) {
+ ASTStringLiteral(final int id) {
super(id);
}
- ASTStringLiteral(Parser p, int id) {
+ ASTStringLiteral(final Parser p, final int id) {
super(p, id);
}
@@ -43,16 +43,16 @@
}
@Override
- protected boolean isConstant(boolean literal) {
+ protected boolean isConstant(final boolean literal) {
return true;
}
- void setLiteral(String literal) {
+ void setLiteral(final String literal) {
this.literal = literal;
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTVar.java b/src/main/java/org/apache/commons/jexl3/parser/ASTVar.java
index 6fbcb2d..c6ef66d 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ASTVar.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ASTVar.java
@@ -20,16 +20,16 @@
* Declares a local variable.
*/
public class ASTVar extends ASTIdentifier {
- public ASTVar(int id) {
+ public ASTVar(final int id) {
super(id);
}
- public ASTVar(Parser p, int id) {
+ public ASTVar(final Parser p, final int id) {
super(p, id);
}
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/FeatureController.java b/src/main/java/org/apache/commons/jexl3/parser/FeatureController.java
index e40192d..8e24c9a 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/FeatureController.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/FeatureController.java
@@ -30,7 +30,7 @@
/**
* Creates a features controller .
*/
- public FeatureController(JexlFeatures features) {
+ public FeatureController(final JexlFeatures features) {
this.features = features;
}
@@ -38,7 +38,7 @@
* Sets the features to controlNode.
* @param fdesc the features
*/
- public void setFeatures(JexlFeatures fdesc) {
+ public void setFeatures(final JexlFeatures fdesc) {
this.features = fdesc;
}
@@ -55,12 +55,12 @@
* @param node the node to controlNode
* @throws JexlException.Feature if required feature is disabled
*/
- public void controlNode(JexlNode node) {
+ public void controlNode(final JexlNode node) {
node.jjtAccept(this, null);
}
@Override
- protected Object visitNode(JexlNode node, Object data) {
+ protected Object visitNode(final JexlNode node, final Object data) {
// no need to visit them since we close them one by one
return data;
}
@@ -70,8 +70,8 @@
* @param feature the feature code
* @param node the node that caused it
*/
- public void throwFeatureException(int feature, JexlNode node) {
- JexlInfo dbgInfo = node.jexlInfo();
+ public void throwFeatureException(final int feature, final JexlNode node) {
+ final JexlInfo dbgInfo = node.jexlInfo();
throw new JexlException.Feature(dbgInfo, feature, "");
}
@@ -80,7 +80,7 @@
* @param child the child node
* @return true if string / integer, false otherwise
*/
- private boolean isArrayReferenceLiteral(JexlNode child) {
+ private boolean isArrayReferenceLiteral(final JexlNode child) {
if (child instanceof ASTStringLiteral) {
return true;
}
@@ -91,10 +91,10 @@
}
@Override
- protected Object visit(ASTArrayAccess node, Object data) {
+ protected Object visit(final ASTArrayAccess node, final Object data) {
if (!features.supportsArrayReferenceExpr()) {
for (int i = 0; i < node.jjtGetNumChildren(); ++i) {
- JexlNode child = node.jjtGetChild(i);
+ final JexlNode child = node.jjtGetChild(i);
if (!isArrayReferenceLiteral(child)) {
throwFeatureException(JexlFeatures.ARRAY_REF_EXPR, child);
}
@@ -104,7 +104,7 @@
}
@Override
- protected Object visit(ASTWhileStatement node, Object data) {
+ protected Object visit(final ASTWhileStatement node, final Object data) {
if (!features.supportsLoops()) {
throwFeatureException(JexlFeatures.LOOP, node);
}
@@ -112,7 +112,7 @@
}
@Override
- protected Object visit(ASTDoWhileStatement node, Object data) {
+ protected Object visit(final ASTDoWhileStatement node, final Object data) {
if (!features.supportsLoops()) {
throwFeatureException(JexlFeatures.LOOP, node);
}
@@ -120,7 +120,7 @@
}
@Override
- protected Object visit(ASTForeachStatement node, Object data) {
+ protected Object visit(final ASTForeachStatement node, final Object data) {
if (!features.supportsLoops()) {
throwFeatureException(JexlFeatures.LOOP, node);
}
@@ -128,7 +128,7 @@
}
@Override
- protected Object visit(ASTConstructorNode node, Object data) {
+ protected Object visit(final ASTConstructorNode node, final Object data) {
if (!features.supportsNewInstance()) {
throwFeatureException(JexlFeatures.NEW_INSTANCE, node);
}
@@ -136,7 +136,7 @@
}
@Override
- protected Object visit(ASTMethodNode node, Object data) {
+ protected Object visit(final ASTMethodNode node, final Object data) {
if (!features.supportsMethodCall()) {
throwFeatureException(JexlFeatures.METHOD_CALL, node);
}
@@ -144,7 +144,7 @@
}
@Override
- protected Object visit(ASTAnnotation node, Object data) {
+ protected Object visit(final ASTAnnotation node, final Object data) {
if (!features.supportsAnnotation()) {
throwFeatureException(JexlFeatures.ANNOTATION, node);
}
@@ -152,7 +152,7 @@
}
@Override
- protected Object visit(ASTArrayLiteral node, Object data) {
+ protected Object visit(final ASTArrayLiteral node, final Object data) {
if (!features.supportsStructuredLiteral()) {
throwFeatureException(JexlFeatures.STRUCTURED_LITERAL, node);
}
@@ -160,7 +160,7 @@
}
@Override
- protected Object visit(ASTMapLiteral node, Object data) {
+ protected Object visit(final ASTMapLiteral node, final Object data) {
if (!features.supportsStructuredLiteral()) {
throwFeatureException(JexlFeatures.STRUCTURED_LITERAL, node);
}
@@ -168,7 +168,7 @@
}
@Override
- protected Object visit(ASTSetLiteral node, Object data) {
+ protected Object visit(final ASTSetLiteral node, final Object data) {
if (!features.supportsStructuredLiteral()) {
throwFeatureException(JexlFeatures.STRUCTURED_LITERAL, node);
}
@@ -176,15 +176,15 @@
}
@Override
- protected Object visit(ASTRangeNode node, Object data) {
+ protected Object visit(final ASTRangeNode node, final Object data) {
if (!features.supportsStructuredLiteral()) {
throwFeatureException(JexlFeatures.STRUCTURED_LITERAL, node);
}
return data;
}
- private Object controlSideEffect(JexlNode node, Object data) {
- JexlNode lv = node.jjtGetChild(0);
+ private Object controlSideEffect(final JexlNode node, final Object data) {
+ final JexlNode lv = node.jjtGetChild(0);
if (!features.supportsSideEffectGlobal() && lv.isGlobalVar()) {
throwFeatureException(JexlFeatures.SIDE_EFFECT_GLOBAL, lv);
}
@@ -195,42 +195,42 @@
}
@Override
- protected Object visit(ASTAssignment node, Object data) {
+ protected Object visit(final ASTAssignment node, final Object data) {
return controlSideEffect(node, data);
}
@Override
- protected Object visit(ASTSetAddNode node, Object data) {
+ protected Object visit(final ASTSetAddNode node, final Object data) {
return controlSideEffect(node, data);
}
@Override
- protected Object visit(ASTSetMultNode node, Object data) {
+ protected Object visit(final ASTSetMultNode node, final Object data) {
return controlSideEffect(node, data);
}
@Override
- protected Object visit(ASTSetDivNode node, Object data) {
+ protected Object visit(final ASTSetDivNode node, final Object data) {
return controlSideEffect(node, data);
}
@Override
- protected Object visit(ASTSetAndNode node, Object data) {
+ protected Object visit(final ASTSetAndNode node, final Object data) {
return controlSideEffect(node, data);
}
@Override
- protected Object visit(ASTSetOrNode node, Object data) {
+ protected Object visit(final ASTSetOrNode node, final Object data) {
return controlSideEffect(node, data);
}
@Override
- protected Object visit(ASTSetXorNode node, Object data) {
+ protected Object visit(final ASTSetXorNode node, final Object data) {
return controlSideEffect(node, data);
}
@Override
- protected Object visit(ASTSetSubNode node, Object data) {
+ protected Object visit(final ASTSetSubNode node, final Object data) {
return controlSideEffect(node, data);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/JexlLexicalNode.java b/src/main/java/org/apache/commons/jexl3/parser/JexlLexicalNode.java
index 448613a..2bf03a9 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/JexlLexicalNode.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/JexlLexicalNode.java
@@ -25,16 +25,16 @@
public class JexlLexicalNode extends JexlNode implements JexlParser.LexicalUnit {
private LexicalScope locals = null;
- public JexlLexicalNode(int id) {
+ public JexlLexicalNode(final int id) {
super(id);
}
- public JexlLexicalNode(Parser p, int id) {
+ public JexlLexicalNode(final Parser p, final int id) {
super(p, id);
}
@Override
- public boolean declareSymbol(int symbol) {
+ public boolean declareSymbol(final int symbol) {
if (locals == null) {
locals = new LexicalScope();
}
@@ -47,7 +47,7 @@
}
@Override
- public boolean hasSymbol(int symbol) {
+ public boolean hasSymbol(final int symbol) {
return locals != null && locals.hasSymbol(symbol);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java b/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java
index f085182..f2458d3 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/JexlNode.java
@@ -38,21 +38,21 @@
T getLiteral();
}
- public JexlNode(int id) {
+ public JexlNode(final int id) {
super(id);
}
- public JexlNode(Parser p, int id) {
+ public JexlNode(final Parser p, final int id) {
super(p, id);
}
- public void jjtSetFirstToken(Token t) {
+ public void jjtSetFirstToken(final Token t) {
// 0xc = 12, 12 bits -> 4096
// 0xfff, 12 bits mask
this.lc = (t.beginLine << 0xc) | (0xfff & t.beginColumn);
}
- public void jjtSetLastToken(Token t) {
+ public void jjtSetLastToken(final Token t) {
// nothing
}
@@ -80,8 +80,8 @@
node = node.jjtGetParent();
}
if (lc >= 0) {
- int c = lc & 0xfff;
- int l = lc >> 0xc;
+ final int c = lc & 0xfff;
+ final int l = lc >> 0xc;
// at least an info with line/column number
return info != null? info.at(l, c) : new JexlInfo(null, l, c);
} else {
@@ -124,17 +124,17 @@
return isConstant(this instanceof JexlNode.Constant<?>);
}
- protected boolean isConstant(boolean literal) {
+ protected boolean isConstant(final boolean literal) {
if (literal) {
for (int n = 0; n < jjtGetNumChildren(); ++n) {
- JexlNode child = jjtGetChild(n);
+ final JexlNode child = jjtGetChild(n);
if (child instanceof ASTReference) {
- boolean is = child.isConstant(true);
+ final boolean is = child.isConstant(true);
if (!is) {
return false;
}
} else if (child instanceof ASTMapEntry) {
- boolean is = child.isConstant(true);
+ final boolean is = child.isConstant(true);
if (!is) {
return false;
}
@@ -159,7 +159,7 @@
|| walk instanceof ASTArrayAccess) {
return true;
}
- int nc = walk.jjtGetNumChildren() - 1;
+ final int nc = walk.jjtGetNumChildren() - 1;
if (nc >= 0) {
walk = walk.jjtGetChild(nc);
} else {
@@ -179,9 +179,9 @@
if (this instanceof ASTIdentifier) {
return ((ASTIdentifier) this).getSymbol() < 0;
}
- int nc = this.jjtGetNumChildren() - 1;
+ final int nc = this.jjtGetNumChildren() - 1;
if (nc >= 0) {
- JexlNode first = this.jjtGetChild(0);
+ final JexlNode first = this.jjtGetChild(0);
return first.isGlobalVar();
}
if (jjtGetParent() instanceof ASTReference) {
@@ -204,7 +204,7 @@
* @param safe whether the engine is in safe-navigation mode
* @return true if safe lhs, false otherwise
*/
- public boolean isSafeLhs(boolean safe) {
+ public boolean isSafeLhs(final boolean safe) {
if (this instanceof ASTReference) {
return jjtGetChild(0).isSafeLhs(safe);
}
@@ -215,15 +215,15 @@
return true;
}
}
- JexlNode parent = this.jjtGetParent();
+ final JexlNode parent = this.jjtGetParent();
if (parent == null) {
return false;
}
// find this node in its parent
- int nsiblings = parent.jjtGetNumChildren();
+ final int nsiblings = parent.jjtGetNumChildren();
int rhs = -1;
for(int s = 0; s < nsiblings; ++s) {
- JexlNode sibling = parent.jjtGetChild(s);
+ final JexlNode sibling = parent.jjtGetChild(s);
if (sibling == this) {
// the next chid offset of this nodes parent
rhs = s + 1;
@@ -285,7 +285,7 @@
* Default ctor.
* @param jnode the node
*/
- public Info(JexlNode jnode) {
+ public Info(final JexlNode jnode) {
this(jnode, jnode.jexlInfo());
}
@@ -294,7 +294,7 @@
* @param jnode the node
* @param info the
*/
- public Info(JexlNode jnode, JexlInfo info) {
+ public Info(final JexlNode jnode, final JexlInfo info) {
this(jnode, info.getName(), info.getLine(), info.getColumn());
}
@@ -305,7 +305,7 @@
* @param l the line
* @param c the column
*/
- private Info(JexlNode jnode, String name, int l, int c) {
+ private Info(final JexlNode jnode, final String name, final int l, final int c) {
super(name, l, c);
node = jnode;
}
@@ -318,7 +318,7 @@
}
@Override
- public JexlInfo at(int l, int c) {
+ public JexlInfo at(final int l, final int c) {
return new Info(node, getName(), l, c);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java b/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
index 85b21d1..2a3b17b 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java
@@ -115,7 +115,7 @@
* Cleanup.
* @param features the feature set to restore if any
*/
- protected void cleanup(JexlFeatures features) {
+ protected void cleanup(final JexlFeatures features) {
info = null;
source = null;
frame = null;
@@ -131,10 +131,10 @@
* @param lstr the list of strings
* @return the dotted version
*/
- protected static String stringify(List<String> lstr) {
- StringBuilder strb = new StringBuilder();
+ protected static String stringify(final List<String> lstr) {
+ final StringBuilder strb = new StringBuilder();
boolean dot = false;
- for(String str : lstr) {
+ for(final String str : lstr) {
if (!dot) {
dot = true;
} else {
@@ -151,15 +151,15 @@
* @param lineno the line number
* @return the line
*/
- protected static String readSourceLine(String src, int lineno) {
+ protected static String readSourceLine(final String src, final int lineno) {
String msg = "";
if (src != null && lineno >= 0) {
try {
- BufferedReader reader = new BufferedReader(new StringReader(src));
+ final BufferedReader reader = new BufferedReader(new StringReader(src));
for (int l = 0; l < lineno; ++l) {
msg = reader.readLine();
}
- } catch (IOException xio) {
+ } catch (final IOException xio) {
// ignore, very unlikely but then again...
}
}
@@ -170,7 +170,7 @@
* Internal, for debug purpose only.
* @param registers whether register syntax is recognized by this parser
*/
- public void allowRegisters(boolean registers) {
+ public void allowRegisters(final boolean registers) {
featureController.setFeatures(new JexlFeatures(featureController.getFeatures()).register(registers));
}
@@ -178,7 +178,7 @@
* Sets a new set of options.
* @param features
*/
- protected void setFeatures(JexlFeatures features) {
+ protected void setFeatures(final JexlFeatures features) {
this.featureController.setFeatures(features);
}
@@ -237,7 +237,7 @@
* Pushes a new lexical unit.
* @param unit the new lexical unit
*/
- protected void pushUnit(LexicalUnit unit) {
+ protected void pushUnit(final LexicalUnit unit) {
if (block != null) {
blocks.push(block);
}
@@ -248,7 +248,7 @@
* Restores the previous lexical unit.
* @param unit restores the previous lexical scope
*/
- protected void popUnit(LexicalUnit unit) {
+ protected void popUnit(final LexicalUnit unit) {
if (block == unit){
if (!blocks.isEmpty()) {
block = blocks.pop();
@@ -265,11 +265,11 @@
* @param symbol
* @return true if symbol accessible in lexical scope
*/
- private boolean isSymbolDeclared(JexlNode.Info info, int symbol) {
+ private boolean isSymbolDeclared(final JexlNode.Info info, final int symbol) {
JexlNode walk = info.getNode();
while(walk != null) {
if (walk instanceof JexlParser.LexicalUnit) {
- LexicalScope scope = ((JexlParser.LexicalUnit) walk).getLexicalScope();
+ final LexicalScope scope = ((JexlParser.LexicalUnit) walk).getLexicalScope();
if (scope != null && scope.hasSymbol(symbol)) {
return true;
}
@@ -289,9 +289,9 @@
* @param name the identifier name
* @return the image
*/
- protected String checkVariable(ASTIdentifier identifier, String name) {
+ protected String checkVariable(final ASTIdentifier identifier, final String name) {
if (frame != null) {
- Integer symbol = frame.getSymbol(name);
+ final Integer symbol = frame.getSymbol(name);
if (symbol != null) {
boolean declared = true;
if (frame.isCapturedSymbol(symbol)) {
@@ -301,7 +301,7 @@
declared = block.hasSymbol(symbol);
// one of the lexical blocks above should declare it
if (!declared) {
- for (LexicalUnit u : blocks) {
+ for (final LexicalUnit u : blocks) {
if (u.hasSymbol(symbol)) {
declared = true;
break;
@@ -330,8 +330,8 @@
* @param image the name
* @return true if allowed, false if reserved
*/
- protected boolean allowVariable(String image) {
- JexlFeatures features = getFeatures();
+ protected boolean allowVariable(final String image) {
+ final JexlFeatures features = getFeatures();
if (!features.supportsLocalVar()) {
return false;
}
@@ -347,9 +347,9 @@
* @return true if symbol can be declared in lexical scope, false (error)
* if it is already declared
*/
- private boolean declareSymbol(int symbol) {
+ private boolean declareSymbol(final int symbol) {
if (blocks != null) {
- for (LexicalUnit lu : blocks) {
+ for (final LexicalUnit lu : blocks) {
if (lu.hasSymbol(symbol)) {
return false;
}
@@ -368,15 +368,15 @@
* @param var the identifier used to declare
* @param token the variable name toekn
*/
- protected void declareVariable(ASTVar var, Token token) {
- String name = token.image;
+ protected void declareVariable(final ASTVar var, final Token token) {
+ final String name = token.image;
if (!allowVariable(name)) {
throwFeatureException(JexlFeatures.LOCAL_VAR, token);
}
if (frame == null) {
frame = new Scope(null, (String[]) null);
}
- int symbol = frame.declareVariable(name);
+ final int symbol = frame.declareVariable(name);
var.setSymbol(symbol, name);
if (frame.isCapturedSymbol(symbol)) {
var.setCaptured(true);
@@ -396,7 +396,7 @@
* @param key the pragma key
* @param value the pragma value
*/
- protected void declarePragma(String key, Object value) {
+ protected void declarePragma(final String key, final Object value) {
if (!getFeatures().supportsPragma()) {
throwFeatureException(JexlFeatures.PRAGMA, getToken(0));
}
@@ -411,19 +411,19 @@
* <p> This method creates an new entry in the symbol map. </p>
* @param token the parameter name toekn
*/
- protected void declareParameter(Token token) {
- String identifier = token.image;
+ protected void declareParameter(final Token token) {
+ final String identifier = token.image;
if (!allowVariable(identifier)) {
throwFeatureException(JexlFeatures.LOCAL_VAR, token);
}
if (frame == null) {
frame = new Scope(null, (String[]) null);
}
- int symbol = frame.declareParameter(identifier);
+ final int symbol = frame.declareParameter(identifier);
// not sure how declaring a parameter could fail...
// lexical feature error
if (!block.declareSymbol(symbol) && getFeatures().isLexical()) {
- JexlInfo xinfo = info.at(token.beginLine, token.beginColumn);
+ final JexlInfo xinfo = info.at(token.beginLine, token.beginColumn);
throw new JexlException(xinfo, identifier + ": variable is already declared", null);
}
}
@@ -433,7 +433,7 @@
* @param top whether the identifier is beginning an l/r value
* @throws ParseException subclasses may throw this
*/
- protected void Identifier(boolean top) throws ParseException {
+ protected void Identifier(final boolean top) throws ParseException {
// Overriden by generated code
}
@@ -475,7 +475,7 @@
* Called by parser at beginning of node construction.
* @param node the node
*/
- protected void jjtreeOpenNodeScope(JexlNode node) {
+ protected void jjtreeOpenNodeScope(final JexlNode node) {
// nothing
}
@@ -486,7 +486,7 @@
* @param node the node
* @throws ParseException
*/
- protected void jjtreeCloseNodeScope(JexlNode node) throws ParseException {
+ protected void jjtreeCloseNodeScope(final JexlNode node) throws ParseException {
if (node instanceof ASTAmbiguous) {
throwAmbiguousException(node);
}
@@ -494,14 +494,14 @@
if (node instanceof ASTJexlLambda && !getFeatures().supportsLambda()) {
throwFeatureException(JexlFeatures.LAMBDA, node.jexlInfo());
}
- ASTJexlScript script = (ASTJexlScript) node;
+ final ASTJexlScript script = (ASTJexlScript) node;
// reaccess in case local variables have been declared
if (script.getScope() != frame) {
script.setScope(frame);
}
popFrame();
} else if (ASSIGN_NODES.contains(node.getClass())) {
- JexlNode lv = node.jjtGetChild(0);
+ final JexlNode lv = node.jjtGetChild(0);
if (!lv.isLeftValue()) {
throwParsingException(JexlException.Assignment.class, null);
}
@@ -515,11 +515,11 @@
* <p>Seeks the end of the ambiguous statement to recover.
* @param node the first token in ambiguous expression
*/
- protected void throwAmbiguousException(JexlNode node) {
- JexlInfo begin = node.jexlInfo();
- Token t = getToken(0);
- JexlInfo end = info.at(t.beginLine, t.endColumn);
- String msg = readSourceLine(source, end.getLine());
+ protected void throwAmbiguousException(final JexlNode node) {
+ final JexlInfo begin = node.jexlInfo();
+ final Token t = getToken(0);
+ final JexlInfo end = info.at(t.beginLine, t.endColumn);
+ final String msg = readSourceLine(source, end.getLine());
throw new JexlException.Ambiguous(begin, end, msg);
}
@@ -528,8 +528,8 @@
* @param feature the feature code
* @param info the exception surroundings
*/
- protected void throwFeatureException(int feature, JexlInfo info) {
- String msg = info != null? readSourceLine(source, info.getLine()) : null;
+ protected void throwFeatureException(final int feature, final JexlInfo info) {
+ final String msg = info != null? readSourceLine(source, info.getLine()) : null;
throw new JexlException.Feature(info, feature, msg);
}
@@ -538,14 +538,14 @@
* @param feature the feature code
* @param token the token that triggered it
*/
- protected void throwFeatureException(int feature, Token token) {
+ protected void throwFeatureException(final int feature, Token token) {
if (token == null) {
token = this.getToken(0);
if (token == null) {
throw new JexlException.Parsing(null, JexlFeatures.stringify(feature));
}
}
- JexlInfo xinfo = info.at(token.beginLine, token.beginColumn);
+ final JexlInfo xinfo = info.at(token.beginLine, token.beginColumn);
throwFeatureException(feature, xinfo);
}
@@ -553,7 +553,7 @@
* Throws a parsing exception.
* @param node the node that caused it
*/
- protected void throwParsingException(JexlNode node) {
+ protected void throwParsingException(final JexlNode node) {
throwParsingException(null, null);
}
@@ -563,7 +563,7 @@
* @param tok the token to report
* @param <T> the parsing exception subclass
*/
- protected <T extends JexlException.Parsing> void throwParsingException(Class<T> xclazz, Token tok) {
+ protected <T extends JexlException.Parsing> void throwParsingException(final Class<T> xclazz, Token tok) {
JexlInfo xinfo = null;
String msg = "unrecoverable state";
JexlException.Parsing xparse = null;
@@ -575,9 +575,9 @@
msg = tok.image;
if (xclazz != null) {
try {
- Constructor<T> ctor = xclazz.getConstructor(JexlInfo.class, String.class);
+ final Constructor<T> ctor = xclazz.getConstructor(JexlInfo.class, String.class);
xparse = ctor.newInstance(xinfo, msg);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
// ignore, very unlikely but then again..
}
}
@@ -591,8 +591,8 @@
* @param tokens the tokens to choose from
* @return the token
*/
- protected static Token errorToken(Token... tokens) {
- for (Token token : tokens) {
+ protected static Token errorToken(final Token... tokens) {
+ for (final Token token : tokens) {
if (token != null && token.image != null && !token.image.isEmpty()) {
return token;
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java b/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java
index 5a14188..00b7e89 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java
@@ -40,7 +40,7 @@
return BIGDF.format(literal);
}
}
- StringBuilder strb = new StringBuilder(literal.toString());
+ final StringBuilder strb = new StringBuilder(literal.toString());
if (Float.class.equals(clazz)) {
strb.append('f');
} else if (Double.class.equals(clazz)) {
@@ -66,14 +66,14 @@
return literal;
}
- static Number parseInteger(String s) {
- NumberParser np = new NumberParser();
+ static Number parseInteger(final String s) {
+ final NumberParser np = new NumberParser();
np.setNatural(s);
return np.getLiteralValue();
}
- static Number parseDouble(String s) {
- NumberParser np = new NumberParser();
+ static Number parseDouble(final String s) {
+ final NumberParser np = new NumberParser();
np.setReal(s);
return np.getLiteralValue();
}
@@ -116,10 +116,10 @@
rclass = Integer.class;
try {
result = Integer.valueOf(s, base);
- } catch (NumberFormatException take2) {
+ } catch (final NumberFormatException take2) {
try {
result = Long.valueOf(s, base);
- } catch (NumberFormatException take3) {
+ } catch (final NumberFormatException take3) {
result = new BigInteger(s, base);
}
}
@@ -134,7 +134,7 @@
* Originally from OGNL.
* @param s the real as string
*/
- void setReal(String s) {
+ void setReal(final String s) {
Number result;
Class<? extends Number> rclass;
if ("#NaN".equals(s) || "NaN".equals(s)) {
@@ -164,7 +164,7 @@
rclass = Double.class;
try {
result = Double.valueOf(s);
- } catch (NumberFormatException take3) {
+ } catch (final NumberFormatException take3) {
result = new BigDecimal(s);
}
break;
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ParseException.java b/src/main/java/org/apache/commons/jexl3/parser/ParseException.java
index c5fb6e7..1fa6e25 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ParseException.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ParseException.java
@@ -53,9 +53,9 @@
* parser within which the parse error occurred. This array is
* defined in the generated ...Constants interface.
*/
- public ParseException(Token currentToken, int[][] expectedTokenSequences, String[] tokenImage) {
+ public ParseException(final Token currentToken, final int[][] expectedTokenSequences, final String[] tokenImage) {
super("parse error");
- Token tok = currentToken.next;
+ final Token tok = currentToken.next;
after = tok.image;
line = tok.beginLine;
column = tok.beginColumn;
@@ -68,7 +68,7 @@
}
/** Constructor with message. */
- public ParseException(String message) {
+ public ParseException(final String message) {
super(message);
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/ParserVisitor.java b/src/main/java/org/apache/commons/jexl3/parser/ParserVisitor.java
index 5aa1296..876a61b 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/ParserVisitor.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/ParserVisitor.java
@@ -26,7 +26,7 @@
* @param data the data
* @return does not return
*/
- protected final Object visit(SimpleNode node, Object data) {
+ protected final Object visit(final SimpleNode node, final Object data) {
throw new UnsupportedOperationException(node.getClass().getSimpleName() + " : not supported yet.");
}
@@ -36,7 +36,7 @@
* @param data the data
* @return does not return
*/
- protected final Object visit(ASTAmbiguous node, Object data) {
+ protected final Object visit(final ASTAmbiguous node, final Object data) {
throw new UnsupportedOperationException("unexpected type of node");
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java b/src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java
index 9678be8..8945f02 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/SimpleNode.java
@@ -45,7 +45,7 @@
* Creates a SimpleNode instance.
* @param i the node type identifier
*/
- public SimpleNode(int i) {
+ public SimpleNode(final int i) {
id = i;
}
@@ -54,7 +54,7 @@
* @param p the parser instance
* @param i the node type identifier
*/
- public SimpleNode(Parser p, int i) {
+ public SimpleNode(final Parser p, final int i) {
this(i);
}
@@ -71,7 +71,7 @@
* @param n the parent
*/
@Override
- public void jjtSetParent(Node n) {
+ public void jjtSetParent(final Node n) {
parent = (JexlNode) n;
}
@@ -89,11 +89,11 @@
* @param i the child offset
*/
@Override
- public void jjtAddChild(Node n, int i) {
+ public void jjtAddChild(final Node n, final int i) {
if (children == null) {
children = new JexlNode[i + 1];
} else if (i >= children.length) {
- JexlNode[] c = new JexlNode[i + 1];
+ final JexlNode[] c = new JexlNode[i + 1];
System.arraycopy(children, 0, c, 0, children.length);
children = c;
}
@@ -101,7 +101,7 @@
}
// For use by ASTJexlScript only
- void jjtSetChildren(JexlNode[] jexlNodes) {
+ void jjtSetChildren(final JexlNode[] jexlNodes) {
children = jexlNodes;
}
@@ -111,7 +111,7 @@
* @return the child node
*/
@Override
- public JexlNode jjtGetChild(int i) {
+ public JexlNode jjtGetChild(final int i) {
return children[i];
}
@@ -127,7 +127,7 @@
/** Sets this node value.
* @param value
*/
- public void jjtSetValue(Object value) {
+ public void jjtSetValue(final Object value) {
this.value = value;
}
@@ -145,7 +145,7 @@
* @return result of visit
**/
@Override
- public Object jjtAccept(ParserVisitor visitor, Object data) {
+ public Object jjtAccept(final ParserVisitor visitor, final Object data) {
return visitor.visit(this, data);
}
@@ -155,9 +155,9 @@
* @param data contextual data
* @return result of visit
**/
- public Object childrenAccept(ParserVisitor visitor, Object data) {
+ public Object childrenAccept(final ParserVisitor visitor, final Object data) {
if (children != null) {
- for (JexlNode child : children) {
+ for (final JexlNode child : children) {
child.jjtAccept(visitor, data);
}
}
@@ -174,16 +174,16 @@
return ParserTreeConstants.jjtNodeName[id];
}
- public String toString(String prefix) {
+ public String toString(final String prefix) {
return prefix + toString();
}
/* Override this method if you want to customize how the JexlNode dumps
out its children. */
- public void dump(String prefix) {
+ public void dump(final String prefix) {
System.out.println(toString(prefix));
if (children != null) {
- for (SimpleNode n : children) {
+ for (final SimpleNode n : children) {
if (n != null) {
n.dump(prefix + " ");
}
diff --git a/src/main/java/org/apache/commons/jexl3/parser/StringParser.java b/src/main/java/org/apache/commons/jexl3/parser/StringParser.java
index 1747c1e..f86c8dd 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/StringParser.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/StringParser.java
@@ -44,11 +44,11 @@
* @param eatsep whether the separator, the first character, should be considered
* @return the built string
*/
- public static String buildString(CharSequence str, boolean eatsep) {
- StringBuilder strb = new StringBuilder(str.length());
- char sep = eatsep ? str.charAt(0) : 0;
- int end = str.length() - (eatsep ? 1 : 0);
- int begin = (eatsep ? 1 : 0);
+ public static String buildString(final CharSequence str, final boolean eatsep) {
+ final StringBuilder strb = new StringBuilder(str.length());
+ final char sep = eatsep ? str.charAt(0) : 0;
+ final int end = str.length() - (eatsep ? 1 : 0);
+ final int begin = (eatsep ? 1 : 0);
read(strb, str, begin, end, sep);
return strb.toString();
}
@@ -58,7 +58,7 @@
* @param str the string to build from
* @return the built string
*/
- public static String buildRegex(CharSequence str) {
+ public static String buildRegex(final CharSequence str) {
return buildString(str.subSequence(1, str.length()), true);
}
@@ -71,7 +71,7 @@
* @param sep the separator, single or double quote, marking end of string
* @return the offset in origin
*/
- public static int readString(StringBuilder strb, CharSequence str, int index, char sep) {
+ public static int readString(final StringBuilder strb, final CharSequence str, final int index, final char sep) {
return read(strb, str, index, str.length(), sep);
}
/** The length of an escaped unicode sequence. */
@@ -87,17 +87,17 @@
* @param sep the separator, single or double quote, marking end of string
* @return the last character offset handled in origin
*/
- private static int read(StringBuilder strb, CharSequence str, int begin, int end, char sep) {
+ private static int read(final StringBuilder strb, final CharSequence str, final int begin, final int end, final char sep) {
boolean escape = false;
int index = begin;
for (; index < end; ++index) {
- char c = str.charAt(index);
+ final char c = str.charAt(index);
if (escape) {
if (c == 'u' && (index + UCHAR_LEN) < end && readUnicodeChar(strb, str, index + 1) > 0) {
index += UCHAR_LEN;
} else {
// if c is not an escapable character, re-emmit the backslash before it
- boolean notSeparator = sep == 0 ? c != '\'' && c != '"' : c != sep;
+ final boolean notSeparator = sep == 0 ? c != '\'' && c != '"' : c != sep;
if (notSeparator && c != '\\') {
switch (c) {
// http://es5.github.io/x7.html#x7.8.4
@@ -139,12 +139,12 @@
* @param begin the begin offset in sequence (after the '\\u')
* @return 0 if char could not be read, 4 otherwise
*/
- private static int readUnicodeChar(StringBuilder strb, CharSequence str, int begin) {
+ private static int readUnicodeChar(final StringBuilder strb, final CharSequence str, final int begin) {
char xc = 0;
int bits = SHIFT;
int value = 0;
for (int offset = 0; offset < UCHAR_LEN; ++offset) {
- char c = str.charAt(begin + offset);
+ final char c = str.charAt(begin + offset);
if (c >= '0' && c <= '9') {
value = (c - '0');
} else if (c >= 'a' && c <= 'h') {
@@ -171,15 +171,15 @@
* @param str the string to escape
* @return the escaped representation
*/
- public static String escapeString(String str, char delim) {
+ public static String escapeString(final String str, final char delim) {
if (str == null) {
return null;
}
final int length = str.length();
- StringBuilder strb = new StringBuilder(length + 2);
+ final StringBuilder strb = new StringBuilder(length + 2);
strb.append(delim);
for (int i = 0; i < length; ++i) {
- char c = str.charAt(i);
+ final char c = str.charAt(i);
switch (c) {
case 0:
continue;
@@ -214,7 +214,7 @@
// convert to Unicode escape sequence
strb.append('\\');
strb.append('u');
- String hex = Integer.toHexString(c);
+ final String hex = Integer.toHexString(c);
for (int h = hex.length(); h < UCHAR_LEN; ++h) {
strb.append('0');
}
@@ -231,13 +231,13 @@
* @param str the identifier escaped string, ie with a backslash before space, quote, double-quote and backslash
* @return the string with no '\\' character
*/
- public static String unescapeIdentifier(String str) {
+ public static String unescapeIdentifier(final String str) {
StringBuilder strb = null;
if (str != null) {
int n = 0;
- int last = str.length();
+ final int last = str.length();
while (n < last) {
- char c = str.charAt(n);
+ final char c = str.charAt(n);
if (c == '\\') {
if (strb == null) {
strb = new StringBuilder(last);
@@ -257,13 +257,13 @@
* @param str the identifier un-escaped string
* @return the string with added backslash character before space, quote, double-quote and backslash
*/
- public static String escapeIdentifier(String str) {
+ public static String escapeIdentifier(final String str) {
StringBuilder strb = null;
if (str != null) {
int n = 0;
- int last = str.length();
+ final int last = str.length();
while (n < last) {
- char c = str.charAt(n);
+ final char c = str.charAt(n);
switch (c) {
case ' ':
case '\'':
diff --git a/src/main/java/org/apache/commons/jexl3/parser/TokenMgrError.java b/src/main/java/org/apache/commons/jexl3/parser/TokenMgrError.java
index 6d788d3..cfb4570 100644
--- a/src/main/java/org/apache/commons/jexl3/parser/TokenMgrError.java
+++ b/src/main/java/org/apache/commons/jexl3/parser/TokenMgrError.java
@@ -50,7 +50,7 @@
* Indicates the reason why the exception is thrown. It will have
* one of the above 4 values.
*/
- private int errorCode;
+ private final int errorCode;
/**
* The lexer state.
*/
@@ -94,13 +94,13 @@
/** Constructor with message and reason. */
- public TokenMgrError(String message, int reason) {
+ public TokenMgrError(final String message, final int reason) {
super(message);
errorCode = reason;
}
/** Full Constructor. */
- public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
+ public TokenMgrError(final boolean EOFSeen, final int lexState, final int errorLine, final int errorColumn, final String errorAfter, final char curChar, final int reason) {
eof = EOFSeen;
state = lexState;
line = errorLine;
@@ -137,8 +137,8 @@
* Replaces unprintable characters by their espaced (or unicode escaped)
* equivalents in the given string
*/
- protected static String addEscapes(String str) {
- StringBuilder retval = new StringBuilder();
+ protected static String addEscapes(final String str) {
+ final StringBuilder retval = new StringBuilder();
char ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i))
@@ -171,7 +171,7 @@
continue;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
- String s = "0000" + Integer.toString(ch, 16);
+ final String s = "0000" + Integer.toString(ch, 16);
retval.append("//u").append(s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
diff --git a/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngine.java b/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngine.java
index fdf11e2..414bd41 100644
--- a/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngine.java
+++ b/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngine.java
@@ -223,10 +223,10 @@
// This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - JexlScript Execution)
context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
try {
- JexlScript jexlScript = jexlEngine.createScript(script);
- JexlContext ctxt = new JexlContextWrapper(context);
+ final JexlScript jexlScript = jexlEngine.createScript(script);
+ final JexlContext ctxt = new JexlContextWrapper(context);
return jexlScript.execute(ctxt);
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new ScriptException(e.toString());
}
}
@@ -243,9 +243,9 @@
throw new NullPointerException("script must be non-null");
}
try {
- JexlScript jexlScript = jexlEngine.createScript(script);
+ final JexlScript jexlScript = jexlEngine.createScript(script);
return new JexlCompiledScript(jexlScript);
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new ScriptException(e.toString());
}
}
@@ -267,8 +267,8 @@
* @return the contents of the reader as a String.
* @throws ScriptException on any error reading the reader.
*/
- private static String readerToString(Reader scriptReader) throws ScriptException {
- StringBuilder buffer = new StringBuilder();
+ private static String readerToString(final Reader scriptReader) throws ScriptException {
+ final StringBuilder buffer = new StringBuilder();
BufferedReader reader;
if (scriptReader instanceof BufferedReader) {
reader = (BufferedReader) scriptReader;
@@ -281,7 +281,7 @@
buffer.append(line).append('\n');
}
return buffer.toString();
- } catch (IOException e) {
+ } catch (final IOException e) {
throw new ScriptException(e);
}
}
@@ -350,7 +350,7 @@
@Override
public boolean has(final String name) {
- Bindings bnd = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
+ final Bindings bnd = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
return bnd.containsKey(name);
}
@@ -382,9 +382,9 @@
// This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - JexlScript Execution)
context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
try {
- JexlContext ctxt = new JexlContextWrapper(context);
+ final JexlContext ctxt = new JexlContextWrapper(context);
return script.execute(ctxt);
- } catch (Exception e) {
+ } catch (final Exception e) {
throw new ScriptException(e.toString());
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngineFactory.java b/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngineFactory.java
index c306041..d95c07e 100644
--- a/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngineFactory.java
+++ b/src/main/java/org/apache/commons/jexl3/scripting/JexlScriptEngineFactory.java
@@ -63,14 +63,14 @@
}
@Override
- public String getMethodCallSyntax(String obj, String m, String... args) {
- StringBuilder sb = new StringBuilder();
+ public String getMethodCallSyntax(final String obj, final String m, final String... args) {
+ final StringBuilder sb = new StringBuilder();
sb.append(obj);
sb.append('.');
sb.append(m);
sb.append('(');
boolean needComma = false;
- for(String arg : args){
+ for(final String arg : args){
if (needComma) {
sb.append(',');
}
@@ -101,7 +101,7 @@
}
@Override
- public String getOutputStatement(String toDisplay) {
+ public String getOutputStatement(final String toDisplay) {
if (toDisplay == null) {
return "JEXL.out.print(null)";
} else {
@@ -110,7 +110,7 @@
}
@Override
- public Object getParameter(String key) {
+ public Object getParameter(final String key) {
switch (key) {
case ScriptEngine.ENGINE:
return getEngineName();
@@ -135,9 +135,9 @@
}
@Override
- public String getProgram(String... statements) {
- StringBuilder sb = new StringBuilder();
- for(String statement : statements){
+ public String getProgram(final String... statements) {
+ final StringBuilder sb = new StringBuilder();
+ for(final String statement : statements){
sb.append(statement.trim());
if (!statement.endsWith(";")){
sb.append(';');
diff --git a/src/main/java/org/apache/commons/jexl3/scripting/Main.java b/src/main/java/org/apache/commons/jexl3/scripting/Main.java
index 9504806..1cf4f85 100644
--- a/src/main/java/org/apache/commons/jexl3/scripting/Main.java
+++ b/src/main/java/org/apache/commons/jexl3/scripting/Main.java
@@ -41,7 +41,7 @@
* @return the reader
* @throws Exception if anything goes wrong
*/
- static BufferedReader read(Charset charset, String fileName) throws Exception {
+ static BufferedReader read(final Charset charset, final String fileName) throws Exception {
return new BufferedReader(
new InputStreamReader(
fileName == null
@@ -66,22 +66,22 @@
*
* @throws Exception if parsing or IO fail
*/
- public static void main(String[] args) throws Exception {
- JexlScriptEngineFactory fac = new JexlScriptEngineFactory();
- ScriptEngine engine = fac.getScriptEngine();
+ public static void main(final String[] args) throws Exception {
+ final JexlScriptEngineFactory fac = new JexlScriptEngineFactory();
+ final ScriptEngine engine = fac.getScriptEngine();
engine.put("args", args);
if (args.length == 1){
- Object value = engine.eval(read(null, args[0]));
+ final Object value = engine.eval(read(null, args[0]));
System.out.println("Return value: "+value);
} else {
- BufferedReader console = read(null, null);
+ final BufferedReader console = read(null, null);
String line;
System.out.print("> ");
while(null != (line=console.readLine())){
try {
- Object value = engine.eval(line);
+ final Object value = engine.eval(line);
System.out.println("Return value: "+value);
- } catch (ScriptException e) {
+ } catch (final ScriptException e) {
System.out.println(e.getLocalizedMessage());
}
System.out.print("> ");
diff --git a/src/test/java/org/apache/commons/jexl3/AnnotationTest.java b/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
index bac0273..2d8cd17 100644
--- a/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
+++ b/src/test/java/org/apache/commons/jexl3/AnnotationTest.java
@@ -43,9 +43,9 @@
@Test
public void test197a() throws Exception {
- JexlContext jc = new MapContext();
- JexlScript e = JEXL.createScript("@synchronized { return 42; }");
- Object r = e.execute(jc);
+ final JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("@synchronized { return 42; }");
+ final Object r = e.execute(jc);
Assert.assertEquals(42, r);
}
@@ -54,7 +54,7 @@
private final Set<String> names = new TreeSet<String>();
@Override
- public Object processAnnotation(String name, Object[] args, Callable<Object> statement) throws Exception {
+ public Object processAnnotation(final String name, final Object[] args, final Callable<Object> statement) throws Exception {
count += 1;
names.add(name);
if ("one".equals(name)) {
@@ -69,7 +69,7 @@
return null;
} else if ("synchronized".equals(name)) {
if (statement instanceof Interpreter.AnnotatedCall) {
- Object sa = ((Interpreter.AnnotatedCall) statement).getStatement();
+ final Object sa = ((Interpreter.AnnotatedCall) statement).getStatement();
if (sa != null) {
synchronized (sa) {
return statement.call();
@@ -97,34 +97,34 @@
public static class OptAnnotationContext extends JexlEvalContext implements JexlContext.AnnotationProcessor {
@Override
- public Object processAnnotation(String name, Object[] args, Callable<Object> statement) throws Exception {
- JexlOptions options = this.getEngineOptions();
+ public Object processAnnotation(final String name, final Object[] args, final Callable<Object> statement) throws Exception {
+ final JexlOptions options = this.getEngineOptions();
// transient side effect for strict
if ("strict".equals(name)) {
- boolean s = (Boolean) args[0];
- boolean b = options.isStrict();
+ final boolean s = (Boolean) args[0];
+ final boolean b = options.isStrict();
options.setStrict(s);
- Object r = statement.call();
+ final Object r = statement.call();
options.setStrict(b);
return r;
}
// transient side effect for silent
if ("silent".equals(name)) {
if (args == null || args.length == 0) {
- boolean b = options.isSilent();
+ final boolean b = options.isSilent();
try {
return statement.call();
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
return null;
} finally {
options.setSilent(b);
}
} else {
- boolean s = (Boolean) args[0];
- boolean b = options.isSilent();
+ final boolean s = (Boolean) args[0];
+ final boolean b = options.isSilent();
options.setSilent(s);
Assert.assertEquals(s, options.isSilent());
- Object r = statement.call();
+ final Object r = statement.call();
options.setSilent(b);
return r;
}
@@ -140,8 +140,8 @@
@Test
public void testVarStmt() throws Exception {
- OptAnnotationContext jc = new OptAnnotationContext();
- JexlOptions options = jc.getEngineOptions();
+ final OptAnnotationContext jc = new OptAnnotationContext();
+ final JexlOptions options = jc.getEngineOptions();
jc.getEngineOptions().set(JEXL);
options.setSharedInstance(true);
JexlScript e;
@@ -152,7 +152,7 @@
try {
r = e.execute(jc, false, true);
Assert.assertEquals(42, r);
- } catch (JexlException.Variable xjexl) {
+ } catch (final JexlException.Variable xjexl) {
Assert.fail("should not have thrown");
}
@@ -162,7 +162,7 @@
try {
r = e.execute(jc, true, false);
Assert.fail("should have thrown");
- } catch (JexlException.Variable xjexl) {
+ } catch (final JexlException.Variable xjexl) {
Assert.assertNull(r);
}
@@ -171,7 +171,7 @@
try {
r = e.execute(jc, true, true);
Assert.assertNull(r);
- } catch (JexlException.Variable xjexl) {
+ } catch (final JexlException.Variable xjexl) {
Assert.fail("should not have thrown");
}
options.setSafe(true);
@@ -181,7 +181,7 @@
try {
r = e.execute(jc, false, false);
Assert.assertEquals(42, r);
- } catch (JexlException.Variable xjexl) {
+ } catch (final JexlException.Variable xjexl) {
Assert.fail("should not have thrown");
}
//Assert.assertEquals(42, r);
@@ -195,9 +195,9 @@
@Test
public void testNoArg() throws Exception {
- AnnotationContext jc = new AnnotationContext();
- JexlScript e = JEXL.createScript("@synchronized { return 42; }");
- Object r = e.execute(jc);
+ final AnnotationContext jc = new AnnotationContext();
+ final JexlScript e = JEXL.createScript("@synchronized { return 42; }");
+ final Object r = e.execute(jc);
Assert.assertEquals(42, r);
Assert.assertEquals(1, jc.getCount());
Assert.assertTrue(jc.getNames().contains("synchronized"));
@@ -205,9 +205,9 @@
@Test
public void testNoArgExpression() throws Exception {
- AnnotationContext jc = new AnnotationContext();
- JexlScript e = JEXL.createScript("@synchronized 42");
- Object r = e.execute(jc);
+ final AnnotationContext jc = new AnnotationContext();
+ final JexlScript e = JEXL.createScript("@synchronized 42");
+ final Object r = e.execute(jc);
Assert.assertEquals(42, r);
Assert.assertEquals(1, jc.getCount());
Assert.assertTrue(jc.getNames().contains("synchronized"));
@@ -215,9 +215,9 @@
@Test
public void testNoArgStatement() throws Exception {
- AnnotationContext jc = new AnnotationContext();
- JexlScript e = JEXL.createScript("@synchronized if (true) 2 * 3 * 7; else -42;");
- Object r = e.execute(jc);
+ final AnnotationContext jc = new AnnotationContext();
+ final JexlScript e = JEXL.createScript("@synchronized if (true) 2 * 3 * 7; else -42;");
+ final Object r = e.execute(jc);
Assert.assertEquals(42, r);
Assert.assertEquals(1, jc.getCount());
Assert.assertTrue(jc.getNames().contains("synchronized"));
@@ -225,9 +225,9 @@
@Test
public void testHoistingStatement() throws Exception {
- AnnotationContext jc = new AnnotationContext();
- JexlScript e = JEXL.createScript("var t = 1; @synchronized for(var x : [2,3,7]) t *= x; t");
- Object r = e.execute(jc);
+ final AnnotationContext jc = new AnnotationContext();
+ final JexlScript e = JEXL.createScript("var t = 1; @synchronized for(var x : [2,3,7]) t *= x; t");
+ final Object r = e.execute(jc);
Assert.assertEquals(42, r);
Assert.assertEquals(1, jc.getCount());
Assert.assertTrue(jc.getNames().contains("synchronized"));
@@ -235,9 +235,9 @@
@Test
public void testOneArg() throws Exception {
- AnnotationContext jc = new AnnotationContext();
- JexlScript e = JEXL.createScript("@one(1) { return 42; }");
- Object r = e.execute(jc);
+ final AnnotationContext jc = new AnnotationContext();
+ final JexlScript e = JEXL.createScript("@one(1) { return 42; }");
+ final Object r = e.execute(jc);
Assert.assertEquals(42, r);
Assert.assertEquals(1, jc.getCount());
Assert.assertTrue(jc.getNames().contains("one"));
@@ -246,9 +246,9 @@
@Test
public void testMultiple() throws Exception {
- AnnotationContext jc = new AnnotationContext();
- JexlScript e = JEXL.createScript("@one(1) @synchronized { return 42; }");
- Object r = e.execute(jc);
+ final AnnotationContext jc = new AnnotationContext();
+ final JexlScript e = JEXL.createScript("@one(1) @synchronized { return 42; }");
+ final Object r = e.execute(jc);
Assert.assertEquals(42, r);
Assert.assertEquals(2, jc.getCount());
Assert.assertTrue(jc.getNames().contains("synchronized"));
@@ -262,19 +262,19 @@
testError(false);
}
- private void testError(boolean silent) throws Exception {
- CaptureLog log = new CaptureLog();
- AnnotationContext jc = new AnnotationContext();
- JexlEngine jexl = new JexlBuilder().logger(log).strict(true).silent(silent).create();
- JexlScript e = jexl.createScript("@error('42') { return 42; }");
+ private void testError(final boolean silent) throws Exception {
+ final CaptureLog log = new CaptureLog();
+ final AnnotationContext jc = new AnnotationContext();
+ final JexlEngine jexl = new JexlBuilder().logger(log).strict(true).silent(silent).create();
+ final JexlScript e = jexl.createScript("@error('42') { return 42; }");
try {
- Object r = e.execute(jc);
+ final Object r = e.execute(jc);
if (!silent) {
Assert.fail("should have failed");
} else {
Assert.assertEquals(1, log.count("warn"));
}
- } catch (JexlException.Annotation xjexl) {
+ } catch (final JexlException.Annotation xjexl) {
Assert.assertEquals("error", xjexl.getAnnotation());
}
Assert.assertEquals(1, jc.getCount());
@@ -291,19 +291,19 @@
testUnknown(false);
}
- private void testUnknown(boolean silent) throws Exception {
- CaptureLog log = new CaptureLog();
- AnnotationContext jc = new AnnotationContext();
- JexlEngine jexl = new JexlBuilder().logger(log).strict(true).silent(silent).create();
- JexlScript e = jexl.createScript("@unknown('42') { return 42; }");
+ private void testUnknown(final boolean silent) throws Exception {
+ final CaptureLog log = new CaptureLog();
+ final AnnotationContext jc = new AnnotationContext();
+ final JexlEngine jexl = new JexlBuilder().logger(log).strict(true).silent(silent).create();
+ final JexlScript e = jexl.createScript("@unknown('42') { return 42; }");
try {
- Object r = e.execute(jc);
+ final Object r = e.execute(jc);
if (!silent) {
Assert.fail("should have failed");
} else {
Assert.assertEquals(1, log.count("warn"));
}
- } catch (JexlException.Annotation xjexl) {
+ } catch (final JexlException.Annotation xjexl) {
Assert.assertEquals("unknown", xjexl.getAnnotation());
}
Assert.assertEquals(1, jc.getCount());
@@ -321,7 +321,7 @@
private int value = 0;
public void inc() {
- int v = value;
+ final int v = value;
// introduce some concurency
for (int i = (int) System.currentTimeMillis() % 5; i >= 0; --i) {
Thread.yield();
@@ -341,8 +341,8 @@
public final Counter syncCounter = new Counter();
public final Counter concCounter = new Counter();
- public void run(Runnable runnable) throws InterruptedException {
- ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS);
+ public void run(final Runnable runnable) throws InterruptedException {
+ final ExecutorService executor = Executors.newFixedThreadPool(NUM_THREADS);
for (int i = 0; i < NUM_THREADS; i++) {
executor.submit(runnable);
}
diff --git a/src/test/java/org/apache/commons/jexl3/AntishCallTest.java b/src/test/java/org/apache/commons/jexl3/AntishCallTest.java
index 08d7ab1..c11be20 100644
--- a/src/test/java/org/apache/commons/jexl3/AntishCallTest.java
+++ b/src/test/java/org/apache/commons/jexl3/AntishCallTest.java
@@ -38,7 +38,7 @@
*/
public static class ClassReference {
final Class<?> clazz;
- ClassReference(Class<?> c) {
+ ClassReference(final Class<?> c) {
this.clazz = c;
}
}
@@ -50,10 +50,10 @@
* @param args the constructor arguments
* @return an instance if that was possible
*/
- public static Object callConstructor(JexlEngine engine, ClassReference ref, Object... args) {
+ public static Object callConstructor(final JexlEngine engine, final ClassReference ref, final Object... args) {
return callConstructor(engine, ref.clazz, args);
}
- public static Object callConstructor(JexlEngine engine, Class<?> clazz, Object... args) {
+ public static Object callConstructor(final JexlEngine engine, final Class<?> clazz, final Object... args) {
if (clazz == null || clazz.isPrimitive() || clazz.isInterface()
|| clazz.isMemberClass() || clazz.isAnnotation() || clazz.isArray()) {
throw new ArithmeticException("not a constructible object");
@@ -72,15 +72,15 @@
* An arithmetic that considers class objects as callable.
*/
public class CallSupportArithmetic extends JexlArithmetic {
- public CallSupportArithmetic(boolean strict) {
+ public CallSupportArithmetic(final boolean strict) {
super(strict);
}
- public Object call(ClassReference clazz, Object... args) {
+ public Object call(final ClassReference clazz, final Object... args) {
return callConstructor(null, clazz, args);
}
- public Object call(Class<?> clazz, Object... args) {
+ public Object call(final Class<?> clazz, final Object... args) {
return callConstructor(null, clazz, args);
}
}
@@ -89,51 +89,51 @@
* A context that considers class references as callable.
*/
public static class CallSupportContext extends MapContext {
- CallSupportContext(Map<String, Object> map) {
+ CallSupportContext(final Map<String, Object> map) {
super(map);
}
private JexlEngine engine;
- @Override public Object get(String str) {
+ @Override public Object get(final String str) {
if (!super.has(str)) {
try {
return CallSupportContext.class.getClassLoader().loadClass(str);
- } catch(Exception xany) {
+ } catch(final Exception xany) {
return null;
}
}
return super.get(str);
}
- @Override public boolean has(String str) {
+ @Override public boolean has(final String str) {
if (!super.has(str)){
try {
return CallSupportContext.class.getClassLoader().loadClass(str) != null;
- } catch(Exception xany) {
+ } catch(final Exception xany) {
return false;
}
}
return true;
}
- CallSupportContext engine(JexlEngine j) {
+ CallSupportContext engine(final JexlEngine j) {
engine = j;
return this;
}
- public Object call(ClassReference clazz, Object... args) {
+ public Object call(final ClassReference clazz, final Object... args) {
return callConstructor(engine, clazz, args);
}
- public Object call(Class<?> clazz, Object... args) {
+ public Object call(final Class<?> clazz, final Object... args) {
return callConstructor(engine, clazz, args);
}
}
@Test
public void testAntishContextVar() throws Exception {
- Map<String,Object> lmap = new TreeMap<String,Object>();
- JexlContext jc = new CallSupportContext(lmap).engine(JEXL);
+ final Map<String,Object> lmap = new TreeMap<String,Object>();
+ final JexlContext jc = new CallSupportContext(lmap).engine(JEXL);
runTestCall(JEXL, jc);
lmap.put("java.math.BigInteger", new ClassReference(BigInteger.class));
runTestCall(JEXL, jc);
@@ -143,10 +143,10 @@
@Test
public void testAntishArithmetic() throws Exception {
- CallSupportArithmetic ja = new CallSupportArithmetic(true);
- JexlEngine jexl = new JexlBuilder().cache(512).arithmetic(ja).create();
- Map<String,Object> lmap = new TreeMap<String,Object>();
- JexlContext jc = new MapContext(lmap);
+ final CallSupportArithmetic ja = new CallSupportArithmetic(true);
+ final JexlEngine jexl = new JexlBuilder().cache(512).arithmetic(ja).create();
+ final Map<String,Object> lmap = new TreeMap<String,Object>();
+ final JexlContext jc = new MapContext(lmap);
lmap.put("java.math.BigInteger", java.math.BigInteger.class);
runTestCall(jexl, jc);
lmap.put("java.math.BigInteger", new ClassReference(BigInteger.class));
@@ -155,27 +155,27 @@
try {
runTestCall(jexl, jc);
Assert.fail("should have failed");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
//
}
}
- void runTestCall(JexlEngine jexl, JexlContext jc) throws Exception {
- JexlScript check1 = jexl.createScript("var x = java.math.BigInteger; x('1234')");
- JexlScript check2 = jexl.createScript("java.math.BigInteger('4321')");
+ void runTestCall(final JexlEngine jexl, final JexlContext jc) throws Exception {
+ final JexlScript check1 = jexl.createScript("var x = java.math.BigInteger; x('1234')");
+ final JexlScript check2 = jexl.createScript("java.math.BigInteger('4321')");
- Object o1 = check1.execute(jc);
+ final Object o1 = check1.execute(jc);
Assert.assertEquals("Result is not 1234", new java.math.BigInteger("1234"), o1);
- Object o2 = check2.execute(jc);
+ final Object o2 = check2.execute(jc);
Assert.assertEquals("Result is not 4321", new java.math.BigInteger("4321"), o2);
}
// JEXL-300
@Test
public void testSafeAnt() throws Exception {
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
ctxt.set("x.y.z", 42);
JexlScript script;
Object result;
@@ -189,9 +189,9 @@
try {
result = script.execute(ctxt);
Assert.fail("antish var shall not be resolved");
- } catch(JexlException.Variable xvar) {
+ } catch(final JexlException.Variable xvar) {
Assert.assertEquals("x", xvar.getVariable());
- } catch(JexlException xother) {
+ } catch(final JexlException xother) {
Assert.assertNotNull(xother);
} finally {
options.setAntish(true);
@@ -207,7 +207,7 @@
try {
result = script.execute(ctxt);
Assert.fail("not antish assign");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
Assert.assertNull(result);
}
@@ -216,7 +216,7 @@
try {
result = script.execute(ctxt);
Assert.fail("x not defined");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
Assert.assertNull(result);
}
@@ -225,7 +225,7 @@
try {
result = script.execute(ctxt);
Assert.fail("not antish assign");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
Assert.assertNull(result);
}
@@ -234,7 +234,7 @@
try {
result = script.execute(ctxt);
Assert.fail("not antish assign");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
Assert.assertNull(result);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java b/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
index 183b286..39084cc 100644
--- a/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
@@ -166,14 +166,14 @@
public static class MatchingContainer {
private final Set<Integer> values;
- public MatchingContainer(int[] is) {
+ public MatchingContainer(final int[] is) {
values = new HashSet<Integer>();
- for (int value : is) {
+ for (final int value : is) {
values.add(value);
}
}
- public boolean contains(int value) {
+ public boolean contains(final int value) {
return values.contains(value);
}
}
@@ -181,9 +181,9 @@
public static class IterableContainer implements Iterable<Integer> {
private final SortedSet<Integer> values;
- public IterableContainer(int[] is) {
+ public IterableContainer(final int[] is) {
values = new TreeSet<Integer>();
- for (int value : is) {
+ for (final int value : is) {
values.add(value);
}
}
@@ -193,36 +193,36 @@
return values.iterator();
}
- public boolean contains(int i) {
+ public boolean contains(final int i) {
return values.contains(i);
}
- public boolean contains(int[] i) {
+ public boolean contains(final int[] i) {
return values.containsAll(Collections.singletonList(i));
}
- public boolean startsWith(int i) {
+ public boolean startsWith(final int i) {
return values.first().equals(i);
}
- public boolean endsWith(int i) {
+ public boolean endsWith(final int i) {
return values.last().equals(i);
}
- public boolean startsWith(int[] i) {
- SortedSet<Integer> sw = values.headSet(i.length);
+ public boolean startsWith(final int[] i) {
+ final SortedSet<Integer> sw = values.headSet(i.length);
int n = 0;
- for(Integer value : sw) {
+ for(final Integer value : sw) {
if(!value.equals(i[n++])) {
return false;
}
}
return true;
}
- public boolean endsWith(int[] i) {
- SortedSet<Integer> sw = values.tailSet(values.size() - i.length);
+ public boolean endsWith(final int[] i) {
+ final SortedSet<Integer> sw = values.tailSet(values.size() - i.length);
int n = 0;
- for(Integer value : sw) {
+ for(final Integer value : sw) {
if(!value.equals(i[n++])) {
return false;
}
@@ -234,24 +234,24 @@
@Test
public void testMatch() throws Exception {
// check in/not-in on array, list, map, set and duck-type collection
- int[] ai = {2, 4, 42, 54};
- List<Integer> al = new ArrayList<Integer>();
- for (int i : ai) {
+ final int[] ai = {2, 4, 42, 54};
+ final List<Integer> al = new ArrayList<Integer>();
+ for (final int i : ai) {
al.add(i);
}
- Map<Integer, String> am = new HashMap<Integer, String>();
+ final Map<Integer, String> am = new HashMap<Integer, String>();
am.put(2, "two");
am.put(4, "four");
am.put(42, "forty-two");
am.put(54, "fifty-four");
- MatchingContainer ad = new MatchingContainer(ai);
- IterableContainer ic = new IterableContainer(ai);
- Set<Integer> as = ad.values;
- Object[] vars = {ai, al, am, ad, as, ic};
+ final MatchingContainer ad = new MatchingContainer(ai);
+ final IterableContainer ic = new IterableContainer(ai);
+ final Set<Integer> as = ad.values;
+ final Object[] vars = {ai, al, am, ad, as, ic};
- for (Object var : vars) {
+ for (final Object var : vars) {
asserter.setVariable("container", var);
- for (int x : ai) {
+ for (final int x : ai) {
asserter.setVariable("x", x);
asserter.assertExpression("x =~ container", Boolean.TRUE);
}
@@ -269,8 +269,8 @@
asserter.assertExpression("x =^ 'foo'", Boolean.FALSE);
asserter.assertExpression("x =$ 'foo'", Boolean.TRUE);
- int[] ai = {2, 4, 42, 54};
- IterableContainer ic = new IterableContainer(ai);
+ final int[] ai = {2, 4, 42, 54};
+ final IterableContainer ic = new IterableContainer(ai);
asserter.setVariable("x", ic);
asserter.assertExpression("x =^ 2", Boolean.TRUE);
asserter.assertExpression("x =$ 54", Boolean.TRUE);
@@ -289,8 +289,8 @@
asserter.assertExpression("x !^ 'foo'", Boolean.TRUE);
asserter.assertExpression("x !$ 'foo'", Boolean.FALSE);
- int[] ai = {2, 4, 42, 54};
- IterableContainer ic = new IterableContainer(ai);
+ final int[] ai = {2, 4, 42, 54};
+ final IterableContainer ic = new IterableContainer(ai);
asserter.setVariable("x", ic);
asserter.assertExpression("x !^ 2", Boolean.FALSE);
asserter.assertExpression("x !$ 54", Boolean.FALSE);
@@ -302,9 +302,9 @@
public static class Aggregate {
private Aggregate() {}
- public static int sum(Iterable<Integer> ii) {
+ public static int sum(final Iterable<Integer> ii) {
int sum = 0;
- for(Integer i : ii) {
+ for(final Integer i : ii) {
sum += i;
}
return sum;
@@ -314,9 +314,9 @@
@Test
@SuppressWarnings("unchecked")
public void testInterval() throws Exception {
- Map<String, Object> ns = new HashMap<String, Object>();
+ final Map<String, Object> ns = new HashMap<String, Object>();
ns.put("calc", Aggregate.class);
- JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
+ final JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
JexlScript script;
Object result;
@@ -351,13 +351,13 @@
}
public static class DateArithmetic extends JexlArithmetic {
- DateArithmetic(boolean flag) {
+ DateArithmetic(final boolean flag) {
super(flag);
}
- protected Object getDateValue(Date date, String key) {
+ protected Object getDateValue(final Date date, final String key) {
try {
- Calendar cal = Calendar.getInstance(UTC);
+ final Calendar cal = Calendar.getInstance(UTC);
cal.setTime(date);
if ("yyyy".equals(key)) {
return cal.get(Calendar.YEAR);
@@ -367,16 +367,16 @@
return cal.get(Calendar.DAY_OF_MONTH);
}
// Otherwise treat as format mask
- SimpleDateFormat df = new SimpleDateFormat(key);//, dfs);
+ final SimpleDateFormat df = new SimpleDateFormat(key);//, dfs);
return df.format(date);
- } catch (Exception ex) {
+ } catch (final Exception ex) {
return null;
}
}
- protected Object setDateValue(Date date, String key, Object value) throws Exception {
- Calendar cal = Calendar.getInstance(UTC);
+ protected Object setDateValue(final Date date, final String key, final Object value) throws Exception {
+ final Calendar cal = Calendar.getInstance(UTC);
cal.setTime(date);
if ("yyyy".equals(key)) {
cal.set(Calendar.YEAR, toInteger(value));
@@ -389,19 +389,19 @@
return date;
}
- public Object propertyGet(Date date, String identifier) {
+ public Object propertyGet(final Date date, final String identifier) {
return getDateValue(date, identifier);
}
- public Object propertySet(Date date, String identifier, Object value) throws Exception {
+ public Object propertySet(final Date date, final String identifier, final Object value) throws Exception {
return setDateValue(date, identifier, value);
}
- public Object arrayGet(Date date, String identifier) {
+ public Object arrayGet(final Date date, final String identifier) {
return getDateValue(date, identifier);
}
- public Object arraySet(Date date, String identifier, Object value) throws Exception {
+ public Object arraySet(final Date date, final String identifier, final Object value) throws Exception {
return setDateValue(date, identifier, value);
}
@@ -409,7 +409,7 @@
return new Date(System.currentTimeMillis());
}
- public Date multiply(Date d0, Date d1) {
+ public Date multiply(final Date d0, final Date d1) {
throw new ArithmeticException("unsupported");
}
}
@@ -417,17 +417,17 @@
public static class DateContext extends MapContext {
private Locale locale = Locale.US;
- void setLocale(Locale l10n) {
+ void setLocale(final Locale l10n) {
this.locale = l10n;
}
- public String format(Date date, String fmt) {
- SimpleDateFormat sdf = new SimpleDateFormat(fmt, locale);
+ public String format(final Date date, final String fmt) {
+ final SimpleDateFormat sdf = new SimpleDateFormat(fmt, locale);
sdf.setTimeZone(UTC);
return sdf.format(date);
}
- public String format(Number number, String fmt) {
+ public String format(final Number number, final String fmt) {
return new DecimalFormat(fmt).format(number);
}
}
@@ -438,21 +438,21 @@
testOperatorError(false);
}
- private void testOperatorError(boolean silent) throws Exception {
- CaptureLog log = new CaptureLog();
- DateContext jc = new DateContext();
- Date d = new Date();
- JexlEngine jexl = new JexlBuilder().logger(log).strict(true).silent(silent).cache(32)
+ private void testOperatorError(final boolean silent) throws Exception {
+ final CaptureLog log = new CaptureLog();
+ final DateContext jc = new DateContext();
+ final Date d = new Date();
+ final JexlEngine jexl = new JexlBuilder().logger(log).strict(true).silent(silent).cache(32)
.arithmetic(new DateArithmetic(true)).create();
- JexlScript expr0 = jexl.createScript("date * date", "date");
+ final JexlScript expr0 = jexl.createScript("date * date", "date");
try {
- Object value0 = expr0.execute(jc, d);
+ final Object value0 = expr0.execute(jc, d);
if (!silent) {
Assert.fail("should have failed");
} else {
Assert.assertEquals(1, log.count("warn"));
}
- } catch(JexlException.Operator xop) {
+ } catch(final JexlException.Operator xop) {
Assert.assertEquals("*", xop.getSymbol());
}
if (!silent) {
@@ -462,10 +462,10 @@
@Test
public void testDateArithmetic() throws Exception {
- Date d = new Date();
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().cache(32).arithmetic(new DateArithmetic(true)).create();
- JexlScript expr0 = jexl.createScript("date.yyyy = 1969; date.MM=7; date.dd=20; ", "date");
+ final Date d = new Date();
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().cache(32).arithmetic(new DateArithmetic(true)).create();
+ final JexlScript expr0 = jexl.createScript("date.yyyy = 1969; date.MM=7; date.dd=20; ", "date");
Object value0 = expr0.execute(jc, d);
Assert.assertNotNull(value0);
value0 = d;
@@ -477,20 +477,20 @@
@Test
public void testFormatArithmetic() throws Exception {
- Calendar cal = Calendar.getInstance(UTC);
+ final Calendar cal = Calendar.getInstance(UTC);
cal.set(1969, Calendar.AUGUST, 20);
- Date x0 = cal.getTime();
- String y0 = "MM/yy/dd";
- Number x1 = 42.12345;
- String y1 = "##0.##";
- DateContext jc = new DateContext();
- JexlEngine jexl = new JexlBuilder().cache(32).arithmetic(new DateArithmetic(true)).create();
- JexlScript expr0 = jexl.createScript("x.format(y)", "x", "y");
+ final Date x0 = cal.getTime();
+ final String y0 = "MM/yy/dd";
+ final Number x1 = 42.12345;
+ final String y1 = "##0.##";
+ final DateContext jc = new DateContext();
+ final JexlEngine jexl = new JexlBuilder().cache(32).arithmetic(new DateArithmetic(true)).create();
+ final JexlScript expr0 = jexl.createScript("x.format(y)", "x", "y");
Object value10 = expr0.execute(jc, x0, y0);
- Object value20 = expr0.execute(jc, x0, y0);
+ final Object value20 = expr0.execute(jc, x0, y0);
Assert.assertEquals(value10, value20);
Object value11 = expr0.execute(jc, x1, y1);
- Object value21 = expr0.execute(jc, x1, y1);
+ final Object value21 = expr0.execute(jc, x1, y1);
Assert.assertEquals(value11, value21);
value10 = expr0.execute(jc, x0, y0);
Assert.assertEquals(value10, value20);
@@ -511,25 +511,25 @@
Assert.assertEquals("mer. 20 ao\u00fbt 1969", s0);
expr1 = jexl.createScript("format(now(), y)", "y");
- Object n0 = expr1.execute(jc, y0);
+ final Object n0 = expr1.execute(jc, y0);
Assert.assertNotNull(n0);
expr1 = jexl.createScript("now().format(y)", "y");
- Object n1 = expr1.execute(jc, y0);
+ final Object n1 = expr1.execute(jc, y0);
Assert.assertNotNull(n0);
Assert.assertEquals(n0, n1);
}
@Test
public void testFormatArithmeticJxlt() throws Exception {
- Map<String, Object> ns = new HashMap<String, Object>();
+ final Map<String, Object> ns = new HashMap<String, Object>();
ns.put("calc", Aggregate.class);
- Calendar cal = Calendar.getInstance(UTC);
+ final Calendar cal = Calendar.getInstance(UTC);
cal.set(1969, Calendar.AUGUST, 20);
- Date x0 = cal.getTime();
- String y0 = "yyyy-MM-dd";
- DateContext jc = new DateContext();
- JexlEngine jexl = new JexlBuilder().cache(32).namespaces(ns).arithmetic(new DateArithmetic(true)).create();
- JxltEngine jxlt = jexl.createJxltEngine();
+ final Date x0 = cal.getTime();
+ final String y0 = "yyyy-MM-dd";
+ final DateContext jc = new DateContext();
+ final JexlEngine jexl = new JexlBuilder().cache(32).namespaces(ns).arithmetic(new DateArithmetic(true)).create();
+ final JxltEngine jxlt = jexl.createJxltEngine();
JxltEngine.Template expr0 = jxlt.createTemplate("${x.format(y)}", "x", "y");
StringWriter strw = new StringWriter();
@@ -543,7 +543,7 @@
strws = strw.toString();
Assert.assertEquals("6", strws);
- JxltEngine.Template expr1 = jxlt.createTemplate("${jexl:include(s, x, y)}", "s", "x", "y");
+ final JxltEngine.Template expr1 = jxlt.createTemplate("${jexl:include(s, x, y)}", "s", "x", "y");
strw = new StringWriter();
expr1.evaluate(jc, strw, expr0, 1, 3);
strws = strw.toString();
diff --git a/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java b/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java
index 53b0ac0..0ae9699 100644
--- a/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ArithmeticTest.java
@@ -139,7 +139,7 @@
asserter.assertExpression("1 + 9223372036854775807", new BigInteger("9223372036854775808"));
asserter.assertExpression("-1 + (-9223372036854775808)", new BigInteger("-9223372036854775809"));
asserter.assertExpression("-9223372036854775808 - 1", new BigInteger("-9223372036854775809"));
- BigInteger maxl = BigInteger.valueOf(Long.MAX_VALUE);
+ final BigInteger maxl = BigInteger.valueOf(Long.MAX_VALUE);
asserter.assertExpression(maxl.toString() + " * " + maxl.toString() , maxl.multiply(maxl));
}
@@ -282,11 +282,11 @@
// JEXL-24: long integers (and doubles)
@Test
public void testLongLiterals() throws Exception {
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "{a = 10L; b = 10l; c = 42.0D; d = 42.0d; e=56.3F; f=56.3f; g=63.5; h=0x10; i=010; j=0x10L; k=010l}";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "{a = 10L; b = 10l; c = 42.0D; d = 42.0d; e=56.3F; f=56.3f; g=63.5; h=0x10; i=010; j=0x10L; k=010l}";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(10L, ctxt.get("a"));
Assert.assertEquals(10L, ctxt.get("b"));
@@ -303,35 +303,35 @@
@Test
public void testBigLiteralValue() throws Exception {
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- JexlExpression e = JEXL.createExpression("9223372036854775806.5B");
- String res = String.valueOf(e.evaluate(ctxt));
+ final JexlExpression e = JEXL.createExpression("9223372036854775806.5B");
+ final String res = String.valueOf(e.evaluate(ctxt));
Assert.assertEquals("9223372036854775806.5", res);
}
@Test
public void testBigdOp() throws Exception {
- BigDecimal sevendot475 = new BigDecimal("7.475");
- BigDecimal SO = new BigDecimal("325");
- JexlContext jc = new MapContext();
+ final BigDecimal sevendot475 = new BigDecimal("7.475");
+ final BigDecimal SO = new BigDecimal("325");
+ final JexlContext jc = new MapContext();
jc.set("SO", SO);
- String expr = "2.3*SO/100";
+ final String expr = "2.3*SO/100";
- Object evaluate = JEXL.createExpression(expr).evaluate(jc);
+ final Object evaluate = JEXL.createExpression(expr).evaluate(jc);
Assert.assertEquals(sevendot475, evaluate);
}
// JEXL-24: big integers and big decimals
@Test
public void testBigLiterals() throws Exception {
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "{a = 10H; b = 10h; c = 42.0B; d = 42.0b;}";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "{a = 10H; b = 10h; c = 42.0B; d = 42.0b;}";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(new BigInteger("10"), ctxt.get("a"));
Assert.assertEquals(new BigInteger("10"), ctxt.get("b"));
@@ -342,11 +342,11 @@
// JEXL-24: big decimals with exponent
@Test
public void testBigExponentLiterals() throws Exception {
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "{a = 42.0e1B; b = 42.0E+2B; c = 42.0e-1B; d = 42.0E-2b; e=4242.4242e1b}";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "{a = 42.0e1B; b = 42.0E+2B; c = 42.0e-1B; d = 42.0E-2b; e=4242.4242e1b}";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(new BigDecimal("42.0e+1"), ctxt.get("a"));
Assert.assertEquals(new BigDecimal("42.0e+2"), ctxt.get("b"));
@@ -358,11 +358,11 @@
// JEXL-24: doubles with exponent
@Test
public void test2DoubleLiterals() throws Exception {
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "{a = 42.0e1D; b = 42.0E+2D; c = 42.0e-1d; d = 42.0E-2d; e=10e10; f= +1.e1; g=1e1; }";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "{a = 42.0e1D; b = 42.0E+2D; c = 42.0e-1d; d = 42.0E-2d; e=10e10; f= +1.e1; g=1e1; }";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(Double.valueOf("42.0e+1"), ctxt.get("a"));
Assert.assertEquals(Double.valueOf("42.0e+2"), ctxt.get("b"));
@@ -381,9 +381,9 @@
*/
@Test
public void testDivideByZero() throws Exception {
- Map<String, Object> vars = new HashMap<String, Object>();
- JexlEvalContext context = new JexlEvalContext(vars);
- JexlOptions options = context.getEngineOptions();
+ final Map<String, Object> vars = new HashMap<String, Object>();
+ final JexlEvalContext context = new JexlEvalContext(vars);
+ final JexlOptions options = context.getEngineOptions();
options.setStrictArithmetic(true);
vars.put("aByte", new Byte((byte) 1));
vars.put("aShort", new Short((short) 2));
@@ -403,7 +403,7 @@
vars.put("zBigInteger", new BigInteger("0"));
vars.put("zBigDecimal", new BigDecimal("0"));
- String[] tnames = {
+ final String[] tnames = {
"Byte", "Short", "Integer", "Long",
"Float", "Double",
"BigInteger", "BigDecimal"
@@ -411,31 +411,31 @@
// number of permutations this will generate
final int PERMS = tnames.length * tnames.length;
- JexlEngine jexl = JEXL;
+ final JexlEngine jexl = JEXL;
// for non-silent, silent...
for (int s = 0; s < 2; ++s) {
- boolean strict = Boolean.valueOf(s != 0);
+ final boolean strict = Boolean.valueOf(s != 0);
options.setStrict(true);
options.setStrictArithmetic(strict);
int zthrow = 0;
int zeval = 0;
// for vars of all types...
- for (String vname : tnames) {
+ for (final String vname : tnames) {
// for zeros of all types...
- for (String zname : tnames) {
+ for (final String zname : tnames) {
// divide var by zero
- String expr = "a" + vname + " / " + "z" + zname;
+ final String expr = "a" + vname + " / " + "z" + zname;
try {
- JexlExpression zexpr = jexl.createExpression(expr);
- Object nan = zexpr.evaluate(context);
+ final JexlExpression zexpr = jexl.createExpression(expr);
+ final Object nan = zexpr.evaluate(context);
// check we have a zero & incremement zero count
if (nan instanceof Number) {
- double zero = ((Number) nan).doubleValue();
+ final double zero = ((Number) nan).doubleValue();
if (zero == 0.0) {
zeval += 1;
}
}
- } catch (Exception any) {
+ } catch (final Exception any) {
// increment the exception count
zthrow += 1;
}
@@ -452,9 +452,9 @@
@Test
public void testNaN() throws Exception {
- Map<String, Object> ns = new HashMap<String, Object>();
+ final Map<String, Object> ns = new HashMap<String, Object>();
ns.put("double", Double.class);
- JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
+ final JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
JexlScript script;
Object result;
script = jexl.createScript("#NaN");
@@ -476,55 +476,55 @@
*/
@Test
public void testMultClass() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext jc = new MapContext();
- Object ra = jexl.createExpression("463.0d * 0.1").evaluate(jc);
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext jc = new MapContext();
+ final Object ra = jexl.createExpression("463.0d * 0.1").evaluate(jc);
Assert.assertEquals(Double.class, ra.getClass());
- Object r0 = jexl.createExpression("463.0B * 0.1").evaluate(jc);
+ final Object r0 = jexl.createExpression("463.0B * 0.1").evaluate(jc);
Assert.assertEquals(java.math.BigDecimal.class, r0.getClass());
- Object r1 = jexl.createExpression("463.0B * 0.1B").evaluate(jc);
+ final Object r1 = jexl.createExpression("463.0B * 0.1B").evaluate(jc);
Assert.assertEquals(java.math.BigDecimal.class, r1.getClass());
}
@Test
public void testDivClass() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext jc = new MapContext();
- Object ra = jexl.createExpression("463.0d / 0.1").evaluate(jc);
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext jc = new MapContext();
+ final Object ra = jexl.createExpression("463.0d / 0.1").evaluate(jc);
Assert.assertEquals(Double.class, ra.getClass());
- Object r0 = jexl.createExpression("463.0B / 0.1").evaluate(jc);
+ final Object r0 = jexl.createExpression("463.0B / 0.1").evaluate(jc);
Assert.assertEquals(java.math.BigDecimal.class, r0.getClass());
- Object r1 = jexl.createExpression("463.0B / 0.1B").evaluate(jc);
+ final Object r1 = jexl.createExpression("463.0B / 0.1B").evaluate(jc);
Assert.assertEquals(java.math.BigDecimal.class, r1.getClass());
}
@Test
public void testPlusClass() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext jc = new MapContext();
- Object ra = jexl.createExpression("463.0d + 0.1").evaluate(jc);
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext jc = new MapContext();
+ final Object ra = jexl.createExpression("463.0d + 0.1").evaluate(jc);
Assert.assertEquals(Double.class, ra.getClass());
- Object r0 = jexl.createExpression("463.0B + 0.1").evaluate(jc);
+ final Object r0 = jexl.createExpression("463.0B + 0.1").evaluate(jc);
Assert.assertEquals(java.math.BigDecimal.class, r0.getClass());
- Object r1 = jexl.createExpression("463.0B + 0.1B").evaluate(jc);
+ final Object r1 = jexl.createExpression("463.0B + 0.1B").evaluate(jc);
Assert.assertEquals(java.math.BigDecimal.class, r1.getClass());
}
@Test
public void testMinusClass() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext jc = new MapContext();
- Object ra = jexl.createExpression("463.0d - 0.1").evaluate(jc);
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext jc = new MapContext();
+ final Object ra = jexl.createExpression("463.0d - 0.1").evaluate(jc);
Assert.assertEquals(Double.class, ra.getClass());
- Object r0 = jexl.createExpression("463.0B - 0.1").evaluate(jc);
+ final Object r0 = jexl.createExpression("463.0B - 0.1").evaluate(jc);
Assert.assertEquals(java.math.BigDecimal.class, r0.getClass());
- Object r1 = jexl.createExpression("463.0B - 0.1B").evaluate(jc);
+ final Object r1 = jexl.createExpression("463.0B - 0.1B").evaluate(jc);
Assert.assertEquals(java.math.BigDecimal.class, r1.getClass());
}
@Test
public void testAddWithStringsLenient() throws Exception {
- JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(false)).create();
+ final JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(false)).create();
JexlScript script;
Object result;
script = jexl.createScript("'a' + 0");
@@ -562,7 +562,7 @@
@Test
public void testAddWithStringsStrict() throws Exception {
- JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(true)).create();
+ final JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(true)).create();
JexlScript script;
Object result;
script = jexl.createScript("'a' + 0");
@@ -600,11 +600,11 @@
@Test
public void testOption() throws Exception {
- Map<String, Object> vars = new HashMap<String, Object>();
- JexlEvalContext context = new JexlEvalContext(vars);
- JexlOptions options = context.getEngineOptions();
+ final Map<String, Object> vars = new HashMap<String, Object>();
+ final JexlEvalContext context = new JexlEvalContext(vars);
+ final JexlOptions options = context.getEngineOptions();
options.setStrictArithmetic(true);
- JexlScript script = JEXL.createScript("0 + '1.2' ");
+ final JexlScript script = JEXL.createScript("0 + '1.2' ");
Object result;
options.setStrictArithmetic(true);
@@ -618,7 +618,7 @@
@Test
public void testIsFloatingPointPattern() throws Exception {
- JexlArithmetic ja = new JexlArithmetic(true);
+ final JexlArithmetic ja = new JexlArithmetic(true);
Assert.assertFalse(ja.isFloatingPointNumber("floating point"));
Assert.assertFalse(ja.isFloatingPointNumber("a1."));
@@ -658,25 +658,25 @@
}
public static class EmptyTestContext extends MapContext implements JexlContext.NamespaceResolver {
- public static int log(Object fmt, Object... arr) {
+ public static int log(final Object fmt, final Object... arr) {
//System.out.println(String.format(fmt.toString(), arr));
return arr == null ? 0 : arr.length;
}
- public static int log(Object fmt, int... arr) {
+ public static int log(final Object fmt, final int... arr) {
//System.out.println(String.format(fmt.toString(), arr));
return arr == null ? 0 : arr.length;
}
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
return this;
}
}
@Test
public void testEmpty() throws Exception {
- Object[] SCRIPTS = {
+ final Object[] SCRIPTS = {
"var x = null; log('x = %s', x);", 0,
"var x = 'abc'; log('x = %s', x);", 1,
"var x = 333; log('x = %s', x);", 1,
@@ -698,15 +698,15 @@
"var x = {}; return empty(x);", true,
"var x = {'A','B'}; return empty(x);", false
};
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext jc = new EmptyTestContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext jc = new EmptyTestContext();
JexlScript script;
for (int e = 0; e < SCRIPTS.length; e += 2) {
- String stext = (String) SCRIPTS[e];
- Object expected = SCRIPTS[e + 1];
+ final String stext = (String) SCRIPTS[e];
+ final Object expected = SCRIPTS[e + 1];
script = jexl.createScript(stext);
- Object result = script.execute(jc);
+ final Object result = script.execute(jc);
Assert.assertEquals("failed on " + stext, expected, result);
}
}
@@ -714,7 +714,7 @@
public static class Var {
int value;
- Var(int v) {
+ Var(final int v) {
value = v;
}
@@ -726,122 +726,122 @@
// an arithmetic that know how to subtract strings
public static class ArithmeticPlus extends JexlArithmetic {
- public ArithmeticPlus(boolean strict) {
+ public ArithmeticPlus(final boolean strict) {
super(strict);
}
- public boolean equals(Var lhs, Var rhs) {
+ public boolean equals(final Var lhs, final Var rhs) {
return lhs.value == rhs.value;
}
- public boolean lessThan(Var lhs, Var rhs) {
+ public boolean lessThan(final Var lhs, final Var rhs) {
return lhs.value < rhs.value;
}
- public boolean lessThanOrEqual(Var lhs, Var rhs) {
+ public boolean lessThanOrEqual(final Var lhs, final Var rhs) {
return lhs.value <= rhs.value;
}
- public boolean greaterThan(Var lhs, Var rhs) {
+ public boolean greaterThan(final Var lhs, final Var rhs) {
return lhs.value > rhs.value;
}
- public boolean greaterThanOrEqual(Var lhs, Var rhs) {
+ public boolean greaterThanOrEqual(final Var lhs, final Var rhs) {
return lhs.value >= rhs.value;
}
- public Var add(Var lhs, Var rhs) {
+ public Var add(final Var lhs, final Var rhs) {
return new Var(lhs.value + rhs.value);
}
- public Var subtract(Var lhs, Var rhs) {
+ public Var subtract(final Var lhs, final Var rhs) {
return new Var(lhs.value - rhs.value);
}
- public Var divide(Var lhs, Var rhs) {
+ public Var divide(final Var lhs, final Var rhs) {
return new Var(lhs.value / rhs.value);
}
- public Var multiply(Var lhs, Var rhs) {
+ public Var multiply(final Var lhs, final Var rhs) {
return new Var(lhs.value * rhs.value);
}
- public Var mod(Var lhs, Var rhs) {
+ public Var mod(final Var lhs, final Var rhs) {
return new Var(lhs.value / rhs.value);
}
- public Var negate(Var arg) {
+ public Var negate(final Var arg) {
return new Var(-arg.value);
}
- public Var and(Var lhs, Var rhs) {
+ public Var and(final Var lhs, final Var rhs) {
return new Var(lhs.value & rhs.value);
}
- public Var or(Var lhs, Var rhs) {
+ public Var or(final Var lhs, final Var rhs) {
return new Var(lhs.value | rhs.value);
}
- public Var xor(Var lhs, Var rhs) {
+ public Var xor(final Var lhs, final Var rhs) {
return new Var(lhs.value ^ rhs.value);
}
- public Boolean contains(Var lhs, Var rhs) {
+ public Boolean contains(final Var lhs, final Var rhs) {
return lhs.toString().contains(rhs.toString());
}
- public Boolean startsWith(Var lhs, Var rhs) {
+ public Boolean startsWith(final Var lhs, final Var rhs) {
return lhs.toString().startsWith(rhs.toString());
}
- public Boolean endsWith(Var lhs, Var rhs) {
+ public Boolean endsWith(final Var lhs, final Var rhs) {
return lhs.toString().endsWith(rhs.toString());
}
- public Var complement(Var arg) {
+ public Var complement(final Var arg) {
return new Var(~arg.value);
}
- public Object subtract(String x, String y) {
- int ix = x.indexOf(y);
+ public Object subtract(final String x, final String y) {
+ final int ix = x.indexOf(y);
if (ix < 0) {
return x;
}
- StringBuilder strb = new StringBuilder(x.substring(0, ix));
+ final StringBuilder strb = new StringBuilder(x.substring(0, ix));
strb.append(x.substring(ix + y.length()));
return strb.toString();
}
public Object negate(final String str) {
final int length = str.length();
- StringBuilder strb = new StringBuilder(str.length());
+ final StringBuilder strb = new StringBuilder(str.length());
for (int c = length - 1; c >= 0; --c) {
strb.append(str.charAt(c));
}
return strb.toString();
}
- public Object not(Var x) {
+ public Object not(final Var x) {
throw new NullPointerException("make it fail");
}
}
@Test
public void testArithmeticPlus() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(64).arithmetic(new ArithmeticPlus(false)).create();
- JexlContext jc = new EmptyTestContext();
+ final JexlEngine jexl = new JexlBuilder().cache(64).arithmetic(new ArithmeticPlus(false)).create();
+ final JexlContext jc = new EmptyTestContext();
runOverload(jexl, jc);
runOverload(jexl, jc);
}
@Test
public void testArithmeticPlusNoCache() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(0).arithmetic(new ArithmeticPlus(false)).create();
- JexlContext jc = new EmptyTestContext();
+ final JexlEngine jexl = new JexlBuilder().cache(0).arithmetic(new ArithmeticPlus(false)).create();
+ final JexlContext jc = new EmptyTestContext();
runOverload(jexl, jc);
}
- protected void runOverload(JexlEngine jexl, JexlContext jc) {
+ protected void runOverload(final JexlEngine jexl, final JexlContext jc) {
JexlScript script;
Object result;
@@ -1019,25 +1019,25 @@
try {
result = script.execute(jc, new Var(-42));
Assert.fail("should fail");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertTrue(xany instanceof JexlException.Operator);
}
}
public static class Callable173 {
- public Object call(String... arg) {
+ public Object call(final String... arg) {
return 42;
}
- public Object call(Integer... arg) {
+ public Object call(final Integer... arg) {
return arg[0] * arg[1];
}
}
@Test
public void testJexl173() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext jc = new MapContext();
- Callable173 c173 = new Callable173();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext jc = new MapContext();
+ final Callable173 c173 = new Callable173();
JexlScript e = jexl.createScript( "c173(9, 6)", "c173" );
Object result = e.execute(jc, c173);
Assert.assertEquals(54, result);
@@ -1052,8 +1052,8 @@
super(false);
}
- protected double divideZero(BigDecimal x) {
- int ls = x.signum();
+ protected double divideZero(final BigDecimal x) {
+ final int ls = x.signum();
if (ls < 0) {
return Double.NEGATIVE_INFINITY;
} else if (ls > 0) {
@@ -1063,8 +1063,8 @@
}
}
- protected double divideZero(BigInteger x) {
- int ls = x.signum();
+ protected double divideZero(final BigInteger x) {
+ final int ls = x.signum();
if (ls < 0) {
return Double.NEGATIVE_INFINITY;
} else if (ls > 0) {
@@ -1075,61 +1075,61 @@
}
@Override
- public Object divide(Object left, Object right) {
+ public Object divide(final Object left, final Object right) {
if (left == null && right == null) {
return controlNullNullOperands();
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
- BigDecimal l = toBigDecimal(left);
- BigDecimal r = toBigDecimal(right);
+ final BigDecimal l = toBigDecimal(left);
+ final BigDecimal r = toBigDecimal(right);
if (BigDecimal.ZERO.equals(r)) {
return divideZero(l);
}
- BigDecimal result = l.divide(r, getMathContext());
+ final BigDecimal result = l.divide(r, getMathContext());
return narrowBigDecimal(left, right, result);
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
- double l = toDouble(left);
- double r = toDouble(right);
+ final double l = toDouble(left);
+ final double r = toDouble(right);
return new Double(l / r);
}
// otherwise treat as integers
- BigInteger l = toBigInteger(left);
- BigInteger r = toBigInteger(right);
+ final BigInteger l = toBigInteger(left);
+ final BigInteger r = toBigInteger(right);
if (BigInteger.ZERO.equals(r)) {
return divideZero(l);
}
- BigInteger result = l.divide(r);
+ final BigInteger result = l.divide(r);
return narrowBigInteger(left, right, result);
}
@Override
- public Object mod(Object left, Object right) {
+ public Object mod(final Object left, final Object right) {
if (left == null && right == null) {
return controlNullNullOperands();
}
// if either are bigdecimal use that type
if (left instanceof BigDecimal || right instanceof BigDecimal) {
- BigDecimal l = toBigDecimal(left);
- BigDecimal r = toBigDecimal(right);
+ final BigDecimal l = toBigDecimal(left);
+ final BigDecimal r = toBigDecimal(right);
if (BigDecimal.ZERO.equals(r)) {
return divideZero(l);
}
- BigDecimal remainder = l.remainder(r, getMathContext());
+ final BigDecimal remainder = l.remainder(r, getMathContext());
return narrowBigDecimal(left, right, remainder);
}
// if either are floating point (double or float) use double
if (isFloatingPointNumber(left) || isFloatingPointNumber(right)) {
- double l = toDouble(left);
- double r = toDouble(right);
+ final double l = toDouble(left);
+ final double r = toDouble(right);
return new Double(l % r);
}
// otherwise treat as integers
- BigInteger l = toBigInteger(left);
- BigInteger r = toBigInteger(right);
- BigInteger result = l.mod(r);
+ final BigInteger l = toBigInteger(left);
+ final BigInteger r = toBigInteger(right);
+ final BigInteger result = l.mod(r);
if (BigInteger.ZERO.equals(r)) {
return divideZero(l);
}
@@ -1139,9 +1139,9 @@
@Test
public void testInfiniteArithmetic() throws Exception {
- Map<String, Object> ns = new HashMap<String, Object>();
+ final Map<String, Object> ns = new HashMap<String, Object>();
ns.put("math", Math.class);
- JexlEngine jexl = new JexlBuilder().arithmetic(new Arithmetic132()).namespaces(ns).create();
+ final JexlEngine jexl = new JexlBuilder().arithmetic(new Arithmetic132()).namespaces(ns).create();
Object evaluate = jexl.createExpression("1/0").evaluate(null);
Assert.assertTrue(Double.isInfinite((Double) evaluate));
@@ -1159,26 +1159,26 @@
Assert.assertEquals(42, evaluate);
}
- private static Document getDocument(String xml) throws Exception {
- DocumentBuilder xmlBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- InputStream stringInputStream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
+ private static Document getDocument(final String xml) throws Exception {
+ final DocumentBuilder xmlBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ final InputStream stringInputStream = new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8));
return xmlBuilder.parse(stringInputStream);
}
public static class XmlArithmetic extends JexlArithmetic {
- public XmlArithmetic(boolean astrict) {
+ public XmlArithmetic(final boolean astrict) {
super(astrict);
}
- public XmlArithmetic(boolean astrict, MathContext bigdContext, int bigdScale) {
+ public XmlArithmetic(final boolean astrict, final MathContext bigdContext, final int bigdScale) {
super(astrict, bigdContext, bigdScale);
}
- public boolean empty(org.w3c.dom.Element elt) {
+ public boolean empty(final org.w3c.dom.Element elt) {
return !elt.hasAttributes() && !elt.hasChildNodes();
}
- public int size(org.w3c.dom.Element elt) {
+ public int size(final org.w3c.dom.Element elt) {
return elt.getChildNodes().getLength();
}
}
@@ -1192,12 +1192,12 @@
Node x;
Boolean empty;
int size;
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlEngine jexl = new JexlBuilder().strict(true).safe(false).arithmetic(new XmlArithmetic(false)).create();
- JexlScript e0 = jexl.createScript("x.empty()", "x");
- JexlScript e1 = jexl.createScript("empty(x)", "x");
- JexlScript s0 = jexl.createScript("x.size()", "x");
- JexlScript s1 = jexl.createScript("size(x)", "x");
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlEngine jexl = new JexlBuilder().strict(true).safe(false).arithmetic(new XmlArithmetic(false)).create();
+ final JexlScript e0 = jexl.createScript("x.empty()", "x");
+ final JexlScript e1 = jexl.createScript("empty(x)", "x");
+ final JexlScript s0 = jexl.createScript("x.size()", "x");
+ final JexlScript s1 = jexl.createScript("size(x)", "x");
empty = (Boolean) e1.execute(null, (Object) null);
Assert.assertTrue(empty);
@@ -1205,22 +1205,22 @@
Assert.assertEquals(0, size);
try {
- Object xx = e0.execute(null, (Object) null);
+ final Object xx = e0.execute(null, (Object) null);
Assert.assertNull(xx);
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.assertNotNull(xvar);
}
try {
- Object xx = s0.execute(null, (Object) null);
+ final Object xx = s0.execute(null, (Object) null);
Assert.assertNull(xx);
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.assertNotNull(xvar);
}
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setSafe(true);
- Object x0 = e0.execute(ctxt, (Object) null);
+ final Object x0 = e0.execute(ctxt, (Object) null);
Assert.assertNull(x0);
- Object x1 = s0.execute(ctxt, (Object) null);
+ final Object x1 = s0.execute(ctxt, (Object) null);
Assert.assertNull(x1);
xml = getDocument("<node info='123'/>");
@@ -1259,12 +1259,12 @@
Assert.assertEquals("123", info.getValue());
// JEXL-161
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("x", xml.getLastChild());
final String y = "456";
jc.set("y", y);
- JexlScript s = jexl.createScript("x.attribute.info = y");
- Object r = s.execute(jc);
+ final JexlScript s = jexl.createScript("x.attribute.info = y");
+ final Object r = s.execute(jc);
nnm = xml.getLastChild().getAttributes();
info = (Attr) nnm.getNamedItem("info");
Assert.assertEquals(y, r);
@@ -1321,26 +1321,26 @@
}
- void checkEmpty(Object x, boolean expect) {
- JexlScript s0 = JEXL.createScript("empty(x)", "x");
+ void checkEmpty(final Object x, final boolean expect) {
+ final JexlScript s0 = JEXL.createScript("empty(x)", "x");
boolean empty = (Boolean) s0.execute(null, x);
Assert.assertEquals(expect, empty);
- JexlScript s1 = JEXL.createScript("empty x", "x");
+ final JexlScript s1 = JEXL.createScript("empty x", "x");
empty = (Boolean) s1.execute(null, x);
Assert.assertEquals(expect, empty);
- JexlScript s2 = JEXL.createScript("x.empty()", "x");
+ final JexlScript s2 = JEXL.createScript("x.empty()", "x");
empty = (Boolean) s2.execute(null, x);
Assert.assertEquals(expect, empty);
}
@Test
public void testCoerceInteger() throws Exception {
- JexlArithmetic ja = JEXL.getArithmetic();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlArithmetic ja = JEXL.getArithmetic();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H;";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H;";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(34, ja.toInteger(ctxt.get("a")));
Assert.assertEquals(45, ja.toInteger(ctxt.get("b")));
@@ -1354,12 +1354,12 @@
@Test
public void testCoerceLong() throws Exception {
- JexlArithmetic ja = JEXL.getArithmetic();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlArithmetic ja = JEXL.getArithmetic();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H;";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H;";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(34L, ja.toLong(ctxt.get("a")));
Assert.assertEquals(45L, ja.toLong(ctxt.get("b")));
@@ -1373,12 +1373,12 @@
@Test
public void testCoerceDouble() throws Exception {
- JexlArithmetic ja = JEXL.getArithmetic();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlArithmetic ja = JEXL.getArithmetic();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "{a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H; }";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "{a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H; }";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(34, ja.toDouble(ctxt.get("a")), EPSILON);
Assert.assertEquals(45, ja.toDouble(ctxt.get("b")), EPSILON);
@@ -1392,12 +1392,12 @@
@Test
public void testCoerceBigInteger() throws Exception {
- JexlArithmetic ja = JEXL.getArithmetic();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlArithmetic ja = JEXL.getArithmetic();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "{a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H; }";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "{a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H; }";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(BigInteger.valueOf(34), ja.toBigInteger(ctxt.get("a")));
Assert.assertEquals(BigInteger.valueOf(45), ja.toBigInteger(ctxt.get("b")));
@@ -1411,12 +1411,12 @@
@Test
public void testCoerceBigDecimal() throws Exception {
- JexlArithmetic ja = JEXL.getArithmetic();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlArithmetic ja = JEXL.getArithmetic();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrictArithmetic(true);
- String stmt = "{a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H; }";
- JexlScript expr = JEXL.createScript(stmt);
+ final String stmt = "{a = 34L; b = 45.0D; c=56.0F; d=67B; e=78H; }";
+ final JexlScript expr = JEXL.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertEquals(BigDecimal.valueOf(34), ja.toBigDecimal(ctxt.get("a")));
Assert.assertEquals(BigDecimal.valueOf(45.), ja.toBigDecimal(ctxt.get("b")));
@@ -1432,8 +1432,8 @@
public void testAtomicBoolean() throws Exception {
// in a condition
JexlScript e = JEXL.createScript("if (x) 1 else 2;", "x");
- JexlContext jc = new MapContext();
- AtomicBoolean ab = new AtomicBoolean(false);
+ final JexlContext jc = new MapContext();
+ final AtomicBoolean ab = new AtomicBoolean(false);
Object o;
o = e.execute(jc, ab);
Assert.assertEquals("Result is not 2", new Integer(2), o);
@@ -1466,14 +1466,14 @@
o = e.execute(jc, 10.d, ab);
Assert.assertEquals(11.d, (Double) o, EPSILON);
- BigInteger bi10 = BigInteger.TEN;
+ final BigInteger bi10 = BigInteger.TEN;
ab.set(false);
o = e.execute(jc, ab, bi10);
Assert.assertEquals(bi10, o);
o = e.execute(jc, bi10, ab);
Assert.assertEquals(bi10, o);
- BigDecimal bd10 = BigDecimal.TEN;
+ final BigDecimal bd10 = BigDecimal.TEN;
ab.set(false);
o = e.execute(jc, ab, bd10);
Assert.assertEquals(bd10, o);
diff --git a/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java b/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java
index a42b330..a53bb28 100644
--- a/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ArrayAccessTest.java
@@ -66,7 +66,7 @@
* test List access
*/
- List<Integer> l = new ArrayList<Integer>();
+ final List<Integer> l = new ArrayList<Integer>();
l.add(new Integer(1));
l.add(new Integer(2));
l.add(new Integer(3));
@@ -82,7 +82,7 @@
* test array access
*/
- String[] args = { "hello", "there" };
+ final String[] args = { "hello", "there" };
asserter.setVariable("array", args);
asserter.assertExpression("array[0]", "hello");
@@ -94,7 +94,7 @@
/*
* test map access
*/
- Map<String, String> m = new HashMap<String, String>();
+ final Map<String, String> m = new HashMap<String, String>();
m.put("foo", "bar");
asserter.setVariable("map", m);
@@ -116,7 +116,7 @@
*/
@Test
public void testDoubleArrays() throws Exception {
- Object[][] foo = new Object[2][2];
+ final Object[][] foo = new Object[2][2];
foo[0][0] = "one";
foo[0][1] = "two";
@@ -153,8 +153,8 @@
@Test
public void testDoubleMaps() throws Exception {
- Map<Object, Map<Object, Object>> foo = new HashMap<Object, Map<Object, Object>>();
- Map<Object, Object> foo0 = new HashMap<Object, Object>();
+ final Map<Object, Map<Object, Object>> foo = new HashMap<Object, Map<Object, Object>>();
+ final Map<Object, Object> foo0 = new HashMap<Object, Object>();
foo.put(0, foo0);
foo0.put(0, "one");
foo0.put(1, "two");
@@ -193,7 +193,7 @@
@Test
public void testArrayProperty() throws Exception {
- Foo foo = new Foo();
+ final Foo foo = new Foo();
asserter.setVariable("foo", foo);
@@ -206,7 +206,7 @@
// This is JEXL-26
@Test
public void testArrayAndDottedConflict() throws Exception {
- Object[] objects = new Object[] {"an", "array", new Long(0)};
+ final Object[] objects = new Object[] {"an", "array", new Long(0)};
asserter.setStrict(false);
asserter.setSilent(true);
asserter.setVariable("objects", objects);
@@ -221,7 +221,7 @@
@Test
public void testArrayIdentifierParsing() throws Exception {
- Map<Object, Number> map = new HashMap<Object, Number>();
+ final Map<Object, Number> map = new HashMap<Object, Number>();
map.put("00200", -42.42d);
map.put(200, 42.42d);
asserter.setVariable("objects", map);
@@ -234,7 +234,7 @@
@Test
public void testArrayMethods() throws Exception {
- Object[] objects = new Object[] {"an", "array", new Long(0)};
+ final Object[] objects = new Object[] {"an", "array", new Long(0)};
asserter.setVariable("objects", objects);
asserter.assertExpression("objects.get(1)", "array");
@@ -246,11 +246,11 @@
@Test
public void testArrayArray() throws Exception {
- Integer i42 = Integer.valueOf(42);
- Integer i43 = Integer.valueOf(43);
- String s42 = "fourty-two";
- String s43 = "fourty-three";
- Object[] foo = new Object[3];
+ final Integer i42 = Integer.valueOf(42);
+ final Integer i43 = Integer.valueOf(43);
+ final String s42 = "fourty-two";
+ final String s43 = "fourty-three";
+ final Object[] foo = new Object[3];
foo[0] = foo;
foo[1] = i42;
foo[2] = s42;
@@ -313,7 +313,7 @@
public static class Sample {
private int[] array;
- public void setFoo(int[] a) {
+ public void setFoo(final int[] a) {
array = a;
}
public int[] getFoo() {
@@ -322,7 +322,7 @@
}
@Test
public void testArrayGetSet() throws Exception {
- Sample bar = new Sample();
+ final Sample bar = new Sample();
bar.setFoo(new int[]{24});
asserter.setVariable("bar", bar);
asserter.assertExpression("bar.foo[0]", 24);
diff --git a/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java b/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java
index 4584f9f..0d8c5f0 100644
--- a/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ArrayLiteralTest.java
@@ -34,7 +34,7 @@
@Test
public void testEmptyArrayLiteral() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
Object o;
o = JEXL.createExpression("[]").evaluate(jc);
Assert.assertTrue(o instanceof Object[]);
@@ -46,66 +46,66 @@
@Test
public void testLiteralWithStrings() throws Exception {
- JexlExpression e = JEXL.createExpression("[ 'foo' , 'bar' ]");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("[ 'foo' , 'bar' ]");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
- Object[] check = {"foo", "bar"};
+ final Object o = e.evaluate(jc);
+ final Object[] check = {"foo", "bar"};
Assert.assertArrayEquals(check, (Object[]) o);
}
@Test
public void testLiteralWithElipsis() throws Exception {
- JexlExpression e = JEXL.createExpression("[ 'foo' , 'bar', ... ]");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("[ 'foo' , 'bar', ... ]");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
- Object[] check = {"foo", "bar"};
+ final Object o = e.evaluate(jc);
+ final Object[] check = {"foo", "bar"};
Assert.assertEquals(Arrays.asList(check), o);
Assert.assertEquals(2, ((List<?>) o).size());
}
@Test
public void testLiteralWithOneEntry() throws Exception {
- JexlExpression e = JEXL.createExpression("[ 'foo' ]");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("[ 'foo' ]");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
- Object[] check = {"foo"};
+ final Object o = e.evaluate(jc);
+ final Object[] check = {"foo"};
Assert.assertArrayEquals(check, (Object[]) o);
}
@Test
public void testLiteralWithNumbers() throws Exception {
- JexlExpression e = JEXL.createExpression("[ 5.0 , 10 ]");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("[ 5.0 , 10 ]");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
- Object[] check = {new Double(5), new Integer(10)};
+ final Object o = e.evaluate(jc);
+ final Object[] check = {new Double(5), new Integer(10)};
Assert.assertArrayEquals(check, (Object[]) o);
Assert.assertTrue(o.getClass().isArray() && o.getClass().getComponentType().equals(Number.class));
}
@Test
public void testLiteralWithNulls() throws Exception {
- String[] exprs = {
+ final String[] exprs = {
"[ null , 10 ]",
"[ 10 , null ]",
"[ 10 , null , 10]",
"[ '10' , null ]",
"[ null, '10' , null ]"
};
- Object[][] checks = {
+ final Object[][] checks = {
{null, new Integer(10)},
{new Integer(10), null},
{new Integer(10), null, new Integer(10)},
{"10", null},
{null, "10", null}
};
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
for (int t = 0; t < exprs.length; ++t) {
- JexlExpression e = JEXL.createExpression(exprs[t]);
- Object o = e.evaluate(jc);
+ final JexlExpression e = JEXL.createExpression(exprs[t]);
+ final Object o = e.evaluate(jc);
Assert.assertArrayEquals(exprs[t], checks[t], (Object[]) o);
}
@@ -113,55 +113,55 @@
@Test
public void testLiteralWithIntegers() throws Exception {
- JexlExpression e = JEXL.createExpression("[ 5 , 10 ]");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("[ 5 , 10 ]");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
- int[] check = {5, 10};
+ final Object o = e.evaluate(jc);
+ final int[] check = {5, 10};
Assert.assertArrayEquals(check, (int[]) o);
}
@Test
public void testSizeOfSimpleArrayLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression("size([ 'foo' , 'bar' ])");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("size([ 'foo' , 'bar' ])");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertEquals(new Integer(2), o);
}
@Test
public void notestCallingMethodsOnNewMapLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression("size({ 'foo' : 'bar' }.values())");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("size({ 'foo' : 'bar' }.values())");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertEquals(new Integer(1), o);
}
@Test
public void testNotEmptySimpleArrayLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression("empty([ 'foo' , 'bar' ])");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("empty([ 'foo' , 'bar' ])");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertFalse((Boolean) o);
}
@Test
public void testChangeThroughVariables() throws Exception {
- JexlContext jc = new MapContext();
- JexlExpression e147 = JEXL.createExpression("quux = [one, two]");
+ final JexlContext jc = new MapContext();
+ final JexlExpression e147 = JEXL.createExpression("quux = [one, two]");
jc.set("one", 1);
jc.set("two", 2);
- int[] o1 = (int[]) e147.evaluate(jc);
+ final int[] o1 = (int[]) e147.evaluate(jc);
Assert.assertEquals(1, o1[0]);
Assert.assertEquals(2, o1[1]);
jc.set("one", 10);
jc.set("two", 20);
- int[] o2 = (int[]) e147.evaluate(jc);
+ final int[] o2 = (int[]) e147.evaluate(jc);
Assert.assertEquals(10, o2[0]);
Assert.assertEquals(20, o2[1]);
}
diff --git a/src/test/java/org/apache/commons/jexl3/AssignTest.java b/src/test/java/org/apache/commons/jexl3/AssignTest.java
index 2473cd6..f4d3fcd 100644
--- a/src/test/java/org/apache/commons/jexl3/AssignTest.java
+++ b/src/test/java/org/apache/commons/jexl3/AssignTest.java
@@ -29,10 +29,10 @@
public static class Froboz {
int value;
- public Froboz(int v) {
+ public Froboz(final int v) {
value = v;
}
- public void setValue(int v) {
+ public void setValue(final int v) {
value = v;
}
public int getValue() {
@@ -43,7 +43,7 @@
public static class Quux {
String str;
Froboz froboz;
- public Quux(String str, int fro) {
+ public Quux(final String str, final int fro) {
this.str = str;
froboz = new Froboz(fro);
}
@@ -52,7 +52,7 @@
return froboz;
}
- public void setFroboz(Froboz froboz) {
+ public void setFroboz(final Froboz froboz) {
this.froboz = froboz;
}
@@ -60,7 +60,7 @@
return str;
}
- public void setStr(String str) {
+ public void setStr(final String str) {
this.str = str;
}
}
@@ -76,9 +76,9 @@
*/
@Test
public void testAntish() throws Exception {
- JexlExpression assign = JEXL.createExpression("froboz.value = 10");
- JexlExpression check = JEXL.createExpression("froboz.value");
- JexlContext jc = new MapContext();
+ final JexlExpression assign = JEXL.createExpression("froboz.value = 10");
+ final JexlExpression check = JEXL.createExpression("froboz.value");
+ final JexlContext jc = new MapContext();
Object o = assign.evaluate(jc);
Assert.assertEquals("Result is not 10", new Integer(10), o);
o = check.evaluate(jc);
@@ -87,9 +87,9 @@
@Test
public void testAntishInteger() throws Exception {
- JexlExpression assign = JEXL.createExpression("froboz.0 = 10");
- JexlExpression check = JEXL.createExpression("froboz.0");
- JexlContext jc = new MapContext();
+ final JexlExpression assign = JEXL.createExpression("froboz.0 = 10");
+ final JexlExpression check = JEXL.createExpression("froboz.0");
+ final JexlContext jc = new MapContext();
Object o = assign.evaluate(jc);
Assert.assertEquals("Result is not 10", new Integer(10), o);
o = check.evaluate(jc);
@@ -98,10 +98,10 @@
@Test
public void testBeanish() throws Exception {
- JexlExpression assign = JEXL.createExpression("froboz.value = 10");
- JexlExpression check = JEXL.createExpression("froboz.value");
- JexlContext jc = new MapContext();
- Froboz froboz = new Froboz(-169);
+ final JexlExpression assign = JEXL.createExpression("froboz.value = 10");
+ final JexlExpression check = JEXL.createExpression("froboz.value");
+ final JexlContext jc = new MapContext();
+ final Froboz froboz = new Froboz(-169);
jc.set("froboz", froboz);
Object o = assign.evaluate(jc);
Assert.assertEquals("Result is not 10", new Integer(10), o);
@@ -111,16 +111,16 @@
@Test
public void testAmbiguous() throws Exception {
- JexlExpression assign = JEXL.createExpression("froboz.nosuchbean = 10");
- JexlContext jc = new MapContext();
- Froboz froboz = new Froboz(-169);
+ final JexlExpression assign = JEXL.createExpression("froboz.nosuchbean = 10");
+ final JexlContext jc = new MapContext();
+ final Froboz froboz = new Froboz(-169);
jc.set("froboz", froboz);
Object o = null;
try {
o = assign.evaluate(jc);
}
- catch(RuntimeException xrt) {
- String str = xrt.toString();
+ catch(final RuntimeException xrt) {
+ final String str = xrt.toString();
Assert.assertTrue(str.contains("nosuchbean"));
}
finally {
@@ -130,10 +130,10 @@
@Test
public void testArray() throws Exception {
- JexlExpression assign = JEXL.createExpression("froboz[\"value\"] = 10");
- JexlExpression check = JEXL.createExpression("froboz[\"value\"]");
- JexlContext jc = new MapContext();
- Froboz froboz = new Froboz(0);
+ final JexlExpression assign = JEXL.createExpression("froboz[\"value\"] = 10");
+ final JexlExpression check = JEXL.createExpression("froboz[\"value\"]");
+ final JexlContext jc = new MapContext();
+ final Froboz froboz = new Froboz(0);
jc.set("froboz", froboz);
Object o = assign.evaluate(jc);
Assert.assertEquals("Result is not 10", new Integer(10), o);
@@ -143,22 +143,22 @@
@Test
public void testMini() throws Exception {
- JexlContext jc = new MapContext();
- JexlExpression assign = JEXL.createExpression("quux = 10");
- Object o = assign.evaluate(jc);
+ final JexlContext jc = new MapContext();
+ final JexlExpression assign = JEXL.createExpression("quux = 10");
+ final Object o = assign.evaluate(jc);
Assert.assertEquals("Result is not 10", new Integer(10), o);
}
@Test
public void testMore() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("quuxClass", Quux.class);
- JexlExpression create = JEXL.createExpression("quux = new(quuxClass, 'xuuq', 100)");
- JexlExpression assign = JEXL.createExpression("quux.froboz.value = 10");
- JexlExpression check = JEXL.createExpression("quux[\"froboz\"].value");
+ final JexlExpression create = JEXL.createExpression("quux = new(quuxClass, 'xuuq', 100)");
+ final JexlExpression assign = JEXL.createExpression("quux.froboz.value = 10");
+ final JexlExpression check = JEXL.createExpression("quux[\"froboz\"].value");
- Quux quux = (Quux) create.evaluate(jc);
+ final Quux quux = (Quux) create.evaluate(jc);
Assert.assertNotNull("quux is null", quux);
Object o = assign.evaluate(jc);
Assert.assertEquals("Result is not 10", new Integer(10), o);
@@ -168,7 +168,7 @@
@Test
public void testUtil() throws Exception {
- Quux quux = JEXL.newInstance(Quux.class, "xuuq", Integer.valueOf(100));
+ final Quux quux = JEXL.newInstance(Quux.class, "xuuq", Integer.valueOf(100));
Assert.assertNotNull(quux);
JEXL.setProperty(quux, "froboz.value", Integer.valueOf(100));
Object o = JEXL.getProperty(quux, "froboz.value");
@@ -180,18 +180,18 @@
@Test
public void testRejectLocal() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
JexlScript assign = JEXL.createScript("var quux = null; quux.froboz.value = 10");
try {
- Object o = assign.execute(jc);
+ final Object o = assign.execute(jc);
Assert.fail("quux is local and null, should fail");
- } catch (JexlException xjexl) {
- String x = xjexl.toString();
- String y = x;
+ } catch (final JexlException xjexl) {
+ final String x = xjexl.toString();
+ final String y = x;
}
// quux is a global antish var
assign = JEXL.createScript("quux.froboz.value = 10");
- Object o = assign.execute(jc);
+ final Object o = assign.execute(jc);
Assert.assertEquals(10, o);
}
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/commons/jexl3/BlockTest.java b/src/test/java/org/apache/commons/jexl3/BlockTest.java
index 5ea9091..fb646ca 100644
--- a/src/test/java/org/apache/commons/jexl3/BlockTest.java
+++ b/src/test/java/org/apache/commons/jexl3/BlockTest.java
@@ -35,17 +35,17 @@
@Test
public void testBlockSimple() throws Exception {
- JexlScript e = JEXL.createScript("if (true) { 'hello'; }");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("if (true) { 'hello'; }");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is wrong", "hello", o);
}
@Test
public void testBlockExecutesAll() throws Exception {
- JexlScript e = JEXL.createScript("if (true) { x = 'Hello'; y = 'World';}");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("if (true) { x = 'Hello'; y = 'World';}");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals("First result is wrong", "Hello", jc.get("x"));
Assert.assertEquals("Second result is wrong", "World", jc.get("y"));
Assert.assertEquals("Block result is wrong", "World", o);
@@ -53,33 +53,33 @@
@Test
public void testEmptyBlock() throws Exception {
- JexlScript e = JEXL.createScript("if (true) { }");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("if (true) { }");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertNull("Result is wrong", o);
}
@Test
public void testBlockLastExecuted01() throws Exception {
- JexlScript e = JEXL.createScript("if (true) { x = 1; } else { x = 2; }");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("if (true) { x = 1; } else { x = 2; }");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals("Block result is wrong", new Integer(1), o);
}
@Test
public void testBlockLastExecuted02() throws Exception {
- JexlScript e = JEXL.createScript("if (false) { x = 1; } else { x = 2; }");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("if (false) { x = 1; } else { x = 2; }");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals("Block result is wrong", new Integer(2), o);
}
@Test
public void testNestedBlock() throws Exception {
- JexlScript e = JEXL.createScript("if (true) { x = 'hello'; y = 'world';" + " if (true) { x; } y; }");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("if (true) { x = 'hello'; y = 'world';" + " if (true) { x; } y; }");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals("Block result is wrong", "world", o);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/CacheTest.java b/src/test/java/org/apache/commons/jexl3/CacheTest.java
index 03f069b..b638f5e 100644
--- a/src/test/java/org/apache/commons/jexl3/CacheTest.java
+++ b/src/test/java/org/apache/commons/jexl3/CacheTest.java
@@ -86,23 +86,23 @@
return getClass().getSimpleName() + "@s#" + arg0 + ",s#" + arg1;
}
- public String compute(Integer arg) {
+ public String compute(final Integer arg) {
return getClass().getSimpleName() + "@i#" + arg;
}
- public String compute(float arg) {
+ public String compute(final float arg) {
return getClass().getSimpleName() + "@f#" + arg;
}
- public String compute(int arg0, int arg1) {
+ public String compute(final int arg0, final int arg1) {
return getClass().getSimpleName() + "@i#" + arg0 + ",i#" + arg1;
}
- public String ambiguous(Integer arg0, int arg1) {
+ public String ambiguous(final Integer arg0, final int arg1) {
return getClass().getSimpleName() + "!i#" + arg0 + ",i#" + arg1;
}
- public String ambiguous(int arg0, Integer arg1) {
+ public String ambiguous(final int arg0, final Integer arg1) {
return getClass().getSimpleName() + "!i#" + arg0 + ",i#" + arg1;
}
@@ -123,11 +123,11 @@
return "CACHED@s#" + arg0 + ",s#" + arg1;
}
- public static String COMPUTE(int arg) {
+ public static String COMPUTE(final int arg) {
return "CACHED@i#" + arg;
}
- public static String COMPUTE(int arg0, int arg1) {
+ public static String COMPUTE(final int arg0, final int arg1) {
return "CACHED@i#" + arg0 + ",i#" + arg1;
}
}
@@ -150,7 +150,7 @@
value = "Cached0:" + arg;
}
- public void setFlag(boolean b) {
+ public void setFlag(final boolean b) {
flag = Boolean.valueOf(b);
}
@@ -177,7 +177,7 @@
value = "Cached2:new";
}
- public Object get(String prop) {
+ public Object get(final String prop) {
if ("value".equals(prop)) {
return value;
} else if ("flag".equals(prop)) {
@@ -186,7 +186,7 @@
throw new RuntimeException("no such property");
}
- public void set(String p, Object v) {
+ public void set(final String p, Object v) {
if (v == null) {
v = "na";
}
@@ -210,12 +210,12 @@
}
@Override
- public Object get(Object key) {
+ public Object get(final Object key) {
return super.get(key.toString());
}
@Override
- public final Object put(String key, Object arg) {
+ public final Object put(final String key, Object arg) {
if (arg == null) {
arg = "na";
}
@@ -223,7 +223,7 @@
return super.put(key, arg);
}
- public void setflag(boolean b) {
+ public void setflag(final boolean b) {
flag = b;
}
@@ -251,7 +251,7 @@
super.set(0, "Cached4:" + arg);
}
- public void setflag(Boolean b) {
+ public void setflag(final Boolean b) {
super.set(1, b.toString());
}
@@ -283,7 +283,7 @@
* @throws Exception if anything goes wrong
*/
@SuppressWarnings("boxing")
- void runThreaded(Class<? extends Task> ctask, int loops, boolean cache) throws Exception {
+ void runThreaded(final Class<? extends Task> ctask, int loops, final boolean cache) throws Exception {
if (loops == 0) {
loops = MIX.length;
}
@@ -292,15 +292,15 @@
} else {
jexl = jexlCache;
}
- java.util.concurrent.ExecutorService execs = java.util.concurrent.Executors.newFixedThreadPool(NTHREADS);
- List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>(NTHREADS);
+ final java.util.concurrent.ExecutorService execs = java.util.concurrent.Executors.newFixedThreadPool(NTHREADS);
+ final List<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>(NTHREADS);
for (int t = 0; t < NTHREADS; ++t) {
tasks.add(jexl.newInstance(ctask, loops));
}
// let's not wait for more than a minute
- List<Future<Integer>> futures = execs.invokeAll(tasks, 60, TimeUnit.SECONDS);
+ final List<Future<Integer>> futures = execs.invokeAll(tasks, 60, TimeUnit.SECONDS);
// check that all returned loops
- for (Future<Integer> future : futures) {
+ for (final Future<Integer> future : futures) {
Assert.assertEquals(Integer.valueOf(loops), future.get());
}
}
@@ -314,7 +314,7 @@
final Map<String, Object> vars = new HashMap<String, Object>();
final JexlEvalContext jc = new JexlEvalContext(vars);
- Task(int loops) {
+ Task(final int loops) {
this.loops = loops;
}
@@ -336,15 +336,15 @@
* @param value the argument value to control
* @return the number of loops performed
*/
- public Integer runAssign(Object value) {
+ public Integer runAssign(final Object value) {
args.value = new Object[]{value};
Object result;
- JexlExpression cacheGetValue = jexl.createExpression("cache.value");
- JexlExpression cacheSetValue = jexl.createExpression("cache.value = value");
+ final JexlExpression cacheGetValue = jexl.createExpression("cache.value");
+ final JexlExpression cacheSetValue = jexl.createExpression("cache.value = value");
for (int l = 0; l < loops; ++l) {
- int px = (int) Thread.currentThread().getId();
- int mix = MIX[(l + px) % MIX.length];
+ final int px = (int) Thread.currentThread().getId();
+ final int mix = MIX[(l + px) % MIX.length];
vars.put("cache", args.ca[mix]);
vars.put("value", args.value[0]);
@@ -372,7 +372,7 @@
* A task to check assignment.
*/
public static class AssignTask extends Task {
- public AssignTask(int loops) {
+ public AssignTask(final int loops) {
super(loops);
}
@@ -386,7 +386,7 @@
* A task to check null assignment.
*/
public static class AssignNullTask extends Task {
- public AssignNullTask(int loops) {
+ public AssignNullTask(final int loops) {
super(loops);
}
@@ -400,7 +400,7 @@
* A task to check boolean assignment.
*/
public static class AssignBooleanTask extends Task {
- public AssignBooleanTask(int loops) {
+ public AssignBooleanTask(final int loops) {
super(loops);
}
@@ -410,15 +410,15 @@
}
/** The actual test function. */
- private Integer runAssignBoolean(Boolean value) {
+ private Integer runAssignBoolean(final Boolean value) {
args.value = new Object[]{value};
- JexlExpression cacheGetValue = jexl.createExpression("cache.flag");
- JexlExpression cacheSetValue = jexl.createExpression("cache.flag = value");
+ final JexlExpression cacheGetValue = jexl.createExpression("cache.flag");
+ final JexlExpression cacheSetValue = jexl.createExpression("cache.flag = value");
Object result;
for (int l = 0; l < loops; ++l) {
- int px = (int) Thread.currentThread().getId();
- int mix = MIX[(l + px) % MIX.length];
+ final int px = (int) Thread.currentThread().getId();
+ final int mix = MIX[(l + px) % MIX.length];
vars.put("cache", args.ca[mix]);
vars.put("value", args.value[0]);
@@ -438,7 +438,7 @@
* A task to check list assignment.
*/
public static class AssignListTask extends Task {
- public AssignListTask(int loops) {
+ public AssignListTask(final int loops) {
super(loops);
}
@@ -450,7 +450,7 @@
/** The actual test function. */
private Integer runAssignList() {
args.value = new Object[]{"foo"};
- java.util.ArrayList<String> c1 = new java.util.ArrayList<String>(2);
+ final java.util.ArrayList<String> c1 = new java.util.ArrayList<String>(2);
c1.add("foo");
c1.add("bar");
args.ca = new Object[]{
@@ -458,13 +458,13 @@
c1
};
- JexlExpression cacheGetValue = jexl.createExpression("cache.0");
- JexlExpression cacheSetValue = jexl.createExpression("cache[0] = value");
+ final JexlExpression cacheGetValue = jexl.createExpression("cache.0");
+ final JexlExpression cacheSetValue = jexl.createExpression("cache[0] = value");
Object result;
for (int l = 0; l < loops; ++l) {
- int px = (int) Thread.currentThread().getId();
- int mix = MIX[(l + px) % MIX.length] % args.ca.length;
+ final int px = (int) Thread.currentThread().getId();
+ final int mix = MIX[(l + px) % MIX.length] % args.ca.length;
vars.put("cache", args.ca[mix]);
vars.put("value", args.value[0]);
@@ -523,7 +523,7 @@
* A task to check method calls.
*/
public static class ComputeTask extends Task {
- public ComputeTask(int loops) {
+ public ComputeTask(final int loops) {
super(loops);
}
@@ -532,17 +532,17 @@
args.ca = new Object[]{args.c0, args.c1, args.c2};
args.value = new Object[]{new Integer(2), "quux"};
//jexl.setDebug(true);
- JexlExpression compute2 = jexl.createExpression("cache.compute(a0, a1)");
- JexlExpression compute1 = jexl.createExpression("cache.compute(a0)");
- JexlExpression compute1null = jexl.createExpression("cache.compute(a0)");
- JexlExpression ambiguous = jexl.createExpression("cache.ambiguous(a0, a1)");
+ final JexlExpression compute2 = jexl.createExpression("cache.compute(a0, a1)");
+ final JexlExpression compute1 = jexl.createExpression("cache.compute(a0)");
+ final JexlExpression compute1null = jexl.createExpression("cache.compute(a0)");
+ final JexlExpression ambiguous = jexl.createExpression("cache.ambiguous(a0, a1)");
//jexl.setDebug(false);
Object result = null;
String expected = null;
for (int l = 0; l < loops; ++l) {
- int mix = MIX[l % MIX.length] % args.ca.length;
- Object value = args.value[l % args.value.length];
+ final int mix = MIX[l % MIX.length] % args.ca.length;
+ final Object value = args.value[l % args.value.length];
vars.put("cache", args.ca[mix]);
if (value instanceof String) {
@@ -565,7 +565,7 @@
vars.put("a1", Short.valueOf((short) 19));
result = ambiguous.evaluate(jc);
Assert.fail("should have thrown an exception");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
// throws due to ambiguous exception
}
}
@@ -586,10 +586,10 @@
vars.put("a0", null);
result = compute1null.evaluate(jc);
Assert.fail("should have thrown an exception");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
// throws due to ambiguous exception
- String sany = xany.getMessage();
- String tname = getClass().getName();
+ final String sany = xany.getMessage();
+ final String tname = getClass().getName();
if (!sany.startsWith(tname)) {
Assert.fail("debug mode should carry caller information, "
+ sany + ", "
@@ -614,13 +614,13 @@
public static class JexlContextNS extends JexlEvalContext {
final Map<String, Object> funcs;
- JexlContextNS(Map<String, Object> vars, Map<String, Object> funcs) {
+ JexlContextNS(final Map<String, Object> vars, final Map<String, Object> funcs) {
super(vars);
this.funcs = funcs;
}
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
return funcs.get(name);
}
@@ -633,23 +633,23 @@
* @param cache
* @throws Exception
*/
- void doCOMPUTE(TestCacheArguments x, int loops, boolean cache) throws Exception {
+ void doCOMPUTE(final TestCacheArguments x, int loops, final boolean cache) throws Exception {
if (loops == 0) {
loops = MIX.length;
}
if (!cache) {
jexl.clearCache();
}
- Map<String, Object> vars = new HashMap<String, Object>();
- java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
- JexlEvalContext jc = new JexlContextNS(vars, funcs);
- JexlExpression compute2 = jexl.createExpression("cached:COMPUTE(a0, a1)");
- JexlExpression compute1 = jexl.createExpression("cached:COMPUTE(a0)");
+ final Map<String, Object> vars = new HashMap<String, Object>();
+ final java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
+ final JexlEvalContext jc = new JexlContextNS(vars, funcs);
+ final JexlExpression compute2 = jexl.createExpression("cached:COMPUTE(a0, a1)");
+ final JexlExpression compute1 = jexl.createExpression("cached:COMPUTE(a0)");
Object result = null;
String expected = null;
for (int l = 0; l < loops; ++l) {
- int mix = MIX[l % MIX.length] % x.ca.length;
- Object value = x.value[l % x.value.length];
+ final int mix = MIX[l % MIX.length] % x.ca.length;
+ final Object value = x.value[l % x.value.length];
funcs.put("cached", x.ca[mix]);
if (value instanceof String) {
@@ -682,7 +682,7 @@
@Test
public void testCOMPUTENoCache() throws Exception {
- TestCacheArguments args = new TestCacheArguments();
+ final TestCacheArguments args = new TestCacheArguments();
args.ca = new Object[]{
Cached.class, Cached1.class, Cached2.class
};
@@ -692,7 +692,7 @@
@Test
public void testCOMPUTECache() throws Exception {
- TestCacheArguments args = new TestCacheArguments();
+ final TestCacheArguments args = new TestCacheArguments();
args.ca = new Object[]{
Cached.class, Cached1.class, Cached2.class
};
diff --git a/src/test/java/org/apache/commons/jexl3/CaptureLog.java b/src/test/java/org/apache/commons/jexl3/CaptureLog.java
index b216c65..08a2a37 100644
--- a/src/test/java/org/apache/commons/jexl3/CaptureLog.java
+++ b/src/test/java/org/apache/commons/jexl3/CaptureLog.java
@@ -23,10 +23,10 @@
* A log implementation to help control tests results.
*/
public class CaptureLog implements Log {
- private List<Object[]> captured = new ArrayList<Object[]>();
+ private final List<Object[]> captured = new ArrayList<Object[]>();
static Object caller() {
- StackTraceElement[] stack = new Exception().fillInStackTrace().getStackTrace();
+ final StackTraceElement[] stack = new Exception().fillInStackTrace().getStackTrace();
return stack[2];
}
@@ -34,7 +34,7 @@
this("org.apache.commons.jexl3");
}
- public CaptureLog(String name) {
+ public CaptureLog(final String name) {
//super(name);
}
@@ -42,9 +42,9 @@
return captured.isEmpty();
}
- public int count(String type) {
+ public int count(final String type) {
int count = 0;
- for (Object[] l : captured) {
+ for (final Object[] l : captured) {
if (type.equals(l[0].toString())) {
count += 1;
}
@@ -53,47 +53,47 @@
}
//@Override
- public boolean isEnabledFor(int /*Priority*/ p) {
+ public boolean isEnabledFor(final int /*Priority*/ p) {
return true;
}
@Override
- public void debug(Object o) {
+ public void debug(final Object o) {
captured.add(new Object[]{"debug", caller(), o});
}
@Override
- public void debug(Object o, Throwable thrwbl) {
+ public void debug(final Object o, final Throwable thrwbl) {
captured.add(new Object[]{"debug", caller(), o, thrwbl});
}
@Override
- public void error(Object o) {
+ public void error(final Object o) {
captured.add(new Object[]{"error", caller(), o});
}
@Override
- public void error(Object o, Throwable thrwbl) {
+ public void error(final Object o, final Throwable thrwbl) {
captured.add(new Object[]{"error", caller(), o, thrwbl});
}
@Override
- public void fatal(Object o) {
+ public void fatal(final Object o) {
captured.add(new Object[]{"fatal", caller(), o});
}
@Override
- public void fatal(Object o, Throwable thrwbl) {
+ public void fatal(final Object o, final Throwable thrwbl) {
captured.add(new Object[]{"fatal", caller(), o, thrwbl});
}
@Override
- public void info(Object o) {
+ public void info(final Object o) {
captured.add(new Object[]{"info", caller(), o});
}
@Override
- public void info(Object o, Throwable thrwbl) {
+ public void info(final Object o, final Throwable thrwbl) {
captured.add(new Object[]{"info", caller(), o, thrwbl});
}
@@ -128,22 +128,22 @@
}
@Override
- public void trace(Object o) {
+ public void trace(final Object o) {
captured.add(new Object[]{"trace", caller(), o});
}
@Override
- public void trace(Object o, Throwable thrwbl) {
+ public void trace(final Object o, final Throwable thrwbl) {
captured.add(new Object[]{"trace", caller(), o, thrwbl});
}
@Override
- public void warn(Object o) {
+ public void warn(final Object o) {
captured.add(new Object[]{"warn", caller(), o});
}
@Override
- public void warn(Object o, Throwable thrwbl) {
+ public void warn(final Object o, final Throwable thrwbl) {
captured.add(new Object[]{"warn", caller(), o, thrwbl});
}
diff --git a/src/test/java/org/apache/commons/jexl3/ClassCreator.java b/src/test/java/org/apache/commons/jexl3/ClassCreator.java
index ef76010..03570d6 100644
--- a/src/test/java/org/apache/commons/jexl3/ClassCreator.java
+++ b/src/test/java/org/apache/commons/jexl3/ClassCreator.java
@@ -61,14 +61,14 @@
*/
private static boolean comSunToolsJavacMain() {
try {
- Class<?> javac = ClassCreatorTest.class.getClassLoader().loadClass("com.sun.tools.javac.Main");
+ final Class<?> javac = ClassCreatorTest.class.getClassLoader().loadClass("com.sun.tools.javac.Main");
return javac != null;
- } catch (Exception xany) {
+ } catch (final Exception xany) {
return false;
}
}
- public ClassCreator(JexlEngine theJexl, File theBase) throws Exception {
+ public ClassCreator(final JexlEngine theJexl, final File theBase) throws Exception {
//jexl = theJexl;
base = theBase;
}
@@ -83,7 +83,7 @@
loader = null;
}
- public void setSeed(int s) {
+ public void setSeed(final int s) {
seed = s;
className = "foo" + s;
sourceName = className + ".java";
@@ -92,7 +92,7 @@
loader = null;
}
- public void setCtorBody(String arg) {
+ public void setCtorBody(final String arg) {
ctorBody = arg;
}
@@ -106,7 +106,7 @@
public ClassLoader getClassLoader() throws Exception {
if (loader == null) {
- URL classpath = (new File(base, Integer.toString(seed))).toURI().toURL();
+ final URL classpath = (new File(base, Integer.toString(seed))).toURI().toURL();
loader = new URLClassLoader(new URL[]{classpath}, getClass().getClassLoader());
}
return loader;
@@ -116,29 +116,29 @@
return createClass(false);
}
- public Class<?> createClass(boolean ftor) throws Exception {
+ public Class<?> createClass(final boolean ftor) throws Exception {
// generate, compile & validate
generate(ftor);
- Class<?> clazz = compile();
+ final Class<?> clazz = compile();
if (clazz == null) {
throw new Exception("failed to compile foo" + seed);
}
if (ftor) {
return clazz;
}
- Object v = validate(clazz);
+ final Object v = validate(clazz);
if (v instanceof Integer && (Integer) v == seed) {
return clazz;
}
throw new Exception("failed to validate foo" + seed);
}
- Object newInstance(Class<?> clazz, JexlContext ctxt) throws Exception {
+ Object newInstance(final Class<?> clazz, final JexlContext ctxt) throws Exception {
return clazz.getConstructor(JexlContext.class).newInstance(ctxt);
}
- void generate(boolean ftor) throws Exception {
- FileWriter aWriter = new FileWriter(new File(packageDir, sourceName), false);
+ void generate(final boolean ftor) throws Exception {
+ final FileWriter aWriter = new FileWriter(new File(packageDir, sourceName), false);
aWriter.write("package ");
aWriter.write(GEN_PACKAGE);
aWriter.write(";\n");
@@ -190,34 +190,34 @@
// }
Class<?> compile() throws Exception {
- String source = packageDir.getPath() + "/" + sourceName;
- JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
- DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<JavaFileObject>();
- StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticsCollector, null, null);
- Iterable<? extends JavaFileObject> compilationUnits = fileManager
+ final String source = packageDir.getPath() + "/" + sourceName;
+ final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ final DiagnosticCollector<JavaFileObject> diagnosticsCollector = new DiagnosticCollector<JavaFileObject>();
+ final StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticsCollector, null, null);
+ final Iterable<? extends JavaFileObject> compilationUnits = fileManager
.getJavaFileObjectsFromStrings(Collections.singletonList(source));
- List<String> options = new ArrayList<String>();
+ final List<String> options = new ArrayList<String>();
options.add("-classpath");
// only add hbase classes to classpath. This is a little bit tricky: assume
// the classpath is {hbaseSrc}/target/classes.
- String currentDir = new File(".").getAbsolutePath();
- String classpath = currentDir + File.separator + "target" + File.separator + "classes"
+ final String currentDir = new File(".").getAbsolutePath();
+ final String classpath = currentDir + File.separator + "target" + File.separator + "classes"
//+ System.getProperty("path.separator") + System.getProperty("java.class.path")
+ System.getProperty("path.separator") + System.getProperty("surefire.test.class.path");
options.add(classpath);
//LOG.debug("Setting classpath to: " + classpath);
- JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnosticsCollector, options,
+ final JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnosticsCollector, options,
null, compilationUnits);
- boolean success = task.call();
+ final boolean success = task.call();
fileManager.close();
if (success) {
return getClassLoader().loadClass(GEN_CLASS + className);
} else {
- List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticsCollector.getDiagnostics();
- for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
+ final List<Diagnostic<? extends JavaFileObject>> diagnostics = diagnosticsCollector.getDiagnostics();
+ for (final Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
// read error dertails from the diagnostic object
System.out.println(diagnostic.getMessage(null));
@@ -226,11 +226,11 @@
}
}
- Object validate(Class<?> clazz) throws Exception {
- Class<?>[] params = {};
- Object[] paramsObj = {};
- Object iClass = clazz.newInstance();
- Method thisMethod = clazz.getDeclaredMethod("getValue", params);
+ Object validate(final Class<?> clazz) throws Exception {
+ final Class<?>[] params = {};
+ final Object[] paramsObj = {};
+ final Object iClass = clazz.newInstance();
+ final Method thisMethod = clazz.getDeclaredMethod("getValue", params);
return thisMethod.invoke(iClass, paramsObj);
}
diff --git a/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java b/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java
index 157b2ed..fe6cbae 100644
--- a/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ClassCreatorTest.java
@@ -61,9 +61,9 @@
deleteDirectory(base);
}
- private void deleteDirectory(File dir) {
+ private void deleteDirectory(final File dir) {
if (dir.isDirectory()) {
- for (File file : dir.listFiles()) {
+ for (final File file : dir.listFiles()) {
if (file.isFile()) {
file.delete();
}
@@ -80,7 +80,7 @@
private final byte[] space = new byte[MEGA];
private final int id;
- public BigObject(int id) {
+ public BigObject(final int id) {
this.id = id;
}
@@ -91,14 +91,14 @@
// A weak reference on class
static final class ClassReference extends WeakReference<Class<?>> {
- ClassReference(Class<?> clazz, ReferenceQueue<Object> queue) {
+ ClassReference(final Class<?> clazz, final ReferenceQueue<Object> queue) {
super(clazz, queue);
}
}
// A soft reference on instance
static final class InstanceReference extends SoftReference<Object> {
- InstanceReference(Object obj, ReferenceQueue<Object> queue) {
+ InstanceReference(final Object obj, final ReferenceQueue<Object> queue) {
super(obj, queue);
}
}
@@ -110,21 +110,21 @@
logger.warn("unable to create classes");
return;
}
- ClassCreator cctor = new ClassCreator(jexl, base);
+ final ClassCreator cctor = new ClassCreator(jexl, base);
cctor.setSeed(1);
- Class<?> foo1 = cctor.createClass();
+ final Class<?> foo1 = cctor.createClass();
Assert.assertEquals("foo1", foo1.getSimpleName());
cctor.clear();
}
@Test
public void testFunctorOne() throws Exception {
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
ctxt.set("value", 1000);
// create a class foo1 with a ctor whose body gets a value
// from the context to initialize its value
- ClassCreator cctor = new ClassCreator(jexl, base);
+ final ClassCreator cctor = new ClassCreator(jexl, base);
cctor.setSeed(1);
cctor.setCtorBody("value = (Integer) ctxt.get(\"value\") + 10;");
Class<?> foo1 = cctor.createClass(true);
@@ -136,7 +136,7 @@
cctor.clear();
// check we can invoke that ctor using its name or class
- JexlScript script = jexl.createScript("(c)->{ new(c).value; }");
+ final JexlScript script = jexl.createScript("(c)->{ new(c).value; }");
result = script.execute(ctxt, foo1);
Assert.assertEquals(1010, result);
result = script.execute(ctxt, foo1.getName());
@@ -145,7 +145,7 @@
// re-create foo1 with a different body!
cctor.setSeed(1);
cctor.setCtorBody("value = (Integer) ctxt.get(\"value\") + 99;");
- Class<?> foo11 = cctor.createClass(true);
+ final Class<?> foo11 = cctor.createClass(true);
Assert.assertEquals("foo1", foo1.getSimpleName());
Assert.assertNotSame(foo11, foo1);
foo1 = foo11;
@@ -161,14 +161,14 @@
}
public static class NsTest implements JexlContext.NamespaceFunctor {
- private String className;
+ private final String className;
- public NsTest(String cls) {
+ public NsTest(final String cls) {
className = cls;
}
@Override
- public Object createFunctor(JexlContext context) {
- JexlEngine jexl = JexlEngine.getThreadEngine();
+ public Object createFunctor(final JexlContext context) {
+ final JexlEngine jexl = JexlEngine.getThreadEngine();
return jexl.newInstance(className, context);
}
@@ -184,16 +184,16 @@
functorTwo(new NsTest(ClassCreator.GEN_CLASS + "foo2"));
}
- void functorTwo(Object nstest) throws Exception {
+ void functorTwo(final Object nstest) throws Exception {
// create jexl2 with a 'test' namespace
- Map<String, Object> ns = new HashMap<String, Object>();
+ final Map<String, Object> ns = new HashMap<String, Object>();
ns.put("test", nstest);
- JexlEngine jexl2 = new JexlBuilder().namespaces(ns).create();
- JexlContext ctxt = new MapContext();
+ final JexlEngine jexl2 = new JexlBuilder().namespaces(ns).create();
+ final JexlContext ctxt = new MapContext();
ctxt.set("value", 1000);
// inject 'foo2' as test namespace functor class
- ClassCreator cctor = new ClassCreator(jexl, base);
+ final ClassCreator cctor = new ClassCreator(jexl, base);
cctor.setSeed(2);
cctor.setCtorBody("value = (Integer) ctxt.get(\"value\") + 10;");
Class<?> foo1 = cctor.createClass(true);
@@ -205,14 +205,14 @@
cctor.clear();
// check the namespace functor behavior
- JexlScript script = jexl2.createScript("test:getValue()");
+ final JexlScript script = jexl2.createScript("test:getValue()");
result = script.execute(ctxt, foo1.getName());
Assert.assertEquals(1010, result);
// change the body
cctor.setSeed(2);
cctor.setCtorBody("value = (Integer) ctxt.get(\"value\") + 99;");
- Class<?> foo11 = cctor.createClass(true);
+ final Class<?> foo11 = cctor.createClass(true);
Assert.assertEquals("foo2", foo1.getSimpleName());
Assert.assertNotSame(foo11, foo1);
foo1 = foo11;
@@ -227,10 +227,10 @@
@Test
public void testFunctorThree() throws Exception {
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
ctxt.set("value", 1000);
- ClassCreator cctor = new ClassCreator(jexl, base);
+ final ClassCreator cctor = new ClassCreator(jexl, base);
cctor.setSeed(2);
cctor.setCtorBody("value = (Integer) ctxt.get(\"value\") + 10;");
Class<?> foo1 = cctor.createClass(true);
@@ -241,17 +241,17 @@
jexl.setClassLoader(cctor.getClassLoader());
cctor.clear();
- Map<String, Object> ns = new HashMap<String, Object>();
+ final Map<String, Object> ns = new HashMap<String, Object>();
ns.put("test", foo1);
- JexlEngine jexl2 = new JexlBuilder().namespaces(ns).create();
+ final JexlEngine jexl2 = new JexlBuilder().namespaces(ns).create();
- JexlScript script = jexl2.createScript("test:getValue()");
+ final JexlScript script = jexl2.createScript("test:getValue()");
result = script.execute(ctxt, foo1.getName());
Assert.assertEquals(1010, result);
cctor.setSeed(2);
cctor.setCtorBody("value = (Integer) ctxt.get(\"value\") + 99;");
- Class<?> foo11 = cctor.createClass(true);
+ final Class<?> foo11 = cctor.createClass(true);
Assert.assertEquals("foo2", foo1.getSimpleName());
Assert.assertNotSame(foo11, foo1);
foo1 = foo11;
@@ -272,18 +272,18 @@
}
int pass = 0;
int gced = -1;
- ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
- List<Reference<?>> stuff = new ArrayList<Reference<?>>();
+ final ReferenceQueue<Object> queue = new ReferenceQueue<Object>();
+ final List<Reference<?>> stuff = new ArrayList<Reference<?>>();
// keeping a reference on methods prevent classes from being GCed
// List<Object> mm = new ArrayList<Object>();
- JexlExpression expr = jexl.createExpression("foo.value");
- JexlExpression newx = jexl.createExpression("foo = new(clazz)");
- JexlEvalContext context = new JexlEvalContext();
- JexlOptions options = context.getEngineOptions();
+ final JexlExpression expr = jexl.createExpression("foo.value");
+ final JexlExpression newx = jexl.createExpression("foo = new(clazz)");
+ final JexlEvalContext context = new JexlEvalContext();
+ final JexlOptions options = context.getEngineOptions();
options.setStrict(false);
options.setSilent(true);
- ClassCreator cctor = new ClassCreator(jexl, base);
+ final ClassCreator cctor = new ClassCreator(jexl, base);
for (int i = 0; i < LOOPS && gced < 0; ++i) {
cctor.setSeed(i);
Class<?> clazz;
@@ -328,7 +328,7 @@
// attempt to force GC:
// while we still have a MB free, create & store big objects
for (int b = 0; b < 1024 && Runtime.getRuntime().freeMemory() > MEGA; ++b) {
- BigObject big = new BigObject(b);
+ final BigObject big = new BigObject(b);
stuff.add(new InstanceReference(big, queue));
}
// hint it...
@@ -336,7 +336,7 @@
// let's see if some weak refs got collected
boolean qr = false;
while (queue.poll() != null) {
- Reference<?> ref = queue.remove(1);
+ final Reference<?> ref = queue.remove(1);
if (ref instanceof ClassReference) {
gced = i;
qr = true;
@@ -359,11 +359,11 @@
public static class TwoCtors {
int value;
- public TwoCtors(int v) {
+ public TwoCtors(final int v) {
this.value = v;
}
- public TwoCtors(Number x) {
+ public TwoCtors(final Number x) {
this.value = -x.intValue();
}
@@ -374,7 +374,7 @@
@Test
public void testBasicCtor() throws Exception {
- JexlScript s = jexl.createScript("(c, v)->{ var ct2 = new(c, v); ct2.value; }");
+ final JexlScript s = jexl.createScript("(c, v)->{ var ct2 = new(c, v); ct2.value; }");
Object r = s.execute(null, TwoCtors.class, 10);
Assert.assertEquals(10, r);
r = s.execute(null, TwoCtors.class, 5 + 5);
@@ -388,11 +388,11 @@
public static class ContextualCtor {
int value = -1;
- public ContextualCtor(JexlContext ctxt) {
+ public ContextualCtor(final JexlContext ctxt) {
value = (Integer) ctxt.get("value");
}
- public ContextualCtor(JexlContext ctxt, int v) {
+ public ContextualCtor(final JexlContext ctxt, final int v) {
value = (Integer) ctxt.get("value") + v;
}
@@ -403,7 +403,7 @@
@Test
public void testContextualCtor() throws Exception {
- MapContext ctxt = new MapContext();
+ final MapContext ctxt = new MapContext();
ctxt.set("value", 42);
JexlScript s = jexl.createScript("(c)->{ new(c).value }");
Object r = s.execute(ctxt, ContextualCtor.class);
diff --git a/src/test/java/org/apache/commons/jexl3/ContextNamespaceTest.java b/src/test/java/org/apache/commons/jexl3/ContextNamespaceTest.java
index 6f38994..2569542 100644
--- a/src/test/java/org/apache/commons/jexl3/ContextNamespaceTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ContextNamespaceTest.java
@@ -35,15 +35,15 @@
public static class Taxes {
private final double vat;
- public Taxes(TaxesContext ctxt) {
+ public Taxes(final TaxesContext ctxt) {
vat = ctxt.getVAT();
}
- public Taxes(double d) {
+ public Taxes(final double d) {
vat = d;
}
- public double vat(double n) {
+ public double vat(final double n) {
return (n * vat) / 100.;
}
}
@@ -55,12 +55,12 @@
private Taxes taxes = null;
private final double vat;
- TaxesContext(double vat) {
+ TaxesContext(final double vat) {
this.vat = vat;
}
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
if ("taxes".equals(name)) {
if (taxes == null) {
taxes = new Taxes(vat);
@@ -77,45 +77,45 @@
@Test
public void testThreadedContext() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- TaxesContext context = new TaxesContext(18.6);
- String strs = "taxes:vat(1000)";
- JexlScript staxes = jexl.createScript(strs);
- Object result = staxes.execute(context);
+ final JexlEngine jexl = new JexlBuilder().create();
+ final TaxesContext context = new TaxesContext(18.6);
+ final String strs = "taxes:vat(1000)";
+ final JexlScript staxes = jexl.createScript(strs);
+ final Object result = staxes.execute(context);
Assert.assertEquals(186., result);
}
@Test
public void testNamespacePragma() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext context = new TaxesContext(18.6);
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext context = new TaxesContext(18.6);
// local namespace tax declared
- String strs =
+ final String strs =
"#pragma jexl.namespace.tax org.apache.commons.jexl3.ContextNamespaceTest$Taxes\n"
+ "tax:vat(2000)";
- JexlScript staxes = jexl.createScript(strs);
- Object result = staxes.execute(context);
+ final JexlScript staxes = jexl.createScript(strs);
+ final Object result = staxes.execute(context);
Assert.assertEquals(372., result);
}
@Test
public void testNamespacePragmaString() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext context = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext context = new MapContext();
// local namespace str declared
- String strs =
+ final String strs =
"#pragma jexl.namespace.str java.lang.String\n"
+ "str:format('%04d', 42)";
- JexlScript staxes = jexl.createScript(strs);
- Object result = staxes.execute(context);
+ final JexlScript staxes = jexl.createScript(strs);
+ final Object result = staxes.execute(context);
Assert.assertEquals("0042", result);
}
public static class Vat {
private double vat;
- Vat(double vat) {
+ Vat(final double vat) {
this.vat = vat;
}
@@ -123,7 +123,7 @@
return vat;
}
- public void setVAT(double vat) {
+ public void setVAT(final double vat) {
this.vat = vat;
}
@@ -131,16 +131,16 @@
throw new UnsupportedOperationException("no way");
}
- public void setvat(double vat) {
+ public void setvat(final double vat) {
throw new UnsupportedOperationException("no way");
}
}
@Test
public void testObjectContext() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).silent(false).create();
- Vat vat = new Vat(18.6);
- ObjectContext<Vat> ctxt = new ObjectContext<Vat>(jexl, vat);
+ final JexlEngine jexl = new JexlBuilder().strict(true).silent(false).create();
+ final Vat vat = new Vat(18.6);
+ final ObjectContext<Vat> ctxt = new ObjectContext<Vat>(jexl, vat);
Assert.assertEquals(18.6d, (Double) ctxt.get("VAT"), 0.0001d);
ctxt.set("VAT", 20.0d);
Assert.assertEquals(20.0d, (Double) ctxt.get("VAT"), 0.0001d);
@@ -148,14 +148,14 @@
try {
ctxt.get("vat");
Assert.fail("should have failed");
- } catch(JexlException.Property xprop) {
+ } catch(final JexlException.Property xprop) {
//
}
try {
ctxt.set("vat", 33.0d);
Assert.fail("should have failed");
- } catch(JexlException.Property xprop) {
+ } catch(final JexlException.Property xprop) {
//
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/DoWhileTest.java b/src/test/java/org/apache/commons/jexl3/DoWhileTest.java
index 9c017f5..370606b 100644
--- a/src/test/java/org/apache/commons/jexl3/DoWhileTest.java
+++ b/src/test/java/org/apache/commons/jexl3/DoWhileTest.java
@@ -33,7 +33,7 @@
@Test
public void testSimpleWhileFalse() throws Exception {
JexlScript e = JEXL.createScript("do {} while (false)");
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
Object o = e.execute(jc);
Assert.assertNull("Result is not null", o);
@@ -46,7 +46,7 @@
@Test
public void testWhileExecutesExpressionWhenLooping() throws Exception {
JexlScript e = JEXL.createScript("do x = x + 1 while (x < 10)");
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("x", 1);
Object o = e.execute(jc);
@@ -67,12 +67,12 @@
@Test
public void testWhileWithBlock() throws Exception {
- JexlScript e = JEXL.createScript("do { x = x + 1; y = y * 2; } while (x < 10)");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("do { x = x + 1; y = y * 2; } while (x < 10)");
+ final JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
jc.set("y", new Integer(1));
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is wrong", new Integer(512), o);
Assert.assertEquals("x is wrong", new Integer(10), jc.get("x"));
Assert.assertEquals("y is wrong", new Integer(512), jc.get("y"));
@@ -81,10 +81,10 @@
@Test
public void testForEachBreakInsideFunction() throws Exception {
try {
- JexlScript e = JEXL.createScript("for (i : 1..2) { y = function() { break; } }");
+ final JexlScript e = JEXL.createScript("for (i : 1..2) { y = function() { break; } }");
Assert.fail("break is out of loop!");
- } catch (JexlException.Parsing xparse) {
- String str = xparse.detailedMessage();
+ } catch (final JexlException.Parsing xparse) {
+ final String str = xparse.detailedMessage();
Assert.assertTrue(str.contains("break"));
}
}
@@ -92,49 +92,49 @@
@Test
public void testForEachContinueInsideFunction() throws Exception {
try {
- JexlScript e = JEXL.createScript("for (i : 1..2) { y = function() { continue; } }");
+ final JexlScript e = JEXL.createScript("for (i : 1..2) { y = function() { continue; } }");
Assert.fail("continue is out of loop!");
- } catch (JexlException.Parsing xparse) {
- String str = xparse.detailedMessage();
+ } catch (final JexlException.Parsing xparse) {
+ final String str = xparse.detailedMessage();
Assert.assertTrue(str.contains("continue"));
}
}
@Test
public void testForEachLambda() throws Exception {
- JexlScript e = JEXL.createScript("(x)->{ for (i : 1..2) { continue; var y = function() { 42; } break; } }");
+ final JexlScript e = JEXL.createScript("(x)->{ for (i : 1..2) { continue; var y = function() { 42; } break; } }");
Assert.assertNotNull(e);
}
@Test
public void testEmptyBody() throws Exception {
- JexlScript e = JEXL.createScript("var i = 0; do ; while((i+=1) < 10); i");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("var i = 0; do ; while((i+=1) < 10); i");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals(10, o);
}
@Test
public void testEmptyStmtBody() throws Exception {
- JexlScript e = JEXL.createScript("var i = 0; do {} while((i+=1) < 10); i");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("var i = 0; do {} while((i+=1) < 10); i");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals(10, o);
}
@Test
public void testWhileEmptyBody() throws Exception {
- JexlScript e = JEXL.createScript("var i = 0; while((i+=1) < 10); i");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("var i = 0; while((i+=1) < 10); i");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals(10, o);
}
@Test
public void testWhileEmptyStmtBody() throws Exception {
- JexlScript e = JEXL.createScript("var i = 0; while((i+=1) < 10) {}; i");
- JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript("var i = 0; while((i+=1) < 10) {}; i");
+ final JexlContext jc = new MapContext();
+ final Object o = e.execute(jc);
Assert.assertEquals(10, o);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/ExceptionTest.java b/src/test/java/org/apache/commons/jexl3/ExceptionTest.java
index 49cabae..ed851dd 100644
--- a/src/test/java/org/apache/commons/jexl3/ExceptionTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ExceptionTest.java
@@ -36,7 +36,7 @@
throw new NullPointerException("ThrowNPE");
}
- public void setFail(boolean f) {
+ public void setFail(final boolean f) {
doThrow = f;
if (f) {
throw new NullPointerException("ThrowNPE/set");
@@ -53,67 +53,67 @@
@Test
public void testWrappedEx() throws Exception {
- JexlEngine jexl = new Engine();
- JexlExpression e = jexl.createExpression("npe()");
- JexlContext jc = new ObjectContext<ThrowNPE>(jexl, new ThrowNPE());
+ final JexlEngine jexl = new Engine();
+ final JexlExpression e = jexl.createExpression("npe()");
+ final JexlContext jc = new ObjectContext<ThrowNPE>(jexl, new ThrowNPE());
try {
e.evaluate(jc);
Assert.fail("Should have thrown NPE");
- } catch (JexlException xany) {
- Throwable xth = xany.getCause();
+ } catch (final JexlException xany) {
+ final Throwable xth = xany.getCause();
Assert.assertEquals(NullPointerException.class, xth.getClass());
}
}
@Test
public void testWrappedExmore() throws Exception {
- JexlEngine jexl = new Engine();
- ThrowNPE npe = new ThrowNPE();
+ final JexlEngine jexl = new Engine();
+ final ThrowNPE npe = new ThrowNPE();
try {
- Object r = jexl.getProperty(npe, "foo");
+ final Object r = jexl.getProperty(npe, "foo");
Assert.fail("Should have thrown JexlException.Property");
- } catch (JexlException.Property xany) {
- Throwable xth = xany.getCause();
+ } catch (final JexlException.Property xany) {
+ final Throwable xth = xany.getCause();
Assert.assertNull(xth);
}
try {
jexl.setProperty(npe, "foo", 42);
Assert.fail("Should have thrown JexlException.Property");
- } catch (JexlException.Property xany) {
- Throwable xth = xany.getCause();
+ } catch (final JexlException.Property xany) {
+ final Throwable xth = xany.getCause();
Assert.assertNull(xth);
}
- boolean b = (Boolean) jexl.getProperty(npe, "fail");
+ final boolean b = (Boolean) jexl.getProperty(npe, "fail");
Assert.assertFalse(b);
try {
jexl.setProperty(npe, "fail", false);
jexl.setProperty(npe, "fail", true);
Assert.fail("Should have thrown JexlException.Property");
- } catch (JexlException.Property xany) {
- Throwable xth = xany.getCause();
+ } catch (final JexlException.Property xany) {
+ final Throwable xth = xany.getCause();
Assert.assertEquals(NullPointerException.class, xth.getClass());
}
try {
jexl.getProperty(npe, "fail");
Assert.fail("Should have thrown JexlException.Property");
- } catch (JexlException.Property xany) {
- Throwable xth = xany.getCause();
+ } catch (final JexlException.Property xany) {
+ final Throwable xth = xany.getCause();
Assert.assertEquals(NullPointerException.class, xth.getClass());
}
try {
jexl.invokeMethod(npe, "foo", 42);
Assert.fail("Should have thrown JexlException.Method");
- } catch (JexlException.Method xany) {
- Throwable xth = xany.getCause();
+ } catch (final JexlException.Method xany) {
+ final Throwable xth = xany.getCause();
Assert.assertNull(xth);
}
try {
jexl.invokeMethod(npe, "npe");
Assert.fail("Should have thrown NullPointerException");
- } catch (JexlException.Method xany) {
- Throwable xth = xany.getCause();
+ } catch (final JexlException.Method xany) {
+ final Throwable xth = xany.getCause();
Assert.assertEquals(NullPointerException.class, xth.getClass());
}
}
@@ -122,10 +122,10 @@
// JEXL-73
@Test
public void testEx() throws Exception {
- JexlEngine jexl = createEngine(false);
- JexlExpression e = jexl.createExpression("c.e * 6");
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final JexlExpression e = jexl.createExpression("c.e * 6");
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
// make unknown vars throw
@@ -134,8 +134,8 @@
try {
/* Object o = */ e.evaluate(ctxt);
Assert.fail("c not defined as variable should throw");
- } catch (JexlException.Variable xjexl) {
- String msg = xjexl.getMessage();
+ } catch (final JexlException.Variable xjexl) {
+ final String msg = xjexl.getMessage();
Assert.assertTrue(msg.indexOf("variable 'c.e'") > 0);
}
@@ -145,8 +145,8 @@
try {
/* Object o = */ e.evaluate(ctxt);
Assert.fail("c.e as null operand should throw");
- } catch (JexlException.Variable xjexl) {
- String msg = xjexl.getMessage();
+ } catch (final JexlException.Variable xjexl) {
+ final String msg = xjexl.getMessage();
Assert.assertTrue(msg.indexOf("variable 'c.e'") > 0);
}
@@ -155,7 +155,7 @@
try {
/* Object o = */ e.evaluate(ctxt);
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
Assert.fail("c.e in expr should not throw");
}
@@ -165,8 +165,8 @@
try {
/* Object o = */ e.evaluate(ctxt);
Assert.fail("c.e not accessible as property should throw");
- } catch (JexlException.Property xjexl) {
- String msg = xjexl.getMessage();
+ } catch (final JexlException.Property xjexl) {
+ final String msg = xjexl.getMessage();
Assert.assertTrue(msg.indexOf("property 'e") > 0);
}
}
@@ -174,10 +174,10 @@
// null local vars and strict arithmetic effects
@Test
public void testExVar() throws Exception {
- JexlEngine jexl = createEngine(false);
- JexlScript e = jexl.createScript("(x)->{ x * 6 }");
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final JexlScript e = jexl.createScript("(x)->{ x * 6 }");
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
// make unknown vars throw
@@ -187,16 +187,16 @@
try {
/* Object o = */ e.execute(ctxt);
Assert.fail("x is null, should throw");
- } catch (JexlException xjexl) {
- String msg = xjexl.getMessage();
+ } catch (final JexlException xjexl) {
+ final String msg = xjexl.getMessage();
Assert.assertTrue(msg.indexOf("null") > 0);
}
// allow null operands
options.setStrictArithmetic(false);
try {
- Object o = e.execute(ctxt, (Object) null);
- } catch (JexlException.Variable xjexl) {
+ final Object o = e.execute(ctxt, (Object) null);
+ } catch (final JexlException.Variable xjexl) {
Assert.fail("arithmetic allows null operands, should not throw");
}
}
@@ -204,10 +204,10 @@
// Unknown vars and properties versus null operands
@Test
public void testExMethod() throws Exception {
- JexlEngine jexl = createEngine(false);
- JexlExpression e = jexl.createExpression("c.e.foo()");
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final JexlExpression e = jexl.createExpression("c.e.foo()");
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
// make unknown vars throw
@@ -216,8 +216,8 @@
try {
/* Object o = */ e.evaluate(ctxt);
Assert.fail("c not declared as variable should throw");
- } catch (JexlException.Variable xjexl) {
- String msg = xjexl.getMessage();
+ } catch (final JexlException.Variable xjexl) {
+ final String msg = xjexl.getMessage();
Assert.assertTrue(msg.indexOf("variable 'c.e'") > 0);
}
@@ -227,8 +227,8 @@
try {
/* Object o = */ e.evaluate(ctxt);
Assert.fail("c.e as null operand should throw");
- } catch (JexlException xjexl) {
- String msg = xjexl.getMessage();
+ } catch (final JexlException xjexl) {
+ final String msg = xjexl.getMessage();
Assert.assertTrue(msg.indexOf("variable 'c.e'") > 0);
}
}
@@ -251,10 +251,10 @@
doTest206(src, true, false);
doTest206(src, true, true);
}
- private void doTest206(String src, boolean strict, boolean silent) throws Exception {
- CaptureLog l = new CaptureLog();
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().logger(l).strict(strict).silent(silent).create();
+ private void doTest206(final String src, final boolean strict, final boolean silent) throws Exception {
+ final CaptureLog l = new CaptureLog();
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().logger(l).strict(strict).silent(silent).create();
JexlScript e;
Object r = -1;
e = jexl.createScript(src);
@@ -263,7 +263,7 @@
if (strict && !silent) {
Assert.fail("should have thrown an exception");
}
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
if (!strict || silent) {
Assert.fail(src + ": should not have thrown an exception");
}
diff --git a/src/test/java/org/apache/commons/jexl3/FeaturesTest.java b/src/test/java/org/apache/commons/jexl3/FeaturesTest.java
index 8255f4d..c2adea5 100644
--- a/src/test/java/org/apache/commons/jexl3/FeaturesTest.java
+++ b/src/test/java/org/apache/commons/jexl3/FeaturesTest.java
@@ -41,25 +41,25 @@
* @param scripts
* @throws Exception
*/
- private void checkFeature(JexlFeatures features, String[] scripts) throws Exception {
- for (String script : scripts) {
- JexlScript ctl = JEXL.createScript(script);
+ private void checkFeature(final JexlFeatures features, final String[] scripts) throws Exception {
+ for (final String script : scripts) {
+ final JexlScript ctl = JEXL.createScript(script);
Assert.assertNotNull(ctl);
try {
- JexlScript e = jexl.createScript(features, null, script);
+ final JexlScript e = jexl.createScript(features, null, script);
Assert.fail("should fail parse: " + script);
- } catch (JexlException.Parsing xfeature) {
- String msg = xfeature.getMessage();
+ } catch (final JexlException.Parsing xfeature) {
+ final String msg = xfeature.getMessage();
Assert.assertNotNull(msg);
}
}
}
- private void assertOk(JexlFeatures features, String[] scripts) {
- for(String str : scripts) {
+ private void assertOk(final JexlFeatures features, final String[] scripts) {
+ for(final String str : scripts) {
try {
- JexlScript e = jexl.createScript(str);
- } catch (JexlException.Feature xfeature) {
+ final JexlScript e = jexl.createScript(str);
+ } catch (final JexlException.Feature xfeature) {
Assert.fail(str + " :: should not fail parse: " + xfeature.getMessage());
}
}
@@ -67,8 +67,8 @@
@Test
public void testNoScript() throws Exception {
- JexlFeatures f = new JexlFeatures().script(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().script(false);
+ final String[] scripts = new String[]{
"if (false) { block(); }",
"{ noway(); }",
"while(true);",
@@ -79,8 +79,8 @@
@Test
public void testNoLoop() throws Exception {
- JexlFeatures f = new JexlFeatures().loops(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().loops(false);
+ final String[] scripts = new String[]{
"while(true);",
"for(var i : {0 .. 10}) { bar(i); }"
};
@@ -89,8 +89,8 @@
@Test
public void testNoLambda() throws Exception {
- JexlFeatures f = new JexlFeatures().lambda(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().lambda(false);
+ final String[] scripts = new String[]{
"var x = ()->{ return 0 };",
"()->{ return 0 };",
"(x, y)->{ return 0 };",
@@ -103,8 +103,8 @@
@Test
public void testNoNew() throws Exception {
- JexlFeatures f = new JexlFeatures().newInstance(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().newInstance(false);
+ final String[] scripts = new String[]{
"return new(clazz);",
"new('java.math.BigDecimal', 12) + 1"
};
@@ -113,8 +113,8 @@
@Test
public void testNoSideEffects() throws Exception {
- JexlFeatures f = new JexlFeatures().sideEffect(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().sideEffect(false);
+ final String[] scripts = new String[]{
"x = 1",
"x.y = 1",
"x().y = 1",
@@ -133,8 +133,8 @@
@Test
public void testNoSideEffectsGlobal() throws Exception {
- JexlFeatures f = new JexlFeatures().sideEffectGlobal(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().sideEffectGlobal(false);
+ final String[] scripts = new String[]{
"x = 1",
"x.y = 1",
"x().y = 1",
@@ -153,10 +153,10 @@
// these should all fail with x undeclared as local, thus x as global
checkFeature(f, scripts);
// same ones with x as local should work
- for(String str : scripts) {
+ for(final String str : scripts) {
try {
- JexlScript e = jexl.createScript("var x = foo(); " + str);
- } catch (JexlException.Feature xfeature) {
+ final JexlScript e = jexl.createScript("var x = foo(); " + str);
+ } catch (final JexlException.Feature xfeature) {
Assert.fail(str + " :: should not fail parse: " + xfeature.getMessage());
}
}
@@ -164,8 +164,8 @@
@Test
public void testNoLocals() throws Exception {
- JexlFeatures f = new JexlFeatures().localVar(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().localVar(false);
+ final String[] scripts = new String[]{
"var x = 0;",
"(x)->{ x }"
};
@@ -174,14 +174,14 @@
@Test
public void testReservedVars() throws Exception {
- JexlFeatures f = new JexlFeatures().reservedNames(Arrays.asList("foo", "bar"));
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().reservedNames(Arrays.asList("foo", "bar"));
+ final String[] scripts = new String[]{
"var foo = 0;",
"(bar)->{ bar }",
"var f = function(bar) { bar; }"
};
checkFeature(f, scripts);
- String[] scriptsOk = new String[]{
+ final String[] scriptsOk = new String[]{
"var foo0 = 0;",
"(bar1)->{ bar }",
"var f = function(bar2) { bar2; }"
@@ -191,9 +191,9 @@
@Test
public void testArrayRefs() throws Exception {
- JexlFeatures f = new JexlFeatures().arrayReferenceExpr(false);
+ final JexlFeatures f = new JexlFeatures().arrayReferenceExpr(false);
- String[] scripts = new String[]{
+ final String[] scripts = new String[]{
"x[y]",
"x['a'][b]",
"x()['a'][b]",
@@ -202,7 +202,7 @@
checkFeature(f, scripts);
assertOk(f, scripts);
// same ones with constant array refs should work
- String[] scriptsOk = new String[]{
+ final String[] scriptsOk = new String[]{
"x['y']",
"x['a'][1]",
"x()['a']['b']",
@@ -212,8 +212,8 @@
}
@Test
public void testMethodCalls() throws Exception {
- JexlFeatures f = new JexlFeatures().methodCall(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().methodCall(false);
+ final String[] scripts = new String[]{
"x.y(z)",
"x['a'].m(b)",
"x()['a'](b)",
@@ -221,7 +221,7 @@
};
checkFeature(f, scripts);
// same ones with constant array refs should work
- String[] scriptsOk = new String[]{
+ final String[] scriptsOk = new String[]{
"x('y')",
"x('a')[1]",
"x()['a']['b']",
@@ -231,8 +231,8 @@
@Test
public void testStructuredLiterals() throws Exception {
- JexlFeatures f = new JexlFeatures().structuredLiteral(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().structuredLiteral(false);
+ final String[] scripts = new String[]{
"{1, 2, 3}",
"[1, 2, 3]",
"{ 1 :'one', 2 : 'two', 3 : 'three' }",
@@ -244,8 +244,8 @@
@Test
public void testAnnotations() throws Exception {
- JexlFeatures f = new JexlFeatures().annotation(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().annotation(false);
+ final String[] scripts = new String[]{
"@synchronized(2) { return 42; }",
"@two var x = 3;"
};
@@ -255,8 +255,8 @@
@Test
public void testPragma() throws Exception {
- JexlFeatures f = new JexlFeatures().pragma(false);
- String[] scripts = new String[]{
+ final JexlFeatures f = new JexlFeatures().pragma(false);
+ final String[] scripts = new String[]{
"#pragma foo 42",
"#pragma foo 'bar'\n@two var x = 3;"
};
@@ -266,13 +266,13 @@
@Test
public void testMixedFeatures() throws Exception {
// no new, no local, no lambda, no loops, no-side effects
- JexlFeatures f = new JexlFeatures()
+ final JexlFeatures f = new JexlFeatures()
.newInstance(false)
.localVar(false)
.lambda(false)
.loops(false)
.sideEffectGlobal(false);
- String[] scripts = new String[]{
+ final String[] scripts = new String[]{
"return new(clazz);",
"()->{ return 0 };",
"var x = 0;",
diff --git a/src/test/java/org/apache/commons/jexl3/Foo.java b/src/test/java/org/apache/commons/jexl3/Foo.java
index 8a7ea20..d37a154 100644
--- a/src/test/java/org/apache/commons/jexl3/Foo.java
+++ b/src/test/java/org/apache/commons/jexl3/Foo.java
@@ -55,11 +55,11 @@
return "String : quux";
}
- public String repeat(String str) {
+ public String repeat(final String str) {
return "Repeat : " + str;
}
- public String convertBoolean(boolean b)
+ public String convertBoolean(final boolean b)
{
return "Boolean : " + b;
}
@@ -70,7 +70,7 @@
public List<String> getCheeseList()
{
- ArrayList<String> answer = new ArrayList<String>();
+ final ArrayList<String> answer = new ArrayList<String>();
answer.add("cheddar");
answer.add("edam");
answer.add("brie");
@@ -97,7 +97,7 @@
return true;
}
- public int square(int value)
+ public int square(final int value)
{
return value * value;
}
@@ -123,7 +123,7 @@
return property1;
}
- public void setProperty1(String newValue) {
+ public void setProperty1(final String newValue) {
property1 = newValue;
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/ForEachTest.java b/src/test/java/org/apache/commons/jexl3/ForEachTest.java
index ab4790a..317b5cf 100644
--- a/src/test/java/org/apache/commons/jexl3/ForEachTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ForEachTest.java
@@ -38,140 +38,140 @@
@Test
public void testForEachWithEmptyStatement() throws Exception {
- JexlScript e = JEXL.createScript("for(item : list) ;");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("for(item : list) ;");
+ final JexlContext jc = new MapContext();
jc.set("list", Collections.emptyList());
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertNull("Result is not null", o);
}
@Test
public void testForEachWithEmptyList() throws Exception {
- JexlScript e = JEXL.createScript("for(item : list) 1+1");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("for(item : list) 1+1");
+ final JexlContext jc = new MapContext();
jc.set("list", Collections.emptyList());
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertNull("Result is not null", o);
}
@Test
public void testForEachWithArray() throws Exception {
- JexlScript e = JEXL.createScript("for(item : list) item");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("for(item : list) item");
+ final JexlContext jc = new MapContext();
jc.set("list", new Object[]{"Hello", "World"});
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", "World", o);
}
@Test
public void testForEachWithCollection() throws Exception {
- JexlScript e = JEXL.createScript("for(var item : list) item");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("for(var item : list) item");
+ final JexlContext jc = new MapContext();
jc.set("list", Arrays.asList(new Object[]{"Hello", "World"}));
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", "World", o);
}
@Test
public void testForEachWithEnumeration() throws Exception {
- JexlScript e = JEXL.createScript("for(var item : list) item");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("for(var item : list) item");
+ final JexlContext jc = new MapContext();
jc.set("list", new StringTokenizer("Hello,World", ","));
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", "World", o);
}
@Test
public void testForEachWithIterator() throws Exception {
- JexlScript e = JEXL.createScript("for(var item : list) item");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("for(var item : list) item");
+ final JexlContext jc = new MapContext();
jc.set("list", Arrays.asList(new Object[]{"Hello", "World"}).iterator());
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", "World", o);
}
@Test
public void testForEachWithMap() throws Exception {
- JexlScript e = JEXL.createScript("for(item : list) item");
- JexlContext jc = new MapContext();
- Map<?, ?> map = System.getProperties();
- String lastProperty = (String) new ArrayList<Object>(map.values()).get(System.getProperties().size() - 1);
+ final JexlScript e = JEXL.createScript("for(item : list) item");
+ final JexlContext jc = new MapContext();
+ final Map<?, ?> map = System.getProperties();
+ final String lastProperty = (String) new ArrayList<Object>(map.values()).get(System.getProperties().size() - 1);
jc.set("list", map);
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", lastProperty, o);
}
@Test
public void testForEachWithBlock() throws Exception {
- JexlScript exs0 = JEXL.createScript("for(var in : list) { x = x + in; }");
- JexlContext jc = new MapContext();
+ final JexlScript exs0 = JEXL.createScript("for(var in : list) { x = x + in; }");
+ final JexlContext jc = new MapContext();
jc.set("list", new Object[]{2, 3});
jc.set("x", new Integer(1));
- Object o = exs0.execute(jc);
+ final Object o = exs0.execute(jc);
Assert.assertEquals("Result is wrong", new Integer(6), o);
Assert.assertEquals("x is wrong", new Integer(6), jc.get("x"));
}
@Test
public void testForEachWithListExpression() throws Exception {
- JexlScript e = JEXL.createScript("for(var item : list.keySet()) item");
- JexlContext jc = new MapContext();
- Map<?, ?> map = System.getProperties();
- String lastKey = (String) new ArrayList<Object>(map.keySet()).get(System.getProperties().size() - 1);
+ final JexlScript e = JEXL.createScript("for(var item : list.keySet()) item");
+ final JexlContext jc = new MapContext();
+ final Map<?, ?> map = System.getProperties();
+ final String lastKey = (String) new ArrayList<Object>(map.keySet()).get(System.getProperties().size() - 1);
jc.set("list", map);
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", lastKey, o);
}
@Test
public void testForEachWithProperty() throws Exception {
- JexlScript e = JEXL.createScript("for(var item : list.cheeseList) item");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("for(var item : list.cheeseList) item");
+ final JexlContext jc = new MapContext();
jc.set("list", new Foo());
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", "brie", o);
}
@Test
public void testForEachWithIteratorMethod() throws Exception {
- JexlScript e = JEXL.createScript("for(var item : list.cheezy) item");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("for(var item : list.cheezy) item");
+ final JexlContext jc = new MapContext();
jc.set("list", new Foo());
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", "brie", o);
}
@Test
public void testForEachBreakMethod() throws Exception {
- JexlScript e = JEXL.createScript(
+ final JexlScript e = JEXL.createScript(
"var rr = -1; for(var item : [1, 2, 3 ,4 ,5, 6]) { if (item == 3) { rr = item; break; }} rr"
);
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("list", new Foo());
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", 3, o);
}
@Test
public void testForEachContinueMethod() throws Exception {
- JexlScript e = JEXL.createScript(
+ final JexlScript e = JEXL.createScript(
"var rr = 0; for(var item : [1, 2, 3 ,4 ,5, 6]) { if (item <= 3) continue; rr = rr + item;}"
);
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("list", new Foo());
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not last evaluated expression", 15, o);
}
@Test
public void testForEachContinueBroken() throws Exception {
try {
- JexlScript e = JEXL.createScript("var rr = 0; continue;");
+ final JexlScript e = JEXL.createScript("var rr = 0; continue;");
Assert.fail("continue is out of loop!");
- } catch (JexlException.Parsing xparse) {
- String str = xparse.detailedMessage();
+ } catch (final JexlException.Parsing xparse) {
+ final String str = xparse.detailedMessage();
Assert.assertTrue(str.contains("continue"));
}
}
@@ -179,10 +179,10 @@
@Test
public void testForEachBreakBroken() throws Exception {
try {
- JexlScript e = JEXL.createScript("if (true) { break; }");
+ final JexlScript e = JEXL.createScript("if (true) { break; }");
Assert.fail("break is out of loop!");
- } catch (JexlException.Parsing xparse) {
- String str = xparse.detailedMessage();
+ } catch (final JexlException.Parsing xparse) {
+ final String str = xparse.detailedMessage();
Assert.assertTrue(str.contains("break"));
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/IfTest.java b/src/test/java/org/apache/commons/jexl3/IfTest.java
index 2309705..7f4077e 100644
--- a/src/test/java/org/apache/commons/jexl3/IfTest.java
+++ b/src/test/java/org/apache/commons/jexl3/IfTest.java
@@ -37,10 +37,10 @@
*/
@Test
public void testSimpleIfTrue() throws Exception {
- JexlScript e = JEXL.createScript("if (true) 1");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if (true) 1");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not 1", new Integer(1), o);
}
@@ -51,10 +51,10 @@
*/
@Test
public void testSimpleIfFalse() throws Exception {
- JexlScript e = JEXL.createScript("if (false) 1");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if (false) 1");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertNull("Return value is not empty", o);
}
@@ -65,10 +65,10 @@
*/
@Test
public void testSimpleElse() throws Exception {
- JexlScript e = JEXL.createScript("if (false) 1 else 2;");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if (false) 1 else 2;");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not 2", new Integer(2), o);
}
@@ -79,10 +79,10 @@
*/
@Test
public void testBlockIfTrue() throws Exception {
- JexlScript e = JEXL.createScript("if (true) { 'hello'; }");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if (true) { 'hello'; }");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is wrong", "hello", o);
}
@@ -93,10 +93,10 @@
*/
@Test
public void testBlockElse() throws Exception {
- JexlScript e = JEXL.createScript("if (false) {1} else {2 ; 3}");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if (false) {1} else {2 ; 3}");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is wrong", new Integer(3), o);
}
@@ -107,17 +107,17 @@
*/
@Test
public void testIfWithSimpleExpression() throws Exception {
- JexlScript e = JEXL.createScript("if (x == 1) true;");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if (x == 1) true;");
+ final JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not true", Boolean.TRUE, o);
}
@Test
public void testIfElseIfExpression() throws Exception {
- JexlScript e = JEXL.createScript("if (x == 1) { 10; } else if (x == 2) 20 else 30", "x");
+ final JexlScript e = JEXL.createScript("if (x == 1) { 10; } else if (x == 2) 20 else 30", "x");
Object o = e.execute(null, 1);
Assert.assertEquals(10, o);
o = e.execute(null, 2);
@@ -128,7 +128,7 @@
@Test
public void testIfElseIfReturnExpression0() throws Exception {
- JexlScript e = JEXL.createScript(
+ final JexlScript e = JEXL.createScript(
"if (x == 1) return 10; if (x == 2) return 20; else if (x == 3) return 30 else { return 40 }",
"x");
Object o = e.execute(null, 1);
@@ -143,7 +143,7 @@
@Test
public void testIfElseIfReturnExpression() throws Exception {
- JexlScript e = JEXL.createScript(
+ final JexlScript e = JEXL.createScript(
"if (x == 1) return 10; if (x == 2) return 20 else if (x == 3) return 30; else return 40;",
"x");
Object o = e.execute(null, 1);
@@ -163,11 +163,11 @@
*/
@Test
public void testIfWithArithmeticExpression() throws Exception {
- JexlScript e = JEXL.createScript("if ((x * 2) + 1 == 5) true;");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if ((x * 2) + 1 == 5) true;");
+ final JexlContext jc = new MapContext();
jc.set("x", new Integer(2));
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not true", Boolean.TRUE, o);
}
@@ -178,11 +178,11 @@
*/
@Test
public void testIfWithDecimalArithmeticExpression() throws Exception {
- JexlScript e = JEXL.createScript("if ((x * 2) == 5) true");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if ((x * 2) == 5) true");
+ final JexlContext jc = new MapContext();
jc.set("x", new Float(2.5f));
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not true", Boolean.TRUE, o);
}
@@ -193,12 +193,12 @@
*/
@Test
public void testIfWithAssignment() throws Exception {
- JexlScript e = JEXL.createScript("if ((x * 2) == 5) {y = 1} else {y = 2;}");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("if ((x * 2) == 5) {y = 1} else {y = 2;}");
+ final JexlContext jc = new MapContext();
jc.set("x", new Float(2.5f));
e.execute(jc);
- Object result = jc.get("y");
+ final Object result = jc.get("y");
Assert.assertEquals("y has the wrong value", new Integer(1), result);
}
@@ -209,11 +209,11 @@
*/
@Test
public void testTernary() throws Exception {
- JexlEngine jexl = JEXL;
+ final JexlEngine jexl = JEXL;
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
- JexlExpression e = jexl.createExpression("x.y.z = foo ?'bar':'quux'");
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
+ final JexlExpression e = jexl.createExpression("x.y.z = foo ?'bar':'quux'");
Object o;
// undefined foo
@@ -269,10 +269,10 @@
*/
@Test
public void testTernaryShorthand() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
- JexlExpression e = JEXL.createExpression("x.y.z = foo?:'quux'");
- JexlExpression f = JEXL.createExpression("foo??'quux'");
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
+ final JexlExpression e = JEXL.createExpression("x.y.z = foo?:'quux'");
+ final JexlExpression f = JEXL.createExpression("foo??'quux'");
Object o;
// undefined foo
@@ -395,14 +395,14 @@
@Test
public void testNullCoaelescing() throws Exception {
Object o;
- JexlEvalContext jc = new JexlEvalContext();
- JexlExpression xtrue = JEXL.createExpression("x??true");
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlExpression xtrue = JEXL.createExpression("x??true");
o = xtrue.evaluate(jc);
Assert.assertEquals("Should be true", true, o);
jc.set("x", false);
o = xtrue.evaluate(jc);
Assert.assertEquals("Should be false", false, o);
- JexlExpression yone = JEXL.createExpression("y??1");
+ final JexlExpression yone = JEXL.createExpression("y??1");
o = yone.evaluate(jc);
Assert.assertEquals("Should be 1", 1, o);
jc.set("y", 0);
@@ -414,14 +414,14 @@
@Test
public void testNullCoaelescingScript() throws Exception {
Object o;
- JexlEvalContext jc = new JexlEvalContext();
- JexlScript xtrue = JEXL.createScript("x??true");
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlScript xtrue = JEXL.createScript("x??true");
o = xtrue.execute(jc);
Assert.assertEquals("Should be true", true, o);
jc.set("x", false);
o = xtrue.execute(jc);
Assert.assertEquals("Should be false", false, o);
- JexlScript yone = JEXL.createScript("y??1");
+ final JexlScript yone = JEXL.createScript("y??1");
o = yone.execute(jc);
Assert.assertEquals("Should be 1", 1, o);
jc.set("y", 0);
@@ -433,16 +433,16 @@
@Test
public void testTernaryFail() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
- JexlExpression e = JEXL.createExpression("false ? bar : quux");
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
+ final JexlExpression e = JEXL.createExpression("false ? bar : quux");
Object o;
options.setStrict(true);
options.setSilent(false);
try {
o = e.evaluate(jc);
Assert.fail("Should have failed");
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
// OK
Assert.assertTrue(xjexl.toString().contains("quux"));
}
diff --git a/src/test/java/org/apache/commons/jexl3/Issues100Test.java b/src/test/java/org/apache/commons/jexl3/Issues100Test.java
index 67edba4..aba1e6d 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues100Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues100Test.java
@@ -53,9 +53,9 @@
@Test
public void test100() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(4).create();
- JexlContext ctxt = new MapContext();
- int[] foo = {42};
+ final JexlEngine jexl = new JexlBuilder().cache(4).create();
+ final JexlContext ctxt = new MapContext();
+ final int[] foo = {42};
ctxt.set("foo", foo);
Object value;
for (int l = 0; l < 2; ++l) {
@@ -75,7 +75,7 @@
String nameA;
String propA;
- public A105(String nameA, String propA) {
+ public A105(final String nameA, final String propA) {
this.nameA = nameA;
this.propA = propA;
}
@@ -93,15 +93,15 @@
return propA;
}
- public String uppercase(String str) {
+ public String uppercase(final String str) {
return str.toUpperCase();
}
}
@Test
public void test105() throws Exception {
- JexlContext context = new MapContext();
- JexlExpression selectExp = new Engine().createExpression("[a.propA]");
+ final JexlContext context = new MapContext();
+ final JexlExpression selectExp = new Engine().createExpression("[a.propA]");
context.set("a", new A105("a1", "p1"));
Object[] r = (Object[]) selectExp.evaluate(context);
Assert.assertEquals("p1", r[0]);
@@ -114,17 +114,17 @@
@Test
public void test106() throws Exception {
- JexlEvalContext context = new JexlEvalContext();
- JexlOptions options = context.getEngineOptions();
+ final JexlEvalContext context = new JexlEvalContext();
+ final JexlOptions options = context.getEngineOptions();
options.setStrict(true);
options.setStrictArithmetic(true);
context.set("a", new BigDecimal(1));
context.set("b", new BigDecimal(3));
- JexlEngine jexl = new Engine();
+ final JexlEngine jexl = new Engine();
try {
- Object value = jexl.createExpression("a / b").evaluate(context);
+ final Object value = jexl.createExpression("a / b").evaluate(context);
Assert.assertNotNull(value);
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
Assert.fail("should not occur");
}
options.setMathContext(MathContext.UNLIMITED);
@@ -132,14 +132,14 @@
try {
jexl.createExpression("a / b").evaluate(context);
Assert.fail("should fail");
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
//ok to fail
}
}
@Test
public void test107() throws Exception {
- String[] exprs = {
+ final String[] exprs = {
"'Q4'.toLowerCase()", "q4",
"(Q4).toLowerCase()", "q4",
"(4).toString()", "4",
@@ -150,12 +150,12 @@
"(['Q4'])[0].toLowerCase()", "q4"
};
- JexlContext context = new MapContext();
+ final JexlContext context = new MapContext();
context.set("Q4", "Q4");
- JexlEngine jexl = new Engine();
+ final JexlEngine jexl = new Engine();
for (int e = 0; e < exprs.length; e += 2) {
JexlExpression expr = jexl.createExpression(exprs[e]);
- Object expected = exprs[e + 1];
+ final Object expected = exprs[e + 1];
Object value = expr.evaluate(context);
Assert.assertEquals(expected, value);
expr = jexl.createExpression(expr.getParsedText());
@@ -168,7 +168,7 @@
public void test108() throws Exception {
JexlScript expr;
Object value;
- JexlEngine jexl = new Engine();
+ final JexlEngine jexl = new Engine();
expr = jexl.createScript("size([])");
value = expr.execute(null);
Assert.assertEquals(0, value);
@@ -200,9 +200,9 @@
@Test
public void test109() throws Exception {
- JexlEngine jexl = new Engine();
+ final JexlEngine jexl = new Engine();
Object value;
- JexlContext context = new MapContext();
+ final JexlContext context = new MapContext();
context.set("foo.bar", 40);
value = jexl.createExpression("foo.bar + 2").evaluate(context);
Assert.assertEquals(42, value);
@@ -210,10 +210,10 @@
@Test
public void test110() throws Exception {
- JexlEngine jexl = new Engine();
- String[] names = {"foo"};
+ final JexlEngine jexl = new Engine();
+ final String[] names = {"foo"};
Object value;
- JexlContext context = new MapContext();
+ final JexlContext context = new MapContext();
value = jexl.createScript("foo + 2", names).execute(context, 40);
Assert.assertEquals(42, value);
context.set("frak.foo", -40);
@@ -222,28 +222,28 @@
}
public static class RichContext extends ObjectContext<A105> {
- RichContext(JexlEngine jexl, A105 a105) {
+ RichContext(final JexlEngine jexl, final A105 a105) {
super(jexl, a105);
}
}
@Test
public void testRichContext() throws Exception {
- A105 a105 = new A105("foo", "bar");
- JexlEngine jexl = new Engine();
+ final A105 a105 = new A105("foo", "bar");
+ final JexlEngine jexl = new Engine();
Object value;
- JexlContext context = new RichContext(jexl, a105);
+ final JexlContext context = new RichContext(jexl, a105);
value = jexl.createScript("uppercase(nameA + propA)").execute(context);
Assert.assertEquals("FOOBAR", value);
}
@Test
public void test111() throws Exception {
- JexlEngine jexl = new Engine();
+ final JexlEngine jexl = new Engine();
Object value;
- JexlContext context = new MapContext();
- String strExpr = "((x>0)?\"FirstValue=\"+(y-x):\"SecondValue=\"+x)";
- JexlExpression expr = jexl.createExpression(strExpr);
+ final JexlContext context = new MapContext();
+ final String strExpr = "((x>0)?\"FirstValue=\"+(y-x):\"SecondValue=\"+x)";
+ final JexlExpression expr = jexl.createExpression(strExpr);
context.set("x", 1);
context.set("y", 10);
@@ -288,11 +288,11 @@
@Test
public void testScaleIssue() throws Exception {
- JexlEngine jexlX = new Engine();
- String expStr1 = "result == salary/month * work.percent/100.00";
- JexlExpression exp1 = jexlX.createExpression(expStr1);
- JexlEvalContext ctx = new JexlEvalContext();
- JexlOptions options = ctx.getEngineOptions();
+ final JexlEngine jexlX = new Engine();
+ final String expStr1 = "result == salary/month * work.percent/100.00";
+ final JexlExpression exp1 = jexlX.createExpression(expStr1);
+ final JexlEvalContext ctx = new JexlEvalContext();
+ final JexlOptions options = ctx.getEngineOptions();
ctx.set("result", new BigDecimal("9958.33"));
ctx.set("salary", new BigDecimal("119500.00"));
ctx.set("month", new BigDecimal("12.00"));
@@ -309,7 +309,7 @@
@Test
public void test112() throws Exception {
Object result;
- JexlEngine jexl = new Engine();
+ final JexlEngine jexl = new Engine();
result = jexl.createScript(Integer.toString(Integer.MAX_VALUE)).execute(null);
Assert.assertEquals(Integer.MAX_VALUE, result);
result = jexl.createScript(Integer.toString(Integer.MIN_VALUE + 1)).execute(null);
@@ -320,11 +320,11 @@
@Test
public void test117() throws Exception {
- JexlEngine jexl = new Engine();
- JexlExpression e = jexl.createExpression("TIMESTAMP > 20100102000000");
- JexlContext ctx = new MapContext();
+ final JexlEngine jexl = new Engine();
+ final JexlExpression e = jexl.createExpression("TIMESTAMP > 20100102000000");
+ final JexlContext ctx = new MapContext();
ctx.set("TIMESTAMP", new Long("20100103000000"));
- Object result = e.evaluate(ctx);
+ final Object result = e.evaluate(ctx);
Assert.assertTrue((Boolean) result);
}
@@ -333,63 +333,63 @@
return "OK";
}
- public String total(String tt) {
+ public String total(final String tt) {
return "total " + tt;
}
}
public static class Foo125Context extends ObjectContext<Foo125> {
- public Foo125Context(JexlEngine engine, Foo125 wrapped) {
+ public Foo125Context(final JexlEngine engine, final Foo125 wrapped) {
super(engine, wrapped);
}
}
@Test
public void test125() throws Exception {
- JexlEngine jexl = new Engine();
- JexlExpression e = jexl.createExpression("method()");
- JexlContext jc = new Foo125Context(jexl, new Foo125());
+ final JexlEngine jexl = new Engine();
+ final JexlExpression e = jexl.createExpression("method()");
+ final JexlContext jc = new Foo125Context(jexl, new Foo125());
Assert.assertEquals("OK", e.evaluate(jc));
}
@Test
public void test130a() throws Exception {
- String myName = "Test.Name";
- Object myValue = "Test.Value";
+ final String myName = "Test.Name";
+ final Object myValue = "Test.Value";
- JexlEngine myJexlEngine = new Engine();
- MapContext myMapContext = new MapContext();
+ final JexlEngine myJexlEngine = new Engine();
+ final MapContext myMapContext = new MapContext();
myMapContext.set(myName, myValue);
- Object myObjectWithTernaryConditional = myJexlEngine.createScript(myName + "?:null").execute(myMapContext);
+ final Object myObjectWithTernaryConditional = myJexlEngine.createScript(myName + "?:null").execute(myMapContext);
Assert.assertEquals(myValue, myObjectWithTernaryConditional);
}
@Test
public void test130b() throws Exception {
- String myName = "Test.Name";
- Object myValue = new Object() {
+ final String myName = "Test.Name";
+ final Object myValue = new Object() {
@Override
public String toString() {
return "Test.Value";
}
};
- JexlEngine myJexlEngine = new Engine();
- MapContext myMapContext = new MapContext();
+ final JexlEngine myJexlEngine = new Engine();
+ final MapContext myMapContext = new MapContext();
myMapContext.set(myName, myValue);
- Object myObjectWithTernaryConditional = myJexlEngine.createScript(myName + "?:null").execute(myMapContext);
+ final Object myObjectWithTernaryConditional = myJexlEngine.createScript(myName + "?:null").execute(myMapContext);
Assert.assertEquals(myValue, myObjectWithTernaryConditional);
}
@Test
public void test135() throws Exception {
- JexlEngine jexl = new Engine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = new Engine();
+ final JexlContext jc = new MapContext();
JexlScript script;
Object result;
- Map<Integer, Object> foo = new HashMap<Integer, Object>();
+ final Map<Integer, Object> foo = new HashMap<Integer, Object>();
foo.put(3, 42);
jc.set("state", foo);
@@ -432,8 +432,8 @@
@Test
public void test136() throws Exception {
- JexlEngine jexl = new Engine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = new Engine();
+ final JexlContext jc = new MapContext();
JexlScript script;
JexlExpression expr;
Object result;
@@ -469,8 +469,8 @@
// }
@Test
public void test143() throws Exception {
- JexlEngine jexl = new Engine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = new Engine();
+ final JexlContext jc = new MapContext();
JexlScript script;
Object result;
@@ -484,15 +484,15 @@
@Test
public void test144() throws Exception {
- JexlEngine jexl = new Engine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = new Engine();
+ final JexlContext jc = new MapContext();
JexlScript script;
Object result;
script = jexl.createScript("var total = 10; total('tt')");
try {
result = script.execute(jc);
Assert.fail("total() is not solvable");
- } catch (JexlException.Method ambiguous) {
+ } catch (final JexlException.Method ambiguous) {
Assert.assertEquals("total", ambiguous.getMethod());
}
}
@@ -515,30 +515,30 @@
return arr2;
}
- public void setArr(String[] arr) {
+ public void setArr(final String[] arr) {
this.arr = arr;
}
- public void setArr2(String[] arr2) {
+ public void setArr2(final String[] arr2) {
this.arr2 = arr2;
}
// Overloaded setter with different argument type.
- public void setArr2(Integer[] arr2) {
+ public void setArr2(final Integer[] arr2) {
}
}
@Test
public void test144a() throws Exception {
- JexlEngine jexl = new Engine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = new Engine();
+ final JexlContext jc = new MapContext();
jc.set("quuxClass", Quux144.class);
- JexlExpression create = jexl.createExpression("quux = new(quuxClass)");
+ final JexlExpression create = jexl.createExpression("quux = new(quuxClass)");
JexlExpression assignArray = jexl.createExpression("quux.arr = [ 'hello', 'world' ]");
- JexlExpression checkArray = jexl.createExpression("quux.arr");
+ final JexlExpression checkArray = jexl.createExpression("quux.arr");
// test with a string
- Quux144 quux = (Quux144) create.evaluate(jc);
+ final Quux144 quux = (Quux144) create.evaluate(jc);
Assert.assertNotNull("quux is null", quux);
// test with a nonempty string array
@@ -568,7 +568,7 @@
assignArray = jexl.createExpression("quux.arr2 = [ ]");
o = assignArray.evaluate(jc);
Assert.fail("The arr2 property shouldn't be set due to its ambiguity (overloaded setters with different types).");
- } catch (JexlException.Property e) {
+ } catch (final JexlException.Property e) {
//System.out.println("Expected ambiguous property setting exception: " + e);
}
Assert.assertNull("The arr2 property value should remain as null, not an empty array.", quux.arr2);
@@ -576,72 +576,72 @@
@Test
public void test147b() throws Exception {
- String[] scripts = {"var x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one", // results to 1
+ final String[] scripts = {"var x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one", // results to 1
"x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one",// results to 1
"x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x['one']",//results to 1
"var x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x['one']"// result to null?
};
- JexlEngine jexl = new Engine();
- JexlContext jc = new MapContext();
- for (String s : scripts) {
- Object o = jexl.createScript(s).execute(jc);
+ final JexlEngine jexl = new Engine();
+ final JexlContext jc = new MapContext();
+ for (final String s : scripts) {
+ final Object o = jexl.createScript(s).execute(jc);
Assert.assertEquals(1, o);
}
}
@Test
public void test147c() throws Exception {
- String[] scripts = {
+ final String[] scripts = {
"var x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one",
"x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x.one",
"x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x['one']",
"var x = new ('java.util.HashMap'); x.one = 1; x.two = 2; x['one']"
};
- JexlEngine jexl = new Engine();
- for (String s : scripts) {
- JexlContext jc = new MapContext();
- Object o = jexl.createScript(s).execute(jc);
+ final JexlEngine jexl = new Engine();
+ for (final String s : scripts) {
+ final JexlContext jc = new MapContext();
+ final Object o = jexl.createScript(s).execute(jc);
Assert.assertEquals(1, o);
}
}
@Test
public void test5115a() throws Exception {
- String str = "{\n"
+ final String str = "{\n"
+ " var x = \"A comment\";\n"
+ " var y = \"A comment\";\n"
+ "}";
- JexlEngine jexl = new Engine();
- JexlScript s = jexl.createScript(str);
+ final JexlEngine jexl = new Engine();
+ final JexlScript s = jexl.createScript(str);
}
@Test
public void test5115b() throws Exception {
- String str = "{\n"
+ final String str = "{\n"
+ " var x = \"A comment\";\n"
+ "}";
- JexlEngine jexl = new Engine();
- JexlScript s = jexl.createScript(str);
+ final JexlEngine jexl = new Engine();
+ final JexlScript s = jexl.createScript(str);
}
static final String TESTA = "src/test/scripts/testA.jexl";
@Test
public void test5115c() throws Exception {
- URL testUrl = new File(TESTA).toURI().toURL();
- JexlEngine jexl = new Engine();
- JexlScript s = jexl.createScript(testUrl);
+ final URL testUrl = new File(TESTA).toURI().toURL();
+ final JexlEngine jexl = new Engine();
+ final JexlScript s = jexl.createScript(testUrl);
}
public static class Utils {
- public <T> List<T> asList(T[] array) {
+ public <T> List<T> asList(final T[] array) {
return Arrays.asList(array);
}
- public List<Integer> asList(int[] array) {
- List<Integer> l = new ArrayList<Integer>(array.length);
- for (int i : array) {
+ public List<Integer> asList(final int[] array) {
+ final List<Integer> l = new ArrayList<Integer>(array.length);
+ for (final int i : array) {
l.add(i);
}
return l;
@@ -650,8 +650,8 @@
@Test
public void test148a() throws Exception {
- JexlEngine jexl = new Engine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = new Engine();
+ final JexlContext jc = new MapContext();
jc.set("u", new Utils());
String src = "u.asList(['foo', 'bar'])";
@@ -669,29 +669,29 @@
@Test
public void test155() throws Exception {
- JexlEngine jexlEngine = new Engine();
- JexlExpression jexlExpresssion = jexlEngine.createExpression("first.second.name");
- JexlContext jc = new MapContext();
+ final JexlEngine jexlEngine = new Engine();
+ final JexlExpression jexlExpresssion = jexlEngine.createExpression("first.second.name");
+ final JexlContext jc = new MapContext();
jc.set("first.second.name", "RIGHT");
jc.set("name", "WRONG");
- Object value = jexlExpresssion.evaluate(jc);
+ final Object value = jexlExpresssion.evaluate(jc);
Assert.assertEquals("RIGHT", value.toString());
}
public static class Question42 extends MapContext {
- public String functionA(String arg) {
+ public String functionA(final String arg) {
return "a".equals(arg) ? "A" : "";
}
- public String functionB(String arg) {
+ public String functionB(final String arg) {
return "b".equals(arg) ? "B" : "";
}
- public String functionC(String arg) {
+ public String functionC(final String arg) {
return "c".equals(arg) ? "C" : "";
}
- public String functionD(String arg) {
+ public String functionD(final String arg) {
return "d".equals(arg) ? "D" : "";
}
}
@@ -701,7 +701,7 @@
super(false);
}
- public Object and(String lhs, String rhs) {
+ public Object and(final String lhs, final String rhs) {
if (rhs.isEmpty()) {
return "";
}
@@ -711,7 +711,7 @@
return lhs + rhs;
}
- public Object or(String lhs, String rhs) {
+ public Object or(final String lhs, final String rhs) {
if (rhs.isEmpty()) {
return lhs;
}
@@ -724,27 +724,27 @@
@Test
public void testQuestion42() throws Exception {
- JexlEngine jexl = new JexlBuilder().arithmetic(new Arithmetic42()).create();
- JexlContext jc = new Question42();
+ final JexlEngine jexl = new JexlBuilder().arithmetic(new Arithmetic42()).create();
+ final JexlContext jc = new Question42();
- String str0 = "(functionA('z') | functionB('b')) & (functionC('c') | functionD('d') ) ";
- JexlExpression expr0 = jexl.createExpression(str0);
- Object value0 = expr0.evaluate(jc);
+ final String str0 = "(functionA('z') | functionB('b')) & (functionC('c') | functionD('d') ) ";
+ final JexlExpression expr0 = jexl.createExpression(str0);
+ final Object value0 = expr0.evaluate(jc);
Assert.assertEquals("BCD", value0);
- String str1 = "(functionA('z') & functionB('b')) | (functionC('c') & functionD('d') ) ";
- JexlExpression expr1 = jexl.createExpression(str1);
- Object value1 = expr1.evaluate(jc);
+ final String str1 = "(functionA('z') & functionB('b')) | (functionC('c') & functionD('d') ) ";
+ final JexlExpression expr1 = jexl.createExpression(str1);
+ final Object value1 = expr1.evaluate(jc);
Assert.assertEquals("CD", value1);
}
@Test
public void test179() throws Exception {
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
- String src = "x = new ('java.util.HashSet'); x.add(1); x";
- JexlScript e = jexl.createScript(src);
- Object o = e.execute(jc);
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final String src = "x = new ('java.util.HashSet'); x.add(1); x";
+ final JexlScript e = jexl.createScript(src);
+ final Object o = e.execute(jc);
Assert.assertTrue(o instanceof Set);
Assert.assertTrue(((Set) o).contains(1));
}
@@ -753,7 +753,7 @@
public C192() {
}
- public static Integer callme(Integer n) {
+ public static Integer callme(final Integer n) {
if (n == null) {
return null;
} else {
@@ -768,9 +768,9 @@
@Test
public void test192() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("x.y.z", C192.class);
- JexlEngine jexl = new JexlBuilder().create();
+ final JexlEngine jexl = new JexlBuilder().create();
JexlExpression js0 = jexl.createExpression("x.y.z.callme(t)");
jc.set("t", null);
Assert.assertNull(js0.evaluate(jc));
@@ -793,10 +793,10 @@
@Test
public void test199() throws Exception {
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(false)).create();
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic(false)).create();
- JexlScript e = jexl.createScript("(x, y)->{ x + y }");
+ final JexlScript e = jexl.createScript("(x, y)->{ x + y }");
Object r = e.execute(jc, true, "EURT");
Assert.assertEquals("trueEURT", r);
r = e.execute(jc, "ELSAF", false);
diff --git a/src/test/java/org/apache/commons/jexl3/Issues200Test.java b/src/test/java/org/apache/commons/jexl3/Issues200Test.java
index 937f1bc..c4db522 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues200Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues200Test.java
@@ -59,53 +59,53 @@
public static class Eval {
private JexlEngine jexl;
- public JexlScript fn(String src) {
+ public JexlScript fn(final String src) {
return jexl.createScript(src);
}
- void setJexl(JexlEngine je) {
+ void setJexl(final JexlEngine je) {
jexl = je;
}
}
@Test
public void test200() throws Exception {
- JexlContext jc = new MapContext();
- Map<String, Object> funcs = new HashMap<String, Object>();
- Eval eval = new Eval();
+ final JexlContext jc = new MapContext();
+ final Map<String, Object> funcs = new HashMap<String, Object>();
+ final Eval eval = new Eval();
funcs.put(null, eval);
- JexlEngine jexl = new JexlBuilder().namespaces(funcs).create();
+ final JexlEngine jexl = new JexlBuilder().namespaces(funcs).create();
eval.setJexl(jexl);
- String src = "var f = fn(\'(x)->{x + 42}\'); f(y)";
- JexlScript s200 = jexl.createScript(src, "y");
+ final String src = "var f = fn(\'(x)->{x + 42}\'); f(y)";
+ final JexlScript s200 = jexl.createScript(src, "y");
Assert.assertEquals(142, s200.execute(jc, 100));
Assert.assertEquals(52, s200.execute(jc, 10));
}
@Test
public void test200b() throws Exception {
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
- JexlScript e = jexl.createScript("var x = 0; var f = (y)->{ x = y; }; f(42); x");
- Object r = e.execute(jc);
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlScript e = jexl.createScript("var x = 0; var f = (y)->{ x = y; }; f(42); x");
+ final Object r = e.execute(jc);
Assert.assertEquals(0, r);
}
@Test
public void test209a() throws Exception {
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
- JexlScript e = jexl.createScript("var x = new('java.util.HashMap'); x.a = ()->{return 1}; x['a']()");
- Object r = e.execute(jc);
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlScript e = jexl.createScript("var x = new('java.util.HashMap'); x.a = ()->{return 1}; x['a']()");
+ final Object r = e.execute(jc);
Assert.assertEquals(1, r);
}
@Test
public void test209b() throws Exception {
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
- JexlScript e = jexl.createScript("var x = new('java.util.HashMap'); x['a'] = ()->{return 1}; x.a()");
- Object r = e.execute(jc);
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlScript e = jexl.createScript("var x = new('java.util.HashMap'); x['a'] = ()->{return 1}; x.a()");
+ final Object r = e.execute(jc);
Assert.assertEquals(1, r);
}
@@ -117,23 +117,23 @@
@Test
public void test210() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("v210", new T210());
- JexlEngine jexl = new JexlBuilder().strict(false).silent(false).create();
- JexlScript e = jexl.createScript("v210.npe()");
+ final JexlEngine jexl = new JexlBuilder().strict(false).silent(false).create();
+ final JexlScript e = jexl.createScript("v210.npe()");
try {
e.execute(jc);
Assert.fail("should have thrown an exception");
- } catch(JexlException xjexl) {
- Throwable th = xjexl.getCause();
+ } catch(final JexlException xjexl) {
+ final Throwable th = xjexl.getCause();
Assert.assertEquals("NPE210", th.getMessage());
}
}
@Test
public void test217() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
jc.set("foo", new int[]{0, 1, 2, 42});
JexlEngine jexl;
JexlScript e;
@@ -150,8 +150,8 @@
try {
r = e.execute(jc);
Assert.fail("should have thrown an exception");
- } catch(JexlException xjexl) {
- Throwable th = xjexl.getCause();
+ } catch(final JexlException xjexl) {
+ final Throwable th = xjexl.getCause();
Assert.assertEquals(ArrayIndexOutOfBoundsException.class, th.getClass());
}
//
@@ -163,12 +163,12 @@
@Test
public void test221() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- Map<String, Integer> map = new HashMap<String, Integer>();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final Map<String, Integer> map = new HashMap<String, Integer>();
map.put("one", 1);
jc.set("map", map);
- JexlEngine jexl = new JexlBuilder().cache(256).create();
- JexlScript e = jexl.createScript("(x)->{ map[x] }");
+ final JexlEngine jexl = new JexlBuilder().cache(256).create();
+ final JexlScript e = jexl.createScript("(x)->{ map[x] }");
Object r;
r = e.execute(jc, (Object) null);
Assert.assertNull(r);
@@ -180,16 +180,16 @@
public static class JexlArithmetic224 extends JexlArithmetic {
- public JexlArithmetic224(boolean astrict) {
+ public JexlArithmetic224(final boolean astrict) {
super(astrict);
}
- protected Object nth(Collection<?> c, int i) {
+ protected Object nth(final Collection<?> c, int i) {
if (c instanceof List) {
// tell engine to use default
return JexlEngine.TRY_FAILED;
}
- for (Object o : c) {
+ for (final Object o : c) {
if (i-- == 0) {
return o;
}
@@ -197,15 +197,15 @@
return null;
}
- public Object propertyGet(Collection<?> c, Number n) {
+ public Object propertyGet(final Collection<?> c, final Number n) {
return nth(c, n.intValue());
}
- public Object arrayGet(Collection<?> c, Number n) {
+ public Object arrayGet(final Collection<?> c, final Number n) {
return nth(c, n.intValue());
}
- public Object call(Collection<?> c, Number n) {
+ public Object call(final Collection<?> c, final Number n) {
if (c instanceof List) {
return ((List) c).get(n.intValue());
}
@@ -215,10 +215,10 @@
@Test
public void test224() throws Exception {
- List<String> a0 = Arrays.asList("one", "two");
- Set<String> a1 = new TreeSet<String>(a0);
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic224(true)).create();
+ final List<String> a0 = Arrays.asList("one", "two");
+ final Set<String> a1 = new TreeSet<String>(a0);
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().arithmetic(new JexlArithmetic224(true)).create();
Object r;
JexlScript e = jexl.createScript("(map, x)->{ map[x] }");
r = e.execute(jc, a0, 1);
@@ -245,29 +245,29 @@
@Test
public void test225() throws Exception {
- Context225 df = new Context225();
- JexlEngine jexl = new JexlBuilder().create();
+ final Context225 df = new Context225();
+ final JexlEngine jexl = new JexlBuilder().create();
- JexlExpression expression = jexl.createExpression("bar()");
+ final JexlExpression expression = jexl.createExpression("bar()");
Assert.assertEquals("bar", expression.evaluate(df));
- ObjectContext<Object> context = new ObjectContext<Object>(jexl, df);
+ final ObjectContext<Object> context = new ObjectContext<Object>(jexl, df);
Assert.assertEquals("bar", expression.evaluate(context));
}
- private static void handle(ExecutorService pool, final JexlScript script, final Map<String, Object> payload) {
+ private static void handle(final ExecutorService pool, final JexlScript script, final Map<String, Object> payload) {
pool.submit(() -> script.execute(new MapContext(payload)));
}
@Test
public void test241() throws Exception {
ExecutorService pool;
- JexlScript script = new JexlBuilder().create().createScript("`${item}`");
+ final JexlScript script = new JexlBuilder().create().createScript("`${item}`");
pool = Executors.newFixedThreadPool(4);
- Map<String, Object> m1 = new HashMap<String, Object>();
+ final Map<String, Object> m1 = new HashMap<String, Object>();
m1.put("item", "A");
- Map<String, Object> m2 = new HashMap<String, Object>();
+ final Map<String, Object> m2 = new HashMap<String, Object>();
m2.put("item", "B");
handle(pool, script, m1);
@@ -277,15 +277,15 @@
@Test
public void test242() throws Exception {
- Double a = -40.05d;
- Double b = -8.01d;
- Double c = a + b;
+ final Double a = -40.05d;
+ final Double b = -8.01d;
+ final Double c = a + b;
final JexlContext context = new MapContext();
context.set("a", a);
context.set("b", b);
- JexlEngine JEXL_ENGINE = new JexlBuilder().strict(true).silent(true).create();
- JexlExpression jsp = JEXL_ENGINE.createExpression("a + b");
- Double e = (Double) jsp.evaluate(context);
+ final JexlEngine JEXL_ENGINE = new JexlBuilder().strict(true).silent(true).create();
+ final JexlExpression jsp = JEXL_ENGINE.createExpression("a + b");
+ final Double e = (Double) jsp.evaluate(context);
Assert.assertEquals(Double.doubleToLongBits(e) + " != " + Double.doubleToLongBits(c), c,
e, 0.0);
Assert.assertEquals(Double.doubleToLongBits(e) + " != " + Double.doubleToLongBits(c), a + b, e, 0.0);
@@ -294,12 +294,12 @@
@Test
public void test243a() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(32).create();
- JexlScript script = jexl.createScript("while(true);");
+ final JexlEngine jexl = new JexlBuilder().cache(32).create();
+ final JexlScript script = jexl.createScript("while(true);");
try {
- JexlExpression expr = jexl.createExpression("while(true);");
+ final JexlExpression expr = jexl.createExpression("while(true);");
Assert.fail("should have failed!, expr do not allow 'while' statement");
- } catch (JexlException xparse) {
+ } catch (final JexlException xparse) {
// ok
}
}
@@ -307,7 +307,7 @@
public static class Foo245 {
private Object bar = null;
- void setBar(Object bar) {
+ void setBar(final Object bar) {
this.bar = bar;
}
@@ -318,17 +318,17 @@
@Test
public void test245() throws Exception {
- MapContext ctx = new MapContext();
- Foo245 foo245 = new Foo245();
+ final MapContext ctx = new MapContext();
+ final Foo245 foo245 = new Foo245();
ctx.set("foo", foo245);
- JexlEngine engine = new JexlBuilder().strict(true).safe(false).silent(false).create();
- JexlExpression foobar = engine.createExpression("foo.bar");
- JexlExpression foobaz = engine.createExpression("foo.baz");
- JexlExpression foobarbaz = engine.createExpression("foo.bar.baz");
+ final JexlEngine engine = new JexlBuilder().strict(true).safe(false).silent(false).create();
+ final JexlExpression foobar = engine.createExpression("foo.bar");
+ final JexlExpression foobaz = engine.createExpression("foo.baz");
+ final JexlExpression foobarbaz = engine.createExpression("foo.bar.baz");
// add ambiguity with null & not-null
- Object[] args = { null, 245 };
- for(Object arg : args ){
+ final Object[] args = { null, 245 };
+ for(final Object arg : args ){
foo245.setBar(arg);
// ok
Assert.assertEquals(foo245.getBar(), foobar.evaluate(ctx));
@@ -336,14 +336,14 @@
try {
foobaz.evaluate(ctx);
Assert.fail("foo.baz is not solvable, exception expected");
- } catch(JexlException xp) {
+ } catch(final JexlException xp) {
Assert.assertTrue(xp instanceof JexlException.Property);
}
// fail level 2
try {
foobarbaz.evaluate(ctx);
Assert.fail("foo.bar.baz is not solvable, exception expected");
- } catch(JexlException xp) {
+ } catch(final JexlException xp) {
Assert.assertTrue(xp instanceof JexlException.Property);
}
}
@@ -351,20 +351,20 @@
@Test
public void test256() throws Exception {
- MapContext ctx = new MapContext() {
- @Override public void set(String name, Object value) {
+ final MapContext ctx = new MapContext() {
+ @Override public void set(final String name, final Object value) {
if ("java".equals(name)) {
throw new JexlException(null, "can not set " + name);
}
super.set(name, value);
}
- @Override public Object get(String name) {
+ @Override public Object get(final String name) {
if ("java".equals(name)) {
return null;
}
return super.get(name);
}
- @Override public boolean has(String name) {
+ @Override public boolean has(final String name) {
if ("java".equals(name)) {
return false;
}
@@ -372,13 +372,13 @@
}
};
ctx.set("java.version", 10);
- JexlEngine engine = new JexlBuilder().strict(true).silent(false).create();
+ final JexlEngine engine = new JexlBuilder().strict(true).silent(false).create();
JexlScript script;
script = engine.createScript("java = 3");
try {
script.execute(ctx);
Assert.fail("should have failed!");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
// expected
}
script = engine.createScript("java.version");
@@ -387,9 +387,9 @@
@Test
public void test230() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(4).create();
- JexlContext ctxt = new MapContext();
- int[] foo = {42};
+ final JexlEngine jexl = new JexlBuilder().cache(4).create();
+ final JexlContext ctxt = new MapContext();
+ final int[] foo = {42};
ctxt.set("fo o", foo);
Object value;
for (int l = 0; l < 2; ++l) {
@@ -406,14 +406,14 @@
@Test
public void test265() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(4).create();
- JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().cache(4).create();
+ final JexlContext ctxt = new MapContext();
ctxt.set("x", 42);
Object result;
JexlScript script;
try {
script = jexl.createScript("(true) ? x : abs(1)");
- } catch (JexlException.Parsing xparse) {
+ } catch (final JexlException.Parsing xparse) {
// ambiguous, parsing fails
}
script = jexl.createScript("(true) ? (x) : abs(2)");
@@ -434,7 +434,7 @@
public static class Iterator266 implements /*Closeable,*/ Iterator<Object> {
private Iterator<Object> iterator;
- Iterator266(Iterator<Object> ator) {
+ Iterator266(final Iterator<Object> ator) {
iterator = ator;
}
@@ -457,7 +457,7 @@
if (iterator == null) {
return false;
}
- boolean n = iterator.hasNext();
+ final boolean n = iterator.hasNext();
if (!n) {
close();
}
@@ -486,31 +486,31 @@
return new LinkedList<Iterator266>();
}
};
- public Arithmetic266(boolean strict) {
+ public Arithmetic266(final boolean strict) {
super(strict);
}
- static void closeIterator(Iterator266 i266) {
- Deque<Iterator266> queue = TLS_FOREACH.get();
+ static void closeIterator(final Iterator266 i266) {
+ final Deque<Iterator266> queue = TLS_FOREACH.get();
if (queue != null) {
queue.remove(i266);
}
}
- public Iterator<?> forEach(Iterable<?> collection) {
- Iterator266 it266 = new Iterator266((Iterator<Object>) collection.iterator());
- Deque<Iterator266> queue = TLS_FOREACH.get();
+ public Iterator<?> forEach(final Iterable<?> collection) {
+ final Iterator266 it266 = new Iterator266((Iterator<Object>) collection.iterator());
+ final Deque<Iterator266> queue = TLS_FOREACH.get();
queue.addFirst(it266);
return it266;
}
- public Iterator<?> forEach(Map<?,?> collection) {
+ public Iterator<?> forEach(final Map<?,?> collection) {
return forEach(collection.values());
}
public void remove() {
- Deque<Iterator266> queue = TLS_FOREACH.get();
- Iterator266 i266 = queue.getFirst();
+ final Deque<Iterator266> queue = TLS_FOREACH.get();
+ final Iterator266 i266 = queue.getFirst();
if (i266 != null) {
i266.remove();
throw new JexlException.Continue(null);
@@ -524,17 +524,17 @@
public void test266() throws Exception {
Object result;
JexlScript script;
- JexlEngine jexl = new JexlBuilder().arithmetic(new Arithmetic266(true)).create();
- JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().arithmetic(new Arithmetic266(true)).create();
+ final JexlContext ctxt = new MapContext();
- List<Integer> li = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5 ,6));
+ final List<Integer> li = new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5 ,6));
ctxt.set("list", li);
script = jexl.createScript("for (var item : list) { if (item <= 3) remove(); } return size(list)");
result = script.execute(ctxt);
Assert.assertEquals(3, result);
Assert.assertEquals(3, li.size());
- Map<String, Integer> msi = new HashMap<String, Integer>();
+ final Map<String, Integer> msi = new HashMap<String, Integer>();
msi.put("a", 1);
msi.put("b", 2);
msi.put("c", 3);
@@ -552,8 +552,8 @@
public void test267() throws Exception {
Object result;
JexlScript script;
- JexlEngine jexl = new JexlBuilder().create();
- JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext ctxt = new MapContext();
// API declared params
script = jexl.createScript("x + y", "x", "y");
result = script.execute(ctxt, 20, 22);
@@ -572,16 +572,16 @@
@Test
public void test274() throws Exception {
JexlEngine jexl = new JexlBuilder().strict(true).safe(true).stackOverflow(5).create();
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
JexlScript script= jexl.createScript("var f = (x)->{ x > 1? x * f(x - 1) : x }; f(a)", "a");
Object result = script.execute(ctxt, 3);
Assert.assertEquals(6, result);
try {
result = script.execute(ctxt, 32);
Assert.fail("should have overflown");
- } catch(JexlException.StackOverflow xstack) {
+ } catch(final JexlException.StackOverflow xstack) {
// expected
- String sxs = xstack.toString();
+ final String sxs = xstack.toString();
Assert.assertTrue(sxs.contains("jexl"));
}
jexl = new JexlBuilder().strict(true).create();
@@ -589,38 +589,38 @@
try {
result = script.execute(ctxt, 32);
Assert.fail("should have overflown");
- } catch(JexlException.StackOverflow xstack) {
+ } catch(final JexlException.StackOverflow xstack) {
// expected
- String sxs = xstack.toString();
+ final String sxs = xstack.toString();
Assert.assertTrue(sxs.contains("jvm"));
}
}
@Test
public void test275a() throws Exception {
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
ctxt.set("out", System.out);
- JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
+ final JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
- JexlScript e = jexl.createScript("out.println(xyz)");
+ final JexlScript e = jexl.createScript("out.println(xyz)");
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.fail("should have thrown");
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.assertEquals("xyz", xvar.getVariable());
}
}
@Test
public void test275b() throws Exception {
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
//ctxt.set("out", System.out);
- JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
- JexlScript e = jexl.createScript("var xyz = xyz");
+ final JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
+ final JexlScript e = jexl.createScript("var xyz = xyz");
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.assertNull(o);
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.fail("should not have thrown");
// Assert.assertEquals("xyz", xvar.getVariable());
}
@@ -628,9 +628,9 @@
@Test
public void test275c() throws Exception {
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
//ctxt.set("out", System.out);
- JexlEngine jexl = new JexlBuilder().strict(true).safe(true).silent(true).create();
+ final JexlEngine jexl = new JexlBuilder().strict(true).safe(true).silent(true).create();
JexlScript e;
Object r;
e = jexl.createScript("(s, v)->{ var x = y ; 42; }");
@@ -638,40 +638,40 @@
try {
r = e.execute(ctxt, false, true);
Assert.assertEquals(42, r);
- } catch (JexlException.Variable xjexl) {
+ } catch (final JexlException.Variable xjexl) {
Assert.fail("should not have thrown");
}
}
@Test
public void test275d() throws Exception {
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
ctxt.set("out", System.out);
- JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
+ final JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
- JexlScript e = jexl.createScript("{ var xyz = 42 } out.println(xyz)");
+ final JexlScript e = jexl.createScript("{ var xyz = 42 } out.println(xyz)");
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.assertNull(o);
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.fail("should not have thrown" + xvar);
}
}
@Test
public void test278() throws Exception {
- String[] srcs = new String[]{
+ final String[] srcs = new String[]{
"return union x143('arg',5,6) ",
"return union y143('arg',5,6) ;",
"return union\n z143('arg',5,6) ;",
"var f =()->{ return union 143 } foo[0]"
};
- Object[] ctls = new Object[]{
+ final Object[] ctls = new Object[]{
"42","42","42", 42
};
- JexlEngine jexl = new JexlBuilder().cache(4).create();
- JexlContext ctxt = new MapContext();
- int[] foo = {42};
+ final JexlEngine jexl = new JexlBuilder().cache(4).create();
+ final JexlContext ctxt = new MapContext();
+ final int[] foo = {42};
ctxt.set("foo", foo);
ctxt.set("union", "42");
Object value;
@@ -681,8 +681,8 @@
try {
jc = jexl.createScript(src);
Assert.fail("should have failed, " + (jc != null));
- } catch(JexlException.Ambiguous xa) {
- String str = xa.toString();
+ } catch(final JexlException.Ambiguous xa) {
+ final String str = xa.toString();
Assert.assertTrue(str.contains("143"));
src = xa.tryCleanSource(src);
}
@@ -693,17 +693,17 @@
}
public static class Context279 extends MapContext {
- public String identity(String x) {
+ public String identity(final String x) {
return x;
}
- public Number identity(Number x) {
+ public Number identity(final Number x) {
return x;
}
- public String[] spread(String str) {
+ public String[] spread(final String str) {
if (str == null) {
return null;
}
- String[] a = new String[str.length()];
+ final String[] a = new String[str.length()];
for(int i = 0; i < str.length(); ++i) {
a[i] = "" + str.charAt(i);
}
@@ -716,8 +716,8 @@
final Log logger = null;//LogFactory.getLog(Issues200Test.class);
Object result;
JexlScript script;
- JexlContext ctxt = new Context279();
- String[] srcs = new String[]{
+ final JexlContext ctxt = new Context279();
+ final String[] srcs = new String[]{
"var z = null; identity(z[0]);",
"var z = null; z.0;",
"var z = null; z.foo();",
@@ -739,9 +739,9 @@
"var z = { 'y' : [null, null] }; z.y.1.foo()"
};
for (int i = 0; i < 2; ++i) {
- for (boolean strict : new boolean[]{true, false}) {
- JexlEngine jexl = new JexlBuilder().safe(false).strict(strict).create();
- for (String src : srcs) {
+ for (final boolean strict : new boolean[]{true, false}) {
+ final JexlEngine jexl = new JexlBuilder().safe(false).strict(strict).create();
+ for (final String src : srcs) {
script = jexl.createScript(src);
try {
result = script.execute(ctxt);
@@ -753,7 +753,7 @@
}
// not reachable
Assert.assertNull("non-null result ?!", result);
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
if (logger != null) {
logger.warn(ctxt.has("z") + ": " + src + ": fail, " + xvar);
}
@@ -762,7 +762,7 @@
} else {
Assert.assertTrue(src + ": " + xvar.toString(), xvar.toString().contains("z"));
}
- } catch (JexlException.Property xprop) {
+ } catch (final JexlException.Property xprop) {
if (logger != null) {
logger.warn(ctxt.has("z") + ": " + src + ": fail, " + xprop);
}
@@ -782,17 +782,17 @@
public void test279b() throws Exception {
Object result;
JexlScript script;
- JexlContext ctxt = new Context279();
+ final JexlContext ctxt = new Context279();
ctxt.set("ctxt", ctxt);
- String src = "(x)->{ spread(x)[0].toString() }";
- JexlEngine jexl = new JexlBuilder().safe(true).strict(true).create();
+ final String src = "(x)->{ spread(x)[0].toString() }";
+ final JexlEngine jexl = new JexlBuilder().safe(true).strict(true).create();
script = jexl.createScript(src);
result = script.execute(ctxt, "abc");
Assert.assertEquals("a", result);
result = null;
try {
result = script.execute(ctxt, (Object) null);
- } catch(JexlException xany) {
+ } catch(final JexlException xany) {
Assert.assertNotNull(xany.getMessage());
}
Assert.assertNull(result);
@@ -800,10 +800,10 @@
@Test
public void test285() throws Exception {
- List<String> out = new ArrayList<String>(6);
- JexlContext ctxt = new MapContext();
+ final List<String> out = new ArrayList<String>(6);
+ final JexlContext ctxt = new MapContext();
ctxt.set("$out", out);
- String src = "for(var b: ['g','h','i']) {\n"
+ final String src = "for(var b: ['g','h','i']) {\n"
+ " var c = b;\n"
+ " $out.add(c);\n"
+ "}\n"
@@ -814,66 +814,66 @@
+ " \n"
+ "$out.size()";
- JexlFeatures features = new JexlFeatures();
+ final JexlFeatures features = new JexlFeatures();
features.lexical(true);
- JexlEngine jexl = new JexlBuilder()
+ final JexlEngine jexl = new JexlBuilder()
//.features(features)
.safe(false).strict(true).lexical(true).create();
- JexlScript script = jexl.createScript(src);
- Object result = script.execute(ctxt, (Object) null);
+ final JexlScript script = jexl.createScript(src);
+ final Object result = script.execute(ctxt, (Object) null);
Assert.assertEquals(6, result);
- List<String> ctl = Arrays.asList("g", "h", "i", "j", "k", "l");
+ final List<String> ctl = Arrays.asList("g", "h", "i", "j", "k", "l");
Assert.assertEquals(ctl, out);
}
@Test
public void test285a() throws Exception {
- List<String> out = new ArrayList<String>(6);
- JexlContext ctxt = new MapContext();
+ final List<String> out = new ArrayList<String>(6);
+ final JexlContext ctxt = new MapContext();
ctxt.set("$out", out);
- String src =
+ final String src =
"for(var b: ['g','h','i']) { $out.add(b); }\n"
+ "for(b: ['j','k','l']) { $out.add(b);}\n"
+ "$out.size()";
- JexlEngine jexl = new JexlBuilder().safe(false).strict(true).lexical(false).create();
- JexlScript script = jexl.createScript(src);
- Object result = script.execute(ctxt, (Object) null);
+ final JexlEngine jexl = new JexlBuilder().safe(false).strict(true).lexical(false).create();
+ final JexlScript script = jexl.createScript(src);
+ final Object result = script.execute(ctxt, (Object) null);
Assert.assertEquals(6, result);
- List<String> ctl = Arrays.asList("g", "h", "i", "j", "k", "l");
+ final List<String> ctl = Arrays.asList("g", "h", "i", "j", "k", "l");
Assert.assertEquals(ctl, out);
}
@Test
public void test285b() throws Exception {
- List<String> out = new ArrayList<String>(6);
- JexlContext ctxt = new MapContext();
+ final List<String> out = new ArrayList<String>(6);
+ final JexlContext ctxt = new MapContext();
ctxt.set("$out", out);
- String src =
+ final String src =
"for(b: ['g','h','i']) { $out.add(b); }\n"
+ "for(var b: ['j','k','l']) { $out.add(b);}\n"
+ "$out.size()";
- JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create();
- JexlScript script = jexl.createScript(src);
- Object result = script.execute(ctxt, (Object) null);
+ final JexlEngine jexl = new JexlBuilder().safe(false).strict(true).create();
+ final JexlScript script = jexl.createScript(src);
+ final Object result = script.execute(ctxt, (Object) null);
Assert.assertEquals(6, result);
- List<String> ctl = Arrays.asList("g", "h", "i", "j", "k", "l");
+ final List<String> ctl = Arrays.asList("g", "h", "i", "j", "k", "l");
Assert.assertEquals(ctl, out);
}
@Test
public void test286() {
- String s286 = "var x = 0; for(x : 1..2){}; return x";
- JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final String s286 = "var x = 0; for(x : 1..2){}; return x";
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
Assert.assertEquals(2, jexl.createScript(s286).execute(null));
}
@Test
public void test287() {
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
- JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
String src;
JexlScript script;
Object result;
@@ -904,13 +904,13 @@
try {
result = script.execute(ctxt, 0);
Assert.fail("should have failed!");
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.assertTrue(xvar.getMessage().contains("y"));
}
options.setStrict(false);
try {
result = script.execute(ctxt, 0);
- } catch (JexlException xvar) {
+ } catch (final JexlException xvar) {
Assert.fail("should not have failed!");
}
Assert.assertNull(result);
@@ -918,8 +918,8 @@
@Test
public void test289() {
- JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
String src;
JexlScript script;
Object result;
@@ -933,14 +933,14 @@
public void test290a() throws Exception {
Object result;
JexlScript script;
- String[] srcs = new String[]{
+ final String[] srcs = new String[]{
"(x)->{ x.nothing().toString() }",
"(x)->{ x.toString().nothing() }",
"(x)->{ x.nothing().nothing() }",
};
- for (boolean safe : new boolean[]{true, false}) {
- JexlEngine jexl = new JexlBuilder().safe(safe).strict(true).create();
- for (String src : srcs) {
+ for (final boolean safe : new boolean[]{true, false}) {
+ final JexlEngine jexl = new JexlBuilder().safe(safe).strict(true).create();
+ for (final String src : srcs) {
script = jexl.createScript(src);
try {
result = script.execute(null, "abc");
@@ -949,7 +949,7 @@
} else {
Assert.assertNull("non-null result ?!", result);
}
- } catch (JexlException.Method xmethod) {
+ } catch (final JexlException.Method xmethod) {
if (safe) {
Assert.fail(src + ", should not have thrown " + xmethod);
} else {
@@ -964,12 +964,12 @@
public void test290b() throws Exception {
Object result;
JexlScript script;
- String[] srcs = new String[]{
+ final String[] srcs = new String[]{
"(x)->{ x?.nothing()?.toString() }",
"(x)->{ x.toString()?.nothing() }",
"(x)->{ x?.nothing().nothing() }",};
- JexlEngine jexl = new JexlBuilder().strict(true).create();
- for (String src : srcs) {
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
+ for (final String src : srcs) {
script = jexl.createScript(src);
result = script.execute(null, "abc");
Assert.assertNull(result);
@@ -979,13 +979,13 @@
@Test
public void test291() throws Exception {
final String str = "{1:'one'}[1]";
- JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
+ final JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
JexlExpression e = jexl.createExpression(str);
Object value = e.evaluate(ctxt);
Assert.assertEquals("one", value);
- JexlEngine sandboxedJexlEngine = new JexlBuilder().
+ final JexlEngine sandboxedJexlEngine = new JexlBuilder().
sandbox(new JexlSandbox(true)). // add a whitebox sandbox
create();
e = sandboxedJexlEngine.createExpression(str);
@@ -995,9 +995,9 @@
@Test
public void testTemplate6565a() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JxltEngine jexlt = jexl.createJxltEngine();
- String source =
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JxltEngine jexlt = jexl.createJxltEngine();
+ final String source =
"$$ var res = '';\n" +
"$$ var meta = session.data['METADATA'];\n" +
"$$ if (meta) {\n" +
@@ -1008,19 +1008,19 @@
"$$ }\n" +
"$$ }\n" +
"${res}\n";
- JxltEngine.Template script = jexlt.createTemplate("$$", new StringReader(source));
+ final JxltEngine.Template script = jexlt.createTemplate("$$", new StringReader(source));
Assert.assertNotNull(script);
- TemplateDebugger dbg = new TemplateDebugger();
- String refactored = dbg.debug(script) ? dbg.toString() : "";
+ final TemplateDebugger dbg = new TemplateDebugger();
+ final String refactored = dbg.debug(script) ? dbg.toString() : "";
Assert.assertNotNull(refactored);
Assert.assertEquals(source, refactored);
}
@Test
public void testTemplate6565b() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JxltEngine jexlt = jexl.createJxltEngine();
- String source =
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JxltEngine jexlt = jexl.createJxltEngine();
+ final String source =
"$$ var res = '';\n" +
"$$ var meta = session.data['METADATA'];\n" +
"$$ if (meta) {\n" +
@@ -1031,10 +1031,10 @@
"${res}\n" +
"$$ }\n" +
"$$ }\n";
- JxltEngine.Template script = jexlt.createTemplate("$$", new StringReader(source));
+ final JxltEngine.Template script = jexlt.createTemplate("$$", new StringReader(source));
Assert.assertNotNull(script);
- TemplateDebugger dbg = new TemplateDebugger();
- String refactored = dbg.debug(script) ? dbg.toString() : "";
+ final TemplateDebugger dbg = new TemplateDebugger();
+ final String refactored = dbg.debug(script) ? dbg.toString() : "";
Assert.assertNotNull(refactored);
Assert.assertEquals(source, refactored);
}
@@ -1046,7 +1046,7 @@
return sz;
}
- public int size(int x) {
+ public int size(final int x) {
return sz + x;
}
@@ -1057,9 +1057,9 @@
@Test
public void test298() throws Exception {
- Cls298 c298 = new Cls298();
- JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
+ final Cls298 c298 = new Cls298();
+ final JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
String str = "c.size()";
JexlScript e = jexl.createScript(str, "c");
diff --git a/src/test/java/org/apache/commons/jexl3/Issues300Test.java b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
index d4de711..6898f66 100644
--- a/src/test/java/org/apache/commons/jexl3/Issues300Test.java
+++ b/src/test/java/org/apache/commons/jexl3/Issues300Test.java
@@ -34,19 +34,19 @@
public class Issues300Test {
@Test
public void testIssue301a() throws Exception {
- JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new JexlArithmetic(false)).create();
- String[] srcs = new String[]{
+ final JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new JexlArithmetic(false)).create();
+ final String[] srcs = new String[]{
"var x = null; x.0", "var x = null; x[0]", "var x = [null,1]; x[0][0]"
};
for (int i = 0; i < srcs.length; ++i) {
- String src = srcs[i];
- JexlScript s = jexl.createScript(src);
+ final String src = srcs[i];
+ final JexlScript s = jexl.createScript(src);
try {
- Object o = s.execute(null);
+ final Object o = s.execute(null);
if (i > 0) {
Assert.fail(src + ": Should have failed");
}
- } catch (Exception ex) {
+ } catch (final Exception ex) {
Assert.assertTrue(ex.getMessage().contains("x"));
}
}
@@ -54,20 +54,20 @@
@Test
public void testIssues301b() throws Exception {
- JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new JexlArithmetic(false)).create();
- Object[] xs = new Object[]{null, null, new Object[]{null, 1}};
- String[] srcs = new String[]{
+ final JexlEngine jexl = new JexlBuilder().safe(false).arithmetic(new JexlArithmetic(false)).create();
+ final Object[] xs = new Object[]{null, null, new Object[]{null, 1}};
+ final String[] srcs = new String[]{
"x.0", "x[0]", "x[0][0]"
};
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
for (int i = 0; i < xs.length; ++i) {
ctxt.set("x", xs[i]);
- String src = srcs[i];
- JexlScript s = jexl.createScript(src);
+ final String src = srcs[i];
+ final JexlScript s = jexl.createScript(src);
try {
- Object o = s.execute(null);
+ final Object o = s.execute(null);
Assert.fail(src + ": Should have failed");
- } catch (Exception ex) {
+ } catch (final Exception ex) {
//
}
}
@@ -75,35 +75,35 @@
@Test
public void testIssue302() throws Exception {
- JexlContext jc = new MapContext();
- String[] strs = new String[]{
+ final JexlContext jc = new MapContext();
+ final String[] strs = new String[]{
"{if (0) 1 else 2; var x = 4;}",
"if (0) 1; else 2; ",
"{ if (0) 1; else 2; }",
"{ if (0) { if (false) 1 else -3 } else 2; }"
};
- JexlEngine jexl = new JexlBuilder().create();
- for(String str : strs) {
- JexlScript e = jexl.createScript(str);
- Object o = e.execute(jc);
- int oo = ((Number) o).intValue() % 2;
+ final JexlEngine jexl = new JexlBuilder().create();
+ for(final String str : strs) {
+ final JexlScript e = jexl.createScript(str);
+ final Object o = e.execute(jc);
+ final int oo = ((Number) o).intValue() % 2;
Assert.assertEquals("Block result is wrong " + str, 0, oo);
}
}
@Test
public void testIssue304() {
- JexlEngine jexlEngine = new JexlBuilder().strict(false).create();
+ final JexlEngine jexlEngine = new JexlBuilder().strict(false).create();
JexlExpression e304 = jexlEngine.createExpression("overview.limit.var");
- HashMap<String,Object> map3 = new HashMap<String,Object>();
+ final HashMap<String,Object> map3 = new HashMap<String,Object>();
map3.put("var", "4711");
- HashMap<String,Object> map2 = new HashMap<String,Object>();
+ final HashMap<String,Object> map2 = new HashMap<String,Object>();
map2.put("limit", map3);
- HashMap<String,Object> map = new HashMap<String,Object>();
+ final HashMap<String,Object> map = new HashMap<String,Object>();
map.put("overview", map2);
- JexlContext context = new MapContext(map);
+ final JexlContext context = new MapContext(map);
Object value = e304.evaluate(context);
assertEquals("4711", value); // fails
@@ -112,7 +112,7 @@
value = e304.evaluate(context);
assertEquals(42, value);
- String allkw = "e304.if.else.do.while.new.true.false.null.var.function.empty.size.not.and.or.ne.eq.le.lt.gt.ge";
+ final String allkw = "e304.if.else.do.while.new.true.false.null.var.function.empty.size.not.and.or.ne.eq.le.lt.gt.ge";
map.put(allkw, 42);
e304 = jexlEngine.createExpression(allkw);
value = e304.evaluate(context);
@@ -121,32 +121,32 @@
@Test
public void testIssue305() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
+ final JexlEngine jexl = new JexlBuilder().create();
JexlScript e;
e = jexl.createScript("{while(false) {}; var x = 1;}");
- String str0 = e.getParsedText();
+ final String str0 = e.getParsedText();
e = jexl.createScript(str0);
Assert.assertNotNull(e);
- String str1 = e.getParsedText();
+ final String str1 = e.getParsedText();
Assert.assertEquals(str0, str1);
}
@Test
public void testIssue306() throws Exception {
- JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
- JexlScript e = jexl.createScript("x.y ?: 2");
- Object o1 = e.execute(null);
+ final JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlScript e = jexl.createScript("x.y ?: 2");
+ final Object o1 = e.execute(null);
Assert.assertEquals(2, o1);
ctxt.set("x.y", null);
- Object o2 = e.execute(ctxt);
+ final Object o2 = e.execute(ctxt);
Assert.assertEquals(2, o2);
}
@Test
public void testIssue306a() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlScript e = jexl.createScript("x.y ?: 2", "x");
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlScript e = jexl.createScript("x.y ?: 2", "x");
Object o = e.execute(null, new Object());
Assert.assertEquals(2, o);
o = e.execute(null);
@@ -155,18 +155,18 @@
@Test
public void testIssue306b() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JexlScript e = jexl.createScript("x?.y ?: 2", "x");
- Object o1 = e.execute(null, new Object());
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JexlScript e = jexl.createScript("x?.y ?: 2", "x");
+ final Object o1 = e.execute(null, new Object());
Assert.assertEquals(2, o1);
- Object o2 = e.execute(null);
+ final Object o2 = e.execute(null);
Assert.assertEquals(2, o2);
}
@Test
public void testIssue306c() throws Exception {
- JexlEngine jexl = new JexlBuilder().safe(true).create();
- JexlScript e = jexl.createScript("x.y ?: 2", "x");
+ final JexlEngine jexl = new JexlBuilder().safe(true).create();
+ final JexlScript e = jexl.createScript("x.y ?: 2", "x");
Object o = e.execute(null, new Object());
Assert.assertEquals(2, o);
o = e.execute(null);
@@ -175,8 +175,8 @@
@Test
public void testIssue306d() throws Exception {
- JexlEngine jexl = new JexlBuilder().safe(true).create();
- JexlScript e = jexl.createScript("x.y[z.t] ?: 2", "x");
+ final JexlEngine jexl = new JexlBuilder().safe(true).create();
+ final JexlScript e = jexl.createScript("x.y[z.t] ?: 2", "x");
Object o = e.execute(null, new Object());
Assert.assertEquals(2, o);
o = e.execute(null);
@@ -185,81 +185,81 @@
@Test
public void testIssue309a() throws Exception {
- String src = "<html lang=\"en\">\n"
+ final String src = "<html lang=\"en\">\n"
+ " <body>\n"
+ " <h1>Hello World!</h1>\n"
+ "$$ var i = 12++;\n"
+ " </body>\n"
+ "</html>";
- JexlEngine jexl = new JexlBuilder().safe(true).create();
- JxltEngine jxlt = jexl.createJxltEngine();
- JexlInfo info = new JexlInfo("template", 1, 1);
+ final JexlEngine jexl = new JexlBuilder().safe(true).create();
+ final JxltEngine jxlt = jexl.createJxltEngine();
+ final JexlInfo info = new JexlInfo("template", 1, 1);
try {
- JxltEngine.Template tmplt = jxlt.createTemplate(info, src);
+ final JxltEngine.Template tmplt = jxlt.createTemplate(info, src);
Assert.fail("shoud have thrown exception");
- } catch (JexlException.Parsing xerror) {
+ } catch (final JexlException.Parsing xerror) {
Assert.assertEquals(4, xerror.getInfo().getLine());
}
}
@Test
public void testIssue309b() throws Exception {
- String src = "<html lang=\"en\">\n"
+ final String src = "<html lang=\"en\">\n"
+ " <body>\n"
+ " <h1>Hello World!</h1>\n"
+ "$$ var i = a b c;\n"
+ " </body>\n"
+ "</html>";
- JexlEngine jexl = new JexlBuilder().safe(true).create();
- JxltEngine jxlt = jexl.createJxltEngine();
- JexlInfo info = new JexlInfo("template", 1, 1);
+ final JexlEngine jexl = new JexlBuilder().safe(true).create();
+ final JxltEngine jxlt = jexl.createJxltEngine();
+ final JexlInfo info = new JexlInfo("template", 1, 1);
try {
- JxltEngine.Template tmplt = jxlt.createTemplate(info, src);
+ final JxltEngine.Template tmplt = jxlt.createTemplate(info, src);
Assert.fail("shoud have thrown exception");
- } catch (JexlException.Parsing xerror) {
+ } catch (final JexlException.Parsing xerror) {
Assert.assertEquals(4, xerror.getInfo().getLine());
}
}
@Test
public void testIssue309c() throws Exception {
- String src = "<html lang=\"en\">\n"
+ final String src = "<html lang=\"en\">\n"
+ " <body>\n"
+ " <h1>Hello World!</h1>\n"
+ "$$ var i =12;\n"
+ " </body>\n"
+ "</html>";
- JexlEngine jexl = new JexlBuilder().safe(true).create();
- JxltEngine jxlt = jexl.createJxltEngine();
- JexlInfo info = new JexlInfo("template", 1, 1);
+ final JexlEngine jexl = new JexlBuilder().safe(true).create();
+ final JxltEngine jxlt = jexl.createJxltEngine();
+ final JexlInfo info = new JexlInfo("template", 1, 1);
try {
- JxltEngine.Template tmplt = jxlt.createTemplate(info, src);
- String src1 = tmplt.asString();
- String src2 = tmplt.toString();
+ final JxltEngine.Template tmplt = jxlt.createTemplate(info, src);
+ final String src1 = tmplt.asString();
+ final String src2 = tmplt.toString();
Assert.assertEquals(src1, src2);
- } catch (JexlException.Parsing xerror) {
+ } catch (final JexlException.Parsing xerror) {
Assert.assertEquals(4, xerror.getInfo().getLine());
}
}
public static class VaContext extends MapContext {
- VaContext(Map<String, Object> vars) {
+ VaContext(final Map<String, Object> vars) {
super(vars);
}
- public int cell(String... ms) {
+ public int cell(final String... ms) {
return ms.length;
}
- public int cell(List<?> l, String...ms) {
+ public int cell(final List<?> l, final String...ms) {
return 42 + cell(ms);
}
}
@Test
public void test314() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).create();
- Map<String,Object> vars = new HashMap<String, Object>();
- JexlContext ctxt = new VaContext(vars);
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final Map<String,Object> vars = new HashMap<String, Object>();
+ final JexlContext ctxt = new VaContext(vars);
JexlScript script;
Object result;
script = jexl.createScript("cell()");
@@ -284,7 +284,7 @@
jexlExp = "TVALOGAR.PEPITO==null?'SIMON':'SIMONAZO'";
script = jexl.createScript(jexlExp);
- Map<String, Object> tva = new LinkedHashMap<String, Object>();
+ final Map<String, Object> tva = new LinkedHashMap<String, Object>();
tva.put("PEPITO", null);
vars.put("TVALOGAR", tva);
result = script.execute(ctxt);
@@ -298,9 +298,9 @@
@Test
public void test315() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).create();
- Map<String,Object> vars = new HashMap<String, Object>();
- JexlContext ctxt = new VaContext(vars);
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final Map<String,Object> vars = new HashMap<String, Object>();
+ final JexlContext ctxt = new VaContext(vars);
JexlScript script;
Object result;
script = jexl.createScript("a?? 42 + 10", "a");
@@ -330,8 +330,8 @@
@Test
public void test317() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).create();
- JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final JexlContext ctxt = new MapContext();
JexlScript script;
Object result;
JexlInfo info = new JexlInfo("test317", 1, 1);
@@ -350,14 +350,14 @@
@Test
public void test322a() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).create();
- JxltEngine jxlt = jexl.createJxltEngine();
- JexlContext context = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final JxltEngine jxlt = jexl.createJxltEngine();
+ final JexlContext context = new MapContext();
- String[] ins = new String[]{
+ final String[] ins = new String[]{
"${'{'}", "${\"{\"}", "${\"{}\"}", "${'{42}'}", "${\"{\\\"\\\"}\"}"
};
- String[] ctls = new String[]{
+ final String[] ctls = new String[]{
"{", "{", "{}", "{42}", "{\"\"}"
};
StringWriter strw;
@@ -365,10 +365,10 @@
String output;
for (int i = 0; i < ins.length; ++i) {
- String src = ins[i];
+ final String src = ins[i];
try {
template = jxlt.createTemplate("$$", new StringReader(src));
- } catch(JexlException xany) {
+ } catch(final JexlException xany) {
Assert.fail(src);
throw xany;
}
@@ -393,10 +393,10 @@
@Test
public void test322b() throws Exception {
- MapContext ctxt = new MapContext();
- String src = "L'utilisateur ${session.user.name} s'est connecte";
- JexlEngine jexl = new JexlBuilder().strict(true).create();
- JxltEngine jxlt = jexl.createJxltEngine();
+ final MapContext ctxt = new MapContext();
+ final String src = "L'utilisateur ${session.user.name} s'est connecte";
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final JxltEngine jxlt = jexl.createJxltEngine();
StringWriter strw;
JxltEngine.Template template;
String output;
@@ -423,9 +423,9 @@
@Test
public void test323() throws Exception {
- JexlEngine jexl = new JexlBuilder().safe(false).create();
- Map<String,Object> vars = new HashMap<String, Object>();
- JexlContext jc = new MapContext(vars);
+ final JexlEngine jexl = new JexlBuilder().safe(false).create();
+ final Map<String,Object> vars = new HashMap<String, Object>();
+ final JexlContext jc = new MapContext(vars);
JexlScript script;
Object result;
@@ -434,7 +434,7 @@
script = jexl.createScript("a.n.t.variable");
result = script.execute(jc);
Assert.fail("a.n.t.variable is undefined!");
- } catch(JexlException.Variable xvar) {
+ } catch(final JexlException.Variable xvar) {
Assert.assertTrue(xvar.toString().contains("a.n.t"));
}
@@ -450,7 +450,7 @@
script = jexl.createScript("a.n.t[0].variable");
result = script.execute(jc);
Assert.fail("a.n.t is null!");
- } catch(JexlException.Variable xvar) {
+ } catch(final JexlException.Variable xvar) {
Assert.assertTrue(xvar.toString().contains("a.n.t"));
}
@@ -460,17 +460,17 @@
script = jexl.createScript("a.n.t[0].variable");
result = script.execute(jc);
Assert.fail("a.n.t is undefined!");
- } catch(JexlException.Variable xvar) {
+ } catch(final JexlException.Variable xvar) {
Assert.assertTrue(xvar.toString().contains("a.n.t"));
}
// defined, derefence undefined property
- List<Object> inner = new ArrayList<Object>();
+ final List<Object> inner = new ArrayList<Object>();
vars.put("a.n.t", inner);
try {
script = jexl.createScript("a.n.t[0].variable");
result = script.execute(jc);
Assert.fail("a.n.t is null!");
- } catch(JexlException.Property xprop) {
+ } catch(final JexlException.Property xprop) {
Assert.assertTrue(xprop.toString().contains("0"));
}
// defined, derefence undefined property
@@ -479,7 +479,7 @@
script = jexl.createScript("a.n.t[0].variable");
result = script.execute(jc);
Assert.fail("a.n.t is null!");
- } catch(JexlException.Property xprop) {
+ } catch(final JexlException.Property xprop) {
Assert.assertTrue(xprop.toString().contains("variable"));
}
@@ -487,36 +487,36 @@
@Test
public void test324() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- String src42 = "new('java.lang.Integer', 42)";
- JexlExpression expr0 = jexl.createExpression(src42);
+ final JexlEngine jexl = new JexlBuilder().create();
+ final String src42 = "new('java.lang.Integer', 42)";
+ final JexlExpression expr0 = jexl.createExpression(src42);
Assert.assertEquals(42, expr0.evaluate(null));
- String parsed = expr0.getParsedText();
+ final String parsed = expr0.getParsedText();
Assert.assertEquals(src42, parsed);
try {
- JexlExpression expr = jexl.createExpression("new()");
+ final JexlExpression expr = jexl.createExpression("new()");
Assert.fail("should not parse");
- } catch (JexlException.Parsing xparse) {
+ } catch (final JexlException.Parsing xparse) {
Assert.assertTrue(xparse.toString().contains("new"));
}
}
@Test
public void test325() throws Exception {
- JexlEngine jexl = new JexlBuilder().safe(false).create();
- Map<String, Object> map = new HashMap<String, Object>() {
+ final JexlEngine jexl = new JexlBuilder().safe(false).create();
+ final Map<String, Object> map = new HashMap<String, Object>() {
@Override
- public Object get(Object key) {
+ public Object get(final Object key) {
return super.get(key == null ? "" : key);
}
@Override
- public Object put(String key, Object value) {
+ public Object put(final String key, final Object value) {
return super.put(key == null ? "" : key, value);
}
};
map.put("42", 42);
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
JexlScript script;
Object result;
@@ -532,10 +532,10 @@
@Test
public void test330() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
+ final JexlEngine jexl = new JexlBuilder().create();
// Extended form of: 'literal' + VARIABLE 'literal'
// missing + operator here ---------------^
- String longExpression = ""
+ final String longExpression = ""
+ //
"'THIS IS A VERY VERY VERY VERY VERY VERY VERY "
+ //
@@ -545,7 +545,7 @@
try {
jexl.createExpression(longExpression);
Assert.fail("parsing malformed expression did not throw exception");
- } catch (JexlException.Parsing exception) {
+ } catch (final JexlException.Parsing exception) {
Assert.assertTrue(exception.getMessage().contains("VARIABLE"));
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/IssuesTest.java b/src/test/java/org/apache/commons/jexl3/IssuesTest.java
index d3f63fa..f72b189 100644
--- a/src/test/java/org/apache/commons/jexl3/IssuesTest.java
+++ b/src/test/java/org/apache/commons/jexl3/IssuesTest.java
@@ -45,11 +45,11 @@
// JEXL-49: blocks not parsed (fixed)
@Test
public void test49() throws Exception {
- JexlEngine jexl = new Engine();
- Map<String, Object> vars = new HashMap<String, Object>();
- JexlContext ctxt = new MapContext(vars);
- String stmt = "a = 'b'; c = 'd';";
- JexlScript expr = jexl.createScript(stmt);
+ final JexlEngine jexl = new Engine();
+ final Map<String, Object> vars = new HashMap<String, Object>();
+ final JexlContext ctxt = new MapContext(vars);
+ final String stmt = "a = 'b'; c = 'd';";
+ final JexlScript expr = jexl.createScript(stmt);
/* Object value = */ expr.execute(ctxt);
Assert.assertTrue("JEXL-49 is not fixed", vars.get("a").equals("b") && vars.get("c").equals("d"));
}
@@ -82,21 +82,21 @@
@Test
public void test48() throws Exception {
- JexlEngine jexl = new Engine();
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
+ final JexlEngine jexl = new Engine();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
// ensure errors will throw
options.setStrict(true);
options.setSilent(false);
try {
- String jexlExp = "(foo.getInner().foo() eq true) and (foo.getInner().goo() = (foo.getInner().goo()+1-1))";
- JexlExpression e = jexl.createExpression(jexlExp);
+ final String jexlExp = "(foo.getInner().foo() eq true) and (foo.getInner().goo() = (foo.getInner().goo()+1-1))";
+ final JexlExpression e = jexl.createExpression(jexlExp);
jc.set("foo", new Foo());
/* Object o = */ e.evaluate(jc);
Assert.fail("Should have failed due to invalid assignment");
- } catch (JexlException.Assignment xparse) {
- String dbg = xparse.toString();
- } catch (JexlException xjexl) {
+ } catch (final JexlException.Assignment xparse) {
+ final String dbg = xparse.toString();
+ } catch (final JexlException xjexl) {
Assert.fail("Should have thrown a parse exception");
}
}
@@ -105,9 +105,9 @@
// JEXL-44: comments dont allow double quotes (fixed in Parser.jjt)
@Test
public void test47() throws Exception {
- JexlEngine jexl = new Engine();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = new Engine();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
@@ -128,19 +128,19 @@
// fixed in JexlArithmetic by allowing add operator to deal with string, null
@Test
public void test42() throws Exception {
- JexlEngine jexl = new JexlBuilder().create();
- JxltEngine uel = jexl.createJxltEngine();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JxltEngine uel = jexl.createJxltEngine();
// ensure errors will throw
//jexl.setSilent(false);
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.set(jexl);
options.setStrict(false);
options.setStrictArithmetic(false);
ctxt.set("ax", "ok");
- JxltEngine.Expression expr = uel.createExpression("${ax+(bx)}");
- Object value = expr.evaluate(ctxt);
+ final JxltEngine.Expression expr = uel.createExpression("${ax+(bx)}");
+ final Object value = expr.evaluate(ctxt);
Assert.assertEquals("should be ok", "ok", value);
}
@@ -159,30 +159,30 @@
@Test
public void test40() throws Exception {
- JexlEngine jexl = new Engine();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = new Engine();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.set(jexl);
// ensure errors will throw
options.setSilent(false);
ctxt.set("derived", new Derived());
- JexlExpression expr = jexl.createExpression("derived.foo()");
- Object value = expr.evaluate(ctxt);
+ final JexlExpression expr = jexl.createExpression("derived.foo()");
+ final Object value = expr.evaluate(ctxt);
Assert.assertTrue("should be true", (Boolean) value);
}
// JEXL-52: can be implemented by deriving Interpreter.{g,s}etAttribute; later
@Test
public void test52base() throws Exception {
- Engine jexl = (Engine) createEngine(false);
- Uberspect uber = (Uberspect) jexl.getUberspect();
+ final Engine jexl = (Engine) createEngine(false);
+ final Uberspect uber = (Uberspect) jexl.getUberspect();
// most likely, call will be in an Interpreter, getUberspect
String[] names = uber.getMethodNames(Another.class);
Assert.assertTrue("should find methods", names.length > 0);
int found = 0;
- for (String name : names) {
+ for (final String name : names) {
if ("foo".equals(name) || "goo".equals(name)) {
found += 1;
}
@@ -192,7 +192,7 @@
names = uber.getFieldNames(Another.class);
Assert.assertTrue("should find fields", names.length > 0);
found = 0;
- for (String name : names) {
+ for (final String name : names) {
if ("name".equals(name)) {
found += 1;
}
@@ -203,29 +203,29 @@
// JEXL-10/JEXL-11: variable checking, null operand is error
@Test
public void test11() throws Exception {
- JexlEngine jexl = createEngine(false);
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
options.setStrict(true);
ctxt.set("a", null);
- String[] exprs = {
+ final String[] exprs = {
//"10 + null",
//"a - 10",
//"b * 10",
"a % b"//,
//"1000 / a"
};
- for (String s : exprs) {
+ for (final String s : exprs) {
try {
- JexlExpression expr = jexl.createExpression(s);
+ final JexlExpression expr = jexl.createExpression(s);
/* Object value = */
expr.evaluate(ctxt);
Assert.fail(s + " : should have failed due to null argument");
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
// expected
}
}
@@ -234,10 +234,10 @@
// JEXL-62
@Test
public void test62() throws Exception {
- JexlEngine jexl = createEngine(false);
- MapContext vars = new MapContext();
- JexlEvalContext ctxt = new JexlEvalContext(vars);
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final MapContext vars = new MapContext();
+ final JexlEvalContext ctxt = new JexlEvalContext(vars);
+ final JexlOptions options = ctxt.getEngineOptions();
options.setStrict(true);
options.setSilent(true);// to avoid throwing JexlException on null method call
@@ -267,13 +267,13 @@
// JEXL-87
@Test
public void test87() throws Exception {
- JexlEngine jexl = createEngine(false);
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
- JexlExpression divide = jexl.createExpression("l / r");
- JexlExpression modulo = jexl.createExpression("l % r");
+ final JexlExpression divide = jexl.createExpression("l / r");
+ final JexlExpression modulo = jexl.createExpression("l % r");
ctxt.set("l", java.math.BigInteger.valueOf(7));
ctxt.set("r", java.math.BigInteger.valueOf(2));
@@ -289,29 +289,29 @@
// JEXL-90
@Test
public void test90() throws Exception {
- JexlEngine jexl = createEngine(false);
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
// ';' is necessary between expressions
- String[] fexprs = {
+ final String[] fexprs = {
"a=3 b=4",
"while(a) while(a)",
"1 2",
"if (true) 2; 3 {}",
"while (x) 1 if (y) 2 3"
};
- for (String fexpr : fexprs) {
+ for (final String fexpr : fexprs) {
try {
jexl.createScript(fexpr);
Assert.fail(fexpr + ": Should have failed in parse");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
// expected to fail in createExpression
}
}
// ';' is necessary between expressions and only expressions
- String[] exprs = {
+ final String[] exprs = {
"if (x) {1} if (y) {2}",
"if (x) 1 if (y) 2",
"while (x) 1 if (y) 2 else 3",
@@ -320,8 +320,8 @@
};
ctxt.set("x", Boolean.FALSE);
ctxt.set("y", Boolean.TRUE);
- for (String expr : exprs) {
- JexlScript s = jexl.createScript(expr);
+ for (final String expr : exprs) {
+ final JexlScript s = jexl.createScript(expr);
Assert.assertEquals(Integer.valueOf(2), s.execute(ctxt));
}
debuggerCheck(jexl);
@@ -330,9 +330,9 @@
// JEXL-44
@Test
public void test44() throws Exception {
- JexlEngine jexl = createEngine(false);
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
JexlScript script;
@@ -348,47 +348,47 @@
@Test
public void test97() throws Exception {
- JexlEngine jexl = createEngine(false);
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = createEngine(false);
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setSilent(false);
for (char v = 'a'; v <= 'z'; ++v) {
ctxt.set(Character.toString(v), 10);
}
- String input
+ final String input
= "(((((((((((((((((((((((((z+y)/x)*w)-v)*u)/t)-s)*r)/q)+p)-o)*n)-m)+l)*k)+j)/i)+h)*g)+f)/e)+d)-c)/b)+a)";
JexlExpression script;
// Make sure everything is loaded...
- long start = System.nanoTime();
+ final long start = System.nanoTime();
script = jexl.createExpression(input);
- Object value = script.evaluate(ctxt);
+ final Object value = script.evaluate(ctxt);
Assert.assertEquals(Integer.valueOf(11), value);
- long end = System.nanoTime();
- double millisec = (end - start) / 1e6;
- double limit = 200.0; // Allow plenty of slack
+ final long end = System.nanoTime();
+ final double millisec = (end - start) / 1e6;
+ final double limit = 200.0; // Allow plenty of slack
Assert.assertTrue("Expected parse to take less than " + limit + "ms, actual " + millisec, millisec < limit);
}
public static class fn98 {
- public String replace(String str, String target, String replacement) {
+ public String replace(final String str, final String target, final String replacement) {
return str.replace(target, replacement);
}
}
@Test
public void test98() throws Exception {
- String[] exprs = {
+ final String[] exprs = {
"fn:replace('DOMAIN\\somename', '\\\\', '\\\\\\\\')",
"fn:replace(\"DOMAIN\\somename\", \"\\\\\", \"\\\\\\\\\")",
"fn:replace('DOMAIN\\somename', '\\u005c', '\\u005c\\u005c')"
};
- Map<String, Object> funcs = new HashMap<String, Object>();
+ final Map<String, Object> funcs = new HashMap<String, Object>();
funcs.put("fn", new fn98());
- JexlEngine jexl = new JexlBuilder().namespaces(funcs).create();
- for (String expr : exprs) {
- Object value = jexl.createExpression(expr).evaluate(null);
+ final JexlEngine jexl = new JexlBuilder().namespaces(funcs).create();
+ for (final String expr : exprs) {
+ final Object value = jexl.createExpression(expr).evaluate(null);
Assert.assertEquals(expr, "DOMAIN\\\\somename", value);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/JXLTTest.java b/src/test/java/org/apache/commons/jexl3/JXLTTest.java
index c154a2e..86a065d 100644
--- a/src/test/java/org/apache/commons/jexl3/JXLTTest.java
+++ b/src/test/java/org/apache/commons/jexl3/JXLTTest.java
@@ -51,7 +51,7 @@
private final JexlEngine ENGINE;
private final JxltEngine JXLT;
- public JXLTTest(JexlBuilder builder) {
+ public JXLTTest(final JexlBuilder builder) {
super("JXLTTest");
BUILDER = builder;
ENGINE = BUILDER.create();
@@ -61,7 +61,7 @@
@Parameterized.Parameters
public static List<JexlBuilder> engines() {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true).lexicalShade(true);
return Arrays.<JexlBuilder>asList(new JexlBuilder[] {
new JexlBuilder().silent(false)
@@ -98,8 +98,8 @@
return options.isLexicalShade();
}
- private static String refactor(TemplateDebugger td, JxltEngine.Template ts) {
- boolean dbg = td.debug(ts);
+ private static String refactor(final TemplateDebugger td, final JxltEngine.Template ts) {
+ final boolean dbg = td.debug(ts);
if (dbg) {
return td.toString();
} else {
@@ -108,13 +108,13 @@
}
/** Extract the source from a toString-ed expression. */
- private String getSource(String tostring) {
- int len = tostring.length();
+ private String getSource(final String tostring) {
+ final int len = tostring.length();
int sc = tostring.lastIndexOf(" /*= ");
if (sc >= 0) {
sc += " /*= ".length();
}
- int ec = tostring.lastIndexOf(" */");
+ final int ec = tostring.lastIndexOf(" */");
if (sc >= 0 && ec >= 0 && ec > sc && ec < len) {
return tostring.substring(sc, ec);
} else {
@@ -126,11 +126,11 @@
public static class Froboz {
int value;
- public Froboz(int v) {
+ public Froboz(final int v) {
value = v;
}
- public void setValue(int v) {
+ public void setValue(final int v) {
value = v;
}
@@ -139,7 +139,7 @@
}
public int plus10() {
- int i = value;
+ final int i = value;
value += 10;
return i;
}
@@ -147,22 +147,22 @@
@Test
public void testStatement() throws Exception {
- Froboz froboz = new Froboz(32);
+ final Froboz froboz = new Froboz(32);
context.set("froboz", froboz);
- JxltEngine.Expression check = JXLT.createExpression("${ froboz.plus10() }");
- Object o = check.evaluate(context);
+ final JxltEngine.Expression check = JXLT.createExpression("${ froboz.plus10() }");
+ final Object o = check.evaluate(context);
Assert.assertEquals("Result is not 32", new Integer(32), o);
Assert.assertEquals("Result is not 42", 42, froboz.getValue());
- Set<List<String>> evars = check.getVariables();
+ final Set<List<String>> evars = check.getVariables();
Assert.assertEquals(1, evars.size());
}
@Test
public void testAssign() throws Exception {
- Froboz froboz = new Froboz(32);
+ final Froboz froboz = new Froboz(32);
context.set("froboz", froboz);
- JxltEngine.Expression assign = JXLT.createExpression("${froboz.value = 42}");
- JxltEngine.Expression check = JXLT.createExpression("${froboz.value}");
+ final JxltEngine.Expression assign = JXLT.createExpression("${froboz.value = 42}");
+ final JxltEngine.Expression check = JXLT.createExpression("${froboz.value}");
Object o = assign.evaluate(context);
Assert.assertEquals("Result is not 10", new Integer(42), o);
o = check.evaluate(context);
@@ -171,8 +171,8 @@
@Test
public void testComposite() throws Exception {
- String source = "Dear ${p} ${name};";
- JxltEngine.Expression expr = JXLT.createExpression(source);
+ final String source = "Dear ${p} ${name};";
+ final JxltEngine.Expression expr = JXLT.createExpression(source);
context.set("p", "Mr");
context.set("name", "Doe");
Assert.assertTrue("expression should be immediate", expr.isImmediate());
@@ -185,8 +185,8 @@
Assert.assertEquals(source, getSource(expr.toString()));
}
- boolean contains(Set<List<String>> set, List<String> list) {
- for (List<String> sl : set) {
+ boolean contains(final Set<List<String>> set, final List<String> list) {
+ for (final List<String> sl : set) {
if (sl.equals(list)) {
return true;
}
@@ -197,26 +197,26 @@
@Test
public void testPrepareEvaluate() throws Exception {
final String source = "Dear #{p} ${name};";
- JxltEngine.Expression expr = JXLT.createExpression("Dear #{p} ${name};");
+ final JxltEngine.Expression expr = JXLT.createExpression("Dear #{p} ${name};");
Assert.assertTrue("expression should be deferred", expr.isDeferred());
- Set<List<String>> evars = expr.getVariables();
+ final Set<List<String>> evars = expr.getVariables();
Assert.assertEquals(1, evars.size());
Assert.assertTrue(contains(evars, Collections.singletonList("name")));
context.set("name", "Doe");
- JxltEngine.Expression phase1 = expr.prepare(context);
- String as = phase1.asString();
+ final JxltEngine.Expression phase1 = expr.prepare(context);
+ final String as = phase1.asString();
Assert.assertEquals("Dear ${p} Doe;", as);
- Set<List<String>> evars1 = phase1.getVariables();
+ final Set<List<String>> evars1 = phase1.getVariables();
Assert.assertEquals(1, evars1.size());
Assert.assertTrue(contains(evars1, Collections.singletonList("p")));
vars.clear();
context.set("p", "Mr");
context.set("name", "Should not be used in 2nd phase");
- Object o = phase1.evaluate(context);
+ final Object o = phase1.evaluate(context);
Assert.assertEquals("Dear Mr Doe;", o);
- String p1 = getSource(phase1.toString());
+ final String p1 = getSource(phase1.toString());
Assert.assertEquals(source, getSource(phase1.toString()));
Assert.assertEquals(source, getSource(expr.toString()));
}
@@ -224,16 +224,16 @@
@Test
public void testNested() throws Exception {
final String source = "#{${hi}+'.world'}";
- JxltEngine.Expression expr = JXLT.createExpression(source);
+ final JxltEngine.Expression expr = JXLT.createExpression(source);
- Set<List<String>> evars = expr.getVariables();
+ final Set<List<String>> evars = expr.getVariables();
Assert.assertEquals(1, evars.size());
Assert.assertTrue(contains(evars, Collections.singletonList("hi")));
context.set("hi", "greeting");
context.set("greeting.world", "Hello World!");
Assert.assertTrue("expression should be deferred", expr.isDeferred());
- Object o = expr.evaluate(context);
+ final Object o = expr.evaluate(context);
Assert.assertEquals("Hello World!", o);
Assert.assertEquals(source, getSource(expr.toString()));
@@ -242,12 +242,12 @@
@Test
public void testNestedTemplate() throws Exception {
final String source = "#{${hi}+'.world'}";
- JxltEngine.Template expr = JXLT.createTemplate(source, "hi");
+ final JxltEngine.Template expr = JXLT.createTemplate(source, "hi");
context.set("greeting.world", "Hello World!");
- StringWriter strw = new StringWriter();
+ final StringWriter strw = new StringWriter();
expr.evaluate(context, strw, "greeting");
- String o = strw.toString();
+ final String o = strw.toString();
Assert.assertEquals("Hello World!", o);
Assert.assertEquals(source, getSource(expr.toString()));
@@ -255,12 +255,12 @@
@Test
public void testImmediate() throws Exception {
- JexlContext none = null;
+ final JexlContext none = null;
final String source = "${'Hello ' + 'World!'}";
- JxltEngine.Expression expr = JXLT.createExpression(source);
- JxltEngine.Expression prepared = expr.prepare(none);
+ final JxltEngine.Expression expr = JXLT.createExpression(source);
+ final JxltEngine.Expression prepared = expr.prepare(none);
Assert.assertEquals("prepare should return same expression", "Hello World!", prepared.asString());
- Object o = expr.evaluate(none);
+ final Object o = expr.evaluate(none);
Assert.assertTrue("expression should be immediate", expr.isImmediate());
Assert.assertEquals("Hello World!", o);
@@ -269,11 +269,11 @@
@Test
public void testConstant() throws Exception {
- JexlContext none = null;
+ final JexlContext none = null;
final String source = "Hello World!";
- JxltEngine.Expression expr = JXLT.createExpression(source);
+ final JxltEngine.Expression expr = JXLT.createExpression(source);
Assert.assertSame("prepare should return same expression", expr.prepare(none), expr);
- Object o = expr.evaluate(none);
+ final Object o = expr.evaluate(none);
Assert.assertTrue("expression should be immediate", expr.isImmediate());
Assert.assertEquals("Hello World!", o);
@@ -282,11 +282,11 @@
@Test
public void testConstant2() throws Exception {
- JexlContext none = null;
+ final JexlContext none = null;
final String source = "${size({'map':123,'map2':456})}";
- JxltEngine.Expression expr = JXLT.createExpression(source);
+ final JxltEngine.Expression expr = JXLT.createExpression(source);
//Assert.assertTrue("prepare should return same expression", expr.prepare(none) == expr);
- Object o = expr.evaluate(none);
+ final Object o = expr.evaluate(none);
Assert.assertTrue("expression should be immediate", expr.isImmediate());
Assert.assertEquals(2, o);
@@ -295,11 +295,11 @@
@Test
public void testConstant3() throws Exception {
- JexlContext none = null;
+ final JexlContext none = null;
final String source = "#{size({'map':123,'map2':456})}";
- JxltEngine.Expression expr = JXLT.createExpression(source);
+ final JxltEngine.Expression expr = JXLT.createExpression(source);
//Assert.assertTrue("prepare should return same expression", expr.prepare(none) == expr);
- Object o = expr.evaluate(none);
+ final Object o = expr.evaluate(none);
Assert.assertTrue("expression should be deferred", expr.isDeferred());
Assert.assertEquals(2, o);
@@ -308,11 +308,11 @@
@Test
public void testConstant4() throws Exception {
- JexlContext none = null;
+ final JexlContext none = null;
final String source = "#{ ${size({'1':2,'2': 3})} }";
- JxltEngine.Expression expr = JXLT.createExpression(source);
+ final JxltEngine.Expression expr = JXLT.createExpression(source);
//Assert.assertTrue("prepare should return same expression", expr.prepare(none) == expr);
- Object o = expr.evaluate(none);
+ final Object o = expr.evaluate(none);
Assert.assertTrue("expression should be deferred", expr.isDeferred());
Assert.assertEquals(2, o);
@@ -321,13 +321,13 @@
@Test
public void testDeferred() throws Exception {
- JexlContext none = null;
+ final JexlContext none = null;
final String source = "#{'world'}";
- JxltEngine.Expression expr = JXLT.createExpression(source);
+ final JxltEngine.Expression expr = JXLT.createExpression(source);
Assert.assertTrue("expression should be deferred", expr.isDeferred());
- String as = expr.prepare(none).asString();
+ final String as = expr.prepare(none).asString();
Assert.assertEquals("prepare should return immediate version", "${'world'}", as);
- Object o = expr.evaluate(none);
+ final Object o = expr.evaluate(none);
Assert.assertEquals("world", o);
Assert.assertEquals(source, getSource(expr.toString()));
@@ -335,7 +335,7 @@
@Test
public void testEscape() throws Exception {
- JexlContext none = null;
+ final JexlContext none = null;
JxltEngine.Expression expr;
Object o;
// $ and # are escapable in TemplateEngine
@@ -349,30 +349,30 @@
@Test
public void testEscapeString() throws Exception {
- JxltEngine.Expression expr = JXLT.createExpression("\\\"${'world\\'s finest'}\\\"");
- JexlContext none = null;
- Object o = expr.evaluate(none);
+ final JxltEngine.Expression expr = JXLT.createExpression("\\\"${'world\\'s finest'}\\\"");
+ final JexlContext none = null;
+ final Object o = expr.evaluate(none);
Assert.assertEquals("\"world's finest\"", o);
}
@Test
public void testNonEscapeString() throws Exception {
- JxltEngine.Expression expr = JXLT.createExpression("c:\\some\\windows\\path");
- JexlContext none = null;
- Object o = expr.evaluate(none);
+ final JxltEngine.Expression expr = JXLT.createExpression("c:\\some\\windows\\path");
+ final JexlContext none = null;
+ final Object o = expr.evaluate(none);
Assert.assertEquals("c:\\some\\windows\\path", o);
}
@Test
public void testMalformed() throws Exception {
try {
- JxltEngine.Expression expr = JXLT.createExpression("${'world'");
- JexlContext none = null;
+ final JxltEngine.Expression expr = JXLT.createExpression("${'world'");
+ final JexlContext none = null;
expr.evaluate(none);
Assert.fail("should be malformed");
- } catch (JxltEngine.Exception xjexl) {
+ } catch (final JxltEngine.Exception xjexl) {
// expected
- String xmsg = xjexl.getMessage();
+ final String xmsg = xjexl.getMessage();
LOGGER.warn(xmsg);
}
}
@@ -380,13 +380,13 @@
@Test
public void testMalformedNested() throws Exception {
try {
- JxltEngine.Expression expr = JXLT.createExpression("#{${hi} world}");
- JexlContext none = null;
+ final JxltEngine.Expression expr = JXLT.createExpression("#{${hi} world}");
+ final JexlContext none = null;
expr.evaluate(none);
Assert.fail("should be malformed");
- } catch (JxltEngine.Exception xjexl) {
+ } catch (final JxltEngine.Exception xjexl) {
// expected
- String xmsg = xjexl.getMessage();
+ final String xmsg = xjexl.getMessage();
LOGGER.warn(xmsg);
}
}
@@ -394,14 +394,14 @@
@Test
public void testMalformedNested2() throws Exception {
try {
- JxltEngine.Expression expr = JXLT.createExpression("#{${hi} world}");
- JexlContext ctxt = new MapContext();
+ final JxltEngine.Expression expr = JXLT.createExpression("#{${hi} world}");
+ final JexlContext ctxt = new MapContext();
ctxt.set("hi", "hello");
expr.evaluate(ctxt);
Assert.fail("should be malformed");
- } catch (JxltEngine.Exception xjexl) {
+ } catch (final JxltEngine.Exception xjexl) {
// expected
- String xmsg = xjexl.getMessage();
+ final String xmsg = xjexl.getMessage();
LOGGER.warn(xmsg);
}
}
@@ -409,13 +409,13 @@
@Test
public void testBadContextNested() throws Exception {
try {
- JxltEngine.Expression expr = JXLT.createExpression("#{${hi}+'.world'}");
- JexlContext none = null;
+ final JxltEngine.Expression expr = JXLT.createExpression("#{${hi}+'.world'}");
+ final JexlContext none = null;
expr.evaluate(none);
Assert.fail("should be malformed");
- } catch (JxltEngine.Exception xjexl) {
+ } catch (final JxltEngine.Exception xjexl) {
// expected
- String xmsg = xjexl.getMessage();
+ final String xmsg = xjexl.getMessage();
LOGGER.warn(xmsg);
}
}
@@ -423,7 +423,7 @@
@Test
public void testCharAtBug() throws Exception {
context.set("foo", "abcdef");
- JexlOptions options = context.getEngineOptions();
+ final JexlOptions options = context.getEngineOptions();
JxltEngine.Expression expr = JXLT.createExpression("${foo.substring(2,4)/*comment*/}");
Object o = expr.evaluate(context);
Assert.assertEquals("cd", o);
@@ -443,11 +443,11 @@
@Test
public void testTemplate0() throws Exception {
- String source = " $$ if(x) {\nx is ${x}\n $$ } else {\n${'no x'}\n$$ }\n";
+ final String source = " $$ if(x) {\nx is ${x}\n $$ } else {\n${'no x'}\n$$ }\n";
StringWriter strw;
String output;
- JxltEngine.Template t = JXLT.createTemplate(source);
+ final JxltEngine.Template t = JXLT.createTemplate(source);
context.set("x", 42);
strw = new StringWriter();
@@ -461,21 +461,21 @@
output = strw.toString();
Assert.assertEquals("no x\n", output);
- String dstr = t.toString();
+ final String dstr = t.toString();
Assert.assertNotNull(dstr);
}
@Test
public void testTemplate10() throws Exception {
- String source = "$$(x)->{ if(x) {\nx is ${x}\n$$ } else {\n${'no x'}\n$$ } }\n";
+ final String source = "$$(x)->{ if(x) {\nx is ${x}\n$$ } else {\n${'no x'}\n$$ } }\n";
StringWriter strw;
String output;
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), (String[]) null);
- String dstr = t.asString();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), (String[]) null);
+ final String dstr = t.asString();
Assert.assertNotNull(dstr);
- String[] ps = t.getParameters();
+ final String[] ps = t.getParameters();
Assert.assertTrue(Arrays.asList(ps).contains("x"));
strw = new StringWriter();
@@ -486,12 +486,12 @@
@Test
public void testTemplate1() throws Exception {
- String source = "$$ if(x) {\nx is ${x}\n$$ } else {\n${'no x'}\n$$ }\n";
+ final String source = "$$ if(x) {\nx is ${x}\n$$ } else {\n${'no x'}\n$$ }\n";
StringWriter strw;
String output;
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), "x");
- String dstr = t.asString();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), "x");
+ final String dstr = t.asString();
Assert.assertNotNull(dstr);
strw = new StringWriter();
@@ -507,12 +507,12 @@
@Test
public void testTemplate2() throws Exception {
- String source = "The answer: ${x}";
+ final String source = "The answer: ${x}";
StringWriter strw;
String output;
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), "x");
- String dstr = t.asString();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), "x");
+ final String dstr = t.asString();
Assert.assertNotNull(dstr);
strw = new StringWriter();
@@ -523,38 +523,38 @@
@Test
public void testPrepareTemplate() throws Exception {
- String source
+ final String source
= "$$ for(var x : list) {\n"
+ "${l10n}=#{x}\n"
+ "$$ }\n";
- int[] args = {42};
- JxltEngine.Template tl10n = JXLT.createTemplate(source, "list");
- String dstr = tl10n.asString();
+ final int[] args = {42};
+ final JxltEngine.Template tl10n = JXLT.createTemplate(source, "list");
+ final String dstr = tl10n.asString();
Assert.assertNotNull(dstr);
- Set<List<String>> vars = tl10n.getVariables();
+ final Set<List<String>> vars = tl10n.getVariables();
Assert.assertFalse(vars.isEmpty());
context.set("l10n", "valeur");
- JxltEngine.Template tpFR = tl10n.prepare(context);
+ final JxltEngine.Template tpFR = tl10n.prepare(context);
context.set("l10n", "value");
- JxltEngine.Template tpEN = tl10n.prepare(context);
+ final JxltEngine.Template tpEN = tl10n.prepare(context);
context.set("l10n", null);
StringWriter strw;
strw = new StringWriter();
tpFR.evaluate(context, strw, args);
- String outFR = strw.toString();
+ final String outFR = strw.toString();
Assert.assertEquals("valeur=42\n", outFR);
context.set("l10n", null);
strw = new StringWriter();
tpEN.evaluate(context, strw, args);
- String outEN = strw.toString();
+ final String outEN = strw.toString();
Assert.assertEquals("value=42\n", outEN);
}
@Test
public void test42() throws Exception {
- String test42
+ final String test42
= "$$ for(var x : list) {\n"
+ "$$ if (x == 42) {\n"
+ "Life, the universe, and everything\n"
@@ -564,12 +564,12 @@
+ "The value ${x} is under fourty-two\n"
+ "$$ }\n"
+ "$$ }\n";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(test42), "list");
- StringWriter strw = new StringWriter();
- int[] list = {1, 3, 5, 42, 169};
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(test42), "list");
+ final StringWriter strw = new StringWriter();
+ final int[] list = {1, 3, 5, 42, 169};
t.evaluate(context, strw, list);
- String output = strw.toString();
- String out42
+ final String output = strw.toString();
+ final String out42
= "The value 1 is under fourty-two\n"
+ "The value 3 is under fourty-two\n"
+ "The value 5 is under fourty-two\n"
@@ -577,37 +577,37 @@
+ "The value 169 is over fourty-two\n";
Assert.assertEquals(out42, output);
- String dstr = t.asString();
+ final String dstr = t.asString();
Assert.assertNotNull(dstr);
- TemplateDebugger td = new TemplateDebugger();
- String refactored = refactor(td, t);
+ final TemplateDebugger td = new TemplateDebugger();
+ final String refactored = refactor(td, t);
Assert.assertNotNull(refactored);
Assert.assertEquals(test42, refactored);
}
@Test
public void testInheritedDebugger() throws Exception {
- String src = "if ($A) { $B + 1; } else { $C - 2 }";
- JexlEngine jexl = JXLT.getEngine();
- JexlScript script = jexl.createScript(src);
+ final String src = "if ($A) { $B + 1; } else { $C - 2 }";
+ final JexlEngine jexl = JXLT.getEngine();
+ final JexlScript script = jexl.createScript(src);
- Debugger sd = new Debugger();
- String rscript = sd.debug(script)? sd.toString() : null;
+ final Debugger sd = new Debugger();
+ final String rscript = sd.debug(script)? sd.toString() : null;
Assert.assertNotNull(rscript);
- TemplateDebugger td = new TemplateDebugger();
- String refactored = td.debug(script)? td.toString() : null;
+ final TemplateDebugger td = new TemplateDebugger();
+ final String refactored = td.debug(script)? td.toString() : null;
Assert.assertNotNull(refactored);
Assert.assertEquals(refactored, rscript);
}
public static class FrobozWriter extends PrintWriter {
- public FrobozWriter(Writer w) {
+ public FrobozWriter(final Writer w) {
super(w);
}
- public void print(Froboz froboz) {
+ public void print(final Froboz froboz) {
super.print("froboz{");
super.print(froboz.value);
super.print("}");
@@ -621,16 +621,16 @@
@Test
public void testWriter() throws Exception {
- Froboz froboz = new Froboz(42);
- Writer writer = new FrobozWriter(new StringWriter());
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("$$$jexl.print(froboz)"), "froboz");
+ final Froboz froboz = new Froboz(42);
+ final Writer writer = new FrobozWriter(new StringWriter());
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("$$$jexl.print(froboz)"), "froboz");
t.evaluate(context, writer, froboz);
Assert.assertEquals("froboz{42}", writer.toString());
}
@Test
public void testReport() throws Exception {
- String rpt
+ final String rpt
= "<report>\n"
+ "\n"
+ "\n$$ var a = 1;"
@@ -640,36 +640,36 @@
+ "\n"
+ "\n ${x + y}"
+ "\n</report>\n";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
+ final StringWriter strw = new StringWriter();
t.evaluate(context, strw);
- String output = strw.toString();
- String ctl = "<report>\n\n\n\n\n 11\n</report>\n";
+ final String output = strw.toString();
+ final String ctl = "<report>\n\n\n\n\n 11\n</report>\n";
Assert.assertEquals(ctl, output);
- TemplateDebugger td = new TemplateDebugger();
- String refactored = refactor(td, t);
+ final TemplateDebugger td = new TemplateDebugger();
+ final String refactored = refactor(td, t);
Assert.assertNotNull(refactored);
Assert.assertEquals(rpt, refactored);
}
@Test
public void testReport1() throws Exception {
- String rpt
+ final String rpt
= "<report>\n"
+ "this is ${x}\n"
+ "${x + 1}\n"
+ "${x + 2}\n"
+ "${x + 3}\n"
+ "</report>\n";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
+ final StringWriter strw = new StringWriter();
context.set("x", 42);
t.evaluate(context, strw, 42);
- String output = strw.toString();
+ final String output = strw.toString();
int count = 0;
for (int i = 0; i < output.length(); ++i) {
- char c = output.charAt(i);
+ final char c = output.charAt(i);
if ('\n' == c) {
count += 1;
}
@@ -683,20 +683,20 @@
@Test
public void testReport2() throws Exception {
- String rpt
+ final String rpt
= "<report>\n"
+ "this is ${x}\n"
+ "${x + 1}\n"
+ "${x + 2}\n"
+ "${x + 3}\n"
+ "</report>\n";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt), "x");
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt), "x");
+ final StringWriter strw = new StringWriter();
t.evaluate(context, strw, 42);
- String output = strw.toString();
+ final String output = strw.toString();
int count = 0;
for (int i = 0; i < output.length(); ++i) {
- char c = output.charAt(i);
+ final char c = output.charAt(i);
if ('\n' == c) {
count += 1;
}
@@ -707,34 +707,34 @@
Assert.assertTrue(output.indexOf("44") > 0);
Assert.assertTrue(output.indexOf("45") > 0);
- TemplateDebugger td = new TemplateDebugger();
- String xxx = refactor(td, t);
+ final TemplateDebugger td = new TemplateDebugger();
+ final String xxx = refactor(td, t);
Assert.assertNotNull(xxx);
Assert.assertEquals(rpt, xxx);
}
@Test
public void testOneLiner() throws Exception {
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("fourty-two"));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("fourty-two"));
+ final StringWriter strw = new StringWriter();
t.evaluate(context, strw);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertEquals("fourty-two", output);
}
@Test
public void testOneLinerVar() throws Exception {
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("fourty-${x}"));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("fourty-${x}"));
+ final StringWriter strw = new StringWriter();
context.set("x", "two");
t.evaluate(context, strw);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertEquals("fourty-two", output);
}
@Test
public void testInterpolation() throws Exception {
- String expr = "`Hello \n${user}`";
- JexlScript script = ENGINE.createScript(expr);
+ final String expr = "`Hello \n${user}`";
+ final JexlScript script = ENGINE.createScript(expr);
context.set("user", "Dimitri");
Object value = script.execute(context);
Assert.assertEquals(expr, "Hello \nDimitri", value);
@@ -748,15 +748,15 @@
if (isLexicalShade()) {
context.set("user", null);
}
- String expr = "user='Dimitri'; `Hello \n${user}`";
- Object value = ENGINE.createScript(expr).execute(context);
+ final String expr = "user='Dimitri'; `Hello \n${user}`";
+ final Object value = ENGINE.createScript(expr).execute(context);
Assert.assertEquals(expr, "Hello \nDimitri", value);
}
@Test
public void testInterpolationLocal() throws Exception {
- String expr = "var user='Henrib'; `Hello \n${user}`";
- Object value = ENGINE.createScript(expr).execute(context);
+ final String expr = "var user='Henrib'; `Hello \n${user}`";
+ final Object value = ENGINE.createScript(expr).execute(context);
Assert.assertEquals(expr, "Hello \nHenrib", value);
}
@@ -765,8 +765,8 @@
if (isLexicalShade()) {
context.set("user", null);
}
- String expr = "user='Dimitri'; var user='Henrib'; `H\\\"ello \n${user}`";
- Object value = ENGINE.createScript(expr).execute(context);
+ final String expr = "user='Dimitri'; var user='Henrib'; `H\\\"ello \n${user}`";
+ final Object value = ENGINE.createScript(expr).execute(context);
Assert.assertEquals(expr, "H\"ello \nHenrib", value);
}
@@ -775,14 +775,14 @@
if (isLexicalShade()) {
context.set("user", null);
}
- String expr = "user='Dimitri'; var user='Henrib'; `H\\`ello \n${user}`";
- Object value = ENGINE.createScript(expr).execute(context);
+ final String expr = "user='Dimitri'; var user='Henrib'; `H\\`ello \n${user}`";
+ final Object value = ENGINE.createScript(expr).execute(context);
Assert.assertEquals(expr, "H`ello \nHenrib", value);
}
@Test
public void testInterpolationParameter() throws Exception {
- String expr = "(user)->{`Hello \n${user}`}";
+ final String expr = "(user)->{`Hello \n${user}`}";
Object value = ENGINE.createScript(expr).execute(context, "Henrib");
Assert.assertEquals(expr, "Hello \nHenrib", value);
value = ENGINE.createScript(expr).execute(context, "Dimitri");
@@ -793,7 +793,7 @@
public void testImmediateTemplate() throws Exception {
context.set("tables", new String[]{"table1", "table2"});
context.set("w" ,"x=1");
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(
"select * from \n"+
"$$var comma = false; \n"+
"$$for(var c : tables) { \n"+
@@ -802,21 +802,21 @@
"\n$$}\n"+
"where ${w}\n"
));
- StringWriter strw = new StringWriter();
+ final StringWriter strw = new StringWriter();
//vars.clear();
t.evaluate(context, strw);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertTrue(output.contains("table1") && output.contains("table2"));
}
public static class Executor311 {
private final String name;
- public Executor311(String name) {
+ public Executor311(final String name) {
this.name = name;
}
// Injects name as first arg of any called script
- public Object execute(JexlScript script, Object ...args) {
+ public Object execute(final JexlScript script, final Object ...args) {
Object[] actuals;
if (args != null && args.length > 0) {
actuals = new Object[args.length + 1] ;
@@ -833,11 +833,11 @@
implements JexlContext.OptionsHandle, JexlContext.ThreadLocal {
private JexlOptions options = null;
- public void setOptions(JexlOptions o) {
+ public void setOptions(final JexlOptions o) {
options = o;
}
- public Executor311 exec(String name) {
+ public Executor311 exec(final String name) {
return new Executor311(name);
}
@@ -854,122 +854,122 @@
@Test
public void test311a() throws Exception {
- JexlContext ctx = null;
- String rpt
+ final JexlContext ctx = null;
+ final String rpt
= "$$((a)->{\n"
+ "<p>Universe ${a}</p>\n"
+ "$$})(42)";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
+ final StringWriter strw = new StringWriter();
t.evaluate(ctx, strw);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertEquals("<p>Universe 42</p>\n", output);
}
@Test
public void test311b() throws Exception {
- JexlContext ctx311 = new Context311();
- String rpt
+ final JexlContext ctx311 = new Context311();
+ final String rpt
= "$$ exec('42').execute(()->{\n"
+ "<p>Universe 42</p>\n"
+ "$$})";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
+ final StringWriter strw = new StringWriter();
t.evaluate(ctx311, strw, 42);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertEquals("<p>Universe 42</p>\n", output);
}
@Test
public void test311c() throws Exception {
- Context311 ctx311 = new Context311();
+ final Context311 ctx311 = new Context311();
ctx311.newOptions().setLexical(true);
- String rpt
+ final String rpt
= "$$ exec('42').execute((a)->{"
+ "\n<p>Universe ${a}</p>"
+ "\n$$})";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
+ final StringWriter strw = new StringWriter();
t.evaluate(ctx311, strw, 42);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertEquals("<p>Universe 42</p>\n", output);
}
@Test
public void test311d() throws Exception {
- Context311 ctx311 = new Context311();
+ final Context311 ctx311 = new Context311();
ctx311.newOptions().setLexical(true);
- String rpt
+ final String rpt
= "$$ exec('4').execute((a, b)->{"
+ "\n<p>Universe ${a}${b}</p>"
+ "\n$$}, '2')";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
+ final StringWriter strw = new StringWriter();
t.evaluate(ctx311, strw, 42);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertEquals("<p>Universe 42</p>\n", output);
}
@Test
public void test311e() throws Exception {
- Context311 ctx311 = new Context311();
+ final Context311 ctx311 = new Context311();
ctx311.newOptions().setLexical(true);
- String rpt
+ final String rpt
= "exec('4').execute((a, b)->{"
+ " '<p>Universe ' + a + b + '</p>'"
+ "}, '2')";
- JexlScript script = JEXL.createScript(rpt);
- String output = script.execute(ctx311, 42).toString();
+ final JexlScript script = JEXL.createScript(rpt);
+ final String output = script.execute(ctx311, 42).toString();
Assert.assertEquals("<p>Universe 42</p>", output);
}
@Test
public void test311f() throws Exception {
- Context311 ctx311 = new Context311();
+ final Context311 ctx311 = new Context311();
ctx311.newOptions().setLexical(true);
- String rpt
+ final String rpt
= "exec('4').execute((a, b)->{"
+ " `<p>Universe ${a}${b}</p>`"
+ "}, '2')";
- JexlScript script = JEXL.createScript(rpt);
- String output = script.execute(ctx311, 42).toString();
+ final JexlScript script = JEXL.createScript(rpt);
+ final String output = script.execute(ctx311, 42).toString();
Assert.assertEquals("<p>Universe 42</p>", output);
}
@Test
public void test311g() throws Exception {
- Context311 ctx311 = new Context311();
+ final Context311 ctx311 = new Context311();
ctx311.newOptions().setLexical(true);
- String rpt
+ final String rpt
= "(a, b)->{"
+ " `<p>Universe ${a}${b}</p>`"
+ "}";
- JexlScript script = JEXL.createScript(rpt);
- String output = script.execute(ctx311, "4", "2").toString();
+ final JexlScript script = JEXL.createScript(rpt);
+ final String output = script.execute(ctx311, "4", "2").toString();
Assert.assertEquals("<p>Universe 42</p>", output);
}
@Test
public void test311h() throws Exception {
- Context311 ctx311 = new Context311();
+ final Context311 ctx311 = new Context311();
ctx311.newOptions().setLexical(true);
- String rpt= " `<p>Universe ${a}${b}</p>`";
- JexlScript script = JEXL.createScript(rpt, "a", "b");
- String output = script.execute(ctx311, "4", "2").toString();
+ final String rpt= " `<p>Universe ${a}${b}</p>`";
+ final JexlScript script = JEXL.createScript(rpt, "a", "b");
+ final String output = script.execute(ctx311, "4", "2").toString();
Assert.assertEquals("<p>Universe 42</p>", output);
}
@Test
public void test311i() throws Exception {
- JexlContext ctx311 = new Context311();
- String rpt
+ final JexlContext ctx311 = new Context311();
+ final String rpt
= "$$var u = 'Universe'; exec('4').execute((a, b)->{"
+ "\n<p>${u} ${a}${b}</p>"
+ "\n$$}, '2')";
- JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(rpt));
+ final StringWriter strw = new StringWriter();
t.evaluate(ctx311, strw, 42);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertEquals("<p>Universe 42</p>\n", output);
}
@@ -1011,19 +1011,19 @@
public static class PragmaticContext extends MapContext implements JexlContext.PragmaProcessor, JexlContext.OptionsHandle {
private final JexlOptions options;
- public PragmaticContext(JexlOptions o) {
+ public PragmaticContext(final JexlOptions o) {
this.options = o;
}
@Override
- public void processPragma(String key, Object value) {
+ public void processPragma(final String key, final Object value) {
if ("script.mode".equals(key) && "pro50".equals(value)) {
options.set(MODE_PRO50);
}
}
@Override
- public Object get(String name) {
+ public Object get(final String name) {
if ("$options".equals(name)) {
return options;
}
@@ -1038,53 +1038,53 @@
@Test
public void testLexicalTemplate() throws Exception {
- JexlOptions opts = new JexlOptions();
- JexlContext ctxt = new PragmaticContext(opts);
+ final JexlOptions opts = new JexlOptions();
+ final JexlContext ctxt = new PragmaticContext(opts);
opts.setCancellable(false);
opts.setStrict(false);
opts.setSafe(true);
opts.setLexical(false);
opts.setLexicalShade(false);
- String src0 = "${$options.strict?'+':'-'}strict"
+ final String src0 = "${$options.strict?'+':'-'}strict"
+ " ${$options.cancellable?'+':'-'}cancellable"
+ " ${$options.lexical?'+':'-'}lexical"
+ " ${$options.lexicalShade?'+':'-'}lexicalShade"
+ " ${$options.safe?'+':'-'}safe";
- JxltEngine.Template tmplt0 = JXLT.createTemplate("$$", new StringReader(src0));
- Writer strw0 = new StringWriter();
+ final JxltEngine.Template tmplt0 = JXLT.createTemplate("$$", new StringReader(src0));
+ final Writer strw0 = new StringWriter();
tmplt0.evaluate(ctxt, strw0);
- String output0 = strw0.toString();
+ final String output0 = strw0.toString();
Assert.assertEquals( "-strict -cancellable -lexical -lexicalShade +safe", output0);
- String src = "$$ #pragma script.mode pro50\n" + src0;
+ final String src = "$$ #pragma script.mode pro50\n" + src0;
- JxltEngine.Template tmplt = JXLT.createTemplate("$$", new StringReader(src));
- Writer strw = new StringWriter();
+ final JxltEngine.Template tmplt = JXLT.createTemplate("$$", new StringReader(src));
+ final Writer strw = new StringWriter();
tmplt.evaluate(ctxt, strw);
- String output = strw.toString();
+ final String output = strw.toString();
Assert.assertEquals("+strict +cancellable +lexical +lexicalShade -safe", output);
}
@Test
public void testTemplatePragmaPro50() throws Exception {
- JexlOptions opts = new JexlOptions();
+ final JexlOptions opts = new JexlOptions();
opts.setCancellable(false);
opts.setStrict(false);
opts.setSafe(true);
opts.setLexical(false);
opts.setLexicalShade(false);
opts.setSharedInstance(true);
- JexlContext ctxt = new PragmaticContext(opts);
- String src = "$$ #pragma script.mode pro50\n"
+ final JexlContext ctxt = new PragmaticContext(opts);
+ final String src = "$$ #pragma script.mode pro50\n"
+ "$$ var tab = null;\n"
+ "$$ tab.dummy();";
- JxltEngine.Template tmplt = JXLT.createTemplate("$$", new StringReader(src));
- Writer strw = new StringWriter();
+ final JxltEngine.Template tmplt = JXLT.createTemplate("$$", new StringReader(src));
+ final Writer strw = new StringWriter();
try {
tmplt.evaluate(ctxt, strw);
Assert.fail("tab var is null");
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.assertEquals("tab", xvar.getVariable());
Assert.assertFalse(xvar.isUndefined());
}
@@ -1092,31 +1092,31 @@
@Test
public void testTemplateOutOfScope() throws Exception {
- JexlOptions opts = new JexlOptions();
+ final JexlOptions opts = new JexlOptions();
opts.setCancellable(false);
opts.setStrict(false);
opts.setLexical(false);
opts.setLexicalShade(false);
opts.setSharedInstance(true);
- JexlContext ctxt = new PragmaticContext(opts);
- String src = "$$if (false) { var tab = 42; }\n"
+ final JexlContext ctxt = new PragmaticContext(opts);
+ final String src = "$$if (false) { var tab = 42; }\n"
+ "${tab}";
JxltEngine.Template tmplt;
- JexlFeatures features = BUILDER.features();
+ final JexlFeatures features = BUILDER.features();
try {
tmplt = JXLT.createTemplate("$$", new StringReader(src));
- } catch (JexlException xparse) {
+ } catch (final JexlException xparse) {
if (features != null && features.isLexicalShade()) {
return;
}
throw xparse;
}
- Writer strw = new StringWriter();
+ final Writer strw = new StringWriter();
opts.setSafe(true);
try {
tmplt.evaluate(ctxt, strw);
Assert.assertTrue(strw.toString().isEmpty());
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.fail("safe should prevent local shade");
}
opts.setStrict(true);
@@ -1124,37 +1124,37 @@
try {
tmplt.evaluate(ctxt, strw);
Assert.fail("tab var is undefined");
- } catch (JexlException.Variable xvar) {
+ } catch (final JexlException.Variable xvar) {
Assert.assertTrue("tab".equals(xvar.getVariable()));
Assert.assertTrue(xvar.isUndefined());
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertTrue(xany.getMessage().contains("tab"));
}
}
@Test
public void testCommentedTemplate0() throws Exception {
- JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
- JxltEngine jxlt = jexl.createJxltEngine();
+ final JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JxltEngine jxlt = jexl.createJxltEngine();
JxltEngine.Template tmplt;
- String src = "$$/*\n"
+ final String src = "$$/*\n"
+ "Hello\n"
+ "$$*/";
tmplt = jxlt.createTemplate(src);
Assert.assertNotNull(tmplt);
- Writer strw = new StringWriter();
+ final Writer strw = new StringWriter();
tmplt.evaluate(ctxt, strw);
Assert.assertTrue(strw.toString().isEmpty());
}
@Test
public void testCommentedTemplate1() throws Exception {
- JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlBuilder().create();
- JxltEngine jxlt = jexl.createJxltEngine();
+ final JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().create();
+ final JxltEngine jxlt = jexl.createJxltEngine();
JxltEngine.Template tmplt;
- String src = "$$/*\n"
+ final String src = "$$/*\n"
+ "one\n"
+ "$$*/\n"
+ "42\n"
@@ -1163,7 +1163,7 @@
+ "$$*/\n";
tmplt = jxlt.createTemplate(src);
Assert.assertNotNull(tmplt);
- Writer strw = new StringWriter();
+ final Writer strw = new StringWriter();
tmplt.evaluate(ctxt, strw);
Assert.assertEquals("42\n", strw.toString());
}
diff --git a/src/test/java/org/apache/commons/jexl3/Jexl.java b/src/test/java/org/apache/commons/jexl3/Jexl.java
index d484613..df3c78c 100644
--- a/src/test/java/org/apache/commons/jexl3/Jexl.java
+++ b/src/test/java/org/apache/commons/jexl3/Jexl.java
@@ -27,20 +27,20 @@
public class Jexl {
private Jexl() {}
- public static void main(String[] args) {
+ public static void main(final String[] args) {
final JexlEngine JEXL = new Engine();
- Map<Object,Object> m = System.getProperties();
+ final Map<Object,Object> m = System.getProperties();
// dummy context to get variables
- JexlContext context = new MapContext();
- for(Map.Entry<Object,Object> e : m.entrySet()) {
+ final JexlContext context = new MapContext();
+ for(final Map.Entry<Object,Object> e : m.entrySet()) {
context.set(e.getKey().toString(), e.getValue());
}
try {
- for (String arg : args) {
- JexlExpression e = JEXL.createExpression(arg);
+ for (final String arg : args) {
+ final JexlExpression e = JEXL.createExpression(arg);
System.out.println("evaluate(" + arg + ") = '" + e.evaluate(context) + "'");
}
- } catch (Exception e) {
+ } catch (final Exception e) {
e.printStackTrace();
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/JexlEvalContext.java b/src/test/java/org/apache/commons/jexl3/JexlEvalContext.java
index 1c8b3af..65e61f4 100644
--- a/src/test/java/org/apache/commons/jexl3/JexlEvalContext.java
+++ b/src/test/java/org/apache/commons/jexl3/JexlEvalContext.java
@@ -51,7 +51,7 @@
* @param map the variables map
*/
@NoJexl
- public JexlEvalContext(Map<String, Object> map) {
+ public JexlEvalContext(final Map<String, Object> map) {
this.vars = map == EMPTY_MAP ? new MapContext() : new MapContext(map);
this.ns = null;
}
@@ -61,7 +61,7 @@
* @param context the context (may be null, implies readonly)
*/
@NoJexl
- public JexlEvalContext(JexlContext context) {
+ public JexlEvalContext(final JexlContext context) {
this(context, context instanceof JexlContext.NamespaceResolver? (JexlContext.NamespaceResolver) context : null);
}
@@ -71,32 +71,32 @@
* @param namespace the namespace (may be null, implies empty namespace)
*/
@NoJexl
- public JexlEvalContext(JexlContext context, JexlContext.NamespaceResolver namespace) {
+ public JexlEvalContext(final JexlContext context, final JexlContext.NamespaceResolver namespace) {
this.vars = context != null? context : JexlEngine.EMPTY_CONTEXT;
this.ns = namespace != null? namespace : JexlEngine.EMPTY_NS;
}
@Override
@NoJexl
- public boolean has(String name) {
+ public boolean has(final String name) {
return vars.has(name);
}
@Override
@NoJexl
- public Object get(String name) {
+ public Object get(final String name) {
return vars.get(name);
}
@Override
@NoJexl
- public void set(String name, Object value) {
+ public void set(final String name, final Object value) {
vars.set(name, value);
}
@Override
@NoJexl
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
return ns != null? ns.resolveNamespace(name) : null;
}
diff --git a/src/test/java/org/apache/commons/jexl3/JexlTest.java b/src/test/java/org/apache/commons/jexl3/JexlTest.java
index 774787f..c9ddb70 100644
--- a/src/test/java/org/apache/commons/jexl3/JexlTest.java
+++ b/src/test/java/org/apache/commons/jexl3/JexlTest.java
@@ -57,11 +57,11 @@
* tests a simple property expression
*/
- JexlExpression e = JEXL.createExpression("foo.bar");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("foo.bar");
+ final JexlContext jc = new MapContext();
jc.set("foo", new Foo());
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertTrue("o not instanceof String", o instanceof String);
Assert.assertEquals("o incorrect", GET_METHOD_STRING, o);
@@ -69,7 +69,7 @@
@Test
public void testBoolean() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", new Foo());
jc.set("a", Boolean.TRUE);
jc.set("b", Boolean.FALSE);
@@ -87,20 +87,20 @@
/*
* tests a simple property expression
*/
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", new Foo());
assertExpression(jc, "foo.repeat(\"woogie\")", "Repeat : woogie");
}
@Test
public void testExpression() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", new Foo());
jc.set("a", Boolean.TRUE);
jc.set("b", Boolean.FALSE);
jc.set("num", new Integer(5));
jc.set("now", Calendar.getInstance().getTime());
- GregorianCalendar gc = new GregorianCalendar(5000, 11, 20);
+ final GregorianCalendar gc = new GregorianCalendar(5000, 11, 20);
jc.set("now2", gc.getTime());
jc.set("bdec", new BigDecimal("7"));
jc.set("bint", new BigInteger("7"));
@@ -154,8 +154,8 @@
@Test
public void testEmpty() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
options.setStrict(false);
jc.set("string", "");
jc.set("array", new Object[0]);
@@ -179,13 +179,13 @@
@Test
public void testSize() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
options.setStrict(false);
jc.set("s", "five!");
jc.set("array", new Object[5]);
- Map<String, Integer> map = new HashMap<String, Integer>();
+ final Map<String, Integer> map = new HashMap<String, Integer>();
map.put("1", new Integer(1));
map.put("2", new Integer(2));
@@ -195,7 +195,7 @@
jc.set("map", map);
- List<String> list = new ArrayList<String>();
+ final List<String> list = new ArrayList<String>();
list.add("1");
list.add("2");
@@ -206,13 +206,13 @@
jc.set("list", list);
// 30652 - support for set
- Set<String> set = new HashSet<String>(list);
+ final Set<String> set = new HashSet<String>(list);
set.add("1");
jc.set("set", set);
// support generic int size() method
- BitSet bitset = new BitSet(5);
+ final BitSet bitset = new BitSet(5);
jc.set("bitset", bitset);
assertExpression(jc, "size(s)", new Integer(5));
@@ -233,8 +233,8 @@
@Test
public void testSizeAsProperty() throws Exception {
- JexlContext jc = new MapContext();
- Map<String, Object> map = new HashMap<String, Object>();
+ final JexlContext jc = new MapContext();
+ final Map<String, Object> map = new HashMap<String, Object>();
map.put("size", "cheese");
map.put("si & ze", "cheese");
jc.set("map", map);
@@ -254,7 +254,7 @@
*/
@Test
public void testNew() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("double", Double.class);
jc.set("foo", "org.apache.commons.jexl3.Foo");
JexlExpression expr;
@@ -275,8 +275,8 @@
*/
@Test
public void testCalculations() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
options.setStrict(false);
options.setStrictArithmetic(false);
@@ -303,16 +303,16 @@
*/
@Test
public void testConditions() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
jc.set("foo", new Integer(2));
jc.set("aFloat", new Float(1));
jc.set("aDouble", new Double(2));
jc.set("aChar", new Character('A'));
jc.set("aBool", Boolean.TRUE);
- StringBuilder buffer = new StringBuilder("abc");
- List<Object> list = new ArrayList<Object>();
- List<Object> list2 = new LinkedList<Object>();
+ final StringBuilder buffer = new StringBuilder("abc");
+ final List<Object> list = new ArrayList<Object>();
+ final List<Object> list2 = new LinkedList<Object>();
jc.set("aBuffer", buffer);
jc.set("aList", list);
jc.set("bList", list2);
@@ -352,9 +352,9 @@
*/
@Test
public void testNotConditions() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
- Foo foo = new Foo();
+ final Foo foo = new Foo();
jc.set("x", Boolean.TRUE);
jc.set("foo", foo);
jc.set("bar", "true");
@@ -384,7 +384,7 @@
*/
@Test
public void testNotConditionsWithDots() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("x.a", Boolean.TRUE);
jc.set("x.b", Boolean.FALSE);
@@ -399,7 +399,7 @@
*/
@Test
public void testComparisons() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", "the quick and lazy fox");
assertExpression(jc, "foo.indexOf('quick') > 0", Boolean.TRUE);
@@ -412,8 +412,8 @@
*/
@Test
public void testNull() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
options.setStrict(false);
jc.set("bar", new Integer(2));
@@ -431,7 +431,7 @@
*/
@Test
public void testStringQuoting() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
assertExpression(jc, "'\"Hello\"'", "\"Hello\"");
assertExpression(jc, "\"I'm testing\"", "I'm testing");
}
@@ -441,7 +441,7 @@
*/
@Test
public void testBlankStrings() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("bar", "");
assertExpression(jc, "bar == ''", Boolean.TRUE);
@@ -455,7 +455,7 @@
*/
@Test
public void testLogicExpressions() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", "abc");
jc.set("bar", "def");
@@ -475,7 +475,7 @@
*/
@Test
public void testVariableNames() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo_bar", "123");
assertExpression(jc, "foo_bar", "123");
@@ -486,10 +486,10 @@
*/
@Test
public void testMapDot() throws Exception {
- Map<String, String> foo = new HashMap<String, String>();
+ final Map<String, String> foo = new HashMap<String, String>();
foo.put("bar", "123");
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", foo);
assertExpression(jc, "foo.bar", "123");
@@ -500,7 +500,7 @@
*/
@Test
public void testStringLiterals() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", "bar");
assertExpression(jc, "foo == \"bar\"", Boolean.TRUE);
@@ -512,13 +512,13 @@
*/
@Test
public void testIntProperty() throws Exception {
- Foo foo = new Foo();
+ final Foo foo = new Foo();
// lets check the square function first..
Assert.assertEquals(4, foo.square(2));
Assert.assertEquals(4, foo.square(-2));
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", foo);
assertExpression(jc, "foo.count", new Integer(5));
@@ -531,8 +531,8 @@
*/
@Test
public void testNegativeIntComparison() throws Exception {
- JexlContext jc = new MapContext();
- Foo foo = new Foo();
+ final JexlContext jc = new MapContext();
+ final Foo foo = new Foo();
jc.set("foo", foo);
assertExpression(jc, "foo.count != -1", Boolean.TRUE);
@@ -545,8 +545,8 @@
*/
@Test
public void testCharAtBug() throws Exception {
- JexlEvalContext jc = new JexlEvalContext();
- JexlOptions options = jc.getEngineOptions();
+ final JexlEvalContext jc = new JexlEvalContext();
+ final JexlOptions options = jc.getEngineOptions();
options.setSilent(true);
jc.set("foo", "abcdef");
@@ -559,7 +559,7 @@
@Test
public void testEmptyDottedVariableName() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("this.is.a.test", "");
@@ -568,8 +568,8 @@
@Test
public void testEmptySubListOfMap() throws Exception {
- JexlContext jc = new MapContext();
- Map<String, ArrayList<?>> m = new HashMap<String, ArrayList<?>>();
+ final JexlContext jc = new MapContext();
+ final Map<String, ArrayList<?>> m = new HashMap<String, ArrayList<?>>();
m.put("aList", new ArrayList<Object>());
jc.set("aMap", m);
@@ -579,7 +579,7 @@
@Test
public void testCoercionWithComparisionOperators() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
assertExpression(jc, "'2' > 1", Boolean.TRUE);
assertExpression(jc, "'2' >= 1", Boolean.TRUE);
@@ -604,10 +604,10 @@
public void testBooleanShortCircuitAnd() throws Exception {
// handle false for the left arg of 'and'
Foo tester = new Foo();
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("first", Boolean.FALSE);
jc.set("foo", tester);
- JexlExpression expr = JEXL.createExpression("first and foo.trueAndModify");
+ final JexlExpression expr = JEXL.createExpression("first and foo.trueAndModify");
expr.evaluate(jc);
Assert.assertFalse("Short circuit failure: rhs evaluated when lhs FALSE", tester.getModified());
// handle true for the left arg of 'and'
@@ -626,10 +626,10 @@
public void testBooleanShortCircuitOr() throws Exception {
// handle false for the left arg of 'or'
Foo tester = new Foo();
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("first", Boolean.FALSE);
jc.set("foo", tester);
- JexlExpression expr = JEXL.createExpression("first or foo.trueAndModify");
+ final JexlExpression expr = JEXL.createExpression("first or foo.trueAndModify");
expr.evaluate(jc);
Assert.assertTrue("Short circuit failure: rhs not evaluated when lhs FALSE", tester.getModified());
// handle true for the left arg of 'or'
@@ -646,7 +646,7 @@
*/
@Test
public void testStringConcatenation() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("first", "Hello");
jc.set("second", "World");
assertExpression(jc, "first + ' ' + second", "Hello World");
@@ -654,8 +654,8 @@
@Test
public void testToString() throws Exception {
- String code = "abcd";
- JexlExpression expr = JEXL.createExpression(code);
+ final String code = "abcd";
+ final JexlExpression expr = JEXL.createExpression(code);
Assert.assertEquals("Bad expression value", code, expr.toString());
}
@@ -668,7 +668,7 @@
try {
assertExpression(new MapContext(), "empty()", null);
Assert.fail("Bad expression didn't throw ParseException");
- } catch (JexlException pe) {
+ } catch (final JexlException pe) {
// expected behavior
}
}
@@ -688,11 +688,11 @@
*/
@Test
public void testAssignment() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("aString", "Hello");
- Foo foo = new Foo();
+ final Foo foo = new Foo();
jc.set("foo", foo);
- Parser parser = new Parser(new StringReader(";"));
+ final Parser parser = new Parser(new StringReader(";"));
parser.parse(null, new JexlFeatures().register(false), "aString = 'World';", null);
assertExpression(jc, "hello = 'world'", "world");
@@ -706,8 +706,8 @@
@Test
public void testAntPropertiesWithMethods() throws Exception {
- JexlContext jc = new MapContext();
- String value = "Stinky Cheese";
+ final JexlContext jc = new MapContext();
+ final String value = "Stinky Cheese";
jc.set("maven.bob.food", value);
assertExpression(jc, "maven.bob.food.length()", new Integer(value.length()));
assertExpression(jc, "empty(maven.bob.food)", Boolean.FALSE);
@@ -722,7 +722,7 @@
@Test
public void testUnicodeSupport() throws Exception {
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
assertExpression(jc, "'x' == '\\u0032?ytkownik'", Boolean.FALSE);
assertExpression(jc, "'c:\\some\\windows\\path'", "c:\\some\\windows\\path");
assertExpression(jc, "'foo\\u0020bar'", "foo\u0020bar");
@@ -734,7 +734,7 @@
int user = 10;
@SuppressWarnings("boxing")
- public Integer get(String val) {
+ public Integer get(final String val) {
if ("zero".equals(val)) {
return 0;
}
@@ -748,7 +748,7 @@
}
@SuppressWarnings("boxing")
- public void set(String val, Object value) {
+ public void set(final String val, final Object value) {
if ("user".equals(val)) {
if ("zero".equals(value)) {
user = 0;
@@ -764,8 +764,8 @@
@SuppressWarnings("boxing")
@Test
public void testDuck() throws Exception {
- JexlEngine jexl = JEXL;
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = JEXL;
+ final JexlContext jc = new MapContext();
jc.set("duck", new Duck());
JexlExpression expr;
Object result;
@@ -792,9 +792,9 @@
@SuppressWarnings("boxing")
@Test
public void testArray() throws Exception {
- int[] array = {100, 101, 102};
- JexlEngine jexl = JEXL;
- JexlContext jc = new MapContext();
+ final int[] array = {100, 101, 102};
+ final JexlEngine jexl = JEXL;
+ final JexlContext jc = new MapContext();
jc.set("array", array);
JexlExpression expr;
Object result;
@@ -813,9 +813,9 @@
* Asserts that the given expression returns the given value when applied to the
* given context
*/
- protected void assertExpression(JexlContext jc, String expression, Object expected) throws Exception {
- JexlExpression e = JEXL.createExpression(expression);
- Object actual = e.evaluate(jc);
+ protected void assertExpression(final JexlContext jc, final String expression, final Object expected) throws Exception {
+ final JexlExpression e = JEXL.createExpression(expression);
+ final Object actual = e.evaluate(jc);
Assert.assertEquals(expression, expected, actual);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/JexlTestCase.java b/src/test/java/org/apache/commons/jexl3/JexlTestCase.java
index 0edf01b..7fb5f50 100644
--- a/src/test/java/org/apache/commons/jexl3/JexlTestCase.java
+++ b/src/test/java/org/apache/commons/jexl3/JexlTestCase.java
@@ -44,11 +44,11 @@
/** A default JEXL engine instance. */
protected final JexlEngine JEXL;
- public JexlTestCase(String name) {
+ public JexlTestCase(final String name) {
this(name, new JexlBuilder().cache(128).create());
}
- protected JexlTestCase(String name, JexlEngine jexl) {
+ protected JexlTestCase(final String name, final JexlEngine jexl) {
//super(name);
JEXL = jexl;
}
@@ -66,7 +66,7 @@
return new JexlBuilder().create();
}
- public static JexlEngine createEngine(boolean lenient) {
+ public static JexlEngine createEngine(final boolean lenient) {
return new JexlBuilder().arithmetic(new JexlArithmetic(!lenient)).cache(128).create();
}
@@ -76,7 +76,7 @@
* testing them for equality with the origin.
* @throws Exception
*/
- public static void debuggerCheck(JexlEngine ijexl) throws Exception {
+ public static void debuggerCheck(final JexlEngine ijexl) throws Exception {
Util.debuggerCheck(ijexl);
}
@@ -85,7 +85,7 @@
* @param name the test method to run
* @throws Exception if anything goes wrong
*/
- public void runTest(String name) throws Exception {
+ public void runTest(final String name) throws Exception {
if ("runTest".equals(name)) {
return;
}
@@ -93,7 +93,7 @@
try {
method = this.getClass().getDeclaredMethod(name, NO_PARMS);
}
- catch(Exception xany) {
+ catch(final Exception xany) {
Assert.fail("no such test: " + name);
return;
}
@@ -117,15 +117,15 @@
* @param mname the test class method
* @throws Exception
*/
- public static void runTest(String tname, String mname) throws Exception {
- String testClassName = "org.apache.commons.jexl3."+tname;
+ public static void runTest(final String tname, final String mname) throws Exception {
+ final String testClassName = "org.apache.commons.jexl3."+tname;
Class<JexlTestCase> clazz = null;
JexlTestCase test = null;
// find the class
try {
clazz = (Class<JexlTestCase>) Class.forName(testClassName);
}
- catch(ClassNotFoundException xclass) {
+ catch(final ClassNotFoundException xclass) {
Assert.fail("no such class: " + testClassName);
return;
}
@@ -135,17 +135,17 @@
ctor = clazz.getConstructor(STRING_PARM);
test = ctor.newInstance("debug");
}
- catch(NoSuchMethodException xctor) {
+ catch(final NoSuchMethodException xctor) {
// instantiate default class ctor
try {
test = clazz.newInstance();
}
- catch(Exception xany) {
+ catch(final Exception xany) {
Assert.fail("cant instantiate test: " + xany);
return;
}
}
- catch(Exception xany) {
+ catch(final Exception xany) {
Assert.fail("cant instantiate test: " + xany);
return;
}
@@ -158,7 +158,7 @@
* @param args where args[0] is the test class name and args[1] the test class method
* @throws Exception
*/
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
runTest(args[0], args[1]);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/LambdaTest.java b/src/test/java/org/apache/commons/jexl3/LambdaTest.java
index 025704b..b696b31 100644
--- a/src/test/java/org/apache/commons/jexl3/LambdaTest.java
+++ b/src/test/java/org/apache/commons/jexl3/LambdaTest.java
@@ -34,22 +34,22 @@
@Test
public void testScriptArguments() throws Exception {
- JexlEngine jexl = createEngine();
- JexlScript s = jexl.createScript(" x + x ", "x");
- JexlScript s42 = jexl.createScript("s(21)", "s");
- Object result = s42.execute(null, s);
+ final JexlEngine jexl = createEngine();
+ final JexlScript s = jexl.createScript(" x + x ", "x");
+ final JexlScript s42 = jexl.createScript("s(21)", "s");
+ final Object result = s42.execute(null, s);
Assert.assertEquals(42, result);
}
@Test
public void testScriptContext() throws Exception {
- JexlEngine jexl = createEngine();
- JexlScript s = jexl.createScript("function(x) { x + x }");
- String fsstr = s.getParsedText(0);
+ final JexlEngine jexl = createEngine();
+ final JexlScript s = jexl.createScript("function(x) { x + x }");
+ final String fsstr = s.getParsedText(0);
Assert.assertEquals("(x)->{ x + x; }", fsstr);
Assert.assertEquals(42, s.execute(null, 21));
JexlScript s42 = jexl.createScript("s(21)");
- JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlEvalContext ctxt = new JexlEvalContext();
ctxt.set("s", s);
Object result = s42.execute(ctxt);
Assert.assertEquals(42, result);
@@ -62,7 +62,7 @@
@Test
public void testLambda() throws Exception {
- JexlEngine jexl = createEngine();
+ final JexlEngine jexl = createEngine();
String strs = "var s = function(x) { x + x }; s(21)";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(null);
@@ -75,7 +75,7 @@
@Test
public void testLambdaClosure() throws Exception {
- JexlEngine jexl = createEngine();
+ final JexlEngine jexl = createEngine();
String strs = "var t = 20; var s = function(x, y) { x + y + t}; s(15, 7)";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(null);
@@ -96,7 +96,7 @@
@Test
public void testLambdaLambda() throws Exception {
- JexlEngine jexl = createEngine();
+ final JexlEngine jexl = createEngine();
String strs = "var t = 19; ( (x, y)->{ var t = 20; x + y + t} )(15, 7);";
JexlScript s42 = jexl.createScript(strs);
Object result = s42.execute(null);
@@ -115,30 +115,30 @@
@Test
public void testNestLambda() throws Exception {
- JexlEngine jexl = createEngine();
- String strs = "( (x)->{ (y)->{ x + y } })(15)(27)";
- JexlScript s42 = jexl.createScript(strs);
- Object result = s42.execute(null);
+ final JexlEngine jexl = createEngine();
+ final String strs = "( (x)->{ (y)->{ x + y } })(15)(27)";
+ final JexlScript s42 = jexl.createScript(strs);
+ final Object result = s42.execute(null);
Assert.assertEquals(42, result);
}
@Test
public void testNestLambada() throws Exception {
- JexlEngine jexl = createEngine();
- JexlContext ctx = null;
- String strs = "(x)->{ (y)->{ x + y } }";
- JexlScript s42 = jexl.createScript(strs);
- JexlScript s42b = jexl.createScript(s42.toString());
+ final JexlEngine jexl = createEngine();
+ final JexlContext ctx = null;
+ final String strs = "(x)->{ (y)->{ x + y } }";
+ final JexlScript s42 = jexl.createScript(strs);
+ final JexlScript s42b = jexl.createScript(s42.toString());
Assert.assertEquals(s42.hashCode(), s42b.hashCode());
Assert.assertEquals(s42, s42b);
Object result = s42.execute(ctx, 15);
Assert.assertTrue(result instanceof JexlScript);
- Object resultb = s42.execute(ctx, 15);
+ final Object resultb = s42.execute(ctx, 15);
Assert.assertEquals(result.hashCode(), resultb.hashCode());
Assert.assertEquals(result, resultb);
Assert.assertEquals(result, jexl.createScript(resultb.toString(), "x").execute(ctx, 15));
- JexlScript s15 = (JexlScript) result;
- Callable<Object> s15b = s15.callable(ctx, 27);
+ final JexlScript s15 = (JexlScript) result;
+ final Callable<Object> s15b = s15.callable(ctx, 27);
result = s15.execute(ctx, 27);
Assert.assertEquals(42, result);
result = s15b.call();
@@ -147,8 +147,8 @@
@Test
public void testHoistLambda() throws Exception {
- JexlEngine jexl = createEngine();
- JexlEvalContext ctx = new JexlEvalContext();
+ final JexlEngine jexl = createEngine();
+ final JexlEvalContext ctx = new JexlEvalContext();
ctx.getEngineOptions().setLexical(false);
JexlScript s42;
Object result;
@@ -188,55 +188,55 @@
@Test
public void testRecurse() throws Exception {
- JexlEngine jexl = createEngine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = createEngine();
+ final JexlContext jc = new MapContext();
try {
- JexlScript script = jexl.createScript("var fact = (x)->{ if (x <= 1) 1; else x * fact(x - 1) }; fact(5)");
- int result = (Integer) script.execute(jc);
+ final JexlScript script = jexl.createScript("var fact = (x)->{ if (x <= 1) 1; else x * fact(x - 1) }; fact(5)");
+ final int result = (Integer) script.execute(jc);
Assert.assertEquals(120, result);
- } catch (JexlException xany) {
- String msg = xany.toString();
+ } catch (final JexlException xany) {
+ final String msg = xany.toString();
throw xany;
}
}
@Test
public void testRecurse2() throws Exception {
- JexlEngine jexl = createEngine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = createEngine();
+ final JexlContext jc = new MapContext();
// adding some captured vars to get it confused
try {
- JexlScript script = jexl.createScript(
+ final JexlScript script = jexl.createScript(
"var y = 1; var z = 1; "
+"var fact = (x)->{ if (x <= y) z; else x * fact(x - 1) }; fact(6)");
- int result = (Integer) script.execute(jc);
+ final int result = (Integer) script.execute(jc);
Assert.assertEquals(720, result);
- } catch (JexlException xany) {
- String msg = xany.toString();
+ } catch (final JexlException xany) {
+ final String msg = xany.toString();
throw xany;
}
}
@Test
public void testRecurse3() throws Exception {
- JexlEngine jexl = createEngine();
- JexlContext jc = new MapContext();
+ final JexlEngine jexl = createEngine();
+ final JexlContext jc = new MapContext();
// adding some captured vars to get it confused
try {
- JexlScript script = jexl.createScript(
+ final JexlScript script = jexl.createScript(
"var y = 1; var z = 1;var foo = (x)->{y + z}; "
+"var fact = (x)->{ if (x <= y) z; else x * fact(x - 1) }; fact(6)");
- int result = (Integer) script.execute(jc);
+ final int result = (Integer) script.execute(jc);
Assert.assertEquals(720, result);
- } catch (JexlException xany) {
- String msg = xany.toString();
+ } catch (final JexlException xany) {
+ final String msg = xany.toString();
throw xany;
}
}
@Test
public void testIdentity() throws Exception {
- JexlEngine jexl = createEngine();
+ final JexlEngine jexl = createEngine();
JexlScript script;
Object result;
@@ -248,12 +248,12 @@
@Test
public void testCurry1() throws Exception {
- JexlEngine jexl = createEngine();
+ final JexlEngine jexl = createEngine();
JexlScript script;
Object result;
String[] parms;
- JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
+ final JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
parms = base.getUnboundParameters();
Assert.assertEquals(3, parms.length);
script = base.curry(5);
@@ -271,12 +271,12 @@
@Test
public void testCurry2() throws Exception {
- JexlEngine jexl = createEngine();
+ final JexlEngine jexl = createEngine();
JexlScript script;
Object result;
String[] parms;
- JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
+ final JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
script = base.curry(5, 15);
parms = script.getUnboundParameters();
Assert.assertEquals(1, parms.length);
@@ -287,11 +287,11 @@
@Test
public void testCurry3() throws Exception {
- JexlEngine jexl = createEngine();
+ final JexlEngine jexl = createEngine();
JexlScript script;
Object result;
- JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
+ final JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
script = base.curry(5, 15);
result = script.execute(null, 22);
Assert.assertEquals(42, result);
@@ -299,13 +299,13 @@
@Test
public void test270() throws Exception {
- JexlEngine jexl = createEngine();
- JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
- String text = base.toString();
+ final JexlEngine jexl = createEngine();
+ final JexlScript base = jexl.createScript("(x, y, z)->{ x + y + z }");
+ final String text = base.toString();
JexlScript script = base.curry(5, 15);
Assert.assertEquals(text, script.toString());
- JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlEvalContext ctxt = new JexlEvalContext();
ctxt.set("s", base);
script = jexl.createScript("return s");
Object result = script.execute(ctxt);
@@ -318,35 +318,35 @@
@Test
public void test271a() throws Exception {
- JexlEngine jexl = createEngine();
- JexlScript base = jexl.createScript("var base = 1; var x = (a)->{ var y = (b) -> {base + b}; return base + y(a)}; x(40)");
- Object result = base.execute(null);
+ final JexlEngine jexl = createEngine();
+ final JexlScript base = jexl.createScript("var base = 1; var x = (a)->{ var y = (b) -> {base + b}; return base + y(a)}; x(40)");
+ final Object result = base.execute(null);
Assert.assertEquals(42, result);
}
@Test
public void test271b() throws Exception {
- JexlEngine jexl = createEngine();
- JexlScript base = jexl.createScript("var base = 2; var sum = (x, y, z)->{ base + x + y + z }; var y = sum.curry(1); y(2,3)");
- Object result = base.execute(null);
+ final JexlEngine jexl = createEngine();
+ final JexlScript base = jexl.createScript("var base = 2; var sum = (x, y, z)->{ base + x + y + z }; var y = sum.curry(1); y(2,3)");
+ final Object result = base.execute(null);
Assert.assertEquals(8, result);
}
@Test
public void test271c() throws Exception {
- JexlEngine jexl = createEngine();
- JexlScript base = jexl.createScript("(x, y, z)->{ 2 + x + y + z };");
- JexlScript y = base.curry(1);
- Object result = y.execute(null, 2, 3);
+ final JexlEngine jexl = createEngine();
+ final JexlScript base = jexl.createScript("(x, y, z)->{ 2 + x + y + z };");
+ final JexlScript y = base.curry(1);
+ final Object result = y.execute(null, 2, 3);
Assert.assertEquals(8, result);
}
@Test
public void test271d() throws Exception {
- JexlEngine jexl = createEngine();
- JexlScript base = jexl.createScript("var base = 2; return (x, y, z)->{ base + x + y + z };");
- JexlScript y = ((JexlScript) base.execute(null)).curry(1);
- Object result = y.execute(null, 2, 3);
+ final JexlEngine jexl = createEngine();
+ final JexlScript base = jexl.createScript("var base = 2; return (x, y, z)->{ base + x + y + z };");
+ final JexlScript y = ((JexlScript) base.execute(null)).curry(1);
+ final Object result = y.execute(null, 2, 3);
Assert.assertEquals(8, result);
}
diff --git a/src/test/java/org/apache/commons/jexl3/LexicalTest.java b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
index 58e05a8..8f1f256 100644
--- a/src/test/java/org/apache/commons/jexl3/LexicalTest.java
+++ b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
@@ -43,12 +43,12 @@
runLexical0(true);
}
- void runLexical0(boolean feature) throws Exception {
- JexlFeatures f = new JexlFeatures();
+ void runLexical0(final boolean feature) throws Exception {
+ final JexlFeatures f = new JexlFeatures();
f.lexical(feature);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setLexical(true);
JexlScript script;
@@ -58,8 +58,8 @@
script.execute(ctxt);
}
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
try {
script = jexl.createScript("var x = 0; for(var y : null) { var y = 1;");
@@ -67,8 +67,8 @@
script.execute(ctxt);
}
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
try {
script = jexl.createScript("var x = 0; for(var x : null) {};");
@@ -76,8 +76,8 @@
script.execute(ctxt);
}
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
try {
script = jexl.createScript("(x)->{ var x = 0; x; }");
@@ -85,8 +85,8 @@
script.execute(ctxt);
}
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
try {
script = jexl.createScript("var x; if (true) { if (true) { var x = 0; x; } }");
@@ -94,8 +94,8 @@
script.execute(ctxt);
}
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
try {
script = jexl.createScript("if (a) { var y = (x)->{ var x = 0; x; }; y(2) }", "a");
@@ -103,8 +103,8 @@
script.execute(ctxt);
}
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
try {
script = jexl.createScript("(x)->{ for(var x : null) { x; } }");
@@ -112,8 +112,8 @@
script.execute(ctxt, 42);
}
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
// no fail
script = jexl.createScript("var x = 32; (()->{ for(var x : null) { x; }})();");
@@ -132,12 +132,12 @@
runLexical1(true);
}
- void runLexical1(boolean shade) throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).create();
- JexlEvalContext ctxt = new JexlEvalContext();
+ void runLexical1(final boolean shade) throws Exception {
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final JexlEvalContext ctxt = new JexlEvalContext();
Object result;
ctxt.set("x", 4242);
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setLexical(true);
options.setLexicalShade(shade);
@@ -149,7 +149,7 @@
if (shade) {
Assert.fail("local shade means 'x' should be undefined");
}
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
if (!shade) {
throw xany;
}
@@ -161,7 +161,7 @@
if (shade) {
Assert.fail("local shade means 'x = 42' should be undefined");
}
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
if (!shade) {
throw xany;
}
@@ -173,7 +173,7 @@
if (shade) {
Assert.fail("local shade means 'y = 42' should be undefined (y is undefined)");
}
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
if (!shade) {
throw xany;
}
@@ -194,7 +194,7 @@
} else {
Assert.fail("local shade means 'y = 42' should be undefined");
}
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
if (!shade) {
throw xany;
}
@@ -203,9 +203,9 @@
@Test
public void testLexical1() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).create();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlEngine jexl = new JexlBuilder().strict(true).create();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
// ensure errors will throw
options.setLexical(true);
JexlScript script;
@@ -216,16 +216,16 @@
result = script.execute(ctxt);
//Assert.assertEquals(42, result);
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
try {
script = jexl.createScript("(x)->{ if (x) { var x = 7 * (x + x); x; } }");
result = script.execute(ctxt, 3);
Assert.fail();
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
}
script = jexl.createScript("{ var x = 0; } var x = 42; x");
@@ -243,11 +243,11 @@
runLexical2(false);
}
- protected void runLexical2(boolean lexical) throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(lexical).create();
- JexlContext ctxt = new MapContext();
- JexlScript script = jexl.createScript("{var x = 42}; {var x; return x; }");
- Object result = script.execute(ctxt);
+ protected void runLexical2(final boolean lexical) throws Exception {
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(lexical).create();
+ final JexlContext ctxt = new MapContext();
+ final JexlScript script = jexl.createScript("{var x = 42}; {var x; return x; }");
+ final Object result = script.execute(ctxt);
if (lexical) {
Assert.assertNull(result);
} else {
@@ -257,10 +257,10 @@
@Test
public void testLexical3() throws Exception {
- String str = "var s = {}; for (var i : [1]) s.add(i); s";
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
+ final String str = "var s = {}; for (var i : [1]) s.add(i); s";
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
JexlScript e = jexl.createScript(str);
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
Object o = e.execute(jc);
Assert.assertTrue(((Set)o).contains(1));
@@ -271,90 +271,90 @@
@Test
public void testLexical4() throws Exception {
- JexlEngine Jexl = new JexlBuilder().silent(false).strict(true).lexical(true).create();
- JxltEngine Jxlt = Jexl.createJxltEngine();
- JexlContext ctxt = new MapContext();
- String rpt
+ final JexlEngine Jexl = new JexlBuilder().silent(false).strict(true).lexical(true).create();
+ final JxltEngine Jxlt = Jexl.createJxltEngine();
+ final JexlContext ctxt = new MapContext();
+ final String rpt
= "<report>\n"
+ "\n$$var y = 1; var x = 2;"
+ "\n${x + y}"
+ "\n</report>\n";
- JxltEngine.Template t = Jxlt.createTemplate("$$", new StringReader(rpt));
- StringWriter strw = new StringWriter();
+ final JxltEngine.Template t = Jxlt.createTemplate("$$", new StringReader(rpt));
+ final StringWriter strw = new StringWriter();
t.evaluate(ctxt, strw);
- String output = strw.toString();
- String ctl = "<report>\n\n3\n</report>\n";
+ final String output = strw.toString();
+ final String ctl = "<report>\n\n3\n</report>\n";
Assert.assertEquals(ctl, output);
}
public static class DebugContext extends MapContext {
public DebugContext() {
}
- public Object debug(Object arg) {
+ public Object debug(final Object arg) {
return arg;
}
}
@Test
public void testLexical5() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
- JexlContext ctxt = new DebugContext();
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
+ final JexlContext ctxt = new DebugContext();
JexlScript script;
Object result;
script = jexl.createScript("var x = 42; var y = () -> { {var x = debug(-42); }; return x; }; y()");
try {
result = script.execute(ctxt);
Assert.assertEquals(42, result);
- } catch (JexlException xany) {
- String ww = xany.toString();
+ } catch (final JexlException xany) {
+ final String ww = xany.toString();
Assert.fail(ww);
}
}
@Test
public void testLexical6a() throws Exception {
- String str = "i = 0; { var i = 32; }; i";
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
- JexlScript e = jexl.createScript(str);
- JexlContext ctxt = new MapContext();
- Object o = e.execute(ctxt);
+ final String str = "i = 0; { var i = 32; }; i";
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
+ final JexlScript e = jexl.createScript(str);
+ final JexlContext ctxt = new MapContext();
+ final Object o = e.execute(ctxt);
Assert.assertEquals(0, o);
}
@Test
public void testLexical6b() throws Exception {
- String str = "i = 0; { var i = 32; }; i";
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).lexicalShade(true).create();
- JexlScript e = jexl.createScript(str);
- JexlContext ctxt = new MapContext();
+ final String str = "i = 0; { var i = 32; }; i";
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).lexicalShade(true).create();
+ final JexlScript e = jexl.createScript(str);
+ final JexlContext ctxt = new MapContext();
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.fail("i should be shaded");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertNotNull(xany);
}
}
@Test
public void testLexical6c() throws Exception {
- String str = "i = 0; for (var i : [42]) i; i";
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).lexicalShade(false).create();
- JexlScript e = jexl.createScript(str);
- JexlContext ctxt = new MapContext();
- Object o = e.execute(ctxt);
+ final String str = "i = 0; for (var i : [42]) i; i";
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).lexicalShade(false).create();
+ final JexlScript e = jexl.createScript(str);
+ final JexlContext ctxt = new MapContext();
+ final Object o = e.execute(ctxt);
Assert.assertEquals(0, o);
}
@Test
public void testLexical6d() throws Exception {
- String str = "i = 0; for (var i : [42]) i; i";
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).lexicalShade(true).create();
- JexlScript e = jexl.createScript(str);
- JexlContext ctxt = new MapContext();
+ final String str = "i = 0; for (var i : [42]) i; i";
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).lexicalShade(true).create();
+ final JexlScript e = jexl.createScript(str);
+ final JexlContext ctxt = new MapContext();
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.fail("i should be shaded");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertNotNull(xany);
}
}
@@ -362,15 +362,15 @@
@Test
public void testPragmaOptions() throws Exception {
// same as 6d but using a pragma
- String str = "#pragma jexl.options '+strict +lexical +lexicalShade -safe'\n"
+ final String str = "#pragma jexl.options '+strict +lexical +lexicalShade -safe'\n"
+ "i = 0; for (var i : [42]) i; i";
- JexlEngine jexl = new JexlBuilder().strict(false).create();
- JexlScript e = jexl.createScript(str);
- JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().strict(false).create();
+ final JexlScript e = jexl.createScript(str);
+ final JexlContext ctxt = new MapContext();
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.fail("i should be shaded");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertNotNull(xany);
}
}
@@ -378,18 +378,18 @@
@Test
public void testPragmaNoop() throws Exception {
// unknow pragma
- String str = "#pragma jexl.options 'no effect'\ni = -42; for (var i : [42]) i; i";
- JexlEngine jexl = new JexlBuilder().lexical(false).strict(true).create();
- JexlScript e = jexl.createScript(str);
- JexlContext ctxt = new MapContext();
- Object result = e.execute(ctxt);
+ final String str = "#pragma jexl.options 'no effect'\ni = -42; for (var i : [42]) i; i";
+ final JexlEngine jexl = new JexlBuilder().lexical(false).strict(true).create();
+ final JexlScript e = jexl.createScript(str);
+ final JexlContext ctxt = new MapContext();
+ final Object result = e.execute(ctxt);
Assert.assertEquals(42, result);
}
@Test
public void testScopeFrame() throws Exception {
- LexicalScope scope = new LexicalScope();
+ final LexicalScope scope = new LexicalScope();
for(int i = 0; i < 128; i += 2) {
Assert.assertTrue(scope.addSymbol(i));
Assert.assertFalse(scope.addSymbol(i));
@@ -402,19 +402,19 @@
@Test
public void testContextualOptions0() throws Exception {
- JexlFeatures f= new JexlFeatures();
- JexlEngine jexl = new JexlBuilder().features(f).strict(true).create();
- JexlEvalContext ctxt = new JexlEvalContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlFeatures f= new JexlFeatures();
+ final JexlEngine jexl = new JexlBuilder().features(f).strict(true).create();
+ final JexlEvalContext ctxt = new JexlEvalContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setSharedInstance(false);
options.setLexical(true);
options.setLexicalShade(true);
ctxt.set("options", options);
- JexlScript script = jexl.createScript("{var x = 42;} options.lexical = false; options.lexicalShade=false; x");
+ final JexlScript script = jexl.createScript("{var x = 42;} options.lexical = false; options.lexicalShade=false; x");
try {
- Object result = script.execute(ctxt);
+ final Object result = script.execute(ctxt);
Assert.fail("setting options.lexical should have no effect during execution");
- } catch(JexlException xf) {
+ } catch(final JexlException xf) {
Assert.assertNotNull(xf);
}
}
@@ -424,7 +424,7 @@
*/
public static class TestContext extends JexlEvalContext {
public TestContext() {}
- public TestContext(Map<String, Object> map) {
+ public TestContext(final Map<String, Object> map) {
super(map);
}
@@ -435,11 +435,11 @@
* @param args the arguments to the lambda
* @return the tryFn result or the catchFn if an exception was raised
*/
- public Object tryCatch(JexlScript tryFn, JexlScript catchFn, Object... args) {
+ public Object tryCatch(final JexlScript tryFn, final JexlScript catchFn, final Object... args) {
Object result;
try {
result = tryFn.execute(this, args);
- } catch (Throwable xthrow) {
+ } catch (final Throwable xthrow) {
result = catchFn != null ? catchFn.execute(this, xthrow) : xthrow;
}
return result;
@@ -448,20 +448,20 @@
@Test
public void testContextualOptions1() throws Exception {
- JexlFeatures f = new JexlFeatures();
- JexlEngine jexl = new JexlBuilder().features(f).strict(true).create();
- JexlEvalContext ctxt = new TestContext();
- JexlOptions options = ctxt.getEngineOptions();
+ final JexlFeatures f = new JexlFeatures();
+ final JexlEngine jexl = new JexlBuilder().features(f).strict(true).create();
+ final JexlEvalContext ctxt = new TestContext();
+ final JexlOptions options = ctxt.getEngineOptions();
options.setSharedInstance(true);
options.setLexical(true);
options.setLexicalShade(true);
ctxt.set("options", options);
- JexlScript runner = jexl.createScript(
+ final JexlScript runner = jexl.createScript(
"options.lexical = flag; options.lexicalShade = flag;"
+ "tryCatch(test, catch, 42);",
"flag", "test", "catch");
- JexlScript tested = jexl.createScript("(y)->{ {var x = y;} x }");
- JexlScript catchFn = jexl.createScript("(xany)-> { xany }");
+ final JexlScript tested = jexl.createScript("(y)->{ {var x = y;} x }");
+ final JexlScript catchFn = jexl.createScript("(xany)-> { xany }");
Object result;
// run it once, old 3.1 semantics, lexical/shade = false
result = runner.execute(ctxt, false, tested, catchFn);
@@ -475,8 +475,8 @@
@Test
public void testParameter0() throws Exception {
- String str = "function(u) {}";
- JexlEngine jexl = new JexlBuilder().create();
+ final String str = "function(u) {}";
+ final JexlEngine jexl = new JexlBuilder().create();
JexlScript e = jexl.createScript(str);
Assert.assertEquals(1, e.getParameters().length);
e = jexl.createScript(new JexlInfo("TestScript", 1, 1), str);
@@ -485,20 +485,20 @@
@Test
public void testParameter1() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
- JexlContext jc = new MapContext();
- String strs = "var s = function(x) { for (var i : 1..3) {if (i > 2) return x}}; s(42)";
- JexlScript s42 = jexl.createScript(strs);
- Object result = s42.execute(jc);
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
+ final JexlContext jc = new MapContext();
+ final String strs = "var s = function(x) { for (var i : 1..3) {if (i > 2) return x}}; s(42)";
+ final JexlScript s42 = jexl.createScript(strs);
+ final Object result = s42.execute(jc);
Assert.assertEquals(42, result);
}
@Test
public void testInnerAccess0() throws Exception {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
- JexlScript script = jexl.createScript(
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlScript script = jexl.createScript(
"var x = 32; ("
+ "()->{ for(var x : null) { var c = 0; {return x; }} })"
+ "();");
@@ -507,34 +507,34 @@
@Test
public void testInnerAccess1() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
- JexlScript script = jexl.createScript("var x = 32; (()->{ for(var x : null) { var c = 0; {return x; }} })();");
+ final JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
+ final JexlScript script = jexl.createScript("var x = 32; (()->{ for(var x : null) { var c = 0; {return x; }} })();");
}
@Test
public void testForVariable0() throws Exception {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
f.lexicalShade(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
try {
- JexlScript script = jexl.createScript("for(var x : 1..3) { var c = 0}; return x");
+ final JexlScript script = jexl.createScript("for(var x : 1..3) { var c = 0}; return x");
Assert.fail("Should not have been parsed");
- } catch (JexlException ex) {
+ } catch (final JexlException ex) {
// OK
}
}
@Test
public void testForVariable1() throws Exception {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
f.lexicalShade(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
try {
- JexlScript script = jexl.createScript("for(var x : 1..3) { var c = 0} for(var x : 1..3) { var c = 0}; return x");
+ final JexlScript script = jexl.createScript("for(var x : 1..3) { var c = 0} for(var x : 1..3) { var c = 0}; return x");
Assert.fail("Should not have been parsed");
- } catch (JexlException ex) {
+ } catch (final JexlException ex) {
// OK
Assert.assertTrue(ex instanceof JexlException);
}
@@ -542,14 +542,14 @@
@Test
public void testUndeclaredVariable() throws Exception {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
f.lexicalShade(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
try {
- JexlScript script = jexl.createScript("{var x = 0}; return x");
+ final JexlScript script = jexl.createScript("{var x = 0}; return x");
Assert.fail("Should not have been parsed");
- } catch (Exception ex) {
+ } catch (final Exception ex) {
// OK
Assert.assertTrue(ex instanceof JexlException);
}
@@ -557,13 +557,13 @@
@Test
public void testLexical6a1() throws Exception {
- String str = "i = 0; { var i = 32; }; i";
- JexlFeatures f = new JexlFeatures();
+ final String str = "i = 0; { var i = 32; }; i";
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
- JexlScript e = jexl.createScript(str);
- JexlContext ctxt = new MapContext();
- Object o = e.execute(ctxt);
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlScript e = jexl.createScript(str);
+ final JexlContext ctxt = new MapContext();
+ final Object o = e.execute(ctxt);
Assert.assertEquals(0, o);
}
@@ -571,13 +571,13 @@
private JexlOptions options = new JexlOptions();
JexlOptions snatchOptions() {
- JexlOptions o = options;
+ final JexlOptions o = options;
options = new JexlOptions();
return o;
}
@Override
- public void processPragma(String key, Object value) {
+ public void processPragma(final String key, final Object value) {
if ("jexl.options".equals(key) && "canonical".equals(value)) {
options.setStrict(true);
options.setLexical(true);
@@ -594,21 +594,21 @@
@Test
public void testInternalLexicalFeatures() throws Exception {
- String str = "42";
- JexlFeatures f = new JexlFeatures();
+ final String str = "42";
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
f.lexicalShade(true);
- JexlEngine jexl = new JexlBuilder().features(f).create();
- JexlScript e = jexl.createScript(str);
- VarContext vars = new VarContext();
- JexlOptions opts = vars.getEngineOptions();
+ final JexlEngine jexl = new JexlBuilder().features(f).create();
+ final JexlScript e = jexl.createScript(str);
+ final VarContext vars = new VarContext();
+ final JexlOptions opts = vars.getEngineOptions();
// so we can see the effect of features on options
opts.setSharedInstance(true);
- Script script = (Script) e;
- JexlFeatures features = script.getFeatures();
+ final Script script = (Script) e;
+ final JexlFeatures features = script.getFeatures();
Assert.assertTrue(features.isLexical());
Assert.assertTrue(features.isLexicalShade());
- Object result = e.execute(vars);
+ final Object result = e.execute(vars);
Assert.assertEquals(42, result);
Assert.assertTrue(opts.isLexical());
Assert.assertTrue(opts.isLexicalShade());
@@ -618,8 +618,8 @@
public void testOptionsPragma() throws Exception {
try {
JexlOptions.setDefaultFlags("+safe", "-lexical", "-lexicalShade");
- VarContext vars = new VarContext();
- JexlEngine jexl = new JexlBuilder().create();
+ final VarContext vars = new VarContext();
+ final JexlEngine jexl = new JexlBuilder().create();
int n42;
JexlOptions o;
@@ -650,54 +650,54 @@
@Test
public void testVarLoop0() throws Exception {
- String src0 = "var count = 10;\n"
+ final String src0 = "var count = 10;\n"
+ "for (var i : 0 .. count-1) {\n"
+ " $out.add(i);\n"
+ "}";
- String src1 = "var count = [0,1,2,3,4,5,6,7,8,9];\n"
+ final String src1 = "var count = [0,1,2,3,4,5,6,7,8,9];\n"
+ "for (var i : count) {\n"
+ " $out.add(i);\n"
+ "}";
- String src2 = "var count = 10;\n" +
+ final String src2 = "var count = 10;\n" +
" var outer = 0;\n"
+ "for (var i : 0 .. count-1) {\n"
+ " $out.add(i);\n"
+ " outer = i;"
+ "}\n"
+ "outer == 9";
- JexlFeatures ff0 = runVarLoop(false, src0);
- JexlFeatures ft0= runVarLoop(true, src0);
- JexlFeatures ff1 = runVarLoop(false, src1);
- JexlFeatures ft1= runVarLoop(true, src1);
- JexlFeatures ff2 = runVarLoop(false, src2);
- JexlFeatures ft2= runVarLoop(true, src2);
+ final JexlFeatures ff0 = runVarLoop(false, src0);
+ final JexlFeatures ft0= runVarLoop(true, src0);
+ final JexlFeatures ff1 = runVarLoop(false, src1);
+ final JexlFeatures ft1= runVarLoop(true, src1);
+ final JexlFeatures ff2 = runVarLoop(false, src2);
+ final JexlFeatures ft2= runVarLoop(true, src2);
// and check some features features
Assert.assertEquals(ff0, ff1);
Assert.assertEquals(ft0, ft1);
Assert.assertNotEquals(ff0, ft0);
- String sff0 = ff0.toString();
- String sff1 = ff1.toString();
+ final String sff0 = ff0.toString();
+ final String sff1 = ff1.toString();
Assert.assertEquals(sff0, sff1);
- String sft1 = ft1.toString();
+ final String sft1 = ft1.toString();
Assert.assertNotEquals(sff0, sft1);
}
- private JexlFeatures runVarLoop(boolean flag, String src) throws Exception {
- VarContext vars = new VarContext();
- JexlOptions options = vars.getEngineOptions();
+ private JexlFeatures runVarLoop(final boolean flag, final String src) throws Exception {
+ final VarContext vars = new VarContext();
+ final JexlOptions options = vars.getEngineOptions();
options.setLexical(true);
options.setLexicalShade(true);
options.setSafe(false);
- JexlFeatures features = new JexlFeatures();
+ final JexlFeatures features = new JexlFeatures();
if (flag) {
features.lexical(true).lexicalShade(true);
}
- JexlEngine jexl = new JexlBuilder().features(features).create();
- JexlScript script = jexl.createScript(src);
- List<Integer> out = new ArrayList<Integer>(10);
+ final JexlEngine jexl = new JexlBuilder().features(features).create();
+ final JexlScript script = jexl.createScript(src);
+ final List<Integer> out = new ArrayList<Integer>(10);
vars.set("$out", out);
- Object result = script.execute(vars);
+ final Object result = script.execute(vars);
Assert.assertEquals(true, result);
Assert.assertEquals(10, out.size());
return features;
@@ -705,12 +705,12 @@
public static class OptAnnotationContext extends JexlEvalContext implements JexlContext.AnnotationProcessor {
@Override
- public Object processAnnotation(String name, Object[] args, Callable<Object> statement) throws Exception {
+ public Object processAnnotation(final String name, final Object[] args, final Callable<Object> statement) throws Exception {
// transient side effect for strict
if ("scale".equals(name)) {
- JexlOptions options = this.getEngineOptions();
- int scale = options.getMathScale();
- int newScale = (Integer) args[0];
+ final JexlOptions options = this.getEngineOptions();
+ final int scale = options.getMathScale();
+ final int newScale = (Integer) args[0];
options.setMathScale(newScale);
try {
return statement.call();
@@ -724,48 +724,48 @@
@Test
public void testAnnotation() throws Exception {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
- JexlScript script = jexl.createScript("@scale(13) @test var i = 42");
- JexlContext jc = new OptAnnotationContext();
- Object result = script.execute(jc);
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlScript script = jexl.createScript("@scale(13) @test var i = 42");
+ final JexlContext jc = new OptAnnotationContext();
+ final Object result = script.execute(jc);
Assert.assertEquals(42, result);
}
@Test
public void testNamed() throws Exception {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
- JexlScript script = jexl.createScript("var i = (x, y, z)->{return x + y + z}; i(22,18,2)");
- JexlContext jc = new MapContext();
- Object result = script.execute(jc);
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlScript script = jexl.createScript("var i = (x, y, z)->{return x + y + z}; i(22,18,2)");
+ final JexlContext jc = new MapContext();
+ final Object result = script.execute(jc);
Assert.assertEquals(42, result);
}
@Test
public void tesstCaptured0() throws Exception {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
- JexlScript script = jexl.createScript(
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlScript script = jexl.createScript(
"var x = 10; (b->{ x + b })(32)");
- JexlContext jc = new MapContext();
- Object result = script.execute(jc);
+ final JexlContext jc = new MapContext();
+ final Object result = script.execute(jc);
Assert.assertEquals(42, result);
}
@Test
public void testCaptured1() throws Exception {
- JexlFeatures f = new JexlFeatures();
+ final JexlFeatures f = new JexlFeatures();
f.lexical(true);
- JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
- JexlScript script = jexl.createScript(
+ final JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+ final JexlScript script = jexl.createScript(
"{var x = 10; } (b->{ x + b })(32)");
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("x", 11);
- Object result = script.execute(jc);
+ final Object result = script.execute(jc);
Assert.assertEquals(43, result);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java b/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java
index 087d93d..8249b60 100644
--- a/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java
+++ b/src/test/java/org/apache/commons/jexl3/MapLiteralTest.java
@@ -34,30 +34,30 @@
@Test
public void testLiteralWithStrings() throws Exception {
- JexlExpression e = JEXL.createExpression("{ 'foo' : 'bar' }");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("{ 'foo' : 'bar' }");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertEquals(Collections.singletonMap("foo", "bar"), o);
}
@Test
public void testLiteralWithMultipleEntries() throws Exception {
- JexlExpression e = JEXL.createExpression("{ 'foo' : 'bar', 'eat' : 'food' }");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("{ 'foo' : 'bar', 'eat' : 'food' }");
+ final JexlContext jc = new MapContext();
- Map<String, String> expected = new HashMap<String, String>();
+ final Map<String, String> expected = new HashMap<String, String>();
expected.put("foo", "bar");
expected.put("eat", "food");
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertEquals(expected, o);
}
@Test
public void testLiteralWithNumbers() throws Exception {
JexlExpression e = JEXL.createExpression("{ 5 : 10 }");
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
Assert.assertEquals(Collections.singletonMap(new Integer(5), new Integer(10)), o);
@@ -105,35 +105,35 @@
@Test
public void testSizeOfSimpleMapLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression("size({ 'foo' : 'bar' })");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("size({ 'foo' : 'bar' })");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertEquals(new Integer(1), o);
}
@Test
public void testCallingMethodsOnNewMapLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression("size({ 'foo' : 'bar' }.values())");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("size({ 'foo' : 'bar' }.values())");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertEquals(new Integer(1), o);
}
@Test
public void testNotEmptySimpleMapLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression("empty({ 'foo' : 'bar' })");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("empty({ 'foo' : 'bar' })");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertFalse((Boolean) o);
}
@Test
public void testMapMapLiteral() throws Exception {
JexlExpression e = JEXL.createExpression("{'foo' : { 'inner' : 'bar' }}");
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
Assert.assertNotNull(o);
@@ -146,7 +146,7 @@
@Test
public void testMapArrayLiteral() throws Exception {
JexlExpression e = JEXL.createExpression("{'foo' : [ 'inner' , 'bar' ]}");
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
Assert.assertNotNull(o);
@@ -158,24 +158,24 @@
@Test
public void testEmptyMap() throws Exception {
- JexlScript script = JEXL.createScript("map['']", "map");
- Object result = script.execute(null, Collections.singletonMap("", 42));
+ final JexlScript script = JEXL.createScript("map['']", "map");
+ final Object result = script.execute(null, Collections.singletonMap("", 42));
Assert.assertEquals(42, result);
}
@Test
public void testVariableMap() throws Exception {
- JexlScript script = JEXL.createScript("{ ['1', '2'.toString()] : someValue }", "someValue");
- Object result = script.execute(null, 42);
+ final JexlScript script = JEXL.createScript("{ ['1', '2'.toString()] : someValue }", "someValue");
+ final Object result = script.execute(null, 42);
Assert.assertTrue(result instanceof Map);
Object key = null;
Object value = null;
- for(Map.Entry<?,?> e : ((Map<?,?>) result).entrySet()) {
+ for(final Map.Entry<?,?> e : ((Map<?,?>) result).entrySet()) {
key = e.getKey();
value = e.getValue();
break;
}
- Object gg = ((Map) result).get(key);
+ final Object gg = ((Map) result).get(key);
Assert.assertEquals(42, ((Number) gg).intValue());
Assert.assertEquals(value, ((Number) gg).intValue());
}
diff --git a/src/test/java/org/apache/commons/jexl3/MethodTest.java b/src/test/java/org/apache/commons/jexl3/MethodTest.java
index 5e6a02c..4808f38 100644
--- a/src/test/java/org/apache/commons/jexl3/MethodTest.java
+++ b/src/test/java/org/apache/commons/jexl3/MethodTest.java
@@ -45,14 +45,14 @@
public static class VarArgs {
public String callInts() {
- int result = -5000;
+ final int result = -5000;
return "Varargs:" + result;
}
- public String callInts(Integer... args) {
+ public String callInts(final Integer... args) {
int result = 0;
if (args != null) {
- for (Integer arg : args) {
+ for (final Integer arg : args) {
result += arg != null ? arg : -100;
}
} else {
@@ -61,10 +61,10 @@
return "Varargs:" + result;
}
- public String callMixed(Integer fixed, Integer... args) {
+ public String callMixed(final Integer fixed, final Integer... args) {
int result = fixed;
if (args != null) {
- for (Integer arg : args) {
+ for (final Integer arg : args) {
result += arg != null ? arg : -100;
}
} else {
@@ -73,10 +73,10 @@
return "Mixed:" + result;
}
- public String callMixed(String mixed, Integer... args) {
+ public String callMixed(final String mixed, final Integer... args) {
int result = 0;
if (args != null) {
- for (Integer arg : args) {
+ for (final Integer arg : args) {
result += arg != null ? arg : -100;
}
} else {
@@ -85,9 +85,9 @@
return mixed + ":" + result;
}
- public String concat(String... strs) {
+ public String concat(final String... strs) {
if (strs.length > 0) {
- StringBuilder strb = new StringBuilder(strs[0]);
+ final StringBuilder strb = new StringBuilder(strs[0]);
for (int s = 1; s < strs.length; ++s) {
strb.append(", ");
strb.append(strs[s]);
@@ -103,12 +103,12 @@
int factor = 6;
final Map<String, Object> funcs;
- EnhancedContext(Map<String, Object> funcs) {
+ EnhancedContext(final Map<String, Object> funcs) {
this.funcs = funcs;
}
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
return funcs.get(name);
}
}
@@ -116,11 +116,11 @@
public static class ContextualFunctor {
private final EnhancedContext context;
- public ContextualFunctor(EnhancedContext theContext) {
+ public ContextualFunctor(final EnhancedContext theContext) {
context = theContext;
}
- public int ratio(int n) {
+ public int ratio(final int n) {
context.factor -= 1;
return n / context.factor;
}
@@ -134,7 +134,7 @@
@Test
public void testCallVarArgMethod() throws Exception {
- VarArgs test = new VarArgs();
+ final VarArgs test = new VarArgs();
asserter.setVariable("test", test);
asserter.assertExpression("test.callInts()", test.callInts());
asserter.assertExpression("test.callInts(1)", test.callInts(1));
@@ -146,7 +146,7 @@
@Test
public void testCallMixedVarArgMethod() throws Exception {
- VarArgs test = new VarArgs();
+ final VarArgs test = new VarArgs();
asserter.setVariable("test", test);
Assert.assertEquals("Mixed:1", test.callMixed(Integer.valueOf(1)));
asserter.assertExpression("test.callMixed(1)", test.callMixed(1));
@@ -161,7 +161,7 @@
@Test
public void testCallJexlVarArgMethod() throws Exception {
- VarArgs test = new VarArgs();
+ final VarArgs test = new VarArgs();
asserter.setVariable("test", test);
Assert.assertEquals("jexl:0", test.callMixed("jexl"));
asserter.assertExpression("test.callMixed('jexl')", "jexl:0");
@@ -178,7 +178,7 @@
private boolean overKill = false;
private String under = null;
- void setKill(boolean ok) {
+ void setKill(final boolean ok) {
overKill = ok;
}
@@ -186,7 +186,7 @@
return 10;
}
- public int plus10(int num) {
+ public int plus10(final int num) {
return num + 10;
}
@@ -194,30 +194,30 @@
return 20;
}
- public static int PLUS20(int num) {
+ public static int PLUS20(final int num) {
return num + 20;
}
- public static Class<?> NPEIfNull(Object x) {
+ public static Class<?> NPEIfNull(final Object x) {
return x.getClass();
}
- public Object over(String f, int i) {
+ public Object over(final String f, final int i) {
if (overKill) {
throw new UnsupportedOperationException("kill " + f + " + " + i);
}
return f + " + " + i;
}
- public Object over(String f, Date g) {
+ public Object over(final String f, final Date g) {
return f + " + " + g;
}
- public Object over(String f, String g) {
+ public Object over(final String f, final String g) {
return f + " + " + g;
}
- public void setUnder(String str) {
+ public void setUnder(final String str) {
if (overKill) {
throw new UnsupportedOperationException("kill " + str);
}
@@ -234,7 +234,7 @@
public static class FunctorOver extends Functor {
- public Object over(Object f, Object g) {
+ public Object over(final Object f, final Object g) {
return f + " + " + g;
}
}
@@ -247,13 +247,13 @@
try {
JEXL.invokeMethod(func, "nonExistentMethod");
Assert.fail("method does not exist!");
- } catch (Exception xj0) {
+ } catch (final Exception xj0) {
// ignore
}
try {
JEXL.invokeMethod(func, "NPEIfNull", (Object[]) null);
Assert.fail("method should have thrown!");
- } catch (Exception xj0) {
+ } catch (final Exception xj0) {
// ignore
}
@@ -261,7 +261,7 @@
try {
result = JEXL.invokeMethod(func, "over", "foo", 42);
Assert.assertEquals("foo + 42", result);
- } catch (Exception xj0) {
+ } catch (final Exception xj0) {
// ignore
result = xj0;
}
@@ -269,7 +269,7 @@
try {
result = JEXL.invokeMethod(func, "over", null, null);
Assert.fail("method should have thrown!");
- } catch (Exception xj0) {
+ } catch (final Exception xj0) {
// ignore
result = xj0;
}
@@ -278,7 +278,7 @@
try {
result = JEXL.invokeMethod(func, "over", null, null);
Assert.assertEquals("null + null", result);
- } catch (Exception xj0) {
+ } catch (final Exception xj0) {
Assert.fail("method should not have thrown!");
}
}
@@ -286,8 +286,8 @@
@Test
public void testAmbiguousInvoke() throws Exception {
// JEXL-299
- Functor func = new Functor();
- JexlContext ctxt = new MapContext();
+ final Functor func = new Functor();
+ final JexlContext ctxt = new MapContext();
ctxt.set("func", func);
Object result;
// basic call works
@@ -297,16 +297,16 @@
try {
JEXL.invokeMethod(func, "over", "not null", null);
Assert.fail("should be ambiguous");
- } catch (JexlException.Method xinvoke) {
+ } catch (final JexlException.Method xinvoke) {
Assert.assertEquals("over(String, Object)", xinvoke.getMethodSignature());
}
// another ambiguous call fails
try {
- String[] arg2 = new String[]{"more", "than", "one"};
+ final String[] arg2 = new String[]{"more", "than", "one"};
JEXL.invokeMethod(func, "over", "not null", arg2);
Assert.fail("should be ambiguous");
- } catch (JexlException.Method xinvoke) {
+ } catch (final JexlException.Method xinvoke) {
Assert.assertEquals("over(String, String[])", xinvoke.getMethodSignature());
}
}
@@ -314,13 +314,13 @@
@Test
public void testTryFailed() throws Exception {
// JEXL-257
- Functor func = new Functor();
- JexlContext ctxt = new MapContext();
+ final Functor func = new Functor();
+ final JexlContext ctxt = new MapContext();
ctxt.set("func", func);
Object result;
- JexlUberspect uber = JEXL.getUberspect();
+ final JexlUberspect uber = JEXL.getUberspect();
// tryInvoke
- JexlMethod method = uber.getMethod(func, "over", "foo", 42);
+ final JexlMethod method = uber.getMethod(func, "over", "foo", 42);
Assert.assertNotNull(method);
// tryInvoke succeeds
result = method.tryInvoke("over", func, "foo", 42);
@@ -330,17 +330,17 @@
try {
/*result = */method.tryInvoke("over", func, "foo", 42);
Assert.fail("should throw TryFailed");
- } catch (JexlException.TryFailed xfail) {
+ } catch (final JexlException.TryFailed xfail) {
Assert.assertEquals(UnsupportedOperationException.class, xfail.getCause().getClass());
}
func.setKill(false);
- JexlPropertySet setter = uber.getPropertySet(func, "under", "42");
+ final JexlPropertySet setter = uber.getPropertySet(func, "under", "42");
result = setter.tryInvoke(func, "under", "42");
Assert.assertFalse(setter.tryFailed(result));
Assert.assertEquals("42", result);
- JexlPropertyGet getter = uber.getPropertyGet(func, "under");
+ final JexlPropertyGet getter = uber.getPropertyGet(func, "under");
result = getter.tryInvoke(func, "under");
Assert.assertFalse(getter.tryFailed(result));
Assert.assertEquals("42", result);
@@ -349,7 +349,7 @@
try {
/*result = */setter.tryInvoke(func, "under", "42");
Assert.fail("should throw TryFailed");
- } catch (JexlException.TryFailed xfail) {
+ } catch (final JexlException.TryFailed xfail) {
Assert.assertEquals(UnsupportedOperationException.class, xfail.getCause().getClass());
}
func.setKill(false);
@@ -360,7 +360,7 @@
try {
/*result = */getter.tryInvoke(func, "under");
Assert.fail("should throw TryFailed");
- } catch (JexlException.TryFailed xfail) {
+ } catch (final JexlException.TryFailed xfail) {
Assert.assertEquals(UnsupportedOperationException.class, xfail.getCause().getClass());
}
@@ -373,12 +373,12 @@
@Test
public void testTryFailedScript() throws Exception {
// JEXL-257
- Functor func = new Functor();
- JexlContext ctxt = new MapContext();
+ final Functor func = new Functor();
+ final JexlContext ctxt = new MapContext();
ctxt.set("func", func);
Object result;
- JexlUberspect uber = JEXL.getUberspect();
- JexlScript method = JEXL.createScript("(x, y)->{ func.over(x, y) }");
+ final JexlUberspect uber = JEXL.getUberspect();
+ final JexlScript method = JEXL.createScript("(x, y)->{ func.over(x, y) }");
// tryInvoke
//JexlMethod method = uber.getMethod(func, "over", "foo", 42);
Assert.assertNotNull(method);
@@ -390,24 +390,24 @@
try {
/*result = */method.execute(ctxt, "foo", 42);
Assert.fail("should throw TryFailed");
- } catch (JexlException xfail) {
+ } catch (final JexlException xfail) {
Assert.assertEquals(UnsupportedOperationException.class, xfail.getCause().getClass());
}
func.setKill(false);
- JexlScript setter = JEXL.createScript("(x)->{ func.under = x }");
+ final JexlScript setter = JEXL.createScript("(x)->{ func.under = x }");
//JexlPropertySet setter = uber.getPropertySet(func, "under", "42");
result = setter.execute(ctxt, "42");
Assert.assertEquals("42", result);
- JexlScript getter = JEXL.createScript("func.under");
+ final JexlScript getter = JEXL.createScript("func.under");
Assert.assertEquals("42", result);
func.setKill(true);
try {
/*result = */setter.execute(ctxt, "42");
Assert.fail("should throw TryFailed");
- } catch (JexlException xfail) {
+ } catch (final JexlException xfail) {
Assert.assertEquals(UnsupportedOperationException.class, xfail.getCause().getClass());
}
func.setKill(false);
@@ -418,7 +418,7 @@
try {
/*result = */getter.execute(ctxt);
Assert.fail("should throw TryFailed");
- } catch (JexlException xfail) {
+ } catch (final JexlException xfail) {
Assert.assertEquals(UnsupportedOperationException.class, xfail.getCause().getClass());
}
@@ -472,19 +472,19 @@
}
public static class MyMath {
- public double cos(double x) {
+ public double cos(final double x) {
return Math.cos(x);
}
}
@Test
public void testTopLevelCall() throws Exception {
- java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
+ final java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
funcs.put(null, new Functor());
funcs.put("math", new MyMath());
funcs.put("cx", ContextualFunctor.class);
- EnhancedContext jc = new EnhancedContext(funcs);
+ final EnhancedContext jc = new EnhancedContext(funcs);
JexlExpression e = JEXL.createExpression("ten()");
Object o = e.evaluate(jc);
@@ -510,12 +510,12 @@
@Test
public void testNamespaceCall() throws Exception {
- java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
+ final java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
funcs.put("func", new Functor());
funcs.put("FUNC", Functor.class);
JexlExpression e = JEXL.createExpression("func:ten()");
- JexlEvalContext jc = new EnhancedContext(funcs);
+ final JexlEvalContext jc = new EnhancedContext(funcs);
Object o = e.evaluate(jc);
Assert.assertEquals("Result is not 10", new Integer(10), o);
@@ -541,52 +541,52 @@
private Edge() {
}
- public int exec(int arg) {
+ public int exec(final int arg) {
return 1;
}
- public int exec(int[] arg) {
+ public int exec(final int[] arg) {
return 20;
}
- public int exec(String arg) {
+ public int exec(final String arg) {
return 2;
}
- public int exec(String... arg) {
+ public int exec(final String... arg) {
return 200;
}
- public int exec(Object args) {
+ public int exec(final Object args) {
return 3;
}
- public int exec(Object... args) {
+ public int exec(final Object... args) {
return 4;
}
- public int exec(Boolean x, int arg) {
+ public int exec(final Boolean x, final int arg) {
return 1;
}
- public int exec(Boolean x, int[] arg) {
+ public int exec(final Boolean x, final int[] arg) {
return 20;
}
- public int exec(Boolean x, String arg) {
+ public int exec(final Boolean x, final String arg) {
return 2;
}
- public int exec(Boolean x, Object args) {
+ public int exec(final Boolean x, final Object args) {
return 3;
}
- public int exec(Boolean x, Object... args) {
+ public int exec(final Boolean x, final Object... args) {
return 4;
}
- public Class<?>[] execute(Object... args) {
- Class<?>[] clazz = new Class<?>[args.length];
+ public Class<?>[] execute(final Object... args) {
+ final Class<?>[] clazz = new Class<?>[args.length];
for (int a = 0; a < args.length; ++a) {
clazz[a] = args[a] != null ? args[a].getClass() : Void.class;
}
@@ -594,10 +594,10 @@
}
}
- private boolean eqExecute(Object lhs, Object rhs) {
+ private boolean eqExecute(final Object lhs, final Object rhs) {
if (lhs instanceof Class<?>[] && rhs instanceof Class<?>[]) {
- Class<?>[] lhsa = (Class<?>[]) lhs;
- Class<?>[] rhsa = (Class<?>[]) rhs;
+ final Class<?>[] lhsa = (Class<?>[]) lhs;
+ final Class<?>[] rhsa = (Class<?>[]) rhs;
return Arrays.deepEquals(lhsa, rhsa);
}
return false;
@@ -605,14 +605,14 @@
@Test
public void testNamespaceCallEdge() throws Exception {
- java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
- Edge func = new Edge();
+ final java.util.Map<String, Object> funcs = new java.util.HashMap<String, Object>();
+ final Edge func = new Edge();
funcs.put("func", func);
Object o;
Object c;
JexlExpression e;
- JexlEvalContext jc = new EnhancedContext(funcs);
+ final JexlEvalContext jc = new EnhancedContext(funcs);
try {
for (int i = 0; i < 2; ++i) {
e = JEXL.createExpression("func:exec([1, 2])");
@@ -666,7 +666,7 @@
c = func.execute(new boolean[]{true});
Assert.assertTrue("execute(Object... args): " + i, eqExecute(o, c));
}
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
Assert.fail(xjexl.toString());
}
}
@@ -674,12 +674,12 @@
public static class ScriptContext extends MapContext implements JexlContext.NamespaceResolver {
Map<String, Object> nsScript;
- ScriptContext(Map<String, Object> ns) {
+ ScriptContext(final Map<String, Object> ns) {
nsScript = ns;
}
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
if (name == null) {
return this;
}
@@ -688,7 +688,7 @@
}
if ("functor".equals(name)) {
return (NamespaceFunctor) context -> {
- Map<String, Object> values = new HashMap<String, Object>();
+ final Map<String, Object> values = new HashMap<String, Object>();
if ("gin".equals(context.get("base"))) {
values.put("drink", "gin fizz");
} else {
@@ -704,13 +704,13 @@
@Test
public void testScriptCall() throws Exception {
JexlContext context = new MapContext();
- JexlScript plus = JEXL.createScript("a + b", new String[]{"a", "b"});
+ final JexlScript plus = JEXL.createScript("a + b", new String[]{"a", "b"});
context.set("plus", plus);
JexlScript forty2 = JEXL.createScript("plus(4, 2) * plus(4, 3)");
Object o = forty2.execute(context);
Assert.assertEquals("Result is not 42", new Integer(42), o);
- Map<String, Object> foo = new HashMap<String, Object>();
+ final Map<String, Object> foo = new HashMap<String, Object>();
foo.put("plus", plus);
context.set("foo", foo);
forty2 = JEXL.createScript("foo.plus(4, 2) * foo.plus(4, 3)");
@@ -723,9 +723,9 @@
Assert.assertEquals("Result is not 42", new Integer(42), o);
final JexlArithmetic ja = JEXL.getArithmetic();
- JexlMethod mplus = new JexlMethod() {
+ final JexlMethod mplus = new JexlMethod() {
@Override
- public Object invoke(Object obj, Object ... params) throws Exception {
+ public Object invoke(final Object obj, final Object ... params) throws Exception {
if (obj instanceof Map<?, ?>) {
return ja.add(params[0], params[1]);
} else {
@@ -734,19 +734,19 @@
}
@Override
- public Object tryInvoke(String name, Object obj, Object ... params) {
+ public Object tryInvoke(final String name, final Object obj, final Object ... params) {
try {
if ("plus".equals(name)) {
return invoke(obj, params);
}
- } catch (Exception xany) {
+ } catch (final Exception xany) {
// ignore and fail by returning this
}
return this;
}
@Override
- public boolean tryFailed(Object rval) {
+ public boolean tryFailed(final Object rval) {
// this is the marker for failure
return rval == this;
}
@@ -775,7 +775,7 @@
@Test
public void testFizzCall() throws Exception {
- ScriptContext context = new ScriptContext(new HashMap<String, Object>());
+ final ScriptContext context = new ScriptContext(new HashMap<String, Object>());
JexlScript bar = JEXL.createScript("functor:get('drink')");
Object o;
@@ -793,31 +793,31 @@
}
public static class ZArithmetic extends JexlArithmetic {
- public ZArithmetic(boolean astrict) {
+ public ZArithmetic(final boolean astrict) {
super(astrict);
}
- public int zzzz(int z) {
+ public int zzzz(final int z) {
return 38 + z;
}
}
public static class ZSpace {
- public int zzz(int z) {
+ public int zzz(final int z) {
return 39 + z;
}
}
public static class ZContext extends MapContext {
- public ZContext(Map<String,Object> map) {
+ public ZContext(final Map<String,Object> map) {
super(map);
}
- public int zz(int z) {
+ public int zz(final int z) {
return 40 + z;
}
- public int z(int z) {
+ public int z(final int z) {
return 181 + z;
}
}
@@ -825,21 +825,21 @@
@Test
public void testVariousFunctionLocation() throws Exception {
// see JEXL-190
- Map<String, Object> vars = new HashMap<String, Object>();
- Map<String,Object> funcs = new HashMap<String,Object>();
+ final Map<String, Object> vars = new HashMap<String, Object>();
+ final Map<String,Object> funcs = new HashMap<String,Object>();
funcs.put(null, new ZSpace());
- JexlEngine jexl = new JexlBuilder().namespaces(funcs).arithmetic(new ZArithmetic(true)).create();
+ final JexlEngine jexl = new JexlBuilder().namespaces(funcs).arithmetic(new ZArithmetic(true)).create();
- JexlContext zjc = new ZContext(vars); // that implements a z(int x) function
- String z41 = "z(41)";
- JexlScript callz41 = jexl.createScript(z41);
+ final JexlContext zjc = new ZContext(vars); // that implements a z(int x) function
+ final String z41 = "z(41)";
+ final JexlScript callz41 = jexl.createScript(z41);
Object onovar = callz41.execute(zjc);
Assert.assertEquals(222, onovar);
// override z() with global var
- JexlScript z241 = jexl.createScript("(x)->{ return x + 241}");
+ final JexlScript z241 = jexl.createScript("(x)->{ return x + 241}");
vars.put("z", z241);
- Object oglobal = callz41.execute(zjc);
+ final Object oglobal = callz41.execute(zjc);
Assert.assertEquals(282, oglobal);
// clear global and execute again
vars.remove("z");
@@ -847,9 +847,9 @@
Assert.assertEquals(222, onovar);
// override z() with local var
- String slocal = "var z = (x)->{ return x + 141}; z(1)";
- JexlScript jlocal = jexl.createScript(slocal);
- Object olocal = jlocal.execute(zjc);
+ final String slocal = "var z = (x)->{ return x + 141}; z(1)";
+ final JexlScript jlocal = jexl.createScript(slocal);
+ final Object olocal = jlocal.execute(zjc);
Assert.assertEquals(142, olocal);
// and now try the context, the null namespace and the arithmetic
diff --git a/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java b/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java
index 17c4c6d..8c1ada7 100644
--- a/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ParseFailuresTest.java
@@ -43,12 +43,12 @@
@Test
public void testMalformedExpression1() throws Exception {
// this will throw a JexlException
- String badExpression = "eq";
+ final String badExpression = "eq";
try {
JEXL.createExpression(badExpression);
Assert.fail("Parsing \"" + badExpression
+ "\" should result in a JexlException");
- } catch (JexlException pe) {
+ } catch (final JexlException pe) {
// expected
LOGGER.info(pe);
}
@@ -57,12 +57,12 @@
@Test
public void testMalformedExpression2() throws Exception {
// this will throw a TokenMgrErr, which we rethrow as a JexlException
- String badExpression = "?";
+ final String badExpression = "?";
try {
JEXL.createExpression(badExpression);
Assert.fail("Parsing \"" + badExpression
+ "\" should result in a JexlException");
- } catch (JexlException pe) {
+ } catch (final JexlException pe) {
// expected
LOGGER.info(pe);
}
@@ -71,12 +71,12 @@
@Test
public void testMalformedScript1() throws Exception {
// this will throw a TokenMgrErr, which we rethrow as a JexlException
- String badScript = "eq";
+ final String badScript = "eq";
try {
JEXL.createScript(badScript);
Assert.fail("Parsing \"" + badScript
+ "\" should result in a JexlException");
- } catch (JexlException pe) {
+ } catch (final JexlException pe) {
// expected
LOGGER.info(pe);
}
@@ -85,12 +85,12 @@
@Test
public void testMalformedScript2() throws Exception {
// this will throw a TokenMgrErr, which we rethrow as a JexlException
- String badScript = "?";
+ final String badScript = "?";
try {
JEXL.createScript(badScript);
Assert.fail("Parsing \"" + badScript
+ "\" should result in a JexlException");
- } catch (JexlException pe) {
+ } catch (final JexlException pe) {
// expected
LOGGER.info(pe);
}
@@ -99,12 +99,12 @@
@Test
public void testMalformedScript3() throws Exception {
// this will throw a TokenMgrErr, which we rethrow as a JexlException
- String badScript = "foo=1;bar=2;a?b:c:d;";
+ final String badScript = "foo=1;bar=2;a?b:c:d;";
try {
JEXL.createScript(badScript);
Assert.fail("Parsing \"" + badScript
+ "\" should result in a JexlException");
- } catch (JexlException pe) {
+ } catch (final JexlException pe) {
// expected
LOGGER.error(pe);
}
diff --git a/src/test/java/org/apache/commons/jexl3/PragmaTest.java b/src/test/java/org/apache/commons/jexl3/PragmaTest.java
index 03a8bd2..70ce468 100644
--- a/src/test/java/org/apache/commons/jexl3/PragmaTest.java
+++ b/src/test/java/org/apache/commons/jexl3/PragmaTest.java
@@ -38,10 +38,10 @@
@Test
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void testPragmas() throws Exception {
- JexlContext jc = new MapContext();
- JexlScript script = JEXL.createScript("#pragma one 1\n#pragma the.very.hard 'truth'\n2;");
+ final JexlContext jc = new MapContext();
+ final JexlScript script = JEXL.createScript("#pragma one 1\n#pragma the.very.hard 'truth'\n2;");
Assert.assertNotNull(script);
- Map<String, Object> pragmas = script.getPragmas();
+ final Map<String, Object> pragmas = script.getPragmas();
Assert.assertEquals(2, pragmas.size());
Assert.assertEquals(1, pragmas.get("one"));
Assert.assertEquals("truth", pragmas.get("the.very.hard"));
@@ -50,11 +50,11 @@
@Test
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void testJxltPragmas() throws Exception {
- JexlContext jc = new MapContext();
- JxltEngine engine = new JexlBuilder().create().createJxltEngine();
- JxltEngine.Template tscript = engine.createTemplate("$$ #pragma one 1\n$$ #pragma the.very.hard 'truth'\n2;");
+ final JexlContext jc = new MapContext();
+ final JxltEngine engine = new JexlBuilder().create().createJxltEngine();
+ final JxltEngine.Template tscript = engine.createTemplate("$$ #pragma one 1\n$$ #pragma the.very.hard 'truth'\n2;");
Assert.assertNotNull(tscript);
- Map<String, Object> pragmas = tscript.getPragmas();
+ final Map<String, Object> pragmas = tscript.getPragmas();
Assert.assertEquals(2, pragmas.size());
Assert.assertEquals(1, pragmas.get("one"));
Assert.assertEquals("truth", pragmas.get("the.very.hard"));
@@ -62,12 +62,12 @@
public static class SafeContext extends JexlEvalContext {
// @Override
- public void processPragmas(Map<String, Object> pragmas) {
+ public void processPragmas(final Map<String, Object> pragmas) {
if (pragmas != null && !pragmas.isEmpty()) {
- JexlOptions options = getEngineOptions();
- for (Map.Entry<String, Object> pragma : pragmas.entrySet()) {
- String key = pragma.getKey();
- Object value = pragma.getValue();
+ final JexlOptions options = getEngineOptions();
+ for (final Map.Entry<String, Object> pragma : pragmas.entrySet()) {
+ final String key = pragma.getKey();
+ final Object value = pragma.getValue();
if ("jexl.safe".equals(key) && value instanceof Boolean) {
options.setSafe((Boolean) value);
} else if ("jexl.strict".equals(key) && value instanceof Boolean) {
@@ -79,10 +79,10 @@
}
}
- public void sleep(long ms) {
+ public void sleep(final long ms) {
try {
Thread.sleep(ms);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
// ignore
}
}
@@ -93,7 +93,7 @@
public void testSafePragma() throws Exception {
SafeContext jc = new SafeContext();
jc.set("foo", null);
- JexlScript script = JEXL.createScript("#pragma jexl.safe true\nfoo.bar;");
+ final JexlScript script = JEXL.createScript("#pragma jexl.safe true\nfoo.bar;");
Assert.assertNotNull(script);
jc.processPragmas(script.getPragmas());
Object result = script.execute(jc);
@@ -103,7 +103,7 @@
try {
result = script.execute(jc);
Assert.fail("should have thrown");
- } catch (JexlException xvar) {
+ } catch (final JexlException xvar) {
// ok, expected
}
}
@@ -113,20 +113,20 @@
// precludes instantiation
private StaticSleeper() {}
- public static void sleep(long ms) {
+ public static void sleep(final long ms) {
try {
Thread.sleep(ms);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
// ignore
}
}
}
public static class Sleeper {
- public void sleep(long ms) {
+ public void sleep(final long ms) {
try {
Thread.sleep(ms);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
// ignore
}
}
@@ -135,50 +135,50 @@
@Test
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void testStaticNamespacePragma() throws Exception {
- SafeContext jc = new SafeContext();
- JexlScript script = JEXL.createScript(
+ final SafeContext jc = new SafeContext();
+ final JexlScript script = JEXL.createScript(
"#pragma jexl.namespace.sleeper " + StaticSleeper.class.getName() + "\n"
+ "sleeper:sleep(100);"
+ "42");
- Object result = script.execute(jc);
+ final Object result = script.execute(jc);
Assert.assertEquals(42, result);
}
@Test
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void testStatictNamespacePragmaCtl() throws Exception {
- Map<String, Object> ns = Collections.singletonMap("sleeper", StaticSleeper.class.getName());
- JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
- SafeContext jc = new SafeContext();
- JexlScript script = jexl.createScript(
+ final Map<String, Object> ns = Collections.singletonMap("sleeper", StaticSleeper.class.getName());
+ final JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
+ final SafeContext jc = new SafeContext();
+ final JexlScript script = jexl.createScript(
"sleeper:sleep(100);"
+ "42");
- Object result = script.execute(jc);
+ final Object result = script.execute(jc);
Assert.assertEquals(42, result);
}
@Test
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void testNamespacePragma() throws Exception {
- SafeContext jc = new SafeContext();
- JexlScript script = JEXL.createScript(
+ final SafeContext jc = new SafeContext();
+ final JexlScript script = JEXL.createScript(
"#pragma jexl.namespace.sleeper " + Sleeper.class.getName() + "\n"
+ "sleeper:sleep(100);"
+ "42");
- Object result = script.execute(jc);
+ final Object result = script.execute(jc);
Assert.assertEquals(42, result);
}
@Test
@SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
public void testNamespacePragmaCtl() throws Exception {
- Map<String, Object> ns = Collections.singletonMap("sleeper", Sleeper.class.getName());
- JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
- SafeContext jc = new SafeContext();
- JexlScript script = jexl.createScript(
+ final Map<String, Object> ns = Collections.singletonMap("sleeper", Sleeper.class.getName());
+ final JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
+ final SafeContext jc = new SafeContext();
+ final JexlScript script = jexl.createScript(
"sleeper:sleep(100);"
+ "42");
- Object result = script.execute(jc);
+ final Object result = script.execute(jc);
Assert.assertEquals(42, result);
}
diff --git a/src/test/java/org/apache/commons/jexl3/PropertyAccessTest.java b/src/test/java/org/apache/commons/jexl3/PropertyAccessTest.java
index 27825f2..a96bdf8 100644
--- a/src/test/java/org/apache/commons/jexl3/PropertyAccessTest.java
+++ b/src/test/java/org/apache/commons/jexl3/PropertyAccessTest.java
@@ -48,10 +48,10 @@
@Test
public void testPropertyProperty() throws Exception {
- Integer i42 = Integer.valueOf(42);
- Integer i43 = Integer.valueOf(43);
- String s42 = "fourty-two";
- Object[] foo = new Object[3];
+ final Integer i42 = Integer.valueOf(42);
+ final Integer i43 = Integer.valueOf(43);
+ final String s42 = "fourty-two";
+ final Object[] foo = new Object[3];
foo[0] = foo;
foo[1] = i42;
foo[2] = s42;
@@ -97,12 +97,12 @@
String value0;
int value1;
- public PropertyContainer(String name, int number) {
+ public PropertyContainer(final String name, final int number) {
value0 = name;
value1 = number;
}
- public Object getProperty(String name) {
+ public Object getProperty(final String name) {
if ("name".equals(name)) {
return value0;
} else if ("number".equals(name)) {
@@ -112,7 +112,7 @@
}
}
- public void setProperty(String name, String value) {
+ public void setProperty(final String name, final String value) {
if ("name".equals(name)) {
this.value0 = value.toUpperCase();
}
@@ -129,17 +129,17 @@
public static class PropertyArithmetic extends JexlArithmetic {
int ncalls = 0;
- public PropertyArithmetic(boolean astrict) {
+ public PropertyArithmetic(final boolean astrict) {
super(astrict);
}
- public Object propertySet(IndexedType.IndexedContainer map, String key, Integer value) {
+ public Object propertySet(final IndexedType.IndexedContainer map, final String key, final Integer value) {
if (map.getContainerClass().equals(PropertyContainer.class)
&& map.getContainerName().equals("property")) {
try {
map.set(key, value.toString());
ncalls += 1;
- } catch (Exception xany) {
+ } catch (final Exception xany) {
throw new JexlException.Operator(null, key + "." + value.toString(), xany);
}
return null;
@@ -154,16 +154,16 @@
@Test
public void testInnerViaArithmetic() throws Exception {
- PropertyArithmetic pa = new PropertyArithmetic(true);
- JexlEngine jexl = new JexlBuilder().arithmetic(pa).debug(true).strict(true).cache(32).create();
- PropertyContainer quux = new PropertyContainer("bar", 169);
+ final PropertyArithmetic pa = new PropertyArithmetic(true);
+ final JexlEngine jexl = new JexlBuilder().arithmetic(pa).debug(true).strict(true).cache(32).create();
+ final PropertyContainer quux = new PropertyContainer("bar", 169);
Object result;
- JexlScript getName = jexl.createScript("foo.property.name", "foo");
+ final JexlScript getName = jexl.createScript("foo.property.name", "foo");
result = getName.execute(null, quux);
Assert.assertEquals("bar", result);
- int calls = pa.getCalls();
- JexlScript setName = jexl.createScript("foo.property.name = $0", "foo", "$0");
+ final int calls = pa.getCalls();
+ final JexlScript setName = jexl.createScript("foo.property.name = $0", "foo", "$0");
setName.execute(null, quux, 123);
result = getName.execute(null, quux);
Assert.assertEquals("123", result);
@@ -176,10 +176,10 @@
Assert.assertEquals("QUUX", result);
Assert.assertEquals(calls + 2, pa.getCalls());
- JexlScript getNumber = jexl.createScript("foo.property.number", "foo");
+ final JexlScript getNumber = jexl.createScript("foo.property.number", "foo");
result = getNumber.execute(null, quux);
Assert.assertEquals(169, result);
- JexlScript setNumber = jexl.createScript("foo.property.number = $0", "foo", "$0");
+ final JexlScript setNumber = jexl.createScript("foo.property.number = $0", "foo", "$0");
setNumber.execute(null, quux, 42);
result = getNumber.execute(null, quux);
Assert.assertEquals(1042, result);
@@ -194,11 +194,11 @@
}
public static class Container extends PropertyContainer {
- public Container(String name, int number) {
+ public Container(final String name, final int number) {
super(name, number);
}
- public Object getProperty(int ref) {
+ public Object getProperty(final int ref) {
switch (ref) {
case 0:
return value0;
@@ -210,25 +210,25 @@
}
@Override
- public void setProperty(String name, String value) {
+ public void setProperty(final String name, final String value) {
if ("name".equals(name)) {
this.value0 = value;
}
}
- public void setProperty(String name, int value) {
+ public void setProperty(final String name, final int value) {
if ("number".equals(name)) {
this.value1 = value;
}
}
- public void setProperty(int ref, String value) {
+ public void setProperty(final int ref, final String value) {
if (0 == ref) {
this.value0 = value;
}
}
- public void setProperty(int ref, int value) {
+ public void setProperty(final int ref, final int value) {
if (1 == ref) {
this.value1 = value;
}
@@ -237,51 +237,51 @@
@Test
public void testInnerProperty() throws Exception {
- PropertyArithmetic pa = new PropertyArithmetic(true);
- JexlEngine jexl = new JexlBuilder().arithmetic(pa).debug(true).strict(true).cache(32).create();
- Container quux = new Container("quux", 42);
- JexlScript get;
+ final PropertyArithmetic pa = new PropertyArithmetic(true);
+ final JexlEngine jexl = new JexlBuilder().arithmetic(pa).debug(true).strict(true).cache(32).create();
+ final Container quux = new Container("quux", 42);
+ final JexlScript get;
Object result;
- int calls = pa.getCalls();
- JexlScript getName = JEXL.createScript("foo.property.name", "foo");
+ final int calls = pa.getCalls();
+ final JexlScript getName = JEXL.createScript("foo.property.name", "foo");
result = getName.execute(null, quux);
Assert.assertEquals("quux", result);
- JexlScript get0 = JEXL.createScript("foo.property.0", "foo");
+ final JexlScript get0 = JEXL.createScript("foo.property.0", "foo");
result = get0.execute(null, quux);
Assert.assertEquals("quux", result);
- JexlScript getNumber = JEXL.createScript("foo.property.number", "foo");
+ final JexlScript getNumber = JEXL.createScript("foo.property.number", "foo");
result = getNumber.execute(null, quux);
Assert.assertEquals(42, result);
- JexlScript get1 = JEXL.createScript("foo.property.1", "foo");
+ final JexlScript get1 = JEXL.createScript("foo.property.1", "foo");
result = get1.execute(null, quux);
Assert.assertEquals(42, result);
- JexlScript setName = JEXL.createScript("foo.property.name = $0", "foo", "$0");
+ final JexlScript setName = JEXL.createScript("foo.property.name = $0", "foo", "$0");
setName.execute(null, quux, "QUUX");
result = getName.execute(null, quux);
Assert.assertEquals("QUUX", result);
result = get0.execute(null, quux);
Assert.assertEquals("QUUX", result);
- JexlScript set0 = JEXL.createScript("foo.property.0 = $0", "foo", "$0");
+ final JexlScript set0 = JEXL.createScript("foo.property.0 = $0", "foo", "$0");
set0.execute(null, quux, "BAR");
result = getName.execute(null, quux);
Assert.assertEquals("BAR", result);
result = get0.execute(null, quux);
Assert.assertEquals("BAR", result);
- JexlScript setNumber = JEXL.createScript("foo.property.number = $0", "foo", "$0");
+ final JexlScript setNumber = JEXL.createScript("foo.property.number = $0", "foo", "$0");
setNumber.execute(null, quux, -42);
result = getNumber.execute(null, quux);
Assert.assertEquals(-42, result);
result = get1.execute(null, quux);
Assert.assertEquals(-42, result);
- JexlScript set1 = JEXL.createScript("foo.property.1 = $0", "foo", "$0");
+ final JexlScript set1 = JEXL.createScript("foo.property.1 = $0", "foo", "$0");
set1.execute(null, quux, 24);
result = getNumber.execute(null, quux);
Assert.assertEquals(24, result);
@@ -294,9 +294,9 @@
@Test
public void testStringIdentifier() throws Exception {
- Map<String, String> foo = new HashMap<String, String>();
+ final Map<String, String> foo = new HashMap<String, String>();
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
jc.set("foo", foo);
foo.put("q u u x", "456");
JexlExpression e = JEXL.createExpression("foo.\"q u u x\"");
@@ -312,16 +312,16 @@
result = s.execute(jc);
Assert.assertEquals("456", result);
- Debugger dbg = new Debugger();
+ final Debugger dbg = new Debugger();
dbg.debug(e);
- String dbgdata = dbg.toString();
+ final String dbgdata = dbg.toString();
Assert.assertEquals("foo.'q u u x'", dbgdata);
}
@Test
public void testErroneousIdentifier() throws Exception {
- MapContext ctx = new MapContext();
- JexlEngine engine = new JexlBuilder().strict(true).silent(false).create();
+ final MapContext ctx = new MapContext();
+ final JexlEngine engine = new JexlBuilder().strict(true).silent(false).create();
// base succeeds
String stmt = "(x)->{ x?.class ?? 'oops' }";
@@ -375,11 +375,11 @@
@Test
public void test250() throws Exception {
- MapContext ctx = new MapContext();
- HashMap<Object, Object> x = new HashMap<Object, Object>();
+ final MapContext ctx = new MapContext();
+ final HashMap<Object, Object> x = new HashMap<Object, Object>();
x.put(2, "123456789");
ctx.set("x", x);
- JexlEngine engine = new JexlBuilder().strict(true).silent(false).create();
+ final JexlEngine engine = new JexlBuilder().strict(true).silent(false).create();
String stmt = "x.2.class.name";
JexlScript script = engine.createScript(stmt);
Object result = script.execute(ctx);
@@ -390,7 +390,7 @@
script = engine.createScript(stmt);
result = script.execute(ctx);
Assert.assertNull(result);
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.fail("Should have evaluated to null");
}
try {
@@ -399,7 +399,7 @@
result = script.execute(ctx);
Assert.fail("Should have thrown, fail on 3");
Assert.assertNull(result);
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertTrue(xany.detailedMessage().contains("3"));
}
try {
@@ -407,7 +407,7 @@
script = engine.createScript(stmt);
result = script.execute(ctx);
Assert.assertNull(result);
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.fail("Should have evaluated to null");
}
try {
@@ -415,7 +415,7 @@
script = engine.createScript(stmt);
result = script.execute(ctx);
Assert.assertNull(result);
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.fail("Should have evaluated to null");
}
try {
@@ -423,7 +423,7 @@
script = engine.createScript(stmt);
result = script.execute(ctx);
Assert.assertNull(result);
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.fail("Should have evaluated to null");
}
try {
@@ -431,7 +431,7 @@
script = engine.createScript(stmt);
result = script.execute(ctx);
Assert.assertNull(result);
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.fail("Should have evaluated to null");
}
}
@@ -439,12 +439,12 @@
public static class Prompt {
private final Map<String, PromptValue> values = new HashMap<String, PromptValue>();
- public Object get(String name) {
- PromptValue v = values.get(name);
+ public Object get(final String name) {
+ final PromptValue v = values.get(name);
return v != null? v.getValue() : null;
}
- public void set(String name, Object value) {
+ public void set(final String name, final Object value) {
values.put(name, new PromptValue(value));
}
}
@@ -457,7 +457,7 @@
/** Prompt value. */
private Object value;
- public PromptValue(Object v) {
+ public PromptValue(final Object v) {
value = v;
}
@@ -465,18 +465,18 @@
return value;
}
- public void setValue(Object value) {
+ public void setValue(final Object value) {
this.value = value;
}
}
@Test
public void test275a() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).safe(false).create();
- JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().strict(true).safe(false).create();
+ final JexlContext ctxt = new MapContext();
JexlScript script;
Object result = null;
- Prompt p0 = new Prompt();
+ final Prompt p0 = new Prompt();
p0.set("stuff", 42);
ctxt.set("$in", p0);
@@ -485,7 +485,7 @@
try {
result = script.execute(ctxt, "fail");
Assert.fail("should have thrown a " + JexlException.Property.class);
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertEquals(JexlException.Property.class, xany.getClass());
}
Assert.assertNull(result);
@@ -504,7 +504,7 @@
try {
result = script.execute(ctxt, "fail");
Assert.fail("should have thrown a " + JexlException.Property.class);
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertEquals(JexlException.Property.class, xany.getClass());
}
result = script.execute(ctxt, "stuff");
@@ -520,10 +520,10 @@
}
@Test
public void test275b() throws Exception {
- JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
- JexlContext ctxt = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().strict(true).safe(true).create();
+ final JexlContext ctxt = new MapContext();
JexlScript script;
- Prompt p0 = new Prompt();
+ final Prompt p0 = new Prompt();
p0.set("stuff", 42);
ctxt.set("$in", p0);
diff --git a/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java b/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java
index 86cc423..47a5c02 100644
--- a/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java
+++ b/src/test/java/org/apache/commons/jexl3/PublicFieldsTest.java
@@ -64,7 +64,7 @@
@Test
public void testGetInt() throws Exception {
- JexlExpression get = JEXL.createExpression("pub.anInt");
+ final JexlExpression get = JEXL.createExpression("pub.anInt");
Assert.assertEquals(42, get.evaluate(ctxt));
JEXL.setProperty(pub, "anInt", -42);
Assert.assertEquals(-42, get.evaluate(ctxt));
@@ -72,7 +72,7 @@
@Test
public void testSetInt() throws Exception {
- JexlExpression set = JEXL.createExpression("pub.anInt = value");
+ final JexlExpression set = JEXL.createExpression("pub.anInt = value");
ctxt.set("value", -42);
Assert.assertEquals(-42, set.evaluate(ctxt));
Assert.assertEquals(-42, JEXL.getProperty(pub, "anInt"));
@@ -83,12 +83,12 @@
ctxt.set("value", UPPER42);
Assert.assertNull(set.evaluate(ctxt));
Assert.fail("should have thrown");
- } catch(JexlException xjexl) {}
+ } catch(final JexlException xjexl) {}
}
@Test
public void testGetString() throws Exception {
- JexlExpression get = JEXL.createExpression("pub.aString");
+ final JexlExpression get = JEXL.createExpression("pub.aString");
Assert.assertEquals(LOWER42, get.evaluate(ctxt));
JEXL.setProperty(pub, "aString", UPPER42);
Assert.assertEquals(UPPER42, get.evaluate(ctxt));
@@ -96,7 +96,7 @@
@Test
public void testSetString() throws Exception {
- JexlExpression set = JEXL.createExpression("pub.aString = value");
+ final JexlExpression set = JEXL.createExpression("pub.aString = value");
ctxt.set("value", UPPER42);
Assert.assertEquals(UPPER42, set.evaluate(ctxt));
Assert.assertEquals(UPPER42, JEXL.getProperty(pub, "aString"));
@@ -107,7 +107,7 @@
@Test
public void testGetInnerDouble() throws Exception {
- JexlExpression get = JEXL.createExpression("pub.inner.aDouble");
+ final JexlExpression get = JEXL.createExpression("pub.inner.aDouble");
Assert.assertEquals(42.0, get.evaluate(ctxt));
JEXL.setProperty(pub, "inner.aDouble", -42);
Assert.assertEquals(-42.0, get.evaluate(ctxt));
@@ -115,7 +115,7 @@
@Test
public void testSetInnerDouble() throws Exception {
- JexlExpression set = JEXL.createExpression("pub.inner.aDouble = value");
+ final JexlExpression set = JEXL.createExpression("pub.inner.aDouble = value");
ctxt.set("value", -42.0);
Assert.assertEquals(-42.0, set.evaluate(ctxt));
Assert.assertEquals(-42.0, JEXL.getProperty(pub, "inner.aDouble"));
@@ -126,7 +126,7 @@
ctxt.set("value", UPPER42);
Assert.assertNull(set.evaluate(ctxt));
Assert.fail("should have thrown");
- } catch(JexlException xjexl) {}
+ } catch(final JexlException xjexl) {}
}
public enum Gender { MALE, FEMALE };
@@ -134,9 +134,9 @@
@Test
public void testGetEnum() throws Exception {
ctxt.set("com.jexl.gender", Gender.class);
- String src = "x = com.jexl.gender.FEMALE";
- JexlScript script = JEXL.createScript(src);
- Object result = script.execute(ctxt);
+ final String src = "x = com.jexl.gender.FEMALE";
+ final JexlScript script = JEXL.createScript(src);
+ final Object result = script.execute(ctxt);
Assert.assertEquals(Gender.FEMALE, result);
Assert.assertEquals(Gender.FEMALE, ctxt.get("x"));
}
@@ -144,9 +144,9 @@
@Test
public void testGetStaticField() throws Exception {
ctxt.set("com.jexl", Inner.class);
- String src = "x = com.jexl.NOT42";
- JexlScript script = JEXL.createScript(src);
- Object result = script.execute(ctxt);
+ final String src = "x = com.jexl.NOT42";
+ final JexlScript script = JEXL.createScript(src);
+ final Object result = script.execute(ctxt);
Assert.assertEquals(Inner.NOT42, result);
Assert.assertEquals(Inner.NOT42, ctxt.get("x"));
}
diff --git a/src/test/java/org/apache/commons/jexl3/RangeTest.java b/src/test/java/org/apache/commons/jexl3/RangeTest.java
index 3fad631..82f1332 100644
--- a/src/test/java/org/apache/commons/jexl3/RangeTest.java
+++ b/src/test/java/org/apache/commons/jexl3/RangeTest.java
@@ -34,14 +34,14 @@
@Test
public void testIntegerRangeOne() throws Exception {
- JexlExpression e = JEXL.createExpression("(1..1)");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("(1..1)");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertTrue(o instanceof Collection<?>);
- Collection<?> c = (Collection<?>) o;
+ final Collection<?> c = (Collection<?>) o;
Assert.assertEquals(1, c.size());
- Object[] a = c.toArray();
+ final Object[] a = c.toArray();
Assert.assertEquals(1, a.length);
Assert.assertEquals(1, ((Number) a[0]).intValue());
Assert.assertFalse((Boolean) JEXL.createScript("empty x", "x").execute(null, e));
@@ -49,13 +49,13 @@
@Test
public void testIntegerRange() throws Exception {
- JexlExpression e = JEXL.createExpression("(1..32)");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("(1..32)");
+ final JexlContext jc = new MapContext();
- Object o0 = e.evaluate(jc);
- Object o = e.evaluate(jc);
+ final Object o0 = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertTrue(o instanceof Collection<?>);
- Collection<?> c = (Collection<?>) o;
+ final Collection<?> c = (Collection<?>) o;
Assert.assertEquals(32, c.size());
Assert.assertNotSame(o0, o);
@@ -63,7 +63,7 @@
Assert.assertEquals(o0, o);
int i = 0;
- for (Object v : c) {
+ for (final Object v : c) {
i += 1;
Assert.assertEquals(i, ((Number) v).intValue());
}
@@ -87,7 +87,7 @@
Assert.assertEquals((int) aa[l], l + 1);
}
- Object[] oaa = c.toArray();
+ final Object[] oaa = c.toArray();
Assert.assertEquals(32, oaa.length);
for (int l = 0; l < 32; ++l) {
Assert.assertEquals(oaa[l], l + 1);
@@ -96,13 +96,13 @@
@Test
public void testLongRange() throws Exception {
- JexlExpression e = JEXL.createExpression("(6789000001L..6789000032L)");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("(6789000001L..6789000032L)");
+ final JexlContext jc = new MapContext();
- Object o0 = e.evaluate(jc);
- Object o = e.evaluate(jc);
+ final Object o0 = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertTrue(o instanceof Collection<?>);
- Collection<?> c = (Collection<?>) o;
+ final Collection<?> c = (Collection<?>) o;
Assert.assertEquals(32, c.size());
Assert.assertFalse((Boolean) JEXL.createScript("empty x", "x").execute(null, e));
@@ -111,7 +111,7 @@
Assert.assertEquals(o0, o);
long i = 6789000000L;
- for (Object v : c) {
+ for (final Object v : c) {
i += 1;
Assert.assertEquals(i, ((Number) v).longValue());
}
@@ -135,7 +135,7 @@
Assert.assertEquals((long) aa[l], 6789000001L + l);
}
- Object[] oaa = c.toArray();
+ final Object[] oaa = c.toArray();
Assert.assertEquals(32, oaa.length);
for (int l = 0; l < 32; ++l) {
Assert.assertEquals(oaa[l], 6789000001L + l);
@@ -144,17 +144,17 @@
@Test
public void testIntegerSum() throws Exception {
- JexlScript e = JEXL.createScript("var s = 0; for(var i : (1..5)) { s = s + i; }; s");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("var s = 0; for(var i : (1..5)) { s = s + i; }; s");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals(15, ((Number) o).intValue());
}
@Test
public void testIntegerContains() throws Exception {
- JexlScript e = JEXL.createScript("(x)->{ x =~ (1..10) }");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("(x)->{ x =~ (1..10) }");
+ final JexlContext jc = new MapContext();
Object o = e.execute(jc, 5);
Assert.assertEquals(Boolean.TRUE, o);
@@ -166,17 +166,17 @@
@Test
public void testLongSum() throws Exception {
- JexlScript e = JEXL.createScript("var s = 0; for(var i : (6789000001L..6789000001L)) { s = s + i; }; s");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("var s = 0; for(var i : (6789000001L..6789000001L)) { s = s + i; }; s");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals(6789000001L, ((Number) o).longValue());
}
@Test
public void testLongContains() throws Exception {
- JexlScript e = JEXL.createScript("(x)->{ x =~ (90000000001L..90000000010L) }");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("(x)->{ x =~ (90000000001L..90000000010L) }");
+ final JexlContext jc = new MapContext();
Object o = e.execute(jc, 90000000005L);
Assert.assertEquals(Boolean.TRUE, o);
diff --git a/src/test/java/org/apache/commons/jexl3/ReadonlyContext.java b/src/test/java/org/apache/commons/jexl3/ReadonlyContext.java
index 7b094e4..cdbc4e4 100644
--- a/src/test/java/org/apache/commons/jexl3/ReadonlyContext.java
+++ b/src/test/java/org/apache/commons/jexl3/ReadonlyContext.java
@@ -33,14 +33,14 @@
* @param context the wrapped context
* @param eopts the engine evaluation options
*/
- public ReadonlyContext(JexlContext context, JexlOptions eopts) {
+ public ReadonlyContext(final JexlContext context, final JexlOptions eopts) {
wrapped = context;
options = eopts;
}
@Override
@NoJexl
- public Object get(String name) {
+ public Object get(final String name) {
return wrapped.get(name);
}
@@ -51,13 +51,13 @@
*/
@Override
@NoJexl
- public void set(String name, Object value) {
+ public void set(final String name, final Object value) {
throw new UnsupportedOperationException("Not supported.");
}
@Override
@NoJexl
- public boolean has(String name) {
+ public boolean has(final String name) {
return wrapped.has(name);
}
diff --git a/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java b/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
index 57fe936..671f1e6 100644
--- a/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ScriptCallableTest.java
@@ -44,16 +44,16 @@
@Test
public void testFuture() throws Exception {
- JexlScript e = JEXL.createScript("while(true);");
- FutureTask<Object> future = new FutureTask<Object>(e.callable(null));
+ final JexlScript e = JEXL.createScript("while(true);");
+ final FutureTask<Object> future = new FutureTask<Object>(e.callable(null));
- ExecutorService executor = Executors.newFixedThreadPool(1);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
executor.submit(future);
Object t = 42;
try {
t = future.get(100, TimeUnit.MILLISECONDS);
Assert.fail("should have timed out");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
// ok, ignore
future.cancel(true);
} finally {
@@ -67,25 +67,25 @@
@Test
public void testCallableCancel() throws Exception {
final Semaphore latch = new Semaphore(0);
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
ctxt.set("latch", latch);
- JexlScript e = JEXL.createScript("latch.release(); while(true);");
+ final JexlScript e = JEXL.createScript("latch.release(); while(true);");
final Script.Callable c = (Script.Callable) e.callable(ctxt);
Object t = 42;
- Callable<Object> kc = () -> {
+ final Callable<Object> kc = () -> {
latch.acquire();
return c.cancel();
};
- ExecutorService executor = Executors.newFixedThreadPool(2);
- Future<?> future = executor.submit(c);
- Future<?> kfc = executor.submit(kc);
+ final ExecutorService executor = Executors.newFixedThreadPool(2);
+ final Future<?> future = executor.submit(c);
+ final Future<?> kfc = executor.submit(kc);
List<Runnable> lr;
try {
Assert.assertTrue((Boolean) kfc.get());
t = future.get();
Assert.fail("should have been cancelled");
- } catch (ExecutionException xexec) {
+ } catch (final ExecutionException xexec) {
// ok, ignore
Assert.assertTrue(xexec.getCause() instanceof JexlException.Cancel);
} finally {
@@ -98,7 +98,7 @@
public static class CancellationContext extends MapContext implements JexlContext.CancellationHandle {
private final AtomicBoolean cancellation;
- CancellationContext(AtomicBoolean c) {
+ CancellationContext(final AtomicBoolean c) {
cancellation = c;
}
@Override
@@ -112,25 +112,25 @@
public void testCallableCancellation() throws Exception {
final Semaphore latch = new Semaphore(0);
final AtomicBoolean cancel = new AtomicBoolean(false);
- JexlContext ctxt = new CancellationContext(cancel);
+ final JexlContext ctxt = new CancellationContext(cancel);
ctxt.set("latch", latch);
- JexlScript e = JEXL.createScript("latch.release(); while(true);");
+ final JexlScript e = JEXL.createScript("latch.release(); while(true);");
final Script.Callable c = (Script.Callable) e.callable(ctxt);
Object t = 42;
- Callable<Object> kc = () -> {
+ final Callable<Object> kc = () -> {
latch.acquire();
return cancel.compareAndSet(false, true);
};
- ExecutorService executor = Executors.newFixedThreadPool(2);
- Future<?> future = executor.submit(c);
- Future<?> kfc = executor.submit(kc);
+ final ExecutorService executor = Executors.newFixedThreadPool(2);
+ final Future<?> future = executor.submit(c);
+ final Future<?> kfc = executor.submit(kc);
List<Runnable> lr;
try {
Assert.assertTrue((Boolean) kfc.get());
t = future.get();
Assert.fail("should have been cancelled");
- } catch (ExecutionException xexec) {
+ } catch (final ExecutionException xexec) {
// ok, ignore
Assert.assertTrue(xexec.getCause() instanceof JexlException.Cancel);
} finally {
@@ -144,20 +144,20 @@
public void testCallableTimeout() throws Exception {
List<Runnable> lr = null;
final Semaphore latch = new Semaphore(0);
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
ctxt.set("latch", latch);
- JexlScript e = JEXL.createScript("latch.release(); while(true);");
- Callable<Object> c = e.callable(ctxt);
+ final JexlScript e = JEXL.createScript("latch.release(); while(true);");
+ final Callable<Object> c = e.callable(ctxt);
Object t = 42;
- ExecutorService executor = Executors.newFixedThreadPool(1);
- Future<?> future = executor.submit(c);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
+ final Future<?> future = executor.submit(c);
try {
latch.acquire();
t = future.get(100, TimeUnit.MILLISECONDS);
Assert.fail("should have timed out");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
// ok, ignore
future.cancel(true);
} finally {
@@ -171,16 +171,16 @@
@Test
public void testCallableClosure() throws Exception {
List<Runnable> lr = null;
- JexlScript e = JEXL.createScript("function(t) {while(t);}");
- Callable<Object> c = e.callable(null, Boolean.TRUE);
+ final JexlScript e = JEXL.createScript("function(t) {while(t);}");
+ final Callable<Object> c = e.callable(null, Boolean.TRUE);
Object t = 42;
- ExecutorService executor = Executors.newFixedThreadPool(1);
- Future<?> future = executor.submit(c);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
+ final Future<?> future = executor.submit(c);
try {
t = future.get(100, TimeUnit.MILLISECONDS);
Assert.fail("should have timed out");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
// ok, ignore
future.cancel(true);
} finally {
@@ -193,20 +193,20 @@
public static class TestContext extends MapContext implements JexlContext.NamespaceResolver {
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
return name == null ? this : null;
}
- public int wait(int s) throws InterruptedException {
+ public int wait(final int s) throws InterruptedException {
Thread.sleep(1000 * s);
return s;
}
- public int waitInterrupt(int s) {
+ public int waitInterrupt(final int s) {
try {
Thread.sleep(1000 * s);
return s;
- } catch (InterruptedException xint) {
+ } catch (final InterruptedException xint) {
Thread.currentThread().interrupt();
}
return -1;
@@ -226,11 +226,11 @@
return 42;
}
- public void sleep(long millis) throws InterruptedException {
+ public void sleep(final long millis) throws InterruptedException {
Thread.sleep(millis);
}
- public int hangs(Object t) {
+ public int hangs(final Object t) {
return 1;
}
}
@@ -238,13 +238,13 @@
@Test
public void testNoWait() throws Exception {
List<Runnable> lr = null;
- JexlScript e = JEXL.createScript("wait(0)");
- Callable<Object> c = e.callable(new TestContext());
+ final JexlScript e = JEXL.createScript("wait(0)");
+ final Callable<Object> c = e.callable(new TestContext());
- ExecutorService executor = Executors.newFixedThreadPool(1);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
try {
- Future<?> future = executor.submit(c);
- Object t = future.get(2, TimeUnit.SECONDS);
+ final Future<?> future = executor.submit(c);
+ final Object t = future.get(2, TimeUnit.SECONDS);
Assert.assertTrue(future.isDone());
Assert.assertEquals(0, t);
} finally {
@@ -256,13 +256,13 @@
@Test
public void testWait() throws Exception {
List<Runnable> lr = null;
- JexlScript e = JEXL.createScript("wait(1)");
- Callable<Object> c = e.callable(new TestContext());
+ final JexlScript e = JEXL.createScript("wait(1)");
+ final Callable<Object> c = e.callable(new TestContext());
- ExecutorService executor = Executors.newFixedThreadPool(1);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
try {
- Future<?> future = executor.submit(c);
- Object t = future.get(2, TimeUnit.SECONDS);
+ final Future<?> future = executor.submit(c);
+ final Object t = future.get(2, TimeUnit.SECONDS);
Assert.assertEquals(1, t);
} finally {
lr = executor.shutdownNow();
@@ -273,17 +273,17 @@
@Test
public void testCancelWait() throws Exception {
List<Runnable> lr = null;
- JexlScript e = JEXL.createScript("wait(10)");
- Callable<Object> c = e.callable(new TestContext());
+ final JexlScript e = JEXL.createScript("wait(10)");
+ final Callable<Object> c = e.callable(new TestContext());
- ExecutorService executor = Executors.newFixedThreadPool(1);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
try {
- Future<?> future = executor.submit(c);
+ final Future<?> future = executor.submit(c);
Object t = 42;
try {
t = future.get(100, TimeUnit.MILLISECONDS);
Assert.fail("should have timed out");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
// ok, ignore
future.cancel(true);
}
@@ -298,17 +298,17 @@
@Test
public void testCancelWaitInterrupt() throws Exception {
List<Runnable> lr = null;
- JexlScript e = JEXL.createScript("waitInterrupt(42)");
- Callable<Object> c = e.callable(new TestContext());
+ final JexlScript e = JEXL.createScript("waitInterrupt(42)");
+ final Callable<Object> c = e.callable(new TestContext());
- ExecutorService executor = Executors.newFixedThreadPool(1);
- Future<?> future = executor.submit(c);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
+ final Future<?> future = executor.submit(c);
Object t = 42;
try {
t = future.get(100, TimeUnit.MILLISECONDS);
Assert.fail("should have timed out");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
// ok, ignore
future.cancel(true);
} finally {
@@ -323,21 +323,21 @@
public void testCancelForever() throws Exception {
List<Runnable> lr = null;
final Semaphore latch = new Semaphore(0);
- JexlContext ctxt = new TestContext();
+ final JexlContext ctxt = new TestContext();
ctxt.set("latch", latch);
- JexlScript e = JEXL.createScript("latch.release(); runForever()");
- Callable<Object> c = e.callable(ctxt);
+ final JexlScript e = JEXL.createScript("latch.release(); runForever()");
+ final Callable<Object> c = e.callable(ctxt);
- ExecutorService executor = Executors.newFixedThreadPool(1);
- Future<?> future = executor.submit(c);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
+ final Future<?> future = executor.submit(c);
Object t = 42;
try {
latch.acquire();
t = future.get(100, TimeUnit.MILLISECONDS);
Assert.fail("should have timed out");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
// ok, ignore
future.cancel(true);
} finally {
@@ -351,17 +351,17 @@
@Test
public void testCancelLoopWait() throws Exception {
List<Runnable> lr = null;
- JexlScript e = JEXL.createScript("while (true) { wait(10) }");
- Callable<Object> c = e.callable(new TestContext());
+ final JexlScript e = JEXL.createScript("while (true) { wait(10) }");
+ final Callable<Object> c = e.callable(new TestContext());
- ExecutorService executor = Executors.newFixedThreadPool(1);
- Future<?> future = executor.submit(c);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
+ final Future<?> future = executor.submit(c);
Object t = 42;
try {
t = future.get(100, TimeUnit.MILLISECONDS);
Assert.fail("should have timed out");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
future.cancel(true);
} finally {
lr = executor.shutdownNow();
@@ -400,14 +400,14 @@
* Redundant test with previous ones but impervious to JEXL engine configuation.
* @throws Exception if there is a regression
*/
- private void runInterrupt(JexlEngine jexl) throws Exception {
+ private void runInterrupt(final JexlEngine jexl) throws Exception {
List<Runnable> lr = null;
- ExecutorService exec = Executors.newFixedThreadPool(2);
+ final ExecutorService exec = Executors.newFixedThreadPool(2);
try {
- JexlContext ctxt = new TestContext();
+ final JexlContext ctxt = new TestContext();
// run an interrupt
- JexlScript sint = jexl.createScript("interrupt(); return 42");
+ final JexlScript sint = jexl.createScript("interrupt(); return 42");
Object t = null;
Script.Callable c = (Script.Callable) sint.callable(ctxt);
try {
@@ -415,7 +415,7 @@
if (c.isCancellable()) {
Assert.fail("should have thrown a Cancel");
}
- } catch (JexlException.Cancel xjexl) {
+ } catch (final JexlException.Cancel xjexl) {
if (!c.isCancellable()) {
Assert.fail("should not have thrown " + xjexl);
}
@@ -432,7 +432,7 @@
if (c.isCancellable()) {
Assert.fail("should have thrown a Cancel");
}
- } catch (ExecutionException xexec) {
+ } catch (final ExecutionException xexec) {
if (!c.isCancellable()) {
Assert.fail("should not have thrown " + xexec);
}
@@ -441,12 +441,12 @@
Assert.assertNotEquals(42, t);
// timeout a sleep
- JexlScript ssleep = jexl.createScript("sleep(30000); return 42");
+ final JexlScript ssleep = jexl.createScript("sleep(30000); return 42");
try {
f = exec.submit(ssleep.callable(ctxt));
t = f.get(100L, TimeUnit.MILLISECONDS);
Assert.fail("should timeout");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
if (f != null) {
f.cancel(true);
}
@@ -456,10 +456,10 @@
// cancel a sleep
try {
final Future<Object> fc = exec.submit(ssleep.callable(ctxt));
- Runnable cancels = () -> {
+ final Runnable cancels = () -> {
try {
Thread.sleep(200L);
- } catch (Exception xignore) {
+ } catch (final Exception xignore) {
}
fc.cancel(true);
@@ -467,17 +467,17 @@
exec.submit(cancels);
t = f.get(100L, TimeUnit.MILLISECONDS);
Assert.fail("should be cancelled");
- } catch (CancellationException xexec) {
+ } catch (final CancellationException xexec) {
// this is the expected result
}
// timeout a while(true)
- JexlScript swhile = jexl.createScript("while(true); return 42");
+ final JexlScript swhile = jexl.createScript("while(true); return 42");
try {
f = exec.submit(swhile.callable(ctxt));
t = f.get(100L, TimeUnit.MILLISECONDS);
Assert.fail("should timeout");
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
if (f != null) {
f.cancel(true);
}
@@ -487,10 +487,10 @@
// cancel a while(true)
try {
final Future<Object> fc = exec.submit(swhile.callable(ctxt));
- Runnable cancels = () -> {
+ final Runnable cancels = () -> {
try {
Thread.sleep(200L);
- } catch (Exception xignore) {
+ } catch (final Exception xignore) {
}
fc.cancel(true);
@@ -498,7 +498,7 @@
exec.submit(cancels);
t = fc.get();
Assert.fail("should be cancelled");
- } catch (CancellationException xexec) {
+ } catch (final CancellationException xexec) {
// this is the expected result
}
Assert.assertNotEquals(42, t);
@@ -510,15 +510,15 @@
@Test
public void testHangs() throws Exception {
- JexlScript e = JEXL.createScript("hangs()");
- Callable<Object> c = e.callable(new TestContext());
+ final JexlScript e = JEXL.createScript("hangs()");
+ final Callable<Object> c = e.callable(new TestContext());
- ExecutorService executor = Executors.newFixedThreadPool(1);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
try {
- Future<?> future = executor.submit(c);
- Object t = future.get(1, TimeUnit.SECONDS);
+ final Future<?> future = executor.submit(c);
+ final Object t = future.get(1, TimeUnit.SECONDS);
Assert.fail("hangs should not be solved");
- } catch(ExecutionException xexec) {
+ } catch(final ExecutionException xexec) {
Assert.assertTrue(xexec.getCause() instanceof JexlException.Method);
} finally {
executor.shutdown();
@@ -527,19 +527,19 @@
public static class AnnotationContext extends MapContext implements JexlContext.AnnotationProcessor {
@Override
- public Object processAnnotation(String name, Object[] args, Callable<Object> statement) throws Exception {
+ public Object processAnnotation(final String name, final Object[] args, final Callable<Object> statement) throws Exception {
if ("timeout".equals(name) && args != null && args.length > 0) {
- long ms = args[0] instanceof Number
+ final long ms = args[0] instanceof Number
? ((Number) args[0]).longValue()
: Long.parseLong(args[0].toString());
- Object def = args.length > 1? args[1] : null;
+ final Object def = args.length > 1? args[1] : null;
if (ms > 0) {
- ExecutorService executor = Executors.newFixedThreadPool(1);
+ final ExecutorService executor = Executors.newFixedThreadPool(1);
Future<?> future = null;
try {
future = executor.submit(statement);
return future.get(ms, TimeUnit.MILLISECONDS);
- } catch (TimeoutException xtimeout) {
+ } catch (final TimeoutException xtimeout) {
if (future != null) {
future.cancel(true);
}
@@ -553,7 +553,7 @@
return statement.call();
}
- public void sleep(long ms) throws InterruptedException {
+ public void sleep(final long ms) throws InterruptedException {
Thread.sleep(ms);
}
@@ -562,11 +562,11 @@
@Test
public void testTimeout() throws Exception {
JexlScript script = JEXL.createScript("(flag)->{ @timeout(100) { while(flag); return 42 }; 'cancelled' }");
- JexlContext ctxt = new AnnotationContext();
+ final JexlContext ctxt = new AnnotationContext();
Object result = null;
try {
result = script.execute(ctxt, true);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
Assert.fail(xany.toString());
}
Assert.assertEquals("cancelled", result);
@@ -576,7 +576,7 @@
script = JEXL.createScript("(flag)->{ @timeout(100, 'cancelled') { while(flag); 42; } }");
try {
result = script.execute(ctxt, true);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
Assert.fail(xany.toString());
}
Assert.assertEquals("cancelled", result);
@@ -586,7 +586,7 @@
script = JEXL.createScript("@timeout(10) {sleep(1000); 42; } -42;");
try {
result = script.execute(ctxt);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
Assert.fail(xany.toString());
}
Assert.assertEquals(-42, result);
@@ -594,14 +594,14 @@
script = JEXL.createScript("@timeout(10) {sleep(1000); return 42; } return -42;");
try {
result = script.execute(ctxt);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
Assert.fail(xany.toString());
}
Assert.assertEquals(-42, result);
script = JEXL.createScript("@timeout(1000) {sleep(10); return 42; } return -42;");
try {
result = script.execute(ctxt);
- } catch (Exception xany) {
+ } catch (final Exception xany) {
Assert.fail(xany.toString());
}
Assert.assertEquals(42, result);
diff --git a/src/test/java/org/apache/commons/jexl3/ScriptTest.java b/src/test/java/org/apache/commons/jexl3/ScriptTest.java
index 933c597..79c9b36 100644
--- a/src/test/java/org/apache/commons/jexl3/ScriptTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ScriptTest.java
@@ -40,7 +40,7 @@
public String getCode () {
return code;
}
- public void setCode(String c) {
+ public void setCode(final String c) {
code = c;
}
}
@@ -56,8 +56,8 @@
*/
@Test
public void testSpacesScript() throws Exception {
- String code = " ";
- JexlScript s = JEXL.createScript(code);
+ final String code = " ";
+ final JexlScript s = JEXL.createScript(code);
Assert.assertNotNull(s);
}
@@ -66,68 +66,68 @@
*/
@Test
public void testSimpleScript() throws Exception {
- String code = "while (x < 10) x = x + 1;";
- JexlScript s = JEXL.createScript(code);
- JexlContext jc = new MapContext();
+ final String code = "while (x < 10) x = x + 1;";
+ final JexlScript s = JEXL.createScript(code);
+ final JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
- Object o = s.execute(jc);
+ final Object o = s.execute(jc);
Assert.assertEquals("Result is wrong", new Integer(10), o);
Assert.assertEquals("getText is wrong", code, s.getSourceText());
}
@Test
public void testScriptFromFile() throws Exception {
- File testScript = new File(TEST1);
- JexlScript s = JEXL.createScript(testScript);
- JexlContext jc = new MapContext();
+ final File testScript = new File(TEST1);
+ final JexlScript s = JEXL.createScript(testScript);
+ final JexlContext jc = new MapContext();
jc.set("out", System.out);
- Object result = s.execute(jc);
+ final Object result = s.execute(jc);
Assert.assertNotNull("No result", result);
Assert.assertEquals("Wrong result", new Integer(7), result);
}
@Test
public void testArgScriptFromFile() throws Exception {
- File testScript = new File(TEST_ADD);
- JexlScript s = JEXL.createScript(testScript,new String[]{"x","y"});
- JexlContext jc = new MapContext();
+ final File testScript = new File(TEST_ADD);
+ final JexlScript s = JEXL.createScript(testScript,new String[]{"x","y"});
+ final JexlContext jc = new MapContext();
jc.set("out", System.out);
- Object result = s.execute(jc, 13, 29);
+ final Object result = s.execute(jc, 13, 29);
Assert.assertNotNull("No result", result);
Assert.assertEquals("Wrong result", new Integer(42), result);
}
@Test
public void testScriptFromURL() throws Exception {
- URL testUrl = new File(TEST1).toURI().toURL();
- JexlScript s = JEXL.createScript(testUrl);
- JexlContext jc = new MapContext();
+ final URL testUrl = new File(TEST1).toURI().toURL();
+ final JexlScript s = JEXL.createScript(testUrl);
+ final JexlContext jc = new MapContext();
jc.set("out", System.out);
- Object result = s.execute(jc);
+ final Object result = s.execute(jc);
Assert.assertNotNull("No result", result);
Assert.assertEquals("Wrong result", new Integer(7), result);
}
@Test
public void testArgScriptFromURL() throws Exception {
- URL testUrl = new File(TEST_ADD).toURI().toURL();
- JexlScript s = JEXL.createScript(testUrl,new String[]{"x","y"});
- JexlContext jc = new MapContext();
+ final URL testUrl = new File(TEST_ADD).toURI().toURL();
+ final JexlScript s = JEXL.createScript(testUrl,new String[]{"x","y"});
+ final JexlContext jc = new MapContext();
jc.set("out", System.out);
- Object result = s.execute(jc, 13, 29);
+ final Object result = s.execute(jc, 13, 29);
Assert.assertNotNull("No result", result);
Assert.assertEquals("Wrong result", new Integer(42), result);
}
@Test
public void testScriptUpdatesContext() throws Exception {
- String jexlCode = "resultat.setCode('OK')";
- JexlExpression e = JEXL.createExpression(jexlCode);
- JexlScript s = JEXL.createScript(jexlCode);
+ final String jexlCode = "resultat.setCode('OK')";
+ final JexlExpression e = JEXL.createExpression(jexlCode);
+ final JexlScript s = JEXL.createScript(jexlCode);
- Tester resultatJexl = new Tester();
- JexlContext jc = new MapContext();
+ final Tester resultatJexl = new Tester();
+ final JexlContext jc = new MapContext();
jc.set("resultat", resultatJexl);
resultatJexl.setCode("");
diff --git a/src/test/java/org/apache/commons/jexl3/SetLiteralTest.java b/src/test/java/org/apache/commons/jexl3/SetLiteralTest.java
index c77955d..3b758ff 100644
--- a/src/test/java/org/apache/commons/jexl3/SetLiteralTest.java
+++ b/src/test/java/org/apache/commons/jexl3/SetLiteralTest.java
@@ -34,83 +34,83 @@
super("SetLiteralTest");
}
- private static Set<?> createSet(Object... args) {
+ private static Set<?> createSet(final Object... args) {
return new HashSet<Object>(Arrays.asList(args));
}
@Test
public void testSetLiteralWithStrings() throws Exception {
- JexlExpression e = JEXL.createExpression("{ 'foo' , 'bar' }");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("{ 'foo' , 'bar' }");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
- Set<?> check = createSet("foo", "bar");
+ final Object o = e.evaluate(jc);
+ final Set<?> check = createSet("foo", "bar");
Assert.assertEquals(check, o);
}
@Test
public void testLiteralWithOneEntry() throws Exception {
- JexlExpression e = JEXL.createExpression("{ 'foo' }");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("{ 'foo' }");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
- Set<?> check = createSet("foo");
+ final Object o = e.evaluate(jc);
+ final Set<?> check = createSet("foo");
Assert.assertEquals(check, o);
}
@Test
public void testSetLiteralWithStringsScript() throws Exception {
- JexlScript e = JEXL.createScript("{ 'foo' , 'bar' }");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("{ 'foo' , 'bar' }");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
- Set<?> check = createSet("foo", "bar");
+ final Object o = e.execute(jc);
+ final Set<?> check = createSet("foo", "bar");
Assert.assertEquals(check, o);
}
@Test
public void testSetLiteralWithOneEntryScript() throws Exception {
- JexlScript e = JEXL.createScript("{ 'foo' }");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("{ 'foo' }");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
- Set<?> check = createSet("foo");
+ final Object o = e.execute(jc);
+ final Set<?> check = createSet("foo");
Assert.assertEquals(check, o);
}
@Test
public void testSetLiteralWithOneEntryBlock() throws Exception {
- JexlScript e = JEXL.createScript("{ { 'foo' }; }");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("{ { 'foo' }; }");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
- Set<?> check = createSet("foo");
+ final Object o = e.execute(jc);
+ final Set<?> check = createSet("foo");
Assert.assertEquals(check, o);
}
@Test
public void testSetLiteralWithOneNestedSet() throws Exception {
- JexlScript e = JEXL.createScript("{ { 'foo' } }");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("{ { 'foo' } }");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
- Set<?> check = createSet(createSet("foo"));
+ final Object o = e.execute(jc);
+ final Set<?> check = createSet(createSet("foo"));
Assert.assertEquals(check, o);
}
@Test
public void testSetLiteralWithNumbers() throws Exception {
- JexlExpression e = JEXL.createExpression("{ 5.0 , 10 }");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("{ 5.0 , 10 }");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
- Set<?> check = createSet(new Double(5.0), new Integer(10));
+ final Object o = e.evaluate(jc);
+ final Set<?> check = createSet(new Double(5.0), new Integer(10));
Assert.assertEquals(check, o);
}
@Test
public void testSetLiteralWithNulls() throws Exception {
- String[] exprs = {
+ final String[] exprs = {
"{ }",
"{ 10 }",
"{ 10 , null }",
@@ -118,7 +118,7 @@
"{ '10' , null }",
"{ null, '10' , 20 }"
};
- Set<?>[] checks = {
+ final Set<?>[] checks = {
Collections.emptySet(),
createSet(new Integer(10)),
createSet(new Integer(10), null),
@@ -126,10 +126,10 @@
createSet("10", null),
createSet(null, "10", new Integer(20))
};
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
for (int t = 0; t < exprs.length; ++t) {
- JexlScript e = JEXL.createScript(exprs[t]);
- Object o = e.execute(jc);
+ final JexlScript e = JEXL.createScript(exprs[t]);
+ final Object o = e.execute(jc);
Assert.assertEquals(exprs[t], checks[t], o);
}
@@ -137,19 +137,19 @@
@Test
public void testSizeOfSimpleSetLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression("size({ 'foo' , 'bar'})");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("size({ 'foo' , 'bar'})");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertEquals(new Integer(2), o);
}
@Test
public void testNotEmptySimpleSetLiteral() throws Exception {
- JexlExpression e = JEXL.createExpression("empty({ 'foo' , 'bar' })");
- JexlContext jc = new MapContext();
+ final JexlExpression e = JEXL.createExpression("empty({ 'foo' , 'bar' })");
+ final JexlContext jc = new MapContext();
- Object o = e.evaluate(jc);
+ final Object o = e.evaluate(jc);
Assert.assertFalse((Boolean) o);
}
diff --git a/src/test/java/org/apache/commons/jexl3/SideEffectTest.java b/src/test/java/org/apache/commons/jexl3/SideEffectTest.java
index c895d1b..adbb053 100644
--- a/src/test/java/org/apache/commons/jexl3/SideEffectTest.java
+++ b/src/test/java/org/apache/commons/jexl3/SideEffectTest.java
@@ -54,9 +54,9 @@
@Test
public void testSideEffectVar() throws Exception {
- Map<String,Object> context = asserter.getVariables();
- Integer i41 = Integer.valueOf(4141);
- Object foo = i41;
+ final Map<String,Object> context = asserter.getVariables();
+ final Integer i41 = Integer.valueOf(4141);
+ final Object foo = i41;
context.put("foo", foo);
asserter.assertExpression("foo += 2", i41 + 2);
@@ -93,9 +93,9 @@
@Test
public void testSideEffectVarDots() throws Exception {
- Map<String,Object> context = asserter.getVariables();
- Integer i41 = Integer.valueOf(4141);
- Object foo = i41;
+ final Map<String,Object> context = asserter.getVariables();
+ final Integer i41 = Integer.valueOf(4141);
+ final Object foo = i41;
context.put("foo.bar.quux", foo);
asserter.assertExpression("foo.bar.quux += 2", i41 + 2);
@@ -132,12 +132,12 @@
@Test
public void testSideEffectArray() throws Exception {
- Integer i41 = Integer.valueOf(4141);
- Integer i42 = Integer.valueOf(42);
- Integer i43 = Integer.valueOf(43);
- String s42 = "fourty-two";
- String s43 = "fourty-three";
- Object[] foo = new Object[3];
+ final Integer i41 = Integer.valueOf(4141);
+ final Integer i42 = Integer.valueOf(42);
+ final Integer i43 = Integer.valueOf(43);
+ final String s42 = "fourty-two";
+ final String s43 = "fourty-three";
+ final Object[] foo = new Object[3];
foo[1] = i42;
foo[2] = i43;
asserter.setVariable("foo", foo);
@@ -169,12 +169,12 @@
@Test
public void testSideEffectDotArray() throws Exception {
- Integer i41 = Integer.valueOf(4141);
- Integer i42 = Integer.valueOf(42);
- Integer i43 = Integer.valueOf(43);
- String s42 = "fourty-two";
- String s43 = "fourty-three";
- Object[] foo = new Object[3];
+ final Integer i41 = Integer.valueOf(4141);
+ final Integer i42 = Integer.valueOf(42);
+ final Integer i43 = Integer.valueOf(43);
+ final String s42 = "fourty-two";
+ final String s43 = "fourty-three";
+ final Object[] foo = new Object[3];
foo[1] = i42;
foo[2] = i43;
asserter.setVariable("foo", foo);
@@ -206,10 +206,10 @@
@Test
public void testSideEffectAntishArray() throws Exception {
- Integer i41 = Integer.valueOf(4141);
- Integer i42 = Integer.valueOf(42);
- Integer i43 = Integer.valueOf(43);
- Object[] foo = new Object[3];
+ final Integer i41 = Integer.valueOf(4141);
+ final Integer i42 = Integer.valueOf(42);
+ final Integer i43 = Integer.valueOf(43);
+ final Object[] foo = new Object[3];
foo[1] = i42;
foo[2] = i43;
asserter.setVariable("foo.bar", foo);
@@ -241,7 +241,7 @@
public static class Foo {
int value;
- Foo(int v) {
+ Foo(final int v) {
value = v;
}
@@ -250,26 +250,26 @@
return Integer.toString(value);
}
- public void setValue(long v) {
+ public void setValue(final long v) {
value = (int) v;
}
public int getValue() {
return value;
}
- public void setBar(int x, long v) {
+ public void setBar(final int x, final long v) {
value = (int) v + x;
}
- public int getBar(int x) {
+ public int getBar(final int x) {
return value + x;
}
}
@Test
public void testSideEffectBean() throws Exception {
- Integer i41 = Integer.valueOf(4141);
- Foo foo = new Foo(0);
+ final Integer i41 = Integer.valueOf(4141);
+ final Foo foo = new Foo(0);
asserter.setVariable("foo", foo);
foo.value = i41;
asserter.assertExpression("foo.value += 2", i41 + 2);
@@ -299,8 +299,8 @@
@Test
public void testSideEffectBeanContainer() throws Exception {
- Integer i41 = Integer.valueOf(4141);
- Foo foo = new Foo(0);
+ final Integer i41 = Integer.valueOf(4141);
+ final Foo foo = new Foo(0);
asserter.setVariable("foo", foo);
foo.value = i41;
asserter.assertExpression("foo.bar[0] += 2", i41 + 2);
@@ -333,26 +333,26 @@
@Test
public void testArithmeticSelf() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(64).arithmetic(new SelfArithmetic(false)).create();
- JexlContext jc = null;
+ final JexlEngine jexl = new JexlBuilder().cache(64).arithmetic(new SelfArithmetic(false)).create();
+ final JexlContext jc = null;
runSelfOverload(jexl, jc);
runSelfOverload(jexl, jc);
}
@Test
public void testArithmeticSelfNoCache() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(0).arithmetic(new SelfArithmetic(false)).create();
- JexlContext jc = null;
+ final JexlEngine jexl = new JexlBuilder().cache(0).arithmetic(new SelfArithmetic(false)).create();
+ final JexlContext jc = null;
runSelfOverload(jexl, jc);
}
- protected void runSelfOverload(JexlEngine jexl, JexlContext jc) {
+ protected void runSelfOverload(final JexlEngine jexl, final JexlContext jc) {
JexlScript script;
Object result;
script = jexl.createScript("(x, y)->{ x += y }");
result = script.execute(jc, 3115, 15);
Assert.assertEquals(3115 + 15, result);
- Var v0 = new Var(3115);
+ final Var v0 = new Var(3115);
result = script.execute(jc, v0, new Var(15));
Assert.assertEquals(result, v0);
Assert.assertEquals(3115 + 15, v0.value);
@@ -360,7 +360,7 @@
script = jexl.createScript("(x, y)->{ x -= y}");
result = script.execute(jc, 3115, 15);
Assert.assertEquals(3115 - 15, result);
- Var v1 = new Var(3115);
+ final Var v1 = new Var(3115);
result = script.execute(jc, v1, new Var(15));
Assert.assertNotEquals(result, v1); // not a real side effect
Assert.assertEquals(3115 - 15, ((Var) result).value);
@@ -368,7 +368,7 @@
script = jexl.createScript("(x, y)->{ x *= y }");
result = script.execute(jc, 3115, 15);
Assert.assertEquals(3115 * 15, result);
- Var v2 = new Var(3115);
+ final Var v2 = new Var(3115);
result = script.execute(jc, v2, new Var(15));
Assert.assertEquals(result, v2);
Assert.assertEquals(3115 * 15, v2.value);
@@ -376,7 +376,7 @@
script = jexl.createScript("(x, y)->{ x /= y }");
result = script.execute(jc, 3115, 15);
Assert.assertEquals(3115 / 15, result);
- Var v3 = new Var(3115);
+ final Var v3 = new Var(3115);
result = script.execute(jc, v3, new Var(15));
Assert.assertEquals(result, v3);
Assert.assertEquals(3115 / 15, v3.value);
@@ -384,7 +384,7 @@
script = jexl.createScript("(x, y)->{ x %= y }");
result = script.execute(jc, 3115, 15);
Assert.assertEquals(3115 % 15, result);
- Var v4 = new Var(3115);
+ final Var v4 = new Var(3115);
result = script.execute(jc, v4, new Var(15));
Assert.assertEquals(result, v4);
Assert.assertEquals(3115 % 15, v4.value);
@@ -392,7 +392,7 @@
script = jexl.createScript("(x, y)->{ x &= y }");
result = script.execute(jc, 3115, 15);
Assert.assertEquals(3115L & 15, result);
- Var v5 = new Var(3115);
+ final Var v5 = new Var(3115);
result = script.execute(jc, v5, new Var(15));
Assert.assertEquals(result, v5);
Assert.assertEquals(3115 & 15, v5.value);
@@ -400,7 +400,7 @@
script = jexl.createScript("(x, y)->{ x |= y }");
result = script.execute(jc, 3115, 15);
Assert.assertEquals(3115L | 15, result);
- Var v6 = new Var(3115);
+ final Var v6 = new Var(3115);
result = script.execute(jc, v6, new Var(15));
Assert.assertEquals(result, v6);
Assert.assertEquals(3115L | 15, v6.value);
@@ -408,7 +408,7 @@
script = jexl.createScript("(x, y)->{ x ^= y }");
result = script.execute(jc, 3115, 15);
Assert.assertEquals(3115L ^ 15, result);
- Var v7 = new Var(3115);
+ final Var v7 = new Var(3115);
result = script.execute(jc, v7, new Var(15));
Assert.assertEquals(result, v7);
Assert.assertEquals(3115L ^ 15, v7.value);
@@ -417,12 +417,12 @@
@Test
public void testOverrideGetSet() throws Exception {
- JexlEngine jexl = new JexlBuilder().cache(64).arithmetic(new SelfArithmetic(false)).create();
- JexlContext jc = null;
+ final JexlEngine jexl = new JexlBuilder().cache(64).arithmetic(new SelfArithmetic(false)).create();
+ final JexlContext jc = null;
JexlScript script;
Object result;
- Var v0 = new Var(3115);
+ final Var v0 = new Var(3115);
script = jexl.createScript("(x)->{ x.value}");
result = script.execute(jc, v0);
Assert.assertEquals(3115, result);
@@ -440,7 +440,7 @@
public static class Var {
int value;
- Var(int v) {
+ Var(final int v) {
value = v;
}
@@ -452,74 +452,74 @@
// an arithmetic that performs side effects
public static class SelfArithmetic extends JexlArithmetic {
- public SelfArithmetic(boolean strict) {
+ public SelfArithmetic(final boolean strict) {
super(strict);
}
- public Object propertyGet(Var var, String property) {
+ public Object propertyGet(final Var var, final String property) {
return "value".equals(property)? var.value : JexlEngine.TRY_FAILED;
}
- public Object propertySet(Var var, String property, int v) {
+ public Object propertySet(final Var var, final String property, final int v) {
return "value".equals(property)? var.value = v : JexlEngine.TRY_FAILED;
}
- public Object arrayGet(Var var, String property) {
+ public Object arrayGet(final Var var, final String property) {
return "VALUE".equals(property)? var.value : JexlEngine.TRY_FAILED;
}
- public Object arraySet(Var var, String property, int v) {
+ public Object arraySet(final Var var, final String property, final int v) {
return "VALUE".equals(property)? var.value = v : JexlEngine.TRY_FAILED;
}
- public JexlOperator selfAdd(Var lhs, Var rhs) {
+ public JexlOperator selfAdd(final Var lhs, final Var rhs) {
lhs.value += rhs.value;
return JexlOperator.ASSIGN;
}
// for kicks, this one does not side effect but overloads nevertheless
- public Var selfSubtract(Var lhs, Var rhs) {
+ public Var selfSubtract(final Var lhs, final Var rhs) {
return new Var(lhs.value - rhs.value);
}
- public JexlOperator selfDivide(Var lhs, Var rhs) {
+ public JexlOperator selfDivide(final Var lhs, final Var rhs) {
lhs.value /= rhs.value;
return JexlOperator.ASSIGN;
}
- public JexlOperator selfMultiply(Var lhs, Var rhs) {
+ public JexlOperator selfMultiply(final Var lhs, final Var rhs) {
lhs.value *= rhs.value;
return JexlOperator.ASSIGN;
}
- public JexlOperator selfMod(Var lhs, Var rhs) {
+ public JexlOperator selfMod(final Var lhs, final Var rhs) {
lhs.value %= rhs.value;
return JexlOperator.ASSIGN;
}
- public Var and(Var lhs, Var rhs) {
+ public Var and(final Var lhs, final Var rhs) {
return new Var(lhs.value & rhs.value);
}
- public JexlOperator selfAnd(Var lhs, Var rhs) {
+ public JexlOperator selfAnd(final Var lhs, final Var rhs) {
lhs.value &= rhs.value;
return JexlOperator.ASSIGN;
}
- public Var or(Var lhs, Var rhs) {
+ public Var or(final Var lhs, final Var rhs) {
return new Var(lhs.value | rhs.value);
}
- public JexlOperator selfOr(Var lhs, Var rhs) {
+ public JexlOperator selfOr(final Var lhs, final Var rhs) {
lhs.value |= rhs.value;
return JexlOperator.ASSIGN;
}
- public Var xor(Var lhs, Var rhs) {
+ public Var xor(final Var lhs, final Var rhs) {
return new Var(lhs.value ^ rhs.value);
}
- public JexlOperator selfXor(Var lhs, Var rhs) {
+ public JexlOperator selfXor(final Var lhs, final Var rhs) {
lhs.value ^= rhs.value;
return JexlOperator.ASSIGN;
}
@@ -529,32 +529,32 @@
* An arithmetic that implements 2 selfAdd methods.
*/
public static class Arithmetic246 extends JexlArithmetic {
- public Arithmetic246(boolean astrict) {
+ public Arithmetic246(final boolean astrict) {
super(astrict);
}
- public JexlOperator selfAdd(Collection<String> c, String item) throws IOException {
+ public JexlOperator selfAdd(final Collection<String> c, final String item) throws IOException {
c.add(item);
return JexlOperator.ASSIGN;
}
- public JexlOperator selfAdd(Appendable c, String item) throws IOException {
+ public JexlOperator selfAdd(final Appendable c, final String item) throws IOException {
c.append(item);
return JexlOperator.ASSIGN;
}
@Override
- public Object add(Object right, Object left) {
+ public Object add(final Object right, final Object left) {
return super.add(left, right);
}
}
public static class Arithmetic246b extends Arithmetic246 {
- public Arithmetic246b(boolean astrict) {
+ public Arithmetic246b(final boolean astrict) {
super(astrict);
}
- public Object selfAdd(Object c, String item) throws IOException {
+ public Object selfAdd(final Object c, final String item) throws IOException {
if (c == null) {
return new ArrayList<String>(Collections.singletonList(item));
}
@@ -576,14 +576,14 @@
run246(new Arithmetic246b(true));
}
- private void run246(JexlArithmetic j246) throws Exception {
- Log log246 = LogFactory.getLog(SideEffectTest.class);
+ private void run246(final JexlArithmetic j246) throws Exception {
+ final Log log246 = LogFactory.getLog(SideEffectTest.class);
// quiesce the logger
- java.util.logging.Logger ll246 = java.util.logging.LogManager.getLogManager().getLogger(SideEffectTest.class.getName());
+ final java.util.logging.Logger ll246 = java.util.logging.LogManager.getLogManager().getLogger(SideEffectTest.class.getName());
// ll246.setLevel(Level.WARNING);
- JexlEngine jexl = new JexlBuilder().arithmetic(j246).cache(32).debug(true).logger(log246).create();
- JexlScript script = jexl.createScript("z += x", "x");
- MapContext ctx = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().arithmetic(j246).cache(32).debug(true).logger(log246).create();
+ final JexlScript script = jexl.createScript("z += x", "x");
+ final MapContext ctx = new MapContext();
List<String> z = new ArrayList<String>(1);
// no ambiguous, std case
@@ -617,20 +617,20 @@
// an arithmetic that performs side effects
public static class Arithmetic248 extends JexlArithmetic {
- public Arithmetic248(boolean strict) {
+ public Arithmetic248(final boolean strict) {
super(strict);
}
- public Object arrayGet(List<?> list, Collection<Integer> range) {
- List<Object> rl = new ArrayList<Object>(range.size());
- for(int i : range) {
+ public Object arrayGet(final List<?> list, final Collection<Integer> range) {
+ final List<Object> rl = new ArrayList<Object>(range.size());
+ for(final int i : range) {
rl.add(list.get(i));
}
return rl;
}
- public Object arraySet(List<Object> list, Collection<Integer> range, Object value) {
- for(int i : range) {
+ public Object arraySet(final List<Object> list, final Collection<Integer> range, final Object value) {
+ for(final int i : range) {
list.set(i, value);
}
return list;
@@ -639,25 +639,25 @@
@Test
public void test248() throws Exception {
- MapContext ctx = new MapContext();
- List<Object> foo = new ArrayList<Object>(Arrays.asList(10, 20, 30, 40));
+ final MapContext ctx = new MapContext();
+ final List<Object> foo = new ArrayList<Object>(Arrays.asList(10, 20, 30, 40));
ctx.set("foo", foo);
- JexlEngine engine = new JexlBuilder().arithmetic(new Arithmetic248(true)).create();
- JexlScript foo12 = engine.createScript("foo[1..2]");
+ final JexlEngine engine = new JexlBuilder().arithmetic(new Arithmetic248(true)).create();
+ final JexlScript foo12 = engine.createScript("foo[1..2]");
try {
- Object r = foo12.execute(ctx);
+ final Object r = foo12.execute(ctx);
Assert.assertEquals(Arrays.asList(20, 30), r);
- } catch (JexlException xp) {
+ } catch (final JexlException xp) {
Assert.assertTrue(xp instanceof JexlException.Property);
}
- JexlScript foo12assign = engine.createScript("foo[1..2] = x", "x");
+ final JexlScript foo12assign = engine.createScript("foo[1..2] = x", "x");
try {
- Object r = foo12assign.execute(ctx, 25);
+ final Object r = foo12assign.execute(ctx, 25);
Assert.assertEquals(25, r);
Assert.assertEquals(Arrays.asList(10, 25, 25, 40), foo);
- } catch (JexlException xp) {
+ } catch (final JexlException xp) {
Assert.assertTrue(xp instanceof JexlException.Property);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/StrategyTest.java b/src/test/java/org/apache/commons/jexl3/StrategyTest.java
index 6660c9e..dd00c1b 100644
--- a/src/test/java/org/apache/commons/jexl3/StrategyTest.java
+++ b/src/test/java/org/apache/commons/jexl3/StrategyTest.java
@@ -38,23 +38,23 @@
// JEXL-174
public static class MapArithmetic extends JexlArithmetic {
- public MapArithmetic(boolean flag) {
+ public MapArithmetic(final boolean flag) {
super(flag);
}
- public Object propertyGet(Map<?,?> map, Object identifier) {
+ public Object propertyGet(final Map<?,?> map, final Object identifier) {
return arrayGet(map, identifier);
}
- public Object propertySet(Map<Object, Object> map, Object identifier, Object value) {
+ public Object propertySet(final Map<Object, Object> map, final Object identifier, final Object value) {
return arraySet(map, identifier, value);
}
- public Object arrayGet(Map<?,?> map, Object identifier) {
+ public Object arrayGet(final Map<?,?> map, final Object identifier) {
return map.get(identifier);
}
- public Object arraySet(Map<Object, Object> map, Object identifier, Object value) {
+ public Object arraySet(final Map<Object, Object> map, final Object identifier, final Object value) {
map.put(identifier, value);
return value;
}
@@ -62,18 +62,18 @@
@Test
public void testRawResolvers() throws Exception {
- Object map = new HashMap<String, Object>();
+ final Object map = new HashMap<String, Object>();
final JexlEngine jexl = new JexlBuilder().create();
- JexlUberspect uberspect = jexl.getUberspect();
- JexlUberspect.PropertyResolver rfieldp = JexlUberspect.JexlResolver.FIELD;
- JexlPropertyGet fget = rfieldp.getPropertyGet(uberspect, map, "key");
+ final JexlUberspect uberspect = jexl.getUberspect();
+ final JexlUberspect.PropertyResolver rfieldp = JexlUberspect.JexlResolver.FIELD;
+ final JexlPropertyGet fget = rfieldp.getPropertyGet(uberspect, map, "key");
Assert.assertNull(fget);
- JexlPropertySet fset = rfieldp.getPropertySet(uberspect, map, "key", "value");
+ final JexlPropertySet fset = rfieldp.getPropertySet(uberspect, map, "key", "value");
Assert.assertNull(fset);
- JexlUberspect.PropertyResolver rmap = JexlUberspect.JexlResolver.MAP;
- JexlPropertyGet mget = rmap.getPropertyGet(uberspect, map, "key");
+ final JexlUberspect.PropertyResolver rmap = JexlUberspect.JexlResolver.MAP;
+ final JexlPropertyGet mget = rmap.getPropertyGet(uberspect, map, "key");
Assert.assertNotNull(mget);
- JexlPropertySet mset = rmap.getPropertySet(uberspect, map, "key", "value");
+ final JexlPropertySet mset = rmap.getPropertySet(uberspect, map, "key", "value");
Assert.assertNotNull(mset);
}
@@ -95,9 +95,9 @@
run171(jexl, false);
}
- public void run171(JexlEngine jexl, boolean std) throws Exception {
+ public void run171(final JexlEngine jexl, final boolean std) throws Exception {
Object result;
- Map<String, Object> i = new HashMap<String, Object>();
+ final Map<String, Object> i = new HashMap<String, Object>();
i.put("class", 42);
result = jexl.createScript("i['class'] ", "i").execute((JexlContext)null, i);
diff --git a/src/test/java/org/apache/commons/jexl3/SynchronizedArithmetic.java b/src/test/java/org/apache/commons/jexl3/SynchronizedArithmetic.java
index c9e42ac..612ba32 100644
--- a/src/test/java/org/apache/commons/jexl3/SynchronizedArithmetic.java
+++ b/src/test/java/org/apache/commons/jexl3/SynchronizedArithmetic.java
@@ -39,7 +39,7 @@
* @param monitor the synchronization monitor
* @param strict whether the arithmetic is strict or not
*/
- protected SynchronizedArithmetic(Monitor monitor, boolean strict) {
+ protected SynchronizedArithmetic(final Monitor monitor, final boolean strict) {
super(strict);
this.monitor = monitor;
}
@@ -60,7 +60,7 @@
* Enter an object monitor.
* @param o the monitored object
*/
- protected void monitorEnter(Object o) {
+ protected void monitorEnter(final Object o) {
enters.incrementAndGet();
}
@@ -68,7 +68,7 @@
* Exits an object monitor.
* @param o the monitored object
*/
- protected void monitorExit(Object o) {
+ protected void monitorExit(final Object o) {
exits.incrementAndGet();
}
@@ -126,7 +126,7 @@
private final Map<Object, Object> monitored = new IdentityHashMap<Object, Object>();
@Override
- protected void monitorEnter(Object o) {
+ protected void monitorEnter(final Object o) {
Object guard;
try {
while (true) {
@@ -143,12 +143,12 @@
guard.wait();
}
}
- } catch (InterruptedException xint) {
+ } catch (final InterruptedException xint) {
// oops
}
}
- @Override protected void monitorExit(Object o) {
+ @Override protected void monitorExit(final Object o) {
final Object guard;
synchronized(monitored) {
guard = monitored.remove(o);
@@ -170,7 +170,7 @@
private final Object monitored;
private Iterator<Object> iterator;
- SynchronizedIterator(Object locked, Iterator<Object> ii) {
+ SynchronizedIterator(final Object locked, final Iterator<Object> ii) {
monitored = locked;
monitor.monitorEnter(monitored);
try {
@@ -201,7 +201,7 @@
if (iterator == null) {
return false;
}
- boolean n = iterator.hasNext();
+ final boolean n = iterator.hasNext();
if (!n) {
close();
}
@@ -231,7 +231,7 @@
* @param key the key
* @return the value associated to the key in the map
*/
- public Object arrayGet(Map<?, ?> map, Object key) {
+ public Object arrayGet(final Map<?, ?> map, final Object key) {
monitor.monitorEnter(map);
try {
return map.get(key);
@@ -246,7 +246,7 @@
* @param key the key
* @param value the value
*/
- public void arraySet(Map<Object, Object> map, Object key, Object value) {
+ public void arraySet(final Map<Object, Object> map, final Object key, final Object value) {
monitor.monitorEnter(map);
try {
map.put(key, value);
@@ -262,7 +262,7 @@
* @param key the key
* @return the value associated to the key in the map
*/
- public Object propertyGet(Map<?, ?> map, Object key) {
+ public Object propertyGet(final Map<?, ?> map, final Object key) {
monitor.monitorEnter(map);
try {
return map.get(key);
@@ -278,7 +278,7 @@
* @param key the key
* @param value the value
*/
- public void propertySet(Map<Object, Object> map, Object key, Object value) {
+ public void propertySet(final Map<Object, Object> map, final Object key, final Object value) {
monitor.monitorEnter(map);
try {
map.put(key, value);
@@ -292,7 +292,7 @@
* @param map the map
* @return the iterator
*/
- public Iterator<Object> forEach(Map<Object, Object> map) {
+ public Iterator<Object> forEach(final Map<Object, Object> map) {
return new SynchronizedIterator(map, map.values().iterator());
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/SynchronizedContext.java b/src/test/java/org/apache/commons/jexl3/SynchronizedContext.java
index b9f9fed..58f15d5 100644
--- a/src/test/java/org/apache/commons/jexl3/SynchronizedContext.java
+++ b/src/test/java/org/apache/commons/jexl3/SynchronizedContext.java
@@ -24,7 +24,7 @@
public class SynchronizedContext extends MapContext implements JexlContext.AnnotationProcessor {
private final JexlContext context;
- public SynchronizedContext(JexlContext ctxt) {
+ public SynchronizedContext(final JexlContext ctxt) {
this.context = ctxt;
}
@@ -34,9 +34,9 @@
* @param script the script
* @return the script value
*/
- public Object call(Object var, JexlScript script) {
- String[] parms = script.getParameters();
- boolean varisarg = parms != null && parms.length == 1;
+ public Object call(final Object var, final JexlScript script) {
+ final String[] parms = script.getParameters();
+ final boolean varisarg = parms != null && parms.length == 1;
if (var == null) {
return varisarg ? script.execute(context, var) : script.execute(context);
} else {
@@ -47,21 +47,21 @@
}
@Override
- public Object get(String name) {
+ public Object get(final String name) {
synchronized (this) {
return super.get(name);
}
}
@Override
- public void set(String name, Object value) {
+ public void set(final String name, final Object value) {
synchronized (this) {
super.set(name, value);
}
}
@Override
- public Object processAnnotation(String name, Object[] args, Callable<Object> statement) throws Exception {
+ public Object processAnnotation(final String name, final Object[] args, final Callable<Object> statement) throws Exception {
if ("synchronized".equals(name)) {
final Object arg = args[0];
synchronized(arg) {
diff --git a/src/test/java/org/apache/commons/jexl3/SynchronizedOverloadsTest.java b/src/test/java/org/apache/commons/jexl3/SynchronizedOverloadsTest.java
index 769da63..7372b93 100644
--- a/src/test/java/org/apache/commons/jexl3/SynchronizedOverloadsTest.java
+++ b/src/test/java/org/apache/commons/jexl3/SynchronizedOverloadsTest.java
@@ -43,35 +43,35 @@
@Test
public void testSynchronizer() throws Exception {
- Map<String, Object> ns = new TreeMap<String, Object>();
+ final Map<String, Object> ns = new TreeMap<String, Object>();
ns.put("synchronized", SynchronizedContext.class);
- JexlContext jc = new MapContext();
- JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
- JexlScript js0 = jexl.createScript("synchronized:call(x, (y)->{y.size()})", "x");
- Object size = js0.execute(jc, "foobar");
+ final JexlContext jc = new MapContext();
+ final JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
+ final JexlScript js0 = jexl.createScript("synchronized:call(x, (y)->{y.size()})", "x");
+ final Object size = js0.execute(jc, "foobar");
Assert.assertEquals(6, size);
}
@Test
public void testSynchronized() throws Exception {
- Map<String, Object> ns = new TreeMap<String, Object>();
- JexlContext jc = new SynchronizedContext(new MapContext());
- JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
- JexlScript js0 = jexl.createScript("@synchronized(y) {return y.size(); }", "y");
- Object size = js0.execute(jc, "foobar");
+ final Map<String, Object> ns = new TreeMap<String, Object>();
+ final JexlContext jc = new SynchronizedContext(new MapContext());
+ final JexlEngine jexl = new JexlBuilder().namespaces(ns).create();
+ final JexlScript js0 = jexl.createScript("@synchronized(y) {return y.size(); }", "y");
+ final Object size = js0.execute(jc, "foobar");
Assert.assertEquals(6, size);
}
@Test
public void testUnsafeMonitor() throws Exception {
- SynchronizedArithmetic.Monitor monitor = new SynchronizedArithmetic.SafeMonitor();
- Map<String, Object> foo = new TreeMap<String, Object>();
+ final SynchronizedArithmetic.Monitor monitor = new SynchronizedArithmetic.SafeMonitor();
+ final Map<String, Object> foo = new TreeMap<String, Object>();
foo.put("one", 1);
foo.put("two", 2);
foo.put("three", 3);
- JexlContext jc = new SynchronizedContext(new MapContext());
- JexlEngine jexl = new JexlBuilder().arithmetic(new SynchronizedArithmetic(monitor, true)).create();
- JexlScript js0 = jexl.createScript("x['four'] = 4; var t = 0.0; for(var z: x) { t += z; }; call(t, (y)->{return y});", "x");
+ final JexlContext jc = new SynchronizedContext(new MapContext());
+ final JexlEngine jexl = new JexlBuilder().arithmetic(new SynchronizedArithmetic(monitor, true)).create();
+ final JexlScript js0 = jexl.createScript("x['four'] = 4; var t = 0.0; for(var z: x) { t += z; }; call(t, (y)->{return y});", "x");
Object t = js0.execute(jc, foo);
Assert.assertEquals(10.0d, t);
Assert.assertTrue(monitor.isBalanced());
diff --git a/src/test/java/org/apache/commons/jexl3/VarTest.java b/src/test/java/org/apache/commons/jexl3/VarTest.java
index d21e2de..e6e1027 100644
--- a/src/test/java/org/apache/commons/jexl3/VarTest.java
+++ b/src/test/java/org/apache/commons/jexl3/VarTest.java
@@ -51,9 +51,9 @@
@Test
public void testStrict() throws Exception {
- JexlEvalContext env = new JexlEvalContext();
- JexlOptions options = env.getEngineOptions();
- JexlContext ctxt = new ReadonlyContext(env, options);
+ final JexlEvalContext env = new JexlEvalContext();
+ final JexlOptions options = env.getEngineOptions();
+ final JexlContext ctxt = new ReadonlyContext(env, options);
options.setStrict(true);
options.setSilent(false);
options.setSafe(false);
@@ -61,53 +61,53 @@
e = JEXL.createScript("x");
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.fail("should have thrown an unknown var exception");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
// ok since we are strict and x does not exist
}
e = JEXL.createScript("x = 42");
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.fail("should have thrown a readonly context exception");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
// ok since we are strict and context is readonly
}
env.set("x", "fourty-two");
e = JEXL.createScript("x.theAnswerToEverything()");
try {
- Object o = e.execute(ctxt);
+ final Object o = e.execute(ctxt);
Assert.fail("should have thrown an unknown method exception");
- } catch(JexlException xjexl) {
+ } catch(final JexlException xjexl) {
// ok since we are strict and method does not exist
}
}
@Test
public void testLocalBasic() throws Exception {
- JexlScript e = JEXL.createScript("var x; x = 42");
- Object o = e.execute(null);
+ final JexlScript e = JEXL.createScript("var x; x = 42");
+ final Object o = e.execute(null);
Assert.assertEquals("Result is not 42", new Integer(42), o);
}
@Test
public void testLocalSimple() throws Exception {
- JexlScript e = JEXL.createScript("var x = 21; x + x");
- Object o = e.execute(null);
+ final JexlScript e = JEXL.createScript("var x = 21; x + x");
+ final Object o = e.execute(null);
Assert.assertEquals("Result is not 42", new Integer(42), o);
}
@Test
public void testLocalFor() throws Exception {
- JexlScript e = JEXL.createScript("var y = 0; for(var x : [5, 17, 20]) { y = y + x; } y;");
- Object o = e.execute(null);
+ final JexlScript e = JEXL.createScript("var y = 0; for(var x : [5, 17, 20]) { y = y + x; } y;");
+ final Object o = e.execute(null);
Assert.assertEquals("Result is not 42", new Integer(42), o);
}
public static class NumbersContext extends MapContext implements JexlContext.NamespaceResolver {
@Override
- public Object resolveNamespace(String name) {
+ public Object resolveNamespace(final String name) {
return name == null ? this : null;
}
@@ -118,17 +118,17 @@
@Test
public void testLocalForFunc() throws Exception {
- JexlContext jc = new NumbersContext();
- JexlScript e = JEXL.createScript("var y = 0; for(var x : numbers()) { y = y + x; } y;");
- Object o = e.execute(jc);
+ final JexlContext jc = new NumbersContext();
+ final JexlScript e = JEXL.createScript("var y = 0; for(var x : numbers()) { y = y + x; } y;");
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not 42", new Integer(42), o);
}
@Test
public void testLocalForFuncReturn() throws Exception {
- JexlContext jc = new NumbersContext();
- JexlScript e = JEXL.createScript("var y = 42; for(var x : numbers()) { if (x > 10) return x } y;");
- Object o = e.execute(jc);
+ final JexlContext jc = new NumbersContext();
+ final JexlScript e = JEXL.createScript("var y = 42; for(var x : numbers()) { if (x > 10) return x } y;");
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is not 17", new Integer(17), o);
Assert.assertTrue(toString(e.getVariables()), e.getVariables().isEmpty());
@@ -139,10 +139,10 @@
* @param refs the variable reference set
* @return the string representation
*/
- String toString(Set<List<String>> refs) {
- StringBuilder strb = new StringBuilder("{");
+ String toString(final Set<List<String>> refs) {
+ final StringBuilder strb = new StringBuilder("{");
int r = 0;
- for (List<String> strs : refs) {
+ for (final List<String> strs : refs) {
if (r++ > 0) {
strb.append(", ");
}
@@ -166,9 +166,9 @@
* @param refs the variable reference set
* @return the set of variables
*/
- Set<List<String>> mkref(String[][] refs) {
- Set<List<String>> set = new HashSet<List<String>>();
- for(String[] ref : refs) {
+ Set<List<String>> mkref(final String[][] refs) {
+ final Set<List<String>> set = new HashSet<List<String>>();
+ for(final String[] ref : refs) {
set.add(Arrays.asList(ref));
}
return set;
@@ -180,15 +180,15 @@
* @param rhs the right set
* @return true if equal, false otherwise
*/
- boolean eq(Set<List<String>> lhs, Set<List<String>> rhs) {
+ boolean eq(final Set<List<String>> lhs, final Set<List<String>> rhs) {
if (lhs.size() != rhs.size()) {
return false;
}
- List<String> llhs = stringify(lhs);
- List<String> lrhs = stringify(rhs);
+ final List<String> llhs = stringify(lhs);
+ final List<String> lrhs = stringify(rhs);
for(int s = 0; s < llhs.size(); ++s) {
- String l = llhs.get(s);
- String r = lrhs.get(s);
+ final String l = llhs.get(s);
+ final String r = lrhs.get(s);
if (!l.equals(r)) {
return false;
}
@@ -196,11 +196,11 @@
return true;
}
- List<String> stringify(Set<List<String>> sls) {
- List<String> ls = new ArrayList<String>();
- for(List<String> l : sls) {
- StringBuilder strb = new StringBuilder();
- for(String s : l) {
+ List<String> stringify(final Set<List<String>> sls) {
+ final List<String> ls = new ArrayList<String>();
+ for(final List<String> l : sls) {
+ final StringBuilder strb = new StringBuilder();
+ for(final String s : l) {
strb.append(s);
strb.append('|');
}
@@ -333,7 +333,7 @@
JexlScript e;
Set<List<String>> vars;
Set<List<String>> expect;
- JexlEngine jexl = new JexlBuilder().strict(true).silent(false).cache(32).collectAll(false).create();
+ final JexlEngine jexl = new JexlBuilder().strict(true).silent(false).cache(32).collectAll(false).create();
e = jexl.createScript("a['b'][c]");
vars = e.getVariables();
@@ -366,9 +366,9 @@
JexlScript e;
// x is a parameter, y a context variable, z a local variable
e = JEXL.createScript("if (x) { y } else { var z = 2 * x}", "x");
- Set<List<String>> vars = e.getVariables();
- String[] parms = e.getParameters();
- String[] locals = e.getLocalVariables();
+ final Set<List<String>> vars = e.getVariables();
+ final String[] parms = e.getParameters();
+ final String[] locals = e.getLocalVariables();
Assert.assertTrue(eq(mkref(new String[][]{{"y"}}), vars));
Assert.assertEquals(1, parms.length);
@@ -383,10 +383,10 @@
public static class VarDate {
private final Calendar cal;
- public VarDate(String date) throws Exception {
+ public VarDate(final String date) throws Exception {
this(SDF.parse(date));
}
- public VarDate(Date date) {
+ public VarDate(final Date date) {
cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
cal.setTime(date);
cal.setLenient(true);
@@ -397,7 +397,7 @@
* @param property yyyy or MM or dd
* @return the string representation of year, month or day
*/
- public String get(String property) {
+ public String get(final String property) {
if ("yyyy".equals(property)) {
return Integer.toString(cal.get(Calendar.YEAR));
}
@@ -416,7 +416,7 @@
* @param keys the property names
* @return the property values
*/
- public List<String> get(String[] keys) {
+ public List<String> get(final String[] keys) {
return get(Arrays.asList(keys));
}
@@ -425,10 +425,10 @@
* @param keys the property names
* @return the property values
*/
- public List<String> get(List<String> keys) {
- List<String> values = new ArrayList<String>();
- for(String key : keys) {
- String value = get(key);
+ public List<String> get(final List<String> keys) {
+ final List<String> values = new ArrayList<String>();
+ for(final String key : keys) {
+ final String value = get(key);
if (value != null) {
values.add(value);
}
@@ -443,10 +443,10 @@
* @param map a map of property name to alias
* @return the alia map
*/
- public Map<String,Object> get(Map<String,String> map) {
- Map<String,Object> values = new LinkedHashMap<String,Object>();
- for(Map.Entry<String,String> entry : map.entrySet()) {
- String value = get(entry.getKey());
+ public Map<String,Object> get(final Map<String,String> map) {
+ final Map<String,Object> values = new LinkedHashMap<String,Object>();
+ for(final Map.Entry<String,String> entry : map.entrySet()) {
+ final String value = get(entry.getKey());
if (value != null) {
values.put(entry.getValue(), value);
}
@@ -460,13 +460,13 @@
* @param str the stringified source
* @return the properties array
*/
- private static String[] readIdentifiers(String str) {
- List<String> ids = new ArrayList<String>();
+ private static String[] readIdentifiers(final String str) {
+ final List<String> ids = new ArrayList<String>();
StringBuilder strb = null;
String id = null;
char kind = 0; // array, set or map kind using first char
for (int i = 0; i < str.length(); ++i) {
- char c = str.charAt(i);
+ final char c = str.charAt(i);
// strb != null when array,set or map deteced
if (strb == null) {
if (c == '{' || c == '(' || c == '[') {
@@ -485,7 +485,7 @@
}
else if (c == '\'' || c == '"') {
strb.append(c);
- int l = JexlParser.readString(strb, str, i + 1, c);
+ final int l = JexlParser.readString(strb, str, i + 1, c);
if (l > 0) {
id = strb.substring(1, strb.length() - 1);
strb.delete(0, l + 1);
@@ -499,13 +499,13 @@
@Test
public void testReferenceLiteral() throws Exception {
- JexlEngine jexld = new JexlBuilder().collectMode(2).create();
+ final JexlEngine jexld = new JexlBuilder().collectMode(2).create();
JexlScript script;
List<String> result;
Set<List<String>> vars;
// in collectAll mode, the collector grabs all syntactic variations of
// constant variable references including map/arry/set literals
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
//d.yyyy = 1969; d.MM = 7; d.dd = 20
ctxt.set("moon.landing", new VarDate("1969-07-20"));
@@ -521,7 +521,7 @@
Assert.assertArrayEquals(new String[]{"yyyy", "MM", "dd"}, readIdentifiers(var.get(2)));
script = jexld.createScript("moon.landing[ { 'yyyy' : 'year', 'MM' : 'month', 'dd' : 'day' } ]");
- Map<String, String> mapr = (Map<String, String>) script.execute(ctxt);
+ final Map<String, String> mapr = (Map<String, String>) script.execute(ctxt);
Assert.assertEquals(3, mapr.size());
Assert.assertEquals("1969", mapr.get("year"));
Assert.assertEquals("7", mapr.get("month"));
@@ -586,8 +586,8 @@
@Test
public void testSyntacticVariations() throws Exception {
- JexlScript script = JEXL.createScript("sum(TOTAL) - partial.sum() + partial['sub'].avg() - sum(partial.sub)");
- Set<List<String>> vars = script.getVariables();
+ final JexlScript script = JEXL.createScript("sum(TOTAL) - partial.sum() + partial['sub'].avg() - sum(partial.sub)");
+ final Set<List<String>> vars = script.getVariables();
Assert.assertEquals(3, vars.size());
}
@@ -596,11 +596,11 @@
private int x;
private String color;
- public void setX(int x) {
+ public void setX(final int x) {
this.x = x;
}
- public void setColor(String color) {
+ public void setColor(final String color) {
this.color = color;
}
@@ -615,8 +615,8 @@
@Test
public void testObjectContext() throws Exception {
- TheVarContext vars = new TheVarContext();
- JexlContext jc = new ObjectContext<TheVarContext>(JEXL, vars);
+ final TheVarContext vars = new TheVarContext();
+ final JexlContext jc = new ObjectContext<TheVarContext>(JEXL, vars);
try {
JexlScript script;
Object result;
@@ -637,7 +637,7 @@
result = script.execute(jc);
Assert.assertTrue((Boolean) result);
Assert.assertTrue(jc.has("color"));
- } catch (JexlException.Method ambiguous) {
+ } catch (final JexlException.Method ambiguous) {
Assert.fail("total() is solvable");
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/WhileTest.java b/src/test/java/org/apache/commons/jexl3/WhileTest.java
index 61909c7..79ae428 100644
--- a/src/test/java/org/apache/commons/jexl3/WhileTest.java
+++ b/src/test/java/org/apache/commons/jexl3/WhileTest.java
@@ -32,31 +32,31 @@
@Test
public void testSimpleWhileFalse() throws Exception {
- JexlScript e = JEXL.createScript("while (false) ;");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("while (false) ;");
+ final JexlContext jc = new MapContext();
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertNull("Result is not null", o);
}
@Test
public void testWhileExecutesExpressionWhenLooping() throws Exception {
- JexlScript e = JEXL.createScript("while (x < 10) x = x + 1;");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("while (x < 10) x = x + 1;");
+ final JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is wrong", new Integer(10), o);
}
@Test
public void testWhileWithBlock() throws Exception {
- JexlScript e = JEXL.createScript("while (x < 10) { x = x + 1; y = y * 2; }");
- JexlContext jc = new MapContext();
+ final JexlScript e = JEXL.createScript("while (x < 10) { x = x + 1; y = y * 2; }");
+ final JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
jc.set("y", new Integer(1));
- Object o = e.execute(jc);
+ final Object o = e.execute(jc);
Assert.assertEquals("Result is wrong", new Integer(512), o);
Assert.assertEquals("x is wrong", new Integer(10), jc.get("x"));
Assert.assertEquals("y is wrong", new Integer(512), jc.get("y"));
diff --git a/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java b/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java
index c8dc705..f75adad 100644
--- a/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java
+++ b/src/test/java/org/apache/commons/jexl3/examples/ArrayTest.java
@@ -36,20 +36,20 @@
/**
* An example for array access.
*/
- static void example(Output out) throws Exception {
+ static void example(final Output out) throws Exception {
/*
* First step is to retrieve an instance of a JexlEngine;
* it might be already existing and shared or created anew.
*/
- JexlEngine jexl = new JexlBuilder().create();
+ final JexlEngine jexl = new JexlBuilder().create();
/*
* Second make a jexlContext and put stuff in it
*/
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
- List<Object> l = new ArrayList<Object>();
+ final List<Object> l = new ArrayList<Object>();
l.add("Hello from location 0");
- Integer two = 2;
+ final Integer two = 2;
l.add(two);
jc.set("array", l);
@@ -77,7 +77,7 @@
* @param args command line arguments
* @throws Exception cos jexl does.
*/
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
example(Output.SYSTEM);
}
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java b/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java
index a2b8a63..81a1ab0 100644
--- a/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java
+++ b/src/test/java/org/apache/commons/jexl3/examples/MethodPropertyTest.java
@@ -38,17 +38,17 @@
* First step is to retrieve an instance of a JexlEngine;
* it might be already existing and shared or created anew.
*/
- JexlEngine jexl = new JexlBuilder().create();
+ final JexlEngine jexl = new JexlBuilder().create();
/*
* Second make a jexlContext and put stuff in it
*/
- JexlContext jc = new MapContext();
+ final JexlContext jc = new MapContext();
/*
* The Java equivalents of foo and number for comparison and checking
*/
- Foo foo = new Foo();
- Integer number = 10;
+ final Foo foo = new Foo();
+ final Integer number = 10;
jc.set("foo", foo);
jc.set("number", number);
@@ -101,7 +101,7 @@
* @param arg property name.
* @return arg prefixed with 'This is the property '.
*/
- public String get(String arg) {
+ public String get(final String arg) {
return "This is the property " + arg;
}
@@ -110,7 +110,7 @@
* @param i a long.
* @return The argument prefixed with 'The value is : '
*/
- public String convert(long i) {
+ public String convert(final long i) {
return "The value is : " + i;
}
}
@@ -130,7 +130,7 @@
* @param args command line arguments
* @throws Exception cos jexl does.
*/
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
example(Output.SYSTEM);
}
}
\ No newline at end of file
diff --git a/src/test/java/org/apache/commons/jexl3/examples/Output.java b/src/test/java/org/apache/commons/jexl3/examples/Output.java
index 826ee7b..2df4527 100644
--- a/src/test/java/org/apache/commons/jexl3/examples/Output.java
+++ b/src/test/java/org/apache/commons/jexl3/examples/Output.java
@@ -43,7 +43,7 @@
*/
public static final Output JUNIT = new Output() {
@Override
- public void print(String expr, Object actual, Object expected) {
+ public void print(final String expr, final Object actual, final Object expected) {
Assert.assertEquals(expr, expected, actual);
}
};
@@ -54,7 +54,7 @@
*/
public static final Output SYSTEM = new Output() {
@Override
- public void print(String expr, Object actual, Object expected) {
+ public void print(final String expr, final Object actual, final Object expected) {
System.out.print(expr);
System.out.println(actual);
}
diff --git a/src/test/java/org/apache/commons/jexl3/internal/Dumper.java b/src/test/java/org/apache/commons/jexl3/internal/Dumper.java
index fec13d7..f539ee9 100644
--- a/src/test/java/org/apache/commons/jexl3/internal/Dumper.java
+++ b/src/test/java/org/apache/commons/jexl3/internal/Dumper.java
@@ -25,7 +25,7 @@
* Utility to dump AST, useful in debug sessions.
*/
public class Dumper {
- private StringBuilder strb = new StringBuilder();
+ private final StringBuilder strb = new StringBuilder();
private int indent = 0;
private void indent() {
@@ -34,7 +34,7 @@
}
}
- private void dump(JexlNode node, Object data) {
+ private void dump(final JexlNode node, final Object data) {
final int num = node.jjtGetNumChildren();
indent();
strb.append(node.getClass().getSimpleName());
@@ -48,7 +48,7 @@
strb.append('(');
indent += 1;
for (int c = 0; c < num; ++c) {
- JexlNode child = node.jjtGetChild(c);
+ final JexlNode child = node.jjtGetChild(c);
if (c > 0) {
strb.append(',');
}
@@ -63,7 +63,7 @@
strb.append(')');
}
- private Dumper(JexlScript script) {
+ private Dumper(final JexlScript script) {
dump(((Script) script).script, null);
}
@@ -72,7 +72,7 @@
return strb.toString();
}
- public static String toString(JexlScript script) {
+ public static String toString(final JexlScript script) {
return new Dumper(script).toString();
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java b/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
index 2369361..8bdf1c5 100644
--- a/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
+++ b/src/test/java/org/apache/commons/jexl3/internal/RangeTest.java
@@ -49,8 +49,8 @@
super.tearDown();
}
- private void checkIteration(LongRange lr, long first, long last) throws Exception {
- Iterator<Long> ii = lr.iterator();
+ private void checkIteration(final LongRange lr, final long first, final long last) throws Exception {
+ final Iterator<Long> ii = lr.iterator();
if (ii.hasNext()) {
long l = ii.next();
Assert.assertEquals(first, l);
@@ -63,8 +63,8 @@
}
}
- private void checkIteration(IntegerRange ir, int first, int last) throws Exception {
- Iterator<Integer> ii = ir.iterator();
+ private void checkIteration(final IntegerRange ir, final int first, final int last) throws Exception {
+ final Iterator<Integer> ii = ir.iterator();
if (ii.hasNext()) {
int l = ii.next();
Assert.assertEquals(first, l);
@@ -79,7 +79,7 @@
@Test
public void testRanges() throws Exception {
- LongRange lr0 = LongRange.create(20,10);
+ final LongRange lr0 = LongRange.create(20,10);
Assert.assertEquals(10L, lr0.getMin());
Assert.assertEquals(20L, lr0.getMax());
Assert.assertFalse(lr0.isEmpty());
@@ -89,14 +89,14 @@
Assert.assertFalse(lr0.contains(5L));
Assert.assertFalse(lr0.contains(null));
checkIteration(lr0, 20L, 10L);
- LongRange lr1 = LongRange.create(10,20);
+ final LongRange lr1 = LongRange.create(10,20);
checkIteration(lr1, 10L, 20L);
Assert.assertTrue(lr0.containsAll(lr1));
- LongRange lr2 = LongRange.create(10,15);
+ final LongRange lr2 = LongRange.create(10,15);
Assert.assertNotEquals(lr0, lr2);
Assert.assertTrue(lr0.containsAll(lr2));
Assert.assertFalse(lr2.containsAll(lr1));
- IntegerRange ir0 = IntegerRange.create(20,10);
+ final IntegerRange ir0 = IntegerRange.create(20,10);
checkIteration(ir0, 20, 10);
Assert.assertEquals(10, ir0.getMin());
Assert.assertEquals(20, ir0.getMax());
@@ -106,20 +106,20 @@
Assert.assertFalse(ir0.contains(30));
Assert.assertFalse(ir0.contains(5));
Assert.assertFalse(ir0.contains(null));
- IntegerRange ir1 = IntegerRange.create(10,20);
+ final IntegerRange ir1 = IntegerRange.create(10,20);
checkIteration(ir1, 10, 20);
Assert.assertTrue(ir0.containsAll(ir1));
Assert.assertNotEquals(ir0, lr0);
Assert.assertNotEquals(ir1, lr1);
- IntegerRange ir2 = IntegerRange.create(10,15);
+ final IntegerRange ir2 = IntegerRange.create(10,15);
Assert.assertNotEquals(ir0, ir2);
Assert.assertTrue(ir0.containsAll(ir2));
Assert.assertFalse(ir2.containsAll(ir1));
long lc0 = 20;
- Iterator<Long> il0 = lr0.iterator();
+ final Iterator<Long> il0 = lr0.iterator();
while(il0.hasNext()) {
- long v0 = il0.next();
+ final long v0 = il0.next();
Assert.assertEquals(lc0, v0);
try {
switch((int)v0) {
@@ -130,7 +130,7 @@
case 14: lr1.removeAll(Collections.singletonList(v0)); Assert.fail(); break;
case 15: lr1.retainAll(Collections.singletonList(v0)); Assert.fail(); break;
}
- } catch(UnsupportedOperationException xuo) {
+ } catch(final UnsupportedOperationException xuo) {
// ok
}
lc0 -= 1;
@@ -139,14 +139,14 @@
try {
il0.next();
Assert.fail();
- } catch(NoSuchElementException xns) {
+ } catch(final NoSuchElementException xns) {
// ok
}
int ic0 = 20;
- Iterator<Integer> ii0 = ir0.iterator();
+ final Iterator<Integer> ii0 = ir0.iterator();
while(ii0.hasNext()) {
- int v0 = ii0.next();
+ final int v0 = ii0.next();
Assert.assertEquals(ic0, v0);
try {
switch(v0) {
@@ -157,7 +157,7 @@
case 14: ir1.removeAll(Collections.singletonList(v0)); Assert.fail(); break;
case 15: ir1.retainAll(Collections.singletonList(v0)); Assert.fail(); break;
}
- } catch(UnsupportedOperationException xuo) {
+ } catch(final UnsupportedOperationException xuo) {
// ok
}
ic0 -= 1;
@@ -166,7 +166,7 @@
try {
ii0.next();
Assert.fail();
- } catch(NoSuchElementException xns) {
+ } catch(final NoSuchElementException xns) {
// ok
}
diff --git a/src/test/java/org/apache/commons/jexl3/internal/Util.java b/src/test/java/org/apache/commons/jexl3/internal/Util.java
index b77056c..6b9f31f 100644
--- a/src/test/java/org/apache/commons/jexl3/internal/Util.java
+++ b/src/test/java/org/apache/commons/jexl3/internal/Util.java
@@ -36,39 +36,39 @@
* testing them for equality with the origin.
* @throws Exception
*/
- public static void debuggerCheck(JexlEngine ijexl) throws Exception {
- Engine jexl = (Engine) ijexl;
+ public static void debuggerCheck(final JexlEngine ijexl) throws Exception {
+ final Engine jexl = (Engine) ijexl;
// without a cache, nothing to check
if (jexl == null || jexl.cache == null) {
return;
}
- Engine jdbg = new Engine();
+ final Engine jdbg = new Engine();
jdbg.parser.allowRegisters(true);
- Debugger dbg = new Debugger();
+ final Debugger dbg = new Debugger();
// iterate over all expression in
- for (Map.Entry<Source, ASTJexlScript> entry : jexl.cache.entries()) {
- JexlNode node = entry.getValue();
+ for (final Map.Entry<Source, ASTJexlScript> entry : jexl.cache.entries()) {
+ final JexlNode node = entry.getValue();
// recreate expr string from AST
dbg.debug(node);
- String expressiondbg = dbg.toString();
- JexlFeatures features = entry.getKey().getFeatures();
+ final String expressiondbg = dbg.toString();
+ final JexlFeatures features = entry.getKey().getFeatures();
// recreate expr from string
try {
- Script exprdbg = jdbg.createScript(features, null, expressiondbg, null);
+ final Script exprdbg = jdbg.createScript(features, null, expressiondbg, null);
// make arg cause become the root cause
JexlNode root = exprdbg.script;
while (root.jjtGetParent() != null) {
root = root.jjtGetParent();
}
// test equality
- String reason = checkEquals(root, node);
+ final String reason = checkEquals(root, node);
if (reason != null) {
throw new RuntimeException("check equal failed: "
+ expressiondbg
+ " /**** " + reason + " **** */ "
+ entry.getKey());
}
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
throw new RuntimeException("check parse failed: "
+ expressiondbg
+ " /*********/ "
@@ -83,8 +83,8 @@
* @param node the script to flatten
* @return the descendants-and-self list
*/
- protected static ArrayList<JexlNode> flatten(JexlNode node) {
- ArrayList<JexlNode> list = new ArrayList<JexlNode>();
+ protected static ArrayList<JexlNode> flatten(final JexlNode node) {
+ final ArrayList<JexlNode> list = new ArrayList<JexlNode>();
flatten(list, node);
return list;
}
@@ -94,8 +94,8 @@
* @param list the list of descendants to add to
* @param node the script & descendants to add
*/
- private static void flatten(List<JexlNode> list, JexlNode node) {
- int nc = node.jjtGetNumChildren();
+ private static void flatten(final List<JexlNode> list, final JexlNode node) {
+ final int nc = node.jjtGetNumChildren();
list.add(node);
for (int c = 0; c < nc; ++c) {
flatten(list, node.jjtGetChild(c));
@@ -111,8 +111,8 @@
*/
private static String checkEquals(JexlNode lhs, JexlNode rhs) {
if (lhs != rhs) {
- ArrayList<JexlNode> lhsl = flatten(lhs);
- ArrayList<JexlNode> rhsl = flatten(rhs);
+ final ArrayList<JexlNode> lhsl = flatten(lhs);
+ final ArrayList<JexlNode> rhsl = flatten(rhs);
if (lhsl.size() != rhsl.size()) {
return "size: " + lhsl.size() + " != " + rhsl.size();
}
@@ -122,8 +122,8 @@
if (lhs.getClass() != rhs.getClass()) {
return "class: " + lhs.getClass() + " != " + rhs.getClass();
}
- String lhss = lhs.toString();
- String rhss = rhs.toString();
+ final String lhss = lhs.toString();
+ final String rhss = rhs.toString();
if ((lhss == null && rhss != null)
|| (lhss != null && rhss == null)) {
return "image: " + lhss + " != " + rhss;
@@ -141,12 +141,12 @@
* @param e the script
* @return an indented version of the AST
*/
- protected static String flattenedStr(JexlScript e) {
+ protected static String flattenedStr(final JexlScript e) {
return "";//e.getText() + "\n" + flattenedStr(((Script)e).script);
}
private static String indent(JexlNode node) {
- StringBuilder strb = new StringBuilder();
+ final StringBuilder strb = new StringBuilder();
while (node != null) {
strb.append(" ");
node = node.jjtGetParent();
@@ -154,13 +154,13 @@
return strb.toString();
}
- private String flattenedStr(JexlNode node) {
- ArrayList<JexlNode> flattened = flatten(node);
- StringBuilder strb = new StringBuilder();
- for (JexlNode flat : flattened) {
+ private String flattenedStr(final JexlNode node) {
+ final ArrayList<JexlNode> flattened = flatten(node);
+ final StringBuilder strb = new StringBuilder();
+ for (final JexlNode flat : flattened) {
strb.append(indent(flat));
strb.append(flat.getClass().getSimpleName());
- String sflat = flat.toString();
+ final String sflat = flat.toString();
if (sflat != null) {
strb.append(" = ");
strb.append(sflat);
diff --git a/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java b/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java
index 3cabcfb..816cc47 100644
--- a/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java
+++ b/src/test/java/org/apache/commons/jexl3/internal/introspection/DiscoveryTest.java
@@ -44,12 +44,12 @@
private String value;
private String eulav;
- public Duck(String v, String e) {
+ public Duck(final String v, final String e) {
value = v;
eulav = e;
}
- public String get(String prop) {
+ public String get(final String prop) {
if ("value".equals(prop)) {
return value;
}
@@ -59,7 +59,7 @@
return "no such property";
}
- public void set(String prop, String v) {
+ public void set(final String prop, final String v) {
if ("value".equals(prop)) {
value = v;
} else if ("eulav".equals(prop)) {
@@ -73,7 +73,7 @@
private String eulav;
private boolean flag;
- public Bean(String v, String e) {
+ public Bean(final String v, final String e) {
value = v;
eulav = e;
flag = true;
@@ -83,7 +83,7 @@
return value;
}
- public void setValue(String v) {
+ public void setValue(final String v) {
value = v;
}
@@ -91,7 +91,7 @@
return eulav;
}
- public void setEulav(String v) {
+ public void setEulav(final String v) {
eulav = v;
}
@@ -99,18 +99,18 @@
return flag;
}
- public void setFlag(boolean f) {
+ public void setFlag(final boolean f) {
flag = f;
}
}
@Test
public void testBeanIntrospection() throws Exception {
- Uberspect uber = Engine.getUberspect(null, null);
- Bean bean = new Bean("JEXL", "LXEJ");
+ final Uberspect uber = Engine.getUberspect(null, null);
+ final Bean bean = new Bean("JEXL", "LXEJ");
- JexlPropertyGet get = uber.getPropertyGet(bean, "value");
- JexlPropertySet set = uber.getPropertySet(bean, "value", "foo");
+ final JexlPropertyGet get = uber.getPropertyGet(bean, "value");
+ final JexlPropertySet set = uber.getPropertySet(bean, "value", "foo");
Assert.assertTrue("bean property getter", get instanceof PropertyGetExecutor);
Assert.assertTrue("bean property setter", set instanceof PropertySetExecutor);
// introspector and uberspect should return same result
@@ -120,12 +120,12 @@
Assert.assertNotEquals(get, uber.getPropertyGet(bean, "eulav"));
Assert.assertNotEquals(set, uber.getPropertySet(bean, "eulav", "foo"));
// setter returns argument
- Object bar = set.invoke(bean, "bar");
+ final Object bar = set.invoke(bean, "bar");
Assert.assertEquals("bar", bar);
// getter should return last value
Assert.assertEquals("bar", get.invoke(bean));
// tryExecute should succeed on same property
- Object quux = set.tryInvoke(bean, "value", "quux");
+ final Object quux = set.tryInvoke(bean, "value", "quux");
Assert.assertEquals("quux", quux);
Assert.assertEquals("quux", get.invoke(bean));
// tryExecute should fail on different property
@@ -135,11 +135,11 @@
@Test
public void testDuckIntrospection() throws Exception {
- Uberspect uber = Engine.getUberspect(null, null);
- Duck duck = new Duck("JEXL", "LXEJ");
+ final Uberspect uber = Engine.getUberspect(null, null);
+ final Duck duck = new Duck("JEXL", "LXEJ");
- JexlPropertyGet get = uber.getPropertyGet(duck, "value");
- JexlPropertySet set = uber.getPropertySet(duck, "value", "foo");
+ final JexlPropertyGet get = uber.getPropertyGet(duck, "value");
+ final JexlPropertySet set = uber.getPropertySet(duck, "value", "foo");
Assert.assertTrue("duck property getter", get instanceof DuckGetExecutor);
Assert.assertTrue("duck property setter", set instanceof DuckSetExecutor);
// introspector and uberspect should return same result
@@ -149,12 +149,12 @@
Assert.assertNotEquals(get, uber.getPropertyGet(duck, "eulav"));
Assert.assertNotEquals(set, uber.getPropertySet(duck, "eulav", "foo"));
// setter returns argument
- Object bar = set.invoke(duck, "bar");
+ final Object bar = set.invoke(duck, "bar");
Assert.assertEquals("bar", bar);
// getter should return last value
Assert.assertEquals("bar", get.invoke(duck));
// tryExecute should succeed on same property
- Object quux = set.tryInvoke(duck, "value", "quux");
+ final Object quux = set.tryInvoke(duck, "value", "quux");
Assert.assertEquals("quux", quux);
Assert.assertEquals("quux", get.invoke(duck));
// tryExecute should fail on different property
@@ -163,13 +163,13 @@
@Test
public void testListIntrospection() throws Exception {
- Uberspect uber = Engine.getUberspect(null, null);
- List<Object> list = new ArrayList<Object>();
+ final Uberspect uber = Engine.getUberspect(null, null);
+ final List<Object> list = new ArrayList<Object>();
list.add("LIST");
list.add("TSIL");
- JexlPropertyGet get = uber.getPropertyGet(list, 1);
- JexlPropertySet set = uber.getPropertySet(list, 1, "foo");
+ final JexlPropertyGet get = uber.getPropertyGet(list, 1);
+ final JexlPropertySet set = uber.getPropertySet(list, 1, "foo");
Assert.assertTrue("list property getter", get instanceof ListGetExecutor);
Assert.assertTrue("list property setter", set instanceof ListSetExecutor);
// introspector and uberspect should return same result
@@ -179,12 +179,12 @@
Assert.assertNotEquals(get, uber.getPropertyGet(list, 0));
Assert.assertNotEquals(get, uber.getPropertySet(list, 0, "foo"));
// setter returns argument
- Object bar = set.invoke(list, "bar");
+ final Object bar = set.invoke(list, "bar");
Assert.assertEquals("bar", bar);
// getter should return last value
Assert.assertEquals("bar", get.invoke(list));
// tryExecute should succeed on integer property
- Object quux = set.tryInvoke(list, 1, "quux");
+ final Object quux = set.tryInvoke(list, 1, "quux");
Assert.assertEquals("quux", quux);
// getter should return last value
Assert.assertEquals("quux", get.invoke(list));
@@ -194,13 +194,13 @@
@Test
public void testMapIntrospection() throws Exception {
- Uberspect uber = Engine.getUberspect(null, null);
- Map<String, Object> map = new HashMap<String, Object>();
+ final Uberspect uber = Engine.getUberspect(null, null);
+ final Map<String, Object> map = new HashMap<String, Object>();
map.put("value", "MAP");
map.put("eulav", "PAM");
- JexlPropertyGet get = uber.getPropertyGet(map, "value");
- JexlPropertySet set = uber.getPropertySet(map, "value", "foo");
+ final JexlPropertyGet get = uber.getPropertyGet(map, "value");
+ final JexlPropertySet set = uber.getPropertySet(map, "value", "foo");
Assert.assertTrue("map property getter", get instanceof MapGetExecutor);
Assert.assertTrue("map property setter", set instanceof MapSetExecutor);
// introspector and uberspect should return same result
@@ -210,12 +210,12 @@
Assert.assertNotEquals(get, uber.getPropertyGet(map, "eulav"));
Assert.assertNotEquals(get, uber.getPropertySet(map, "eulav", "foo"));
// setter returns argument
- Object bar = set.invoke(map, "bar");
+ final Object bar = set.invoke(map, "bar");
Assert.assertEquals("bar", bar);
// getter should return last value
Assert.assertEquals("bar", get.invoke(map));
// tryExecute should succeed on same property class
- Object quux = set.tryInvoke(map, "value", "quux");
+ final Object quux = set.tryInvoke(map, "value", "quux");
Assert.assertEquals("quux", quux);
// getter should return last value
Assert.assertEquals("quux", get.invoke(map));
@@ -224,45 +224,45 @@
}
public static class Bulgroz {
- public Object list(int x) {
+ public Object list(final int x) {
return 0;
}
- public Object list(String x) {
+ public Object list(final String x) {
return 1;
}
- public Object list(Object x) {
+ public Object list(final Object x) {
return 2;
}
- public Object list(int x, Object...y) {
+ public Object list(final int x, final Object...y) {
return 3;
}
- public Object list(int x, int y) {
+ public Object list(final int x, final int y) {
return 4;
}
- public Object list(String x, Object...y) {
+ public Object list(final String x, final Object...y) {
return 5;
}
- public Object list(String x, String y) {
+ public Object list(final String x, final String y) {
return 6;
}
- public Object list(Object x, Object...y) {
+ public Object list(final Object x, final Object...y) {
return 7;
}
- public Object list(Object x, Object y) {
+ public Object list(final Object x, final Object y) {
return 8;
}
- public Object amb(Serializable x) {
+ public Object amb(final Serializable x) {
return -1;
}
- public Object amb(Number x) {
+ public Object amb(final Number x) {
return -2;
}
}
@Test
public void testMethodIntrospection() throws Exception {
- Uberspect uber = new Uberspect(null, null);
- Bulgroz bulgroz = new Bulgroz();
+ final Uberspect uber = new Uberspect(null, null);
+ final Bulgroz bulgroz = new Bulgroz();
JexlMethod jmethod;
Object result;
jmethod = uber.getMethod(bulgroz, "list", 0);
diff --git a/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java b/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java
index 1aece52..c3e3fd2 100644
--- a/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java
+++ b/src/test/java/org/apache/commons/jexl3/internal/introspection/MethodKeyTest.java
@@ -82,9 +82,9 @@
private static final MethodKey[] KEY_LIST;
/** * Creates & inserts a key into the BY_KEY & byString map */
- private static void setUpKey(String name, Class<?>[] parms) {
- MethodKey key = new MethodKey(name, parms);
- String str = key.toString();
+ private static void setUpKey(final String name, final Class<?>[] parms) {
+ final MethodKey key = new MethodKey(name, parms);
+ final String str = key.toString();
BY_KEY.put(key, str);
BY_STRING.put(str, key);
@@ -94,15 +94,15 @@
static {
BY_KEY = new java.util.HashMap< MethodKey, String>();
BY_STRING = new java.util.HashMap<String, MethodKey>();
- for (String method : METHODS) {
- for (Class<?> value : PRIMS) {
- Class<?>[] arg0 = {value};
+ for (final String method : METHODS) {
+ for (final Class<?> value : PRIMS) {
+ final Class<?>[] arg0 = {value};
setUpKey(method, arg0);
- for (Class<?> aClass : PRIMS) {
- Class<?>[] arg1 = {value, aClass};
+ for (final Class<?> aClass : PRIMS) {
+ final Class<?>[] arg1 = {value, aClass};
setUpKey(method, arg1);
- for (Class<?> prim : PRIMS) {
- Class<?>[] arg2 = {value, aClass, prim};
+ for (final Class<?> prim : PRIMS) {
+ final Class<?>[] arg2 = {value, aClass, prim};
setUpKey(method, arg2);
}
}
@@ -112,45 +112,45 @@
}
/** Builds a string key */
- String makeStringKey(String method, Class<?>... params) {
- StringBuilder builder = new StringBuilder(method);
- for (Class<?> param : params) {
+ String makeStringKey(final String method, final Class<?>... params) {
+ final StringBuilder builder = new StringBuilder(method);
+ for (final Class<?> param : params) {
builder.append(MethodKey.primitiveClass(param).getName());
}
return builder.toString();
}
/** Checks that a string key does exist */
- void checkStringKey(String method, Class<?>... params) {
- String key = makeStringKey(method, params);
- MethodKey out = BY_STRING.get(key);
+ void checkStringKey(final String method, final Class<?>... params) {
+ final String key = makeStringKey(method, params);
+ final MethodKey out = BY_STRING.get(key);
Assert.assertNotNull(out);
}
/** Builds a method key */
- MethodKey makeKey(String method, Class<?>... params) {
+ MethodKey makeKey(final String method, final Class<?>... params) {
return new MethodKey(method, params);
}
/** Checks that a method key exists */
- void checkKey(String method, Class<?>... params) {
- MethodKey key = makeKey(method, params);
- String out = BY_KEY.get(key);
+ void checkKey(final String method, final Class<?>... params) {
+ final MethodKey key = makeKey(method, params);
+ final String out = BY_KEY.get(key);
Assert.assertNotNull(out);
}
@Test
public void testDebugString() throws Exception {
- MethodKey c = KEY_LIST[0];
- String str = c.debugString();
+ final MethodKey c = KEY_LIST[0];
+ final String str = c.debugString();
Assert.assertNotNull(str);
}
@Test
public void testObjectKey() throws Exception {
- for (MethodKey ctl : KEY_LIST) {
- MethodKey key = makeKey(ctl.getMethod(), ctl.getParameters());
- String out = BY_KEY.get(key);
+ for (final MethodKey ctl : KEY_LIST) {
+ final MethodKey key = makeKey(ctl.getMethod(), ctl.getParameters());
+ final String out = BY_KEY.get(key);
Assert.assertNotNull(out);
Assert.assertEquals(ctl.toString() + " != " + out, ctl.toString(), out);
}
@@ -159,9 +159,9 @@
@Test
public void testStringKey() throws Exception {
- for (MethodKey ctl : KEY_LIST) {
- String key = makeStringKey(ctl.getMethod(), ctl.getParameters());
- MethodKey out = BY_STRING.get(key);
+ for (final MethodKey ctl : KEY_LIST) {
+ final String key = makeStringKey(ctl.getMethod(), ctl.getParameters());
+ final MethodKey out = BY_STRING.get(key);
Assert.assertNotNull(out);
Assert.assertEquals(ctl.toString() + " != " + key, ctl, out);
}
@@ -172,9 +172,9 @@
@Test
public void testPerfKey() throws Exception {
for (int l = 0; l < LOOP; ++l) {
- for (MethodKey ctl : KEY_LIST) {
- MethodKey key = makeKey(ctl.getMethod(), ctl.getParameters());
- String out = BY_KEY.get(key);
+ for (final MethodKey ctl : KEY_LIST) {
+ final MethodKey key = makeKey(ctl.getMethod(), ctl.getParameters());
+ final String out = BY_KEY.get(key);
Assert.assertNotNull(out);
}
}
@@ -183,9 +183,9 @@
@Test
public void testPerfString() throws Exception {
for (int l = 0; l < LOOP; ++l) {
- for (MethodKey ctl : KEY_LIST) {
- String key = makeStringKey(ctl.getMethod(), ctl.getParameters());
- MethodKey out = BY_STRING.get(key);
+ for (final MethodKey ctl : KEY_LIST) {
+ final String key = makeStringKey(ctl.getMethod(), ctl.getParameters());
+ final MethodKey out = BY_STRING.get(key);
Assert.assertNotNull(out);
}
}
@@ -194,12 +194,12 @@
@Test
public void testPerfKey2() throws Exception {
for (int l = 0; l < LOOP; ++l) {
- for (String method : METHODS) {
- for (Object value : ARGS) {
+ for (final String method : METHODS) {
+ for (final Object value : ARGS) {
checkKey(method, value.getClass());
- for (Object o : ARGS) {
+ for (final Object o : ARGS) {
checkKey(method, value.getClass(), o.getClass());
- for (Object arg : ARGS) {
+ for (final Object arg : ARGS) {
checkKey(method, value.getClass(), o.getClass(), arg.getClass());
}
}
@@ -211,12 +211,12 @@
@Test
public void testPerfStringKey2() throws Exception {
for (int l = 0; l < LOOP; ++l) {
- for (String method : METHODS) {
- for (Object value : ARGS) {
+ for (final String method : METHODS) {
+ for (final Object value : ARGS) {
checkStringKey(method, value.getClass());
- for (Object o : ARGS) {
+ for (final Object o : ARGS) {
checkStringKey(method, value.getClass(), o.getClass());
- for (Object arg : ARGS) {
+ for (final Object arg : ARGS) {
checkStringKey(method, value.getClass(), o.getClass(), arg.getClass());
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/introspection/SandboxTest.java b/src/test/java/org/apache/commons/jexl3/introspection/SandboxTest.java
index 88c52e1..dc32ba5 100644
--- a/src/test/java/org/apache/commons/jexl3/introspection/SandboxTest.java
+++ b/src/test/java/org/apache/commons/jexl3/introspection/SandboxTest.java
@@ -80,11 +80,11 @@
public String alias;
public @NoJexl
- Foo(String name, String notcallable) {
+ Foo(final String name, final String notcallable) {
throw new RuntimeException("should not be callable!");
}
- public Foo(String name) {
+ public Foo(final String name) {
this.name = name;
this.alias = name + "-alias";
}
@@ -93,7 +93,7 @@
return name;
}
- public void setName(String name) {
+ public void setName(final String name) {
this.name = name;
}
@@ -123,21 +123,21 @@
@Test
public void testCtorBlock() throws Exception {
- String expr = "new('" + Foo.class.getName() + "', '42')";
+ final String expr = "new('" + Foo.class.getName() + "', '42')";
JexlScript script = JEXL.createScript(expr);
Object result;
result = script.execute(null);
Assert.assertEquals("42", ((Foo) result).getName());
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
sandbox.block(Foo.class.getName()).execute("");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
script = sjexl.createScript(expr);
try {
result = script.execute(null);
Assert.fail("ctor should not be accessible");
- } catch (JexlException.Method xmethod) {
+ } catch (final JexlException.Method xmethod) {
// ok, ctor should not have been accessible
LOGGER.info(xmethod.toString());
}
@@ -145,22 +145,22 @@
@Test
public void testMethodBlock() throws Exception {
- String expr = "foo.Quux()";
+ final String expr = "foo.Quux()";
JexlScript script = JEXL.createScript(expr, "foo");
- Foo foo = new Foo("42");
+ final Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo);
Assert.assertEquals(foo.Quux(), result);
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
sandbox.block(Foo.class.getName()).execute("Quux");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
script = sjexl.createScript(expr, "foo");
try {
result = script.execute(null, foo);
Assert.fail("Quux should not be accessible");
- } catch (JexlException.Method xmethod) {
+ } catch (final JexlException.Method xmethod) {
// ok, Quux should not have been accessible
LOGGER.info(xmethod.toString());
}
@@ -168,22 +168,22 @@
@Test
public void testGetBlock() throws Exception {
- String expr = "foo.alias";
+ final String expr = "foo.alias";
JexlScript script = JEXL.createScript(expr, "foo");
- Foo foo = new Foo("42");
+ final Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo);
Assert.assertEquals(foo.alias, result);
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
sandbox.block(Foo.class.getName()).read("alias");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
script = sjexl.createScript(expr, "foo");
try {
result = script.execute(null, foo);
Assert.fail("alias should not be accessible");
- } catch (JexlException.Property xvar) {
+ } catch (final JexlException.Property xvar) {
// ok, alias should not have been accessible
LOGGER.info(xvar.toString());
}
@@ -191,22 +191,22 @@
@Test
public void testSetBlock() throws Exception {
- String expr = "foo.alias = $0";
+ final String expr = "foo.alias = $0";
JexlScript script = JEXL.createScript(expr, "foo", "$0");
- Foo foo = new Foo("42");
+ final Foo foo = new Foo("42");
Object result;
result = script.execute(null, foo, "43");
Assert.assertEquals("43", result);
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
sandbox.block(Foo.class.getName()).write("alias");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
script = sjexl.createScript(expr, "foo", "$0");
try {
result = script.execute(null, foo, "43");
Assert.fail("alias should not be accessible");
- } catch (JexlException.Property xvar) {
+ } catch (final JexlException.Property xvar) {
// ok, alias should not have been accessible
LOGGER.info(xvar.toString());
}
@@ -214,21 +214,21 @@
@Test
public void testCantSeeMe() throws Exception {
- JexlContext jc = new MapContext();
- String expr = "foo.doIt()";
+ final JexlContext jc = new MapContext();
+ final String expr = "foo.doIt()";
JexlScript script;
Object result;
- JexlSandbox sandbox = new JexlSandbox(false);
+ final JexlSandbox sandbox = new JexlSandbox(false);
sandbox.allow(Foo.class.getName());
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
jc.set("foo", new CantSeeMe());
script = sjexl.createScript(expr);
try {
result = script.execute(jc);
Assert.fail("should have failed, doIt()");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
//
}
jc.set("foo", new Foo("42"));
@@ -238,13 +238,13 @@
@Test
public void testCtorAllow() throws Exception {
- String expr = "new('" + Foo.class.getName() + "', '42')";
+ final String expr = "new('" + Foo.class.getName() + "', '42')";
JexlScript script;
Object result;
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
sandbox.allow(Foo.class.getName()).execute("");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
script = sjexl.createScript(expr);
result = script.execute(null);
@@ -253,14 +253,14 @@
@Test
public void testMethodAllow() throws Exception {
- Foo foo = new Foo("42");
- String expr = "foo.Quux()";
+ final Foo foo = new Foo("42");
+ final String expr = "foo.Quux()";
JexlScript script;
Object result;
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
sandbox.allow(Foo.class.getName()).execute("Quux");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).strict(true).safe(false).create();
script = sjexl.createScript(expr, "foo");
result = script.execute(null, foo);
@@ -269,8 +269,8 @@
@Test
public void testMethodNoJexl() throws Exception {
- Foo foo = new Foo("42");
- String[] exprs = {
+ final Foo foo = new Foo("42");
+ final String[] exprs = {
"foo.cantCallMe()",
"foo.tryMe()",
"foo.tryMeARiver()",
@@ -281,8 +281,8 @@
JexlScript script;
Object result;
- JexlEngine sjexl = new JexlBuilder().strict(true).safe(false).create();
- for (String expr : exprs) {
+ final JexlEngine sjexl = new JexlBuilder().strict(true).safe(false).create();
+ for (final String expr : exprs) {
script = sjexl.createScript(expr, "foo");
try {
result = script.execute(null, foo);
@@ -296,15 +296,15 @@
@Test
public void testGetAllow() throws Exception {
- Foo foo = new Foo("42");
- String expr = "foo.alias";
+ final Foo foo = new Foo("42");
+ final String expr = "foo.alias";
JexlScript script;
Object result;
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
sandbox.allow(Foo.class.getName()).read("alias");
sandbox.get(Foo.class.getName()).read().alias("alias", "ALIAS");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
script = sjexl.createScript(expr, "foo");
result = script.execute(null, foo);
@@ -317,14 +317,14 @@
@Test
public void testSetAllow() throws Exception {
- Foo foo = new Foo("42");
- String expr = "foo.alias = $0";
+ final Foo foo = new Foo("42");
+ final String expr = "foo.alias = $0";
JexlScript script;
Object result;
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
sandbox.allow(Foo.class.getName()).write("alias");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
script = sjexl.createScript(expr, "foo", "$0");
result = script.execute(null, foo, "43");
@@ -334,15 +334,15 @@
@Test
public void testRestrict() throws Exception {
- JexlContext context = new MapContext();
+ final JexlContext context = new MapContext();
context.set("System", System.class);
- JexlSandbox sandbox = new JexlSandbox();
+ final JexlSandbox sandbox = new JexlSandbox();
// only allow call to currentTimeMillis (avoid exit, gc, loadLibrary, etc)
sandbox.allow(System.class.getName()).execute("currentTimeMillis");
// can not create a new file
sandbox.block(java.io.File.class.getName()).execute("");
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
String expr;
JexlScript script;
@@ -352,7 +352,7 @@
try {
result = script.execute(context);
Assert.fail("should not allow calling exit!");
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
LOGGER.info(xjexl.toString());
}
@@ -360,7 +360,7 @@
try {
result = script.execute(context);
Assert.fail("should not allow calling exit!");
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
LOGGER.info(xjexl.toString());
}
@@ -368,7 +368,7 @@
try {
result = script.execute(context);
Assert.fail("should not allow creating a file");
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
LOGGER.info(xjexl.toString());
}
@@ -381,15 +381,15 @@
@Test
public void testSandboxInherit0() throws Exception {
Object result;
- JexlContext ctxt = null;
- List<String> foo = new ArrayList<String>();
- JexlSandbox sandbox = new JexlSandbox(false, true);
+ final JexlContext ctxt = null;
+ final List<String> foo = new ArrayList<String>();
+ final JexlSandbox sandbox = new JexlSandbox(false, true);
sandbox.allow(java.util.List.class.getName());
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
- JexlScript method = sjexl.createScript("foo.add(y)", "foo", "y");
- JexlScript set = sjexl.createScript("foo[x] = y", "foo", "x", "y");
- JexlScript get = sjexl.createScript("foo[x]", "foo", "x");
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
+ final JexlScript method = sjexl.createScript("foo.add(y)", "foo", "y");
+ final JexlScript set = sjexl.createScript("foo[x] = y", "foo", "x", "y");
+ final JexlScript get = sjexl.createScript("foo[x]", "foo", "x");
result = method.execute(ctxt, foo, "nothing");
Assert.assertEquals(true, result);
@@ -407,7 +407,7 @@
public abstract static class Operation {
protected final int base;
- public Operation(int sz) {
+ public Operation(final int sz) {
base = sz;
}
@@ -416,17 +416,17 @@
}
public static class Operation2 extends Operation {
- public Operation2(int sz) {
+ public Operation2(final int sz) {
super(sz);
}
@Override
- public int someOp(int x) {
+ public int someOp(final int x) {
return base + x;
}
@Override
- public int nonCallable(int y) {
+ public int nonCallable(final int y) {
throw new UnsupportedOperationException("do NOT call");
}
}
@@ -434,21 +434,21 @@
@Test
public void testSandboxInherit1() throws Exception {
Object result;
- JexlContext ctxt = null;
- Operation2 foo = new Operation2(12);
- JexlSandbox sandbox = new JexlSandbox(false, true);
+ final JexlContext ctxt = null;
+ final Operation2 foo = new Operation2(12);
+ final JexlSandbox sandbox = new JexlSandbox(false, true);
sandbox.allow(Operation.class.getName());
sandbox.block(Operation.class.getName()).execute("nonCallable");
//sandbox.block(Foo.class.getName()).execute();
- JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
- JexlScript someOp = sjexl.createScript("foo.someOp(y)", "foo", "y");
+ final JexlEngine sjexl = new JexlBuilder().sandbox(sandbox).safe(false).strict(true).create();
+ final JexlScript someOp = sjexl.createScript("foo.someOp(y)", "foo", "y");
result = someOp.execute(ctxt, foo, 30);
Assert.assertEquals(42, result);
- JexlScript nonCallable = sjexl.createScript("foo.nonCallable(y)", "foo", "y");
+ final JexlScript nonCallable = sjexl.createScript("foo.nonCallable(y)", "foo", "y");
try {
result = nonCallable.execute(null, foo, 0);
Assert.fail("should not be possible");
- } catch (JexlException xjm) {
+ } catch (final JexlException xjm) {
// ok
LOGGER.info(xjm.toString());
}
@@ -477,14 +477,14 @@
@Test
public void testNoJexl312() throws Exception {
- JexlContext ctxt = new MapContext();
+ final JexlContext ctxt = new MapContext();
- JexlEngine sjexl = new JexlBuilder().safe(false).strict(true).create();
- JexlScript foo = sjexl.createScript("x.getFoo()", "x");
+ final JexlEngine sjexl = new JexlBuilder().safe(false).strict(true).create();
+ final JexlScript foo = sjexl.createScript("x.getFoo()", "x");
try {
foo.execute(ctxt, new Foo44());
Assert.fail("should have thrown");
- } catch (JexlException xany) {
+ } catch (final JexlException xany) {
Assert.assertNotNull(xany);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/junit/Asserter.java b/src/test/java/org/apache/commons/jexl3/junit/Asserter.java
index eba2e4c..3949200 100644
--- a/src/test/java/org/apache/commons/jexl3/junit/Asserter.java
+++ b/src/test/java/org/apache/commons/jexl3/junit/Asserter.java
@@ -51,7 +51,7 @@
* Create an asserter.
* @param jexl the JEXL engine to use
*/
- public Asserter(JexlEngine jexl) {
+ public Asserter(final JexlEngine jexl) {
engine = jexl;
}
@@ -71,16 +71,16 @@
return context;
}
- public void setStrict(boolean s) {
+ public void setStrict(final boolean s) {
context.getEngineOptions().setStrict(s);
}
- public void setStrict(boolean es, boolean as) {
+ public void setStrict(final boolean es, final boolean as) {
context.getEngineOptions().setStrict(es);
context.getEngineOptions().setStrictArithmetic(as);
}
- public void setSilent(boolean silent) {
+ public void setSilent(final boolean silent) {
context.getEngineOptions().setSilent(silent);
}
@@ -93,19 +93,19 @@
* @throws Exception if the expression could not be evaluationed or an assertion
* fails
*/
- public void assertExpression(String expression, Object expected) throws Exception {
- JexlScript exp = engine.createScript(expression);
- Object value = exp.execute(context);
+ public void assertExpression(final String expression, final Object expected) throws Exception {
+ final JexlScript exp = engine.createScript(expression);
+ final Object value = exp.execute(context);
if (expected instanceof BigDecimal) {
- JexlArithmetic jexla = engine.getArithmetic();
+ final JexlArithmetic jexla = engine.getArithmetic();
Assert.assertEquals("expression: " + expression, 0,
((BigDecimal) expected).compareTo(jexla.toBigDecimal(value)));
}
if (expected != null && value != null) {
if (expected.getClass().isArray() && value.getClass().isArray()) {
- int esz = Array.getLength(expected);
- int vsz = Array.getLength(value);
- String report = "expression: " + expression;
+ final int esz = Array.getLength(expected);
+ final int vsz = Array.getLength(value);
+ final String report = "expression: " + expression;
Assert.assertEquals(report + ", array size", esz, vsz);
for (int i = 0; i < vsz; ++i) {
Assert.assertEquals(report + ", value@[]" + i, Array.get(expected, i), Array.get(value, i));
@@ -130,12 +130,12 @@
* @param matchException the exception message pattern
* @throws Exception if the expression did not fail or the exception did not match the expected pattern
*/
- public void failExpression(String expression, String matchException) throws Exception {
+ public void failExpression(final String expression, final String matchException) throws Exception {
try {
- JexlScript exp = engine.createScript(expression);
+ final JexlScript exp = engine.createScript(expression);
exp.execute(context);
fail("expression: " + expression);
- } catch (JexlException xjexl) {
+ } catch (final JexlException xjexl) {
if (matchException != null && !xjexl.getMessage().matches(matchException)) {
fail("expression: " + expression + ", expected: " + matchException + ", got " + xjexl.getMessage());
}
@@ -149,7 +149,7 @@
* @param name variable name
* @param value variable value
*/
- public void setVariable(String name, Object value) {
+ public void setVariable(final String name, final Object value) {
variables.put(name, value);
}
@@ -158,7 +158,7 @@
* @param name variable name
* @return variable value
*/
- public Object removeVariable(String name) {
+ public Object removeVariable(final String name) {
return variables.remove(name);
}
@@ -168,7 +168,7 @@
* @param name variable name
* @return value variable value
*/
- public Object getVariable(String name) {
+ public Object getVariable(final String name) {
return variables.get(name);
}
diff --git a/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java b/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java
index 837056c..aafc7b7 100644
--- a/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java
+++ b/src/test/java/org/apache/commons/jexl3/junit/AsserterTest.java
@@ -35,21 +35,21 @@
@Test
public void testThis() throws Exception {
- Asserter asserter = new Asserter(JEXL);
+ final Asserter asserter = new Asserter(JEXL);
asserter.setVariable("this", new Foo());
asserter.assertExpression("this.repeat('abc')", "Repeat : abc");
try {
asserter.assertExpression("this.count", "Wrong Value");
Assert.fail("This method should have thrown an assertion exception");
}
- catch (AssertionError e) {
+ catch (final AssertionError e) {
// it worked!
}
}
@Test
public void testVariable() throws Exception {
- Asserter asserter = new Asserter(JEXL);
+ final Asserter asserter = new Asserter(JEXL);
asserter.setSilent(true);
asserter.setVariable("foo", new Foo());
asserter.setVariable("person", "James");
@@ -64,7 +64,7 @@
asserter.assertExpression("bar.count", new Integer(5));
Assert.fail("This method should have thrown an assertion exception");
}
- catch (AssertionError e) {
+ catch (final AssertionError e) {
// it worked!
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java b/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
index 222e14d..94eb462 100644
--- a/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
+++ b/src/test/java/org/apache/commons/jexl3/parser/ParserTest.java
@@ -36,7 +36,7 @@
*/
@Test
public void testParse() throws Exception {
- Parser parser = new Parser(new StringReader(";"));
+ final Parser parser = new Parser(new StringReader(";"));
JexlNode sn;
sn = parser.parse(null, FEATURES, "foo = 1;", null);
Assert.assertNotNull("parsed node is null", sn);
@@ -50,40 +50,40 @@
@Test
public void testErrorAssign() throws Exception {
- String[] ops = { "=", "+=", "-=", "/=", "*=", "^=", "&=", "|=" };
- for(String op : ops) {
- Parser parser = new Parser(new StringReader(";"));
+ final String[] ops = { "=", "+=", "-=", "/=", "*=", "^=", "&=", "|=" };
+ for(final String op : ops) {
+ final Parser parser = new Parser(new StringReader(";"));
try {
- JexlNode sn = parser.parse(null, FEATURES, "foo() "+op+" 1;", null);
+ final JexlNode sn = parser.parse(null, FEATURES, "foo() "+op+" 1;", null);
Assert.fail("should have failed on invalid assignment " + op);
- } catch (JexlException.Parsing xparse) {
+ } catch (final JexlException.Parsing xparse) {
// ok
- String ss = xparse.getDetail();
- String sss = xparse.toString();
+ final String ss = xparse.getDetail();
+ final String sss = xparse.toString();
}
}
}
@Test
public void testErrorAmbiguous() throws Exception {
- Parser parser = new Parser(new StringReader(";"));
+ final Parser parser = new Parser(new StringReader(";"));
try {
- JexlNode sn = parser.parse(null, FEATURES, "x = 1 y = 5", null);
+ final JexlNode sn = parser.parse(null, FEATURES, "x = 1 y = 5", null);
Assert.fail("should have failed on ambiguous statement");
- } catch (JexlException.Ambiguous xambiguous) {
+ } catch (final JexlException.Ambiguous xambiguous) {
// ok
- } catch(JexlException xother) {
+ } catch(final JexlException xother) {
Assert.fail(xother.toString());
}
}
@Test
public void testIdentifierEscape() {
- String[] ids = new String[]{"a\\ b", "a\\ b\\ c", "a\\'b\\\"c", "a\\ \\ c"};
- for(String id : ids) {
- String esc0 = StringParser.unescapeIdentifier(id);
+ final String[] ids = new String[]{"a\\ b", "a\\ b\\ c", "a\\'b\\\"c", "a\\ \\ c"};
+ for(final String id : ids) {
+ final String esc0 = StringParser.unescapeIdentifier(id);
Assert.assertFalse(esc0.contains("\\"));
- String esc1 = StringParser.escapeIdentifier(esc0);
+ final String esc1 = StringParser.escapeIdentifier(esc0);
Assert.assertEquals(id, esc1);
}
}
@@ -95,7 +95,7 @@
public void testControlCharacters() {
// Both '' and "" are valid JEXL string
// The array of tuples where the first element is an expected result and the second element is a test string.
- String[][] strings = new String[][] {
+ final String[][] strings = new String[][] {
new String[] {"a\nb\tc", "'a\nb\tc'"}, // we still honor the actual characters
new String[] {"a\nb\tc", "'a\\nb\\tc'"},
new String[] {"a\nb\tc", "\"a\\nb\\tc\""},
@@ -104,8 +104,8 @@
new String[] {"\"hi\"", "'\"hi\"'"},
new String[] {"\"hi\"", "'\"hi\"'"},
};
- for(String[] pair: strings) {
- String output = StringParser.buildString(pair[1], true);
+ for(final String[] pair: strings) {
+ final String output = StringParser.buildString(pair[1], true);
Assert.assertEquals(pair[0], output);
}
}
diff --git a/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineOptionalTest.java b/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineOptionalTest.java
index 713d852..1680b81 100644
--- a/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineOptionalTest.java
+++ b/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineOptionalTest.java
@@ -34,7 +34,7 @@
@Test
public void testOutput() throws Exception {
- String output = factory.getOutputStatement("foo\u00a9bar");
+ final String output = factory.getOutputStatement("foo\u00a9bar");
Assert.assertEquals("JEXL.out.print('foo\\u00a9bar')", output);
// redirect output to capture evaluation result
final StringWriter outContent = new StringWriter();
@@ -45,7 +45,7 @@
@Test
public void testError() throws Exception {
- String error = "JEXL.err.print('ERROR')";
+ final String error = "JEXL.err.print('ERROR')";
// redirect error to capture evaluation result
final StringWriter outContent = new StringWriter();
engine.getContext().setErrorWriter(outContent);
@@ -56,8 +56,8 @@
@Test
public void testCompilable() throws Exception {
Assert.assertTrue("Engine should implement Compilable", engine instanceof Compilable);
- Compilable cengine = (Compilable) engine;
- CompiledScript script = cengine.compile("40 + 2");
+ final Compilable cengine = (Compilable) engine;
+ final CompiledScript script = cengine.compile("40 + 2");
Assert.assertEquals(42, script.eval());
Assert.assertEquals(42, script.eval());
}
diff --git a/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java b/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java
index 63d16bc..ebd8e1e 100644
--- a/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java
+++ b/src/test/java/org/apache/commons/jexl3/scripting/JexlScriptEngineTest.java
@@ -39,7 +39,7 @@
@Test
public void testScriptEngineFactory() throws Exception {
- JexlScriptEngineFactory factory = new JexlScriptEngineFactory();
+ final JexlScriptEngineFactory factory = new JexlScriptEngineFactory();
Assert.assertEquals("JEXL Engine", factory.getParameter(ScriptEngine.ENGINE));
Assert.assertEquals("3.2", factory.getParameter(ScriptEngine.ENGINE_VERSION));
Assert.assertEquals("JEXL", factory.getParameter(ScriptEngine.LANGUAGE));
@@ -55,32 +55,32 @@
@Test
public void testScriptingGetBy() throws Exception {
- ScriptEngineManager manager = new ScriptEngineManager();
+ final ScriptEngineManager manager = new ScriptEngineManager();
Assert.assertNotNull("Manager should not be null", manager);
- for (String name : NAMES) {
- ScriptEngine engine = manager.getEngineByName(name);
+ for (final String name : NAMES) {
+ final ScriptEngine engine = manager.getEngineByName(name);
Assert.assertNotNull("Engine should not be null (name)", engine);
}
- for (String extension : EXTENSIONS) {
- ScriptEngine engine = manager.getEngineByExtension(extension);
+ for (final String extension : EXTENSIONS) {
+ final ScriptEngine engine = manager.getEngineByExtension(extension);
Assert.assertNotNull("Engine should not be null (extension)", engine);
}
- for (String mime : MIMES) {
- ScriptEngine engine = manager.getEngineByMimeType(mime);
+ for (final String mime : MIMES) {
+ final ScriptEngine engine = manager.getEngineByMimeType(mime);
Assert.assertNotNull("Engine should not be null (mime)", engine);
}
}
@Test
public void testScripting() throws Exception {
- ScriptEngineManager manager = new ScriptEngineManager();
+ final ScriptEngineManager manager = new ScriptEngineManager();
Assert.assertNotNull("Manager should not be null", manager);
- ScriptEngine engine = manager.getEngineByName("jexl3");
+ final ScriptEngine engine = manager.getEngineByName("jexl3");
final Integer initialValue = 123;
Assert.assertEquals(initialValue,engine.eval("123"));
Assert.assertEquals(initialValue,engine.eval("0;123"));// multiple statements
- long time1 = System.currentTimeMillis();
- Long time2 = (Long) engine.eval(
+ final long time1 = System.currentTimeMillis();
+ final Long time2 = (Long) engine.eval(
"sys=context.class.forName(\"java.lang.System\");"
+"now=sys.currentTimeMillis();"
);
@@ -101,29 +101,29 @@
@Test
public void testNulls() throws Exception {
- ScriptEngineManager manager = new ScriptEngineManager();
+ final ScriptEngineManager manager = new ScriptEngineManager();
Assert.assertNotNull("Manager should not be null", manager);
- ScriptEngine engine = manager.getEngineByName("jexl3");
+ final ScriptEngine engine = manager.getEngineByName("jexl3");
Assert.assertNotNull("Engine should not be null (name)", engine);
try {
engine.eval((String)null);
Assert.fail("Should have caused NPE");
- } catch (NullPointerException e) {
+ } catch (final NullPointerException e) {
// NOOP
}
try {
engine.eval((Reader)null);
Assert.fail("Should have caused NPE");
- } catch (NullPointerException e) {
+ } catch (final NullPointerException e) {
// NOOP
}
}
@Test
public void testScopes() throws Exception {
- ScriptEngineManager manager = new ScriptEngineManager();
+ final ScriptEngineManager manager = new ScriptEngineManager();
Assert.assertNotNull("Manager should not be null", manager);
- ScriptEngine engine = manager.getEngineByName("JEXL");
+ final ScriptEngine engine = manager.getEngineByName("JEXL");
Assert.assertNotNull("Engine should not be null (JEXL)", engine);
manager.put("global", 1);
engine.put("local", 10);
@@ -143,9 +143,9 @@
@Test
public void testDottedNames() throws Exception {
- ScriptEngineManager manager = new ScriptEngineManager();
+ final ScriptEngineManager manager = new ScriptEngineManager();
Assert.assertNotNull("Manager should not be null", manager);
- ScriptEngine engine = manager.getEngineByName("JEXL");
+ final ScriptEngine engine = manager.getEngineByName("JEXL");
Assert.assertNotNull("Engine should not be null (JEXL)", engine);
engine.eval("this.is.a.test=null");
Assert.assertNull(engine.get("this.is.a.test"));
@@ -157,7 +157,7 @@
@Test
public void testDirectNew() throws Exception {
- ScriptEngine engine = new JexlScriptEngine();
+ final ScriptEngine engine = new JexlScriptEngine();
final Integer initialValue = 123;
Assert.assertEquals(initialValue,engine.eval("123"));
}