222785 [expressions] Can resolve and with expressions return false
diff --git a/bundles/org.eclipse.core.expressions/apichanges_core-expressions.html b/bundles/org.eclipse.core.expressions/apichanges_core-expressions.html
index 645a842..c974eb7 100644
--- a/bundles/org.eclipse.core.expressions/apichanges_core-expressions.html
+++ b/bundles/org.eclipse.core.expressions/apichanges_core-expressions.html
@@ -44,6 +44,14 @@
<li><code>addAccessedPropertyName</code></li></ul>
</td>
</tr>
+ <tr>
+ <td>
+ New API constant added: <code>IEvaluationContext.UNDEFINED_VARIABLE</code>.
+ <ul><li>Represents the value used by variables that exist but are not defined
+ in a evaluation context. When tested by the 'with' expression, <code>false</code>
+ will be returned.</li></ul>
+ </td>
+ </tr>
</tbody>
</table>
<p>
diff --git a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/IEvaluationContext.java b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/IEvaluationContext.java
index 83b9bb1..2b70a36 100644
--- a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/IEvaluationContext.java
+++ b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/expressions/IEvaluationContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -26,6 +26,15 @@
* @since 3.0
*/
public interface IEvaluationContext {
+
+ /**
+ * Represents the value used by variables that exist but are not defined
+ * in a evaluation context. When tested by the 'with' expression, <code>false</code>
+ * will be returned.
+ *
+ * @since 3.4
+ */
+ public static Object UNDEFINED_VARIABLE = new Object();
/**
* Returns the parent context or <code>null</code> if
diff --git a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/WithExpression.java b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/WithExpression.java
index 4d2c488..996d055 100644
--- a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/WithExpression.java
+++ b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/WithExpression.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -66,6 +66,9 @@
ExpressionStatus.VARIABLE_NOT_DEFINED,
Messages.format(ExpressionMessages.WithExpression_variable_not_defined, fVariable)));
}
+ if (variable == IEvaluationContext.UNDEFINED_VARIABLE) {
+ return EvaluationResult.FALSE;
+ }
return evaluateAnd(new EvaluationContext(context, variable));
}
diff --git a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java
index 801561d..ae4f925 100644
--- a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java
+++ b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/ExpressionTests.java
@@ -438,6 +438,26 @@
expression1.hashCode(), expression2.hashCode());
}
+ public void testWithExpressionNoVariable() throws Exception {
+ WithExpression expr = new WithExpression("variable");
+ expr.add(new EqualsExpression(new Object()));
+ EvaluationContext context = new EvaluationContext(null, new Object());
+ try {
+ expr.evaluate(context);
+ fail("Should throw exceptoin");
+ } catch (CoreException e) {
+ // this is success
+ }
+ }
+
+ public void testWithExpressionUndefinedVariable() throws Exception {
+ WithExpression expr = new WithExpression("variable");
+ expr.add(new EqualsExpression(new Object()));
+ EvaluationContext context = new EvaluationContext(null, new Object());
+ context.addVariable("variable", IEvaluationContext.UNDEFINED_VARIABLE);
+ assertEquals(EvaluationResult.FALSE, expr.evaluate(context));
+ }
+
public void testVariableResolver() throws Exception {
final Object result= new Object();
IVariableResolver resolver= new IVariableResolver() {