private void traceItem(Item val, String label, PrintStream out) { if (val==null) { out.println(label + ": empty sequence"); } else { if (val instanceof NodeInfo) { out.println(label + ": " + Type.displayTypeName(val) + ": " + Navigator.getPath((NodeInfo)val)); } else { out.println(label + ": " + Type.displayTypeName(val) + ": " + val.getStringValue()); } } }
/** * Get an ItemType that all the items matching this pattern must satisfy */ @Override public ItemType getItemType() { ItemType t1 = p1.getItemType(); ItemType t2 = p2.getItemType(); return Type.getCommonSuperType(t1, t2); }
/** * Get the (lowest common) item type * * @return integer identifying an item type to which all the items in this * sequence conform * @param th the type hierarchy cache */ public ItemType getItemType(TypeHierarchy th) { if (itemType != null) { // only calculate it the first time return itemType; } if (end==start) { itemType = AnyItemType.getInstance(); } else { itemType = Type.getItemType(value[start], th); for (int i=start+1; i<end; i++) { if (itemType == AnyItemType.getInstance()) { // make a quick exit return itemType; } itemType = Type.getCommonSuperType(itemType, Type.getItemType(value[i], th), th); } } return itemType; }
!Type.isComparable(v0.getPrimitiveType(), v1.getPrimitiveType(), Token.isOrderedOperator(operator))) { XPathException e2 = new XPathException("Cannot compare " + Type.displayTypeName(v0) + " to " + Type.displayTypeName(v1)); e2.setErrorCode("XPTY0004"); e2.setIsTypeError(true);
/** * Test whether a system function with a given name and arity is available. This supports * the function-available() function in XSLT. This method may be called either at compile time * or at run time. * @param functionName * @param arity The number of arguments. This is set to -1 in the case of the single-argument * function-available() function; in this case the method should return true if there is some */ public boolean isAvailable(StructuredQName functionName, int arity) { if (arity != 1 && arity != -1) { return false; } String uri = functionName.getNamespaceURI(); String local = functionName.getLocalName(); if (uri.equals(NamespaceConstant.SCHEMA)) { AtomicType type = (AtomicType)Type.getBuiltInItemType(uri, local); return type != null && type.getFingerprint() != StandardNames.XS_NOTATION; } int fingerprint = config.getNamePool().getFingerprint(uri, local); if (fingerprint == -1) { return false; } else { SchemaType st = config.getSchemaType(fingerprint); return (st != null && st.isAtomicType()); } }
public Item next() throws XPathException { while (true) { AtomicValue i = (AtomicValue)base.next(); if (i==null) break; index++; if (Type.isComparable(primitiveTypeRequired, i.getPrimitiveType(), false)) { try { if (comparer.comparesEqual(i, value)) { current = Int64Value.makeIntegerValue(index); position++; return current; } } catch (ClassCastException err) { // non-comparable values are treated as not equal // Exception shouldn't happen but we catch it anyway } } } current = null; position = -1; return null; }
throws XPathException { if (checkTypes && !Type.isGuaranteedComparable(v0.getPrimitiveType(), v1.getPrimitiveType(), Token.isOrderedOperator(op))) { XPathException e2 = new XPathException("Cannot compare " + Type.displayTypeName(v0) + " to " + Type.displayTypeName(v1)); e2.setErrorCode("XPTY0004"); e2.setIsTypeError(true); throw err.getCause(); } catch (ClassCastException err) { XPathException e2 = new XPathException("Cannot compare " + Type.displayTypeName(v0) + " to " + Type.displayTypeName(v1)); e2.setErrorCode("XPTY0004"); e2.setIsTypeError(true);
argValue.iterate().forEachOrFail(item -> { PJConverter converter = PJConverter.allocate( config, Type.getItemType(item, config.getTypeHierarchy()), StaticProperty.ALLOWS_ONE, Object.class); target.add(converter.convert(item, Object.class, context)); });
if (Type.isGuaranteedComparable(pt0, pt1, false)) { knownToBeComparable = true; } else if (!Type.isPossiblyComparable(pt0, pt1, false)) { env.issueWarning("Cannot compare " + t0.toString() + " to " + t1.toString(), getLocation());
if (!Type.isPossiblyComparable(pt0, pt1, Token.isOrderedOperator(singletonOperator))) { String message = "In {" + toShortString() + "}: cannot compare " + t0 + " to " + t1; if (Cardinality.allowsZero(c0) || Cardinality.allowsZero(c1)) { needsRuntimeCheck = !Type.isGuaranteedGenerallyComparable(pt0, pt1, Token.isOrderedOperator(singletonOperator));
/** * Determine whether two primitive atomic types are comparable under the rules for GeneralComparisons * (that is, untyped atomic values treated as comparable to anything) * * @param t1 the first type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param t2 the second type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param ordered true if testing for an ordering comparison (lt, gt, le, ge). False * if testing for an equality comparison (eq, ne) * @return true if the types are comparable, as defined by the rules of the "=" operator */ public static boolean isGenerallyComparable(/*@NotNull*/ BuiltInAtomicType t1, /*@NotNull*/ BuiltInAtomicType t2, boolean ordered) { return t1.equals(BuiltInAtomicType.ANY_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_ATOMIC) || t1.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || t2.equals(BuiltInAtomicType.UNTYPED_ATOMIC) || isGuaranteedComparable(t1, t2, ordered); }
return null; SimpleType type = Type.getBuiltInSimpleType(uri, localName); if (type != null) { if (type.isAtomicType()) {
/** * Determine whether two primitive atomic types are guaranteed comparable under the rules for GeneralComparisons * (that is, untyped atomic values treated as comparable to anything). This method returns false if a run-time * check is necessary. * * @param t1 the first type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param t2 the second type to compared. * This must be a primitive atomic type as defined by {@link ItemType#getPrimitiveType} * @param ordered true if testing for an ordering comparison (lt, gt, le, ge). False * if testing for an equality comparison (eq, ne) * @return true if the types are comparable, as defined by the rules of the "=" operator */ public static boolean isGuaranteedGenerallyComparable(/*@NotNull*/ BuiltInAtomicType t1, /*@NotNull*/ BuiltInAtomicType t2, boolean ordered) { return !(t1.equals(BuiltInAtomicType.ANY_ATOMIC) || t2.equals(BuiltInAtomicType.ANY_ATOMIC)) && isGenerallyComparable(t1, t2, ordered); }
if (Type.isNodeType(itemType)) { if (required.isAssignableFrom(NodeInfo.class)) { return 20;
!Type.isComparable(v0.getPrimitiveType(), v1.getPrimitiveType(), Token.isOrderedOperator(operator))) { XPathException e2 = new XPathException("Cannot compare " + Type.displayTypeName(v0) + " to " + Type.displayTypeName(v1)); e2.setErrorCode("XPTY0004"); e2.setIsTypeError(true);
/** * Test whether a system function with a given name and arity is available. This supports * the function-available() function in XSLT. This method may be called either at compile time * or at run time. * @param functionName * @param arity The number of arguments. This is set to -1 in the case of the single-argument * function-available() function; in this case the method should return true if there is some */ public boolean isAvailable(StructuredQName functionName, int arity) { if (arity != 1 && arity != -1) { return false; } String uri = functionName.getNamespaceURI(); String local = functionName.getLocalName(); if (uri.equals(NamespaceConstant.SCHEMA)) { AtomicType type = (AtomicType)Type.getBuiltInItemType(uri, local); return type != null && type.getFingerprint() != StandardNames.XS_NOTATION; } int fingerprint = config.getNamePool().getFingerprint(uri, local); if (fingerprint == -1) { return false; } else { SchemaType st = config.getSchemaType(fingerprint); return (st != null && st.isAtomicType()); } }
public Item next() throws XPathException { while (true) { AtomicValue i = (AtomicValue)base.next(); if (i==null) break; index++; if (Type.isComparable(primitiveTypeRequired, i.getPrimitiveType(), false)) { try { if (comparer.comparesEqual(i, value)) { current = Int64Value.makeIntegerValue(index); position++; return current; } } catch (ClassCastException err) { // non-comparable values are treated as not equal // Exception shouldn't happen but we catch it anyway } } } current = null; position = -1; return null; }
throws XPathException { if (checkTypes && !Type.isGuaranteedComparable(v0.getPrimitiveType(), v1.getPrimitiveType(), Token.isOrderedOperator(op))) { XPathException e2 = new XPathException("Cannot compare " + Type.displayTypeName(v0) + " to " + Type.displayTypeName(v1)); e2.setErrorCode("XPTY0004"); e2.setIsTypeError(true); throw err.getCause(); } catch (ClassCastException err) { XPathException e2 = new XPathException("Cannot compare " + Type.displayTypeName(v0) + " to " + Type.displayTypeName(v1)); e2.setErrorCode("XPTY0004"); e2.setIsTypeError(true);
argValue.iterate().forEachOrFail(item -> { PJConverter converter = PJConverter.allocate( config, Type.getItemType(item, config.getTypeHierarchy()), StaticProperty.ALLOWS_ONE, Object.class); target.add(converter.convert(item, Object.class, context)); });
if (Type.isGuaranteedComparable(pt0, pt1, false)) { knownToBeComparable = true; } else if (!Type.isPossiblyComparable(pt0, pt1, false)) { env.issueWarning("Cannot compare " + t0.toString() + " to " + t1.toString(), getLocation());