org.eclipse.mtl.parser.ast.ocl
Class OCLParser

java.lang.Object
  extended by org.eclipse.mtl.parser.ast.ocl.OCLParser

public class OCLParser
extends java.lang.Object

To parse an OCL Expression. Make sure to call dispose() once you're done with the parser.


Field Summary
static java.lang.String ANNOTATION_KEY_TYPE
          To set the value of the 'type' key for each MTL annotation.
static java.lang.String ANNOTATION_SOURCE
          To set the value of the 'Source' attribute for each MTL annotation.
 
Constructor Summary
OCLParser(org.eclipse.emf.ecore.resource.Resource oclEnvironmentResource)
          Create a new OCL parser for MTL.
 
Method Summary
 void addMetamodel(org.eclipse.emf.ecore.EPackage metamodel)
          Add a new EPackage in the list of the metamodels considered during the parsing.
 void addRecursivelyBehavioralFeaturesToScope(Module oModule)
          Add the behavioral features of a module in the current parsing scope.
 void addRecursivelyMetamodelsToScope(Module oModule)
          Add all EPackage of a module in the list of the metamodels considered during the parsing.
 org.eclipse.emf.ecore.EClassifier addRecursivelyVariablesToScopeAndGetContextClassifierAt(Module oModule, int offset)
          Add the accessible variables (at the given index) in the current parsing scope.
 void addVariableToScope(org.eclipse.ocl.ecore.Variable newVariable)
          Add a new variable in the current parsing scope.
 void dispose()
          Clear all contextual information.
 org.eclipse.emf.ecore.EClassifier getInvalidType()
          Obtains the single instance of the OCL invalid type.
 java.util.List<org.eclipse.ocl.helper.Choice> getSyntaxHelp(java.lang.String text)
          Obtains syntax completion choices for the specified fragment of an OCL expression.
 java.util.List<org.eclipse.emf.ecore.EClassifier> getTypes()
          Gets the meta-model types of the current module.
 org.eclipse.emf.ecore.EClassifier lookupClassifier(java.lang.String name)
          Selects the meta-model object for the given name in the current module.
 org.eclipse.ocl.ecore.OCLExpression parseOCLExpression(java.lang.String text, int realOffsetInTheBuffer)
          Parse an OCL Expression and return the corresponding instance.
 void popContext()
          Restores the previous context.
 void pushContext(org.eclipse.emf.ecore.EClassifier newContext)
          Next OCL expressions will have this new context.
 void removeMetamodel(org.eclipse.emf.ecore.EPackage metamodel)
          Remove a EPackage in the list of the metamodels considered during the parsing.
 void removeRecursivelyBehavioralFeaturesToScope(Module oModule)
          Remove the behavioral features in the current parsing scope.
 void removeVariableFromScope(org.eclipse.ocl.ecore.Variable oldVariable)
          Remove an accessible variable from the current parser scope.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANNOTATION_SOURCE

public static final java.lang.String ANNOTATION_SOURCE
To set the value of the 'Source' attribute for each MTL annotation.

See Also:
Constant Field Values

ANNOTATION_KEY_TYPE

public static final java.lang.String ANNOTATION_KEY_TYPE
To set the value of the 'type' key for each MTL annotation.

See Also:
Constant Field Values
Constructor Detail

OCLParser

public OCLParser(org.eclipse.emf.ecore.resource.Resource oclEnvironmentResource)
Create a new OCL parser for MTL.

Parameters:
oclEnvironmentResource - resource used to keep the OCL environment.
Method Detail

pushContext

public void pushContext(org.eclipse.emf.ecore.EClassifier newContext)
Next OCL expressions will have this new context.

Parameters:
newContext - is the new context

popContext

public void popContext()
Restores the previous context.


addVariableToScope

public void addVariableToScope(org.eclipse.ocl.ecore.Variable newVariable)
Add a new variable in the current parsing scope.

Parameters:
newVariable - a new ocl variable to consider while parsing.

addRecursivelyVariablesToScopeAndGetContextClassifierAt

public org.eclipse.emf.ecore.EClassifier addRecursivelyVariablesToScopeAndGetContextClassifierAt(Module oModule,
                                                                                                 int offset)
Add the accessible variables (at the given index) in the current parsing scope. It browses the given module, and its children that are accessible at the given index. It returns the context classifier. It is defined by a variable (a loop variable, the first parameter of a template...)

Parameters:
oModule - is the current module
offset - is the offset in the text
Returns:
the context classifier, or null if the current block doesn't define a new context

addRecursivelyBehavioralFeaturesToScope

public void addRecursivelyBehavioralFeaturesToScope(Module oModule)
Add the behavioral features of a module in the current parsing scope. It browses the given module, its children, and the imported modules...

Parameters:
oModule - is the current module

removeRecursivelyBehavioralFeaturesToScope

public void removeRecursivelyBehavioralFeaturesToScope(Module oModule)
Remove the behavioral features in the current parsing scope. It browses the given module, its children, and the imported modules...

Parameters:
oModule - is the current module

addRecursivelyMetamodelsToScope

public void addRecursivelyMetamodelsToScope(Module oModule)
Add all EPackage of a module in the list of the metamodels considered during the parsing.

Parameters:
oModule - is the current module

addMetamodel

public void addMetamodel(org.eclipse.emf.ecore.EPackage metamodel)
Add a new EPackage in the list of the metamodels considered during the parsing.

Parameters:
metamodel - EPackage to add in the current EPackage's known by the parser.

removeMetamodel

public void removeMetamodel(org.eclipse.emf.ecore.EPackage metamodel)
Remove a EPackage in the list of the metamodels considered during the parsing.

Parameters:
metamodel - EPackage to remove in the current EPackage's known by the parser.

lookupClassifier

public org.eclipse.emf.ecore.EClassifier lookupClassifier(java.lang.String name)
Selects the meta-model object for the given name in the current module.

Parameters:
name - is the name of the type to search
Returns:
the meta-model object, or null if it doesn't exist

getTypes

public java.util.List<org.eclipse.emf.ecore.EClassifier> getTypes()
Gets the meta-model types of the current module.

Returns:
the meta-model objects, or an empty list

getInvalidType

public org.eclipse.emf.ecore.EClassifier getInvalidType()
Obtains the single instance of the OCL invalid type.

Returns:
the OCL invalid type

parseOCLExpression

public org.eclipse.ocl.ecore.OCLExpression parseOCLExpression(java.lang.String text,
                                                              int realOffsetInTheBuffer)
                                                       throws org.eclipse.ocl.ParserException
Parse an OCL Expression and return the corresponding instance. Make sure to declare all the needed contextual elements (variables or contexts) before trying to parse.

Parameters:
text - is the OCL text to parse, just a part of the file
realOffsetInTheBuffer - beginning index of the given text in the file, this index is used to compute the real offset of a problem...
Returns:
an OCLExpression instance.
Throws:
org.eclipse.ocl.ParserException - if the given text is not conform to what we expect.

dispose

public void dispose()
Clear all contextual information.


removeVariableFromScope

public void removeVariableFromScope(org.eclipse.ocl.ecore.Variable oldVariable)
Remove an accessible variable from the current parser scope.

Parameters:
oldVariable - oldVariable is the variable to remove.

getSyntaxHelp

public java.util.List<org.eclipse.ocl.helper.Choice> getSyntaxHelp(java.lang.String text)
Obtains syntax completion choices for the specified fragment of an OCL expression.

Parameters:
text - a partial OCL expression for which to seek choices that could be appended to it
Returns:
a list of Choices, possibly empty. The ordering of the list may or may not indicate relative relevance or frequency of a choice

Copyright 2008 Obeo
All Rights Reserved.