public MultipleNodeKindTest(UType u) { this.uType = u; if (UType.DOCUMENT.overlaps(u)) { nodeKindMask |= 1 << Type.DOCUMENT; } if (UType.ELEMENT.overlaps(u)) { nodeKindMask |= 1 << Type.ELEMENT; } if (UType.ATTRIBUTE.overlaps(u)) { nodeKindMask |= 1 << Type.ATTRIBUTE; } if (UType.TEXT.overlaps(u)) { nodeKindMask |= 1 << Type.TEXT; } if (UType.COMMENT.overlaps(u)) { nodeKindMask |= 1 << Type.COMMENT; } if (UType.PI.overlaps(u)) { nodeKindMask |= 1 << Type.PROCESSING_INSTRUCTION; } if (UType.NAMESPACE.overlaps(u)) { nodeKindMask |= 1 << Type.NAMESPACE; } }
public MultipleNodeKindTest(UType u) { this.uType = u; if (UType.DOCUMENT.overlaps(u)) { nodeKindMask |= 1 << Type.DOCUMENT; } if (UType.ELEMENT.overlaps(u)) { nodeKindMask |= 1 << Type.ELEMENT; } if (UType.ATTRIBUTE.overlaps(u)) { nodeKindMask |= 1 << Type.ATTRIBUTE; } if (UType.TEXT.overlaps(u)) { nodeKindMask |= 1 << Type.TEXT; } if (UType.COMMENT.overlaps(u)) { nodeKindMask |= 1 << Type.COMMENT; } if (UType.PI.overlaps(u)) { nodeKindMask |= 1 << Type.PROCESSING_INSTRUCTION; } if (UType.NAMESPACE.overlaps(u)) { nodeKindMask |= 1 << Type.NAMESPACE; } }
/** * Determine whether a node test is a peer node test. A peer node test is one that, if it * matches a node, cannot match any of its descendants. For example, text() is a peer node-test. * * @param test the node test * @return true if nodes selected by this node-test will never contain each other as descendants */ private static boolean isPeerNodeTest(NodeTest test) { if (test == null) { return false; } UType uType = test.getUType(); if (uType.overlaps(UType.ELEMENT)) { // can match elements; for the moment, assume these can contain each other return false; } else if (uType.overlaps(UType.DOCUMENT)) { // can match documents; return false if we can also match non-documents return uType.equals(UType.DOCUMENT); } else { return true; } }
/** * Determine whether a node test is a peer node test. A peer node test is one that, if it * matches a node, cannot match any of its descendants. For example, text() is a peer node-test. * * @param test the node test * @return true if nodes selected by this node-test will never contain each other as descendants */ private static boolean isPeerNodeTest(NodeTest test) { if (test == null) { return false; } UType uType = test.getUType(); if (uType.overlaps(UType.ELEMENT)) { // can match elements; for the moment, assume these can contain each other return false; } else if (uType.overlaps(UType.DOCUMENT)) { // can match documents; return false if we can also match non-documents return uType.equals(UType.DOCUMENT); } else { return true; } }
String or = ""; UType u = uType; if (UType.DOCUMENT.overlaps(u)) { fsb.append(or + "item.nodeType===9||item.nodeType===11"); or = "||"; if (UType.ELEMENT.overlaps(u)) { fsb.append(or + "item.nodeType===1"); or = "||"; if (UType.ATTRIBUTE.overlaps(u)) { fsb.append(or + "item.nodeType===2"); or = "||"; if (UType.TEXT.overlaps(u)) { fsb.append(or + "item.nodeType===3"); or = "||"; if (UType.COMMENT.overlaps(u)) { fsb.append(or + "item.nodeType===8"); or = "||"; if (UType.PI.overlaps(u)) { fsb.append(or + "item.nodeType===7"); or = "||"; if (UType.NAMESPACE.overlaps(u)) { fsb.append(or + "item.nodeType===13"); or = "||";
String or = ""; UType u = uType; if (UType.DOCUMENT.overlaps(u)) { fsb.append(or + "item.nodeType===9||item.nodeType===11"); or = "||"; if (UType.ELEMENT.overlaps(u)) { fsb.append(or + "item.nodeType===1"); or = "||"; if (UType.ATTRIBUTE.overlaps(u)) { fsb.append(or + "item.nodeType===2"); or = "||"; if (UType.TEXT.overlaps(u)) { fsb.append(or + "item.nodeType===3"); or = "||"; if (UType.COMMENT.overlaps(u)) { fsb.append(or + "item.nodeType===8"); or = "||"; if (UType.PI.overlaps(u)) { fsb.append(or + "item.nodeType===7"); or = "||"; if (UType.NAMESPACE.overlaps(u)) { fsb.append(or + "item.nodeType===13"); or = "||";
public PrecedingIterator(/*@NotNull*/ TinyTree doc, /*@NotNull*/ TinyNodeImpl node, NodeTest nodeTest, boolean includeAncestors) { this.includeAncestors = includeAncestors; tree = doc; current = node; nextAncestorDepth = doc.depth[node.nodeNr] - 1; this.nodeTest = nodeTest; this.matcher = nodeTest.getMatcher(doc); matchesTextNodes = nodeTest.getUType().overlaps(UType.TEXT); }
public PrecedingIterator(/*@NotNull*/ TinyTree doc, /*@NotNull*/ TinyNodeImpl node, NodeTest nodeTest, boolean includeAncestors) { this.includeAncestors = includeAncestors; tree = doc; current = node; nextAncestorDepth = doc.depth[node.nodeNr] - 1; this.nodeTest = nodeTest; this.matcher = nodeTest.getMatcher(doc); matchesTextNodes = nodeTest.getUType().overlaps(UType.TEXT); }
/** * Create an iterator over the descendant axis * * @param doc the containing TinyTree * @param node the node whose descendants are required * @param nodeTest test to be satisfied by each returned node */ GraftingDescendantIterator(/*@NotNull*/ TinyTree doc, /*@NotNull*/ TinyNodeImpl node, NodeTest nodeTest) { tree = doc; startNode = node; test = nodeTest; nextNodeNr = node.nodeNr; startDepth = doc.depth[nextNodeNr]; matcher = nodeTest.getMatcher(doc); includeTextNodes = nodeTest.getUType().overlaps(UType.TEXT); }
/** * Get extra diagnostic information about why a supplied item does not conform to this * item type, if available. If extra information is returned, it should be in the form of a complete * sentence, minus the closing full stop. No information should be returned for obvious cases. * * @param item the item that doesn't match this type * @param th the type hierarchy cache * @return optionally, a message explaining why the item does not match the type */ @Override public Optional<String> explainMismatch(Item item, TypeHierarchy th) { if (item instanceof NodeInfo) { UType actualKind = UType.getUType(item); if (!getUType().overlaps(actualKind)) { return Optional.of("The supplied value is " + actualKind.toStringWithIndefiniteArticle()); } return Optional.empty(); } else { return Optional.of("The supplied value is " + item.getGenre().getDescription()); } }
/** * Get extra diagnostic information about why a supplied item does not conform to this * item type, if available. If extra information is returned, it should be in the form of a complete * sentence, minus the closing full stop. No information should be returned for obvious cases. * * @param item the item that doesn't match this type * @param th the type hierarchy cache * @return optionally, a message explaining why the item does not match the type */ @Override public Optional<String> explainMismatch(Item item, TypeHierarchy th) { if (item instanceof NodeInfo) { UType actualKind = UType.getUType(item); if (!getUType().overlaps(actualKind)) { return Optional.of("The supplied value is " + actualKind.toStringWithIndefiniteArticle()); } return Optional.empty(); } else { return Optional.of("The supplied value is " + item.getGenre().getDescription()); } }
/** * Get extra diagnostic information about why a supplied item does not conform to this * item type, if available. If extra information is returned, it should be in the form of a complete * sentence, minus the closing full stop. No information should be returned for obvious cases. * * @param item the item that doesn't match this type * @param th the type hierarchy cache * @return optionally, a message explaining why the item does not match the type */ @Override public Optional<String> explainMismatch(Item item, TypeHierarchy th) { Optional<String> explanation = super.explainMismatch(item, th); if (explanation.isPresent()) { return explanation; } if (item instanceof NodeInfo) { UType actualKind = UType.getUType(item); if (!getUType().overlaps(actualKind)) { return Optional.of("The supplied value is " + actualKind.toStringWithIndefiniteArticle()); } else { return Optional.empty(); } } else { return Optional.of("The supplied value is " + item.getGenre().getDescription()); } }
/** * Get a NodeTest to use as a filter for nodes, given a pattern. */ private static NodeTest getNodeTestForPattern(Pattern pattern) { ItemType type = pattern.getItemType(); if (type instanceof NodeTest) { return (NodeTest) type; } else if (pattern.getUType().overlaps(UType.ANY_NODE)) { return AnyNodeTest.getInstance(); } else { return ErrorType.getInstance(); } }
/** * Get extra diagnostic information about why a supplied item does not conform to this * item type, if available. If extra information is returned, it should be in the form of a complete * sentence, minus the closing full stop. No information should be returned for obvious cases. * * @param item the item that doesn't match this type * @param th the type hierarchy cache * @return optionally, a message explaining why the item does not match the type */ @Override public Optional<String> explainMismatch(Item item, TypeHierarchy th) { Optional<String> explanation = super.explainMismatch(item, th); if (explanation.isPresent()) { return explanation; } if (item instanceof NodeInfo) { UType actualKind = UType.getUType(item); if (!getUType().overlaps(actualKind)) { return Optional.of("The supplied value is " + actualKind.toStringWithIndefiniteArticle()); } else { return Optional.empty(); } } else { return Optional.of("The supplied value is " + item.getGenre().getDescription()); } }
/** * Get a NodeTest to use as a filter for nodes, given a pattern. */ private static NodeTest getNodeTestForPattern(Pattern pattern) { ItemType type = pattern.getItemType(); if (type instanceof NodeTest) { return (NodeTest) type; } else if (pattern.getUType().overlaps(UType.ANY_NODE)) { return AnyNodeTest.getInstance(); } else { return ErrorType.getInstance(); } }
private void computeSingleValued(TypeHierarchy th) { ItemType operandType = getOperandItemType(); if (th.relationship(operandType, ArrayItemType.ANY_ARRAY_TYPE) != TypeHierarchy.DISJOINT) { singleValued = false; } else { singleValued = untyped; if (!singleValued) { ItemType nodeType = getBaseExpression().getItemType(); if (nodeType instanceof NodeTest) { SchemaType st = ((NodeTest) nodeType).getContentType(); if (st == Untyped.getInstance() || st.isAtomicType() || (st.isComplexType() && st != AnyType.getInstance())) { singleValued = true; } if (!nodeType.getUType().overlaps(UType.ELEMENT.union(UType.ATTRIBUTE))) { singleValued = true; } } } } }
private void computeSingleValued(TypeHierarchy th) { ItemType operandType = getOperandItemType(); if (th.relationship(operandType, ArrayItemType.ANY_ARRAY_TYPE) != TypeHierarchy.DISJOINT) { singleValued = false; } else { singleValued = untyped; if (!singleValued) { ItemType nodeType = getBaseExpression().getItemType(); if (nodeType instanceof NodeTest) { SchemaType st = ((NodeTest) nodeType).getContentType(); if (st == Untyped.getInstance() || st.isAtomicType() || (st.isComplexType() && st != AnyType.getInstance())) { singleValued = true; } if (!nodeType.getUType().overlaps(UType.ELEMENT.union(UType.ATTRIBUTE))) { singleValued = true; } } } } }