Bug 102460 - [code templates] Simple expressions in code templates
Summary: [code templates] Simple expressions in code templates
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 enhancement with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-01 06:57 EDT by Erwin Bolwidt CLA
Modified: 2010-01-27 03:51 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erwin Bolwidt CLA 2005-07-01 06:57:20 EDT
Support for simple expressions involving template variable would be nice. 

There is one particular use for expressions that I am looking for the most:
given a property name, create the method name for a setter or a getter. To do
this correct in all cases, knowledge of types would be necessary. For most
cases, capitalization of the first character of a variable is enough.
I use templates for repetitive code that involves properties, for example code
to fire PropertyChangeEvents in setter methods.

I would be happy with a special-purpose modification to allow upper/lowercasing,
but perhaps a more generic approach involving functions and expressions is
possible? Plugins could add functions to a library.

I have no idea how complex this would be, but I would like to offer this as a
suggestion for enhancement.
Comment 1 Richard Arthur CLA 2010-01-26 19:36:33 EST
If I understand this correctly, I think you are looking for something that will take a Template that looks like this:

=================

private ${type} ${field};
public ${type} get${property}()
{
	return this.${field};
}
public void set${property}(${type} value)
{
	this.${field} = value;
}

=================

and instead of typing three separate variables, I would type two: the ${type} and ${property}. Then, the template would reformat the ${property} as either camelCasing or PascalCasing, depending on some feature of the variable. For example, I could have a template like this:

=================

private ${type} ${property:camelCasing};
public ${type} get${property:PascalCasing}()
{
	return this.${property:camelCasing};
}
public void set${property:PascalCasing}(${type} value)
{
	this.${property:camelCasing} = value;
}

=================

If this is what you would like, I absolutely agree. I have a lot of templates that I use frequently where I have to type the same thing twice to match both casings.
Comment 2 Erwin Bolwidt CLA 2010-01-27 03:51:52 EST
Yes, that is exactly what I would like.

(BTW: wow, that's a blast from the past. 2005! :-) )

But I believe other people may want different functions on the field name, and if this were implemented, it probably wouldn't be much harder to make the functions like 'camelCase' or 'PascalCase' extensible through a plugin.