Debian Codegraph @

net/sf/saxon/expr/TreatExpression.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;
9
10 import net.sf.saxon.expr.parser.RoleDiagnostic;
11 import net.sf.saxon.value.SequenceType;
12
13 /**
14 * Treat Expression: implements "treat as data-type ( expression )". This is a factory class only.
15 */
16
17 public abstract class TreatExpression {
18
19 /**
20 * This class is never instantiated
21 */
22 private TreatExpression() {
23 }
24
25 /**
26 * Make a treat expression with error code XPDY0050
27 *
28 * @param sequence the expression whose result is to be checked
29 * @param type the type against which the result is to be checked
30 * @return the expression
31 */
32
33 public static Expression make(Expression sequence, SequenceType type) {
34 return make(sequence, type, "XPDY0050");
35 }
36
37 /**
38 * Make a treat expression with a non-standard error code
39 *
40 * @param sequence the expression whose result is to be checked
41 * @param type the type against which the result is to be checked
42 * @param errorCode the error code to be returned if the check fails
43 * @return the expression
44 */
45
46 public static Expression make(Expression sequence, SequenceType type, String errorCode) {
47 RoleDiagnostic role = new RoleDiagnostic(RoleDiagnostic.TYPE_OP, "treat as", 0);
48 role.setErrorCode(errorCode);
49 Expression e = CardinalityChecker.makeCardinalityChecker(sequence, type.getCardinality(), role);
50 return new ItemChecker(e, type.getPrimaryType(), role);
51 }
52
53 }
54