public final class JavaPatternWorker extends AbstractConversionWorker implements JavaTokenTypes
JavaTokenTypes
) to their
integral types.Modifier and Type | Class and Description |
---|---|
class |
JavaPatternWorker.JavaAstHelper
Helper to create, edit, move and delete Java ASTs.
|
private static class |
JavaPatternWorker.WorkArea
Context local work area.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
autoload
If
true , the target Java AST will be created or loaded
when a new source AST is visited. |
private static ContextLocal<JavaPatternWorker.WorkArea> |
context |
private JavaAst |
current
Current active Java AST associated with the current source AST.
|
private JavaPatternWorker.JavaAstHelper |
helper
Cache current instance of the helper so that common methods have
access.
|
static java.lang.String |
JAST_POSTFIX
Text to append to a filename to generate a unique name for persisting
a Java AST.
|
private JavaAst |
root
Root of the target tree currently being processed.
|
PEER_ID
resolver
ANNOTATION, ANON_CTOR, ASSIGN, BEGIN_DOCTAGS, BITWISE_AND, BITWISE_OR, BITWISE_XOR, BLOCK, BLOCK_DEF, BOGUS, BOOL_FALSE, BOOL_TRUE, CAST, CHAR_LITERAL, CLASS_REFERENCE, COMPILE_UNIT, COMPLEMENT, CONSTRUCTOR, CS_BEGIN, CS_CONSTANTS, CS_CONSTRUCTORS, CS_END, CS_INNER_CLASSES, CS_INSTANCE_METHODS, CS_INSTANCE_VARS, CS_STATIC_INITS, CS_STATIC_METHODS, CS_STATIC_VARS, DEC_LITERAL, DECREMENT, DIVIDE, DO_WHILE, DOC_COMMENT, DOC_HTML, DOC_PARAGRAPH, DOC_TEXTRUN, DOCTAG_LINK, DOCTAG_PARAM, DOCTAG_RETURN, ELSE_IF, END_DOCTAGS, EQUALS, EXPRESSION, GT, GTE, INCREMENT, INDENT_GRP, INITIALIZER, KW_ABSTRACT, KW_ASSERT, KW_BOOLEAN, KW_BREAK, KW_BYTE, KW_CASE, KW_CATCH, KW_CHAR, KW_CLASS, KW_CONST, KW_CONTINUE, KW_DEFAULT, KW_DO, KW_DOUBLE, KW_ELSE, KW_ENUM, KW_EXTENDS, KW_FINAL, KW_FINALLY, KW_FLOAT, KW_FOR, KW_GOTO, KW_IF, KW_IMPLEMENTS, KW_IMPORT, KW_INSTANCEOF, KW_INT, KW_INTERFACE, KW_LONG, KW_NATIVE, KW_NEW, KW_PACKAGE, KW_PRIVATE, KW_PROTECTED, KW_PUBLIC, KW_RETURN, KW_SHORT, KW_STATIC, KW_STRICTFP, KW_SUPER, KW_SWITCH, KW_SYNCHRONIZED, KW_THIS, KW_THROW, KW_THROWS, KW_TRANSIENT, KW_TRY, KW_VOID, KW_VOLATILE, KW_WHILE, LABEL, LABEL_DEF, LAMBDA, LBRACKET, LOGICAL_AND, LOGICAL_NOT, LOGICAL_OR, LPARENS, LSHIFT, LT, LTE, MEMBER, METHOD_CALL, METHOD_DECL, METHOD_DEF, MINUS, MINUS_ASSIGN, MODULO, MULTIPLY, NOT_EQ, NULL_LITERAL, NUM_LITERAL, OR_ELSE_IF, PLACEHOLDER, PLUS, PLUS_ASSIGN, REFERENCE, REFERENCE_DEF, RSHIFT, SKIP, SLASH_COMMENT, STAR_COMMENT, STATIC_IMPORT, STATIC_METHOD_CALL, STRING, SYMBOL, TERN_IF_ELSE, THEN, UN_MINUS, UN_PLUS, UNRECOGNIZED, ZERO_RSHIFT
Constructor and Description |
---|
JavaPatternWorker()
Default constructor which initializes libraries.
|
Modifier and Type | Method and Description |
---|---|
static JavaAst |
createAst(int type,
java.lang.String text,
JavaAst parent,
AstSymbolResolver resolver,
int index)
Worker routine to centralize creation of new Java ASTs.
|
static JavaAst |
createPeerAst(Aast source,
int type,
java.lang.String text,
JavaAst parent,
AstSymbolResolver resolver,
int index)
Worker routine to peer AST creation.
|
static JavaAst |
createRootAst(java.io.File file,
AstSymbolResolver resolver)
Worker routine to centralize creation of a new Java AST that is a
root node.
|
static JavaAst |
createRootAst(java.lang.String filename,
AstSymbolResolver resolver)
Worker routine to centralize creation of a new Java AST that is a root node.
|
static void |
disableNewFileTracking()
Disables tracking mode such that any JAST files that are persisted
will no longer be logged in the set that can be queried by
getPersistedFiles() . |
static void |
enableNewFileTracking()
Clears past contents of the new files list and enables tracking mode
where all JAST files that are persisted are logged in a set that
can be queried by
getPersistedFiles() . |
private java.lang.String |
generateJavaFilename(Aast ast)
Generate a unique Java AST persistence filename based on the current
source AST filename.
|
static java.lang.String |
generateJavaFilename(java.lang.String filename)
Generate a unique Java AST persistence filename based on the passed
filename.
|
static java.lang.String[] |
getPersistedFiles()
Accesses the list of files persisted since the last call
to
enableNewFileTracking() . |
java.lang.Object |
resolveConstant(java.lang.String constant)
This method is called each time the pattern engine needs to resolve
a string constant into a numeric, boolean, or string literal value.
|
void |
visitAst(Aast ast)
Optionally creates or loads a Java target AST that is associated with
the passed-in source AST.
|
crossReferencePeerAsts, getClosestPeerId, getParentPeer, initializeAst, initializeAst, initializeRootAst, initializeRootAst
finish, getCopy, getLibrary, getSource, initialize, registerTree, setLibrary
public static final java.lang.String JAST_POSTFIX
private static final ContextLocal<JavaPatternWorker.WorkArea> context
private boolean autoload
true
, the target Java AST will be created or loaded
when a new source AST is visited.private JavaAst current
private JavaAst root
private JavaPatternWorker.JavaAstHelper helper
public JavaPatternWorker()
public static JavaAst createAst(int type, java.lang.String text, JavaAst parent, AstSymbolResolver resolver, int index)
type
- The token type for the Java AST.text
- The text for the AST.parent
- The parent AST node or null
.resolver
- The current instance of the AstSymbolResolver
in use
or null
.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.public static JavaAst createPeerAst(Aast source, int type, java.lang.String text, JavaAst parent, AstSymbolResolver resolver, int index)
type
- The token type for the Java AST.text
- The text for the AST.parent
- The parent AST node.resolver
- The current instance of the AstSymbolResolver
in use.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.public static JavaAst createRootAst(java.io.File file, AstSymbolResolver resolver)
AstManager
and set into the AST.file
- The file in which to persist the new AST.resolver
- The current instance of the AstSymbolResolver
in use
or null
.null
on error.public static JavaAst createRootAst(java.lang.String filename, AstSymbolResolver resolver)
AstManager
and set into the AST.filename
- The name of the file in which to persist the new AST. Can be real or virtual (i.e.
the file can be never persisted into the file system, the name is used to map some
ID to the AST).resolver
- The current instance of the AstSymbolResolver
in use
or null
.null
on error.public static java.lang.String generateJavaFilename(java.lang.String filename)
filename
- The filename used as a base for the Java AST filename.public static void enableNewFileTracking()
getPersistedFiles()
. Use
disableNewFileTracking()
when the tracking session is no
longer needed.public static void disableNewFileTracking()
getPersistedFiles()
. Does not alter the contents of the current
persisted files list. Use this to finish a session started with
enableNewFileTracking()
public static java.lang.String[] getPersistedFiles()
enableNewFileTracking()
. There are no duplicate entries in
the list.public java.lang.Object resolveConstant(java.lang.String constant)
resolveConstant
in interface PatternWorker
resolveConstant
in class AbstractPatternWorker
constant
- A case-insensitive token name to be resolved to a token type.Long
value associated with the token type
represented by the token name constant
, or
null
if the given constant is not the name of a
valid, Java language token.public void visitAst(Aast ast)
Any changes made during processing of the previous AST will be lost if they haven't been persisted by this point.
visitAst
in interface PatternWorker
visitAst
in class AbstractPatternWorker
ast
- AST about to be processed by the pattern engine.private java.lang.String generateJavaFilename(Aast ast)