Dresden OCL Toolkit

tudresden.ocl
Class OclTree

java.lang.Object
  extended bytudresden.ocl.OclTree
All Implemented Interfaces:
NameBoundQueryable, Switch, Switchable, TypeQueryable

public class OclTree
extends Object
implements NameBoundQueryable, TypeQueryable, Switchable


Field Summary
protected  Start ast
           
protected  HashSet invariants
           
protected  String name
          the name of the constraint, i.e.
protected static String NAME_SEPARATOR
           
protected  NameBoundQueryable nameBoundQueryable
           
protected  NameCreator nameCreator
           
protected  QueryableFactory qFactory
           
protected  TypeFactory tFactory
           
protected  TypeQueryable typeQueryable
           
 
Constructor Summary
protected OclTree()
           
  OclTree(Start ast)
           
 
Method Summary
 void apply(Switch s)
          apply a tree traversal to the abstract syntax tree; see the SableCC documentation for tree traversals
 void applyDefaultNormalizations()
           
 void applyGeneratedTests()
           
 void assureInvariant(String oclConstraint)
          By calling this method, a normalizer assures that the given OCL invariant holds for this AST.
 void assureTypes()
          starts a type check if tree has not already been checked
 void breakInvariant(String oclConstraint)
          A normalizer can use this method to notify the OclTree that the AST no longer fulfilles an invariant.
 void changeNotify()
           
 void changeNotify(Node subtree)
          notify the NameBoundQueryable that the ASTs subtree starting at the node given as parameter may have changed
protected  void checkNameBoundQueryable()
           
protected  void checkTypeQueryable()
           
static OclTree createTree(String oclExpression, ModelFacade mf)
          creates an OclTree that uses a TypeChecker to acquire type and name binding information
static OclTree createTree(String oclExpression, ModelFacade mf, QueryableFactory qf)
           
protected static TypeFactory createTypeFactory(ModelFacade mf)
           
 boolean equalsExpression(OclTree tree)
           
 boolean fulfillsInvariant(String oclConstraint)
          This method determines whether the AST fulfills a given OCL invariant.
 HashSet getBoundNames(Node n)
           
 CodeFragment[] getCode(CodeGenerator cgen)
           
 String getConstraintName()
           
 String getDefaultContext(Node n)
           
 String getExpression()
           
 NameCreator getNameCreator()
           
 Type getNodeType(Node n)
           
 Start getRoot()
           
 Type getTypeFor(String name, Node node)
           
 boolean isNameBound(String name, Node node)
           
 void requireInvariant(String oclConstraint)
           
 void setNameCreator(NameCreator nc)
          A NameCreator is created on demand when getNameCreator() is called for the first time; calling this operation is necessary only if you want several OCL trees to use the same NameCreator, which will then create unique names beyond the scope of a single OCL constraint.
It is safe to first create the tree using createTree and afterwards set the NameCreator.
 void setQueryableFactory(QueryableFactory qf)
          calling this method is only effective before checkNameBoundQueryable and checkTypeQueryable are called for the first time
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME_SEPARATOR

protected static final String NAME_SEPARATOR
See Also:
ast, Constant Field Values

ast

protected Start ast

name

protected String name
the name of the constraint, i.e. the names of the constraint bodies concatenated with NAME_SEPARATOR as separator

See Also:
NAME_SEPARATOR

invariants

protected HashSet invariants

nameCreator

protected NameCreator nameCreator

typeQueryable

protected TypeQueryable typeQueryable

nameBoundQueryable

protected NameBoundQueryable nameBoundQueryable

qFactory

protected QueryableFactory qFactory

tFactory

protected TypeFactory tFactory
Constructor Detail

OclTree

public OclTree(Start ast)

OclTree

protected OclTree()
Method Detail

createTree

public static OclTree createTree(String oclExpression,
                                 ModelFacade mf)
                          throws OclParserException,
                                 IOException
creates an OclTree that uses a TypeChecker to acquire type and name binding information

Throws:
OclParserException
IOException

createTree

public static OclTree createTree(String oclExpression,
                                 ModelFacade mf,
                                 QueryableFactory qf)
                          throws IOException
Parameters:
qf - may be null
Throws:
IOException

createTypeFactory

protected static TypeFactory createTypeFactory(ModelFacade mf)

assureTypes

public void assureTypes()
starts a type check if tree has not already been checked


applyGeneratedTests

public void applyGeneratedTests()

applyDefaultNormalizations

public void applyDefaultNormalizations()

equalsExpression

public boolean equalsExpression(OclTree tree)
Returns:
true if this OclTree and the OclTree given as parameter contain equal ASTs

getConstraintName

public String getConstraintName()

getRoot

public Start getRoot()

getExpression

public String getExpression()
Returns:
a String representation of the OCL constraint held by this OclTree

setNameCreator

public void setNameCreator(NameCreator nc)
A NameCreator is created on demand when getNameCreator() is called for the first time; calling this operation is necessary only if you want several OCL trees to use the same NameCreator, which will then create unique names beyond the scope of a single OCL constraint.
It is safe to first create the tree using createTree and afterwards set the NameCreator.


getNameCreator

public NameCreator getNameCreator()
Returns:
a NameCreator that creates unique names for this OCL constraint

assureInvariant

public void assureInvariant(String oclConstraint)
By calling this method, a normalizer assures that the given OCL invariant holds for this AST.

Parameters:
oclConstraint - the String representation of an OCL constraint; it must contain exactly those ignored tokens it would contain if it was parsed and then retransformed into a String

fulfillsInvariant

public boolean fulfillsInvariant(String oclConstraint)
This method determines whether the AST fulfills a given OCL invariant. For performance reasons it does this not be examination of the tree but by looking up if the assureConstraint method was called earlier with exaclty the given String.

Parameters:
oclConstraint - the String representation of an OCL constraint; it must contain exactly those ignored tokens it would contain if it was parsed and then retransformed into a String
See Also:
assureInvariant(String inv)

requireInvariant

public void requireInvariant(String oclConstraint)
                      throws PreconditionViolatedException
Throws:
PreconditionViolatedException - if the AST does not fulfill the given precondition
See Also:
assureInvariant(String inv)

breakInvariant

public void breakInvariant(String oclConstraint)
A normalizer can use this method to notify the OclTree that the AST no longer fulfilles an invariant. If the tree didn't fulfill the invariant anyway nothing happens.


toString

public String toString()

apply

public void apply(Switch s)
apply a tree traversal to the abstract syntax tree; see the SableCC documentation for tree traversals

Specified by:
apply in interface Switchable

getCode

public CodeFragment[] getCode(CodeGenerator cgen)

getDefaultContext

public String getDefaultContext(Node n)
Specified by:
getDefaultContext in interface NameBoundQueryable
Returns:
a String representing the default context in the given node, which is either "self" or the name of an iterator; returns null if there is no default context, e.g. the iterator is not named

changeNotify

public void changeNotify()

changeNotify

public void changeNotify(Node subtree)
Description copied from interface: NameBoundQueryable
notify the NameBoundQueryable that the ASTs subtree starting at the node given as parameter may have changed

Specified by:
changeNotify in interface NameBoundQueryable

getTypeFor

public Type getTypeFor(String name,
                       Node node)
Specified by:
getTypeFor in interface TypeQueryable
Returns:
the type of the variable bound to the given name, or null if the name is not bound

getNodeType

public Type getNodeType(Node n)
Specified by:
getNodeType in interface TypeQueryable

isNameBound

public boolean isNameBound(String name,
                           Node node)
Specified by:
isNameBound in interface NameBoundQueryable
Returns:
true if the given String denotes a OCL variable in the given node and namespace

getBoundNames

public HashSet getBoundNames(Node n)
Specified by:
getBoundNames in interface NameBoundQueryable
Returns:
all names that are bound in the given node

checkNameBoundQueryable

protected void checkNameBoundQueryable()

checkTypeQueryable

protected void checkTypeQueryable()

setQueryableFactory

public void setQueryableFactory(QueryableFactory qf)
calling this method is only effective before checkNameBoundQueryable and checkTypeQueryable are called for the first time


Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.