org.cesta.trans.java
Class AbstractRewriteTransformation

java.lang.Object
  extended by org.cesta.trans.AbstractTransformation
      extended by org.cesta.trans.java.AbstractRewriteTransformation
All Implemented Interfaces:
Transformation
Direct Known Subclasses:
CheckTransactions, IfSwitchReplacement, ShadowVariables, ValidateStateTransitions

public abstract class AbstractRewriteTransformation
extends AbstractTransformation

Abstract class for Java Card rewrite transformations. So far, all Java Card transformations are similar - Java based tree rewrites with output to templates. Abstract transformation contains common methods.

Parameters:

NameTypeDefaultDescription
generateComments Boolean true whether to generate comments in transformed file
templatePath String "templates" path to templates, multiple directories separated by ":", directories can be located anywhere on classpath
templateGroup String parser class simple name, e.g. ShadowVariablesParser name of template group, which should be used to load templates
javaCard Boolean true optimize transformation for Java Card, example usage is to handle differently runtime exceptions in templates.
nestedRewrite Boolean true allow nested rewrites (rewrite part of already rewritten code), with some transformations it can cause pretty big overhead

Author:
Tobias Smolka

Field Summary
protected  org.antlr.runtime.TokenRewriteStream tokens
           
protected  org.antlr.runtime.tree.CommonTree tree
           
 
Fields inherited from class org.cesta.trans.AbstractTransformation
logger
 
Constructor Summary
AbstractRewriteTransformation()
           
 
Method Summary
 void execute()
          Main entry point of the transformation
 java.util.Map<java.lang.String,java.lang.Object> getDefaultParams()
          Returns default parameters
protected  org.antlr.runtime.tree.TreeNodeStream prepareTreeNodeStream(org.antlr.runtime.CharStream inputStream)
          Prepares tree node stream from inputStream.
 void registerTemplateGroupLoader()
          Registers default template group loader.
abstract  void transform(MappedFile filePair)
          Transforms single file
 
Methods inherited from class org.cesta.trans.AbstractTransformation
addMappedFile, clearParams, getMappedFiles, getParam, getParam, getParamB, getParamB, getParams, getParamS, getParamS, setMappedFiles, setParam, setParams
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tokens

protected org.antlr.runtime.TokenRewriteStream tokens

tree

protected org.antlr.runtime.tree.CommonTree tree
Constructor Detail

AbstractRewriteTransformation

public AbstractRewriteTransformation()
Method Detail

getDefaultParams

public java.util.Map<java.lang.String,java.lang.Object> getDefaultParams()
Returns default parameters

Overrides:
getDefaultParams in class AbstractTransformation
Returns:
map of parameters

prepareTreeNodeStream

protected org.antlr.runtime.tree.TreeNodeStream prepareTreeNodeStream(org.antlr.runtime.CharStream inputStream)
                                                               throws TransformationException
Prepares tree node stream from inputStream.

Parameters:
inputStream - input stream
Returns:
initialized tree node stream
Throws:
TransformationException - in case input stream could not be read or contains errors

transform

public abstract void transform(MappedFile filePair)
                        throws TransformationException
Transforms single file

Parameters:
filePair - File pair (input/output) to transform
Throws:
TransformationException - In case transformation failed

execute

public void execute()
             throws TransformationException
Main entry point of the transformation

Specified by:
execute in interface Transformation
Specified by:
execute in class AbstractTransformation
Throws:
TransformationException - In case transformation failed

registerTemplateGroupLoader

public void registerTemplateGroupLoader()
Registers default template group loader. Default path can be overriden by parameter "templatePath".