On Sun, 2003-09-07 at 03:28, Tim O'Brien wrote:
> JexlTest line 443: "assertExpression(jc, "array.length", new Integer(5));"
>
> This is failing because (from what I'm seeing), length isn't given any special
> treatment in Parser.jjt.
>
> Any ideas?
I proposed the attached fix a few months back, but geir wanted to
discuss other possible ways of implementing the length function so he
didn't apply it. There's been no progress since then though.
-Mark.
Index: src/java/org/apache/commons/jexl/parser/ASTIdentifier.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/jexl/src/java/org/apache/commons/jexl/parser/ASTIdentifier.java,v
retrieving revision 1.4
diff -u -r1.4 ASTIdentifier.java
--- src/java/org/apache/commons/jexl/parser/ASTIdentifier.java 16 Dec 2002 10:41:59 -0000 1.4
+++ src/java/org/apache/commons/jexl/parser/ASTIdentifier.java 9 Sep 2003 10:37:41 -0000
@@ -55,6 +55,8 @@
package org.apache.commons.jexl.parser;
+import java.lang.reflect.Array;
+
import org.apache.commons.jexl.JexlContext;
/**
@@ -98,7 +100,16 @@
public Object execute(Object obj, JexlContext jc)
throws Exception
{
- return ASTArrayAccess.evaluateExpr(obj, val);
+ if (!val.equals("length"))
+ {
+ return ASTArrayAccess.evaluateExpr(obj, val);
+ }
+ if (obj.getClass().isArray())
+ {
+ return new Integer(Array.getLength(obj));
+ }
+
+ throw new Exception("length : " + obj.getClass() + " is not an array");
}
public String getIdentifierString()
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]