Debian Codegraph @

net/sf/saxon/trans/ComponentTest.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.trans;
9
10
11 import net.sf.saxon.expr.instruct.Actor;
12 import net.sf.saxon.om.StandardNames;
13 import net.sf.saxon.pattern.LocalNameTest;
14 import net.sf.saxon.pattern.NameTest;
15 import net.sf.saxon.pattern.NamespaceTest;
16 import net.sf.saxon.pattern.QNameTest;
17
18 public class ComponentTest {
19
20 private int componentKind;
21 private QNameTest nameTest;
22 private int arity;
23
24 public ComponentTest(int componentKind, QNameTest nameTest, int arity) {
25 this.componentKind = componentKind;
26 this.nameTest = nameTest;
27 this.arity = arity;
28 }
29
30 public int getComponentKind() {
31 return componentKind;
32 }
33
34 public QNameTest getQNameTest() {
35 return nameTest;
36 }
37
38 public int getArity() {
39 return arity;
40 }
41
42 public boolean isPartialWildcard() {
43 return nameTest instanceof LocalNameTest || nameTest instanceof NamespaceTest;
44 }
45
46 public boolean matches(Actor component) {
47 return matches(component.getSymbolicName());
48 }
49
50 public boolean matches(SymbolicName sn) {
51 return (componentKind == -1 || sn.getComponentKind() == componentKind) &&
52 nameTest.matches(sn.getComponentName()) &&
53 !((componentKind == StandardNames.XSL_FUNCTION) && arity != -1 && arity != ((SymbolicName.F) sn).getArity());
54 }
55
56 public SymbolicName getSymbolicNameIfExplicit() {
57 if (nameTest instanceof NameTest) {
58 if (componentKind == StandardNames.XSL_FUNCTION) {
59 return new SymbolicName.F(((NameTest)nameTest).getMatchingNodeName(), arity);
60 } else {
61 return new SymbolicName(componentKind, ((NameTest) nameTest).getMatchingNodeName());
62 }
63 } else {
64 return null;
65 }
66 }
67
68 public boolean equals(Object other) {
69 return other instanceof ComponentTest &&
70 ((ComponentTest) other).componentKind == componentKind &&
71 ((ComponentTest) other).arity == arity &&
72 ((ComponentTest) other).nameTest.equals(nameTest);
73 }
74
75 public int hashCode() {
76 return componentKind ^ arity ^ nameTest.hashCode();
77 }
78 }