Bookmark and Share


TEMPLATES

This part of the documentation explains the fastcode templates. This templates differs from eclipse code templates. With fastcode templates, one can select multiple fields in a class/multiple classes from a package/multiple files from a folder and can create generated code easily to configure velocity templates. One can also add new templates. Various kind of code snippets can be created with this plugin. The plugin comes with some built-in templates.

  • The templates can be invoked with the following steps:

Navigate to an appropriate file. For example, if one wants to create jsp form elements, one needs to be in a jsp file or if one needs to create a spring bean definition one needs to be in a spring configuration file or if one needs to create an instance of a class one needs to be in a java file.

Before selecting the menu, one needs to first check the Templates Preference page, by default the values will be set as shown and one can find how to set the values with detailed descriptions.

One can modify the templates as required by going into Templates Preference Page.

One can export templates. We can add new templates or update the templates and import the changes done.

Select appropriate template by using shortcut key Ctrl-Alt-Shift-T.

Alternatively, one can go to Fast Code ->Templates at the top and select appropriate template.

For example: if one selects the template "Create Instance of Class", a create snippet dialog is shown where one can select the class name whose instance needs to be created. The instance will be created at the point where the cursor is located in a java file. Here java file is where the template is invoked from.

The list of sample templates are created as demo which illustrates the usage of templates.

Please see different types of snippets available in fastcode templates.

One can setup a standard J2EE Base environment using J2EEBase Templates to develop web-based applications.

One can configure some basic template features by going to Windows -> Preference ->Fast Code -->Templates as shown in Templates preference dialog:

templateprefembeddedfeilds

Basic template features can be set in Templates Preference page as follows:

Show child Fields: One can set to view child (parent-child hierarchy) fields in Template page of the classes either in flat or hierarchical view while creating snippets as shown below. If the project is not included in Include Package option then the child fields will not be shown.

In the below sample, Person is a class with 8 fields and the fields "address" and "salary" are instance of another class com.test.address and com.test.salary, the field selection view displays the fields of the class com.test.Person and also the fields of the class com.test.address and com.test.salary in the hierarchical and flat view as shown below:

  FLAT VIEW                                                                                     HIERARCHICAL VIEW

Flat view            hierarchical view

Include Package: One can add list of packages from which fields need to be extracted in "Include package" option. The fields of the classes are extracted only if package is included in Template Page, If the classes are not within the included package, then the fields will not be displayed for a class.

Exclude Package: One can exclude list of packages using exclude package option in template page. The fields in the class present within these packages will be excluded.

In the above sample, Salary class has a field "company" which is instance of another class " test.company" and package "test" is set in exclude package list as shown in template preference page, then the fields of company class will not be displayed.

Strictly maintain getter/setter: Some of the templates display fields from a class. Among the fields listed there can be fields which have getter/setter and those which dont have. In case user chooses a field that does not have getter/setter, but the template chosen needs the field to have getter/setter, then such fields will be skipped. In order to handle such scenario, there is an option provided in Template page as Striclty maintain getter/setter, If this check box is selected, then only fields with getter/setter are displayed. In case user want all the fields to be shown irrespective of whether it has getter/setter, then they can always un-check this field in the Template page.

Delimiter for File Template : One can set the delimiter value for File templates in Templates page. This delimiter value will be used while generating code snippets with delimited data for text files.

Template Preferences:

One can update the templates by going to Windows--> Preferences-->Fast Code-->Templates-->Templates. One can enable or disable any template from templates preference page, but to modify or insert a new template, one has to update the templates-config.xml file. One can however export the templates by using Export. Once the template file is in place, one can update the templates and then import the updated template using Import. The Templates preference dialog is shown below:

templates

One can view the templates in detail by selecting the template and clicking on Edit option in preference page as shown:

templates

Detailed description of the templates preference page are as follows:

Variations: Variations can be left completely blank. In that case, only one kind of template will be possible. One can put special characters like "\n", "\t", "t" in the template body. It may be useful to build the string by template using set command in velocity rather than straight macro. One can study the template provided for toString as an example.

Allowed File names: This option is used to set which type of files one needs to create. For eg: if it is *.java then the template is allowed only for java files. Similarly, one can also set multiple variations for a template by checking Allow Multiple Variation option.

First Template Item : This option denotes that a template is based on a class, file, package or folder selection. Based on these options, the second item options will be selected. The preference page allows only valid options to be selected specific to each template. One cannot select invalid options, if it is invalid option, then it prints a message what needs to be selected for each option.

Number Required Items: This option denotes the number of fields needed from one class for a template.

Second Template Item : This option is used to select methods, fields, class or file based on class to create a code snippet.

If one selects Class in first item, then one can select either Method, Field or custom option for a class in second template item. Similarly, if the first item is File, then none of these options will be selected. For example. if one needs to just print the resource bundle, then only file can be selected. If it is a Package, then second item will be a Class or none. If the option is Folder, then the second item should be File or none. One can find available list of first and second template items below.

Required Getter Setter: One can set getter/setter both, just getter or setter or none this will be set for variables created while creating a code snippet.

Additional Parameters: Additional parameters are extra variables that can be injected into a template. One can inject an arbitrary number of parameters which can be a string, class, file, package and folder which are seperated by a space. These additional parameters are made optional.

For example: If we put additional parameters as myvar myclass:class myfile:file mypackage:package myfolder:folder, where myvar is a simple string, myclass is placeholder that contains the class, myfile is the file and mypackage is the package and myfolder is the folder. One can see these parameters in additional parameters dialog as shown below:

additionalparameter

On click of myclass browse button, a class selection dialog is shown where one can select the class as shown. In the same way, using browse button one can select the file, package and folder.

additionalparameter

Similarly, another example is shown for template "Create Static String Field And Import". One can add additional parameter as targetClass:class fieldName value which are seperated by a space. Additional parameters comes as an extra dialog while creating snippets.

additionalparameter

The template shown below is defined in templates-config.xml file.

additionalparameterThe static string field for the above example. is created as shown:

import static com.test.Person.FIRSTNAME;
public class Car {
	public static final String FIRSTNAME = "xyz";
}

Template body : The most important item is the template body which is a velocity template. Also useful is the variation which can be used to generate various kind of templates. If there are variations present, it is expected that the template body can have branching condition as shown below:

	// Creating new instance of ${class.name}
	final ${class.name} ${class.defaultInstance} = new ${class.name}();
	#foreach ($field in ${fields})
		${class.defaultInstance}.${field.setter}(${field.value});
	#end

A default placeholder is created to hold the variation and it is _template_variation. As one can see, one can check against various values for this variable. Name of this variation variable is configurable. In the fast-code.properties file in the jar file there is a property called default.template.variation.field.name which can be changed to any other value. Typically, one does not need to do that.

Special variables are always available as enclosing_file and enclosing_class for example ${enclosing_class.name} and ${enclosing_file.name}.

All the built in templates can be viewed or downloaded from template list.

The template can be a arbitrary velocity template with the following place holders :

Place Holders
Options
Example
                class
${class.name}

Person

${class.fullyQualifiedName}

com.test.Person

${class.defaultInstance}

person

${class.defaultConstructor}

true/false

${class.package.name}

com.test

                classes
${classes}

Array (which holds list of classes)

                from_class
${from_class}

Person

                to_class
${to_class}

Car

                fields
${fields}

Array (which holds list of fields)

                field
${field.name}

firstName

${field.setter}

setFirstName

${field.getter}

getFirstName

${field.value}

""

${field.nameAsWord}

First Name

${field.type.name}

String

${field.fullName}

firstName

                instance
${instance}

person

                target class
${targetClass.fullyQualifiedName}

com.test.Person

                file
${file.name}

Person.jsp

${file.fullName}

Web-INF/jsp/Person.jsp

                folder
${folder.fullPath}

sample/Web-INF/jsp/

${folder.name}

Web-INF/jsp/

                class header
${class_header}

/* * This class has been generated by Fast Code Eclipse Plugin

* For more information please go to http://fast-code.sourceforge.net/

* @author : ${user}

* Created : ${today}

*/

                package
${package.name}

com.test

${package.javaProject}

sample

                project
${project.name}

sample

                modifier
${modifier}

final

 

Detailed description for place holders are as follows:

  • class: class has several attributes like:
  •       ${class.name} is the name of class selected.
  •       ${class.fullyQualifiedName} is the name of fully qualified class name.
  •       ${from_class} and ${to_class} are two classes which are needed in dozer mapping file or copy between two classes.
  •       ${class.defaultInstance} is the default instance which will have the class name in lower case.
  •       ${class.defaultConstructor} is the default constructor.
  •       ${class.package.name} is the package name of the class.
  • ${from_class} is used to hold class as "from class" which is needed in dozer mapping file or copy between two classes.
  • ${to_class} is used to hold class as "to class" which is needed in dozer mapping file or copy between two classes.
  • ${fields} is list of fields selected where each element can be accessed as ${field}.
  • field: fields has several attributes like:
  •       ${field} is the type of the element within ${fields}. Each has the attributes name, fullName, value, getter, setter, type.
  •       ${field.name} is the name of the field. For example: if a class has a field named x and which has field named y then ${field.name}.
  •       ${field.nameAsWord} is a computed attribute which converts the name to a word, example: firstName will become First Name.
    •       ${field.value} is used to hold the value of the field. It will be the default value based on the datatype of the field. For example: Field is a Srting then the ${field.value} will be "".
  •       ${field.getter} used to hold the getter method of the field. For example: if a class has a field named x then getX is present in ${field.getter}.
  •       ${field.setter} used to hold the setter method of the field. For example: if a class has a field named x then setX is present in ${field.setter}.
  •       ${field.type.name} is a computed attribute which holds the datatype for a field like String, int, etc.
  •       ${field.fullName} is the full name of the field. For example: if a class has a field named x and which has field named y, then fullName will be will be x.y.
  •          This is only relevant if x is a composite object i.e. not a simple field like String or int. When it is expected to have one field, then a variable named field will be          available as ${field}. All private fields will be available unless it is configured to exclude certain fields. To do so, one needs to modify the property
  •          exclude.fields.from.snippets in fast-code.properties file in the plugin jar file. A line containing the property item is already there, one just needs to uncomment          it and put appropriate value. Typically, there are fields like createUser, updateUser, etc which are typically not needed in jsp or java files. This will reduce quite          bit of clutter.
  • File: File has attributes as follows:
  •       ${files} is list of files selected where each file can be accessed as ${file}.
  •       ${file} is the type of the element within ${files}. ${file.name} ${file.fullName},${file.extention}
  • Folder: Folder variable is used to specify the folder. One can use ${folder.fullPath}, ${folder.name} to get the attributes of the folder.
  • Instance: ${instance} is the value of instance in the create snippet dialog and one can change the instance name as required.
  • Class Header: ${class_header} is the placeholder which holds the header information for a class like who generated the class, class created date/time, and so. One can edit the class header information by going into Windows -> Preferences ->Fast Code.
  • Package: Package is the placeholder used to specify the package. The attributes ${package.name}, ${package.javaProject} are used to get the package name and the project within that package.
  • Project: Package is the placeholder used to specify the project. The attribute ${project.name} is used to get the project name.
  • Target class: Used to hold the fully qualified class name.
  • Modifier: is the placeholder used to hold the access modifiers like public, private, etc.

     

  • List of first and second template items and available place holders:
  • First Template Item
    Second Template Item
    Place Holders
     class  field  ${class}
     ${fields}
     class  method  ${class}
     ${method}
     class

     custom

     ${class}
     ${field}
     file  none  ${files}
     folder

     file

     ${file}
     ${folder}
     folder  none  ${folder}
     package  class  ${class}
     ${package}
     package  none  ${package}
     none  none  ${module}
     ${project}, etc
     (It can vary,one can specify in additional parameters as required)
     enum   field  ${enum}
     ${fields}

 

In templates, we now have some special tags:

Special Tags
Attributes
Content
Usage
 FC import  NA  Fully qualified class

 <fc:import>
 ${field.type.fullyQualifiedName}
 </fc:import>

 FC method  name (method name)
 target (optional)

 Complete source body
 fc:import

 <fc:method name="create${class.name}"  target="${targetClass.fullyQualifiedName}">
 /* Complete Source body */
 <fc:import>${field.type.fullyQualifiedName}</fc:import>
 </fc:method>

 FC class

 type (class or interface type)
 name (classname)
 package (packagename)
 project (optional)

 Complete source body  <fc:class type="class" name="${className}"  package="${package.name}" project="${package.javaProject}">
 /* Complete Source body */
 </fc:class>
 FC field  name (field name)  Complete code for field  <fc:field name="${class.defaultInstance}">
 /* complete code for field */
 </fc:field>
 FC file

 dir (file dir)

 name (file name)

 File Content  <fc:file dir="folder.fullpath" name="fileName">
 /* File content */
 </fc:file>
 FC xml

 parent (entity)
 node (named-query)
 target (optional)

 Complete source body  <fc:xml parent="entity-mappings" node=" named-query"  target="${target}">
 /* Complete Source body */
 </fc:xml>
 FC message  title (message title)  Message Body  <fc:message title="title">
 /* message body */
 </fc:message>
 FC exit  NA  NA  <fc:exit></fc:exit>

 

FC import: Fc:import tag can be used to import a class into the enclosing java class. The target is fully qualified class. Fc:import can be used within <fc:method> tag.

	${field.type.fullyQualifiedName}
                            

Example: One can create fc:import tags as shown below:

	org.apache.log4j.Logger
                            

FC method: Fc:method is used to create a method within the enclosing java class. For fc:method, name(method name) is mandatory and if target is present then the method will be created in target class else the method is created from where the template is invoked. So target is optional. Fc:import tag can be used within the fc:method tag.

	 // method name is mandatory and target is optional 
		/*
	 	* Complete Source body
	 	*
		*/
	com.test.util.PersonUtil#method name		
    

FC class: FC class is used to create a class for a given package and project selected. The type can be class/interface/innerclass/test. An innerclass type is used to create innerclass within the class from where one is working with. The type attribute test is used to create test class in default test path "src/test/java" which is set in FastCode Preference page.

One can also add optional attribute in fc:class tag. If optional is set to "true" for a class, then user can decide in the runtime, if they want the particular class to be created or not. If they want it to be created, they can select it in the action selection dialog, else they can ignore it.

	
	// class type can be class, interface, test or innerclass. Name and package are mandatory.  Project is optional.
		/*
 		* Complete Source body
 		*
 		*/
	

FC field: Fc:field tag is used to create a field within the enclosing java class.

	 /*here field name is mandatory for one to create a field*/
		/*
	    *complete code for field
	    */
	

Example: Logger field can be created using fc:field name tags while printing a class:

	private static final Logger logger = Logger.getLogger(${enclosing_class.name}.class);
                            
FC file: FC file tag is used to create a file in the specified dir and one can specify file name, full source path, file description to create a file within the enclosing java class.

	
		// file is full folder path. Here both dir and filenames are mandatory.
		/*
 		* File content
 		*
 		*/
	
                            

FC xml: FC xml tag is used to generate an xml files for a given entity in specified target.

	
		/*parent is the entity-mappings, node is the named-query and target is the xml file */
	  	/*
 	  	* Complete Source body
 	  	*
 	  	*/
   

FC message: FC message tag is used to create a message within the enclosing java class.

	
 		/*
		*message body
		*/
	 
	 

FC exit: FC exit tag can be used to exit within an enclosing java class.


                            

 

Snippets: A snippet files can be created using fastcode plugin which provides easy way to implement commonly used code. Just type Ctrl-Alt-Shift-T and select appropriate templates or by going into Fast Code ->Templates.

One can create the following types of snippets:

Class/Field Based Templates

Class/Method Based Templates

File Based Templates

Package Based Templates

Folder Based Templates

Enum Based Templates

Create instance of a class Create snippet from method Create New simple Snippet with File Create Intances of classes Create File and Include Create Switch case with the selected Enum
Extract fields from a class into variables Delegate Method Print Resource Bundle Create Impl Multiple Files Create if-else-if block with the selected Enum
Print fields of a class Override Methods Include Files Create Multiple class Create File with Selected Content  
Create instance of a class as method Json from class as file Create Multiple interfaces  
Create to String method Spring Bean as File Create Multiple abstract classes  
Copy class as method   Create Value Annotation Create Multiple exception classes

 

 
Create a spring bean     Create Multiple Runtime exception classes

 

 
Create a JSF managed bean     Copy Classes

 

 
Create dozer mapping between two classes     Create Instance of generic Dao

 

 
Json from Class     Create Servlet

 

 
Create Struts validation     Spring Bean of Multiple Classes

 

 
Create instance of a class web     Test Suites  
Simple Class Snippet      
Create Struts validation      
Create instance of a class web      
Create Struts validation      
Export/Import Templates    

 

 
Create New Resource Bundle    

 

 
Create HQL          
Create if-else-if block with Constants          
Create switch case with Constants          
Create Comparator Class          
Create Resource Bundle as File          
Converter Class          
Create Field and Constructor          

  

CREATE INSTANCE OF A CLASS                         

One can create an instance of a java bean. To select create instance of class one can click the menu or type Ctl-Alt-Shift-T which will show create snippet dialog menu. To appreciate the use of it, let us consider a case where one has to create an instance of a java bean with some twenty fields as shown below.

The Person fields can be selected using the field selection dialog as shown:

Below sample shows the snippet code generated:


	public void someMethod() {
		// following instance of PersonVo can be created with the plugin
		// Creating new instance of Person
		final Person person = new Person();
		person.setBirthDate(null);
		person.setFirstName(null);
		person.setGender(null);
		person.setLastName(null);
		person.setPersonId(0);
		person.setTitle(null);
		// so on with twenty other fields.
	}

 

EXTRACT FIELDS OF A CLASS

One can extract fields of class as well. To do this, please select extract fields of a class from the menu or by typing Ctl-Alt-Shift-T and select extract fields of a class option. As before, if you select a class Person, it will create a snippet as shown below:

	// plugin can create the following lines to extract fields out of person
	final String firstName = person.getFirstName();
	final String lastName = person.getLastName();
	final Date birthDate = person.getBirthDate();
	final String gender = person.getGender();
	final Integer personId = person.getPersonId();
	final Car car = person.getCar();
	final String color = person.getCar().getColor();
	final String model = person.getCar().getModel();
	final String fuel = person.getCar().getFuel();
	final String engineno = person.getCar().getEngineNo();

As one can see it will extract the fields from the class through their getter methods and assign the type of it automatically.

CREATE INSTANCE OF A CLASS AS METHOD

One can also create an instance of a class as method.

This template shows how an fc tag can be used to create a method:

	
	${class.fullyQualifiedName}
	// It will create a method in target file PersonUtil 
	/**
	* This will create an instance of ${class.name}
	*
	#foreach ($field in ${fields})
	* @parm ${field.type}
	#end
	* @return
	*
	*/
	public static ${class.name} create${class.name}
	(#foreach ($field in ${fields}) ${field.type} ${field.name}
		#if (${velocityCount} < ${fields.size()}),#end #end) {
	final ${class.name} ${class.defaultInstance} = new ${class.name}();
	#foreach ($field in ${fields})
		${field.type.fullyQualifiedName}
		${class.defaultInstance}.${field.setter}(${field.name});
	#end
	return ${class.defaultInstance};
	}
	

Further variations can be used to this template to enhance fc:method tag

 

This plugin makes it very easy to generate codes like this. To invoke one can either go to the top menu and select appropriate template or type Ctl-Alt-Shift-T and select instance of class template type. This option allows one to create code snippets to create an instance of a class with setters with multiple fields from the class. It will first open the type dialog (same dialog as you get with Ctl-Shift-T in eclipse) and once one selects a java bean class, it will prompt one with the fields within the class as shown below. Once one selects the fields it will able to generate code snippet as shown above. It is also possible to generate instance using the builder pattern as described by Martin Fowler. The details is not described here. It has been very well explained in this blog.

The velocity template that is needed for the snippet is shown below as an example. For the subsequent snippet types the velocity macro will not be shown but one can always see it in the configuration.

	// ## Warning this is a velocity template 
	// ## So Do not include '//' at the begining of lines  
	// ## One can keep the ## which is a comment in velocity.
	// ## This line below will create the instance of the class.
	final ${class_name} ${instance} = new ${class_name}();
	// ## The loop below will iterate through the fields selected and 
	// ## put the corresponding setter methods.
	#foreach (${field} in ${fields})
		${instance}.${field.setter}(null);
	#end

The PersonUtil fields can be selected using the field selection dialog as shown:

Once fields are selected for a class, one can specifiy the targetclass to create instance of a class as method which comes as an additional parameters as shown:

In Selection dialog, one can select the elements from the tree like the imports, method to be created in a class.

instance of class method

The below snippet is generated for class PersonUtil in target class StringUtil.
import com.test.util.PersonUtil;
import java.util.Date;
import static com.test.util.StringUtil.createPersonUtil;

public class StringUtil {

	/**
	 * This will create an instance of PersonUtil
	 * 
	 * @parm Date
	 * @parm String
	 * @parm String
	 * @parm String
	 * @parm Integer
	 * @return
	 * 
	 */
	public static PersonUtil createPersonUtil(final Date birthDate,
			final String firstName, final String gender, final String lastName,
			final Integer personId) {
		final PersonUtil personUtil = new PersonUtil();
		personUtil.setBirthDate(birthDate);
		personUtil.setFirstName(firstName);
		personUtil.setGender(gender);
		personUtil.setLastName(lastName);
		personUtil.setPersonId(personId);
		return personUtil;
	}

	PersonUtil personUtil = createPersonUtil(null, "", "", "", 0);
}
PRINT FIELDS OF A CLASS

One example of a template is the print fields of a class. To use it, just type Ctl-Alt-Shift-T from inside any method of a class. A dialog box as shown will appear and choose Print fields of Class from there. One can select any one of the variations.

For example, logger.debug variation is selected for a Person Class. Once variations and class is selected, a fields selection dialog appears as shown:

print_fields_of_class

print_fields_of_class1

In Create snippet dialog, If "Include local variables" option is selected, a variable selection dialog is shown where one can select the local variable within the method for printing as shown below:

print_fields_of_class1

One can select a few fields from there and it will generate the following code:

 if (logger.isDebugEnabled()) {
    logger.debug("Address Line1 {}" , address.getAddressLine1());
    logger.debug("Address Line2 {}" , address.getAddressLine2());
    logger.debug("State {}" , address.getState());
    logger.debug("Country {}" , address.getCountry());
    logger.debug("Zipcode {}" , address.getZipcode());
    logger.debug("City {}" , address.getCity());
    logger.debug("City Name {}" , address.getCity().getCityName());
    logger.debug("p1 {} ", p1) ; //local variables is printed here	
    logger.debug("p2 {} ", p2) ;
    } 

One can include tags fc:import and fc:field name while printing a logger class and logger field as shown below:

	org.apache.log4j.Logger
    private static final Logger logger = Logger.getLogger(${enclosing_class.name}.class);

As one can see it can convert the field names to english words such as firstName to First Name, dateOfBirth to Date Of Birth, etc. This is also useful in generating the toString method. The built-in toString generator in eclipse will only print the field name as it is.

PRINT FIELDS OF A CLASS IN A JSP

Printing fields in a jsp or xhtml can be very painstaking. This plugin makes this easy as well. For this one needs to select the Print Fields of Class Web option.

<!-- The following jsp snippet can be generated by the plugin -->
 
<table align="center" >
	<tr>
		<td align="right" align="top"> 
			<bean:message bundle="personVo" key="firstName"/> : 
		</td> 
		<td align="right" valign="top">
			<html:text name="personVo" property="firstName" size="10"/>
		</td>
	</tr>
	<tr>  
		<td align="right" valign="top">
			<bean:message bundle="personVo" key="lastName"/> : 
		</td>
		<td align="right" valign="top">
			<html:text name="personVo" property="lastName" size="10"/> 
		</td>
	</tr>
</table>
 

Now to generate the display element for another field which will be different type, (example, title which will be a select box) one needs to invoke Print Fields of Class Web Single option. To repeat the process for several fields, one can use the Last Snippet Action from the Fast Code menu from top or better yet use Ctl-Alt-Shift-L shortcut. The snippet is generated in html table format, one can change it to other format if one wishes. The label has been generated with standard <bean:message> tag. If one likes, one can use the more direct way : <td align="right" valign="top">${field.makeWord()} : </td>. By default struts tags and jsf tags are provided. One remove the some of them or add new ones.

TO STRING METHOD

One example of a template is to create a string method of a class. To use it, just type Ctl-Alt-Shift-T from inside any mehtod of a class. A dialog box as shown will appear and choose ToString Method from there.

 

It converts the methods in a java file into string for the methods selected as shown in below sample:

	/**
	 * toString method for Car
	 *
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
	    final StringBuilder sb = new StringBuilder();
	
	 sb.append("Color :  " + this.color == null ? "" :  this.color  + ",");
	 sb.append("Model :  " + this.model == null ? "" :  this.model  + ",");
	 sb.append("Fuel :  " + this.fuel == null ? "" :  this.fuel  + ",");
	 sb.append("Engine No :  " + this.engineNo == null ? "" :  this.engineNo  + ","); 
	 return "Car [" + sb.toString() + "]";
	}						
CREATE INSTANCE OF A CLASS WEB

This plugin can create instance of class in a file in the web tier for example jsp, js files etc. If one select PersonVo as the class it can create a snippet as show below which are usually useful in a javasctipt fiels to make ajax calls with frameworks such as DWR.

	var personVo =  new  Object();
	personVo.firstName = firstname;
	personVo.lastName = lastname;
	personVo.title = title;
	personVo.dateOfBirth = dateOfBirth;
	// so on with more fields

If one selects jsp:useBean as the variation, it will create the following snippet:

 	<jsp:useBean id="personVo" scope="page" class="com.test.vo.PersonVo">
		<jsp:setProperty name="personVo" property="firstName" value=""/> 
		<jsp:setProperty name="personVo" property="lastName" value="" /> 
		<jsp:setProperty name="personVo" property="title" value="" /> 
		<jsp:setProperty name="personVo" property="dateOfBirth" value="" /> 
	</jsp:useBean>

It can form elements with fields of a class in the ExtJs format as well. The following snippet will be produced if you select all the fields from the PersonVo class as before.

	{
		xtype : 'textfield',
		fieldLabel : 'First Name',
		name : 'firstName'
	},   {
		xtype : 'textfield',
		fieldLabel : 'Last Name', 
		name : 'lastName'
	},   {
		xtype : 'datefield',
		fieldLabel : 'Date Of Birth,
		name : 'dateOfBirth'
	} // so on with more fields 
 
SIMPLE CLASS SNIPPET

Sometimes, one just needs to create simple snippets of a class. Using this menu, one can easily create a code template to create a class snippet like below. To do this, just use shortcut Ctrl-Alt-Shift-Y. Once invoked, it will show the below snippet dialog. A class snippet will be created when appropriate template variations and class is selected.

 

If one selects template variation "class-name" as the variation, it will create a simple snippet for the class-name provided in snippet dialog. Similarly, for variation "fully-qualified-class-name", it creates snippet with the fully qualified class name as "com.test.Person".

If one selects template variation "field-name", it will create a snippet for the fields of a class. A field selection dialog is shown where one can select the field of the class. The user can select a single field and it will place the full name of the field at the point where the cursor is located. Similary the user can create code templates for other kinds of fields, example: html:radio, html:select, html:checkbox, etc.

One can select a single method of a class using template variation "method-name". When method is selected using method selection dialog, it will place the full name of the method at the point where the cursor is located.

One can get all the Jsp code templates for struts and other web frameworks from Template List.

<!-- One can generate the familiar html:text with a regular code templates in eclipse. Then use the plugin to fill in the value for the property attribute--> <html:text size="10" name="myFormBean" property="${cursor}" maxlength="10"/>

// It is not just the form elements in jsp, it can easily create see tag in javadocs as 
// shown below.
 
/**
 *
 * @see com.abc.test.class
 */
		
		
		<listener>
			<listener-class>  
				org.springframework.web.context.ContextLoaderListener
			</listener-class>
		</listener>
 
		
		
		
		
	    <action path="/somepath" type="com.abc.web.action.SomeAction" name="someBean" scope="request">
		</action>
 
SIMPLE SNIPPET WITH FILE

Similarly, simple snippets are provided with files. WIth his option one can easilly create classpath elements. A direct shortcut is available for this as well and it is Ctrl-Alt-Shift-Z. To use this, just type Ctrl-Alt-Shift-Z, a file dialog will come up, when the user selects a file, it will put the file name or path in the editor. This feature can be used wherever a file name is needed and where the ide does not provide auto complete. Examples can be generating context-param in web.xml, or placing javascript file in a jsp, or putting a jsp file inside <jsp:include />, etc.

The template body for action is ${file.name}.

		
		<context-param>
		<param-name>contextConfigLocation</param-name>
			<param-value>
				/WEB-INF/classes/foo-service.xml    
				/WEB-INF/classes/bar-service.xml
			</param-value>
		</context-param>		
	
	
	<SCRIPT type= "text/javascript"src="/scripts/foo.js"></SCRIPT>  
	
	
	<jsp:include page="some.jsp" />
	
	<beans>
		<import resource="resources/someresource.xml"/>
	</beans>
 
CREATE RESOURCE BUNDLE

One can also create resource bundle for the fields of a class. For this one has to be in the properties file and execute the create resource bundle option. The below example creates resource bundle for fields of Person class.

# Resource Bundle for com.test.Person 

MY_RESOURCES.personId = Person Id 
MY_RESOURCES.firstName = First Name
MY_RESOURCES.lastName = Last Name
MY_RESOURCES.birthDate = Birth Date

CREATE RESOURCE BUNDLE AS FILE

Similarly, one can also create resource bundle for the fields of a class as a file. One can invoke this menu in any type of file and execute the create resource bundle as file option. To do this, just use shortcut Ctrl-Alt-Shift-T. Once invoked, it will show the snippet dialog where one can select the class to create resource bundle.

One can specify the folder, fileName and prefix in additional parameters to create the resource bundle. The file Person.properties file is created.

The resource bundle for fields of Person class is created in Person.properties file as shown:

# Resource Bundle for com.test.Person 

MY_RESOURCES.personId = Person Id 
MY_RESOURCES.firstName = First Name
MY_RESOURCES.lastName = Last Name
MY_RESOURCES.birthDate = Birth Date

PRINT RESOURCE BUNDLE

One can print a key from resource bundle without switching to the resource file. This is very convenient as one can see and use the key from the specified resource bundle from a jsp file. To do this, just select the print resource bundle option and select the resource file from the file selection dialog. It will then show the list keys contained in the file. For convenience, keys are shown first the key = value is shown. This helps to search for the key one wants.

	
	<bean:message bundle="somebundle" key="label.property"/>
 
COPY CLASS

Sometime one wants to write a copy method which will copy the properties of one java bean to another. This plugin helps one do that also easily. Unlike other template options, this will require two classes for obvious reason. If the two classes and the fields have been selected it will create the following method:

	 /**
	  * This method copies fields from PersonVo to PersonDto
	  * @param personVo
	  * @param personDto
	  *
	  */
	  public void copyPersonVoToPersonDto(final PersonVo personVo, final PersonDto personDto) {
	 
		personDto.setFirstName(personVo.getFirstName());
		personDto.setLastName(personVo.getLastName());
		personDto.setTitle(personVo.getTitle());
		personDto.setDateOfBirth(personVo.getDateOfBirth()); 
		// and so on with twenty other fields.
	  }

The field selection dialog will come once as it expect the field name in one class will be the same in the other class. If one wants to copy fields with different name example, field foo in PersonVo to field bar in PersonDto one needs to select the Copy Class Single option which will show two field selection dialogs, one for the from_class and the other one for the to_class.

DOZER MAPPING BETWEEN CLASSES

Dozer mapping can be created easily between two classes. Two classes are required for this option and one needs to be in the dozer mapping file before executing this option. Once the two classes have been selected, it will open the field selection dialog once with fields which are same in both classes. To map fields of different name one needs to select dozer mapping single option where two fields selection dialog will open and one can select the from_field first and the to_field next. An example of the mapping generated is shown below.

	<mapping>
		<class-a>com.test.vo.PersonVo<class-a> 
		<class-b>com.test.dto.PersonDto<class-b> 
			<field> 
				<a>firstName</a> 
				<b>firstName</b> 
			</field>
			<field> 
				<a>lastName</a> 
				<b>lasttName</b> 
			<field>
	<mapping> 
 
STRUTS VALIDATION

One can create struts validation snippets as well. If one selects PersonForm class and the firstName and lastName property, a validaion snippet will be generated if validation types of required, minlength and maxlength are chosen as shown below.

Unlike other templates this one lets one choose multiple variations. To have this feature, one needs to check the allow multiple variation checkbox in the configuration. To make it work, one needs to be in the validation file and place the cursor at appropriate place.

	<form name="personForm">
		<field property="firstName" depends="required, minlength, maxlength">
	
			<arg1 name="minlength" key="${var:minlength}" resource="false"/> 
			<arg1 name="maxlength" key="${var:maxlength}" resource="false" />
			<var>
				<var-name>minlength</var-name>
				<var-value>1</var-value>
			</var>
			<var>
				<var-name>maxlength</var-name>
				<var-value>10</var-value>
			</var>
		</field> 
		<field property="lastName" depends="required, minlength, maxlength">
			<arg1 name="minlength" key="${var:minlength}" resource="false" /> 
			<arg1 name="maxlength" key="${var:maxlength}" resource="false" />
			<var>
				<var-name>minlength</var-name>
				<var-value>1</var-value>
			</var>
			<var>
				<var-name>maxlength</var-name>
				<var-value>10</var-value>
			</var>
		</field>
	</form>

One still needs to change the values of var-name minlength and maxlength according to one's requirement, but one can see that it generated a chunk of code. Also notice that it does not create the <formset> tag or the <form-validation> tag. One needs to create them manually or by some other code templates.

If one needs to create validation snippet for another field with different type (example: dateOfBirth which will have validation type date), one should invoke the Struts Validation Single option as shown above. For this also one needs to place the cursor on an empty line after the last element and execute this option with appropriate field name and validation type. If one needs to create the validation snippet repeatedly for many fields, one can invoke the Last Snippet Action or by using keyboard shortcuts (Ctl-Alt-Shift-L). This saves the user finding the class and goes the fields selection dialog directly.

It is also possible to create xwork (struts2) validation style snippets as well. This is, however, not included in the jar file. But one can download the below template and add in templates-config.xml and uncomment the struts2 validation part.

These templates can automatically be generated using Fast Code Plugin template. One can download the below templates and add in templates-config.xml (please see details how to add/export/import templates).Then just type Ctrl+Alt+Shift T and select the template as "STRUTS_VALIDATION” or "STRUTS_VALIDATION_SINGLE”.

STRUTS_VALIDATION TEMPLATE:

							
STRUTS_VALIDATION_SINGLE TEMPLATE:

	
SPRING BEAN

One can create spring bean definition. For this one needs to select the Create New Spring Bean option.

After selecting the Spring Bean option, one needs to select the template variations for bean type injections as shown below.

Once the appropriate template variation and class is selected, a spring bean definition will be created. Below one such bean definition is shown for Person with setter injection variation.

<bean id="person" class="com.test.Person">
	<property name="addressDAO" ref="addressDAO" />
</bean> 
One can select as many fields within the class Person, but the it will not check if bean definitions exist for those fields. Also the id attribute will be Person, but one would probably want to change it to person. Simliarly, it will generate bean definition for constructor injection as shown below.
	<bean id="person" class="com.test.Person">
		<constructor-arg index="0">
			<ref bean="addressDAO" />
		</constructor-arg>
	</bean>

One thing to note it will not check if the constructor actually exists or the order in which the parameters would appear.

SPRING BEAN OF MULTIPLE CLASSES

One can create spring bean definitions for multiple classes at a time. To do this, just invoke the menu using shortcut Ctrl-Alt-Shift-T in any xml file. Once invoked, it will show the below snippet dialog. The following template variations for bean type injections can be selected as shown below.

Once the appropriate template variation and package is selected, the below Select Classes dialog is shown where one can select multiple classes of the selected package.

The below bean definition is generated for the selected classes with setter injection variation:









If one select template variation "embedded-constructor", it will create the spring definition for the selected classes as shown:

























 
JSF MANAGED BEAN

One can create JSF managed bean by selecting the appropriate option of same name. One needs to open the faces-config.xml file into an editor before executing this option. An example is shown below where SomeBean is a managed bean which contains SomeOtherBean which is another managed bean. This plugin will not verify the managed bean definition exists for SomeOtherBean, one needs to create the managed bean definition for SomeOtherBean manually.

	<managed-bean> 
		<managed-bean-name>SomeBean</managed-bean-name>
		<managed-bean-class>com.test.bean.SomeBean</managed-bean-class> 
		<managed-property> 
			<property-name>SomeOtherBean</property-name>
			<value>#{SomeOtherBean}</value>
		</managed-property>
	<managed-bean> 

This template can automatically be generated using Fast Code Plugin template. One can download the below template and add in templates-config.xml (please see details how to add/export/import templates).Then just type Ctrl+Alt+Shift T in an xml file as allowed file name for this template is *.xml and select the template as "JSF_MANAGED_BEAN".

	
 
CREATE HQL

Most of the snippets are created within one file. However, it has the ability to generate one snippet in one file and another in a different file at the same time. This is useful in the case of hql in hibernate where a named query is created in a xml file, and the code to invoke the named query is needed in the java class. To do this one needs to select one of the hql select/update/delete options and when the snippet dialog come up one need to select the named query option. With this option, it will prompt one for the location of the named query file for the first time. If the file is there and it is a valid xml file with proper tags, it will ask if the user wants to create a new query or use an existing query.

The snippet is contained in the templates-config.xml file. The hql query will be contained in the additional-templates-config.xml file. The template with type hql.select.format is used for the hql select. Similarly type hql.update.format is used for the hql update. For hql select there are three kinds of fields : selected_fields are the ones to use in the select part of the hql, where_fields are used in the where condition and join_fields are use for the joined fields. Similarly, for update hqls there is update_fields and where_fields . It is possible to use existing named query or create named query as shown in the picture below.

The special logic for hql is hard coded in the program, it is not possible to configure it except for the templates. It is, however, possible to remove the variation dialog altogether. If one is interested only in creating named queries only, one can edit the file fast-code.properties in the resources folder and put

•hql.variation.default=named-query
The line is already there, one just needs to uncomment it. It is also necessary to leave variation and variation field fields blank. In this case no variations dialog will appear and it will directly do the named query instead. It is to be noted that the query it generates will not be ready to use. You need make sure all the names are distinct and you may have to change some of them manually.

 
SPRING BEAN AS A FILE

This plugin can create spring bean of a class in a file. If one select Car as the class it can create a new snippet file using fc:file tag in file dir "Sample/src/xml" and one can set the xml file name for a class in templates-config.xml file. Once appropriate template variation and class is selected, a spring bean definition will be created in a xml file. Below one such bean definition is shown for Car with embeded-setter injection variation.



	
		
			
				
				
				
				
			
		
	


 

DELEGATE METHOD

This menu is used to create instance of the class selected and a delegate method with the method selected. Delegate method contains the target object along with the method to be invoked.

    

	/**
			  *
			  *@return
			  */
			@Override
			public String getFirstName ()  {
				  String getFirstName =  person.getFirstName();
								return getFirstName;
						}
	/**
			  *
			  *@return
			  */
			@Override
			public String getLastName ()  {
				  String getLastName =  person.getLastName();
								return getLastName;
						}
	/**
			  *
			  *@return
			  */
			@Override
			public Integer getPersonId ()  {
				  Integer getPersonId =  person.getPersonId();
								return getPersonId;
						}

 

CREATE INSTANCE OF CLASSES

One can create instance of classes of the given names in the specified package. To use this menu, just type Ctrl-Alt-Shift-T.

    

The code generated below shows how an instance is created for classes Person, Salary and Address.

	@Resource
			private Address address;
	@Resource
			private Car car;
	@Resource
			private City city;
 
CREATE IMPL

One can create implementation of interfaces. To do this, just use shortcut key Ctrl-Alt-Shift-T which will show snippet dialog where one can select the package. Once package is selected, one needs to give the instance of the class name. A class selection dialog is shown, where one can select multiple classes to create implementation.

The template shows how one can create Implementation of interfaces using fc:class tag. Sometimes, the interfaces are not located in the same package as the implementing class, so import is used in the templates to import the interfaces. @Service annotation is used to tell the spring which beans should be managed and how they can be connected with the implementation class.

					
						import ${class.fullyQualifiedName}; //Imports the fully qualified name for eg: com.test.Person
						import org.springframework.stereotype.Service;
						import ${InstanceOfClass.fullyQualifiedName}; //Imports the fully qualified name of instance class
						@Service
						public class ${class.name}Impl implements ${class.name}{
							private ${InstanceOfClass.name} ${InstanceOfClass.defaultInstance};
						}
					
 
 
CREATE MULTIPLE CLASS

One can create multiple classes of the given names in the specified package. To do this, just type Ctrl-Alt-Shift-T. Multiple class names can be provided seperated by a space and even the suffix can be provided to the classes as dao, impl, service, etc as shown:

CREATE MULTIPLE INTERFACE

Using this option, one can create multiple interface files of the given file names in the specified package. One can also provide suffix to the interface files to be created as shown. To use this menu, one needs to use shortcut key Ctrl-Alt-Shift-T.

 

CREATE MULTIPLE ABSTRACT CLASSES

One can create multiple abstract classes of the given names in the specified package. To do this, just type Ctrl-Alt-Shift-T, which will show create snippet dialog menu. Once Package is selected, one needs to provide the class names seperated by space in additional paramters dialog as shown:

The class names will then be prefixed as "Abstract" for all the classes as shown in the selection dialog. Here one has the option to select the classes to create abstract class, only the selected classes will be created.

 
CREATE MULTIPLE EXCEPTION CLASSES

Multiple exception classes can be created using this menu. To do this, just type Ctrl-Alt-Shift-T which will show create snippet dialog menu. Once Package is selected, one needs to provide the class names seperated by space in additional paramters dialog. The exception classes will be created which extends Exception of the given names in the specified package.

The following example shows how a CarException class is generated using fc:class tag:

public class CarException extends Exception {
	/**
		 *
		 */
	public CarException() {
		super();
	}

	/**
	 * 
	 * @param message
	 */
	public CarException(final String message) {
		super(message);
	}

	/**
	 * 
	 * @param message
	 * @param throwable
	 */
	public CarException(final String message, final Throwable cause) {
		super(message, cause);
	}

	/**
	 * 
	 * @param throwable
	 */
	public CarException(final Throwable cause) {
		super(cause);
	}
}
 
CREATE MULTIPLE RUNTIME EXCEPTION CLASSES

One can generate multiple runtime exception classes which extends RuntimeException of the given names in the specified package. To use this menu, just type Ctrl-Alt-Shift-T.

The following example shows how PersonException class which extends runtime exception is generated for Person class using fc:class tag:

public class PersonException extends RuntimeException {
	/**
		 *
		 */
	public PersonException() {
		super();
	}

	/**
	 * 
	 * @param message
	 */
	public PersonException(final String message) {
		super(message);
	}

	/**
	 * 
	 * @param message
	 * @param throwable
	 */
	public PersonException(final String message, final Throwable cause) {
		super(message, cause);
	}

	/**
	 * 
	 * @param throwable
	 */
	public PersonException(final Throwable cause) {
		super(cause);
	}
}
COPY CLASSES

One can copy multiple classes at a time from one package to another package. At the sametime, this menu also helps to change the suffixes of the classnames to to specified suffix names of the classes while copying as shown below:

In below sample, classes Customerdao, CustomerDetailsdao, Orderdao are selected, a dialog appears to select the elements from the tree where the classnames are changed to given suffix as "domain" and also ask for the source path for the classes to be created.

    

CREATE SNIPPET FROM METHOD

This menu is used to create code snippet from the attributes of a method. A sample template with all the available place holders for this menu, is present in the template-config.xml. Below is the list of place holders:
Method return Type -- ${method.returnType.name}
Method Annotations -- ${method.annotations}
Annotations -- ${annot.type.name}
Annotation Parameter -- ${annot.parameterList}
Exceptions -- ${method.exceptions}
Method Parameters -- ${method.parameters}

Below snippet dialog shows how a snippet with method can be created. Class and file selection can be done using browse button as shown or by selecting in dropdown or even one can write the class name directly in the text box.

 
CREATE INSTANCE OF GENERIC DAO

This menu is used to generate instance for generic dao class. One can select a package and select classes in the package to create instance of generic dao as follows:

 

JSON FROM CLASS

One can create JSON from a class in json or js files. One can update the JSON templates by going to Windows--> Preference-->Fast Code-->Templates-->Templates. This plugin can create instance of a class in the JSON format. If one selects JSON FROM CLASS, it will create JSON formatted snippet.

The following example shows the JSON representation of a class that describes a Person class. The person class has string fields for personId, firstname, lastname, birthdate etc and contains an object representing the person's car.

{
  " personId " :  0,
  " firstName " :  "",
  " lastName " :  "",
  " birthDate " :  null,
  " gender " :  "",
  " companyName " :  "",
  " car " :  {
 	 " color " :  "",
 	 " model " :  "",
 	 " fuel " :  "",
 	 " engineNo " :  "" }
 }

 

JSON FROM CLASS AS FILE

This menu can create JSON from a class in a file in the web tier example: jsp, js files etc. One can update the Json templates by going to Windows--> Preference-->Fast Code-->Templates-->Templates.  In template body, one can set the source path and the filename to create the Json class.

	
	/*file dir is the complete source path and name holds the js or jsp file name */
	/**
	*Source body
	**/
	


To use JSON from class, just type Ctl-Alt-Shift-T from inside any js or jsp file. A dialog box as shown will appear and choose JSON FROM CLASS AS FILE from there.

 

The following example shows the JSON representation of a class that describes a Person class. The Person class has string fields for firstname, lastname, birthdate, personId, etc and contains an object representing the person's car.

The fields are selected from field selection dialog which is displayed in a hierarchical structure. It generates the following JSON format in PersonJson.js file as shown below:

{					
"personId" :  0,
"firstName" :  "",
"lastName" :  "",
"birthDate" :  null,
"gender" :  "",
"companyName" :  "",
"car" :  {
	"color" :  "",
	"model" :  "",
	"fuel" :  "",
	"engineNo" :  "" }
 }	
 
MULTIPLE FILES

This menu has the ability to create multiple files in the selected folder at a time. One can also provide the file type/extention (.java, .jsp, .js, etc) while creating the files as shown below:

 

One can update content of the files by updating the templates as shown below:


	/*
	**File content*
	*/

#end

 

INCLUDE FILES

One can select a folder and can include any number of files (js, jsp, css and img files) they want to include with this template as shown in below sample where Person.jsp and car.jsp files are included in Sample.jsp file.

	
	

 

CREATE FILE AND INCLUDE

This menu is used while working with a jsp/html file. For example, one can create a file and include this file in the file one is working with. They can change the template to include js or jsp or any other file as it is easier to have a file open and invoke this menu. To do this, just use shortcut Ctrl-Alt-Shift-T. Once invoked, it will show the snippet dialog where one can select the project to create a file. Below is an example to create a js file and include it:

Once the project is selected, an additional parameters dialog is shown where one needs to provide the filename.extention as shown. Here one needs to give the extention as to create a specified file type as js, jsp or html file as required. For example, Person.js is the file which needs to be created, once the filename is provided, it creates the file in the specified folder and place the javascript to include this Person.js file in the file from where you are working with.

 

The code generated below shows how an include script is generated:

CREATE IF ELSE IF BLOCK WITH CONSTANTS

This menu is used to create if-else-if block with constants from inside any method of a class. To do this, just type Ctl-Alt-Shift-T. Once invoked, one can select the class and fields of a class to create if-else-if block. Local variables within the method can be selected in additional parameters. Below example shows how an if-else-if block is created for a class Address and selected fields personId, addressLine1, addressLine2, state.

	if (p1 == (Address.personId)) {
	} else if (p1.equals((Address.addressLine1))) {
	} else if (p1.equals((Address.addressLine2))) {
	} else if (p1.equals((Address.state))) {
	} else { }	//Here p1 is the local variable selected within the method of a class

 

CREATE SWITCH CASE STATEMENT WITH CONSTANTS

One can create switch case statement with constants from inside any method of a class. To do this, just type Ctl-Alt-Shift-T. Once invoked, one can select the class and fields of a class to create switch case. Local variables within the method can be selected in additional parameters. Below example shows how an switch case statement is created for a class Person and for selected fields.

switch (p1) {
	case Person.birthDate:
	break;
	case Person.firstName:
	break;
	case Person.lastName:
	break;
	case Person.personId:
	break;
	default:
	break;
	}

CREATE SWITCH CASE STATEMENT WITH ENUMERATOR

One can also create switch case statement for selected enumerators. To do this, just use shortcut Ctrl-Alt-Shift-T. Once invoked, one can select the enum type and enum type fields to create switch case. Below example shows how an switch case statement is created for a enum type Days for selected fields.

	switch (days) {
	case SUNDAY:
	break;
	case MONDAY:
	break;
	case TUESDAY:
	break;
	case WEDNESDAY:
	break;
	case THURSDAY:
	break;
	case FRIDAY:
	break;
	case SATURDAY:
	break;

CREATE IF ELSE IF BLOCK WITH ENUMERATOR

One can also create if-else-if block for selected enumerators. To do this, just use shortcut Ctrl-Alt-Shift-T. Once invoked, one can select the enum type and enum type fields to create if-else-if block. Below example shows how an if-else-if block is created for a enum type Days for selected fields.

	if (days == (Days.SUNDAY)) {
	} else if (days == (Days.MONDAY)) {
	} else if (days == (Days.TUESDAY)) {
	} else if (days == (Days.WEDNESDAY)) {
	} else if (days == (Days.THURSDAY)) {
	} else if (days == (Days.FRIDAY)) {
	} else if (days == (Days.SATURDAY)) {
	} else {
	}

CREATE COMPARATOR CLASS

This menu is used to create comparator class for a selected class. To do this, just use shortcut Ctrl-Alt-Shift-T. Once invoked, it will show the snippet dialog where one can select the class to create a comparator class. In below sample, Person class is selected to generate comparator class.

The Person fields can be selected using the field selection dialog as shown:

An Inner class is created within the class from where one is working with. Fc:class tag is used to create inner class which is comparator class by using type attribute which can have values class/interface/test/innerclass as shown in below template:


			public class ${class.name}Comparator implements Comparator<${class.name}>{

				@Override
				public int compare(${class.name} ${class.defaultInstance}1, ${class.name} ${class.defaultInstance}2) {
					#foreach ($field in ${fields})
					if (${class.defaultInstance}1.${field.getter}() != null) {
						final int compareResult = ${class.defaultInstance}1.${field.getter}().compareTo(${class.defaultInstance}2.${field.getter}());
						if (compareResult != 0) {
							return compareResult;
						}
					} else if (${class.defaultInstance}2.${field.getter}() != null) {
						return -1;
					}
					#end
					return 0;
				}
			}
			

The code generated below shows how an PersonComparator Class is generated:

	public class PersonComparator implements Comparator{
		@Override
		public int compare(Person person1, Person person2) {
					if (person1.getFirstName() != null) {
				final int compareResult = person1.getFirstName().compareTo(person2.getFirstName());
				if (compareResult != 0) {
					return compareResult;
				}
			} else if (person2.getFirstName() != null) {
				return -1;
			}
					if (person1.getLastName() != null) {
				final int compareResult = person1.getLastName().compareTo(person2.getLastName());
				if (compareResult != 0) {
					return compareResult;
				}
			} else if (person2.getLastName() != null) {
				return -1;
			}
				return 0;
		}
	}

CREATE SERVLET

This menu is used to create a servlet for HTTP-specific servlet classes where HttpServlet class provides methods, such as doGet and doPost, for handling HTTP-specific services. Using this menu one can select methods to override HttpServlet requests. To do this, just use shortcut Ctrl-Alt-Shift-T in web.xml file. Once invoked, it will show the snippet dialog where one can select the package to create a servlet.

One can provide Servletname, project and url in additional parameters as shown:

The below selection dialog shows the PersonDetailsServlet created for a given package in additional parameters. 

One can select the methods for handling HTTP-specific services as shown:

The below servlet class PersonDetailsServlet is generated in selected package com.test.

package com.test;


/**
 * This class has been generated by Fast Code Eclipse Plugin 
 * For more information please go to http://fast-code.sourceforge.net/
 * @author : Administrator
 * Created : 04/10/2013
 */

import javax.servlet.http.HttpServlet;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class PersonDetailsServlet extends HttpServlet {

	/**
	 *
	 * @param req
	 * @param resp
	 */
	public void doDelete(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
		return;
	}

	/**
	 *
	 * @param req
	 * @param resp
	 */
	public void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
		return;
	}

	/**
	 *
	 * @param req
	 * @param resp
	 */
	public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
		return;
	}

	/**
	 *
	 * @param req
	 * @param resp
	 */
	public void doPut(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
		return;
	}

	/**
	 *
	 * @param req
	 * @param resp
	 */
	public void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
		return;
	}

	/**
	 *
	 * @param req
	 * @param res
	 */
	public void service(final ServletRequest req, final ServletResponse res) throws ServletException, IOException {
		return;
	}
}

CREATE VALUE ANNOTATION

One can also inject values into the classes using spring's value annotation. This can be created using this menu. To do this, just use shortcut Ctrl-Alt-Shift-T and select "VALUE" menu as shown. Once invoked, it will show the snippet dialog where one can select the file to create value annotation.

The below selection dialog shows how one can select the imports which is required to create spring's value annotation. 

The below value annotation is created for property files at the point from where the menu is invoked.

@Value("${${property.name}}")
 

TEST SUITES

One can execute several test classes using Test Suite.  Running a test suite will execute all test classes in that suite. Using this menu, one can select multiple test classes from a given package and create a Test Suite class in a selected target package.

The following Test Suite will be created for the test classes testcomp, testcomp1 selected.

package com;

import org.junit.runners.Suite;
import org.junit.runner.RunWith;
import com.test.testcomp;
import com.test.testcomp1;

@RunWith(Suite.class)
@Suite.SuiteClasses({ testcomp.class, testcomp1.class })
public class Testsuites {

}
 
CONVERTER CLASS

Using this menu, one can create a converter class which performs Object-to-String and String-to-Object conversions between model data objects and creates a string representation of those objects.

Below sample shows how converter class is created for Person Class:

package com.test.domain;

/**
 * This class has been generated by Fast Code Eclipse Plugin 
 * For more information please go to http://fast-code.sourceforge.net/
 * @author : Administrator
 * Created : 05/29/2013
 */

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

public class PersonConverter implements Converter {
	@Override
	public Object getAsObject(FacesContext context, UIComponent component,
			String value) {
		Person person = new Person();
		person.setBirthDate(null);
		person.setFirstName("");
		person.setGender("");
		person.setLastName("");
		person.setPersonId(0);
		person.setTitle("");
		person.setSalaries(null);
	}

	@Override
	public String getAsString(FacesContext context, UIComponent component,
			Object value) {
		Person person = new Person();
		Date birthDate = person.getBirthDate();
		String firstName = person.getFirstName();
		String gender = person.getGender();
		String lastName = person.getLastName();
		Integer personId = person.getPersonId();
		String title = person.getTitle();
		Set salaries = person.getSalaries();
		return null;
	}
}

CREATE FILE WITH SELECTED CONTENT

Using this menu, user has the option to create a file with the selected content.  One needs to select the content and invoke the menu (use shortcut Ctrl-Alt-Shift-T). It will show the snippet dialog where one can select the folder to create a file. The file gets created with the same extension of the file from where the content is selected. Below is an example to create a jsp file:

Once the Folder is selected, an additional parameters dialog is shown where one needs to provide the filename to be created. For example, Person is the fileName given which is created with the selected content as Person.jsp. Here, we are selecting the content of a jsp file hence the file gets created with the same extension.

OVERRIDE METHODS

This template is used to create a class which will override method/methods of the extended class. To do this, just use shortcut Ctrl-Alt-Shift-T. Once invoked, it will show the snippet dialog where one can select the class to extend which will be a super class as shown.

Once the methods are selected, an additional parameters dialog is shown where one needs to provide the ClassName PersonDetails to create a class. One can specify the project and package name to create a class.

Below sample shows how an override method PersonDetails is created from Person Class:

package com.test;

import com.test.Person;

public class PersonDetails extends Person {
	@Override
	public String getFirstName() {
		super.getFirstName();
		return null;
	}

	@Override
	public String getLastName() {
		super.getLastName();
		return null;
	}

	@Override
	public Integer getPersonId() {
		super.getPersonId();
		return 0;
	}
}

CREATE FIELD AND CONSTRUCTOR

This template is used to create a constructor of the same class (class from where the menu is invoked) and auto assign the parameters of the selected class. To do this, just use shortcut Ctrl-Alt-Shift-T. Once invoked, it will show the below snippet dialog where one can select the class to assign as parameters while creating the constructor.

The below snippet shows how a constructor is generated for Car class and the selected class (Person) is assigned as parameter.

	private Person person;

	public Car(Person person) {
		this.person = person;
	}
IMPORT/EXPORT TEMPLATES

The templates can be exported by going to Windows -->Preferences -->FastCode-->Templates -->Templates -->Export as shown in below Templates preference page.

templates

When exported, a new project called 'Fast Code Eclipse Plugin' will be created and there will be a resources folder within it. Inside the resources folder, a subfolder templates is created. After the export is completed, one can see the files templates-config.xml in templates folder as shown below. Similarly, for additional templates one can import/export templates by going to Windows -->Preferences -->FastCode-->Templates -->Templates Additional.

Now one can change the templates by opening them in the editor within eclipse. It is more convenient to change in this manner than going through the preferences. Once they are edited, one can import them from the fast code top menu. Once exported, one can check in to local repositories, example: cvs, svn, etc. Then other team members can check out and start using the templates right away.

For example: If one needs to "create instance of class" template, one can see how the mapping is done between the preference page and the templates-config.xml file.

Design downloaded from Free Templates - your source for free web templates