org.eclipse.emf.ocl.parser
Interface Environment

All Known Subinterfaces:
PersistentEnvironment
All Known Implementing Classes:
EcoreEnvironment

public interface Environment

An Environment stores the variables created while evaluating an OCL expression, including self. It also maintains the package, if the OCL package statement is used.

This interface is not intended to be implemented by clients "directly". It is highly recommended to extend the EcoreEnvironment class, instead.

See Also:
EcoreEnvironment, EnvironmentFactory

Field Summary
static java.lang.String ANNOTATION_URI_BODY
          Source URI of the annotation for the body expression of an operation.
static java.lang.String ANNOTATION_URI_DEFINE
          Source URI of the annotation for the expression defining an additional property or operation.
static java.lang.String ANNOTATION_URI_DERIVE
          Source URI of the annotation for the expression defining the derived value of a property.
static java.lang.String ANNOTATION_URI_INIT
          Source URI of the annotation for the expression defining the initial value of a property.
 
Method Summary
 boolean addElement(java.lang.String name, Variable elem, boolean imp)
          Adds a variable declaration to the environment.
 void deleteElement(java.lang.String name)
          Removes a name when it goes out of scope.
 org.eclipse.emf.ecore.EClass getAssociationClass(org.eclipse.emf.ecore.EReference reference)
          Obtains the association class that the specified reference represents, as an EClass, if any.
 org.eclipse.emf.ecore.EClassifier getContextClassifier()
          Obtains the context classifier of this environment.
 org.eclipse.emf.ecore.EOperation getContextOperation()
          Obtains the context operation of this environment, if it is an operation context.
 org.eclipse.emf.ecore.EStructuralFeature getContextProperty()
          Obtains the context property of this environment, if it is a property context.
 java.lang.String getDescription(org.eclipse.emf.ecore.ENamedElement namedElement)
          Obtains the user-presentable description of a named Ecore element.
 EnvironmentFactory getFactory()
          Obtains the factory that created me, or an appropriate default factory if I was not created using a factory.
 org.eclipse.emf.common.util.EList getMemberEnds(org.eclipse.emf.ecore.EClass associationClass)
          Obtains the ends of the specified association class as a list of EReferences.
 Environment getParent()
          get the parent environment
 org.eclipse.emf.common.util.EList getQualifiers(org.eclipse.emf.ecore.EStructuralFeature property)
          Gets the qualifiers of a property representing a UML association end.
 Variable getSelfVariable()
          Gets the self variable, looking it up in a parent environment if necessary.
 org.eclipse.emf.common.util.EList getSignals(org.eclipse.emf.ecore.EClassifier owner)
          Retrieves a list of all signal receptions defined by the specified owner classifier.
 java.lang.String getStateName(org.eclipse.emf.ecore.EObject state)
          Obtains the simple name of the specified state (not the qualified name path).
 org.eclipse.emf.common.util.EList getStates(org.eclipse.emf.ecore.EClassifier owner, java.util.List pathPrefix)
          Retrieves a list of all possible states of the specified owner whose paths are prefixed by the specified partial name.
 java.util.Collection getVariables()
          Returns the Variables registered in me explicitly.
 boolean isAssociationClass(org.eclipse.emf.ecore.EClass eclass)
          Determines whether the specified eclass is an association class.
 boolean isEmpty()
          Is the environment empty?
 boolean isQuery(org.eclipse.emf.ecore.EOperation operation)
          Determines whether the specified operation is a query operation.
 Variable lookup(java.lang.String name)
          returns the VariableDeclaration for a variable Looks in parent environment scope if not found in current scope.
 org.eclipse.emf.ecore.EClass lookupAssociationClassReference(org.eclipse.emf.ecore.EClassifier parent, java.lang.String name)
          Find reference in the specified class to the named association class.
 Variable lookupImplicitSourceForAssociationClass(java.lang.String name)
          Return the variable declaration in namedElements which references the named association class.
 Variable lookupImplicitSourceForOperation(java.lang.String name, org.eclipse.emf.common.util.EList params)
          Return the Variable declaration in namedElements which contains the name as an EOperation.
 Variable lookupImplicitSourceForProperty(java.lang.String name)
          Return the most appropriate matching variable to use as the implicit source of a call to the specified property.
 Variable lookupLocal(java.lang.String name)
          Returns the VariableDeclaration for a variable name.
 org.eclipse.emf.ecore.EOperation lookupOperation(org.eclipse.emf.ecore.EClassifier owner, java.lang.String name, org.eclipse.emf.common.util.EList args)
          Find the operation in the specified class.
 org.eclipse.emf.ecore.EPackage lookupPackage(java.util.List names)
          Finds the EPackage corresponding to the path: name::...
 org.eclipse.emf.ecore.EClassifier lookupPathName(java.util.List names)
          Finds the EClassifier corresponding to the path: name::...
 org.eclipse.emf.ecore.EStructuralFeature lookupProperty(org.eclipse.emf.ecore.EClassifier parent, java.lang.String name)
          Find a property defined or inherited by the specified classifier.
 org.eclipse.emf.ecore.EClass lookupSignal(org.eclipse.emf.ecore.EClassifier owner, java.lang.String name, org.eclipse.emf.common.util.EList args)
          Find a received signal in the specified classifier.
 void setParent(Environment env)
          Set the parent environment
 void setSelfVariable(Variable var)
          Sets the "self" variable that is the implicit source of any attribute, association end, or operation call.
 

Field Detail

ANNOTATION_URI_DEFINE

public static final java.lang.String ANNOTATION_URI_DEFINE
Source URI of the annotation for the expression defining an additional property or operation.

See Also:
Constant Field Values

ANNOTATION_URI_INIT

public static final java.lang.String ANNOTATION_URI_INIT
Source URI of the annotation for the expression defining the initial value of a property.

See Also:
Constant Field Values

ANNOTATION_URI_DERIVE

public static final java.lang.String ANNOTATION_URI_DERIVE
Source URI of the annotation for the expression defining the derived value of a property.

See Also:
Constant Field Values

ANNOTATION_URI_BODY

public static final java.lang.String ANNOTATION_URI_BODY
Source URI of the annotation for the body expression of an operation.

See Also:
Constant Field Values
Method Detail

getFactory

public EnvironmentFactory getFactory()
Obtains the factory that created me, or an appropriate default factory if I was not created using a factory. This factory can be used to create nested environments within me.

Returns:
my originating factory
See Also:
EnvironmentFactory.createEnvironment(Environment)

setParent

public void setParent(Environment env)
Set the parent environment

Parameters:
env -

getParent

public Environment getParent()
get the parent environment

Returns:
Environment

getContextClassifier

public org.eclipse.emf.ecore.EClassifier getContextClassifier()
Obtains the context classifier of this environment.

Returns:
the context classifier

getContextOperation

public org.eclipse.emf.ecore.EOperation getContextOperation()
Obtains the context operation of this environment, if it is an operation context.

Returns:
the context operation, or null if this is not an operation environment

getContextProperty

public org.eclipse.emf.ecore.EStructuralFeature getContextProperty()
Obtains the context property of this environment, if it is a property context.

Returns:
the context property, or null if this is not a property environment

isEmpty

public boolean isEmpty()
Is the environment empty?

Returns:
boolean

lookupLocal

public Variable lookupLocal(java.lang.String name)
Returns the VariableDeclaration for a variable name. Does not look in parent environment scopes.

Parameters:
name -
Returns:
VariableDeclaration

lookup

public Variable lookup(java.lang.String name)
returns the VariableDeclaration for a variable Looks in parent environment scope if not found in current scope.

Parameters:
name -
Returns:
VariableDeclaration

lookupPackage

public org.eclipse.emf.ecore.EPackage lookupPackage(java.util.List names)
Finds the EPackage corresponding to the path: name::...::name If no EPackage is found, return null.

Parameters:
names - the path name
Returns:
the package, or null if not found

lookupPathName

public org.eclipse.emf.ecore.EClassifier lookupPathName(java.util.List names)
Finds the EClassifier corresponding to the path: name::...::name If no EClassifier is found, return null.

Parameters:
names -
Returns:
EClassifier

lookupOperation

public org.eclipse.emf.ecore.EOperation lookupOperation(org.eclipse.emf.ecore.EClassifier owner,
                                                        java.lang.String name,
                                                        org.eclipse.emf.common.util.EList args)
Find the operation in the specified class.

Parameters:
owner - the owner type of the called operation
name - the name of the called operation
args - the arguments (as OCLExpressions) passed to the operation
Returns:
the matching operation, or null if not found

lookupProperty

public org.eclipse.emf.ecore.EStructuralFeature lookupProperty(org.eclipse.emf.ecore.EClassifier parent,
                                                               java.lang.String name)
Find a property defined or inherited by the specified classifier.

Parameters:
name - the property name
Returns:
the property, or null if it could not be found

lookupAssociationClassReference

public org.eclipse.emf.ecore.EClass lookupAssociationClassReference(org.eclipse.emf.ecore.EClassifier parent,
                                                                    java.lang.String name)
Find reference in the specified class to the named association class.

Parameters:
parent - the referencing class to search
name - the association class name (with an initial lower case as per the OCL convention)
Returns:
the association class, or null if the specified parent classifier does not have any references implemented by the named association class

getStates

public org.eclipse.emf.common.util.EList getStates(org.eclipse.emf.ecore.EClassifier owner,
                                                   java.util.List pathPrefix)
Retrieves a list of all possible states of the specified owner whose paths are prefixed by the specified partial name. If the owner is null, then the target of the oclIsInState() operation call is implicit and must be looked up in the usual way for implicit operation call targets.

Parameters:
owner - the classifier for which states are being sought. Can be null in the case of an oclIsInState() call on an implicit target
pathPrefix - partial path name of the states being sought. This can be empty to find the first level of state names
Returns:
the list of all possible states directly contained in the namespace indicated by the path prefix (i.e., only one level of state nesting)

getStateName

public java.lang.String getStateName(org.eclipse.emf.ecore.EObject state)
Obtains the simple name of the specified state (not the qualified name path).

Parameters:
state - representation of a UML state
Returns:
its simple name

lookupSignal

public org.eclipse.emf.ecore.EClass lookupSignal(org.eclipse.emf.ecore.EClassifier owner,
                                                 java.lang.String name,
                                                 org.eclipse.emf.common.util.EList args)
Find a received signal in the specified classifier.

Parameters:
owner - the owner type of the signal reception
name - the name of the signal
args - the arguments (as OCLExpressions) passed in the signal
Returns:
the matching signal, or null if not found

getSignals

public org.eclipse.emf.common.util.EList getSignals(org.eclipse.emf.ecore.EClassifier owner)
Retrieves a list of all signal receptions defined by the specified owner classifier. This must include also signals defined by supertypes of the owner.

Parameters:
owner - the owner type of the signal receptions
Returns:
the available signals (as EClasses), or an empty list if none

isQuery

public boolean isQuery(org.eclipse.emf.ecore.EOperation operation)
Determines whether the specified operation is a query operation.

Parameters:
operation - an operation
Returns:
whether it is a query operation

getQualifiers

public org.eclipse.emf.common.util.EList getQualifiers(org.eclipse.emf.ecore.EStructuralFeature property)
Gets the qualifiers of a property representing a UML association end.

Parameters:
property - a property of the model class
Returns:
the qualifiers (as a list of EStructuralFeatures, or an empty list if the property has no qualifiers

isAssociationClass

public boolean isAssociationClass(org.eclipse.emf.ecore.EClass eclass)
Determines whether the specified eclass is an association class.

Parameters:
eclass - an Ecore class
Returns:
whether it is an association class

getAssociationClass

public org.eclipse.emf.ecore.EClass getAssociationClass(org.eclipse.emf.ecore.EReference reference)
Obtains the association class that the specified reference represents, as an EClass, if any. This gets the "class" aspect of the association class, for which the reference represents the "association" aspect.

Parameters:
reference - a reference
Returns:
the association class, or null if the reference does not represent an association class

getMemberEnds

public org.eclipse.emf.common.util.EList getMemberEnds(org.eclipse.emf.ecore.EClass associationClass)
Obtains the ends of the specified association class as a list of EReferences.

Parameters:
associationClass - an EClass representing an association class
Returns:
the EReferences representing its member ends (the association roles)

addElement

public boolean addElement(java.lang.String name,
                          Variable elem,
                          boolean imp)
Adds a variable declaration to the environment. If the name is null, then a new unique temporary name is generated.

Parameters:
name -
elem - -- variable declaration
imp - -- is the variable implicit?
Returns:
- boolean

deleteElement

public void deleteElement(java.lang.String name)
Removes a name when it goes out of scope.

Parameters:
name -

getVariables

public java.util.Collection getVariables()
Returns the Variables registered in me explicitly.

Returns:
my variable declarations

setSelfVariable

public void setSelfVariable(Variable var)
Sets the "self" variable that is the implicit source of any attribute, association end, or operation call.

Parameters:
var - the "self" variable

getSelfVariable

public Variable getSelfVariable()
Gets the self variable, looking it up in a parent environment if necessary.

Returns:
the self variable, or null if none (which should not happen as there is always some classifier context)

lookupImplicitSourceForProperty

public Variable lookupImplicitSourceForProperty(java.lang.String name)
Return the most appropriate matching variable to use as the implicit source of a call to the specified property. Variables are returned based on inner-most scope first.

Parameters:
name - the property name
Returns:
the matching variable

lookupImplicitSourceForAssociationClass

public Variable lookupImplicitSourceForAssociationClass(java.lang.String name)
Return the variable declaration in namedElements which references the named association class. Variables are returned based on inner-most scope first.

Parameters:
name - the association class name to seek
Returns:
the matching variable declaration, or null if none is found

lookupImplicitSourceForOperation

public Variable lookupImplicitSourceForOperation(java.lang.String name,
                                                 org.eclipse.emf.common.util.EList params)
                                          throws SemanticException
Return the Variable declaration in namedElements which contains the name as an EOperation. Variables are returned based on inner-most scope first.

Parameters:
name -
Returns:
the matching variable declaration
Throws:
SemanticException

getDescription

public java.lang.String getDescription(org.eclipse.emf.ecore.ENamedElement namedElement)
Obtains the user-presentable description of a named Ecore element. For example, this might be the type name of an ETypedElement (the user model name) or the localized metaclass name of the underlying adapted element in the case of an EClassifier.

Parameters:
namedElement - a named element obtained by adaptation of a user model element
Returns:
the named element's description

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