public class JavaPatternWorker.JavaAstHelper
extends java.lang.Object
Constructor and Description |
---|
JavaAstHelper() |
Modifier and Type | Method and Description |
---|---|
Aast |
createJavaAst(long type,
java.lang.String text,
Aast parent)
General purpose Java AST creation function which can create a
JavaAst node using the passed token type and text
and then it will attach that node to the specified parent. |
Aast |
createJavaAst(long type,
java.lang.String text,
Aast parent,
int index)
General purpose Java AST creation function which can create a
JavaAst node using the passed token type and text
and then it will attach that node to the specified parent at the
given index position. |
java.lang.Long |
createJavaAst(long type,
java.lang.String text,
java.lang.Long parent)
General purpose Java AST creation function which can create a
JavaAst node using the passed token type and text
and then it will attach that node to the specified parent. |
java.lang.Long |
createJavaAst(long type,
java.lang.String text,
java.lang.Long parent,
int index)
General purpose Java AST creation function which can create a
JavaAst node using the passed token type and text
and then it will attach that node to the specified parent at the
given index position. |
boolean |
createJavaFile(java.lang.String filename,
boolean projectRelative)
Creates a new Java target AST that is associated with a name of the
caller's selection, and sets this AST as the current target AST.
|
boolean |
createJavaFile(java.lang.String filename,
boolean projectRelative,
boolean virtualFile)
Creates a new Java target AST that is associated with a name of the
caller's selection, and sets this AST as the current target AST.
|
java.lang.Long |
createPeerAst(long type,
java.lang.String text)
Simplest case for Java AST creation which creates a
JavaAst node using the passed token type and text
and then it will attach that node to the parent specified by the
'peerid' annotation of the source AST's parent node. |
Aast |
createPeerAst(long type,
java.lang.String text,
Aast parent)
General purpose Java AST creation function which can create a
JavaAst node using the passed token type and text
and then it will attach that node to the specified parent. |
Aast |
createPeerAst(long type,
java.lang.String text,
Aast parent,
int index)
General purpose Java AST creation function which can create a
JavaAst node using the passed token type and text
and then it will attach that node to the specified parent. |
java.lang.Long |
createPeerAst(long type,
java.lang.String text,
java.lang.Long parent)
General purpose Java AST creation function which can create a
JavaAst node using the passed token type and text
and then it will attach that node to the specified parent. |
java.lang.Long |
createPeerAst(long type,
java.lang.String text,
java.lang.Long parent,
int index)
General purpose Java AST creation function which can create a
JavaAst node using the passed token type and text
and then it will attach that node to the specified parent. |
long |
getClosestPeerId()
Search the current source AST node and up each ancestor node in the
path to the root to find the first instance of the 'peerid'
annotation.
|
long |
getJavaRootId()
Exposes the root node ID of the current Java file as a variable.
|
Aast |
getSectionAnchor(Aast classAst,
int type)
Convenience method to retrieve the class section AST which anchors
a certain category of class member.
|
Aast |
getSectionAnchor(int type)
Convenience method to retrieve the class section AST which anchors
a certain category of class member.
|
Aast |
getSectionAnchor(java.lang.Long classId,
int type)
Convenience method to retrieve the class section AST which anchors
a certain category of class member.
|
boolean |
loadJavaFile(java.lang.String filename,
boolean projectRelative)
Loads a persisted Java target AST that is associated with a name of
the caller's selection, and sets this AST as the current target AST.
|
boolean |
persistJavaAst(JavaAst ast)
Save the specified Java AST to file if the tree is not empty (the root has at least 1
child).
|
boolean |
persistJavaAst(java.lang.String filename,
JavaAst ast)
Save the specified Java AST to file if the tree is not empty (the root has at least 1
child).
|
boolean |
persistJavaFile()
Save the current target Java AST to file if the tree is not empty
(the root has at least 1 child).
|
boolean |
persistJavaFile(java.lang.String filename)
Save the current target Java AST to file if the tree is not empty
(the root has at least 1 child).
|
boolean |
setAutoload(boolean auto)
Enables or disables autoloading of the target Java AST each time a
new Progress source AST is visited.
|
public boolean setAutoload(boolean auto)
auto
- true
to enable autoloading.true
.public long getJavaRootId()
public long getClosestPeerId()
public java.lang.Long createJavaAst(long type, java.lang.String text, java.lang.Long parent)
JavaAst
node using the passed token type and text
and then it will attach that node to the specified parent.
The new node will be added as the last child of the parent.
type
- The token type for the Java AST.text
- The text for the AST.parent
- The ID of the parent AST node.null
if the parent ID is invalid, if the type
is not valid or on any unexpected error during AST
creation.public Aast createJavaAst(long type, java.lang.String text, Aast parent)
JavaAst
node using the passed token type and text
and then it will attach that node to the specified parent.
The new node will be added as the last child of the parent.
type
- The token type for the Java AST.text
- The text for the AST.parent
- The parent AST node.null
if the
parent node is invalid, if the type is not valid or on any
unexpected error during AST creation.public java.lang.Long createJavaAst(long type, java.lang.String text, java.lang.Long parent, int index)
JavaAst
node using the passed token type and text
and then it will attach that node to the specified parent at the
given index position.type
- The token type for the Java AST.text
- The text for the AST.parent
- The ID of the parent AST node.index
- 0 to insert as the first child, -1 to insert as the last
child or a 0-based index to specify an exact child index
at which to insert the new child. All current children at
that index or at a greater index, are moved right. If the
index is greater than the current number of children, the
new child will be added at the end.null
if the parent ID is invalid, if the type
is not valid or on any unexpected error during AST
creation.public Aast createJavaAst(long type, java.lang.String text, Aast parent, int index)
JavaAst
node using the passed token type and text
and then it will attach that node to the specified parent at the
given index position.type
- The token type for the Java AST.text
- The text for the AST.parent
- The parent AST node.index
- 0 to insert as the first child, -1 to insert as the last
child or a 0-based index to specify an exact child index
at which to insert the new child. All current children at
that index or at a greater index, are moved right. If the
index is greater than the current number of children, the
new child will be added at the end.null
if the
parent node is invalid, if the type is not valid or on any
unexpected error during AST creation.public java.lang.Long createPeerAst(long type, java.lang.String text, java.lang.Long parent)
JavaAst
node using the passed token type and text
and then it will attach that node to the specified parent. Most
importantly, on success the ID of the generated AST node will be
stored in the current source AST node's 'peerid' annotation. This
provides a standard mechanism to duplicate the structure of a
source AST in the target Java AST. The source AST's ID will also
be stored in the target Java AST 'peerid' annotation which allows
subsequent bidirectional referencing between these peers. This
is used in cases where the conversion is simple enough to drive
it completely from the rule set rather than from a custom worker.type
- The token type for the Java AST.text
- The text for the AST.parent
- The ID of the parent AST node.null
if the parent ID is invalid, if the type
is not valid or on any unexpected error during AST
creation.public Aast createPeerAst(long type, java.lang.String text, Aast parent)
JavaAst
node using the passed token type and text
and then it will attach that node to the specified parent. Most
importantly, on success the ID of the generated AST node will be
stored in the current source AST node's 'peerid' annotation. This
provides a standard mechanism to duplicate the structure of a
source AST in the target Java AST. The source AST's ID will also
be stored in the target Java AST 'peerid' annotation which allows
subsequent bidirectional referencing between these peers. This
is used in cases where the conversion is simple enough to drive
it completely from the rule set rather than from a custom worker.
The new node will be added as the last child of the parent.
type
- The token type for the Java AST.text
- The text for the AST.parent
- The ID of the parent AST node.null
if the
parent node is invalid, if the type is not valid or on any
unexpected error during AST creation.public java.lang.Long createPeerAst(long type, java.lang.String text, java.lang.Long parent, int index)
JavaAst
node using the passed token type and text
and then it will attach that node to the specified parent. Most
importantly, on success the ID of the generated AST node will be
stored in the current source AST node's 'peerid' annotation. This
provides a standard mechanism to duplicate the structure of a
source AST in the target Java AST. The source AST's ID will also
be stored in the target Java AST 'peerid' annotation which allows
subsequent bidirectional referencing between these peers. This
is used in cases where the conversion is simple enough to drive
it completely from the rule set rather than from a custom worker.type
- The token type for the Java AST.text
- The text for the AST.parent
- The ID of the parent AST node.index
- 0 to insert as the first child, -1 to insert as the last
child or a 0-based index to specify an exact child index
at which to insert the new child. All current children at
that index or at a greater index, are moved right. If the
index is greater than the current number of children, the
new child will be added at the end.null
if the parent ID is invalid, if the type
is not valid or on any unexpected error during AST
creation.public Aast createPeerAst(long type, java.lang.String text, Aast parent, int index)
JavaAst
node using the passed token type and text
and then it will attach that node to the specified parent. Most
importantly, on success the ID of the generated AST node will be
stored in the current source AST node's 'peerid' annotation. This
provides a standard mechanism to duplicate the structure of a
source AST in the target Java AST. The source AST's ID will also
be stored in the target Java AST 'peerid' annotation which allows
subsequent bidirectional referencing between these peers. This
is used in cases where the conversion is simple enough to drive
it completely from the rule set rather than from a custom worker.type
- The token type for the Java AST.text
- The text for the AST.parent
- The ID of the parent AST node.index
- 0 to insert as the first child, -1 to insert as the last
child or a 0-based index to specify an exact child index
at which to insert the new child. All current children at
that index or at a greater index, are moved right. If the
index is greater than the current number of children, the
new child will be added at the end.null
if the
parent node is invalid, if the type is not valid or on any
unexpected error during AST creation.public java.lang.Long createPeerAst(long type, java.lang.String text)
JavaAst
node using the passed token type and text
and then it will attach that node to the parent specified by the
'peerid' annotation of the source AST's parent node. This greatly
simplifies creation of entire hierarchies of structure that
match between the source and target ASTs. This uses the services
of createPeerAst(long,String,Long)
.
The new node will be added as the last child of the parent.
type
- The token type for the Java AST.text
- The text for the AST.null
if the parent ID is invalid, if the type
is not valid or on any unexpected error during AST
creation.public Aast getSectionAnchor(int type)
type
- Token type indicating which section is required. Must be
within the range CS_BEGIN < type <
CS_END
.null
if the section does not
exist.java.lang.IllegalArgumentException
- if type
is not within the valid range of
token types specified above.public Aast getSectionAnchor(java.lang.Long classId, int type)
classId
- ID of the class AST within which the target section
resides.type
- Token type indicating which section is required. Must be
within the range CS_BEGIN < type <
CS_END
.null
if the section does not
exist.java.lang.IllegalArgumentException
- if type
is not within the valid range of
token types specified above.public Aast getSectionAnchor(Aast classAst, int type)
classAst
- The class AST within which the target section resides.type
- Token type indicating which section is required. Must be
within the range CS_BEGIN < type <
CS_END
.null
if the section does not
exist.java.lang.IllegalArgumentException
- if type
is not within the valid range of
token types specified above.public boolean createJavaFile(java.lang.String filename, boolean projectRelative)
Any changes made during processing of the previous AST will be lost if they haven't been persisted by this point.
filename
- The filename to use as the Java AST filename.projectRelative
- true
if the filename is relative to the
project home directory, false
if the filename
is absolute or relative to the current directory.public boolean createJavaFile(java.lang.String filename, boolean projectRelative, boolean virtualFile)
Any changes made during processing of the previous AST will be lost if they haven't been persisted by this point.
filename
- The filename to use as the Java AST filename.projectRelative
- true
if the filename is relative to the
project home directory, false
if the filename
is absolute or relative to the current directory.virtualFile
- If true
then the file is not supposed to be persisted into the file
system, the file name is used to map some ID to the AST.public boolean loadJavaFile(java.lang.String filename, boolean projectRelative)
Any changes made during processing of the previous AST will be lost if they haven't been persisted by this point.
filename
- The filename from which to read the Java AST.projectRelative
- true
if the filename is relative to the
project home directory, false
if the filename
is absolute or relative to the current directory.public boolean persistJavaFile() throws ConfigurationException, AstException, java.io.IOException
AstManager
which will essentially disable
further use of this AST.true
if the tree is persisted,
false
if the tree is empty or on any failure
during persistence.ConfigurationException
- if environment is not properly configuredAstException
- if there is an error writing Java AST.java.io.IOException
public boolean persistJavaAst(JavaAst ast) throws ConfigurationException, AstException, java.io.IOException
AstManager
which will
essentially disable further use of this AST.ast
- The AST to be persisted.true
if the tree is persisted,
false
if the tree is empty or on any failure during persistence.ConfigurationException
- if environment is not properly configuredAstException
- if there is an error writing Java AST.java.io.IOException
public boolean persistJavaAst(java.lang.String filename, JavaAst ast) throws ConfigurationException, AstException, java.io.IOException
AstManager
which will
essentially disable further use of this AST.filename
- Base filename (without jast
extension) under which to save the
Java AST. Must be an absolute path or relative to the project root.ast
- The AST to be persisted.true
if the tree is persisted,
false
if the tree is empty or on any failure during persistence.ConfigurationException
- if environment is not properly configuredAstException
- if there is an error writing Java AST.java.io.IOException
public boolean persistJavaFile(java.lang.String filename) throws ConfigurationException, AstException, java.io.IOException
AstManager
which will essentially disable
further use of this AST.filename
- Base filename (without jast
extension) under
which to save the Java AST. Must be an absolute path or
relative to the project root.true
if the tree is persisted,
false
if the tree is empty or on any failure
during persistence.ConfigurationException
- if environment is not properly configuredAstException
- if there is an error writing Java AST.java.io.IOException