Debian Codegraph @

net/sf/saxon/expr/PseudoExpression.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2013 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.expr;
9
10 import net.sf.saxon.om.Item;
11 import net.sf.saxon.om.SequenceIterator;
12 import net.sf.saxon.trans.XPathException;
13 import net.sf.saxon.type.AnyItemType;
14 import net.sf.saxon.type.ItemType;
15
16 /**
17 * A pseudo-expression is an object that can appear as a node on the expression tree, but which cannot
18 * actually be evaluated in its own right. An example is a sort key definition. This has to be a node
19 * on the tree, because it contains subexpressions, so recursive traversals of the tree need to process
20 * it. But evaluating a sort key definition throws an exception.
21 *
22 * <p>A constraint for pseudo-expressions is that rewrite methods (simplify, typecheck, promote etc)
23 * always return an object of the same class (nearly always the same object)</p>
24 */
25 public abstract class PseudoExpression extends Expression {
26
27 private void cannotEvaluate() throws XPathException {
28 throw new XPathException("Cannot evaluate " + getClass().getName());
29 }
30
31 @Override
32 public int getImplementationMethod() {
33 return 0;
34 }
35
36 @Override
37 protected final int computeCardinality() {
38 return StaticProperty.ALLOWS_ZERO_OR_MORE;
39 }
40
41 @Override
42 public ItemType getItemType() {
43 return AnyItemType.getInstance();
44 }
45
46 @Override
47 public final Item evaluateItem(XPathContext context) throws XPathException {
48 cannotEvaluate();
49 return null;
50 }
51
52 @Override
53 public boolean effectiveBooleanValue(XPathContext context) throws XPathException {
54 cannotEvaluate();
55 return false;
56 }
57
58 @Override
59 public final CharSequence evaluateAsString(XPathContext context) throws XPathException {
60 cannotEvaluate();
61 return "";
62 }
63
64 @Override
65 public final SequenceIterator<?> iterate(XPathContext context) throws XPathException {
66 cannotEvaluate();
67 return null;
68 }
69
70 @Override
71 public void process(XPathContext context) throws XPathException {
72 cannotEvaluate();
73 }
74 }
75