Debian Codegraph @

net/sf/saxon/expr/flwor/ClauseInfo.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.parser.ExplicitLocation;
11 import net.sf.saxon.expr.parser.Location;
12 import net.sf.saxon.om.NamespaceResolver;
13 import net.sf.saxon.om.StructuredQName;
14 import net.sf.saxon.trace.InstructionInfo;
15 import net.sf.saxon.trace.LocationKind;
16
17 import java.util.Collections;
18 import java.util.Iterator;
19 import java.util.List;
20
21 /**
22 * A "trace" clause in a FLWOR expression, added by a TraceCodeInjector
23 */
24 public class ClauseInfo implements InstructionInfo {
25
26 private Clause clause;
27 private NamespaceResolver nsResolver;
28
29 public ClauseInfo(Clause clause) {
30 this.clause = clause;
31 }
32
33 /**
34 * Get the clause being traced
35 *
36 * @return the clause in the FLWOR expression to which this ClauseInfo relates
37 */
38
39 public Clause getClause() {
40 return clause;
41 }
42
43 /**
44 * Get the type of construct. This will either be the fingerprint of a standard XSLT instruction name
45 * (values in {@link net.sf.saxon.om.StandardNames}: all less than 1024)
46 * or it will be a constant in class {@link LocationKind}.
47 *
48 * @return an integer identifying the kind of construct
49 */
50 public int getConstructType() {
51 return LocationKind.CLAUSE_BASE + clause.getClauseKey();
52 }
53
54 /**
55 * Get a name identifying the object of the expression, for example a function name, template name,
56 * variable name, key name, element name, etc. This is used only where the name is known statically.
57 *
58 * @return the QName of the object declared or manipulated by this instruction or expression
59 */
60 public StructuredQName getObjectName() {
61 LocalVariableBinding[] vars = clause.getRangeVariables();
62 if (vars != null && vars.length > 0) {
63 return vars[0].getVariableQName();
64 } else {
65 return null;
66 }
67 }
68
69 /**
70 * Get the namespace bindings from the static context of the clause
71 *
72 * @return a namespace resolver that reflects the in scope namespaces of the clause
73 */
74
75 public NamespaceResolver getNamespaceResolver() {
76 return nsResolver;
77 }
78
79 /**
80 * Set the namespace bindings from the static context of the clause
81 *
82 * @param nsResolver a namespace resolver that reflects the in scope namespaces of the clause
83 */
84
85 public void setNamespaceResolver(NamespaceResolver nsResolver) {
86 this.nsResolver = nsResolver;
87 }
88
89 /**
90 * Get the system identifier (URI) of the source stylesheet or query module containing
91 * the instruction. This will generally be an absolute URI. If the system
92 * identifier is not known, the method may return null. In some cases, for example
93 * where XML external entities are used, the correct system identifier is not
94 * always retained.
95 *
96 * @return the URI of the containing module
97 */
98 public String getSystemId() {
99 return clause.getLocation().getSystemId();
100 }
101
102 /**
103 * Get the line number of the instruction in the source stylesheet module.
104 * If this is not known, or if the instruction is an artificial one that does
105 * not relate to anything in the source code, the value returned may be -1.
106 *
107 * @return the line number of the expression within the containing module
108 */
109 public int getLineNumber() {
110 return clause.getLocation().getLineNumber();
111 }
112
113 /**
114 * Get an immutable copy of this Location object. By default Location objects may be mutable, so they
115 * should not be saved for later use. The result of this operation holds the same location information,
116 * but in an immutable form.
117 */
118 public Location saveLocation() {
119 return new ExplicitLocation(this);
120 }
121
122 /**
123 * Get the value of a particular property of the instruction. Properties
124 * of XSLT instructions are generally known by the name of the stylesheet attribute
125 * that defines them.
126 *
127 * @param name The name of the required property
128 * @return The value of the requested property, or null if the property is not available
129 */
130 public Object getProperty(String name) {
131 return null;
132 }
133
134 /**
135 * Get an iterator over all the properties available. The values returned by the iterator
136 * will be of type String, and each string can be supplied as input to the getProperty()
137 * method to retrieve the value of the property. The iterator may return properties whose
138 * value is null.
139 *
140 * @return an iterator over the properties.
141 */
142 public Iterator<String> getProperties() {
143 List<String> ls = Collections.emptyList();
144 return ls.iterator();
145 }
146
147 /**
148 * Return the public identifier for the current document event.
149 * <p>The return value is the public identifier of the document
150 * entity or of the external parsed entity in which the markup
151 * triggering the event appears.</p>
152 *
153 * @return A string containing the public identifier, or
154 * null if none is available.
155 * @see #getSystemId
156 */
157 public String getPublicId() {
158 return null;
159 }
160
161 /**
162 * Return the column number where the current document event ends.
163 * This is one-based number of Java <code>char</code> values since
164 * the last line end.
165 * <p><strong>Warning:</strong> The return value from the method
166 * is intended only as an approximation for the sake of diagnostics;
167 * it is not intended to provide sufficient information
168 * to edit the character content of the original XML document.
169 * For example, when lines contain combining character sequences, wide
170 * characters, surrogate pairs, or bi-directional text, the value may
171 * not correspond to the column in a text editor's display. </p>
172 * <p>The return value is an approximation of the column number
173 * in the document entity or external parsed entity where the
174 * markup triggering the event appears.</p>
175 * <p>If possible, the SAX driver should provide the line position
176 * of the first character after the text associated with the document
177 * event. The first column in each line is column 1.</p>
178 *
179 * @return The column number, or -1 if none is available.
180 * @see #getLineNumber
181 */
182 public int getColumnNumber() {
183 return -1;
184 }
185 }
186