|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.saxon.expr.TypeChecker
public final class TypeChecker
This class provides Saxon's type checking capability. It contains a static method, staticTypeCheck, which is called at compile time to perform type checking of an expression. This class is never instantiated.
Method Summary | |
---|---|
static XPathException |
ebvError(Expression exp,
TypeHierarchy th)
Test whether a given expression is capable of returning a value that has an effective boolean value. |
static Expression |
staticTypeCheck(Expression supplied,
SequenceType req,
boolean backwardsCompatible,
RoleLocator role,
ExpressionVisitor visitor)
Check an expression against a required type, modifying it if necessary. |
static Expression |
strictTypeCheck(Expression supplied,
SequenceType req,
RoleLocator role,
StaticContext env)
Check an expression against a required type, modifying it if necessary. |
static XPathException |
testConformance(ValueRepresentation val,
SequenceType requiredType,
XPathContext context)
Test whether a given value conforms to a given type |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Expression staticTypeCheck(Expression supplied, SequenceType req, boolean backwardsCompatible, RoleLocator role, ExpressionVisitor visitor) throws XPathException
This method takes the supplied expression and checks to see whether it is known statically to conform to the specified type. There are three possible outcomes. If the static type of the expression is a subtype of the required type, the method returns the expression unchanged. If the static type of the expression is incompatible with the required type (for example, if the supplied type is integer and the required type is string) the method throws an exception (this results in a compile-time type error being reported). If the static type is a supertype of the required type, then a new expression is constructed that evaluates the original expression and checks the dynamic type of the result; this new expression is returned as the result of the method.
The rules applied are those for function calling in XPath, that is, the rules that the argument of a function call must obey in relation to the signature of the function. Some contexts require slightly different rules (for example, operands of polymorphic operators such as "+"). In such cases this method cannot be used.
Note that this method does not do recursive type-checking of the sub-expressions.
supplied
- The expression to be type-checkedreq
- The required type for the context in which the expression is usedbackwardsCompatible
- True if XPath 1.0 backwards compatibility mode is applicablerole
- Information about the role of the subexpression within the
containing expression, used to provide useful error messagesvisitor
- An expression visitor
XPathException
- if the supplied type is statically inconsistent with the
required type (that is, if they have no common subtype)public static Expression strictTypeCheck(Expression supplied, SequenceType req, RoleLocator role, StaticContext env) throws XPathException
staticTypeCheck(net.sf.saxon.expr.Expression, net.sf.saxon.value.SequenceType, boolean, net.sf.saxon.expr.RoleLocator, net.sf.saxon.expr.ExpressionVisitor)
used for expressions that
declare variables in XQuery. In these contexts, conversions such as numeric
type promotion and atomization are not allowed.
supplied
- The expression to be type-checkedreq
- The required type for the context in which the expression is usedrole
- Information about the role of the subexpression within the
containing expression, used to provide useful error messagesenv
- The static context containing the types being checked. At present
this is used only to locate a NamePool
XPathException
- if the supplied type is statically inconsistent with the
required type (that is, if they have no common subtype)public static XPathException testConformance(ValueRepresentation val, SequenceType requiredType, XPathContext context) throws XPathException
val
- the valuerequiredType
- the required typecontext
- XPath dynamic context
XPathException
- if a failure occurs reading the valuepublic static XPathException ebvError(Expression exp, TypeHierarchy th)
exp
- the given expressionth
- the type hierarchy cache
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |