Debian Codegraph @

net/sf/saxon/om/Function.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.om;
9
10 import net.sf.saxon.expr.Callable;
11 import net.sf.saxon.expr.ContextOriginator;
12 import net.sf.saxon.expr.OperandRole;
13 import net.sf.saxon.expr.XPathContext;
14 import net.sf.saxon.expr.sort.AtomicComparer;
15 import net.sf.saxon.query.AnnotationList;
16 import net.sf.saxon.trace.ExpressionPresenter;
17 import net.sf.saxon.trans.XPathException;
18 import net.sf.saxon.type.FunctionItemType;
19
20 /**
21 * XDM 3.0 introduces a third kind of item, beyond nodes and atomic values: the function. Functions
22 * implement this interface.
23 */
24
25 public interface Function extends Item<Function>, Callable, GroundedValue<Function> {
26
27 /**
28 * Ask whether this function item is a map
29 * @return true if this function item is a map, otherwise false
30 */
31
32 boolean isMap();
33
34 /**
35 * Ask whether this function item is an array
36 * @return true if this function item is an array, otherwise false
37 */
38
39 boolean isArray();
40
41 /**
42 * Get the item type of the function item
43 *
44 * @return the function item's type
45 */
46
47 FunctionItemType getFunctionItemType();
48
49 /**
50 * Get the name of the function, or null if it is anonymous
51 *
52 * @return the function name, or null for an anonymous inline function
53 */
54
55 StructuredQName getFunctionName();
56
57 /**
58 * Get the arity of the function
59 *
60 * @return the number of arguments in the function signature
61 */
62
63 int getArity();
64
65 /**
66 * Get the roles of the arguments, for the purposes of streaming
67 * @return an array of OperandRole objects, one for each argument
68 */
69
70 OperandRole[] getOperandRoles();
71
72 /**
73 * Get the function annotations (as defined in XQuery). Returns an empty
74 * list if there are no function annotations.
75 * @return the function annotations
76 */
77
78 AnnotationList getAnnotations();
79
80 /**
81 * Prepare an XPathContext object for evaluating the function
82 *
83 * @param callingContext the XPathContext of the function calling expression
84 * @param originator identifies the location of the caller for diagnostics
85 * @return a suitable context for evaluating the function (which may or may
86 * not be the same as the caller's context)
87 */
88
89 XPathContext makeNewContext(XPathContext callingContext, ContextOriginator originator);
90
91 /**
92 * Invoke the function
93 *
94 * @param context the XPath dynamic evaluation context
95 * @param args the actual arguments to be supplied
96 * @return the result of invoking the function
97 * @throws XPathException if a dynamic error occurs within the function
98 */
99
100 Sequence<?> call(XPathContext context, Sequence[] args) throws XPathException;
101
102 /**
103 * Test whether this FunctionItem is deep-equal to another function item,
104 * under the rules of the deep-equal function
105 *
106 * @param other the other function item
107 * @param context the dynamic evaluation context
108 * @param comparer the object to perform the comparison
109 * @param flags options for how the comparison is performed
110 * @return true if the two function items are deep-equal
111 * @throws XPathException if the comparison cannot be performed
112 */
113
114 boolean deepEquals(Function other, XPathContext context, AtomicComparer comparer, int flags) throws XPathException;
115
116 /**
117 * Get a description of this function for use in error messages. For named functions, the description
118 * is the function name (as a lexical QName). For others, it might be, for example, "inline function",
119 * or "partially-applied ends-with function".
120 * @return a description of the function for use in error messages
121 */
122
123 String getDescription();
124
125 /**
126 * Output information about this function item to the diagnostic explain() output
127 */
128
129 void export(ExpressionPresenter out) throws XPathException;
130
131
132 /**
133 * Check that result type is of the trusted system functions to return a result of the correct type
134 */
135
136 boolean isTrustedResultType();
137
138 /**
139 * Provide a short string showing the contents of the item, suitable
140 * for use in error messages
141 *
142 * @return a depiction of the item suitable for use in error messages
143 */
144 @Override
145 default String toShortString() {
146 return getDescription();
147 }
148
149 /**
150 * Get the genre of this item
151 *
152 * @return the genre: specifically, {@link Genre#FUNCTION}. Overridden for maps and arrays.
153 */
154 @Override
155 default Genre getGenre() {
156 return Genre.FUNCTION;
157 }
158
159 @SafeVarargs
160 static Sequence<?>[] argumentArray(Sequence<?>... args) {
161 return args;
162 }
163 }
164