variable - how to change javadoc author in eclipse




How do I update an Eclipse template variable on the fly? (2)

This email chain from 2004 says it might not be possible:

the Java editor chooses not to respect resolvers contributed to its two context types ('java' and 'javadoc'), but only recognizes the built-in resolvers.

The html editor you are working with may have a similar restriction.

I've added the following new Eclipse template via extension point. It simply adds a template for a sample testTag tag.

<!-- Add code template -->
<extension point="org.eclipse.ui.editors.templates">
   <template autoinsert="true"
             contextTypeId="html_tag"
             description="[Description] Template populated by Snippet values ***"
             id="org.eclipse.jst.jsf.ui.newHtmltag"
             name="testTag">
       <pattern>
            <![CDATA[
                <testTag style="background: ${color}"></testTag> 
            ]]>
       </pattern>
   </template>
  <resolver
     contextTypeId="html_tag"
     type="src" 
     class="TestTagTemplateVariableResolver">
  </resolver>
</extension>

What I'd cannot figure out is how to change the value of the $(color) variable at runtime. More specifically, when the user presses Ctrl + Space (or the equivalent for content-assist) and types in "testTag" and presses Enter -- instead of the "color" placeholder text, I'd like it replaced by some other text value I have in another class. How do I do this?


I'm not entirely sure what you want, but you may be able to do what you want with templates.

For example, open a java editor, place the cursor inside a method, type arraya then ctlr-space, and select arrayadd from the pop up menu. You will get a template with String highlighted, pressing tab jumps to the next variable. The template source can be seen in,

Preferences -> java -> editor ->templates

${array_type}[] ${result:newName(array)} = new ${array_type}[${array}.length + 1];
System.arraycopy(${array}, 0, ${result}, 0, ${array}.length);
${result}[${array}.length]= ${var};

Everything starting the a $ is a variable that you can fill in, and you can tab between variables while filling in the template.