/** * Construct an annotation list containing a single annotation * @param ann the single annotation in the annotation list * @return a singleton annotation list */ public static AnnotationList singleton(Annotation ann) { return new AnnotationList(Collections.singletonList(ann)); }
/** * Check an annotation list for internal consistency (e.g. rules that %public and %private cannot coexist) * @param where the context where the list appears: one of "DF" (declare function), "DV" (declare variable), * "IF" (inline function declaration), "FT" (function test) * @throws XPathException if the annotation list is not internally consistent */ public void check(Configuration config, String where) throws XPathException { Map<String, List<Annotation>> map = groupByNamespace(); for (Map.Entry<String, List<Annotation>> entry : map.entrySet()) { FunctionAnnotationHandler handler = config.getFunctionAnnotationHandler(entry.getKey()); if (handler != null) { handler.check(new AnnotationList(entry.getValue()), where); } } }
/** * Ask whether the function has an annotation with a particular name * @param name the name of the required annotation */ public boolean hasAnnotation(StructuredQName name) { return annotations.includes(name); }
@Override public void check(AnnotationList annotations, String construct) throws XPathException { for (int i = 0; i < annotations.size(); i++) { Annotation ann = annotations.get(i); for (DisallowedCombination dc : blackList) { if (dc.one.equals(ann.getAnnotationQName()) && dc.where.contains(construct)) { if (dc.two == null) { throw new XPathException("Annotation %" + ann.getAnnotationQName().getLocalPart() + " is not allowed here", dc.errorCode); } else { for (int j = 0; j < i; j++) { Annotation other = annotations.get(j); if (dc.two.equals(other.getAnnotationQName())) { if (dc.two.equals(ann.getAnnotationQName())) { throw new XPathException("Annotation %" + ann.getAnnotationQName().getLocalPart() + " cannot appear more than once", dc.errorCode); } else { throw new XPathException("Annotations %" + ann.getAnnotationQName().getLocalPart() + " and " + other.getAnnotationQName().getLocalPart() + " cannot appear together", dc.errorCode); } } } } } } } }
if (handler != null) { int localRel = SAME_TYPE; AnnotationList firstFiltered = first.filterByNamespace(ns); AnnotationList secondFiltered = second.filterByNamespace(ns); if (firstFiltered.isEmpty()) { if (secondFiltered.isEmpty()) { if (secondFiltered.isEmpty()) { localRel = SUBSUMED_BY; } else {
AnnotationList atns = fn.getAnnotations(); logger.trace("lookupFunctions; fn annotations: {}", atns.size()); StringBuilder buff = new StringBuilder(); for (Annotation atn: atns) {
grumble("Expected 'function' to follow the annotation assertion"); annotations.check(env.getConfiguration(), "IF"); return parseInlineFunction(annotations);
/** * Test whether this function type equals another function type */ public boolean equals(Object other) { if (other instanceof SpecificFunctionType) { SpecificFunctionType f2 = (SpecificFunctionType) other; if (!resultType.equals(f2.resultType)) { return false; } if (argTypes.length != f2.argTypes.length) { return false; } for (int i = 0; i < argTypes.length; i++) { if (!argTypes[i].equals(f2.argTypes[i])) { return false; } } // Compare the annotations if (!getAnnotationAssertions().equals(f2.getAnnotationAssertions())) { return false; } return true; } return false; }
@Override public void check(AnnotationList annotations, String construct) throws XPathException { for (int i = 0; i < annotations.size(); i++) { Annotation ann = annotations.get(i); for (DisallowedCombination dc : blackList) { if (dc.one.equals(ann.getAnnotationQName()) && dc.where.contains(construct)) { if (dc.two == null) { throw new XPathException("Annotation %" + ann.getAnnotationQName().getLocalPart() + " is not allowed here", dc.errorCode); } else { for (int j = 0; j < i; j++) { Annotation other = annotations.get(j); if (dc.two.equals(other.getAnnotationQName())) { if (dc.two.equals(ann.getAnnotationQName())) { throw new XPathException("Annotation %" + ann.getAnnotationQName().getLocalPart() + " cannot appear more than once", dc.errorCode); } else { throw new XPathException("Annotations %" + ann.getAnnotationQName().getLocalPart() + " and " + other.getAnnotationQName().getLocalPart() + " cannot appear together", dc.errorCode); } } } } } } } }
if (handler != null) { int localRel = SAME_TYPE; AnnotationList firstFiltered = first.filterByNamespace(ns); AnnotationList secondFiltered = second.filterByNamespace(ns); if (firstFiltered.isEmpty()) { if (secondFiltered.isEmpty()) { if (secondFiltered.isEmpty()) { localRel = SUBSUMED_BY; } else {
grumble("Expected 'function' to follow the annotation assertion"); annotations.check(env.getConfiguration(), "IF"); return parseInlineFunction(annotations);
/** * Test whether this function type equals another function type */ public boolean equals(Object other) { if (other instanceof SpecificFunctionType) { SpecificFunctionType f2 = (SpecificFunctionType) other; if (!resultType.equals(f2.resultType)) { return false; } if (argTypes.length != f2.argTypes.length) { return false; } for (int i = 0; i < argTypes.length; i++) { if (!argTypes[i].equals(f2.argTypes[i])) { return false; } } // Compare the annotations if (!getAnnotationAssertions().equals(f2.getAnnotationAssertions())) { return false; } return true; } return false; }
/** * Ask whether the function has an annotation with a particular name * @param name the name of the required annotation */ public boolean hasAnnotation(StructuredQName name) { return annotations.includes(name); }
/** * Construct an annotation list containing a single annotation * @param ann the single annotation in the annotation list * @return a singleton annotation list */ public static AnnotationList singleton(Annotation ann) { return new AnnotationList(Collections.singletonList(ann)); }
/** * Check an annotation list for internal consistency (e.g. rules that %public and %private cannot coexist) * @param where the context where the list appears: one of "DF" (declare function), "DV" (declare variable), * "IF" (inline function declaration), "FT" (function test) * @throws XPathException if the annotation list is not internally consistent */ public void check(Configuration config, String where) throws XPathException { Map<String, List<Annotation>> map = groupByNamespace(); for (Map.Entry<String, List<Annotation>> entry : map.entrySet()) { FunctionAnnotationHandler handler = config.getFunctionAnnotationHandler(entry.getKey()); if (handler != null) { handler.check(new AnnotationList(entry.getValue()), where); } } }
AnnotationList annotationList = parseAnnotationsList(); if (isKeyword("function")) { annotationList.check(env.getConfiguration(), "DF"); parseFunctionDeclaration(annotationList); } else if (isKeyword("variable")) { annotationList.check(env.getConfiguration(), "DV"); parseVariableDeclaration(annotationList); } else {
/** * Test whether a function with a given list of annotations satisfies an annotation assertion present * on a function item test. * * @param assertion the annotation assertion present in the function item test * @param annotationList the annotations present on the function being tested * @return true if the assertion is satisfied, false if not */ public boolean satisfiesAssertion(Annotation assertion, AnnotationList annotationList) { String local = assertion.getAnnotationQName().getLocalPart(); if (local.startsWith("not-")) { return !annotationList.includes(local.substring(4)); } else { return annotationList.includes(local); } }
/** * Filter the annotation list by the namespace URI part of the annotation name * @param ns the namespace URI required * @return an annotation list containing the subset of this annotation list where the * annotation names have the required namespace */ public AnnotationList filterByNamespace(String ns) { List<Annotation> out = new ArrayList<>(); for (Annotation ann : list) { if (ann.getAnnotationQName().hasURI(ns)) { out.add(ann); } } return new AnnotationList(out); }
AnnotationList annotationList = parseAnnotationsList(); if (isKeyword("function")) { annotationList.check(env.getConfiguration(), "DF"); parseFunctionDeclaration(annotationList); } else if (isKeyword("variable")) { annotationList.check(env.getConfiguration(), "DV"); parseVariableDeclaration(annotationList); } else {
/** * Test whether a function with a given list of annotations satisfies an annotation assertion present * on a function item test. * * @param assertion the annotation assertion present in the function item test * @param annotationList the annotations present on the function being tested * @return true if the assertion is satisfied, false if not */ public boolean satisfiesAssertion(Annotation assertion, AnnotationList annotationList) { String local = assertion.getAnnotationQName().getLocalPart(); if (local.startsWith("not-")) { return !annotationList.includes(local.substring(4)); } else { return annotationList.includes(local); } }