archimate.codegen
Class JavaHelper

java.lang.Object
  extended by archimate.codegen.JavaHelper

public class JavaHelper
extends java.lang.Object

This utility class provides methods for accessing and editing source code parsed by the ASTParser

Author:
Samuel Esposito

Field Summary
static java.lang.String ARCHIMATETAG
          TagName for the archiMateTag
static java.lang.String METHOD_DECLARATION
          Constant defining a method declaration in an interface
static java.lang.String METHOD_IMPLEMENTATION
          Constant defining a method implementation in a class
static java.lang.String METHOD_INVOCATION
          Constant defining a method invocation in a class
 
Constructor Summary
JavaHelper(java.lang.String currentPattern)
          Creates a new JavaHelper
 
Method Summary
 void addClass(org.eclipse.jdt.core.dom.CompilationUnit unit, JavaClass javaClass)
          Adds a class declaration to the CompilationUnit.
 void addImports(org.eclipse.jdt.core.dom.CompilationUnit unit, java.util.ArrayList<java.lang.String> imports)
          Adds the given imports to the given CompilationUnit if it doesn't already contain them.
 void addJavaDoc(org.eclipse.jdt.core.dom.BodyDeclaration body, ICodeElement element)
          Adds JavaDoc to a BodyDeclaration based on the settings of the ICodeElement
 void addMethod(org.eclipse.jdt.core.dom.TypeDeclaration node, JavaMethod method)
          Adds a method to a TypeDeclaration based on the settings of the JavaMethod.
 void addMethodInvocation(org.eclipse.jdt.core.dom.Block methodBlock, java.lang.String objectName, java.lang.String methodName, java.util.ArrayList<java.lang.String> arglist)
          Adds a method invocation to the method block
 void addMethods(org.eclipse.jdt.core.dom.TypeDeclaration node, TagNode tagnode, org.eclipse.core.runtime.MultiStatus status)
          Adds methods defined by the TagNodes ICodeElements to the TypeDeclaration node
 void addObject(org.eclipse.jdt.core.dom.Block methodBlock, java.lang.String type, java.lang.String name, java.util.ArrayList<java.lang.String> arglist)
          Adds a statement that creates an object.
static java.lang.String camelize(java.lang.String name)
          Camelizes a name
 void compare(org.eclipse.jdt.core.dom.MethodDeclaration node, TagNode tagnode, org.eclipse.core.runtime.MultiStatus status, java.lang.String pattern)
          Compares the TagNodes source elements with the given MethodDeclaration and sets the MultiStatus according to the result
 void compare(org.eclipse.jdt.core.dom.TypeDeclaration node, TagNode tagnode, org.eclipse.core.runtime.MultiStatus status, java.lang.String pattern)
          Compares the TagNodes source elements with the given TypeDeclaration and sets the MultiStatus according to the result
 java.lang.String getArchiMateTag(org.eclipse.jdt.core.dom.BodyDeclaration node)
          Searches for an archiMateTag in the javadoc of the given node.
 java.lang.String getName(org.eclipse.jdt.core.dom.MethodDeclaration node)
          Returns the name of the MethodDeclaration
 java.lang.String getName(org.eclipse.jdt.core.dom.TypeDeclaration node)
          Returns the name of the TypeDeclaration
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARCHIMATETAG

public static final java.lang.String ARCHIMATETAG
TagName for the archiMateTag

See Also:
Constant Field Values

METHOD_IMPLEMENTATION

public static final java.lang.String METHOD_IMPLEMENTATION
Constant defining a method implementation in a class

See Also:
Constant Field Values

METHOD_INVOCATION

public static final java.lang.String METHOD_INVOCATION
Constant defining a method invocation in a class

See Also:
Constant Field Values

METHOD_DECLARATION

public static final java.lang.String METHOD_DECLARATION
Constant defining a method declaration in an interface

See Also:
Constant Field Values
Constructor Detail

JavaHelper

public JavaHelper(java.lang.String currentPattern)
Creates a new JavaHelper

Parameters:
currentPattern - the pattern currently processed
Method Detail

getArchiMateTag

public java.lang.String getArchiMateTag(org.eclipse.jdt.core.dom.BodyDeclaration node)
Searches for an archiMateTag in the javadoc of the given node.

Parameters:
node - ASTNode to be searched
Returns:
The found archiMateTag

getName

public java.lang.String getName(org.eclipse.jdt.core.dom.TypeDeclaration node)
Returns the name of the TypeDeclaration

Parameters:
node - a TypeDeclaration
Returns:
The name of the TypeDeclaration

getName

public java.lang.String getName(org.eclipse.jdt.core.dom.MethodDeclaration node)
Returns the name of the MethodDeclaration

Parameters:
node - a MethodDeclaration
Returns:
The name of the MethodDeclaration

addImports

public void addImports(org.eclipse.jdt.core.dom.CompilationUnit unit,
                       java.util.ArrayList<java.lang.String> imports)
Adds the given imports to the given CompilationUnit if it doesn't already contain them.

Parameters:
unit - The CompilationUnit to add the imports to.
imports - A list of import names to be added

addClass

public void addClass(org.eclipse.jdt.core.dom.CompilationUnit unit,
                     JavaClass javaClass)
Adds a class declaration to the CompilationUnit.

Parameters:
unit - The CompilationUnit to add the class declaration to
javaClass - The JavaClass defining the class to create

addMethods

public void addMethods(org.eclipse.jdt.core.dom.TypeDeclaration node,
                       TagNode tagnode,
                       org.eclipse.core.runtime.MultiStatus status)
Adds methods defined by the TagNodes ICodeElements to the TypeDeclaration node

Parameters:
node - TypeDeclaration node to add the methods to
tagnode - TagNode with a list of ICodeElements

addMethod

public void addMethod(org.eclipse.jdt.core.dom.TypeDeclaration node,
                      JavaMethod method)
Adds a method to a TypeDeclaration based on the settings of the JavaMethod. If the JavaMethods type is a JavaMethod.DECLARATION, a method declaration is added. If the JavaMethods type is a JavaMethod.IMPLEMENTATION, a method with a method block is added. If the JavaMethods type is a JavaMethod.INVOCATION, a method with a method invocation in its block is added.

Parameters:
node - TypeDeclaration node to add the methods to
method - JavaMethod object containing all the settings for the new method

addJavaDoc

public void addJavaDoc(org.eclipse.jdt.core.dom.BodyDeclaration body,
                       ICodeElement element)
Adds JavaDoc to a BodyDeclaration based on the settings of the ICodeElement

Parameters:
body - the BodyDeclaration to add the JavaDoc to
element - the ICodeElement to derive the documentation from

addObject

public void addObject(org.eclipse.jdt.core.dom.Block methodBlock,
                      java.lang.String type,
                      java.lang.String name,
                      java.util.ArrayList<java.lang.String> arglist)
Adds a statement that creates an object. For instance: Object object = new Object(params)


addMethodInvocation

public void addMethodInvocation(org.eclipse.jdt.core.dom.Block methodBlock,
                                java.lang.String objectName,
                                java.lang.String methodName,
                                java.util.ArrayList<java.lang.String> arglist)
Adds a method invocation to the method block

Parameters:
methodBlock - The Block to add the invocation to
objectName - The name of the object on which to invoke the method
methodName - The name of the method to invoke
arglist - The list of arguments for the method call

camelize

public static java.lang.String camelize(java.lang.String name)
Camelizes a name

Parameters:
name - The name to camelize
Returns:
The camelized name

compare

public void compare(org.eclipse.jdt.core.dom.TypeDeclaration node,
                    TagNode tagnode,
                    org.eclipse.core.runtime.MultiStatus status,
                    java.lang.String pattern)
Compares the TagNodes source elements with the given TypeDeclaration and sets the MultiStatus according to the result

Parameters:
node - the TypeDeclaration to compare with
tagnode - the given TagNode
status - the MultiStatus to set
pattern - the currently processed pattern

compare

public void compare(org.eclipse.jdt.core.dom.MethodDeclaration node,
                    TagNode tagnode,
                    org.eclipse.core.runtime.MultiStatus status,
                    java.lang.String pattern)
Compares the TagNodes source elements with the given MethodDeclaration and sets the MultiStatus according to the result

Parameters:
node - the MethodDeclaration to compare with
tagnode - the given TagNode
status - the MultiStatus to set
pattern - the currently processed pattern