summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbkolb2007-12-11 05:44:10 (EST)
committer bkolb2007-12-11 05:44:10 (EST)
commit62e0e9c17a5dfd253e32e6e4aa8c14b946188764 (patch)
tree44c253d1c73608e38a67575ecb7cef21a5963052
parent2d44b836c315f3cb65b5905395e50b293b06be4e (diff)
downloadorg.eclipse.xpand-62e0e9c17a5dfd253e32e6e4aa8c14b946188764.zip
org.eclipse.xpand-62e0e9c17a5dfd253e32e6e4aa8c14b946188764.tar.gz
org.eclipse.xpand-62e0e9c17a5dfd253e32e6e4aa8c14b946188764.tar.bz2
fixed bug in forAll
-rw-r--r--plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/typesystem/baseimpl/CollectionFeaturesTest.java6
-rw-r--r--plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java10
2 files changed, 9 insertions, 7 deletions
diff --git a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/typesystem/baseimpl/CollectionFeaturesTest.java b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/typesystem/baseimpl/CollectionFeaturesTest.java
index a3d0f50..9407737 100644
--- a/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/typesystem/baseimpl/CollectionFeaturesTest.java
+++ b/plugins/org.eclipse.xtend.tests/src/org/eclipse/xtend/typesystem/baseimpl/CollectionFeaturesTest.java
@@ -90,8 +90,14 @@ public class CollectionFeaturesTest extends TestCase {
assertEquals(Boolean.TRUE, ef.evaluate("vals.exists(s| s == \"3\")", Collections.singletonMap("vals", vals)));
assertEquals(Boolean.FALSE, ef.evaluate("vals.exists(s| s == \"33\")", Collections.singletonMap("vals", vals)));
}
+
+ public final void testNotExists() {
+ assertEquals(Boolean.FALSE, ef.evaluate("vals.notExists(s| s == \"3\")", Collections.singletonMap("vals", vals)));
+ assertEquals(Boolean.TRUE, ef.evaluate("vals.notExists(s| s == \"33\")", Collections.singletonMap("vals", vals)));
+ }
public final void testForAll() {
+ assertEquals(Boolean.FALSE, ef.evaluate("{}.forAll(s | true)"));
assertEquals(Boolean.TRUE, ef.evaluate("vals.forAll(s| s.length == 1)", Collections.singletonMap("vals", vals)));
assertEquals(Boolean.FALSE, ef.evaluate("vals.forAll(s| s == \"3\")", Collections.singletonMap("vals", vals)));
}
diff --git a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java
index 10e76e3..d38cf92 100644
--- a/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java
+++ b/plugins/org.eclipse.xtend/src/org/eclipse/internal/xtend/expression/ast/CollectionExpression.java
@@ -117,6 +117,7 @@ public class CollectionExpression extends FeatureCall {
}
private Object executeForAll(final Collection collection, ExecutionContext ctx) {
+ if ( collection.size()== 0) return Boolean.FALSE;
for (final Iterator iter = collection.iterator(); iter.hasNext();) {
ctx = ctx.cloneWithVariable(new Variable(getElementName(), iter.next()));
final Object result = closure.evaluate(ctx);
@@ -137,13 +138,8 @@ public class CollectionExpression extends FeatureCall {
}
private Object executeNotExists(final Collection collection, ExecutionContext ctx) {
- for (final Iterator iter = collection.iterator(); iter.hasNext();) {
- ctx = ctx.cloneWithVariable(new Variable(getElementName(), iter.next()));
- final Object result = closure.evaluate(ctx);
- if (result instanceof Boolean && ((Boolean) result).booleanValue())
- return Boolean.FALSE;
- }
- return Boolean.TRUE;
+ Boolean bool = (Boolean) executeExists(collection, ctx);
+ return Boolean.valueOf(!bool);
}
private Object executeReject(final Collection collection, ExecutionContext ctx) {