Author: rahul
Date: Mon Aug 10 20:58:32 2009
New Revision: 802926
URL: http://svn.apache.org/viewvc?rev=802926&view=rev
Log:
Change foreach syntax -- now aligned with enhanced for.
Add note that 1.1 syntax is deprecated.
Based on patch by Henri Biestro <hbiestro at gmail dot com>.
JEXL-82
Modified:
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java
commons/proper/jexl/branches/2.0/xdocs/reference/syntax.xml
Modified:
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt?rev=802926&r1=802925&r2=802926&view=diff
==============================================================================
---
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt
(original)
+++
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl/parser/Parser.jjt
Mon Aug 10 20:58:32 2009
@@ -415,6 +415,8 @@
void ForeachStatement() :
{}
{
+ "for" "(" Reference() ":" Reference() ")" Statement()
+|
"foreach" "(" Reference() "in" Reference() ")" Statement()
}
Modified:
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java?rev=802926&r1=802925&r2=802926&view=diff
==============================================================================
---
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java
(original)
+++
commons/proper/jexl/branches/2.0/src/test/java/org/apache/commons/jexl/ForEachTest.java
Mon Aug 10 20:58:32 2009
@@ -36,7 +36,7 @@
}
public void testForEachWithEmptyStatement() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list) ;");
+ Expression e = JEXL.createExpression("for(item : list) ;");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
@@ -44,7 +44,7 @@
}
public void testForEachWithEmptyList() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list) 1+1");
+ Expression e = JEXL.createExpression("for(item : list) 1+1");
JexlContext jc = JexlHelper.createContext();
Object o = e.evaluate(jc);
@@ -52,7 +52,7 @@
}
public void testForEachWithArray() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("for(item : list) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", new Object[] {"Hello", "World"});
Object o = e.evaluate(jc);
@@ -60,7 +60,7 @@
}
public void testForEachWithCollection() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("for(item : list) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", Arrays.asList(new Object[] {"Hello",
"World"}));
Object o = e.evaluate(jc);
@@ -68,7 +68,7 @@
}
public void testForEachWithEnumeration() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("for(item : list) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", new StringTokenizer("Hello,World", ","));
Object o = e.evaluate(jc);
@@ -76,7 +76,7 @@
}
public void testForEachWithIterator() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("for(item : list) item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", Arrays.asList(new Object[] {"Hello",
"World"}).iterator());
Object o = e.evaluate(jc);
@@ -84,7 +84,7 @@
}
public void testForEachWithMap() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list) item");
+ Expression e = JEXL.createExpression("for(item : list) item");
JexlContext jc = JexlHelper.createContext();
Map<?, ?> map = System.getProperties();
String lastProperty = (String) new
ArrayList<Object>(map.values()).get(System.getProperties().size() - 1);
@@ -94,7 +94,7 @@
}
public void testForEachWithBlock() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list) { x = x +
item; }");
+ Expression e = JEXL.createExpression("for(item : list) { x = x + item;
}");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", new Object[] {"1", "1"});
jc.getVars().put("x", new Integer(0));
@@ -104,7 +104,7 @@
}
public void testForEachWithListExpression() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in list.keySet())
item");
+ Expression e = JEXL.createExpression("for(item : list.keySet()) item");
JexlContext jc = JexlHelper.createContext();
Map<?, ?> map = System.getProperties();
String lastKey = (String) new
ArrayList<Object>(map.keySet()).get(System.getProperties().size() - 1);
@@ -114,7 +114,7 @@
}
public void testForEachWithProperty() throws Exception {
- Expression e = JEXL.createExpression("foreach (item in
list.cheeseList) item");
+ Expression e = JEXL.createExpression("for(item : list.cheeseList)
item");
JexlContext jc = JexlHelper.createContext();
jc.getVars().put("list", new Foo());
Object o = e.evaluate(jc);
Modified: commons/proper/jexl/branches/2.0/xdocs/reference/syntax.xml
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/xdocs/reference/syntax.xml?rev=802926&r1=802925&r2=802926&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/xdocs/reference/syntax.xml (original)
+++ commons/proper/jexl/branches/2.0/xdocs/reference/syntax.xml Mon Aug 10
20:58:32 2009
@@ -449,11 +449,12 @@
</td>
</tr>
<tr>
- <td>foreach</td>
+ <td>for</td>
<td>
Loop through items of an Array, Collection, Map, Iterator or
Enumeration, e.g.
- <code>foreach (item in list) { x = x + item; }</code>
+ <code>for(item : list) { x = x + item; }</code>
Where <code>item</code> and <code>list</code> are variables.
+ The JEXL 1.1 syntax using <code>foreach(item in list)</code> is
now <strong>deprecated</strong>.
</td>
</tr>
<tr>