net.sf.commonclipse
Class Generator

java.lang.Object
  extended by net.sf.commonclipse.Generator
Direct Known Subclasses:
CompareToGenerator, EqualsGenerator, HashcodeGenerator, ToStringGenerator

public abstract class Generator
extends java.lang.Object

Version:
$Revision: 1.7 $ ($Author: fgiust $)
Author:
fgiust

Constructor Summary
Generator()
           
 
Method Summary
protected abstract  void addImports(org.eclipse.jdt.core.IType type)
          Adds required imports to type.
protected  java.lang.String buildAppenderList(org.eclipse.jdt.core.IType type)
          Iterates on fields and call getFieldString() on any match not in the configurable excluded list.
protected  java.util.Map buildFieldMap(org.eclipse.jdt.core.IType type)
          Returns a Set containing all the names of fields visible by this type.
 int computeIndent(java.lang.String line)
          Returns the indent of the given string.
protected abstract  java.lang.String createMethod(org.eclipse.jdt.core.IType type)
          Creates the method for the ITYPE type.
 void generate(org.eclipse.jdt.core.IType type, org.eclipse.swt.widgets.Shell shell)
          Generates the appropriate method in type.
 void generateMethod(org.eclipse.jdt.core.IType type, org.eclipse.jdt.core.ICompilationUnit cu, org.eclipse.swt.widgets.Shell shell, org.eclipse.core.runtime.IProgressMonitor monitor)
          Generates the method by: call createMethod format the given method add it to type call addImports .
protected abstract  org.eclipse.jdt.core.IMethod getExistingMethod(org.eclipse.jdt.core.IType type)
          Returns the existing method.
protected abstract  java.lang.String getFieldAppender(java.lang.String fieldName, java.lang.String accessor)
          get the "append" statement for a field.
 int getIndentUsed(org.eclipse.jdt.core.IJavaElement elem, org.eclipse.jdt.core.ICompilationUnit cu)
          Evaluates the indention used by a Java element.
protected abstract  java.lang.String getMethodName()
          Returns the generated method name.
protected  boolean isExcluded(java.lang.String fieldName)
          Checks if a given field should be excluded from generated method.
protected  boolean validate(org.eclipse.jdt.core.IType type, org.eclipse.swt.widgets.Shell shell)
          Checks if a corresponding method already exists and prompt the user for replacing it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Generator

public Generator()
Method Detail

generate

public void generate(org.eclipse.jdt.core.IType type,
                     org.eclipse.swt.widgets.Shell shell)
Generates the appropriate method in type.

Parameters:
type - IType
shell - Shell

validate

protected boolean validate(org.eclipse.jdt.core.IType type,
                           org.eclipse.swt.widgets.Shell shell)
Checks if a corresponding method already exists and prompt the user for replacing it.

Parameters:
type - IType
shell - Shell
Returns:
true if the method doesn't exists or the user has choosen to overwrite it

generateMethod

public void generateMethod(org.eclipse.jdt.core.IType type,
                           org.eclipse.jdt.core.ICompilationUnit cu,
                           org.eclipse.swt.widgets.Shell shell,
                           org.eclipse.core.runtime.IProgressMonitor monitor)
                    throws org.eclipse.jdt.core.JavaModelException
Generates the method by: .

Parameters:
type - IType
cu - compilation unit
shell - Shell for messages
monitor - progress monitor, updated during processing
Throws:
org.eclipse.jdt.core.JavaModelException - any exception in method generation

getIndentUsed

public int getIndentUsed(org.eclipse.jdt.core.IJavaElement elem,
                         org.eclipse.jdt.core.ICompilationUnit cu)
                  throws org.eclipse.jdt.core.JavaModelException
Evaluates the indention used by a Java element.

Parameters:
elem - Java element
cu - compilation unit
Returns:
indentation level
Throws:
org.eclipse.jdt.core.JavaModelException - model exception when trying to access source

computeIndent

public int computeIndent(java.lang.String line)
Returns the indent of the given string.

Parameters:
line - the text line
Returns:
indent level

getMethodName

protected abstract java.lang.String getMethodName()
Returns the generated method name.

Returns:
String method name

createMethod

protected abstract java.lang.String createMethod(org.eclipse.jdt.core.IType type)
                                          throws org.eclipse.jdt.core.JavaModelException
Creates the method for the ITYPE type.

Parameters:
type - Itype
Returns:
Method String
Throws:
org.eclipse.jdt.core.JavaModelException - exception in creating method

getExistingMethod

protected abstract org.eclipse.jdt.core.IMethod getExistingMethod(org.eclipse.jdt.core.IType type)
Returns the existing method.

Parameters:
type - IType
Returns:
IMethod

addImports

protected abstract void addImports(org.eclipse.jdt.core.IType type)
                            throws org.eclipse.jdt.core.JavaModelException
Adds required imports to type.

Parameters:
type - IType
Throws:
org.eclipse.jdt.core.JavaModelException - exception in adding imports

buildAppenderList

protected java.lang.String buildAppenderList(org.eclipse.jdt.core.IType type)
                                      throws org.eclipse.jdt.core.JavaModelException
Iterates on fields and call getFieldString() on any match not in the configurable excluded list.

Parameters:
type - IType
Returns:
String
Throws:
org.eclipse.jdt.core.JavaModelException - exception in analyzing fields

buildFieldMap

protected java.util.Map buildFieldMap(org.eclipse.jdt.core.IType type)
                               throws org.eclipse.jdt.core.JavaModelException
Returns a Set containing all the names of fields visible by this type.

Parameters:
type - IType
Returns:
Map containg field names - IField objects
Throws:
org.eclipse.jdt.core.JavaModelException - exception in analyzing type

isExcluded

protected boolean isExcluded(java.lang.String fieldName)
Checks if a given field should be excluded from generated method.

Parameters:
fieldName - field/property name
Returns:
true if the field should not be included in generathed method

getFieldAppender

protected abstract java.lang.String getFieldAppender(java.lang.String fieldName,
                                                     java.lang.String accessor)
get the "append" statement for a field.

Parameters:
fieldName - name of the field
accessor - can be different for fieldname
Returns:
String


Copyright © 2003-2005 sourceforge. All Rights Reserved.