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.
 Type getContextClassifier()
          Obtains my OCL context classifier as a classifier.
 Operation getContextOperation()
          Obtains my context operation, if my environment is an operation context.
 Property getContextProperty()
          Obtains my context attribute, if my environment is an attribute context.
 Environment getEnvironment()
          Obtains the environment defining my current classifier, operation, or attribute context.
 OCL 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 setContext(org.eclipse.emf.ecore.EClassifier context)
          Sets the classifier 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 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 setInstancePropertyContext(java.lang.Object instance, Property property)
          Sets the operation context implied by the specified instance.
 void setOperationContext(org.eclipse.emf.ecore.EClassifier context, org.eclipse.emf.ecore.EOperation operation)
          Sets the operation context of the OCL expression for which syntax or parsing help is to be provided.
 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 setPropertyContext(org.eclipse.emf.ecore.EClassifier context, org.eclipse.emf.ecore.EStructuralFeature property)
          Sets the attribute context of the OCL expression for which syntax or parsing help is to be provided.
 void setPropertyContext(Type context, Property property)
          Sets the attribute 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(@NonNull
                org.eclipse.emf.ecore.EClassifier 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(Type, Operation), setPropertyContext(Type, Property)

setContext

void setContext(@NonNull
                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(Type, Operation), setPropertyContext(Type, Property)

getContextClassifier

@Nullable
Type getContextClassifier()
Obtains my OCL context classifier as a classifier.

Returns:
my context classifier (never null)

setOperationContext

void setOperationContext(@NonNull
                         org.eclipse.emf.ecore.EClassifier context,
                         @NonNull
                         org.eclipse.emf.ecore.EOperation 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(EClassifier)

setOperationContext

void setOperationContext(@NonNull
                         Type context,
                         @NonNull
                         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(Type)

getContextOperation

@Nullable
Operation getContextOperation()
Obtains my context operation, if my environment is an operation context.

Returns:
my context operation, or null if there is only a classifier or attribute context

setPropertyContext

void setPropertyContext(@NonNull
                        Type context,
                        @NonNull
                        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(Type)

setPropertyContext

void setPropertyContext(@NonNull
                        org.eclipse.emf.ecore.EClassifier context,
                        @NonNull
                        org.eclipse.emf.ecore.EStructuralFeature 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(EClassifier)

getContextProperty

@Nullable
Property getContextProperty()
Obtains my context attribute, if my environment is an attribute context.

Returns:
my context attribute, or null if there is only a classifier or operation context

setInstanceContext

void setInstanceContext(@NonNull
                        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(EClassifier)

setInstanceOperationContext

void setInstanceOperationContext(@NonNull
                                 java.lang.Object instance,
                                 @NonNull
                                 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(Type, Operation)

setInstancePropertyContext

void setInstancePropertyContext(@NonNull
                                java.lang.Object instance,
                                @NonNull
                                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:
setPropertyContext(Type, Property)

getOCL

@NonNull
OCL 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

@NonNull
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
See Also:
setContext(Type), setOperationContext(Type, Operation), setPropertyContext(Type, Property)

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

@NonNull
ExpressionInOCL createQuery(@NonNull
                                    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

@NonNull
ExpressionInOCL createInvariant(@NonNull
                                        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

@NonNull
ExpressionInOCL createPrecondition(@NonNull
                                           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(Type, Operation)

createPostcondition

@NonNull
ExpressionInOCL createPostcondition(@NonNull
                                            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(Type, Operation)

createBodyCondition

@NonNull
ExpressionInOCL createBodyCondition(@NonNull
                                            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(Type, Operation)

createDerivedValueExpression

@NonNull
ExpressionInOCL createDerivedValueExpression(@NonNull
                                                     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:
setPropertyContext(Type, Property)

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