Package net.sf.saxon.expr.parser
Class RoleDiagnostic
- java.lang.Object
-
- net.sf.saxon.expr.parser.RoleDiagnostic
-
public class RoleDiagnostic extends java.lang.Object
A RoleDiagnostic (formerly RoleLocator) identifies the role in which an expression is used, for example as the third argument of the concat() function. This information is stored in an ItemChecker or CardinalityChecker so that good diagnostics can be achieved when run-time type errors are detected.
-
-
Field Summary
Fields Modifier and Type Field Description static int
AXIS_STEP
static int
BINARY_EXPR
static int
CHARACTER_MAP_EXPANSION
static int
CONTEXT_ITEM
static int
EVALUATE_RESULT
static int
FOR_MEMBER
static int
FUNCTION
static int
FUNCTION_RESULT
static int
INSTRUCTION
static int
MATCH_PATTERN
static int
MISC
static int
OPTION
static int
ORDER_BY
static int
PARAM
static int
TEMPLATE_RESULT
static int
TYPE_OP
static int
UNARY_EXPR
static int
UPDATING_EXPR
static int
VARIABLE
-
Constructor Summary
Constructors Constructor Description RoleDiagnostic(int kind, java.lang.String operation, int operand)
Create information about the role of a subexpression within its parent expression
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
composeErrorMessage(ItemType requiredItemType, Expression supplied, TypeHierarchy th)
Construct a full error message, containing the supplied expression (for use when the error is reported statically)java.lang.String
composeErrorMessage(ItemType requiredItemType, Item item, TypeHierarchy th)
Construct a full error message, displaying the item in error (suitable for use when a type error is reported dynamically)java.lang.String
composeErrorMessage(ItemType requiredItemType, ItemType suppliedItemType)
Construct a full error messagejava.lang.String
composeErrorMessage(ItemType requiredItemType, UType suppliedItemType)
Construct a full error message, in terms of UTypesjava.lang.String
composeRequiredMessage(ItemType requiredItemType)
Construct the part of the message giving the required item typejava.lang.String
getErrorCode()
Get the error code to be produced if a type error is detectedjava.lang.String
getMessage()
Construct and return the error message indicating a type errorboolean
isTypeError()
Ask whether the error code represents a type errorstatic java.lang.String
ordinal(int n)
Get the ordinal representation of a number (used to identify which argument of a function is in error)static RoleDiagnostic
reconstruct(java.lang.String in)
Reconstruct from a saved stringjava.lang.String
save()
Save as a string, for use when serializing the expression treevoid
setErrorCode(java.lang.String code)
Set the error code to be produced if a type error is detected
-
-
-
Field Detail
-
FUNCTION
public static final int FUNCTION
- See Also:
- Constant Field Values
-
BINARY_EXPR
public static final int BINARY_EXPR
- See Also:
- Constant Field Values
-
TYPE_OP
public static final int TYPE_OP
- See Also:
- Constant Field Values
-
VARIABLE
public static final int VARIABLE
- See Also:
- Constant Field Values
-
INSTRUCTION
public static final int INSTRUCTION
- See Also:
- Constant Field Values
-
FUNCTION_RESULT
public static final int FUNCTION_RESULT
- See Also:
- Constant Field Values
-
ORDER_BY
public static final int ORDER_BY
- See Also:
- Constant Field Values
-
TEMPLATE_RESULT
public static final int TEMPLATE_RESULT
- See Also:
- Constant Field Values
-
PARAM
public static final int PARAM
- See Also:
- Constant Field Values
-
UNARY_EXPR
public static final int UNARY_EXPR
- See Also:
- Constant Field Values
-
UPDATING_EXPR
public static final int UPDATING_EXPR
- See Also:
- Constant Field Values
-
EVALUATE_RESULT
public static final int EVALUATE_RESULT
- See Also:
- Constant Field Values
-
CONTEXT_ITEM
public static final int CONTEXT_ITEM
- See Also:
- Constant Field Values
-
AXIS_STEP
public static final int AXIS_STEP
- See Also:
- Constant Field Values
-
OPTION
public static final int OPTION
- See Also:
- Constant Field Values
-
CHARACTER_MAP_EXPANSION
public static final int CHARACTER_MAP_EXPANSION
- See Also:
- Constant Field Values
-
FOR_MEMBER
public static final int FOR_MEMBER
- See Also:
- Constant Field Values
-
MATCH_PATTERN
public static final int MATCH_PATTERN
- See Also:
- Constant Field Values
-
MISC
public static final int MISC
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RoleDiagnostic
public RoleDiagnostic(int kind, java.lang.String operation, int operand)
Create information about the role of a subexpression within its parent expression- Parameters:
kind
- the kind of parent expression, e.g. a function call or a variable referenceoperation
- the name of the object in the parent expression, e.g. a function name or instruction name. A QName is provided in display form, prefix:local. For a string, the special format element/attribute is recognized, for example xsl:for-each/select, to identify the role of an XPath expression in a stylesheet.operand
- Ordinal position of this subexpression, e.g. the position of an argument in a function call
-
-
Method Detail
-
setErrorCode
public void setErrorCode(java.lang.String code)
Set the error code to be produced if a type error is detected- Parameters:
code
- The error code
-
getErrorCode
public java.lang.String getErrorCode()
Get the error code to be produced if a type error is detected- Returns:
- code The error code
-
isTypeError
public boolean isTypeError()
Ask whether the error code represents a type error- Returns:
- true if the error is treated as a type error
-
getMessage
public java.lang.String getMessage()
Construct and return the error message indicating a type error- Returns:
- the constructed error message
-
composeRequiredMessage
public java.lang.String composeRequiredMessage(ItemType requiredItemType)
Construct the part of the message giving the required item type- Parameters:
requiredItemType
- the item type required by the context of a particular expression- Returns:
- a message of the form "Required item type of X is Y"
-
composeErrorMessage
public java.lang.String composeErrorMessage(ItemType requiredItemType, ItemType suppliedItemType)
Construct a full error message- Parameters:
requiredItemType
- the item type required by the context of a particular expressionsuppliedItemType
- the item type inferred by static analysis of an expression- Returns:
- a message of the form "Required item type of A is R; supplied value has item type S"
-
composeErrorMessage
public java.lang.String composeErrorMessage(ItemType requiredItemType, Expression supplied, TypeHierarchy th)
Construct a full error message, containing the supplied expression (for use when the error is reported statically)- Parameters:
requiredItemType
- the item type required by the context of a particular expressionsupplied
- the supplied expressionth
- the type hierarchy- Returns:
- a message of the form "Required item type of A is R; supplied value has item type S"
-
composeErrorMessage
public java.lang.String composeErrorMessage(ItemType requiredItemType, Item item, TypeHierarchy th)
Construct a full error message, displaying the item in error (suitable for use when a type error is reported dynamically)- Parameters:
requiredItemType
- the item type required by the context of a particular expressionitem
- the actual item in error. Must NOT be null (unlike earlier releases).th
- the type hierarchy- Returns:
- a message of the form "Required item type of A is R; supplied value has item type S"
-
composeErrorMessage
public java.lang.String composeErrorMessage(ItemType requiredItemType, UType suppliedItemType)
Construct a full error message, in terms of UTypes- Parameters:
requiredItemType
- the item type required by the context of a particular expressionsuppliedItemType
- the item type inferred by static analysis of an expression- Returns:
- a message of the form "Required item type of A is R; supplied value has item type S"
-
save
public java.lang.String save()
Save as a string, for use when serializing the expression tree- Returns:
- a string representation of the object
-
reconstruct
public static RoleDiagnostic reconstruct(java.lang.String in)
Reconstruct from a saved string- Parameters:
in
- the saved string representation of the RoleDiagnostic- Returns:
- the RoleDiagnostic
-
ordinal
public static java.lang.String ordinal(int n)
Get the ordinal representation of a number (used to identify which argument of a function is in error)- Parameters:
n
- the cardinal number- Returns:
- the ordinal representation
-
-