There are too many time I encounter the need to write an adder/remover methods for lists:
public void addSomething(Something something){
somethings.add(something);
}
public void removeSomething(Something something){
somethings.remove(something);
}
If I got it right, then Eclipse templates can support auto complete... for example, if I have a:
Vector<Something> somethings=new Vector<Something>();
I would like the template to add the method to the Auto-Complete of Eclipse, and would auto complete the entire method:
public void addSomething(Something something){
somethings.add(something);
}
when I type "add" + (Ctrl + Space)...
Any idea how to accomplish something like this... perhaps point me to a reading material specific to this sort of subject.
** UPDATE **
Well, this is what I have so far:
public final void add${type:elemType(collection)}(${type} ${varName:newName(type)}) {
${collection}.add(${varName});
}
Here is the problem though, If I type "add" + (Ctrl + Space):
In the class level, and the collection is declared as a field, I get an empty variable as a collection.
public final void addtype(type type) {
collection.add(type);
}
In the method level, and the collection is declared as a field, I get an empty variable as a collection.
public final void addtype(type type) {
collection.add(type);
}
In the method level, and the collection reference is a local variable of the method I get the correct syntax, but the add method is inside the other method.
public void method(...) {
public final void addSomething(Something something) {
this.somethings.add(something);
}
}
Which means I don't get field level reference, how can I obtain it?
** UPDATE 2 **
This also gives the same result:
public final void add${type:elemType(collection)}(${type} ${varName:newName(type)}) {
${collection:field(java.util.Collection)}.add(${varName});
}
public final void remove${type:elemType(collection)}(${type} ${varName:newName(type)}) {
${collection:field(java.util.Collection)}.remove(${varName});
}
Thanks,
Adam.