Skip to content
Permalink
Browse files
fix code smells; fix typos; do language level migration to java8;
  • Loading branch information
XenoAmess committed May 25, 2020
1 parent a90b696 commit f398ed89a787ef142a5db8bfb65b96401ad7d5c1
Showing 75 changed files with 356 additions and 475 deletions.
@@ -30,5 +30,5 @@ matrix:
allow_failures:
- jdk: openjdk-ea
after_success:
- mvn -V -B -e clean cobertura:cobertura coveralls:report
- mvn clean test jacoco:report coveralls:report

@@ -50,7 +50,7 @@ Getting Started

+ Make sure you have a [JIRA account](https://issues.apache.org/jira/).
+ Make sure you have a [GitHub account](https://github.com/signup/free).
+ If you're planning to implement a new feature it makes sense to discuss you're changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons JEXL's scope.
+ If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons JEXL's scope.
+ Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist.
+ Clearly describe the issue including steps to reproduce when it is a bug.
+ Make sure you fill in the earliest version that you know has the issue.
@@ -23,7 +23,6 @@
<version>50</version>
</parent>

<groupId>org.apache.commons</groupId>
<artifactId>commons-jexl3</artifactId>
<version>3.2-SNAPSHOT</version>
<name>Apache Commons JEXL</name>
@@ -609,21 +609,13 @@ protected String readSource(final File file) {
if (file == null) {
throw new NullPointerException("source file is null");
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), getCharset()));
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),
getCharset()))) {
return toString(reader);
} catch (IOException xio) {
throw new JexlException(createInfo(file.toString(), 1, 1), "could not read source File", xio);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException xignore) {
// cant do much
}
}
}
// cant do much
}

/**
@@ -636,20 +628,10 @@ protected String readSource(final URL url) {
if (url == null) {
throw new NullPointerException("source URL is null");
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(url.openStream(), getCharset()));
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), getCharset()))) {
return toString(reader);
} catch (IOException xio) {
throw new JexlException(createInfo(url.toString(), 1, 1), "could not read source URL", xio);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException xignore) {
// cant do much
}
}
}
}
}
@@ -205,7 +205,7 @@ private static Throwable unwrap(Throwable xthrow) {
* @return the info to use
*/
private static JexlInfo merge(JexlInfo info, JavaccError cause) {
JexlInfo dbgn = info != null ? info : null;
JexlInfo dbgn = info;
if (cause == null || cause.getLine() < 0) {
return dbgn;
} else if (dbgn == null) {
@@ -488,7 +488,7 @@ protected String detailedMessage() {
/**
* The various type of variable issues.
*/
public static enum VariableIssue {
public enum VariableIssue {
/** The variable is undefined. */
UNDEFINED,
/** The variable is already declared. */
@@ -16,10 +16,7 @@
*/
package org.apache.commons.jexl3;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
import java.util.*;

/**
* A set of language feature options.
@@ -139,8 +136,7 @@ public boolean equals(Object obj) {
if (this.flags != other.flags) {
return false;
}
if (this.reservedNames != other.reservedNames
&& (this.reservedNames == null || !this.reservedNames.equals(other.reservedNames))) {
if (!Objects.equals(this.reservedNames, other.reservedNames)) {
return false;
}
return true;
@@ -19,10 +19,7 @@
import org.apache.commons.jexl3.JexlArithmetic;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
* Helper class to create typed arrays.
@@ -114,9 +111,7 @@ public Object create(boolean extended) {
if (untyped != null) {
if (extended) {
List<Object> list = new ArrayList<Object>(added);
for(int i = 0; i < added; ++i) {
list.add(untyped[i]);
}
list.addAll(Arrays.asList(untyped).subList(0, added));
return list;
}
// convert untyped array to the common class if not Object.class
@@ -19,6 +19,8 @@
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.parser.ASTJexlLambda;

import java.util.Objects;

/**
* A Script closure.
*/
@@ -72,10 +74,10 @@ public boolean equals(Object obj) {
if (this.jexl != other.jexl) {
return false;
}
if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) {
if (!Objects.equals(this.source, other.source)) {
return false;
}
if (this.frame != other.frame && (this.frame == null || !this.frame.equals(other.frame))) {
if (!Objects.equals(this.frame, other.frame)) {
return false;
}
return true;
@@ -260,11 +260,7 @@ public void setIndentation(int level) {
* @return this debugger instance
*/
public Debugger indentation(int level) {
if (level <= 0) {
indent = 0;
} else {
indent = level;
}
indent = Math.max(level, 0);
indentLevel = 0;
return this;
}
@@ -788,7 +788,7 @@ protected Object visit(ASTDoWhileStatement node, Object data) {

@Override
protected Object visit(ASTAndNode node, 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.
@@ -1853,12 +1853,8 @@ public Object call() throws Exception {
processed[0] = true;
try {
return processAnnotation(stmt, index + 1, data);
} catch(JexlException.Return xreturn) {
} catch(JexlException.Return | JexlException.Continue | JexlException.Break xreturn) {
return xreturn;
} catch(JexlException.Break xbreak) {
return xbreak;
} catch(JexlException.Continue xcontinue) {
return xcontinue;
}
}
};
@@ -65,7 +65,7 @@ public boolean hasSymbol(int symbol) {
if (symbol < LONGBITS) {
return (symbols & (1L << symbol)) != 0L;
} else {
return moreSymbols == null ? false : moreSymbols.get(symbol - LONGBITS);
return moreSymbols != null && moreSymbols.get(symbol - LONGBITS);
}
}

@@ -27,6 +27,7 @@

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* <p>A JexlScript implementation.</p>
@@ -168,7 +169,7 @@ public boolean equals(Object obj) {
if (this.jexl != other.jexl) {
return false;
}
if ((this.source == null) ? (other.source != null) : !this.source.equals(other.source)) {
if (!Objects.equals(this.source, other.source)) {
return false;
}
return true;
@@ -18,6 +18,8 @@

import org.apache.commons.jexl3.JexlFeatures;

import java.util.Objects;

/**
* Maintains the set of allowed features associated with a script/expression source.
* <p>This is meant for caching scripts using their 'source' as key but still distinguishing
@@ -69,11 +71,10 @@ public boolean equals(Object obj) {
return false;
}
final Source other = (Source) obj;
if (this.features != other.features
&& (this.features == null || !this.features.equals(other.features))) {
if (!Objects.equals(this.features, other.features)) {
return false;
}
if ((this.str == null) ? (other.str != null) : !this.str.equals(other.str)) {
if (!Objects.equals(this.str, other.str)) {
return false;
}
return true;
@@ -641,8 +641,7 @@ protected TemplateExpression prepare(Interpreter interpreter) {
final ExpressionBuilder builder = new ExpressionBuilder(size);
// tracking whether prepare will return a different expression
boolean eq = true;
for (int e = 0; e < size; ++e) {
TemplateExpression expr = exprs[e];
for (TemplateExpression expr : exprs) {
TemplateExpression prepared = expr.prepare(interpreter);
// add it if not null
if (prepared != null) {
@@ -660,8 +659,8 @@ protected Object evaluate(Interpreter interpreter) {
Object value;
// common case: evaluate all expressions & concatenate them as a string
StringBuilder strb = new StringBuilder();
for (int e = 0; e < size; ++e) {
value = exprs[e].evaluate(interpreter);
for (TemplateExpression expr : exprs) {
value = expr.evaluate(interpreter);
if (value != null) {
strb.append(value.toString());
}
@@ -161,9 +161,9 @@ private void printComposite(TemplateEngine.CompositeExpression composite) {
TemplateEngine.TemplateExpression[] cexprs = composite.exprs;
final int size = cexprs.length;
Object value;
for (int e = 0; e < size; ++e) {
value = cexprs[e].evaluate(this);
doPrint(cexprs[e].getInfo(), value);
for (TemplateExpression cexpr : cexprs) {
value = cexpr.evaluate(this);
doPrint(cexpr.getInfo(), value);
}
}

@@ -69,10 +69,13 @@ public TemplateScript(TemplateEngine engine, JexlInfo info, String directive, Re
if (directive == null) {
throw new NullPointerException("null prefix");
}
if (Character.toString(engine.getImmediateChar()).equals(directive)
|| (Character.toString(engine.getImmediateChar()) + "{").equals(directive)
|| Character.toString(engine.getDeferredChar()).equals(directive)
|| (Character.toString(engine.getDeferredChar()) + "{").equals(directive)) {
final String engineImmediateCharString = Character.toString(engine.getImmediateChar());
final String engineDeferredCharString = Character.toString(engine.getDeferredChar());

if (engineImmediateCharString.equals(directive)
|| engineDeferredCharString.equals(directive)
|| (engineImmediateCharString + "{").equals(directive)
|| (engineDeferredCharString + "{").equals(directive)) {
throw new IllegalArgumentException(directive + ": is not a valid directive pattern");
}
if (reader == null) {
@@ -126,12 +129,11 @@ public TemplateScript(TemplateEngine engine, JexlInfo info, String directive, Re
// jexl:print(...) expression counter
int jpe = 0;
// create the exprs using the intended scopes
for (int b = 0; b < blocks.size(); ++b) {
Block block = blocks.get(b);
for (Block block : blocks) {
if (block.getType() == BlockType.VERBATIM) {
JexlNode.Info ji = minfo.get(jpe);
uexprs.add(
jxlt.parseExpression(ji, block.getBody(), scopeOf(ji))
jxlt.parseExpression(ji, block.getBody(), scopeOf(ji))
);
jpe += 1;
}
@@ -159,7 +161,7 @@ public TemplateScript(TemplateEngine engine, JexlInfo info, String directive, Re
script = theScript;
exprs = theExprs;
}

/**
* Gets the scope from an info.
* @param info the node info
@@ -175,7 +177,7 @@ private static Scope scopeOf(JexlNode.Info info) {
}
return null;
}

/**
* Collects the scope surrounding a call to jexl:print(i).
* <p>This allows to later parse the blocks with the known symbols
@@ -245,7 +247,7 @@ public String asString() {
}
return strb.toString();
}

@Override
public TemplateScript prepare(JexlContext context) {
final Engine jexl = jxlt.getEngine();
@@ -53,7 +53,7 @@ static java.lang.reflect.Method initMarker(Class<?> clazz, String name, Class<?>
* @return an Integer if it can be converted, null otherwise
*/
static Integer castInteger(Object arg) {
return arg instanceof Number? Integer.valueOf(((Number) arg).intValue()) : null;
return arg instanceof Number? ((Number) arg).intValue() : null;
}

/**
@@ -68,6 +68,7 @@ public ArrayIterator(Object arr) {
*
* @return The next object in the array.
*/
@Override
public Object next() {
if (pos < size) {
return Array.get(array, pos++);
@@ -82,13 +83,15 @@ public Object next() {
*
* @return Whether there is another element.
*/
@Override
public boolean hasNext() {
return (pos < size);
}

/**
* No op--merely added to satify the <code>Iterator</code> interface.
*/
@Override
public void remove() {
throw new UnsupportedOperationException();
}

0 comments on commit f398ed8

Please sign in to comment.