title: How to create a custom Intellij template setter for use with Guava's Optional
body: <p>I am trying to write a custom setter using Intelij Template's but for Google's Guava Optionals. For example if I have a class as follows:</p>
  
  <pre><code>public class Note {
      public Optional&lt;String&gt; title;
  }
  </code></pre>
  
  <p>Using the default <code>Setter</code> generation in Android Studio outputs:</p>
  
  <pre><code>public class Note {
      public Optional&lt;String&gt; title;
  
      public void setTitle(Optional&lt;String&gt; title) {
          this.title = title;
      } 
  }
  </code></pre>
  
  <p>What I want to achieve is:</p>
  
  <pre><code>public class Note {
      public Optional&lt;String&gt; title;
  
      public void setTitle(String title) {
          this.title = Optional.fromNullable(title);
      } 
  }
  </code></pre>
  
  <p>What I have tried so far is copying Intelij's Template and using <code>StringUtil.split()</code> to strip the <code>Optional&lt;</code> part of the method signature. However I'm getting an error while I'm using the template below.</p>
  
  <p>Error</p>
  
  <pre><code>Incorrect method 'public void setTitle($StringUtil.split($field.type, true, "&lt;").get(1) title) { mTitle = title; }
  </code></pre>
  
  <p>Any advice on what I should do?</p>
  
  <p>Default <code>Intelij Default</code> Template for Setter Generation</p>
  
  <pre><code>#set($paramName = $helper.getParamName($field, $project))
  public ##
  #if($field.modifierStatic)
    static ##
  #end
  void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) {
    #if ($field.name == $paramName)
      #if (!$field.modifierStatic)
        this.##
      #else
        $classname.##
      #end
    #end
    $field.name = $paramName;
  }
  </code></pre>
  
  <p>My custom Guava Optional Setter Generation</p>
  
  <pre><code>#set($paramName = $helper.getParamName($field, $project))
  public ##
  #if($field.modifierStatic)
    static ##
  #end
  void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($StringUtil.split($field.type, true, "&lt;").get(1) $paramName) {
    #if ($field.name == $paramName)
      #if (!$field.modifierStatic)
        this.##
      #else
        $classname.##
      #end
    #end
    $field.name = $paramName;
  }
  </code></pre>