Debian Codegraph @

net/sf/saxon/lib/FunctionAnnotationHandler.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
9 package net.sf.saxon.lib;
10
11 import net.sf.saxon.query.Annotation;
12 import net.sf.saxon.query.AnnotationList;
13 import net.sf.saxon.trans.XPathException;
14
15 /**
16 * Interface to a user-supplied class that handles XQuery annotation assertions in a particular namespace.
17 * The interface provides a callback method used to determine whether the set of annotations on a given user
18 * defined function satisfies a particular annotation assertion defined in a function item test (for example,
19 * the required function type for an argument of a higher-order function)
20 */
21
22 public interface FunctionAnnotationHandler {
23
24 /**
25 * Get the namespace handled by this function annotation handler. This handler will only be called in respect
26 * of annotation assertions that are in this namespace. Use the empty string to refer to the null namespace
27 * @return the namespace handled by this function annotation handler.
28 */
29
30 String getAssertionNamespace();
31
32 /**
33 * Test whether a given set of annotations in this namespace is valid.
34 * @param annotations the annotation list (filtered by namespace: all the annotations
35 * will have names in the namespace for this annotation handler)
36 * @param construct the construct on which this list of annotations appears. One of "DF" (declare function),
37 * "DV" (declare variable), "IF" (inline function), "FT" (function test)
38 * @throws XPathException if the annotation is invalid, or if it is inconsistent with the annotations
39 * in the existing list.
40 */
41
42 void check(AnnotationList annotations, String construct) throws XPathException;
43
44 /**
45 * Test whether a function with a given list of annotations satisfies an annotation assertion present
46 * on a function item test.
47 * @param assertion the annotation assertion present in the function item test
48 * @param annotationList the annotations present on the function being tested, filtered by namespace
49 * @return true if the assertion is satisfied, false if not
50 */
51
52 boolean satisfiesAssertion(Annotation assertion, AnnotationList annotationList);
53
54 /**
55 * Test the relationship of one list of annotation assertions to another list of annotation assertions,
56 * all from this namespace.
57 *
58 * <p>The lists will always be non-empty, because it is assumed that a test with an empty list of
59 * assertions always subsumes a test with a non-empty list.</p>
60 * @param firstList the first list of annotation assertions
61 * @param secondList the second list of annotation assertions
62 * @return the relationship between the two lists, as one of the values {@link net.sf.saxon.type.TypeHierarchy#SAME_TYPE},
63 * {@link net.sf.saxon.type.TypeHierarchy#DISJOINT}, {@link net.sf.saxon.type.TypeHierarchy#OVERLAPS},
64 * {@link net.sf.saxon.type.TypeHierarchy#SUBSUMES}, {@link net.sf.saxon.type.TypeHierarchy#SUBSUMED_BY}.
65 * For example, if the first list is <code>%colour("blue")</code> and the second list is <code>%colour("green")</code>,
66 * and no function can be both blue and green, then return <code>DISJOINT</code>. But if a function can have more than
67 * one colour, return <code>OVERLAPS</code> because the set of functions conforming to the two assertions has a non-empty
68 * intersection. If the first list is <code>%colour("any")</code> and the second list is <code>%colour("blue")</code>,
69 * then return <code>SUBSUMES</code>, because the set of functions satisfying the first assertion is a superset of those
70 * satisfying the second assertion.
71 * <p>The result of this method must be consistent with the {@link #satisfiesAssertion(Annotation, AnnotationList)} method.
72 * For example, if this method indicates that <code>%big</code> subsumes <code>%huge</code>, then it must indeed
73 * be the case that the set of functions that satisfy the assertion <code>%big</code> is a superset of those that
74 * satisfy the assertion <code>%huge</code>.</p>
75 * <p>If in doubt, it is always safe to return <code>OVERLAPS</code>: the worst that can happen is that type-checking is deferred
76 * until run-time.</p>
77 */
78
79 int relationship(AnnotationList firstList, AnnotationList secondList);
80
81
82
83 }
84