Skip to content

Commit 142d851

Browse files
committed
[refactor] Generalised the solution so that it isn't just about TextConstructor
1 parent 73dce43 commit 142d851

File tree

6 files changed

+35
-9
lines changed

6 files changed

+35
-9
lines changed

exist-core/src/main/java/org/exist/xquery/AbstractExpression.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,9 @@ public Expression simplify() {
183183
public Expression getParent() {
184184
return null;
185185
}
186+
187+
@Override
188+
public boolean evalNextExpressionOnEmptyContextSequence() {
189+
return false;
190+
}
186191
}

exist-core/src/main/java/org/exist/xquery/DebuggableExpression.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,4 +194,9 @@ public Expression simplify() {
194194
public Expression getParent() {
195195
return null;
196196
}
197+
198+
@Override
199+
public boolean evalNextExpressionOnEmptyContextSequence() {
200+
return false;
201+
}
197202
}

exist-core/src/main/java/org/exist/xquery/Expression.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,13 @@ public interface Expression {
255255
public boolean allowMixedNodesInReturn();
256256

257257
public Expression getParent();
258+
259+
/**
260+
* Return true only if the next expression within a path expression
261+
* should be evaluated even when this expression returns an
262+
* empty sequence.
263+
*
264+
* @return true if the next expression should be evaluated, false otherwise.
265+
*/
266+
boolean evalNextExpressionOnEmptyContextSequence();
258267
}

exist-core/src/main/java/org/exist/xquery/PathExpr.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,15 @@ public Sequence eval(Sequence contextSequence, final Item contextItem) throws XP
302302

303303
/**
304304
* If the result is an Empty Sequence, we don't need to process
305-
* any more steps as there is no Context Item for the next step!
305+
* any more steps as there is no Context Sequence for the next step!
306306
*
307-
* There is one exception to this rule, which is a TextConstructor,
308-
* that only contains whitespace but has been configured
307+
* There is one exception to this rule, which is a TextConstructor
308+
* expression that only contains whitespace but has been configured
309309
* to strip-whitespace. In this instance the TextConstructor will
310-
* return an {@link Sequence.EMPTY_SEQUENCE_VALID} to indicate
311-
* that.
310+
* return true when {@link Expression#evalNextExpressionOnEmptyContextSequence()}
311+
* is called to indicate that.
312312
*/
313-
if (result != Sequence.EMPTY_SEQUENCE_VALID && result.isEmpty()) {
313+
if (result.isEmpty() && !step.evalNextExpressionOnEmptyContextSequence()) {
314314
break;
315315
}
316316
}

exist-core/src/main/java/org/exist/xquery/TextConstructor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public TextConstructor(XQueryContext context, String text) throws XPathException
5454
*/
5555
public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
5656
if (isWhitespaceOnly && context.stripWhitespace())
57-
{return Sequence.EMPTY_SEQUENCE_VALID;}
57+
{return Sequence.EMPTY_SEQUENCE;}
5858
if (newDocumentContext)
5959
{context.pushDocumentContext();}
6060
try {
@@ -96,4 +96,13 @@ public String getText() {
9696
public boolean allowMixedNodesInReturn() {
9797
return true;
9898
}
99+
100+
@Override
101+
public boolean evalNextExpressionOnEmptyContextSequence() {
102+
/*
103+
When this TextConstructor only contains whitespace but has been configured
104+
to strip-whitespace, return true so that the next expression is processed correctly.
105+
*/
106+
return isWhitespaceOnly && context.stripWhitespace();
107+
}
99108
}

exist-core/src/main/java/org/exist/xquery/value/Sequence.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ public interface Sequence {
5454
*/
5555
Sequence EMPTY_SEQUENCE = new EmptySequence();
5656

57-
Sequence EMPTY_SEQUENCE_VALID = new EmptySequence();
58-
5957
/**
6058
* The purpose of ordered and unordered flag is to set the ordering mode
6159
* in the static context to ordered or unordered for a certain region in a query.

0 commit comments

Comments
 (0)