|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.antlr.runtime.tree.BaseTree
org.antlr.runtime.tree.CommonTree
net.sourceforge.nrl.parser.ast.impl.Antlr3NRLBaseAst
net.sourceforge.nrl.parser.ast.constraints.impl.ConstraintImpl
net.sourceforge.nrl.parser.ast.constraints.impl.ModelReferenceImpl
public class ModelReferenceImpl
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.
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 |
---|
public static final char KEYWORD_ESCAPE_CHARACTER
getOriginalString()
.
Constructor Detail |
---|
public ModelReferenceImpl(org.antlr.runtime.Token token)
public ModelReferenceImpl(ModelReferenceImpl other)
other
- the reference to cloneMethod Detail |
---|
public void accept(INRLAstVisitor visitor)
INRLAstNode
accept
in interface INRLAstNode
accept
in class Antlr3NRLBaseAst
visitor
- the visitorpublic String dump(int indent)
INRLAstNode
dump
in interface INRLAstNode
dump
in class Antlr3NRLBaseAst
indent
- the indentation count, 0 on first call
public IModelElement getCurrentContext()
IModelReference
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.
getCurrentContext
in interface IModelReference
public int getInitialStepType()
IModelReference
getInitialStepType
in interface IModelReference
public Object getInitialStep()
IModelReference
IModelReference.getInitialStepType()
this will
return:
IAttribute
object
IModelElement
object
IVariable
object
IMPORTANT: This can only be called after a model has been loaded, because information from the model is needed to determine this.
getInitialStep
in interface IModelReference
public IAttribute getLastAttribute()
IModelReference
attr1.attr2.attr3
, returns attr3
attr1
, returns attr1
getLastAttribute
in interface IModelReference
public List<IAttribute> getRemainingSteps()
IModelReference
IAttribute
objects.
getRemainingSteps
in interface IModelReference
public int getReferenceType()
IModelReference
IModelReference.REFERENCE_ELEMENT
,
IModelReference.REFERENCE_RELATIVE_ATTRIBUTE
, IModelReference.REFERENCE_STATIC_ATTRIBUTE
,
IModelReference.REFERENCE_TOP_CONTEXT_RELATIVE_ATTRIBUTE
or
IModelReference.REFERENCE_VARIABLE_RELATIVE_ATTRIBUTE
.
getReferenceType
in interface IModelReference
public IModelElement getTarget()
IModelReference
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.
getTarget
in interface IModelReference
public List<String> getStepsAsStrings()
public String getOriginalString()
IModelReference
getOriginalString
in interface IModelReference
public void initializeSteps()
This converts steps of the form a.b.c
and c of b of a
into a string
step list.
public void setInitialStep(Object obj)
public void addStep(IAttribute step)
public void resetSteps()
public void setCurrentContext(IModelElement currentContext)
public void setReferenceType(int referenceType)
public void shiftStepsLeft()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |