Debian Codegraph @

net/sf/saxon/expr/flwor/CountClause.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.expr.flwor;
9
10 import net.sf.saxon.expr.XPathContext;
11 import net.sf.saxon.expr.parser.PathMap;
12 import net.sf.saxon.expr.parser.RebindingMap;
13 import net.sf.saxon.trace.ExpressionPresenter;
14 import net.sf.saxon.trans.XPathException;
15 import net.sf.saxon.tree.util.FastStringBuffer;
16
17 /**
18 * A "count" clause in a FLWOR expression
19 */
20 public class CountClause extends Clause {
21
22 private LocalVariableBinding rangeVariable;
23
24 @Override
25 public int getClauseKey() {
26 return COUNT;
27 }
28
29 public CountClause copy(FLWORExpression flwor, RebindingMap rebindings) {
30 CountClause c2 = new CountClause();
31 c2.rangeVariable = rangeVariable.copy();
32 c2.setPackageData(getPackageData());
33 c2.setLocation(getLocation());
34 return c2;
35 }
36
37 public void setRangeVariable(LocalVariableBinding binding) {
38 this.rangeVariable = binding;
39 }
40
41 public LocalVariableBinding getRangeVariable() {
42 return rangeVariable;
43 }
44
45 /**
46 * Get the number of variables bound by this clause
47 *
48 * @return the number of variable bindings
49 */
50 @Override
51 public LocalVariableBinding[] getRangeVariables() {
52 return new LocalVariableBinding[]{rangeVariable};
53 }
54
55 /**
56 * Get a tuple stream that implements the functionality of this clause, taking its
57 * input from another tuple stream which this clause modifies
58 *
59 * @param base the input tuple stream
60 * @param context
61 * @return the output tuple stream
62 */
63
64 @Override
65 public TuplePull getPullStream(TuplePull base, XPathContext context) {
66 return new CountClausePull(base, this);
67 }
68
69 /**
70 * Get a push-mode tuple stream that implements the functionality of this clause, supplying its
71 * output to another tuple stream
72 *
73 * @param destination the output tuple stream
74 * @param context
75 * @return the push tuple stream that implements the functionality of this clause of the FLWOR
76 * expression
77 */
78 @Override
79 public TuplePush getPushStream(TuplePush destination, XPathContext context) {
80 return new CountClausePush(destination, this);
81 }
82
83 /**
84 * Process the subexpressions of this clause
85 *
86 * @param processor the expression processor used to process the subexpressions
87 */
88 @Override
89 public void processOperands(OperandProcessor processor) throws XPathException {
90 // no action
91 }
92
93 @Override
94 public void addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) {
95 // no action
96 }
97
98 /**
99 * Diagnostic print of expression structure. The abstract expression tree
100 * is written to the supplied output destination.
101 *
102 * @param out the expression presenter used to display the structure
103 */
104 @Override
105 public void explain(ExpressionPresenter out) throws XPathException {
106 out.startElement("count");
107 out.emitAttribute("var", getRangeVariable().getVariableQName());
108 out.endElement();
109 }
110
111 public String toString() {
112 FastStringBuffer fsb = new FastStringBuffer(FastStringBuffer.C64);
113 fsb.append("count $");
114 fsb.append(rangeVariable.getVariableQName().getDisplayName());
115 return fsb.toString();
116 }
117 }
118
119 // Copyright (c) 2011 Saxonica Limited.
120
121