/** * Get a UType indicating which kinds of items this Pattern can match. * * @return a UType indicating all the primitive types of item that the pattern can match. */ @Override public UType getUType() { return p1.getUType().union(p2.getUType()); }
/** * Get a UType indicating which kinds of items this Pattern can match. * * @return a UType indicating all the primitive types of item that the pattern can match. */ @Override public UType getUType() { return p1.getUType().union(p2.getUType()); }
/** * Get the corresponding {@link net.sf.saxon.type.UType}. A UType is a union of primitive item * types. * * @return the smallest UType that subsumes this item type */ public UType getUType() { UType u1 = nodetest1.getUType(); UType u2 = nodetest2.getUType(); switch (operator) { case Token.UNION: return u1.union(u2); case Token.INTERSECT: return u1.intersection(u2); case Token.EXCEPT: return u1; default: throw new IllegalArgumentException("Unknown operator in Combined Node Test"); } }
/** * Get the corresponding {@link net.sf.saxon.type.UType}. A UType is a union of primitive item * types. * * @return the smallest UType that subsumes this item type */ public UType getUType() { UType u1 = nodetest1.getUType(); UType u2 = nodetest2.getUType(); switch (operator) { case Token.UNION: return u1.union(u2); case Token.INTERSECT: return u1.intersection(u2); case Token.EXCEPT: return u1; default: throw new IllegalArgumentException("Unknown operator in Combined Node Test"); } }
/** * Get the UType of a Sequence * @param sequence the sequence whose UType is required * @return the UType of the item */ public static UType getUType(GroundedValue sequence) { UnfailingIterator iter = sequence.iterate(); Item item; UType u = UType.VOID; while ((item = iter.next()) != null) { u = u.union(getUType(item)); } return u; }
/** * Get the UType of a Sequence * @param sequence the sequence whose UType is required * @return the UType of the item */ public static UType getUType(GroundedValue sequence) { UnfailingIterator iter = sequence.iterate(); Item item; UType u = UType.VOID; while ((item = iter.next()) != null) { u = u.union(getUType(item)); } return u; }
/** * Given a context item type and an axis, determine the kinds of nodes that can be returned * @param origin the context item type, as a UType representing one or more node kinds * @param axis identifies the axis * @return the set of possible node kinds in the result of the axis expression, as a UType */ public static UType getTargetUType(UType origin, byte axis) { UType resultType = UType.VOID; Set<PrimitiveUType> origins = origin.intersection(UType.ANY_NODE).decompose(); for (PrimitiveUType u : origins) { UType r = axisTransitions.get(makeKey(u, axis)); resultType = resultType.union(r); } return resultType; }
/** * Given a context item type and an axis, determine the kinds of nodes that can be returned * @param origin the context item type, as a UType representing one or more node kinds * @param axis identifies the axis * @return the set of possible node kinds in the result of the axis expression, as a UType */ public static UType getTargetUType(UType origin, byte axis) { UType resultType = UType.VOID; Set<PrimitiveUType> origins = origin.intersection(UType.ANY_NODE).decompose(); for (PrimitiveUType u : origins) { UType r = axisTransitions.get(makeKey(u, axis)); resultType = resultType.union(r); } return resultType; }
/** * Get the UType of the items in a sequence. If the sequence is heterogeneous, * the method returns the lowest common supertype. If the sequence is empty, it returns * ErrorType (the type to which no instance can belong) * * @param sequence the input sequence * @return the lowest common supertype of the types of the items in the sequence */ public static UType getUType(Sequence<?> sequence) { if (sequence instanceof Item) { return UType.getUType((Item) sequence); } else if (sequence instanceof GroundedValue) { UType type = UType.VOID; UnfailingIterator iter = ((GroundedValue) sequence).iterate(); Item item; while ((item = iter.next()) != null) { type = type.union(UType.getUType(item)); if (type == UType.ANY) { break; } } return type; } else { return UType.ANY; } }
/** * Get the UType of the items in a sequence. If the sequence is heterogeneous, * the method returns the lowest common supertype. If the sequence is empty, it returns * ErrorType (the type to which no instance can belong) * * @param sequence the input sequence * @return the lowest common supertype of the types of the items in the sequence */ public static UType getUType(Sequence<?> sequence) { if (sequence instanceof Item) { return UType.getUType((Item) sequence); } else if (sequence instanceof GroundedValue) { UType type = UType.VOID; UnfailingIterator iter = ((GroundedValue) sequence).iterate(); Item item; while ((item = iter.next()) != null) { type = type.union(UType.getUType(item)); if (type == UType.ANY) { break; } } return type; } else { return UType.ANY; } }
/** * After adding an entry to the map, update the cached type information * @param key the new key * @param val the new associated value * @param wasEmpty true if the map was empty before adding these values */ private void updateTypeInformation(AtomicValue key, Sequence<?> val, boolean wasEmpty) { // if (Instrumentation.ACTIVE) { // Instrumentation.count("updateTypeInformation"); // } if (wasEmpty) { keyUType = key.getUType(); valueUType = SequenceTool.getUType(val); keyAtomicType = key.getItemType(); valueItemType = MapItem.getItemTypeOfSequence(val); valueCardinality = SequenceTool.getCardinality(val); } else { keyUType = keyUType.union(key.getUType()); valueUType = valueUType.union(SequenceTool.getUType(val)); valueCardinality = Cardinality.union(valueCardinality, SequenceTool.getCardinality(val)); if (key.getItemType() != keyAtomicType) { keyAtomicType = null; } if (!MapItem.isKnownToConform(val, valueItemType)) { valueItemType = null; } } }
/** * After adding an entry to the map, update the cached type information * @param key the new key * @param val the new associated value * @param wasEmpty true if the map was empty before adding these values */ private void updateTypeInformation(AtomicValue key, Sequence<?> val, boolean wasEmpty) { // if (Instrumentation.ACTIVE) { // Instrumentation.count("updateTypeInformation"); // } if (wasEmpty) { keyUType = key.getUType(); valueUType = SequenceTool.getUType(val); keyAtomicType = key.getItemType(); valueItemType = MapItem.getItemTypeOfSequence(val); valueCardinality = SequenceTool.getCardinality(val); } else { keyUType = keyUType.union(key.getUType()); valueUType = valueUType.union(SequenceTool.getUType(val)); valueCardinality = Cardinality.union(valueCardinality, SequenceTool.getCardinality(val)); if (key.getItemType() != keyAtomicType) { keyAtomicType = null; } if (!MapItem.isKnownToConform(val, valueItemType)) { valueItemType = null; } } }
/** * Get the static type of the expression as a UType, following precisely the type * inference rules defined in the XSLT 3.0 specification. * * @return the static item type of the expression according to the XSLT 3.0 defined rules * @param contextItemType */ @Override public UType getStaticUType(UType contextItemType) { if (isInstruction()) { return super.getStaticUType(contextItemType); } else { UType type = getAction(0).getStaticUType(contextItemType); for (int i = 1; i < size(); i++) { type = type.union(getAction(i).getStaticUType(contextItemType)); } return type; } }
/** * Get the static type of the expression as a UType, following precisely the type * inference rules defined in the XSLT 3.0 specification. * * @return the static item type of the expression according to the XSLT 3.0 defined rules * @param contextItemType */ @Override public UType getStaticUType(UType contextItemType) { if (isInstruction()) { return super.getStaticUType(contextItemType); } else { UType type = getAction(0).getStaticUType(contextItemType); for (int i = 1; i < size(); i++) { type = type.union(getAction(i).getStaticUType(contextItemType)); } return type; } }
/** * Get the static type of the expression as a UType, following precisely the type * inference rules defined in the XSLT 3.0 specification. * * @return the static item type of the expression according to the XSLT 3.0 defined rules * @param contextItemType the static type of the context item */ @Override public UType getStaticUType(UType contextItemType) { if (isInstruction()) { return super.getStaticUType(contextItemType); } else { if (size() == 0) { return UType.VOID; } UType t1 = child(0).getStaticUType(contextItemType); for (int i = 1; i < size(); i++) { t1 = t1.union(child(i).getStaticUType(contextItemType)); if (t1 == UType.ANY) { return t1; // no point going any further } } return t1; } }
/** * Get the static type of the expression as a UType, following precisely the type * inference rules defined in the XSLT 3.0 specification. * * @return the static item type of the expression according to the XSLT 3.0 defined rules * @param contextItemType the static type of the context item */ @Override public UType getStaticUType(UType contextItemType) { if (isInstruction()) { return super.getStaticUType(contextItemType); } else { if (size() == 0) { return UType.VOID; } UType t1 = child(0).getStaticUType(contextItemType); for (int i = 1; i < size(); i++) { t1 = t1.union(child(i).getStaticUType(contextItemType)); if (t1 == UType.ANY) { return t1; // no point going any further } } return t1; } }
/** * Get the static type of the expression as a UType, following precisely the type * inference rules defined in the XSLT 3.0 specification. * * @return the static item type of the expression according to the XSLT 3.0 defined rules * @param contextItemType the static type of the context item */ @Override public UType getStaticUType(UType contextItemType) { switch (operator) { case Token.UNION: return getLhsExpression().getStaticUType(contextItemType).union(getRhsExpression().getStaticUType(contextItemType)); case Token.INTERSECT: return getLhsExpression().getStaticUType(contextItemType).intersection(getRhsExpression().getStaticUType(contextItemType)); case Token.EXCEPT: default: return getLhsExpression().getStaticUType(contextItemType); } }
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; } } } } }
/** * Get the static type of the expression as a UType, following precisely the type * inference rules defined in the XSLT 3.0 specification. * * @return the static item type of the expression according to the XSLT 3.0 defined rules * @param contextItemType the static type of the context item */ @Override public UType getStaticUType(UType contextItemType) { switch (operator) { case Token.UNION: return getLhsExpression().getStaticUType(contextItemType).union(getRhsExpression().getStaticUType(contextItemType)); case Token.INTERSECT: return getLhsExpression().getStaticUType(contextItemType).intersection(getRhsExpression().getStaticUType(contextItemType)); case Token.EXCEPT: default: return getLhsExpression().getStaticUType(contextItemType); } }
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; } } } } }