ptolemy.backtrack.eclipse.ast.transform
Class AbstractTransformer

java.lang.Object
  extended by ptolemy.backtrack.eclipse.ast.transform.AbstractTransformer
Direct Known Subclasses:
AssignmentTransformer, ConstructorTransformer

public abstract class AbstractTransformer
extends java.lang.Object

The abstract superclass of Java source code transformers. A transformer is a class that defines transformation on Java Abstract Syntax Trees (ASTs). It modifies the input AST and produces the output according to a certain transformation semantics.

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.

Since:
Ptolemy II 5.1
Version:
$Id: AbstractTransformer.java 55296 2009-07-28 16:55:06Z cxh $
Author:
Thomas Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Red (tfeng)

Field Summary
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 Summary
AbstractTransformer()
           
 
Method Summary
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.
private static java.lang.String _getNonarrayClassName(java.lang.String name, TypeAnalyzerState state, org.eclipse.jdt.core.dom.CompilationUnit root)
          Get the shortest possible name of the a class.
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ASSIGN_PREFIX

public static final java.lang.String ASSIGN_PREFIX
The prefix of assignment methods.

See Also:
Constant Field Values

BACKUP_PREFIX

public static final java.lang.String BACKUP_PREFIX
The prefix of backup functions.

See Also:
Constant Field Values

CHECKPOINT_NAME

public static final java.lang.String CHECKPOINT_NAME
The name of the checkpoint object.

See Also:
Constant Field Values

CHECKPOINT_RECORD_NAME

public static final java.lang.String CHECKPOINT_RECORD_NAME
The name of the checkpoint record.

See Also:
Constant Field Values

GET_CHECKPOINT_NAME

public static final java.lang.String GET_CHECKPOINT_NAME
The name of the method to get the checkpoint.

See Also:
Constant Field Values

SET_CHECKPOINT_NAME

public static final java.lang.String SET_CHECKPOINT_NAME
The name of the method to set a checkpoint.

See Also:
Constant Field Values
Constructor Detail

AbstractTransformer

public AbstractTransformer()
Method Detail

addToLists

public 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. If the list does not exist, it is created and put into the table.

Parameters:
lists - The table of lists.
key - The key.
value - The value to be added.

createName

public 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 ".").

Parameters:
ast - The AST object.
name - The name.
Returns:
The AST name node.

createType

public 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 "[]").

Parameters:
ast - The AST object.
type - The type.
Returns:
The AST type node.

getClassName

public 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. If there is no conflict, the class is first imported, and only the simple class is returned; otherwise, the its full name is returned.

Parameters:
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.
Returns:
The shortest possible class name.

getClassName

public 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. If there is no conflict, the class is first imported, and only the simple class is returned; otherwise, the its full name is returned.

Parameters:
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.
Returns:
The shortest possible class name.

hasMethod

public 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. This is the same as _hasMethod(c, methodName, parameters, false).

Parameters:
c - The current class.
methodName - The method name.
parameters - The types of parameters for the method.
Returns:
true if the method is already in the class.

hasMethod

public 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.

Parameters:
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.
Returns:
true if the method is already in the class.

indexOf

public static int indexOf(java.lang.String s,
                          char[] chars,
                          int startPos)
Find the first appearance of any of the given characters in a string.

Parameters:
s - The string.
chars - The array of characters.
startPos - The starting position from which the search begins.
Returns:
The index of the first appearance of any of the given characters in the string, or -1 if none of them is found.

isFieldDuplicated

public static boolean isFieldDuplicated(java.lang.Class c,
                                        java.lang.String fieldName)
Test if a field to be added already exists.

Parameters:
c - The current class.
fieldName - The field name.
Returns:
true if the field is already in the class.

lastIndexOf

public static int lastIndexOf(java.lang.String s,
                              char[] chars)
Find the last appearance of any of the given characters in a string.

Parameters:
s - The string.
chars - The array of characters.
Returns:
The index of the last appearance of any of the given characters in the string, or -1 if none of them is found.

removeNode

public static void removeNode(org.eclipse.jdt.core.dom.ASTNode node)
Remove an AST node from the its parent.

Parameters:
node - The node to be removed.

replaceNode

public 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.

Parameters:
node - The node to be replace.
newNode - The new node.

_getAssignMethodName

protected java.lang.String _getAssignMethodName(java.lang.String fieldName,
                                                boolean special)
Get the name of the assignment method.

Parameters:
fieldName - The field name.
special - Whether the method handles special assign operators.
Returns:
The name of the assignment method.

_getBackupMethodName

protected java.lang.String _getBackupMethodName(java.lang.String fieldName)
Get the name of the backup method.

Parameters:
fieldName - The field name.
Returns:
The name of the backup method.

_getNonarrayClassName

private static java.lang.String _getNonarrayClassName(java.lang.String name,
                                                      TypeAnalyzerState state,
                                                      org.eclipse.jdt.core.dom.CompilationUnit root)
Get the shortest possible name of the a class. If there is no conflict, the class is first imported, and only the simple class is returned; otherwise, the its full name is returned.

Parameters:
name - The full class name. It must not be the name of an array type.
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.
Returns:
The shortest possible class name.