Eclipse JDT
2.1

org.eclipse.jdt.ui
Class CodeGeneration

java.lang.Object
  |
  +--org.eclipse.jdt.ui.CodeGeneration

public class CodeGeneration
extends Object

Class that offers access to the templates contained in the 'code generation' preference page.

Since:
2.1

Method Summary
static String getCompilationUnitContent(ICompilationUnit cu, String typeComment, String typeContent, String lineDelimiter)
          Returns the content for a new compilation unit using the 'new Java file' code template.
static String getMethodBodyContent(ICompilationUnit cu, String declaringTypeName, String methodName, boolean isConstructor, String bodyStatement, String lineDelimiter)
          Returns the content of body for a method or constructor using the method body templates.
static String getMethodComment(ICompilationUnit cu, String declaringTypeName, MethodDeclaration decl, IMethodBinding overridden, String lineDelimiter)
          Returns the comment for a method or constructor using the comment code templates (constructor / method / overriding method).
static String getMethodComment(ICompilationUnit cu, String declaringTypeName, String methodName, String[] paramNames, String[] excTypeSig, String retTypeSig, IMethod overridden, String lineDelimiter)
          Returns the comment for a method or constructor using the comment code templates (constructor / method / overriding method).
static String getMethodComment(IMethod method, IMethod overridden, String lineDelimiter)
          Returns the comment for a method or constructor using the comment code templates (constructor / method / overriding method).
static String getTypeComment(ICompilationUnit cu, String typeQualifiedName, String lineDelimiter)
          Returns the content for a new type comment using the 'typecomment' code template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCompilationUnitContent

public static String getCompilationUnitContent(ICompilationUnit cu,
                                               String typeComment,
                                               String typeContent,
                                               String lineDelimiter)
                                        throws CoreException
Returns the content for a new compilation unit using the 'new Java file' code template.
Parameters:
cu - The compilation to create the source for. The compilation unit does not need to exist.
typeComment - The comment for the type to created. Used when the code template contains a ${typecomment} variable. Can be null if no comment should be added.
typeContent - The code of the type, including type declaration and body.
lineDelimiter - The line delimiter to be used.
Returns:
Returns the new content or null if the template is undefined or empty.
Throws:
CoreException -  

getTypeComment

public static String getTypeComment(ICompilationUnit cu,
                                    String typeQualifiedName,
                                    String lineDelimiter)
                             throws CoreException
Returns the content for a new type comment using the 'typecomment' code template. The returned content is unformatted and is not indented.
Parameters:
cu - The compilation where the type is contained. The compilation unit does not need to exist.
typeQualifiedName - The name of the type to which the comment is added. For inner types the name must be qualified and include the outer types names (dot separated). See IType.getTypeQualifiedName(char).
lineDelimiter - The line delimiter to be used.
Returns:
Returns the new content or null if the code template is undefined or empty. The returned content is unformatted and is not indented.
Throws:
CoreException -  

getMethodComment

public static String getMethodComment(ICompilationUnit cu,
                                      String declaringTypeName,
                                      MethodDeclaration decl,
                                      IMethodBinding overridden,
                                      String lineDelimiter)
                               throws CoreException
Returns the comment for a method or constructor using the comment code templates (constructor / method / overriding method). null is returned if the template is empty.
Parameters:
cu - The compilation unit to which the method belongs. The compilation unit does not need to exist.
declaringTypeName - Name of the type to which the method belongs. For inner types the name must be qualified and include the outer types names (dot separated). See IType.getTypeQualifiedName(char)
decl - The MethodDeclaration AST node that will be added as new method. The node does not need to exist in an AST (no parent needed) and does not need to resolve. See AST.newMethodDeclaration() fo how to create such a node.
overridden - The binding of the method that will be overridden by the created method or null if no method is overridden.
lineDelimiter - The line delimiter to be used.
Returns:
Returns the generated method comment or null if the code template is empty. The returned content is unformatted and not indented (formatting required).
Throws:
CoreException -  

getMethodComment

public static String getMethodComment(ICompilationUnit cu,
                                      String declaringTypeName,
                                      String methodName,
                                      String[] paramNames,
                                      String[] excTypeSig,
                                      String retTypeSig,
                                      IMethod overridden,
                                      String lineDelimiter)
                               throws CoreException
Returns the comment for a method or constructor using the comment code templates (constructor / method / overriding method). null is returned if the template is empty.

The returned string is unformatted and not indented.

Exception types and return type are in signature notation. e.g. a source method declared as public void foo(String text, int length) would return the array {"QString;","I"} as parameter types. See Signature

Parameters:
cu - The compilation unit to which the method belongs. The compilation unit does not need to exist.
declaringTypeName - Name of the type to which the method belongs. For inner types the name must be qualified and include the outer types names (dot separated).
methodName - Name of the method.
paramNames - Names of the parameters for the method.
excTypeSig - Throwns exceptions (Signature notation)
retTypeSig - Return type (Signature notation) or null for constructors.
overridden - The method that will be overridden by the created method or null for non-overriding methods. If not null, the method must exist.
lineDelimiter - The line delimiter to be used
Returns:
Returns the constructed comment or null if the comment code template is empty. The returned content is unformatted and not indented (formatting required).
Throws:
CoreException -  

getMethodComment

public static String getMethodComment(IMethod method,
                                      IMethod overridden,
                                      String lineDelimiter)
                               throws CoreException
Returns the comment for a method or constructor using the comment code templates (constructor / method / overriding method). null is returned if the template is empty.

The returned string is unformatted and not indented.

Parameters:
method - The method to be documented. The method must exist.
overridden - The method that will be overridden by the created method or null for non-overriding methods. If not null, the method must exist.
lineDelimiter - The line delimiter to be used
Returns:
String Returns the constructed comment or null if the comment code template is empty. The returned string is unformatted and and has no indent (formatting required).
Throws:
CoreException -  

getMethodBodyContent

public static String getMethodBodyContent(ICompilationUnit cu,
                                          String declaringTypeName,
                                          String methodName,
                                          boolean isConstructor,
                                          String bodyStatement,
                                          String lineDelimiter)
                                   throws CoreException
Returns the content of body for a method or constructor using the method body templates. null is returned if the template is empty.

The returned string is unformatted and not indented.

Parameters:
cu - The compilation unit to which the method belongs. The compilation unit does not need to exist.
declaringTypeName - Name of the type to which the method belongs. For inner types the name must be qualified and include the outer types names (dot separated).
methodName - Name of the method.
isConstructor - Defines if the created body is for a constructor
bodyStatement - The code to be entered at the place of the variable ${body_statement}.
Returns:
String Returns the constructed body contnet or null if the comment code template is empty. The returned string is unformatted and and has no indent (formatting required).
Throws:
CoreException -  

Eclipse JDT
2.1

Copyright (c) IBM Corp. and others 2000, 2003. All Rights Reserved.