You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ra...@apache.org on 2009/07/17 08:15:37 UTC
svn commit: r794976 [2/2] - in /commons/proper/jexl/branches/2.0: ./
src/conf/ src/java/org/apache/commons/jexl/
src/java/org/apache/commons/jexl/util/
src/java/org/apache/commons/jexl/util/introspection/
src/test/org/apache/commons/jexl/
Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java?rev=794976&r1=794975&r2=794976&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/UberspectImpl.java Fri Jul 17 06:15:35 2009
@@ -52,7 +52,7 @@
/*
* static signature for method(object,object)
*/
- static final Class[] OBJECT_OBJECT = { Object.class, Object.class };
+ static final Class<?>[] OBJECT_OBJECT = { Object.class, Object.class };
/**
* Our runtime logger.
*/
@@ -87,35 +87,35 @@
/**
* {@inheritDoc}
*/
- public Iterator getIterator(Object obj, Info i) {
+ public Iterator<?> getIterator(Object obj, Info i) {
if (obj.getClass().isArray()) {
return new ArrayIterator(obj);
- } else if (obj instanceof Collection) {
- return ((Collection) obj).iterator();
- } else if (obj instanceof Map) {
- return ((Map) obj).values().iterator();
- } else if (obj instanceof Iterator) {
+ } else if (obj instanceof Collection<?>) {
+ return ((Collection<?>) obj).iterator();
+ } else if (obj instanceof Map<?,?>) {
+ return ((Map<?,?>) obj).values().iterator();
+ } else if (obj instanceof Iterator<?>) {
rlog.warn("Warning! The iterative " + " is an Iterator in the #foreach() loop at [" + i.getLine() + ","
+ i.getColumn() + "]" + " in template " + i.getTemplateName() + ". Because it's not resetable,"
+ " if used in more than once, this may lead to" + " unexpected results.");
- return ((Iterator) obj);
- } else if (obj instanceof Enumeration) {
+ return ((Iterator<?>) obj);
+ } else if (obj instanceof Enumeration<?>) {
rlog.warn("Warning! The iterative " + " is an Enumeration in the #foreach() loop at [" + i.getLine() + ","
+ i.getColumn() + "]" + " in template " + i.getTemplateName() + ". Because it's not resetable,"
+ " if used in more than once, this may lead to" + " unexpected results.");
- return new EnumerationIterator((Enumeration) obj);
+ return new EnumerationIterator((Enumeration<?>) obj);
} else {
// look for an iterator() method to support the JDK5 Iterable
// interface or any user tools/DTOs that want to work in
// foreach without implementing the Collection interface
- Class type = obj.getClass();
+ Class<?> type = obj.getClass();
try {
- Method iter = type.getMethod("iterator", (Class[]) null);
- Class returns = iter.getReturnType();
+ Method iter = type.getMethod("iterator", (Class<?>[]) null);
+ Class<?> returns = iter.getReturnType();
if (Iterator.class.isAssignableFrom(returns)) {
- return (Iterator) iter.invoke(obj, (Object[])null);
+ return (Iterator<?>) iter.invoke(obj, (Object[])null);
} else {
rlog.error("iterator() method of reference in #foreach loop at "
+ i + " does not return a true Iterator.");
@@ -158,8 +158,8 @@
// before invoking the method
return new VelMethodImpl(m, true);
}
- } else if (obj instanceof Class) {
- m = introspector.getMethod((Class) obj, methodName, args);
+ } else if (obj instanceof Class<?>) {
+ m = introspector.getMethod((Class<?>) obj, methodName, args);
}
return (m == null) ? null : new VelMethodImpl(m);
@@ -171,7 +171,7 @@
public VelPropertyGet getPropertyGet(Object obj, String identifier, Info i) {
AbstractExecutor executor;
- Class claz = obj.getClass();
+ Class<?> claz = obj.getClass();
/*
* first try for a getFoo() type of property (also getfoo() )
@@ -208,7 +208,7 @@
* {@inheritDoc}
*/
public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i) {
- Class claz = obj.getClass();
+ Class<?> claz = obj.getClass();
VelMethod vm = null;
try {
@@ -296,9 +296,9 @@
*/
public Object invoke(Object o, Object[] params) throws Exception {
if (isVarArg()) {
- Class[] formal = method.getParameterTypes();
+ Class<?>[] formal = method.getParameterTypes();
int index = formal.length - 1;
- Class type = formal[index].getComponentType();
+ Class<?> type = formal[index].getComponentType();
if (params.length >= index) {
params = handleVarArg(type, index, params);
}
@@ -326,11 +326,11 @@
*/
public boolean isVarArg() {
if (isVarArg == null) {
- Class[] formal = method.getParameterTypes();
+ Class<?>[] formal = method.getParameterTypes();
if (formal == null || formal.length == 0) {
this.isVarArg = Boolean.FALSE;
} else {
- Class last = formal[formal.length - 1];
+ Class<?> last = formal[formal.length - 1];
// if the last arg is an array, then
// we consider this a varargs method
this.isVarArg = Boolean.valueOf(last.isArray());
@@ -349,7 +349,7 @@
* @return The actual parameters adjusted for the varargs in order
* to fit the method declaration.
*/
- private Object[] handleVarArg(Class type, int index, Object[] actual) {
+ private Object[] handleVarArg(Class<?> type, int index, Object[] actual) {
// if no values are being passed into the vararg
if (actual.length == index) {
// create an empty array of the expected type
@@ -404,7 +404,7 @@
/**
* {@inheritDoc}
*/
- public Class getReturnType() {
+ public Class<?> getReturnType() {
return method.getReturnType();
}
} // CSON: VisibilityModifier
@@ -515,4 +515,4 @@
}
}
-}
+}
\ No newline at end of file
Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/VelMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/VelMethod.java?rev=794976&r1=794975&r2=794976&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/VelMethod.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/util/introspection/VelMethod.java Fri Jul 17 06:15:35 2009
@@ -57,5 +57,5 @@
* returns the return type of the method invoked.
* @return return type
*/
- Class getReturnType();
-}
+ Class<?> getReturnType();
+}
\ No newline at end of file
Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java?rev=794976&r1=794975&r2=794976&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ArithmeticTest.java Fri Jul 17 06:15:35 2009
@@ -125,7 +125,7 @@
Map vars = context.getVars();
vars.put("aByte", new Byte((byte) 1));
vars.put("aShort", new Short((short) 2));
- vars.put("anInteger", new Integer(3));
+ vars.put("aInteger", new Integer(3));
vars.put("aLong", new Long(4));
vars.put("aFloat", new Float(5.5));
vars.put("aDouble", new Double(6.6));
@@ -151,9 +151,10 @@
final int PERMS = tnames.length * tnames.length;
JexlEngine jexl = new JexlEngine();
+ jexl.setSilent(false);
// for non-silent, silent...
for (int s = 0; s < 2; ++s) {
- jexl.setSilent(s != 0);
+ jexl.setLenient(s == 0);
int zthrow = 0;
int zeval = 0;
// for vars of all types...
@@ -178,13 +179,13 @@
}
}
}
- if (!jexl.isSilent())
- assertTrue("All expressions should have thrown " + zthrow,
+ if (!jexl.isLenient())
+ assertTrue("All expressions should have thrown " + zthrow + "/" + PERMS,
zthrow == PERMS);
else
- assertTrue("All expressions should have zeroed" + zeval,
+ assertTrue("All expressions should have zeroed " + zeval + "/" + PERMS,
zeval == PERMS);
}
}
-}
+}
\ No newline at end of file
Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ForEachTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ForEachTest.java?rev=794976&r1=794975&r2=794976&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ForEachTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/ForEachTest.java Fri Jul 17 06:15:35 2009
@@ -122,4 +122,8 @@
Object o = e.evaluate(jc);
assertEquals("Result is not last evaluated expression", "brie", o);
}
-}
+
+ public static void main(String[] args) throws Exception {
+ new ForEachTest("").testForEachWithEmptyStatement();
+ }
+}
\ No newline at end of file
Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/IssuesTest.java?rev=794976&r1=794975&r2=794976&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/IssuesTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/IssuesTest.java Fri Jul 17 06:15:35 2009
@@ -24,17 +24,18 @@
*/
public class IssuesTest extends TestCase {
- // JEXL-52: can be implemented by deriving Interpreter.{g,s}etAttribute
- // JEXL-50: can be implemented through a namespace:function or through JexlArithmetic derivation
-
+ public void setUp() throws Exception {
+ // ensure jul logging is only error to avoid warning in silent mode
+ java.util.logging.Logger.getLogger(JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
+ }
+
// JEXL-49: blocks not parsed (fixed)
public void test49() throws Exception {
JexlContext ctxt = JexlHelper.createContext();
- Map vars = ctxt.getVars();
-
String stmt = "{a = 'b'; c = 'd';}";
Script expr = ScriptFactory.createScript(stmt);
Object value = expr.execute(ctxt);
+ Map vars = ctxt.getVars();
assertTrue("JEXL-49 is not fixed", vars.get("a").equals("b") && vars.get("c").equals("d"));
}
@@ -42,11 +43,9 @@
// JEXL-48: bad assignment detection
public static class Another {
private Boolean foo = true;
-
public Boolean foo() {
return foo;
}
-
public int goo() {
return 100;
}
@@ -54,11 +53,9 @@
public static class Foo {
private Another inner;
-
Foo() {
inner = new Another();
}
-
public Another getInner() {
return inner;
}
@@ -82,8 +79,8 @@
}
}
- // JEXL-47: C style comments (single & multi line) (fixed)
- // JEXL-44: comments dont allow double quotes (fixed)
+ // JEXL-47: C style comments (single & multi line) (fixed in Parser.jjt)
+ // JEXL-44: comments dont allow double quotes (fixed in Parser.jjt)
public void test47() throws Exception {
JexlEngine jexl = new JexlEngine();
// ensure errors will throw
@@ -103,10 +100,8 @@
assertFalse("should be false", (Boolean) value);
}
- // JEXL-46: regexp syntax; should we really add more syntactic elements?
- // JEXL-45: unhandled division by zero (fixed see ArithmeticTest)
-
- // JEXL-42: NullPointerException evaluating an expression (fixed)
+ // JEXL-42: NullPointerException evaluating an expression
+ // fixed in JexlArithmetic by allowing add to deal with string, null
public void test42() throws Exception {
JexlEngine jexl = new JexlEngine();
UnifiedJEXL uel = new UnifiedJEXL(jexl);
@@ -120,8 +115,75 @@
assertTrue("should be ok", "ok".equals(value));
}
+ // JEXL-40: failed to discover all methods (non public class implements public method)
+ // fixed in ClassMap by taking newer version of populateCache from Velocity
+ public static abstract class Base {
+ public abstract boolean foo();
+ }
+
+ class Derived extends Base {
+ public boolean foo() {
+ return true;
+ }
+ }
+
+ public void test40() throws Exception {
+ JexlEngine jexl = new JexlEngine();
+ // ensure errors will throw
+ jexl.setSilent(false);
+ JexlContext ctxt = JexlHelper.createContext();
+ ctxt.getVars().put("derived", new Derived() );
+
+ Expression expr = jexl.createExpression( "derived.foo()" );
+ Object value = expr.evaluate(ctxt);
+ assertTrue("should be true", (Boolean) value);
+ }
+
+ // JEXL-52: can be implemented by deriving Interpreter.{g,s}etAttribute; wontfix
+ // JEXL-50: can be implemented through a namespace:function or through JexlArithmetic derivation - wontfix
+
+ // JEXL-46: regexp syntax; should we really add more syntactic elements? - later/vote?
+ // JEXL-45: unhandled division by zero; already fixed in trunk
+
+ // JEXL-35: final API requirements; fixed in trunk ?
+ // JEXL-32: BigDecimal values are treated as Long values which results in loss of precision; no longer affects 2.0 // Dion
+ // JEXL-21: operator overloading / hooks on operator processing (wontfix, derive JexlArithmetic)
+ // JEXL-20: checkstyle
+ // JEXL-3: static method resolution; fixed in trunk
+ // JEXL-3: change to JexlContext (setVar, getVar) - later, watch out for JEXL-10, differentiate null versus undefined?
+
+ // JEXL-10: Make possible checking for unresolved variables
+ // JEXL-11: Don't make null convertible into anything
+ public void test11() throws Exception {
+ JexlEngine jexl = new JexlEngine();
+ // ensure errors will throw
+ jexl.setSilent(false);
+ jexl.setLenient(false);
+ JexlContext ctxt = JexlHelper.createContext();
+ ctxt.getVars().put("a", null );
+
+ String[] exprs = {
+ "10 + null",
+ "a - 10",
+ "b * 10",
+ "a % b",
+ "1000 / a"
+ };
+ for(int e = 0; e < exprs.length; ++e) {
+ try {
+ Expression expr = jexl.createExpression( exprs[e]);
+ Object value = expr.evaluate(ctxt);
+ fail("Should have failed due to null argument");
+ }
+ catch(JexlException xjexl) {
+ // expected
+ String msg = xjexl.toString();
+ String xmsg = msg;
+ }
+ }
+ }
public static void main(String[] args) throws Exception {
- new IssuesTest().test42();
+ new IssuesTest().test11();
}
-}
+}
\ No newline at end of file
Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java?rev=794976&r1=794975&r2=794976&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/JexlTest.java Fri Jul 17 06:15:35 2009
@@ -551,7 +551,7 @@
assertExpression(jc, "foo.substring(2,4)", "cd");
assertExpression(jc, "foo.charAt(2)", new Character('c'));
- assertExpression(jc, "foo.charAt(-2)", null);
+ assertExpression(jc, "foo.charAt(-2)", null);
}
@@ -749,4 +749,4 @@
jt.testEmpty();
}
-}
+}
\ No newline at end of file
Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/UnifiedJEXLTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/UnifiedJEXLTest.java?rev=794976&r1=794975&r2=794976&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/UnifiedJEXLTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/UnifiedJEXLTest.java Fri Jul 17 06:15:35 2009
@@ -23,10 +23,17 @@
public class UnifiedJEXLTest extends TestCase {
static JexlEngine JEXL = new JexlEngine();
static {
+ JEXL.setLenient(false);
JEXL.setSilent(false);
+ JEXL.setCache(128);
}
static UnifiedJEXL EL = new UnifiedJEXL(JEXL);
+ public void setUp() throws Exception {
+ // ensure jul logging is only error
+ java.util.logging.Logger.getLogger(JexlEngine.class.getName()).setLevel(java.util.logging.Level.SEVERE);
+ }
+
public static class Froboz {
int value;
public Froboz(int v) {
@@ -115,14 +122,14 @@
public void testImmediate() throws Exception {
UnifiedJEXL.Expression expr = EL.parse("${'Hello ' + 'World!'}");
- JexlContext jc = JexlHelper.createContext();
+ JexlContext jc = null;
Object o = expr.evaluate(jc);
assertEquals("Hello World!", o);
}
public void testDeferred() throws Exception {
UnifiedJEXL.Expression expr = EL.parse("#{'world'}");
- JexlContext jc = JexlHelper.createContext();
+ JexlContext jc = null;
Object o = expr.evaluate(jc);
assertEquals("world", o);
}
@@ -146,6 +153,6 @@
public static void main(String[] args) throws Exception {
//new UnifiedELTest("debug").testClassHash();
- new UnifiedJEXLTest("debug").testCharAtBug();
+ new UnifiedJEXLTest("debug").testAssign();
}
-}
+}
\ No newline at end of file