org.ow2.clif.scenario.isac.egui.wizards.plugin
Class CodeManipulator

java.lang.Object
  extended by org.ow2.clif.scenario.isac.egui.wizards.plugin.CodeManipulator

public class CodeManipulator
extends java.lang.Object

This class permits to manipulate Java code with the Eclipse JDT API in order to construct a valid Java class for ISAC plugin. A AST Tree is loaded in memory and modified at each user action.

Author:
Fabrice Rivart

Constructor Summary
CodeManipulator()
          Constructor.
 
Method Summary
 void addAction(java.lang.String action, java.lang.String name, int value)
          This method adds action in java code (interface type + field + method + switch case)
 void addActionParameter(java.lang.String action, java.lang.String actionName, java.lang.String parameterName)
          This method adds action parameter in java code (field) (SAMPLE_ACTION_, TIMER_ACTION_, TEST_ACTION_, CONTROL_ACTION_)
 org.eclipse.jdt.core.ICompilationUnit getCompilationUnit()
          Applies all modifications and returns compilation unit.
 boolean isDataProvider()
           
 void load(org.eclipse.jdt.core.ICompilationUnit arg0, java.lang.String arg1, org.eclipse.swt.widgets.Shell arg2)
          This method loads information and contructs a AST Tree.
 void removeAction(java.lang.String action, java.lang.String name, java.lang.String[] params)
          This method removes action in java code if user does not use the field.
 void removeActionParameter(java.lang.String action, java.lang.String actionName, java.lang.String parameterName)
          This method removes action parameter in java code (field) (SAMPLE_ACTION_, TIMER_ACTION_, TEST_ACTION_, CONTROL_ACTION_)
 void reset()
          This method resets memory.
 void setCompilationUnit(org.eclipse.jdt.core.ICompilationUnit cu)
           
 void setDataProvider(boolean provider)
          This method adds or removes informations about DataProvider interface.
 void updateAction(java.lang.String action, java.lang.String oldName, java.lang.String newName, java.lang.String[] params)
          This method updates action and action parameters in project by doing a rename refactoring.
 void updateActionParameter(java.lang.String action, java.lang.String actionName, java.lang.String oldParameterName, java.lang.String newParameterName)
          This method updates action parameter in java code by doing rename refactoring
 void updateClassName(java.lang.String className)
          This method updates class name by doing a rename refactoring.
 void updatePackage(java.lang.String packageName)
          This method updates package name declaration.
 void updatePluginName(java.lang.String arg0)
          This method updates plugin name in class (Javadoc, exception, ...).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CodeManipulator

public CodeManipulator()
Constructor.

Method Detail

load

public void load(org.eclipse.jdt.core.ICompilationUnit arg0,
                 java.lang.String arg1,
                 org.eclipse.swt.widgets.Shell arg2)
          throws java.lang.Exception
This method loads information and contructs a AST Tree.

Parameters:
arg0 - ICompilationUnit representing java class
arg1 - String representing plugin name
arg2 - Shell representing the parent shell
Throws:
java.lang.Exception

reset

public void reset()
This method resets memory.


updatePluginName

public void updatePluginName(java.lang.String arg0)
                      throws java.lang.Exception
This method updates plugin name in class (Javadoc, exception, ...). Plugin name must have this syntax ~name~ to be replaced.

Parameters:
arg0 - String representing new plugin name
Throws:
java.lang.Exception

updatePackage

public void updatePackage(java.lang.String packageName)
                   throws java.lang.Exception
This method updates package name declaration.

Parameters:
packageName - String representing new package name declaration
Throws:
java.lang.Exception

updateClassName

public void updateClassName(java.lang.String className)
                     throws java.lang.Exception
This method updates class name by doing a rename refactoring.

Parameters:
className - String representing new class name
Throws:
java.lang.Exception

setDataProvider

public void setDataProvider(boolean provider)
                     throws java.lang.Exception
This method adds or removes informations about DataProvider interface.

Parameters:
provider - true if class must implements DataProvider interface
Throws:
java.lang.Exception

addAction

public void addAction(java.lang.String action,
                      java.lang.String name,
                      int value)
               throws java.lang.Exception
This method adds action in java code (interface type + field + method + switch case)

Parameters:
action - String representing action (sample, timer, test, control, provider)
name - String representing action name
value - int representing action value
Throws:
java.lang.Exception

removeAction

public void removeAction(java.lang.String action,
                         java.lang.String name,
                         java.lang.String[] params)
                  throws java.lang.Exception
This method removes action in java code if user does not use the field. If field is used, it will be renamed by refactoring with new name 'OLDi_', i is an incremental number, and all switch case will be commented. If field is not used, field will be deleted and all relation too (interface type, method, import)

Parameters:
action - String representing action (sample, timer, test, control)
name - String representing action name
params - String [] representing all action parameters name
Throws:
java.lang.Exception

updateAction

public void updateAction(java.lang.String action,
                         java.lang.String oldName,
                         java.lang.String newName,
                         java.lang.String[] params)
                  throws java.lang.Exception
This method updates action and action parameters in project by doing a rename refactoring.

Parameters:
action - String representing action (sample, timer, test, control)
oldName - String representing old action name
newName - String representing new action name
params - String [] representing all action parameters name
Throws:
java.lang.Exception

addActionParameter

public void addActionParameter(java.lang.String action,
                               java.lang.String actionName,
                               java.lang.String parameterName)
This method adds action parameter in java code (field) (SAMPLE_ACTION_, TIMER_ACTION_, TEST_ACTION_, CONTROL_ACTION_)

Parameters:
action - String representing action (sample, timer, test, control, object)
actionName - String representing action name
parameterName - String representing parameter name

removeActionParameter

public void removeActionParameter(java.lang.String action,
                                  java.lang.String actionName,
                                  java.lang.String parameterName)
                           throws java.lang.Exception
This method removes action parameter in java code (field) (SAMPLE_ACTION_, TIMER_ACTION_, TEST_ACTION_, CONTROL_ACTION_)

Parameters:
action - String representing action (sample, timer, test, control, provider)
actionName - String representing action name
parameterName - String representing parameter name
Throws:
java.lang.Exception

updateActionParameter

public void updateActionParameter(java.lang.String action,
                                  java.lang.String actionName,
                                  java.lang.String oldParameterName,
                                  java.lang.String newParameterName)
                           throws java.lang.Exception
This method updates action parameter in java code by doing rename refactoring

Parameters:
action - String representing action (sample, timer, test, control, object)
actionName - String representing action name
oldParameterName - String representing old parameter name
newParameterName - String representing new parameter name
Throws:
java.lang.Exception

isDataProvider

public boolean isDataProvider()
Returns:
true if class implements DataProvider interface.

getCompilationUnit

public org.eclipse.jdt.core.ICompilationUnit getCompilationUnit()
                                                         throws java.lang.Exception
Applies all modifications and returns compilation unit.

Returns:
the CompilationUnit
Throws:
java.lang.Exception

setCompilationUnit

public void setCompilationUnit(org.eclipse.jdt.core.ICompilationUnit cu)
Parameters:
cu - the CompilationUnit to set