Author: henrib
Date: Mon Jul 18 11:12:35 2011
New Revision: 1147811
URL: http://svn.apache.org/viewvc?rev=1147811&view=rev
Log:
Checkstyle, PMD, Javadoc, etc
Modified:
commons/proper/jexl/trunk/pom.xml
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/DebugInfo.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlInfo.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/NamespaceResolver.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/ReadonlyContext.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/Introspector.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlParser.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java
commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java
Modified: commons/proper/jexl/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/pom.xml?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
--- commons/proper/jexl/trunk/pom.xml (original)
+++ commons/proper/jexl/trunk/pom.xml Mon Jul 18 11:12:35 2011
@@ -254,10 +254,14 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
- <version>2.4</version>
+ <version>2.5.1</version>
<configuration>
<instrumentation>
+ <ignores>
+ <ignore>**/generated-sources/**/*</ignore>
+ </ignores>
<excludes>
+ <exclude>**/generated-sources/**/*</exclude>
<exclude>org/apache/commons/jexl2/parser/*.class</exclude>
<exclude>org/apache/commons/jexl2/**/*Test.class</exclude>
</excludes>
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/DebugInfo.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/DebugInfo.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/DebugInfo.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/DebugInfo.java
Mon Jul 18 11:12:35 2011
@@ -18,9 +18,8 @@ package org.apache.commons.jexl2;
/**
- * Little class to carry in info such as a url/file name, line and column for
- * information error reporting from the uberspector implementations.
- * @version $Id$
+ * Helper class to carry in info such as a url/file name, line and column for
+ * debugging information reporting.
*/
public class DebugInfo implements JexlInfo {
/** line number. */
@@ -63,6 +62,11 @@ public class DebugInfo implements JexlIn
public String debugString() {
return toString();
}
+
+ /** {@inheritDoc} */
+ public DebugInfo debugInfo() {
+ return this;
+ }
/**
* Gets the file/script/url name.
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Interpreter.java
Mon Jul 18 11:12:35 2011
@@ -127,7 +127,7 @@ public class Interpreter implements Pars
public Interpreter(JexlEngine jexl, JexlContext aContext) {
this(jexl, aContext, !jexl.isLenient(), jexl.isSilent());
}
-
+
/**
* Creates an interpreter.
* @param jexl the engine creating this interpreter
@@ -170,7 +170,7 @@ public class Interpreter implements Pars
public boolean isStrict() {
return this.strict;
}
-
+
/**
* Checks whether this interpreter throws JexlException when encountering
errors.
* @return true if silent, false otherwise
@@ -260,7 +260,7 @@ public class Interpreter implements Pars
*/
protected JexlNode findNullOperand(RuntimeException xrt, JexlNode node,
Object left, Object right) {
if (xrt instanceof NullPointerException
- && (Object) JexlException.NULL_OPERAND == xrt.getMessage()) {
+ && (Object) JexlException.NULL_OPERAND == xrt.getMessage()) {
if (left == null) {
return node.jjtGetChild(0);
}
@@ -311,7 +311,7 @@ public class Interpreter implements Pars
}
return cancelled;
}
-
+
/**
* Resolves a namespace, eventually allocating an instance using context
as constructor argument.
* The lifetime of such instances span the current expression or script
evaluation.
@@ -571,7 +571,7 @@ public class Interpreter implements Pars
}
try {
context.set(String.valueOf(property), right);
- } catch(UnsupportedOperationException xsupport) {
+ } catch (UnsupportedOperationException xsupport) {
throw new JexlException(node, "context is readonly",
xsupport);
}
return right;
@@ -1388,7 +1388,7 @@ public class Interpreter implements Pars
if (node == null) {
throw new RuntimeException(xany);
} else {
- JexlException xjexl = new JexlException(node, "get object
property error", xany);
+ JexlException xjexl = new JexlException.Variable(node,
attribute.toString());
if (strict) {
throw xjexl;
}
@@ -1469,14 +1469,14 @@ public class Interpreter implements Pars
}
}
if (xjexl == null) {
- String error = "unable to set object property"
- + ", class: " + object.getClass().getName()
- + ", property: " + attribute
- + ", argument: " + value.getClass().getSimpleName();
if (node == null) {
+ String error = "unable to set object property"
+ + ", class: " + object.getClass().getName()
+ + ", property: " + attribute
+ + ", argument: " + value.getClass().getSimpleName();
throw new UnsupportedOperationException(error);
}
- xjexl = new JexlException(node, error, null);
+ xjexl = new JexlException.Variable(node, attribute.toString());
}
if (strict) {
throw xjexl;
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
Mon Jul 18 11:12:35 2011
@@ -429,7 +429,7 @@ public class JexlEngine {
*/
public Expression createExpression(String expression, JexlInfo info) {
// Parse the expression
- ASTJexlScript tree = parse(expression, info);
+ ASTJexlScript tree = parse(expression, info, null);
if (tree.jjtGetNumChildren() > 1) {
logger.warn("The JEXL Expression created will be a reference"
+ " to the first expression from the supplied script: \""
+ expression + "\" ");
@@ -976,6 +976,7 @@ public class JexlEngine {
* @param info debug information structure
* @return the parsed tree
* @throws JexlException if any error occured during parsing
+ * @deprecated
*/
protected ASTJexlScript parse(CharSequence expression, JexlInfo info) {
return parse(expression, info, null);
@@ -992,6 +993,7 @@ public class JexlEngine {
protected ASTJexlScript parse(CharSequence expression, JexlInfo info,
String[] names) {
String expr = cleanExpression(expression);
ASTJexlScript script = null;
+ DebugInfo dbgInfo = null;
synchronized (parser) {
if (cache != null) {
script = cache.get(expr);
@@ -1003,7 +1005,11 @@ public class JexlEngine {
Reader reader = new StringReader(expr);
// use first calling method of JexlEngine as debug info
if (info == null) {
- info = debugInfo();
+ dbgInfo = debugInfo();
+ } else if (info instanceof DebugInfo) {
+ dbgInfo = (DebugInfo) info;
+ } else {
+ dbgInfo = info.debugInfo();
}
Map<String, Integer> params = null;
if (names != null) {
@@ -1013,7 +1019,8 @@ public class JexlEngine {
}
parser.setNamedRegisters(params);
}
- script = parser.parse(reader, info);
+ script = parser.parse(reader, dbgInfo);
+ // reaccess in case local variables have been declared
params = parser.getNamedRegisters();
if (params != null) {
String[] registers = (new
ArrayList<String>(params.keySet())).toArray(new String[0]);
@@ -1023,9 +1030,9 @@ public class JexlEngine {
cache.put(expr, script);
}
} catch (TokenMgrError xtme) {
- throw new JexlException.Tokenization(info, expression, xtme);
+ throw new JexlException.Tokenization(dbgInfo, expression,
xtme);
} catch (ParseException xparse) {
- throw new JexlException.Parsing(info, expression, xparse);
+ throw new JexlException.Parsing(dbgInfo, expression, xparse);
} finally {
parser.setNamedRegisters(null);
}
@@ -1040,7 +1047,7 @@ public class JexlEngine {
* @param c column number
* @return a JexlInfo instance
*/
- protected JexlInfo createInfo(String fn, int l, int c) {
+ protected DebugInfo createInfo(String fn, int l, int c) {
return new DebugInfo(fn, l, c);
}
@@ -1050,8 +1057,8 @@ public class JexlEngine {
* not owned by JexlEngine, UnifiedJEXL or {Script,Expression}Factory.</p>
* @return an Info if debug is set, null otherwise
*/
- protected JexlInfo debugInfo() {
- JexlInfo info = null;
+ protected DebugInfo debugInfo() {
+ DebugInfo info = null;
if (debug) {
Throwable xinfo = new Throwable();
xinfo.fillInStackTrace();
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlException.java
Mon Jul 18 11:12:35 2011
@@ -40,7 +40,7 @@ public class JexlException extends Runti
public JexlException(JexlNode node, String msg) {
super(msg);
mark = node;
- info = node != null? node.getInfo() : null;
+ info = node != null? node.debugInfo() : null;
}
@@ -53,7 +53,7 @@ public class JexlException extends Runti
public JexlException(JexlNode node, String msg, Throwable cause) {
super(msg, cause);
mark = node;
- info = node != null? node.getInfo() : null;
+ info = node != null? node.debugInfo() : null;
}
/**
@@ -88,7 +88,7 @@ public class JexlException extends Runti
}
/**
- * The exception thrown when tokenization fails.
+ * Thrown when tokenization fails.
*/
public static class Tokenization extends JexlException {
/**
@@ -115,7 +115,7 @@ public class JexlException extends Runti
}
/**
- * The exception thrown parsing fails.
+ * Thrown when parsing fails.
*/
public static class Parsing extends JexlException {
/**
@@ -142,7 +142,7 @@ public class JexlException extends Runti
}
/**
- * The exception thrown when a variable is unknown.
+ * Thrown when a variable is unknown.
*/
public static class Variable extends JexlException {
/**
@@ -168,7 +168,7 @@ public class JexlException extends Runti
}
/**
- * The exception thrown when a method or ctor is unknown, ambiguous or
inaccessible.
+ * Thrown when a method or ctor is unknown, ambiguous or inaccessible.
*/
public static class Method extends JexlException {
/**
@@ -194,7 +194,7 @@ public class JexlException extends Runti
}
/**
- * The class of exceptions that will force the interpreter to return,
allways behaving in strict mode.
+ * Thrown to return a value.
*/
protected static class Return extends JexlException {
/** The returned value. */
@@ -218,7 +218,7 @@ public class JexlException extends Runti
}
/**
- * The class of exceptions used when the interpreter cancels a script
execution.
+ * Thrown to cancel a script execution.
*/
protected static class Cancel extends JexlException {
/**
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlInfo.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlInfo.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlInfo.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlInfo.java
Mon Jul 18 11:12:35 2011
@@ -26,4 +26,9 @@ public interface JexlInfo {
* @return a human readable string.
*/
String debugString();
+ /**
+ * Gets the underlying debugging information.
+ * @return a debug info instance
+ */
+ DebugInfo debugInfo();
}
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
Mon Jul 18 11:12:35 2011
@@ -26,8 +26,8 @@ public class JexlThreadedArithmetic exte
/** Holds the threaded version of some arithmetic features. */
static class Features {
- Features() {
- }
+ /** Default ctor. */
+ Features() {}
/** Whether this JexlArithmetic instance behaves in strict or lenient
mode. */
private Boolean lenient = null;
/** The big decimal math context. */
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/NamespaceResolver.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/NamespaceResolver.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/NamespaceResolver.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/NamespaceResolver.java
Mon Jul 18 11:12:35 2011
@@ -17,11 +17,12 @@
package org.apache.commons.jexl2;
/**
- * In JEXL, a namespace is an object that serves the purpose of encapsulating
functions; for instance,
- * the "math" namespace would be the proper object to expose functions like
"log(...)", "sinus(...)", etc.
*
* This interface declares how to resolve a namespace from its name; it is
used by the interpreter during evalutation.
- *
+ * <p>
+ * In JEXL, a namespace is an object that serves the purpose of encapsulating
functions; for instance,
+ * the "math" namespace would be the proper object to expose functions like
"log(...)", "sinus(...)", etc.
+ * </p>
* In expressions like "ns:function(...)", the resolver is called with
resolveNamespace("ns").
*/
public interface NamespaceResolver {
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/ReadonlyContext.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/ReadonlyContext.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/ReadonlyContext.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/ReadonlyContext.java
Mon Jul 18 11:12:35 2011
@@ -36,7 +36,11 @@ public final class ReadonlyContext imple
return wrapped.get(name);
}
- /** {@inheritDoc} */
+ /**
+ * Will throw an UnsupportedOperationException when called; the JexlEngine
deals with it appropriately.
+ * @param name the unused variable name
+ * @param value the unused variable value
+ */
public void set(String name, Object value) {
throw new UnsupportedOperationException("Not supported.");
}
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/Script.java
Mon Jul 18 11:12:35 2011
@@ -82,6 +82,8 @@ public interface Script {
/**
* Creates a Callable from this script.
+ * <p>This allows to submit it to an executor pool and provides support
for asynchronous calls.</p>
+ * <p>The interpreter will handle interruption/cancellation gracefully if
needed.</p>
* @param context the context
* @return the callable
*/
@@ -89,6 +91,8 @@ public interface Script {
/**
* Creates a Callable from this script.
+ * <p>This allows to submit it to an executor pool and provides support
for asynchronous calls.</p>
+ * <p>The interpreter will handle interruption/cancellation gracefully if
needed.</p>
* @param context the context
* @param args the script arguments
* @return the callable
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java
Mon Jul 18 11:12:35 2011
@@ -594,7 +594,7 @@ public final class UnifiedJEXL {
@Override
public Expression prepare(Interpreter interpreter) {
String value = interpreter.interpret(node).toString();
- JexlNode dnode = toNode(value, jexl.isDebug() ? node.getInfo() :
null);
+ JexlNode dnode = toNode(value, jexl.isDebug() ? node.debugInfo() :
null);
return new DeferredExpression(value, dnode, this);
}
@@ -803,7 +803,7 @@ public final class UnifiedJEXL {
* @throws JexlException if an error occur during parsing
*/
private JexlNode toNode(CharSequence expression) {
- return jexl.parse(expression, null);
+ return jexl.parse(expression, null, null);
}
/**
@@ -814,7 +814,7 @@ public final class UnifiedJEXL {
* @throws JexlException if an error occur during parsing
*/
private JexlNode toNode(CharSequence expression, JexlInfo info) {
- return jexl.parse(expression, info);
+ return jexl.parse(expression, info, null);
}
/**
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/Introspector.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/Introspector.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/Introspector.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/internal/Introspector.java
Mon Jul 18 11:12:35 2011
@@ -83,7 +83,7 @@ public class Introspector {
protected final IntrospectorBase base() {
IntrospectorBase intro = ref.get();
if (intro == null) {
- // double checked locking (fixed by Java 5 memory model).
+ // double checked locking is ok (fixed by Java 5 memory model).
synchronized(this) {
intro = ref.get();
if (intro == null) {
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlNode.java
Mon Jul 18 11:12:35 2011
@@ -43,7 +43,8 @@ public abstract class JexlNode extends S
super(p, id);
}
- public DebugInfo getInfo() {
+ /** {@inheritDoc} */
+ public DebugInfo debugInfo() {
JexlNode node = this;
while (node != null) {
if (node.value instanceof DebugInfo) {
@@ -56,7 +57,7 @@ public abstract class JexlNode extends S
/** {@inheritDoc} */
public String debugString() {
- DebugInfo info = getInfo();
+ DebugInfo info = debugInfo();
return info != null? info.debugString() : "";
}
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlParser.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlParser.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/JexlParser.java
Mon Jul 18 11:12:35 2011
@@ -18,13 +18,15 @@ package org.apache.commons.jexl2.parser;
import java.util.LinkedHashMap;
import java.util.Map;
+import org.apache.commons.jexl2.DebugInfo;
+import org.apache.commons.jexl2.JexlException;
/**
*
* @author henri
*/
public class JexlParser extends StringParser {
- /**
+ /**
* The map of named registers aka script parameters.
* Each parameter is associated to a register and is materialized as an
offset in the registers array used
* during evaluation.
@@ -41,7 +43,7 @@ public class JexlParser extends StringPa
public void setNamedRegisters(Map<String, Integer> registers) {
namedRegisters = registers;
}
-
+
/**
* Gets the map of registers used by this parser.
* <p>
@@ -56,7 +58,7 @@ public class JexlParser extends StringPa
/**
* Checks whether an identifier is a local variable or argument, ie stored
in a register.
- * @param node the identifier
+ * @param identifier the identifier
* @param image the identifier image
* @return the image
*/
@@ -69,7 +71,7 @@ public class JexlParser extends StringPa
}
return image;
}
-
+
/**
* Declares a local variable.
* <p>
@@ -91,7 +93,6 @@ public class JexlParser extends StringPa
identifier.image = image;
}
-
/**
* Default implementation does nothing but is overriden by generated code.
* @param top whether the identifier is beginning an l/r value
@@ -100,34 +101,33 @@ public class JexlParser extends StringPa
public void Identifier(boolean top) throws ParseException {
// Overriden by generated code
}
-
+
final public void Identifier() throws ParseException {
Identifier(false);
}
-
+
public Token getToken(int index) {
return null;
}
-
- void jjtreeOpenNodeScope(Node n) {}
+
+ void jjtreeOpenNodeScope(JexlNode n) {
+ }
+
/**
* Ambiguous statement detector.
* @param n the node
* @throws ParseException
*/
- void jjtreeCloseNodeScope(Node n) throws ParseException {
- if (n instanceof ASTAmbiguous && n.jjtGetNumChildren() > 0) {
- Token tok = this.getToken(0);
- StringBuilder strb = new StringBuilder("Ambiguous statement ");
- if (tok != null) {
- strb.append("@");
- strb.append(tok.beginLine);
- strb.append(":");
- strb.append(tok.beginColumn);
- }
- strb.append(", missing ';' between expressions");
- throw new ParseException(strb.toString());
- }
+ void jjtreeCloseNodeScope(JexlNode n) throws ParseException {
+ if (n instanceof ASTAmbiguous && n.jjtGetNumChildren() > 0) {
+ DebugInfo dbgInfo = null;
+ Token tok = this.getToken(0);
+ if (tok != null) {
+ dbgInfo = new DebugInfo(tok.image, tok.beginLine,
tok.beginColumn);
+ } else {
+ dbgInfo = n.debugInfo();
+ }
+ throw new JexlException.Parsing(dbgInfo, "Ambiguous statement,
missing ';' between expressions", null);
+ }
}
-
}
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/parser/StringParser.java
Mon Jul 18 11:12:35 2011
@@ -37,7 +37,7 @@ public class StringParser {
/** Default constructor. */
public StringParser() {
}
-
+
/**
* Builds a string, handles escaping through '\' syntax.
* @param str the string to build from
@@ -65,7 +65,6 @@ public class StringParser {
public static int readString(StringBuilder strb, CharSequence str, int
index, char sep) {
return read(strb, str, index, str.length(), sep);
}
-
/** The length of an escaped unicode sequence. */
private static final int UCHAR_LEN = 4;
@@ -89,7 +88,7 @@ public class StringParser {
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;
+ boolean notSeparator = sep == 0 ? c != '\'' && c != '"' :
c != sep;
if (notSeparator && c != '\\') {
strb.append('\\');
}
@@ -109,11 +108,11 @@ public class StringParser {
}
return index;
}
-
/** Initial shift value for composing a Unicode char from 4 nibbles (16 -
4). */
private static final int SHIFT = 12;
/** The base 10 offset used to convert hexa characters to decimal. */
private static final int BASE10 = 10;
+
/**
* Reads a Unicode escape character.
* @param strb the builder to write the character to
@@ -125,12 +124,12 @@ public class StringParser {
char xc = 0;
int bits = SHIFT;
int value = 0;
- for(int offset = 0; offset < UCHAR_LEN; ++offset) {
+ for (int offset = 0; offset < UCHAR_LEN; ++offset) {
char c = str.charAt(begin + offset);
if (c >= '0' && c <= '9') {
value = (c - '0');
} else if (c >= 'a' && c <= 'h') {
- value = (c - 'a' + BASE10);
+ value = (c - 'a' + BASE10);
} else if (c >= 'A' && c <= 'H') {
value = (c - 'A' + BASE10);
} else {
@@ -142,9 +141,10 @@ public class StringParser {
strb.append(xc);
return UCHAR_LEN;
}
-
/** The last 7bits ascii character. */
private static final char LAST_ASCII = 127;
+ /** The first printable 7bits ascii character. */
+ private static final char FIRST_ASCII = 32;
/**
* Escapes a String representation, expand non-ASCII characters as Unicode
escape sequence.
@@ -160,27 +160,46 @@ public class StringParser {
strb.append('\'');
for (int i = 0; i < length; ++i) {
char c = str.charAt(i);
- if (c < LAST_ASCII) {
- if (c == '\'') {
- // escape quote
- strb.append('\\');
- strb.append('\'');
- } else if (c == '\\') {
- // escape backslash
- strb.append('\\');
- strb.append('\\');
- } else {
- strb.append(c);
- }
- } else {
- // convert to Unicode escape sequence
- strb.append('\\');
- strb.append('u');
- String hex = Integer.toHexString(c);
- for (int h = hex.length(); h < UCHAR_LEN; ++h) {
- strb.append('0');
- }
- strb.append(hex);
+ switch (c) {
+ case 0:
+ continue;
+ case '\b':
+ strb.append("\\b");
+ break;
+ case '\t':
+ strb.append("\\t");
+ break;
+ case '\n':
+ strb.append("\\n");
+ break;
+ case '\f':
+ strb.append("\\f");
+ break;
+ case '\r':
+ strb.append("\\r");
+ break;
+ case '\"':
+ strb.append("\\\"");
+ break;
+ case '\'':
+ strb.append("\\\'");
+ break;
+ case '\\':
+ strb.append("\\\\");
+ break;
+ default:
+ if (c >= FIRST_ASCII && c <= LAST_ASCII) {
+ strb.append(c);
+ } else {
+ // convert to Unicode escape sequence
+ strb.append('\\');
+ strb.append('u');
+ String hex = Integer.toHexString(c);
+ for (int h = hex.length(); h < UCHAR_LEN; ++h) {
+ strb.append('0');
+ }
+ strb.append(hex);
+ }
}
}
strb.append('\'');
Modified: commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml (original)
+++ commons/proper/jexl/trunk/src/site/xdoc/reference/syntax.xml Mon Jul 18
11:12:35 2011
@@ -89,10 +89,18 @@
<tr>
<td>Scripts</td>
<td>
+ <p>
A script in Jexl is made up of zero or more statements. Scripts
can be read from a String, File or URL.
+ </p>
+ <p>
They can be created with named parameters which allow a later
evaluation to be performed with arguments.
+ </p>
+ <p>
A script returns the last expression evaluated by default.
+ </p>
+ <p>
Using the <code>return</code> keyword, a script will return the
expression that follows (or null).
+ </p>
</td>
</tr>
<tr>
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
Mon Jul 18 11:12:35 2011
@@ -408,7 +408,7 @@ public class IssuesTest extends JexlTest
assertEquals(Integer.valueOf(11), value);
long end = System.nanoTime();
double millisec = (end - start) / 1e6;
- double limit = 100.0; // Allow plenty of slack
+ double limit = 200.0; // Allow plenty of slack
assertTrue("Expected parse to take less than " + limit + "ms, actual "
+ millisec, millisec < limit);
}
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java?rev=1147811&r1=1147810&r2=1147811&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ScriptCallableTest.java
Mon Jul 18 11:12:35 2011
@@ -95,6 +95,17 @@ public class ScriptCallableTest extends
}
}
+ public void testNoWait() throws Exception {
+ Script e = JEXL.createScript("wait(0)");
+ Callable<Object> c = e.callable(new TestContext());
+
+ ExecutorService executor = Executors.newFixedThreadPool(1);
+ Future<?> future = executor.submit(c);
+ Object t = future.get(2, TimeUnit.SECONDS);
+ assertTrue(future.isDone());
+ assertEquals(0, t);
+ }
+
public void testWait() throws Exception {
Script e = JEXL.createScript("wait(1)");
Callable<Object> c = e.callable(new TestContext());