org.prorefactor.core
Class JPNode

java.lang.Object
  extended by BaseAST
      extended by org.prorefactor.core.JPNode
All Implemented Interfaces:
Xferable, IJPNode
Direct Known Subclasses:
BlockNode, FieldRefNode, ProparseDirectiveNode, RecordNameNode

public class JPNode
extends BaseAST
implements IJPNode, Xferable

Extension to antlr.BaseAST, which allows us to extract an external "antlr" AST view of a Proparse AST, which we can then run tree parsers against. Note that tree transformation functions are currently (Feb 2004) untested and unused, since we tend to only use the AST for analysis and not for code motion.


Field Summary
static int AK_ABBREVIATED
           
static int AK_FROMUSERDICT
           
static int AK_FULLTEXT
           
static int AK_INLINEVARDEF
           
static int AK_KEYWORD
           
static int AK_OPERATOR
           
static int AK_PROPARSEDIRECTIVE
           
static int AK_QUALIFIEDCLASS
           
static int AK_SOURCENUM
           
static int AK_STATE2
           
static int AK_STATEHEAD
           
static int AK_STORETYPE
           
static int AV_FALSE
           
static int AV_ST_DBTABLE
           
static int AV_ST_TTABLE
           
static int AV_ST_VARIABLE
           
static int AV_ST_WTABLE
           
static int AV_TRUE
           
static int BLOCK
          A valid value for setLink() and getLink().
static int BUFFERSCOPE
          A valid value for setLink() and getLink().
static int CONTEXT_QUALIFIER
          Just a shortcut to IConstants.CONTEXT_QUALIFIER
static int FILE_NAME_ARRAY
          A value for setLink() and getLink().
static int STATE2
          Just a shortcut to IConstants.STATE2
static int SUPER_CLASS_TREE
          A value for setLink() and getLink().
static int SYMBOL
          A valid value for setLink() and getLink()
static int TETNode
          A valid value for setLink() and getLink()
 
Constructor Summary
JPNode()
           
JPNode(int type)
          Create an node with a given token type.
JPNode(int file, int line, int column)
          For temporary nodes for comparison in set of nodes sorted by position
JPNode(int type, JPNode original)
          If this AST is constructed from another, then create with link to the original.
JPNode(int type, java.lang.String text)
           
JPNode(ProToken t)
           
 
Method Summary
 java.lang.String allLeadingHiddenText()
           
 int attrGet(int key)
           
 java.lang.String attrGetS(int attrNum)
           
 java.lang.String attrGetS(java.lang.String attrName)
           
 void attrSet(int key, int val)
           
 void attrSet(int key, java.lang.String value)
           
 void attrSetS(java.lang.String key, java.lang.String value)
           
static void finalizeTrailingHidden(JPNode root)
           
 JPNode findDirectChild(int nodeType)
          Find the first direct child with a given node type.
 JPNode firstChild()
           
 JPNode firstNaturalChild()
          First Natural Child is found by repeating firstChild() until a natural node is found.
 Call getCall()
          Some nodes like RUN, USER_FUNC, LOCAL_METHOD_REF have a Call object linked to them by TreeParser01.
 int getColumn()
           
 java.lang.String getComments()
          Get the comments that precede this node.
 java.util.ArrayList<JPNode> getDirectChildren()
          Get an ArrayList of the direct children of this node.
 FieldContainer getFieldContainer()
          Get the FieldContainer (Frame or Browse) for a statement head node or a frame field reference.
 int getFileIndex()
           
 java.lang.String getFilename()
           
 java.lang.String[] getFilenames()
          Get the array of file names.
 ProToken getHiddenAfter()
           
 ProToken getHiddenBefore()
           
 ProToken getHiddenFirst()
           
 java.util.List<ProToken> getHiddenTokens()
           
static JPNode getLastDescendant(JPNode top)
          Find the last child of the last child of the...
 int getLine()
           
 java.lang.Object getLink(java.lang.Integer key)
          Get a link to an arbitrary object.
 int getNodeNum()
          Node number, as counted in the syntax tree.
 JPNode getOriginal()
          If this AST was constructed from another, then get the original.
 int[] getPos()
          Return int[3] of nodes file/line/col.
 int getSourceNum()
          Source number in the macro tree.
 int getState2()
          Attribute "state2" is necessary for the tree parsers, so it is one attribute which must always be available.
 JPNode getStatement()
          Return self if statehead, otherwise returns enclosing statehead.
 int getSubtypeIndex()
          Every JPNode subtype has its own index.
 Symbol getSymbol()
          Certain nodes will have a link to a Symbol, set by TreeParser01.
 java.lang.String getText()
           
 int getType()
           
 void initialize(AST t)
           
 void initialize(int t, java.lang.String txt)
           
 boolean isNatural()
          Is this a natural node (from real source text)? If not, then it is a synthetic node, added just for tree structure.
 boolean isStateHead()
          Does this node have the Proparse STATEHEAD attribute?
 JPNode lastChild()
          Return the last immediate child (no grandchildren).
 JPNode lastDescendant()
           
 JPNode nextNode()
          First child if there is one, otherwise next sibling.
 JPNode nextSibling()
           
 JPNode parent()
           
 JPNode prevNode()
          Previous sibling if there is one, otherwise parent.
 java.util.ArrayList<JPNode> query(int findType)
          Get an array of all descendant nodes (including this node) of a given type.
 void setCall(Call call)
          Some nodes like RUN, USER_FUNC, LOCAL_METHOD_REF have a Call object linked to them by TreeParser01.
 void setColumn(int column)
          Used when re-loading serialized nodes.
 void setComments(java.lang.String comments)
          Set the comments preceding this node.
 void setFieldContainer(FieldContainer fieldContainer)
           
 void setFileIndex(int fileIndex)
          Used when re-loading serialized nodes.
 void setFilenameList(IntegerIndex<java.lang.String> filenameList)
          A reference to the collection of filenames from the parse.
 void setFirstChild(JPNode child)
           
 void setHiddenAfter(ProToken t)
           
 void setHiddenBefore(ProToken t)
           
 void setLine(int line)
          Used when re-loading serialized nodes.
 void setLink(java.lang.Integer key, java.lang.Object value)
           
 void setNextSibling(JPNode sibling)
           
 void setNextSiblingWithLinks(AST n)
           
 void setNodeNum(int nodeNum)
          For use by the JPNode tree construction classes only.
 void setParent(JPNode parent)
           
 void setParentInChildren()
           
 void setPrevSibling(JPNode n)
           
 void setSourceNum(int n)
          Used when re-loading serialized nodes.
 void setSymbol(Symbol symbol)
          Assigned by the tree parser.
 void setText(java.lang.String text)
           
 void setType(int type)
           
 java.lang.String toString()
           
 java.lang.String toStringFulltext()
          Get the full, preprocessed text from a node.
 void walk(ICallback callback)
          Walk the tree from the input node down.
 void writeXferBytes(DataXferStream out)
          Implement Xferable.
 void writeXferSchema(DataXferStream out)
          Implement Xferable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATE2

public static final int STATE2
Just a shortcut to IConstants.STATE2

See Also:
Constant Field Values

CONTEXT_QUALIFIER

public static final int CONTEXT_QUALIFIER
Just a shortcut to IConstants.CONTEXT_QUALIFIER

See Also:
Constant Field Values

SYMBOL

public static final int SYMBOL
A valid value for setLink() and getLink()

See Also:
Constant Field Values

TETNode

public static final int TETNode
A valid value for setLink() and getLink()

See Also:
Constant Field Values

BUFFERSCOPE

public static final int BUFFERSCOPE
A valid value for setLink() and getLink(). Link to a BufferScope object, set by tp01 for RECORD_NAME nodes and for Field_ref nodes for Field (not for Variable). Will not be present if this Field_ref is a reference to the symbol without referencing its value (i.e. no buffer scope).

See Also:
Constant Field Values

BLOCK

public static final int BLOCK
A valid value for setLink() and getLink(). You should not use this directly. Only JPNodes of subtype BlockNode will have this set, so use BlockNode.getBlock instead.

See Also:
BlockNode, Constant Field Values

SUPER_CLASS_TREE

public static final int SUPER_CLASS_TREE
A value for setLink() and getLink(). A link from a CLASS node to the class's superclass's syntax tree.

See Also:
Constant Field Values

FILE_NAME_ARRAY

public static final int FILE_NAME_ARRAY
A value for setLink() and getLink(). Used only for DataXferStream in ProgramRootNode.java. A link from a Program_root node to a copy of the array of filenames.

See Also:
Constant Field Values

AK_STORETYPE

public static final int AK_STORETYPE
See Also:
Constant Field Values

AK_OPERATOR

public static final int AK_OPERATOR
See Also:
Constant Field Values

AK_STATE2

public static final int AK_STATE2
See Also:
Constant Field Values

AK_STATEHEAD

public static final int AK_STATEHEAD
See Also:
Constant Field Values

AK_PROPARSEDIRECTIVE

public static final int AK_PROPARSEDIRECTIVE
See Also:
Constant Field Values

AK_KEYWORD

public static final int AK_KEYWORD
See Also:
Constant Field Values

AK_ABBREVIATED

public static final int AK_ABBREVIATED
See Also:
Constant Field Values

AK_FULLTEXT

public static final int AK_FULLTEXT
See Also:
Constant Field Values

AK_FROMUSERDICT

public static final int AK_FROMUSERDICT
See Also:
Constant Field Values

AK_INLINEVARDEF

public static final int AK_INLINEVARDEF
See Also:
Constant Field Values

AK_SOURCENUM

public static final int AK_SOURCENUM
See Also:
Constant Field Values

AK_QUALIFIEDCLASS

public static final int AK_QUALIFIEDCLASS
See Also:
Constant Field Values

AV_FALSE

public static final int AV_FALSE
See Also:
Constant Field Values

AV_TRUE

public static final int AV_TRUE
See Also:
Constant Field Values

AV_ST_VARIABLE

public static final int AV_ST_VARIABLE
See Also:
Constant Field Values

AV_ST_DBTABLE

public static final int AV_ST_DBTABLE
See Also:
Constant Field Values

AV_ST_TTABLE

public static final int AV_ST_TTABLE
See Also:
Constant Field Values

AV_ST_WTABLE

public static final int AV_ST_WTABLE
See Also:
Constant Field Values
Constructor Detail

JPNode

public JPNode()

JPNode

public JPNode(ProToken t)

JPNode

public JPNode(int type)
Create an node with a given token type. Used extensively by Antlr auto-generated tree constructors.


JPNode

public JPNode(int type,
              JPNode original)
If this AST is constructed from another, then create with link to the original.


JPNode

public JPNode(int type,
              java.lang.String text)

JPNode

public JPNode(int file,
              int line,
              int column)
For temporary nodes for comparison in set of nodes sorted by position

Method Detail

allLeadingHiddenText

public java.lang.String allLeadingHiddenText()

attrGet

public int attrGet(int key)

attrGetS

public java.lang.String attrGetS(int attrNum)

attrGetS

public java.lang.String attrGetS(java.lang.String attrName)

attrSet

public void attrSet(int key,
                    java.lang.String value)

attrSet

public void attrSet(int key,
                    int val)

attrSetS

public void attrSetS(java.lang.String key,
                     java.lang.String value)

finalizeTrailingHidden

public static void finalizeTrailingHidden(JPNode root)

firstChild

public JPNode firstChild()

findDirectChild

public JPNode findDirectChild(int nodeType)
Find the first direct child with a given node type.


firstNaturalChild

public JPNode firstNaturalChild()
First Natural Child is found by repeating firstChild() until a natural node is found. If the start node is a natural node, then it is returned. Note: This is very different than Prolint's "NextNaturalNode" in lintsuper.p.

See Also:
TokenTypes.isNatural(int)

getCall

public Call getCall()
Some nodes like RUN, USER_FUNC, LOCAL_METHOD_REF have a Call object linked to them by TreeParser01.


getColumn

public int getColumn()

getComments

public java.lang.String getComments()
Get the comments that precede this node. Gets the consecutive comments from Proparse if "connected", otherwise gets the comments stored within this node object. CAUTION: We want to know if line breaks exist between comments and nodes, and if they exist between consecutive comments. To preserve that information, the String returned here may have "\n" in front of the first comment, may have "\n" separating comments, and may have "\n" appended to the last comment. We do not preserve the number of newlines, nor do we preserve any other whitespace.

Returns:
null if no comments.

getDirectChildren

public java.util.ArrayList<JPNode> getDirectChildren()
Get an ArrayList of the direct children of this node.


getFieldContainer

public FieldContainer getFieldContainer()
Get the FieldContainer (Frame or Browse) for a statement head node or a frame field reference. This value is set by TreeParser01. Head nodes for statements with the [WITH FRAME | WITH BROWSE] option have this value set. Is also available on the Field_ref node for #(Field_ref INPUT ...) and for #(USING #(Field_ref...)...).


getFilename

public java.lang.String getFilename()

getFilenames

public java.lang.String[] getFilenames()
Get the array of file names. The file at index zero is always the compile unit. The others are include files. The array index position corresponds to JPNode.getFileIndex(). The array is genereated every time this is called, so don't make repeated calls to this.


getFileIndex

public int getFileIndex()

getHiddenAfter

public ProToken getHiddenAfter()

getHiddenBefore

public ProToken getHiddenBefore()

getHiddenFirst

public ProToken getHiddenFirst()

getHiddenTokens

public java.util.List<ProToken> getHiddenTokens()

getLastDescendant

public static JPNode getLastDescendant(JPNode top)
Find the last child of the last child of the...


getLine

public int getLine()

getLink

public java.lang.Object getLink(java.lang.Integer key)
Get a link to an arbitrary object. Integers from -200 through -499 are reserved for Joanju.


getNodeNum

public int getNodeNum()
Node number, as counted in the syntax tree. If this node was created from PUB or from the "getTree" functions to build the tree from Proparse, then the nodeNum is set. Otherwise, it is -1. The count begins at zero at the Program_root node. The node numbers are simply derived by walking down through the tree, depth first. These node numbers are useful for mapping from externally persistent data back to nodes that are no longer in memory but are instead pulled out of PUB files when needed.


getOriginal

public JPNode getOriginal()
If this AST was constructed from another, then get the original.


getPos

public int[] getPos()
Return int[3] of nodes file/line/col.


getSourceNum

public int getSourceNum()
Source number in the macro tree.

See Also:
ListingParser.sourceArray()

getState2

public int getState2()
Description copied from interface: IJPNode
Attribute "state2" is necessary for the tree parsers, so it is one attribute which must always be available.

Specified by:
getState2 in interface IJPNode

getStatement

public JPNode getStatement()
Return self if statehead, otherwise returns enclosing statehead.


getSubtypeIndex

public int getSubtypeIndex()
Every JPNode subtype has its own index. Used for persistent storage.


getSymbol

public Symbol getSymbol()
Certain nodes will have a link to a Symbol, set by TreeParser01.


getText

public java.lang.String getText()

getType

public int getType()

initialize

public void initialize(int t,
                       java.lang.String txt)

initialize

public void initialize(AST t)

isNatural

public boolean isNatural()
Is this a natural node (from real source text)? If not, then it is a synthetic node, added just for tree structure.

See Also:
TokenTypes.isNatural(int)

isStateHead

public boolean isStateHead()
Does this node have the Proparse STATEHEAD attribute?


lastChild

public JPNode lastChild()
Return the last immediate child (no grandchildren).


lastDescendant

public JPNode lastDescendant()

nextNode

public JPNode nextNode()
First child if there is one, otherwise next sibling.


nextSibling

public JPNode nextSibling()

parent

public JPNode parent()

prevNode

public JPNode prevNode()
Previous sibling if there is one, otherwise parent.


query

public java.util.ArrayList<JPNode> query(int findType)
Get an array of all descendant nodes (including this node) of a given type. Same idea as Proparse's "query" functions.


setCall

public void setCall(Call call)
Some nodes like RUN, USER_FUNC, LOCAL_METHOD_REF have a Call object linked to them by TreeParser01.


setColumn

public void setColumn(int column)
Used when re-loading serialized nodes.


setComments

public void setComments(java.lang.String comments)
Set the comments preceding this node. CAUTION: Does not change any values in Proparse. Only use this if the JPNode tree is "disconnected", because getComments returns the comments from the "hidden tokens" in Proparse in "connected" mode.


setFieldContainer

public void setFieldContainer(FieldContainer fieldContainer)
See Also:
getFieldContainer()

setFileIndex

public void setFileIndex(int fileIndex)
Used when re-loading serialized nodes.


setFilenameList

public void setFilenameList(IntegerIndex<java.lang.String> filenameList)
A reference to the collection of filenames from the parse.


setLine

public void setLine(int line)
Used when re-loading serialized nodes.


setLink

public void setLink(java.lang.Integer key,
                    java.lang.Object value)
See Also:
getLink(Integer)

setNodeNum

public void setNodeNum(int nodeNum)
For use by the JPNode tree construction classes only.


setParent

public void setParent(JPNode parent)

setParentInChildren

public void setParentInChildren()

setSourceNum

public void setSourceNum(int n)
Used when re-loading serialized nodes.


setSymbol

public void setSymbol(Symbol symbol)
Assigned by the tree parser.


setFirstChild

public void setFirstChild(JPNode child)

setHiddenAfter

public void setHiddenAfter(ProToken t)

setHiddenBefore

public void setHiddenBefore(ProToken t)

setNextSibling

public void setNextSibling(JPNode sibling)

setPrevSibling

public void setPrevSibling(JPNode n)

setNextSiblingWithLinks

public void setNextSiblingWithLinks(AST n)

setText

public void setText(java.lang.String text)

setType

public void setType(int type)

toString

public java.lang.String toString()

toStringFulltext

public java.lang.String toStringFulltext()
Get the full, preprocessed text from a node. When run on top node, the result is very comparable to COMPILE..PREPROCESS. This is the same as the old C++ Proparse API writeNode(). Also see org.joanju.proparse.Iwdiff.


walk

public void walk(ICallback callback)
Walk the tree from the input node down.


writeXferBytes

public void writeXferBytes(DataXferStream out)
                    throws java.io.IOException
Implement Xferable.

Specified by:
writeXferBytes in interface Xferable
Throws:
java.io.IOException

writeXferSchema

public void writeXferSchema(DataXferStream out)
                     throws java.io.IOException
Implement Xferable.

Specified by:
writeXferSchema in interface Xferable
Throws:
java.io.IOException


Copyright © 2008 Joanju Software. All Rights Reserved.