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