public abstract class AbstractTransformer
extends java.lang.Object
Static methods that can be used in any transformer are defined in this class. It is also safe to call them in non-transformer classes to modify the AST.
This abstract class has no protected methods that need to be overridden by subclasses. It is stateless. States may be introduced by subclasses.
Red (tfeng) |
Red (tfeng) |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ASSIGN_PREFIX
The prefix of assignment methods.
|
static java.lang.String |
BACKUP_PREFIX
The prefix of backup functions.
|
static java.lang.String |
CHECKPOINT_NAME
The name of the checkpoint object.
|
static java.lang.String |
CHECKPOINT_RECORD_NAME
The name of the checkpoint record.
|
static java.lang.String |
GET_CHECKPOINT_NAME
The name of the method to get the checkpoint.
|
static java.lang.String |
SET_CHECKPOINT_NAME
The name of the method to set a checkpoint.
|
Constructor and Description |
---|
AbstractTransformer() |
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
_getAssignMethodName(java.lang.String fieldName,
boolean special)
Get the name of the assignment method.
|
protected java.lang.String |
_getBackupMethodName(java.lang.String fieldName)
Get the name of the backup method.
|
static <K,V> void |
addToLists(java.util.Hashtable<K,java.util.List<V>> lists,
K key,
V value)
Given a table of lists, add a value to the list associated with a key.
|
static org.eclipse.jdt.core.dom.Name |
createName(org.eclipse.jdt.core.dom.AST ast,
java.lang.String name)
Create an AST name node with a name string (possibly partitioned with
".").
|
static org.eclipse.jdt.core.dom.Type |
createType(org.eclipse.jdt.core.dom.AST ast,
java.lang.String type)
Create an AST type node with a type string (possibly partitioned with
"." and "[]").
|
static java.lang.String |
getClassName(java.lang.Class c,
TypeAnalyzerState state,
org.eclipse.jdt.core.dom.CompilationUnit root)
Get the shortest possible name of the a class.
|
static java.lang.String |
getClassName(java.lang.String name,
TypeAnalyzerState state,
org.eclipse.jdt.core.dom.CompilationUnit root)
Get the shortest possible name of the a class.
|
static boolean |
hasMethod(java.lang.Class c,
java.lang.String methodName,
java.lang.Class[] parameters)
Test if a method exists in a class or its superclasses.
|
static boolean |
hasMethod(java.lang.Class c,
java.lang.String methodName,
java.lang.Class[] parameters,
boolean thisClassOnly)
Test if a method exists in a class.
|
static int |
indexOf(java.lang.String s,
char[] chars,
int startPos)
Find the first appearance of any of the given characters in a string.
|
static boolean |
isFieldDuplicated(java.lang.Class c,
java.lang.String fieldName)
Test if a field to be added already exists.
|
static int |
lastIndexOf(java.lang.String s,
char[] chars)
Find the last appearance of any of the given characters in a string.
|
static void |
removeNode(org.eclipse.jdt.core.dom.ASTNode node)
Remove an AST node from the its parent.
|
static void |
replaceNode(org.eclipse.jdt.core.dom.ASTNode node,
org.eclipse.jdt.core.dom.ASTNode newNode)
Replace an AST node with another one by substituting the corresponding
child of its parent.
|
public static final java.lang.String ASSIGN_PREFIX
public static final java.lang.String BACKUP_PREFIX
public static final java.lang.String CHECKPOINT_NAME
public static final java.lang.String CHECKPOINT_RECORD_NAME
public static final java.lang.String GET_CHECKPOINT_NAME
public static final java.lang.String SET_CHECKPOINT_NAME
public static <K,V> void addToLists(java.util.Hashtable<K,java.util.List<V>> lists, K key, V value)
lists
- The table of lists.key
- The key.value
- The value to be added.public static org.eclipse.jdt.core.dom.Name createName(org.eclipse.jdt.core.dom.AST ast, java.lang.String name)
ast
- The AST
object.name
- The name.public static org.eclipse.jdt.core.dom.Type createType(org.eclipse.jdt.core.dom.AST ast, java.lang.String type)
ast
- The AST
object.type
- The type.public static java.lang.String getClassName(java.lang.Class c, TypeAnalyzerState state, org.eclipse.jdt.core.dom.CompilationUnit root)
c
- The class.state
- The state of the type analyzer.root
- The root of the AST. If there is no conflict and the class
has not been imported yet, a new ImportDeclaration
is added to
it.public static java.lang.String getClassName(java.lang.String name, TypeAnalyzerState state, org.eclipse.jdt.core.dom.CompilationUnit root)
name
- The full class name.state
- The state of the type analyzer.root
- The root of the AST. If there is no conflict and
the class has not been imported yet, a new ImportDeclaration
is added to it.public static boolean hasMethod(java.lang.Class c, java.lang.String methodName, java.lang.Class[] parameters)
c
- The current class.methodName
- The method name.parameters
- The types of parameters for the method.public static boolean hasMethod(java.lang.Class c, java.lang.String methodName, java.lang.Class[] parameters, boolean thisClassOnly)
c
- The current class.methodName
- The method name.thisClassOnly
- Whether to test the given class only (but not
test its superclasses).parameters
- The types of parameters for the method.public static int indexOf(java.lang.String s, char[] chars, int startPos)
s
- The string.chars
- The array of characters.startPos
- The starting position from which the search begins.public static boolean isFieldDuplicated(java.lang.Class c, java.lang.String fieldName)
c
- The current class.fieldName
- The field name.public static int lastIndexOf(java.lang.String s, char[] chars)
s
- The string.chars
- The array of characters.public static void removeNode(org.eclipse.jdt.core.dom.ASTNode node)
node
- The node to be removed.public static void replaceNode(org.eclipse.jdt.core.dom.ASTNode node, org.eclipse.jdt.core.dom.ASTNode newNode)
node
- The node to be replace.newNode
- The new node.protected java.lang.String _getAssignMethodName(java.lang.String fieldName, boolean special)
fieldName
- The field name.special
- Whether the method handles special assign operators.protected java.lang.String _getBackupMethodName(java.lang.String fieldName)
fieldName
- The field name.