org.eclipse.emf.ocl.expressions.util
Class ExpressionsUtil

java.lang.Object
  extended byorg.eclipse.emf.ocl.expressions.util.ExpressionsUtil

public class ExpressionsUtil
extends java.lang.Object

Static utilities for working with expressions.


Method Summary
static org.eclipse.emf.ecore.EObject containerOfType(org.eclipse.emf.ecore.EClass type, org.eclipse.emf.ecore.EObject eObject)
          Computes the nearest container of an eObject that has the specified type.
static OCLExpression createBodyCondition(org.eclipse.emf.ecore.EClassifier classifier, org.eclipse.emf.ecore.EOperation context, java.lang.String expression, boolean validate)
          Creates an operation body condition expression.
static OCLExpression createBodyCondition(Environment env, java.lang.String expression, boolean validate)
          Creates an operation body condition expression in the specified environment.
static OCLExpression createBodyCondition(org.eclipse.emf.ecore.EOperation context, java.lang.String expression, boolean validate)
          Creates an operation body condition expression.
static Environment createClassifierContext(org.eclipse.emf.ecore.EClassifier classifier)
          Creates an environment for OCL constraints in the context of the specified classifier.
static OCLExpression createDerivedValueExpression(org.eclipse.emf.ecore.EClassifier classifier, org.eclipse.emf.ecore.EStructuralFeature context, java.lang.String expression, boolean validate)
          Creates an property derived value expression.
static OCLExpression createDerivedValueExpression(Environment env, java.lang.String expression, boolean validate)
          Creates a property derived value expression in the specified environment.
static OCLExpression createDerivedValueExpression(org.eclipse.emf.ecore.EStructuralFeature context, java.lang.String expression, boolean validate)
          Creates a property derived value expression.
static OCLExpression createInitialValueExpression(org.eclipse.emf.ecore.EClassifier classifier, org.eclipse.emf.ecore.EStructuralFeature context, java.lang.String expression, boolean validate)
          Creates an property initial value expression.
static OCLExpression createInitialValueExpression(Environment env, java.lang.String expression, boolean validate)
          Creates a property initial value expression in the specified environment.
static OCLExpression createInitialValueExpression(org.eclipse.emf.ecore.EStructuralFeature context, java.lang.String expression, boolean validate)
          Creates a property initial value expression.
static OCLExpression createInvariant(org.eclipse.emf.ecore.EClassifier context, java.lang.String expression, boolean validate)
          Creates an invariant constraint expression.
static OCLExpression createInvariant(Environment env, java.lang.String expression, boolean validate)
          Creates an invariant constraint expression in the specified environment.
static Environment createOperationContext(org.eclipse.emf.ecore.EClassifier classifier, org.eclipse.emf.ecore.EOperation operation)
          Creates an environment for OCL constraints in the context of the specified classifier and operation.
static Environment createOperationContext(org.eclipse.emf.ecore.EOperation operation)
          Creates an environment for OCL constraints in the context of the specified operation.
static OCLExpression createPostcondition(org.eclipse.emf.ecore.EClassifier classifier, org.eclipse.emf.ecore.EOperation context, java.lang.String expression, boolean validate)
          Creates an operation postcondition constraint expression.
static OCLExpression createPostcondition(Environment env, java.lang.String expression, boolean validate)
          Creates an operation postcondition constraint expression in the specified environment.
static OCLExpression createPostcondition(org.eclipse.emf.ecore.EOperation context, java.lang.String expression, boolean validate)
          Creates an operation postcondition constraint expression.
static OCLExpression createPrecondition(org.eclipse.emf.ecore.EClassifier classifier, org.eclipse.emf.ecore.EOperation context, java.lang.String expression, boolean validate)
          Creates an operation precondition constraint expression.
static OCLExpression createPrecondition(Environment env, java.lang.String expression, boolean validate)
          Creates an operation precondition constraint expression in the specified environment.
static OCLExpression createPrecondition(org.eclipse.emf.ecore.EOperation context, java.lang.String expression, boolean validate)
          Creates an operation precondition constraint expression.
static Environment createPropertyContext(org.eclipse.emf.ecore.EClassifier classifier, org.eclipse.emf.ecore.EStructuralFeature property)
          Creates an environment for OCL constraints in the context of the specified classifier and property.
static Environment createPropertyContext(org.eclipse.emf.ecore.EStructuralFeature property)
          Creates an environment for OCL constraints in the context of the specified property.
static OCLExpression createQuery(org.eclipse.emf.ecore.EClassifier context, java.lang.String expression, boolean validate)
          Creates a query expression with an arbitrary result type.
static OCLExpression createQuery(Environment env, java.lang.String expression, boolean validate)
          Creates a query expression with an arbitrary result type in the specified environment.
static void define(org.eclipse.emf.ecore.EClassifier context, java.lang.String expression)
          Defines a property or an operation of the specified signature.
static org.eclipse.emf.ecore.ETypedElement define(Environment env, java.lang.String defExpression)
          Defines a property or operation of the specified signature.
static boolean isInPostcondition(OCLExpression exp)
          Checks whether the specified OCL expression is in an operation postcondition constraint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createClassifierContext

public static Environment createClassifierContext(org.eclipse.emf.ecore.EClassifier classifier)
Creates an environment for OCL constraints in the context of the specified classifier.

Parameters:
classifier - the context classifier
Returns:
the OCL environment

createOperationContext

public static Environment createOperationContext(org.eclipse.emf.ecore.EClassifier classifier,
                                                 org.eclipse.emf.ecore.EOperation operation)
Creates an environment for OCL constraints in the context of the specified classifier and operation. This is useful when defining constraints on the redefinition of an operation in the context of a classifier that inherits it (i.e., different from the classifier that defines the operation).

Parameters:
classifier - the context classifier
operation - the operation context
Returns:
the OCL environment
See Also:
ExpressionsUtil.createOperationContext(EOperation)

createOperationContext

public static Environment createOperationContext(org.eclipse.emf.ecore.EOperation operation)
Creates an environment for OCL constraints in the context of the specified operation. The implied classifier context is the classifier that defines the operation.

Parameters:
operation - the operation context
Returns:
the OCL environment
See Also:
ExpressionsUtil.createOperationContext(EClassifier, EOperation)

createPropertyContext

public static Environment createPropertyContext(org.eclipse.emf.ecore.EClassifier classifier,
                                                org.eclipse.emf.ecore.EStructuralFeature property)
Creates an environment for OCL constraints in the context of the specified classifier and property. This is useful when defining constraints on the redefinition of a property in the context of a classifier that inherits it (i.e., different from the classifier that defines the property).

Parameters:
classifier - the context classifier
property - the property context
Returns:
the OCL environment
See Also:
#createProper

createPropertyContext

public static Environment createPropertyContext(org.eclipse.emf.ecore.EStructuralFeature property)
Creates an environment for OCL constraints in the context of the specified property. The implied classifier context is the classifier that defines the property.

Parameters:
property - the property context
Returns:
the OCL environment
See Also:
ExpressionsUtil.createOperationContext(EClassifier, EOperation)

createQuery

public static OCLExpression createQuery(org.eclipse.emf.ecore.EClassifier context,
                                        java.lang.String expression,
                                        boolean validate)
                                 throws ParserException
Creates a query expression with an arbitrary result type.

Parameters:
context - the invariant's classifier context
expression - the expression (without any "inv:" or similar preamble)
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createQuery

public static OCLExpression createQuery(Environment env,
                                        java.lang.String expression,
                                        boolean validate)
                                 throws ParserException
Creates a query expression with an arbitrary result type in the specified environment.

Parameters:
env - the OCL environment
expression - the expression (without any "inv:" or similar preamble)
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createInvariant

public static OCLExpression createInvariant(org.eclipse.emf.ecore.EClassifier context,
                                            java.lang.String expression,
                                            boolean validate)
                                     throws ParserException
Creates an invariant constraint expression.

Parameters:
context - the invariant's classifier context
expression - the expression (without the "inv:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createInvariant

public static OCLExpression createInvariant(Environment env,
                                            java.lang.String expression,
                                            boolean validate)
                                     throws ParserException
Creates an invariant constraint expression in the specified environment.

Parameters:
env - the OCL environment
expression - the expression (without the "inv:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createPrecondition

public static OCLExpression createPrecondition(org.eclipse.emf.ecore.EOperation context,
                                               java.lang.String expression,
                                               boolean validate)
                                        throws ParserException
Creates an operation precondition constraint expression.

Parameters:
context - the precondition's operation context
expression - the expression (without the "pre:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createPrecondition

public static OCLExpression createPrecondition(org.eclipse.emf.ecore.EClassifier classifier,
                                               org.eclipse.emf.ecore.EOperation context,
                                               java.lang.String expression,
                                               boolean validate)
                                        throws ParserException
Creates an operation precondition constraint expression.

Parameters:
classifier - the context classifier
context - the precondition's operation context
expression - the expression (without the "pre:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createPrecondition

public static OCLExpression createPrecondition(Environment env,
                                               java.lang.String expression,
                                               boolean validate)
                                        throws ParserException
Creates an operation precondition constraint expression in the specified environment.

Parameters:
env - the OCL environment
expression - the expression (without the "pre:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createPostcondition

public static OCLExpression createPostcondition(org.eclipse.emf.ecore.EOperation context,
                                                java.lang.String expression,
                                                boolean validate)
                                         throws ParserException
Creates an operation postcondition constraint expression.

Parameters:
context - the postcondition's operation context
expression - the expression (without the "post:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createPostcondition

public static OCLExpression createPostcondition(org.eclipse.emf.ecore.EClassifier classifier,
                                                org.eclipse.emf.ecore.EOperation context,
                                                java.lang.String expression,
                                                boolean validate)
                                         throws ParserException
Creates an operation postcondition constraint expression.

Parameters:
classifier - the context classifier
context - the postcondition's operation context
expression - the expression (without the "post:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createPostcondition

public static OCLExpression createPostcondition(Environment env,
                                                java.lang.String expression,
                                                boolean validate)
                                         throws ParserException
Creates an operation postcondition constraint expression in the specified environment.

Parameters:
env - the OCL environment
expression - the expression (without the "post:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createBodyCondition

public static OCLExpression createBodyCondition(org.eclipse.emf.ecore.EOperation context,
                                                java.lang.String expression,
                                                boolean validate)
                                         throws ParserException
Creates an operation body condition expression.

Parameters:
context - the body's operation context
expression - the expression (without the "body:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createBodyCondition

public static OCLExpression createBodyCondition(org.eclipse.emf.ecore.EClassifier classifier,
                                                org.eclipse.emf.ecore.EOperation context,
                                                java.lang.String expression,
                                                boolean validate)
                                         throws ParserException
Creates an operation body condition expression.

Parameters:
classifier - the context classifier
context - the body's operation context
expression - the expression (without the "body:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createBodyCondition

public static OCLExpression createBodyCondition(Environment env,
                                                java.lang.String expression,
                                                boolean validate)
                                         throws ParserException
Creates an operation body condition expression in the specified environment.

Parameters:
env - the OCL environment
expression - the expression (without the "body:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createInitialValueExpression

public static OCLExpression createInitialValueExpression(org.eclipse.emf.ecore.EStructuralFeature context,
                                                         java.lang.String expression,
                                                         boolean validate)
                                                  throws ParserException
Creates a property initial value expression.

Parameters:
context - the property context
expression - the expression (without the "init:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createInitialValueExpression

public static OCLExpression createInitialValueExpression(org.eclipse.emf.ecore.EClassifier classifier,
                                                         org.eclipse.emf.ecore.EStructuralFeature context,
                                                         java.lang.String expression,
                                                         boolean validate)
                                                  throws ParserException
Creates an property initial value expression.

Parameters:
classifier - the context classifier
context - the property context
expression - the expression (without the "init:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createInitialValueExpression

public static OCLExpression createInitialValueExpression(Environment env,
                                                         java.lang.String expression,
                                                         boolean validate)
                                                  throws ParserException
Creates a property initial value expression in the specified environment.

Parameters:
env - the OCL property environment
expression - the expression (without the "init:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createDerivedValueExpression

public static OCLExpression createDerivedValueExpression(org.eclipse.emf.ecore.EStructuralFeature context,
                                                         java.lang.String expression,
                                                         boolean validate)
                                                  throws ParserException
Creates a property derived value expression.

Parameters:
context - the property context
expression - the expression (without the "derive:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createDerivedValueExpression

public static OCLExpression createDerivedValueExpression(org.eclipse.emf.ecore.EClassifier classifier,
                                                         org.eclipse.emf.ecore.EStructuralFeature context,
                                                         java.lang.String expression,
                                                         boolean validate)
                                                  throws ParserException
Creates an property derived value expression.

Parameters:
classifier - the context classifier
context - the property context
expression - the expression (without the "derive:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

createDerivedValueExpression

public static OCLExpression createDerivedValueExpression(Environment env,
                                                         java.lang.String expression,
                                                         boolean validate)
                                                  throws ParserException
Creates a property derived value expression in the specified environment.

Parameters:
env - the OCL property environment
expression - the expression (without the "derive:")
validate - whether to validate the result or not
Returns:
the corresponding OCL expression
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

define

public static void define(org.eclipse.emf.ecore.EClassifier context,
                          java.lang.String expression)
                   throws ParserException
Defines a property or an operation of the specified signature.

Parameters:
context - the classifier context to own the new property or operation
expression - the expression (without the "def:" preamble but including the "name(...) : type =" part)
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

define

public static org.eclipse.emf.ecore.ETypedElement define(Environment env,
                                                         java.lang.String defExpression)
                                                  throws ParserException
Defines a property or operation of the specified signature.

Parameters:
defExpression - the definition expression (without the "def:" preamble but including the "name(...) : type =" part)
Returns:
the newly defined EOperation or EStructuralFeature
Throws:
ParserException - if the expression fails to parse
java.lang.IllegalArgumentException - if the expression fails to validate

containerOfType

public static org.eclipse.emf.ecore.EObject containerOfType(org.eclipse.emf.ecore.EClass type,
                                                            org.eclipse.emf.ecore.EObject eObject)
Computes the nearest container of an eObject that has the specified type.

Parameters:
type - the container type to look for
eObject - the object for which we seek a container
Returns:
the nearest container of the specified type, or null if no such container is found

isInPostcondition

public static boolean isInPostcondition(OCLExpression exp)
Checks whether the specified OCL expression is in an operation postcondition constraint.

Parameters:
exp - an OCL expression
Returns:
true if it is in a postcondition constraint; false, otherwise (including case of no constraint at all)

Copyright 2002, 2006 IBM Corporation and others.
All Rights Reserved.