Bookmark and Share


Generating getters setters in eclipse is fairly easy. Also this plug-in makes it easy to create fields with the getter setters. However, if one wishes to generate interceptor with the template mechanism that is also possible. This plug in might provide more flexibility with the format of the getter setters as eclipse provides a way to customize the body of the getters setters only. To illustrate that let's consider sometime when one might want to create compact one line getter setters as shown below.


public String getFoo() { return foo; }

public void setFoo(String foo) { this.foo = foo; }


This has been actually proposed as an enhancement to eclipse.

With this plug-in one can create this kind of getter setters easily. The template for this is shown below. One needs to just add this to the templates-config.xml and import the templates from the fast code --> templates menu. Other kinds of getter setters can also be generated easily by modifying the templates. For rest of the documentation one can refer to the templates.

	
<template type="GETTER_SETTER">
		<description>Used to Create Getter Setters</description>
		<variation></variation>
		<class-pattern></class-pattern>
		<getter-setter></getter-setter>
		<allowed-file-extensions>java</allowed-file-extensions>
		<number-required-classes>0</number-required-classes>
		<allow-multiple-variation></allow-multiple-variation>
		<template-body>
			<!--[CDATA[ 				
				#foreach ($field in ${fields})
					public ${field.type} get${field.name.substring(0,1).toUpperCase()}${field.name.substring(1)}() {return ${field.name};}
					public ${field.type} set${field.name.substring(0,1).toUpperCase()}${field.name.substring(1)}(${field.type} ${field.name}) {this.${field.name} = ${field.name};}
				#end
			]]-->
		</template-body>
	</template>

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