org.prorefactor.core
Class JPUtil

java.lang.Object
  extended by org.prorefactor.core.JPUtil

public class JPUtil
extends java.lang.Object

Joanju Proparse Utility Pack

Integer return values

Integer return values are not like traditional C return values where 0 is success and any other number is an error number. Instead, these are consistent with Proparse's return values: For many of these functions, where the return value is an int, if the integer return value does not already have another meaning, the function could be viewed as a logical "YES we got it / NO it doesn't exist"
1 "success"
0 "failure"
-1 "warning"
-2 "error"


Method Summary
 boolean findDirectChild(int parent, int intoHandle, int nodeType)
          Find the first direct child of a given node type
 void findFieldRefIdNode(int parent, int idNode)
          Find the ID node for a Field_ref
 int findFirstDescendant(int rootNode, int intoHandle, java.lang.String tokenTypeName)
          Find the first descendant of a given type.
 int findFirstHiddenAfterLastDescendant(int node)
          Find the first hidden token after the current node's last descendant.
 ProToken findFirstHiddenAfterLastDescendant(JPNode node)
          Find the first hidden token after the current node's last descendant.
 int firstNaturalChild(int h1, int h2)
          First Natural Child is found by repeating firstChild() until a natural node is found.
 java.lang.String getFilename(int astHandle)
          Get a node's filename - even for a synthetic node.
static JPUtil getInstance()
          This class implements the "Singleton" design pattern.
 int[] getPosition(int astHandle)
          Get a node's fileIndex/line/col position - even for a synthetic node.
 java.lang.String getPositionString(int node)
          Get a string representation of a node's position, ex: "mydir/myfile.p:12:13".
 java.lang.String getPositionString(int[] pos)
          Get a string representation of an int[3] position, ex: "mydir/myfile.p:12:13".
 java.lang.String handleToString(int h1)
          Return a simple string representation of a node.
 boolean isDefineShared(int node)
          Convenience method just to tell if a DEFINE node is DEFINE--SHARED.
 int lastChild(int h1, int h2)
          Finds the last immediate child of a node (no grandchildren).
 int numSiblings(int theNode)
          Number of Siblings - Count the number of "next siblings".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static JPUtil getInstance()
This class implements the "Singleton" design pattern.


isDefineShared

public boolean isDefineShared(int node)
Convenience method just to tell if a DEFINE node is DEFINE--SHARED.

Parameters:
node - The AST node handle.
Returns:
True if DEFINE [NEW [GLOBAL]] SHARED.

findDirectChild

public boolean findDirectChild(int parent,
                               int intoHandle,
                               int nodeType)
Find the first direct child of a given node type

Parameters:
parent - The parent node handle
intoHandle - If found, this handle will point to the desired node
nodeType - Integer token type
Returns:
true if found, false otherwise

findFieldRefIdNode

public void findFieldRefIdNode(int parent,
                               int idNode)
Find the ID node for a Field_ref

Parameters:
parent -
intoHandle -

findFirstDescendant

public int findFirstDescendant(int rootNode,
                               int intoHandle,
                               java.lang.String tokenTypeName)
Find the first descendant of a given type. Input root node handle, input handle to put pointer to resulting node into, input String token type name. Returns 0 on fail, 1 on success.


findFirstHiddenAfterLastDescendant

public int findFirstHiddenAfterLastDescendant(int node)
Find the first hidden token after the current node's last descendant.

Returns:
The result from the hiddenGet... call. (i.e. 1 if found, 0 if not found, negative number on error.)

findFirstHiddenAfterLastDescendant

public ProToken findFirstHiddenAfterLastDescendant(JPNode node)
Find the first hidden token after the current node's last descendant.


firstNaturalChild

public int firstNaturalChild(int h1,
                             int h2)
First Natural Child is found by repeating firstChild() until a natural node is found. Input: start handle, target handle. Start handle is not changed. If the start handle is a natural node, then the target handle will be changed to be pointing at the same node as the start handle. Return value: integer node type of the first natural child found, if any, otherwise 0 is returned. The test for "natural" node is line number. Synthetic node line numbers == 0. Note: This is very different than Prolint's "NextNaturalNode" in lintsuper.p.


getFilename

public java.lang.String getFilename(int astHandle)
Get a node's filename - even for a synthetic node. Uses firstNaturalChild() to ensure that we have a natural node to get the filename from.

Parameters:
Handle - to a node.
Returns:
Whatever was returned after firstNaturalChild() and parser.getNodeFilename().

getPosition

public int[] getPosition(int astHandle)
Get a node's fileIndex/line/col position - even for a synthetic node. Uses firstNaturalChild() to ensure that we have a natural node to get the position from.

Parameters:
Handle - to a node.
Returns:
Array of integers for fileIndex/line/col. Value is {-1, -1, -1} if there's no natural child to the node.

getPositionString

public java.lang.String getPositionString(int node)
Get a string representation of a node's position, ex: "mydir/myfile.p:12:13". Useful for throwing into an Exception's text.


getPositionString

public java.lang.String getPositionString(int[] pos)
Get a string representation of an int[3] position, ex: "mydir/myfile.p:12:13". Useful for throwing into an Exception's text.


handleToString

public java.lang.String handleToString(int h1)
Return a simple string representation of a node. (Usually for testing / debugging)


lastChild

public int lastChild(int h1,
                     int h2)
Finds the last immediate child of a node (no grandchildren). Input: start handle, target handle. If there are no children, the target handle is left unchanged, otherwise it is changed to point at the last immediate child.

Returns:
The last child's integer node type on success, a number less than 1 on fail or error.

numSiblings

public int numSiblings(int theNode)
Number of Siblings - Count the number of "next siblings".



Copyright © 2008 Joanju Software. All Rights Reserved.