org.eclipse.ocl.examples.pivot.helper
Interface OCLHelper

All Known Implementing Classes:
OCLHelperImpl

public interface OCLHelper

A utility object that provides OCL syntax completion suggestions for OCL expressions and convenient API for parsing OCL constraint expressions without the encumbrance of context declarations. The latter is most useful for processing OCL constraints and expressions embedded in the user model, where the context is implied by the placement of the constraint in the model.

An OCL helper is created by the OCL.createOCLHelper() factory method and inherits the current context Environment of the OCL that created it.

Since 1.2, the helper supplies diagnostics indicating any problems encountered while parsing. The diagnostics pertain always to the most recently executed parse operation.

Note that this interface is not intended to be implemented by clients.

See the Environment class for a description of the generic type parameters of this class.

Author:
Yasser Lulu, Christian W. Damus (cdamus)
See Also:
OCL.createOCLHelper()

Method Summary
 ExpressionInOcl createBodyCondition(java.lang.String expression)
          Creates an operation body.
 ExpressionInOcl createDerivedValueExpression(java.lang.String expression)
          Creates a property derived value expression.
 ExpressionInOcl createInvariant(java.lang.String expression)
          Creates an invariant constraint in the current classifier context.
 ExpressionInOcl createPostcondition(java.lang.String expression)
          Creates an operation postcondition constraint.
 ExpressionInOcl createPrecondition(java.lang.String expression)
          Creates an operation precondition constraint.
 ExpressionInOcl createQuery(java.lang.String expression)
          Creates a query expression in the current classifier context.
 Environment getEnvironment()
          Obtains the environment defining my current classifier, operation, or attribute context.
 OCLBase getOCL()
          Obtains the OCL instance that created me.
 org.eclipse.emf.common.util.Diagnostic getProblems()
          Obtains problems, if any, found in parsing the last OCL constraint or query expression.
 boolean isValidating()
          Queries whether I validate the expressions that I parse.
 void setAttributeContext(Type context, Property property)
          Sets the attribute context of the OCL expression for which syntax or parsing help is to be provided.
 void setContext(Type context)
          Sets the classifier context of the OCL expression for which syntax or parsing help is to be provided.
 void setInstanceAttributeContext(java.lang.Object instance, Property property)
          Sets the operation context implied by the specified instance.
 void setInstanceContext(java.lang.Object instance)
          Sets the classifier context implied by the specified instance.
 void setInstanceOperationContext(java.lang.Object instance, Operation operation)
          Sets the operation context implied by the specified instance.
 void setOperationContext(Type context, Operation operation)
          Sets the operation context of the OCL expression for which syntax or parsing help is to be provided.
 void setValidating(boolean validating)
          Sets whether I should validate the expressions that I parse.
 

Method Detail

setContext

void setContext(Type context)
Sets the classifier context of the OCL expression for which syntax or parsing help is to be provided.

Parameters:
context - the OCL context classifier
See Also:
#setOperationContext(Object, Object), #setAttributeContext(Object, Object)

setOperationContext

void setOperationContext(Type context,
                         Operation operation)
Sets the operation context of the OCL expression for which syntax or parsing help is to be provided. The operation is the model element against which the OCL will be parsed as an operation applicable to an OCL type. Note that the operation needs not necessarily be defined by the specified context classifier; it could be inherited.

Parameters:
context - the OCL context classifier
operation - the OCL context operation
See Also:
#setContext(Object)

setAttributeContext

void setAttributeContext(Type context,
                         Property property)
Sets the attribute context of the OCL expression for which syntax or parsing help is to be provided. The attribute is the model element against which the OCL will be parsed as an attribute available in an OCL classifier. Note that the attribute needs not necessarily be defined by the specified context classifier; it could be inherited.

Parameters:
context - the OCL context classifier
property - the OCL context attribute
See Also:
#setContext(Object)

setInstanceContext

void setInstanceContext(java.lang.Object instance)
Sets the classifier context implied by the specified instance. The appropriate classifier will be determined from the run-time type of this object, if possible. If not possible, OclAny is assumed.

This method is convenient for ad hoc parsing and evaluation of OCL constraints or expressions in the context of a model instance.

Parameters:
instance - the OCL context instance
See Also:
#setContext(Object)

setInstanceOperationContext

void setInstanceOperationContext(java.lang.Object instance,
                                 Operation operation)
Sets the operation context implied by the specified instance. The appropriate classifier will be determined from the run-time type of this object, if possible. If not possible, OclAny is assumed.

This method is convenient for ad hoc parsing and evaluation of OCL constraints or expressions in the context of a model instance.

Parameters:
instance - the OCL context instance
operation - the OCL context operation
See Also:
#setOperationContext(Object, Object)

setInstanceAttributeContext

void setInstanceAttributeContext(java.lang.Object instance,
                                 Property property)
Sets the operation context implied by the specified instance. The appropriate classifier will be determined from the run-time type of this object, if possible. If not possible, OclAny is assumed.

This method is convenient for ad hoc parsing and evaluation of OCL constraints or expressions in the context of a model instance.

Parameters:
instance - the OCL context instance
property - the OCL context attribute
See Also:
#setAttributeContext(Object, Object)

getOCL

OCLBase getOCL()
Obtains the OCL instance that created me. Note that many of the generic type parameter bindings will not be known, so clients should keep track of the OCL instance themselves where that is a problem.

Returns:
the OCL instance that created me

getEnvironment

Environment getEnvironment()
Obtains the environment defining my current classifier, operation, or attribute context. Accessing the environment is convenient for, e.g., adding variable definitions to insert global objects into the OCL context.

Returns:
my current context environment, or null if I have not yet been assigned a context
Since:
1.2
See Also:
#setContext(Object), #setOperationContext(Object, Object), #setAttributeContext(Object, Object)

isValidating

boolean isValidating()
Queries whether I validate the expressions that I parse. Validation applies more well-formedness checks than are implied by parsing, especially because parsing supports partial (incomplete) expressions for syntax completion. Validation adds some amount of processing, which is not necessary in all cases.

Returns:
whether I validate the expressions that I parse. Validation is on by default

setValidating

void setValidating(boolean validating)
Sets whether I should validate the expressions that I parse.

Parameters:
validating - whether I should validate parsed expressions

createQuery

ExpressionInOcl createQuery(java.lang.String expression)
                            throws ParserException
Creates a query expression in the current classifier context. This may be specified, for example, as an expression value in the model.

Parameters:
expression - the expression (without any context declaration). This expression can have any result type; it needs not be a boolean
Returns:
the query expression
Throws:
ParserException - if the expression fails to parse

createInvariant

ExpressionInOcl createInvariant(java.lang.String expression)
                                throws ParserException
Creates an invariant constraint in the current classifier context.

Parameters:
expression - the constraint expression (without any context declaration). This must be a boolean-valued expression
Returns:
the invariant constraint
Throws:
ParserException - if the expression fails to parse

createPrecondition

ExpressionInOcl createPrecondition(java.lang.String expression)
                                   throws ParserException
Creates an operation precondition constraint. This is appropriate only if my context is an operation.

Parameters:
expression - the constraint expression (without any context declaration). This must be a boolean-valued expression
Returns:
the precondition
Throws:
ParserException - if the expression fails to parse
See Also:
#setOperationContext(Object, Object)

createPostcondition

ExpressionInOcl createPostcondition(java.lang.String expression)
                                    throws ParserException
Creates an operation postcondition constraint. This is appropriate only if my context is an operation.

Parameters:
expression - the constraint expression (without any context declaration). This must be a boolean-valued expression
Returns:
the postcondition
Throws:
ParserException - if the expression fails to parse
See Also:
#setOperationContext(Object, Object)

createBodyCondition

ExpressionInOcl createBodyCondition(java.lang.String expression)
                                    throws ParserException
Creates an operation body. This is appropriate only if my context is an operation.

Parameters:
expression - the constraint expression (without any context declaration). Ordinarily, this is an expression of the same type as the operation, specifying the value of the operation. Alternatively, this may be a boolean-valued expression phrased like a post-condition (according to the well-formedness rules of UML constraints)
Returns:
the body condition
Throws:
ParserException - if the expression fails to parse
See Also:
#setOperationContext(Object, Object)

createDerivedValueExpression

ExpressionInOcl createDerivedValueExpression(java.lang.String expression)
                                             throws ParserException
Creates a property derived value expression. This is appropriate only if my context is a property.

Parameters:
expression - the derived value expression (without any context declaration). This must conform to my context property type
Returns:
the derived value expression
Throws:
ParserException - if the expression fails to parse or is not valid for my context property
See Also:
#setAttributeContext(Object, Object)

getProblems

org.eclipse.emf.common.util.Diagnostic getProblems()
Obtains problems, if any, found in parsing the last OCL constraint or query expression.

Returns:
parsing problems or null if all was OK
Since:
1.2