net.sourceforge.nrl.parser.ast.constraints.impl
Class ModelReferenceImpl

java.lang.Object
  extended by org.antlr.runtime.tree.BaseTree
      extended by org.antlr.runtime.tree.CommonTree
          extended by net.sourceforge.nrl.parser.ast.impl.Antlr3NRLBaseAst
              extended by net.sourceforge.nrl.parser.ast.constraints.impl.ConstraintImpl
                  extended by net.sourceforge.nrl.parser.ast.constraints.impl.ModelReferenceImpl
All Implemented Interfaces:
IConstraint, IExpression, IIdentifier, IModelReference, INRLAstNode, org.antlr.runtime.tree.Tree

public class ModelReferenceImpl
extends ConstraintImpl
implements IModelReference

Implementation of a model reference. When initialised during parsing, this class contains only a broken up list of strings representing the steps through the model. This list can be obtained using getStepsAsStrings().

A model resolver needs to be used to set the actual model references in the initial step, and the remaining steps. In the ANTLR implementation, the AntlrModelResolver class performs this task.

Author:
Christian Nentwich

Field Summary
static char KEYWORD_ESCAPE_CHARACTER
          The character that may appear at the start of steps to escape an NRL keyword.
 
Fields inherited from class org.antlr.runtime.tree.CommonTree
childIndex, parent, startIndex, stopIndex, token
 
Fields inherited from class org.antlr.runtime.tree.BaseTree
children
 
Fields inherited from interface net.sourceforge.nrl.parser.ast.IModelReference
REFERENCE_ELEMENT, REFERENCE_GLOBAL_VARIABLE, REFERENCE_RELATIVE_ATTRIBUTE, REFERENCE_STATIC_ATTRIBUTE, REFERENCE_TOP_CONTEXT_RELATIVE_ATTRIBUTE, REFERENCE_VARIABLE_RELATIVE_ATTRIBUTE, SEPARATOR, STEP_ATTRIBUTE, STEP_MODEL_ELEMENT, STEP_VARIABLE
 
Fields inherited from interface net.sourceforge.nrl.parser.ast.INRLAstNode
NEWLINE
 
Fields inherited from interface org.antlr.runtime.tree.Tree
INVALID_NODE
 
Constructor Summary
ModelReferenceImpl(ModelReferenceImpl other)
          Initialise the model reference by cloning another
ModelReferenceImpl(org.antlr.runtime.Token token)
           
 
Method Summary
 void accept(INRLAstVisitor visitor)
          Accept a visitor to this node.
 void addStep(IAttribute step)
           
 String dump(int indent)
          Dump the AST and its children for debugging purposes
 IModelElement getCurrentContext()
          Return the "current context" in which this reference was made.
 Object getInitialStep()
          Return the initial step.
 int getInitialStepType()
          Return the type of model reference this is: whether it starts with a variable, with a model element, or with an attribute.
 IAttribute getLastAttribute()
          Get the last attribute in a model reference.
 String getOriginalString()
          Return the original model reference string found in the NRL text.
 int getReferenceType()
          Indicate what type of reference this is: to an attribute, to a static attribute or enumeration, etc.
 List<IAttribute> getRemainingSteps()
          Return the remaining steps after the initial step has been traversed.
 List<String> getStepsAsStrings()
           
 IModelElement getTarget()
          Return the final target of a reference, which is always a model element.
 void initializeSteps()
          AST processing method: initialise the stepsAsStrings and originalString member variables from the steps.
 void resetSteps()
           
 void setCurrentContext(IModelElement currentContext)
           
 void setInitialStep(Object obj)
           
 void setReferenceType(int referenceType)
           
 void shiftStepsLeft()
          Delete the left-most step in the model reference, and move all other steps left.
 
Methods inherited from class net.sourceforge.nrl.parser.ast.constraints.impl.ConstraintImpl
getNRLDataType, setNRLDataType
 
Methods inherited from class net.sourceforge.nrl.parser.ast.impl.Antlr3NRLBaseAst
doIndent, getColumn, getLine, getUserData, initialisePositionFromChild, setColumn, setLine, setUserData
 
Methods inherited from class org.antlr.runtime.tree.CommonTree
dupNode, getCharPositionInLine, getChildIndex, getParent, getText, getToken, getTokenStartIndex, getTokenStopIndex, getType, isNil, setChildIndex, setParent, setTokenStartIndex, setTokenStopIndex, setUnknownTokenBoundaries, toString
 
Methods inherited from class org.antlr.runtime.tree.BaseTree
addChild, addChildren, createChildrenList, deleteChild, freshenParentAndChildIndexes, freshenParentAndChildIndexes, getAncestor, getAncestors, getChild, getChildCount, getChildren, getFirstChildWithType, hasAncestor, replaceChildren, sanityCheckParentAndChildIndexes, sanityCheckParentAndChildIndexes, setChild, toStringTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.nrl.parser.ast.constraints.IConstraint
getNRLDataType, setNRLDataType
 
Methods inherited from interface net.sourceforge.nrl.parser.ast.INRLAstNode
getColumn, getLine, getUserData, setUserData
 

Field Detail

KEYWORD_ESCAPE_CHARACTER

public static final char KEYWORD_ESCAPE_CHARACTER
The character that may appear at the start of steps to escape an NRL keyword. This is stripped off by this class and will only appear in the string returned by getOriginalString().

See Also:
Constant Field Values
Constructor Detail

ModelReferenceImpl

public ModelReferenceImpl(org.antlr.runtime.Token token)

ModelReferenceImpl

public ModelReferenceImpl(ModelReferenceImpl other)
Initialise the model reference by cloning another

Parameters:
other - the reference to clone
Method Detail

accept

public void accept(INRLAstVisitor visitor)
Description copied from interface: INRLAstNode
Accept a visitor to this node.

Specified by:
accept in interface INRLAstNode
Overrides:
accept in class Antlr3NRLBaseAst
Parameters:
visitor - the visitor

dump

public String dump(int indent)
Description copied from interface: INRLAstNode
Dump the AST and its children for debugging purposes

Specified by:
dump in interface INRLAstNode
Overrides:
dump in class Antlr3NRLBaseAst
Parameters:
indent - the indentation count, 0 on first call
Returns:
the AST as a string

getCurrentContext

public IModelElement getCurrentContext()
Description copied from interface: IModelReference
Return the "current context" in which this reference was made. This is only valid if IModelReference.getReferenceType() returns IModelReference.REFERENCE_RELATIVE_ATTRIBUTE.

For an attribute reference, this returns the model element in which the attribute occurred. For example, in the rule in each of the trades, the tradeDate is equal to '2005-12-12', calling this method on the tradeDate reference would return Trade or whatever the type of 'trades' was.

Specified by:
getCurrentContext in interface IModelReference
Returns:
the element or null if wrong reference type

getInitialStepType

public int getInitialStepType()
Description copied from interface: IModelReference
Return the type of model reference this is: whether it starts with a variable, with a model element, or with an attribute.

Specified by:
getInitialStepType in interface IModelReference
Returns:
the initial step type, one of the STEP constants defined in this interface

getInitialStep

public Object getInitialStep()
Description copied from interface: IModelReference
Return the initial step. Depending on the result of IModelReference.getInitialStepType() this will return:

IMPORTANT: This can only be called after a model has been loaded, because information from the model is needed to determine this.

Specified by:
getInitialStep in interface IModelReference
Returns:
the initial step, never null

getLastAttribute

public IAttribute getLastAttribute()
Description copied from interface: IModelReference
Get the last attribute in a model reference. For example:

getRemainingSteps

public List<IAttribute> getRemainingSteps()
Description copied from interface: IModelReference
Return the remaining steps after the initial step has been traversed. This is always a collection of IAttribute objects.

Specified by:
getRemainingSteps in interface IModelReference
Returns:
the collection, can be empty

getReferenceType

public int getReferenceType()
Description copied from interface: IModelReference
Indicate what type of reference this is: to an attribute, to a static attribute or enumeration, etc. This returns one of IModelReference.REFERENCE_ELEMENT, IModelReference.REFERENCE_RELATIVE_ATTRIBUTE, IModelReference.REFERENCE_STATIC_ATTRIBUTE, IModelReference.REFERENCE_TOP_CONTEXT_RELATIVE_ATTRIBUTE or IModelReference.REFERENCE_VARIABLE_RELATIVE_ATTRIBUTE.

Specified by:
getReferenceType in interface IModelReference
Returns:
the constant

getTarget

public IModelElement getTarget()
Description copied from interface: IModelReference
Return the final target of a reference, which is always a model element. This is used to determine what the last step in a sequence of steps pointed to.

There is only one case where this can return null: If the initial step is a variable that points to a complex expression rather than a model element. In that case, retrieve the expression from the variable.

Specified by:
getTarget in interface IModelReference
Returns:
the target attribute

getStepsAsStrings

public List<String> getStepsAsStrings()

getOriginalString

public String getOriginalString()
Description copied from interface: IModelReference
Return the original model reference string found in the NRL text.

Specified by:
getOriginalString in interface IModelReference
Returns:
the string

initializeSteps

public void initializeSteps()
AST processing method: initialise the stepsAsStrings and originalString member variables from the steps.

This converts steps of the form a.b.c and c of b of a into a string step list.


setInitialStep

public void setInitialStep(Object obj)

addStep

public void addStep(IAttribute step)

resetSteps

public void resetSteps()

setCurrentContext

public void setCurrentContext(IModelElement currentContext)

setReferenceType

public void setReferenceType(int referenceType)

shiftStepsLeft

public void shiftStepsLeft()
Delete the left-most step in the model reference, and move all other steps left. If this leaves an empty model reference, which should never happen, this throws a runtime exception.



Copyright © 2006-2013. All Rights Reserved.