Debian Codegraph @

net/sf/saxon/style/XSLGlobalParam.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.style;
9
10 import net.sf.saxon.expr.Component;
11 import net.sf.saxon.expr.Expression;
12 import net.sf.saxon.expr.instruct.GlobalParam;
13 import net.sf.saxon.expr.parser.Optimizer;
14 import net.sf.saxon.trans.Visibility;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.value.SequenceType;
17
18 /**
19 * An xsl:param element representing a global parameter (stylesheet parameter) in the stylesheet. <br>
20 * The xsl:param element has mandatory attribute name and optional attributes
21 * select, required, as, ...
22 */
23
24 public class XSLGlobalParam extends XSLGlobalVariable {
25
26 protected int getPermittedAttributes() {
27 return
28 SourceBinding.REQUIRED |
29 SourceBinding.SELECT |
30 SourceBinding.AS |
31 SourceBinding.STATIC;
32 }
33
34 /*@Nullable*/ Expression conversion = null;
35
36 public XSLGlobalParam() {
37 sourceBinding.setProperty(SourceBinding.PARAM, true);
38 }
39
40 /**
41 * Visibility for xsl:param is always PUBLIC
42 * @return {@link Visibility#PUBLIC}, always
43 */
44
45 public Visibility getVisibility() {
46 return Visibility.PUBLIC;
47 }
48
49 public void validate(ComponentDeclaration decl) throws XPathException {
50
51 if (sourceBinding.hasProperty(SourceBinding.REQUIRED)) {
52 if (sourceBinding.getSelectExpression() != null) {
53 // NB, we do this test before setting the default select attribute
54 compileError("The select attribute must be absent when required='yes'", "XTSE0010");
55 }
56 if (hasChildNodes()) {
57 compileError("A parameter specifying required='yes' must have empty content", "XTSE0010");
58 }
59 }
60
61 super.validate(decl);
62 }
63
64
65 /**
66 * Compile a global xsl:param element: this ensures space is available for local variables declared within
67 * this global variable
68 */
69
70 public void compileDeclaration(Compilation compilation, ComponentDeclaration decl) throws XPathException {
71 if (sourceBinding.isStatic()) {
72 super.compileDeclaration(compilation, decl);
73
74 } else if (!redundant) {
75 sourceBinding.handleSequenceConstructor(compilation, decl);
76
77 GlobalParam binding = (GlobalParam)compiledVariable;
78 binding.setPackageData(getCompilation().getPackageData());
79 binding.obtainDeclaringComponent(this);
80 Expression select = sourceBinding.getSelectExpression();
81 binding.setSelectExpression(select);
82 binding.setVariableQName(sourceBinding.getVariableQName());
83 initializeBinding(binding);
84
85 binding.setRequiredType(getRequiredType());
86 binding.setRequiredParam(sourceBinding.hasProperty(SourceBinding.REQUIRED));
87 binding.setImplicitlyRequiredParam(sourceBinding.hasProperty(SourceBinding.IMPLICITLY_REQUIRED));
88 sourceBinding.fixupBinding(binding);
89 //compiledVariable = binding;
90
91 Component overridden = getOverriddenComponent();
92 if (overridden != null) {
93 checkCompatibility(overridden);
94 }
95 }
96 }
97
98
99 /**
100 * Get the static type of the parameter. This is the declared type, because we cannot know
101 * the actual value in advance.
102 */
103
104 public SequenceType getRequiredType() {
105 SequenceType declaredType = sourceBinding.getDeclaredType();
106 if (declaredType != null) {
107 return declaredType;
108 } else {
109 return SequenceType.ANY_SEQUENCE;
110 }
111 }
112
113 public void insertBytecodeCandidate(Optimizer opt) {
114
115 }
116 }
117