Debian Codegraph @

net/sf/saxon/functions/AbstractFunction.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 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.functions;
9
10 import net.sf.saxon.expr.ContextOriginator;
11 import net.sf.saxon.expr.OperandRole;
12 import net.sf.saxon.expr.OperandUsage;
13 import net.sf.saxon.expr.XPathContext;
14 import net.sf.saxon.expr.parser.ContextItemStaticInfo;
15 import net.sf.saxon.expr.parser.ExpressionVisitor;
16 import net.sf.saxon.expr.sort.AtomicComparer;
17 import net.sf.saxon.om.AtomicSequence;
18 import net.sf.saxon.om.Function;
19 import net.sf.saxon.query.AnnotationList;
20 import net.sf.saxon.trace.ExpressionPresenter;
21 import net.sf.saxon.trans.XPathException;
22
23 import java.util.Arrays;
24
25 /**
26 * Abstract superclass (and factory class) for implementations of Function
27 */
28 public abstract class AbstractFunction implements Function {
29
30 /**
31 * Get the roles of the arguments, for the purposes of streaming
32 *
33 * @return an array of OperandRole objects, one for each argument
34 */
35 public OperandRole[] getOperandRoles() {
36 OperandRole[] roles = new OperandRole[getArity()];
37 Arrays.fill(roles, new OperandRole(0, OperandUsage.NAVIGATION));
38 return roles;
39 }
40
41 /**
42 * Atomize the item.
43 *
44 * @return the result of atomization
45 * @throws net.sf.saxon.trans.XPathException
46 * if atomization is not allowed for this kind of item
47 */
48 public AtomicSequence atomize() throws XPathException {
49 throw new XPathException("Function items (other than arrays) cannot be atomized", "FOTY0013");
50 }
51
52 /**
53 * Ask whether this function is an array
54 *
55 * @return true if this function item is an array, otherwise false
56 */
57 public boolean isArray() {
58 return false;
59 }
60
61 /**
62 * Ask whether this function is a map
63 *
64 * @return true if this function item is a map, otherwise false
65 */
66 public boolean isMap() {
67 return false;
68 }
69
70 /**
71 * Get the string value of the function
72 *
73 * @throws UnsupportedOperationException (the string value of a function is not defined)
74 */
75
76 public String getStringValue() {
77 throw new UnsupportedOperationException("The string value of a function is not defined");
78 }
79
80 /**
81 * Get the string value of the function
82 *
83 * @throws UnsupportedOperationException (the string value of a function is not defined)
84 */
85
86 public CharSequence getStringValueCS() {
87 throw new UnsupportedOperationException("The string value of a function is not defined");
88 }
89
90 @Override
91 public AnnotationList getAnnotations() {
92 return AnnotationList.EMPTY;
93 }
94
95 /**
96 * Get the effective boolean value of the function item
97 *
98 * @throws XPathException (the EBVof a function item is not defined)
99 */
100
101 public boolean effectiveBooleanValue() throws XPathException {
102 throw new XPathException("A function has no effective boolean value", "XPTY0004");
103 }
104
105
106
107 public void simplify() throws XPathException {
108 // default: no action
109 }
110
111 /**
112 * Type check the function (may modify it by adding code for converting the arguments)
113 *
114 * @param visitor the expression visitor, supplies context information
115 * @param contextItemType the context item type at the point where the function definition appears
116 * @throws XPathException if any failure (e.g. a type checking failure) occurs
117 */
118
119 public void typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException {
120 // default: no action
121 }
122
123 /**
124 * Prepare an XPathContext object for evaluating the function
125 *
126 * @param callingContext the XPathContext of the function calling expression
127 * @param originator
128 * @return a suitable context for evaluating the function (which may or may
129 * not be the same as the caller's context)
130 */
131
132 public XPathContext makeNewContext(XPathContext callingContext, ContextOriginator originator) {
133 return callingContext;
134 }
135
136 /**
137 * Test whether this FunctionItem is deep-equal to another function item,
138 * under the rules of the deep-equal function
139 *
140 * @param other the other function item
141 */
142 public boolean deepEquals(Function other, XPathContext context, AtomicComparer comparer, int flags) throws XPathException {
143 throw new XPathException("Argument to deep-equal() contains a function item", "FOTY0015");
144 }
145
146 /**
147 * Output information about this function item to the diagnostic explain() output
148 */
149 public void export(ExpressionPresenter out) throws XPathException {
150 throw new UnsupportedOperationException("export() not implemented for " + this.getClass());
151 }
152
153 /**
154 * Check that result type is SystemFunction or AtomicConstructorFunction
155 *
156 */
157 public boolean isTrustedResultType() {
158 return false;
159 }
160 }
161
162