This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
commit 627587b7279f696d82a8d7364a531a49adf5c8fb Author: Gary D. Gregory <[email protected]> AuthorDate: Thu Oct 30 08:46:08 2025 -0400 Don't use star imports - Reduce nesting - Inline single use local variable - Use final - Remove extra parentheses --- .../org/apache/commons/jexl3/JexlFeatures.java | 3 +- .../apache/commons/jexl3/internal/Debugger.java | 20 ++--- .../org/apache/commons/jexl3/internal/Engine.java | 4 +- .../commons/jexl3/internal/FqcnResolver.java | 26 +++--- .../org/apache/commons/jexl3/internal/Frame.java | 2 +- .../apache/commons/jexl3/internal/Interpreter.java | 8 +- .../commons/jexl3/internal/ScriptVisitor.java | 99 +++++++++++++++++++++- .../commons/jexl3/internal/TemplateScript.java | 6 +- .../commons/jexl3/parser/ASTCaseExpression.java | 4 +- .../commons/jexl3/parser/ASTCaseStatement.java | 8 +- .../jexl3/parser/ASTIdentifierAccessJxlt.java | 4 +- .../commons/jexl3/parser/ASTJxltLiteral.java | 4 +- .../commons/jexl3/parser/ASTSwitchExpression.java | 4 +- .../commons/jexl3/parser/ASTSwitchStatement.java | 26 +++--- .../apache/commons/jexl3/parser/JexlParser.java | 57 ++++++------- .../commons/jexl3/parser/JexlScriptParser.java | 2 +- .../apache/commons/jexl3/parser/NumberParser.java | 2 +- 17 files changed, 186 insertions(+), 93 deletions(-) diff --git a/src/main/java/org/apache/commons/jexl3/JexlFeatures.java b/src/main/java/org/apache/commons/jexl3/JexlFeatures.java index 1eb51bdd..9fb0516f 100644 --- a/src/main/java/org/apache/commons/jexl3/JexlFeatures.java +++ b/src/main/java/org/apache/commons/jexl3/JexlFeatures.java @@ -742,8 +742,7 @@ public final class JexlFeatures { * @return true if statements can be ambiguous, false otherwise */ public boolean supportsAmbiguousStatement() { - boolean sas = getFeature(AMBIGUOUS_STATEMENT); - return sas; + return getFeature(AMBIGUOUS_STATEMENT); } /** 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 95fb39f7..adb7683a 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Debugger.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Debugger.java @@ -469,7 +469,7 @@ public class Debugger extends ParserVisitor implements JexlInfo.Detail { * @param builder where to append * @param value the value to append */ - static void acceptValue(StringBuilder builder, Object value, boolean quotedStrings) { + static void acceptValue(final StringBuilder builder, final Object value, final boolean quotedStrings) { if (value == null) { builder.append("null"); } else if (value instanceof String) { @@ -647,7 +647,7 @@ public class Debugger extends ParserVisitor implements JexlInfo.Detail { return acceptBlock(node, 0, data); } - private Object acceptBlock(final JexlNode node, int begin, final Object data) { + private Object acceptBlock(final JexlNode node, final int begin, final Object data) { builder.append('{'); if (indent > 0) { indentLevel += 1; @@ -709,7 +709,7 @@ public class Debugger extends ParserVisitor implements JexlInfo.Detail { } @Override - protected Object visit(ASTSwitchStatement node, Object data) { + protected Object visit(final ASTSwitchStatement node, final Object data) { builder.append("switch ("); accept(node.jjtGetChild(0), data); builder.append(") "); @@ -718,14 +718,14 @@ public class Debugger extends ParserVisitor implements JexlInfo.Detail { } @Override - protected Object visit(ASTCaseStatement node, Object data) { - List<Object> values = node.getValues(); + protected Object visit(final ASTCaseStatement node, final Object data) { + final List<Object> values = node.getValues(); if (values.isEmpty()) { // default case builder.append("default : "); } else { // regular case - for (Object value : values) { + for (final Object value : values) { builder.append("case "); acceptValue(builder, value, true); builder.append(" : "); @@ -736,13 +736,13 @@ public class Debugger extends ParserVisitor implements JexlInfo.Detail { } @Override - protected Object visit(ASTSwitchExpression node, Object data) { + protected Object visit(final ASTSwitchExpression node, final Object data) { return visit((ASTSwitchStatement) node, data); } @Override - protected Object visit(ASTCaseExpression node, Object data) { - List<Object> values = node.getValues(); + protected Object visit(final ASTCaseExpression node, final Object data) { + final List<Object> values = node.getValues(); if (values.isEmpty()) { // default case builder.append("default -> "); @@ -750,7 +750,7 @@ public class Debugger extends ParserVisitor implements JexlInfo.Detail { builder.append("case -> "); // regular case boolean first = true; - for (Object value : values) { + for (final Object value : values) { if (!first) { builder.append(", "); } else { 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 6bf4d903..a275e112 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Engine.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Engine.java @@ -767,7 +767,7 @@ public class Engine extends JexlEngine implements JexlUberspect.ConstantResolver } @Override - public JexlUberspect.ClassConstantResolver createConstantResolver(Collection<String> imports) { + public JexlUberspect.ClassConstantResolver createConstantResolver(final Collection<String> imports) { return imports == null || imports.isEmpty() ? classNameSolver : new FqcnResolver(classNameSolver).importPackages(imports); @@ -807,7 +807,7 @@ public class Engine extends JexlEngine implements JexlUberspect.ConstantResolver } } final JexlInfo ninfo = info == null && debug ? createInfo() : info; - JexlEngine se = putThreadEngine(this); + final JexlEngine se = putThreadEngine(this); try { // if parser not in use... if (parsing.compareAndSet(false, true)) { diff --git a/src/main/java/org/apache/commons/jexl3/internal/FqcnResolver.java b/src/main/java/org/apache/commons/jexl3/internal/FqcnResolver.java index 0353c38d..5e3b3359 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/FqcnResolver.java +++ b/src/main/java/org/apache/commons/jexl3/internal/FqcnResolver.java @@ -96,11 +96,11 @@ public class FqcnResolver implements JexlUberspect.ClassConstantResolver { * @param name the simple class name * @return the fully qualified class name or null if not found */ - private String solveClassName(String name) { + private String solveClassName(final String name) { for (final String pkg : imports) { // try package.classname or fqcn$classname (inner class) - for (char dot : new char[]{'.', '$'}) { - Class<?> clazz = uberspect.getClassByName(pkg + dot + name); + for (final char dot : new char[]{'.', '$'}) { + final Class<?> clazz = uberspect.getClassByName(pkg + dot + name); // solved it if (clazz != null) { return clazz.getName(); @@ -131,10 +131,10 @@ public class FqcnResolver implements JexlUberspect.ClassConstantResolver { return; } // check the package name actually points to a package to avoid clutter - Package pkg = Package.getPackage(name); + final Package pkg = Package.getPackage(name); if (pkg == null) { // if it is a class, solve it now - Class<?> clazz = uberspect.getClassByName(name); + final Class<?> clazz = uberspect.getClassByName(name); if (clazz == null) { throw new JexlException(null, "Cannot import '" + name + "' as it is neither a package nor a class"); } @@ -190,24 +190,24 @@ public class FqcnResolver implements JexlUberspect.ClassConstantResolver { private Object getConstant(final String... ids) { if (ids.length == 1) { final String pname = ids[0]; - for (String cname : fqcns.keySet()) { - Object constant = getConstant(cname, pname); + for (final String cname : fqcns.keySet()) { + final Object constant = getConstant(cname, pname); if (constant != JexlEngine.TRY_FAILED) { return constant; } } } else if (ids.length == 2) { - String cname = ids[0]; - String id = ids[1]; - String fqcn = resolveClassName(cname); + final String cname = ids[0]; + final String id = ids[1]; + final String fqcn = resolveClassName(cname); if (fqcn != null) { - Class<?> clazz = uberspect.getClassByName(fqcn); + final Class<?> clazz = uberspect.getClassByName(fqcn); if (clazz != null) { - JexlPropertyGet getter = uberspect.getPropertyGet(clazz, id); + final JexlPropertyGet getter = uberspect.getPropertyGet(clazz, id); if (getter != null && getter.isConstant()) { try { return getter.invoke(clazz); - } catch (Exception xany) { + } catch (final Exception xany) { // ignore } } 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 e86d498f..30957537 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Frame.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Frame.java @@ -41,7 +41,7 @@ public class Frame { scope = s; stack = r; curried = c; - String[] symbols = scope.getSymbols(); + final String[] symbols = scope.getSymbols(); if (symbols.length != r.length) { throw new IllegalArgumentException("Scope and stack frame size mismatch: " + symbols.length + " != " + r.length); 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 4046f761..a86411b0 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java +++ b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java @@ -380,7 +380,7 @@ public class Interpreter extends InterpreterBase { * @param <NODE> the node type */ private <NODE extends JexlNode & JexlNode.JxltHandle> Object evalJxltHandle(final NODE node) { - JxltEngine.Expression expr = node.getExpression(); + final JxltEngine.Expression expr = node.getExpression(); // internal classes to evaluate in context if (expr instanceof TemplateEngine.TemplateExpression) { final Object eval = ((TemplateEngine.TemplateExpression) expr).evaluate(context, frame, options); @@ -1221,7 +1221,7 @@ public class Interpreter extends InterpreterBase { } @Override - protected Object visit(ASTCaseStatement node, Object data) { + protected Object visit(final ASTCaseStatement node, final Object data) { final int argc = node.jjtGetNumChildren(); Object result = null; for (int i = 0; i < argc; i++) { @@ -1231,7 +1231,7 @@ public class Interpreter extends InterpreterBase { } @Override - protected Object visit(ASTCaseExpression node, Object data) { + protected Object visit(final ASTCaseExpression node, final Object data) { return node.jjtGetChild(0).jjtAccept(this, data); } @@ -2029,7 +2029,7 @@ public class Interpreter extends InterpreterBase { protected Object visit(final ASTSwitchStatement node, final Object data) { final int count = node.jjtGetNumChildren(); Object value = node.jjtGetChild(0).jjtAccept(this, data); - int index = node.switchIndex(value); + final int index = node.switchIndex(value); if (index > 0) { for (int i = index; i < count; ++i) { try { 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 0068ea13..f51bc5b5 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/ScriptVisitor.java +++ b/src/main/java/org/apache/commons/jexl3/internal/ScriptVisitor.java @@ -18,7 +18,104 @@ package org.apache.commons.jexl3.internal; import org.apache.commons.jexl3.JexlExpression; import org.apache.commons.jexl3.JexlScript; -import org.apache.commons.jexl3.parser.*; +import org.apache.commons.jexl3.parser.ASTAddNode; +import org.apache.commons.jexl3.parser.ASTAndNode; +import org.apache.commons.jexl3.parser.ASTAnnotatedStatement; +import org.apache.commons.jexl3.parser.ASTAnnotation; +import org.apache.commons.jexl3.parser.ASTArguments; +import org.apache.commons.jexl3.parser.ASTArrayAccess; +import org.apache.commons.jexl3.parser.ASTArrayLiteral; +import org.apache.commons.jexl3.parser.ASTAssignment; +import org.apache.commons.jexl3.parser.ASTBitwiseAndNode; +import org.apache.commons.jexl3.parser.ASTBitwiseComplNode; +import org.apache.commons.jexl3.parser.ASTBitwiseOrNode; +import org.apache.commons.jexl3.parser.ASTBitwiseXorNode; +import org.apache.commons.jexl3.parser.ASTBlock; +import org.apache.commons.jexl3.parser.ASTBreak; +import org.apache.commons.jexl3.parser.ASTCaseExpression; +import org.apache.commons.jexl3.parser.ASTCaseStatement; +import org.apache.commons.jexl3.parser.ASTConstructorNode; +import org.apache.commons.jexl3.parser.ASTContinue; +import org.apache.commons.jexl3.parser.ASTDecrementGetNode; +import org.apache.commons.jexl3.parser.ASTDefineVars; +import org.apache.commons.jexl3.parser.ASTDivNode; +import org.apache.commons.jexl3.parser.ASTDoWhileStatement; +import org.apache.commons.jexl3.parser.ASTEQNode; +import org.apache.commons.jexl3.parser.ASTEQSNode; +import org.apache.commons.jexl3.parser.ASTERNode; +import org.apache.commons.jexl3.parser.ASTEWNode; +import org.apache.commons.jexl3.parser.ASTEmptyFunction; +import org.apache.commons.jexl3.parser.ASTExtendedLiteral; +import org.apache.commons.jexl3.parser.ASTFalseNode; +import org.apache.commons.jexl3.parser.ASTForeachStatement; +import org.apache.commons.jexl3.parser.ASTFunctionNode; +import org.apache.commons.jexl3.parser.ASTGENode; +import org.apache.commons.jexl3.parser.ASTGTNode; +import org.apache.commons.jexl3.parser.ASTGetDecrementNode; +import org.apache.commons.jexl3.parser.ASTGetIncrementNode; +import org.apache.commons.jexl3.parser.ASTIdentifier; +import org.apache.commons.jexl3.parser.ASTIdentifierAccess; +import org.apache.commons.jexl3.parser.ASTIfStatement; +import org.apache.commons.jexl3.parser.ASTIncrementGetNode; +import org.apache.commons.jexl3.parser.ASTInstanceOf; +import org.apache.commons.jexl3.parser.ASTJexlScript; +import org.apache.commons.jexl3.parser.ASTJxltLiteral; +import org.apache.commons.jexl3.parser.ASTLENode; +import org.apache.commons.jexl3.parser.ASTLTNode; +import org.apache.commons.jexl3.parser.ASTMapEntry; +import org.apache.commons.jexl3.parser.ASTMapLiteral; +import org.apache.commons.jexl3.parser.ASTMethodNode; +import org.apache.commons.jexl3.parser.ASTModNode; +import org.apache.commons.jexl3.parser.ASTMulNode; +import org.apache.commons.jexl3.parser.ASTNENode; +import org.apache.commons.jexl3.parser.ASTNESNode; +import org.apache.commons.jexl3.parser.ASTNEWNode; +import org.apache.commons.jexl3.parser.ASTNRNode; +import org.apache.commons.jexl3.parser.ASTNSWNode; +import org.apache.commons.jexl3.parser.ASTNotInstanceOf; +import org.apache.commons.jexl3.parser.ASTNotNode; +import org.apache.commons.jexl3.parser.ASTNullLiteral; +import org.apache.commons.jexl3.parser.ASTNullpNode; +import org.apache.commons.jexl3.parser.ASTNumberLiteral; +import org.apache.commons.jexl3.parser.ASTOrNode; +import org.apache.commons.jexl3.parser.ASTQualifiedIdentifier; +import org.apache.commons.jexl3.parser.ASTRangeNode; +import org.apache.commons.jexl3.parser.ASTReference; +import org.apache.commons.jexl3.parser.ASTReferenceExpression; +import org.apache.commons.jexl3.parser.ASTRegexLiteral; +import org.apache.commons.jexl3.parser.ASTReturnStatement; +import org.apache.commons.jexl3.parser.ASTSWNode; +import org.apache.commons.jexl3.parser.ASTSetAddNode; +import org.apache.commons.jexl3.parser.ASTSetAndNode; +import org.apache.commons.jexl3.parser.ASTSetDivNode; +import org.apache.commons.jexl3.parser.ASTSetLiteral; +import org.apache.commons.jexl3.parser.ASTSetModNode; +import org.apache.commons.jexl3.parser.ASTSetMultNode; +import org.apache.commons.jexl3.parser.ASTSetOrNode; +import org.apache.commons.jexl3.parser.ASTSetShiftLeftNode; +import org.apache.commons.jexl3.parser.ASTSetShiftRightNode; +import org.apache.commons.jexl3.parser.ASTSetShiftRightUnsignedNode; +import org.apache.commons.jexl3.parser.ASTSetSubNode; +import org.apache.commons.jexl3.parser.ASTSetXorNode; +import org.apache.commons.jexl3.parser.ASTShiftLeftNode; +import org.apache.commons.jexl3.parser.ASTShiftRightNode; +import org.apache.commons.jexl3.parser.ASTShiftRightUnsignedNode; +import org.apache.commons.jexl3.parser.ASTSizeFunction; +import org.apache.commons.jexl3.parser.ASTStringLiteral; +import org.apache.commons.jexl3.parser.ASTSubNode; +import org.apache.commons.jexl3.parser.ASTSwitchExpression; +import org.apache.commons.jexl3.parser.ASTSwitchStatement; +import org.apache.commons.jexl3.parser.ASTTernaryNode; +import org.apache.commons.jexl3.parser.ASTThrowStatement; +import org.apache.commons.jexl3.parser.ASTTrueNode; +import org.apache.commons.jexl3.parser.ASTTryResources; +import org.apache.commons.jexl3.parser.ASTTryStatement; +import org.apache.commons.jexl3.parser.ASTUnaryMinusNode; +import org.apache.commons.jexl3.parser.ASTUnaryPlusNode; +import org.apache.commons.jexl3.parser.ASTVar; +import org.apache.commons.jexl3.parser.ASTWhileStatement; +import org.apache.commons.jexl3.parser.JexlNode; +import org.apache.commons.jexl3.parser.ParserVisitor; /** * Concrete visitor base, used for feature and operator controllers. 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 990045cc..e967d541 100644 --- a/src/main/java/org/apache/commons/jexl3/internal/TemplateScript.java +++ b/src/main/java/org/apache/commons/jexl3/internal/TemplateScript.java @@ -124,7 +124,7 @@ public final class TemplateScript implements JxltEngine.Template { * @param blocks the list of blocks * @return the script source */ - private static String callerScript(Block[] blocks) { + private static String callerScript(final Block[] blocks) { final StringBuilder strb = new StringBuilder(); int nuexpr = 0; int line = 1; @@ -197,7 +197,7 @@ public final class TemplateScript implements JxltEngine.Template { // create the caller script final Block[] blocks = jxlt.readTemplate(prefix, reader).toArray(new Block[0]); int verbatims = 0; - for(Block b : blocks) { + for(final Block b : blocks) { if (BlockType.VERBATIM == b.getType()) { verbatims += 1; } @@ -206,7 +206,7 @@ public final class TemplateScript implements JxltEngine.Template { // allow lambda defining params final JexlInfo info = jexlInfo == null ? jexl.createInfo() : jexlInfo; final Scope scope = parms == null ? null : new Scope(null, parms); - ASTJexlScript callerScript = jexl.jxltParse(info.at(1, 1), false, scriptSource, scope).script(); + final ASTJexlScript callerScript = jexl.jxltParse(info.at(1, 1), false, scriptSource, scope).script(); // seek the map of expression number to scope so we can parse Unified // expression blocks with the appropriate symbols final JexlNode.Info[] callSites = new JexlNode.Info[verbatims]; diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTCaseExpression.java b/src/main/java/org/apache/commons/jexl3/parser/ASTCaseExpression.java index fdbd2ec5..50535a14 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTCaseExpression.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTCaseExpression.java @@ -19,12 +19,12 @@ package org.apache.commons.jexl3.parser; public class ASTCaseExpression extends ASTCaseStatement { - public ASTCaseExpression(int id) { + public ASTCaseExpression(final int id) { super(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/ASTCaseStatement.java b/src/main/java/org/apache/commons/jexl3/parser/ASTCaseStatement.java index 6a0d9633..1a87f007 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTCaseStatement.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTCaseStatement.java @@ -28,16 +28,16 @@ public class ASTCaseStatement extends JexlNode { /** The values of the case statement. */ protected List<Object> values = Collections.emptyList(); - public ASTCaseStatement(int id) { + public ASTCaseStatement(final int id) { super(id); } @Override - public Object jjtAccept(ParserVisitor visitor, Object data) { + public Object jjtAccept(final ParserVisitor visitor, final Object data) { return visitor.visit(this, data); } - public void setValue(Object value) { + public void setValue(final Object value) { if (value == null) { this.values = Collections.emptyList(); } else { @@ -45,7 +45,7 @@ public class ASTCaseStatement extends JexlNode { } } - public void setValues(List<Object> values) { + public void setValues(final List<Object> values) { if (values == null) { this.values = Collections.emptyList(); } else if (values.size() == 1) { 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 59f9972d..2fdc54cc 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessJxlt.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTIdentifierAccessJxlt.java @@ -55,9 +55,9 @@ public class ASTIdentifierAccessJxlt extends ASTIdentifierAccess implements Jexl public void setIdentifier(final String src, final Scope scope) { super.setIdentifier(src); if (src != null && !src.isEmpty()) { - JexlEngine jexl = JexlEngine.getThreadEngine(); + final JexlEngine jexl = JexlEngine.getThreadEngine(); if (jexl != null) { - JxltEngine jxlt = jexl.createJxltEngine(); + final JxltEngine jxlt = jexl.createJxltEngine(); if (jxlt instanceof TemplateEngine) { this.jxltExpression = ((TemplateEngine) jxlt).createExpression(jexlInfo(), src, scope); } 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 fda769c5..e39596c5 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTJxltLiteral.java @@ -68,9 +68,9 @@ public final class ASTJxltLiteral extends JexlNode implements JexlNode.JxltHandl void setLiteral(final String src, final Scope scope) { this.literal = src; if (src != null && !src.isEmpty()) { - JexlEngine jexl = JexlEngine.getThreadEngine(); + final JexlEngine jexl = JexlEngine.getThreadEngine(); if (jexl != null) { - JxltEngine jxlt = jexl.createJxltEngine(); + final JxltEngine jxlt = jexl.createJxltEngine(); if (jxlt instanceof TemplateEngine) { this.jxltExpression = ((TemplateEngine) jxlt).createExpression(jexlInfo(), src, scope); } diff --git a/src/main/java/org/apache/commons/jexl3/parser/ASTSwitchExpression.java b/src/main/java/org/apache/commons/jexl3/parser/ASTSwitchExpression.java index 7e75462c..c7413b89 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTSwitchExpression.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTSwitchExpression.java @@ -18,12 +18,12 @@ package org.apache.commons.jexl3.parser; public class ASTSwitchExpression extends ASTSwitchStatement { - public ASTSwitchExpression(int id) { + public ASTSwitchExpression(final int id) { super(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/ASTSwitchStatement.java b/src/main/java/org/apache/commons/jexl3/parser/ASTSwitchStatement.java index 6ea12992..a42b55f3 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/ASTSwitchStatement.java +++ b/src/main/java/org/apache/commons/jexl3/parser/ASTSwitchStatement.java @@ -31,12 +31,12 @@ public class ASTSwitchStatement extends JexlNode { */ protected Map<Object, Integer> cases = Collections.emptyMap(); - public ASTSwitchStatement(int id) { + public ASTSwitchStatement(final int id) { super(id); } @Override - public Object jjtAccept(ParserVisitor visitor, Object data) { + public Object jjtAccept(final ParserVisitor visitor, final Object data) { return visitor.visit(this, data); } @@ -50,9 +50,10 @@ public class ASTSwitchStatement extends JexlNode { */ public List<Object>[] getCasesList() { @SuppressWarnings("unchecked") + final List<Object>[] list = (List<Object>[]) new List[jjtGetNumChildren() -1]; - for (Map.Entry<Object, Integer> entry : cases.entrySet()) { - int index = entry.getValue(); + for (final Map.Entry<Object, Integer> entry : cases.entrySet()) { + final int index = entry.getValue(); if (index < 0 || index >= list.length) { throw new IndexOutOfBoundsException("switch index out of bounds: " + index); } @@ -66,7 +67,7 @@ public class ASTSwitchStatement extends JexlNode { } @SuppressWarnings("unchecked") - public void setCases(Map cases) { + public void setCases(final Map cases) { this.cases = cases == null ? Collections.emptyMap() : (Map<Object, Integer>) cases; } @@ -74,8 +75,8 @@ public class ASTSwitchStatement extends JexlNode { return cases; } - public int switchIndex(Object value) { - Object code = JexlParser.switchCode(value); + public int switchIndex(final Object value) { + final Object code = JexlParser.switchCode(value); Integer index = cases.get(code); if (index == null) { index = cases.get(JexlParser.DFLT); @@ -95,16 +96,15 @@ public class ASTSwitchStatement extends JexlNode { private boolean defaultDefined = false; private final Map<Object, Integer> dispatch = new LinkedHashMap<>(); - void defineCase(JexlParser.SwitchSet constants) throws ParseException { + void defineCase(final JexlParser.SwitchSet constants) throws ParseException { if (constants.isEmpty()) { if (defaultDefined) { throw new ParseException("default clause is already defined"); - } else { - defaultDefined = true; - dispatch.put(JexlParser.DFLT, nswitch); } + defaultDefined = true; + dispatch.put(JexlParser.DFLT, nswitch); } else { - for (Object constant : constants) { + for (final Object constant : constants) { if (dispatch.put(constant == null ? JexlParser.NIL : constant, nswitch) != null) { throw new ParseException("duplicate case in switch statement for value: " + constant); } @@ -114,7 +114,7 @@ public class ASTSwitchStatement extends JexlNode { nswitch += 1; } - void defineSwitch(ASTSwitchStatement statement) { + void defineSwitch(final ASTSwitchStatement statement) { statement.cases = dispatch; } } 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 c2ba77a8..9d3430a3 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java +++ b/src/main/java/org/apache/commons/jexl3/parser/JexlParser.java @@ -202,18 +202,16 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse protected final List<String> imports; - void addImport(String importName) { - if (importName != null && !importName.isEmpty()) { - if (!imports.contains(importName)) { - imports.add(importName); - } + void addImport(final String importName) { + if (importName != null && !importName.isEmpty() && !imports.contains(importName)) { + imports.add(importName); } } - Object resolveConstant(String name) { + Object resolveConstant(final String name) { JexlUberspect.ClassConstantResolver resolver = fqcnResolver.get(); if (resolver == null) { - JexlEngine engine = JexlEngine.getThreadEngine(); + final JexlEngine engine = JexlEngine.getThreadEngine(); if (engine instanceof JexlUberspect.ConstantResolverFactory) { resolver = ((JexlUberspect.ConstantResolverFactory) engine).createConstantResolver(imports); fqcnResolver.set(resolver); @@ -273,7 +271,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * This is the constructor used to create a parser for template expressions. * </p> */ - protected JexlParser(JexlParser parser) { + protected JexlParser(final JexlParser parser) { this.info = null; this.source = null; if (parser != null) { @@ -333,7 +331,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * @param value the value * @return the encoded value, which is either the value itself, or NAN (for NaN) or NIL (for null) */ - static Object switchCode(Object value) { + static Object switchCode(final Object value) { if (value == null) { return NIL; } @@ -348,7 +346,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * @param value an encoded value, which is either a value or NAN (for NaN) or NIL (for null) * @return the decoded value */ - static Object switchDecode(Object value) { + static Object switchDecode(final Object value) { if (value == NIL) { return null; } @@ -370,8 +368,8 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * Adds a collection of values to the set. * @param values the values to add */ - void addAll(Collection<Object> values) { - for (Object value : values) { + void addAll(final Collection<Object> values) { + for (final Object value : values) { add(value); } } @@ -380,8 +378,8 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * Adds a value to the set. * @param value the value to add */ - void add(Object value) { - Object code = switchCode(value); + void add(final Object value) { + final Object code = switchCode(value); if (!values.add(code)) { throw new JexlException.Parsing(info, "duplicate constant value: " + value); } @@ -569,7 +567,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse // function is const fun... if (declareSymbol(symbol)) { scope.addLexical(symbol); - LexicalUnit block = getUnit(); + final LexicalUnit block = getUnit(); block.setConstant(symbol); } else { if (getFeatures().isLexical()) { @@ -602,7 +600,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse final int symbol = scope.declareParameter(identifier); // not sure how declaring a parameter could fail... // lexical feature error - LexicalUnit block = getUnit(); + final LexicalUnit block = getUnit(); if (!block.declareSymbol(symbol)) { if (lexical || getFeatures().isLexical()) { final JexlInfo xinfo = info.at(token.beginLine, token.beginColumn); @@ -682,7 +680,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse break; } } - LexicalUnit block = getUnit(); + final LexicalUnit block = getUnit(); return block == null || block.declareSymbol(symbol); } @@ -725,8 +723,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse } else if (lexical) { scope.addLexical(symbol); if (constant) { - LexicalUnit block = getUnit(); - block.setConstant(symbol); + getUnit().setConstant(symbol); } } } @@ -781,7 +778,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse */ private boolean isConstant(final int symbol) { if (symbol >= 0) { - LexicalUnit block = getUnit(); + final LexicalUnit block = getUnit(); if (block != null && block.hasSymbol(symbol)) { return block.isConstant(symbol); } @@ -892,7 +889,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * @return true if a variable with that name was declared */ protected boolean isVariable(final String name) { - Scope scope = scopeReference.get(); + final Scope scope = scopeReference.get(); return scope != null && scope.getSymbol(name) != null; } @@ -905,10 +902,10 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * @param semicolon the semicolon token kind * @return true if statement is ambiguous, false otherwise */ - protected boolean isAmbiguousStatement(int semicolon) { + protected boolean isAmbiguousStatement(final int semicolon) { if (autoSemicolon) { - Token current = getToken(0); - Token next = getToken(1); + final Token current = getToken(0); + final Token next = getToken(1); if (current != null && next != null && current.endLine != next.beginLine) { // if the next token is on a different line, no ambiguity reported return false; @@ -934,7 +931,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse } final ASTJexlScript script = (ASTJexlScript) node; // reaccess in case local variables have been declared - Scope scope = scopeReference.get(); + final Scope scope = scopeReference.get(); if (script.getScope() != scope) { script.setScope(scope); } @@ -967,7 +964,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * @return the parsed tree */ @Override - public ASTJexlScript jxltParse(JexlInfo info, JexlFeatures features, String src, Scope scope) { + public ASTJexlScript jxltParse(final JexlInfo info, final JexlFeatures features, final String src, final Scope scope) { return new Parser(this).parse(info, features, src, scope); } @@ -1002,7 +999,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * Pops back to previous local variable scope. */ protected void popScope() { - Scope scope = scopes.isEmpty() ? null : scopes.pop(); + final Scope scope = scopes.isEmpty() ? null : scopes.pop(); scopeReference.set(scope); if (!loopCounts.isEmpty()) { loopCount.set(loopCounts.pop()); @@ -1014,7 +1011,7 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * @param unit restores the previous lexical scope */ protected void popUnit(final LexicalUnit unit) { - LexicalUnit block = blockReference.get(); + final LexicalUnit block = blockReference.get(); if (block == unit){ blockScopes.remove(unit); blockReference.set(blocks.isEmpty()? null : blocks.pop()); @@ -1039,9 +1036,9 @@ public abstract class JexlParser extends StringParser implements JexlScriptParse * @param unit the new lexical unit */ protected void pushUnit(final LexicalUnit unit) { - Scope scope = scopeReference.get(); + final Scope scope = scopeReference.get(); blockScopes.put(unit, scope); - LexicalUnit block = blockReference.get(); + final LexicalUnit block = blockReference.get(); if (block != null) { blocks.push(block); } diff --git a/src/main/java/org/apache/commons/jexl3/parser/JexlScriptParser.java b/src/main/java/org/apache/commons/jexl3/parser/JexlScriptParser.java index d857e200..c2a086d7 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/JexlScriptParser.java +++ b/src/main/java/org/apache/commons/jexl3/parser/JexlScriptParser.java @@ -48,7 +48,7 @@ public interface JexlScriptParser { * @return the parsed tree * @throws JexlException if any error occurred during parsing */ - default ASTJexlScript jxltParse(JexlInfo info, JexlFeatures features, String src, Scope scope) { + default ASTJexlScript jxltParse(final JexlInfo info, final JexlFeatures features, final String src, final Scope scope) { return parse(info, features, src, scope); } 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 4ebc147b..1a0acdbe 100644 --- a/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java +++ b/src/main/java/org/apache/commons/jexl3/parser/NumberParser.java @@ -47,7 +47,7 @@ public final class NumberParser implements Serializable { this(null); } - public NumberParser(Number number) { + public NumberParser(final Number number) { if (number != null) { this.literal = number; this.clazz = number.getClass();
