EGF Engine
Release 0.1.0

org.eclipse.egf.pattern.ecore
Class AnnotationHandler

java.lang.Object
  extended by org.eclipse.egf.pattern.ecore.AnnotationHandler

public class AnnotationHandler
extends Object

The annotation handler translates a pattern methods annotations to java code annotations.
It also provides with a parsing of the methods annotations.


Nested Class Summary
protected  class AnnotationHandler.AnnotationCodeAppender
          Annotation code appender.
protected  class AnnotationHandler.JavaCodeAppender
          Java code append to existing pattern operation code.
protected  class AnnotationHandler.PatternCodeAppender
          Pattern code appender to existing pattern operation.
protected  class AnnotationHandler.UnbufferedJavaCodeAppender
          A java code appender that is not prefixed by a call to the string builder.
 
Field Summary
protected static String JAVA_CODE_ANNOTATION_SOURCE
          Java code annotation source.
protected static String JAVA_CODE_APPEND_TO_STRING_BUILDER
          Append to string builder.
protected static String JAVA_CODE_CREATE_STRING_BUILDER
          Create string builder.
protected static String JAVA_CODE_GET_STRING_BUILDER_RESULT
          Return string builder result.
protected static String JAVA_CODE_READ_FILE_CALL_PREFIX
          Read file method call prefix.
protected static String JAVA_CODE_SUPER_CALL_PREFIX
          Super method call prefix.
protected static String OPERATION_ANNOTATION_BODY
          Operation annotation body.
static String PATTERN_CODE_ANNOTATION_SOURCE
          Pattern code annotation source.
protected static String PATTERN_METHOD_ID_PREFIX
          Pattern method id prefix.
static String PATTERN_PRODUCTION_ANNOTATION_BODY_BUFFER_MODIFICATION
          Pattern production buffer modification annotation body.
static String PATTERN_PRODUCTION_ANNOTATION_BODY_COMPILATION
          Pattern production compilation annotation body.
static String PATTERN_PRODUCTION_ANNOTATION_BODY_PATH
          Pattern production path annotation body.
static String PATTERN_PRODUCTION_ANNOTATION_SOURCE
          Pattern production annotation source.
protected static String UID_ANNOTATION_SOURCE
          UID annotation source.
 
Constructor Summary
AnnotationHandler()
           
 
Method Summary
protected  void addCallMethodJavaCode(EOperation operation_p, String methodName_p)
          Add call method (java code) for given operation and method name.
 void addCallMethodPatternCode(EOperation operation_p, String methodName_p)
          Add call method (pattern code) for given operation and method name.
protected  void addGenerateOtherPatternJavaCode(EOperation operation_p, String patternFullId_p)
          TODO Guillaume
Specific to JET templates.
 void addGenerateOtherPatternPatternCode(EOperation operation_p, String patternFullId_p)
          Add generate identified pattern (pattern code) for given operation and pattern full id.
 boolean addProductionAnnotation(Pattern pattern_p, PatternHandler.ProductionOptionsHandler productionHandler_p)
          Add/replace pattern production annotation based on given production handler values.
protected  void addReadFileJavaCode(EOperation operation_p, String fileRelativePath_p)
          Add read file (java code) for given operation and file relative path.
 void addReadFilePatternCode(EOperation operation_p, String fileRelativePath_p)
          Add read file (pattern code) for given operation and file relative path.
protected  void addSuperMethodCallJavaCode(EOperation operation_p, String methodName_p)
          Add call to super method (java code) for given operation and method name.
 void addSuperMethodCallPatternCode(EOperation operation_p, String methodName_p)
          Add call to super method (pattern code) for given operation and method name.
 String addUidAnnotation(EOperation operation_p)
          Add UID annotation to given operation.
protected  void doAppendPatternCode(String operationName_p, String parameter_p, StringBuilder existingCode_p)
          Append operation to given string builder of pattern code.
protected  boolean doTranslateAnnotation(EOperation operation_p)
          Do translate annotation for given operation.
protected  void explore(Tree tree_p, List<Couple<String,String>> actions_p)
          Explore current tree level, and fill given pattern code actions list accordingly.
protected  void exploreAndTranslate(Tree tree_p, EOperation operation_p)
          Explore annotation abstract syntax tree and translate accordingly.
protected  void finalizeJavaCode(EOperation operation_p)
          Finalize java code for given operation.
protected  Couple<String,String> getActionAndParameter(Tree tree_p)
          Get a couple composed of the top action (and its parameter) of given tree.
 List<String> getCalledPatternIDs(EOperation operation_p)
          Get pattern IDs that are called through this operation.
protected  String getCallOtherPatternTemplateCode(String patternFullId_p)
          TODO Guillaume
Specific to JET templates.
protected  String getFirstChild(Tree tree_p)
          Get first child of given tree as a string.
protected  EAnnotation getOrCreateAnnotation(EOperation operation_p, String sourceAnnotation_p, boolean forceCreation_p)
          Get annotation for given operation and source.
protected  EAnnotation getOrCreateJavaCodeAnnotation(EOperation operation_p)
          Get or create java code annotation for given operation.
protected  EAnnotation getOrCreatePatternCodeAnnotation(EOperation operation_p, boolean forceCreation_p)
          Get or create pattern code annotation for given operation.
 List<Couple<String,String>> getOrderedActionsFor(EOperation operation_p)
          Get ordered list of pattern code actions for given pattern operation.
protected  String getPatternCode(EOperation operation_p)
          Get pattern code for given operation.
protected  CommonTree getTree(String patternCode_p)
          Get abstract syntax tree out of given pattern code.
 String getUid(EOperation operation_p)
          Get operation UID.
 boolean hasPatternCode(EOperation operation_p)
          Is given operation referencing pattern code ?
protected  void initializeJavaCode(EOperation operation_p)
          Initialize java code for given operation.
 void recomputeAnnotationFromActions(EOperation operation_p, List<Couple<String,String>> actions_p)
          Recompute pattern code annotation for given method using given actions.
 List<Couple<String,String>> removeActionsFor(String parameterValue_p, List<Couple<String,String>> actions_p)
          Deprecated.  
 EAnnotation removeProductionAnnotation(Pattern pattern_p)
          Remove production annotation from given pattern, if any.
 void replaceParameter(String oldParameterValue_p, String newParameterValue_p, List<Couple<String,String>> actions_p)
          Replace old parameter value with new one, everywhere it is used in given actions list.
 boolean translateAnnotations(List<EOperation> operations_p)
          Translate annotations from pattern code to java code for given pattern operations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA_CODE_SUPER_CALL_PREFIX

protected static final String JAVA_CODE_SUPER_CALL_PREFIX
Super method call prefix.

See Also:
Constant Field Values

JAVA_CODE_READ_FILE_CALL_PREFIX

protected static final String JAVA_CODE_READ_FILE_CALL_PREFIX
Read file method call prefix.

See Also:
Constant Field Values

JAVA_CODE_CREATE_STRING_BUILDER

protected static final String JAVA_CODE_CREATE_STRING_BUILDER
Create string builder.

See Also:
Constant Field Values

JAVA_CODE_APPEND_TO_STRING_BUILDER

protected static final String JAVA_CODE_APPEND_TO_STRING_BUILDER
Append to string builder.

See Also:
Constant Field Values

JAVA_CODE_GET_STRING_BUILDER_RESULT

protected static final String JAVA_CODE_GET_STRING_BUILDER_RESULT
Return string builder result.

See Also:
Constant Field Values

OPERATION_ANNOTATION_BODY

protected static final String OPERATION_ANNOTATION_BODY
Operation annotation body.

See Also:
Constant Field Values

UID_ANNOTATION_SOURCE

protected static final String UID_ANNOTATION_SOURCE
UID annotation source.

See Also:
Constant Field Values

JAVA_CODE_ANNOTATION_SOURCE

protected static final String JAVA_CODE_ANNOTATION_SOURCE
Java code annotation source.

See Also:
Constant Field Values

PATTERN_CODE_ANNOTATION_SOURCE

public static final String PATTERN_CODE_ANNOTATION_SOURCE
Pattern code annotation source.

See Also:
Constant Field Values

PATTERN_PRODUCTION_ANNOTATION_SOURCE

public static final String PATTERN_PRODUCTION_ANNOTATION_SOURCE
Pattern production annotation source.

See Also:
Constant Field Values

PATTERN_PRODUCTION_ANNOTATION_BODY_PATH

public static final String PATTERN_PRODUCTION_ANNOTATION_BODY_PATH
Pattern production path annotation body.

See Also:
Constant Field Values

PATTERN_PRODUCTION_ANNOTATION_BODY_COMPILATION

public static final String PATTERN_PRODUCTION_ANNOTATION_BODY_COMPILATION
Pattern production compilation annotation body.

See Also:
Constant Field Values

PATTERN_PRODUCTION_ANNOTATION_BODY_BUFFER_MODIFICATION

public static final String PATTERN_PRODUCTION_ANNOTATION_BODY_BUFFER_MODIFICATION
Pattern production buffer modification annotation body.

See Also:
Constant Field Values

PATTERN_METHOD_ID_PREFIX

protected static final String PATTERN_METHOD_ID_PREFIX
Pattern method id prefix.

See Also:
Constant Field Values
Constructor Detail

AnnotationHandler

public AnnotationHandler()
Method Detail

getTree

protected CommonTree getTree(String patternCode_p)
Get abstract syntax tree out of given pattern code.

Parameters:
patternCode_p -
Returns:

getOrderedActionsFor

public List<Couple<String,String>> getOrderedActionsFor(EOperation operation_p)
Get ordered list of pattern code actions for given pattern operation.

Parameters:
operation_p -
Returns:
List of (action, parameter) couples.

getCalledPatternIDs

public List<String> getCalledPatternIDs(EOperation operation_p)
Get pattern IDs that are called through this operation.
Only applicable to the generate method.

Parameters:
operation_p -
Returns:
An empty list of String if given method is null or is not the generate method or no external pattern is called. A list of called patterns full IDs otherwise.

replaceParameter

public void replaceParameter(String oldParameterValue_p,
                             String newParameterValue_p,
                             List<Couple<String,String>> actions_p)
Replace old parameter value with new one, everywhere it is used in given actions list.

Parameters:
oldParameterValue_p -
newParameterValue_p - As a result, given actions list remains unmodified, but its contained actions are (unless no modification happened).

removeActionsFor

public List<Couple<String,String>> removeActionsFor(String parameterValue_p,
                                                    List<Couple<String,String>> actions_p)
Deprecated. 

Remove actions using given parameter from given actions list.

Parameters:
parameterValue_p -
actions_p -
Returns:
List of removed actions.

recomputeAnnotationFromActions

public void recomputeAnnotationFromActions(EOperation operation_p,
                                           List<Couple<String,String>> actions_p)
Recompute pattern code annotation for given method using given actions.
As a result, java code annotation is removed, and is to be recomputed.

Parameters:
operation_p -
actions_p -

addUidAnnotation

public String addUidAnnotation(EOperation operation_p)
Add UID annotation to given operation.

Parameters:
operation_p -
Returns:
String, the UID set for this operation, null if given operation is null.

addProductionAnnotation

public boolean addProductionAnnotation(Pattern pattern_p,
                                       PatternHandler.ProductionOptionsHandler productionHandler_p)
Add/replace pattern production annotation based on given production handler values.

Parameters:
pattern_p -
productionHandler_p -
Returns:

removeProductionAnnotation

public EAnnotation removeProductionAnnotation(Pattern pattern_p)
Remove production annotation from given pattern, if any.

Parameters:
pattern_p -
Returns:
Removed annotation, or null if given pattern is null or is not containing such an annotation.

getUid

public String getUid(EOperation operation_p)
Get operation UID.

Parameters:
operation_p -
Returns:
null if given operation is null.

getActionAndParameter

protected Couple<String,String> getActionAndParameter(Tree tree_p)
Get a couple composed of the top action (and its parameter) of given tree.

Parameters:
tree_p -
Returns:
Key = action name, Value = parameter.

explore

protected void explore(Tree tree_p,
                       List<Couple<String,String>> actions_p)
Explore current tree level, and fill given pattern code actions list accordingly.

Parameters:
tree_p -
actions_p -

translateAnnotations

public boolean translateAnnotations(List<EOperation> operations_p)
Translate annotations from pattern code to java code for given pattern operations.

Parameters:
operations_p -
Returns:
true if successful, false otherwise.

hasPatternCode

public boolean hasPatternCode(EOperation operation_p)
Is given operation referencing pattern code ?

Parameters:
operation_p -
Returns:

doTranslateAnnotation

protected boolean doTranslateAnnotation(EOperation operation_p)
Do translate annotation for given operation.

Parameters:
operation_p -
Returns:

exploreAndTranslate

protected void exploreAndTranslate(Tree tree_p,
                                   EOperation operation_p)
Explore annotation abstract syntax tree and translate accordingly.

Parameters:
tree_p -
operation_p -

getFirstChild

protected String getFirstChild(Tree tree_p)
Get first child of given tree as a string.

Parameters:
tree_p -
Returns:
null if none could be found.

getPatternCode

protected String getPatternCode(EOperation operation_p)
Get pattern code for given operation.

Parameters:
operation_p -
Returns:
null if no code could be found.

initializeJavaCode

protected void initializeJavaCode(EOperation operation_p)
Initialize java code for given operation.
It does create a new java code annotation, and add string builder creation code.

Parameters:
operation_p -

finalizeJavaCode

protected void finalizeJavaCode(EOperation operation_p)
Finalize java code for given operation.
Adds string builder return code.

Parameters:
operation_p -

addGenerateOtherPatternPatternCode

public void addGenerateOtherPatternPatternCode(EOperation operation_p,
                                               String patternFullId_p)
Add generate identified pattern (pattern code) for given operation and pattern full id.

Parameters:
operation_p -
patternFullId_p -

addGenerateOtherPatternJavaCode

protected void addGenerateOtherPatternJavaCode(EOperation operation_p,
                                               String patternFullId_p)
TODO Guillaume
Specific to JET templates.
Add generate identified pattern (java code) for given operation and pattern full id.

Parameters:
operation_p -
patternFullId_p -

getCallOtherPatternTemplateCode

protected String getCallOtherPatternTemplateCode(String patternFullId_p)
TODO Guillaume
Specific to JET templates.
Get call to another pattern template code.

Parameters:
patternFullId_p - The pattern to call full id.
Returns:

addReadFilePatternCode

public void addReadFilePatternCode(EOperation operation_p,
                                   String fileRelativePath_p)
Add read file (pattern code) for given operation and file relative path.

Parameters:
operation_p -
fileRelativePath_p -

addReadFileJavaCode

protected void addReadFileJavaCode(EOperation operation_p,
                                   String fileRelativePath_p)
Add read file (java code) for given operation and file relative path.

Parameters:
operation_p -
fileRelativePath_p -

addCallMethodPatternCode

public void addCallMethodPatternCode(EOperation operation_p,
                                     String methodName_p)
Add call method (pattern code) for given operation and method name.

Parameters:
operation_p -
methodName_p -

addCallMethodJavaCode

protected void addCallMethodJavaCode(EOperation operation_p,
                                     String methodName_p)
Add call method (java code) for given operation and method name.

Parameters:
operation_p -
methodName_p -

addSuperMethodCallPatternCode

public void addSuperMethodCallPatternCode(EOperation operation_p,
                                          String methodName_p)
Add call to super method (pattern code) for given operation and method name.

Parameters:
operation_p -
methodName_p -

addSuperMethodCallJavaCode

protected void addSuperMethodCallJavaCode(EOperation operation_p,
                                          String methodName_p)
Add call to super method (java code) for given operation and method name.

Parameters:
operation_p -
methodName_p - Can be null, the given operation name is used instead.

getOrCreateJavaCodeAnnotation

protected EAnnotation getOrCreateJavaCodeAnnotation(EOperation operation_p)
Get or create java code annotation for given operation.

Parameters:
operation_p -
Returns:

getOrCreatePatternCodeAnnotation

protected EAnnotation getOrCreatePatternCodeAnnotation(EOperation operation_p,
                                                       boolean forceCreation_p)
Get or create pattern code annotation for given operation.
If creation flag is set to false, then no creation will be attempted if no annotation could be found.

Parameters:
operation_p -
forceCreation_p -
Returns:

getOrCreateAnnotation

protected EAnnotation getOrCreateAnnotation(EOperation operation_p,
                                            String sourceAnnotation_p,
                                            boolean forceCreation_p)
Get annotation for given operation and source.
If none exists, and force creation flag is set to true, create a new one that matches these parameters.

Parameters:
operation_p -
sourceAnnotation_p -
forceCreation_p - Should an annotation be created if none could be found ?
Returns:
A not null annotation.

doAppendPatternCode

protected void doAppendPatternCode(String operationName_p,
                                   String parameter_p,
                                   StringBuilder existingCode_p)
Append operation to given string builder of pattern code.

Parameters:
operationName_p - Operation to use.
parameter_p - Operation parameter. Always a String. May be null.
existingCode_p - a not null StringBuilder containing existing pattern code.

EGF Engine
Release 0.1.0

Copyright (c) Thales Corporate Services S.A.S, 2009.

This page is made available under license. For full details see the LEGAL in the documentation book that contains this page.