You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2019/11/07 21:14:35 UTC
[commons-jexl] branch master updated: JEXL-307: tidy API Task
#JEXL-307 - Variable redeclaration option
This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
The following commit(s) were added to refs/heads/master by this push:
new a9411b4 JEXL-307: tidy API Task #JEXL-307 - Variable redeclaration option
a9411b4 is described below
commit a9411b42ac64c9cf97ba4f1ce5d61bc77d8b6997
Author: henrib <he...@apache.org>
AuthorDate: Thu Nov 7 22:13:53 2019 +0100
JEXL-307: tidy API
Task #JEXL-307 - Variable redeclaration option
---
.../java/org/apache/commons/jexl3/JexlOptions.java | 23 ++++++----
.../org/apache/commons/jexl3/internal/Engine.java | 14 +++---
.../commons/jexl3/internal/InterpreterBase.java | 2 +-
.../org/apache/commons/jexl3/internal/Options.java | 50 +++++++++++-----------
4 files changed, 49 insertions(+), 40 deletions(-)
diff --git a/src/main/java/org/apache/commons/jexl3/JexlOptions.java b/src/main/java/org/apache/commons/jexl3/JexlOptions.java
index 200fcd0..dc35074 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlOptions.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlOptions.java
@@ -151,13 +151,6 @@ public interface JexlOptions {
void setMathScale(int mscale);
/**
- * Set options from engine.
- * @param jexl the engine
- * @return this instance
- */
- JexlOptions set(JexlEngine jexl);
-
- /**
* Sets whether the engine considers null in navigation expression as errors
* during evaluation.
* @param flag true if safe, false otherwise
@@ -183,7 +176,21 @@ public interface JexlOptions {
* @param stricta true or false
*/
void setStrictArithmetic(boolean stricta);
-
+
+ /**
+ * Set options from engine.
+ * @param jexl the engine
+ * @return this instance
+ */
+ JexlOptions set(JexlEngine jexl);
+
+ /**
+ * Set options from options.
+ * @param options the options
+ * @return this instance
+ */
+ JexlOptions set(JexlOptions options);
+
/**
* Creates a copy of this instance.
* @return a copy
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 4f19bb5..d752cca 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Engine.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Engine.java
@@ -171,11 +171,12 @@ public class Engine extends JexlEngine {
*/
public Engine(JexlBuilder conf) {
// options:
- JexlOptions opts = conf.options();
- this.strict = opts.isStrict();
- this.safe = opts.isSafe();
- this.silent = opts.isSilent();
+ this.options = conf.options().copy();
+ this.strict = options.isStrict();
+ this.safe = options.isSafe();
+ this.silent = options.isSilent();
this.cancellable = option(conf.cancellable(), !silent && strict);
+ options.setCancellable(cancellable);
this.debug = option(conf.debug(), true);
this.collectAll = option(conf.collectAll(), true);
this.stackOverflow = conf.stackOverflow() > 0? conf.stackOverflow() : Integer.MAX_VALUE;
@@ -193,6 +194,9 @@ public class Engine extends JexlEngine {
}
this.logger = conf.logger() == null ? LogFactory.getLog(JexlEngine.class) : conf.logger();
this.arithmetic = conf.arithmetic() == null ? new JexlArithmetic(this.strict) : conf.arithmetic();
+ options.setMathContext(arithmetic.getMathContext());
+ options.setMathScale(arithmetic.getMathScale());
+ 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();
@@ -205,8 +209,6 @@ public class Engine extends JexlEngine {
if (uberspect == null) {
throw new IllegalArgumentException("uberspect can not be null");
}
- // capture options
- this.options = opts.copy().set(this);
}
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 a41192f..74c8f8f 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
@@ -120,7 +120,7 @@ public abstract class InterpreterBase extends ParserVisitor {
functions = ii.functions;
functors = ii.functors;
operators = ii.operators;
- options = new org.apache.commons.jexl3.internal.Options(ii.options);
+ options = ii.options.copy();
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Options.java b/src/main/java/org/apache/commons/jexl3/internal/Options.java
index 535a4a0..04dd182 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Options.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Options.java
@@ -32,7 +32,7 @@ public class Options implements JexlOptions {
/** The local shade bit. */
protected static final int SHADE = 6;
/** The antish var bit. */
- protected static final int ANTISH_VAR = 5;
+ protected static final int ANTISH = 5;
/** The lexical scope bit. */
protected static final int LEXICAL = 4;
/** The safe bit. */
@@ -48,7 +48,7 @@ public class Options implements JexlOptions {
"cancellable", "strict", "silent", "safe", "lexical", "antish", "lexicalShade"
};
/** Default mask .*/
- protected static int DEFAULT = 1 /*<< CANCELLABLE*/ | 1 << STRICT | 1 << ANTISH_VAR | 1 << SAFE;
+ protected static int DEFAULT = 1 /*<< CANCELLABLE*/ | 1 << STRICT | 1 << ANTISH | 1 << SAFE;
/** The arithmetic math context. */
private MathContext mathContext = null;
/** The arithmetic math scale. */
@@ -125,33 +125,24 @@ public class Options implements JexlOptions {
return mask;
}
- /**
- * Set options from engine.
- * @param jexl the engine
- * @return this instance
- */
@Override
public Options set(JexlEngine jexl) {
- mathContext = jexl.getArithmetic().getMathContext();
- mathScale = jexl.getArithmetic().getMathScale();
- strictArithmetic = jexl.getArithmetic().isStrict();
- set(STRICT, flags, jexl.isStrict());
- set(SILENT, flags, jexl.isSilent());
- set(SAFE, flags, jexl.isSafe());
- set(CANCELLABLE, flags, jexl.isCancellable());
+ if (jexl instanceof Engine) {
+ set(((Engine) jexl).options);
+ } else {
+ mathContext = jexl.getArithmetic().getMathContext();
+ mathScale = jexl.getArithmetic().getMathScale();
+ strictArithmetic = jexl.getArithmetic().isStrict();
+ set(STRICT, flags, jexl.isStrict());
+ set(SILENT, flags, jexl.isSilent());
+ set(SAFE, flags, jexl.isSafe());
+ set(CANCELLABLE, flags, jexl.isCancellable());
+ }
return this;
}
@Override
- public JexlOptions copy() {
- return new Options(this);
- }
-
- /**
- * Create a copy from another set of options.
- * @param opts the source options to copy
- */
- public Options(JexlOptions opts) {
+ public Options set(JexlOptions opts) {
if (opts instanceof Options) {
Options src = (Options) opts;
mathContext = src.mathContext;
@@ -167,13 +158,22 @@ public class Options implements JexlOptions {
mask = set(SILENT, mask, opts.isSilent());
mask = set(SAFE, mask, opts.isSafe());
mask = set(CANCELLABLE, mask, opts.isCancellable());
+ mask = set(LEXICAL, mask, opts.isLexical());
+ mask = set(SHADE, mask, opts.isLexicalShade());
+ mask = set(ANTISH, mask, opts.isAntish());
flags = mask;
}
+ return this;
+ }
+
+ @Override
+ public Options copy() {
+ return new Options().set(this);
}
@Override
public void setAntish(boolean flag) {
- flags = set(ANTISH_VAR, flags, flag);
+ flags = set(ANTISH, flags, flag);
}
@Override
@@ -223,7 +223,7 @@ public class Options implements JexlOptions {
@Override
public boolean isAntish() {
- return isSet(ANTISH_VAR, flags);
+ return isSet(ANTISH, flags);
}
@Override