JDT provides several editor templates. You can also add your own via the Templates View. However, if you want to share the templates between your several workspaces or with others you can also create a plugin.
As a first step, define the following extension for the extension point org.eclipse.ui.editors.templates.
I have also shared a plugin with the above code on GitHub.
As a first step, define the following extension for the extension point org.eclipse.ui.editors.templates.
<extensionThe xml file just contains the template descriptors. For example, here is a template for printing the enclosing type and the enclosing method.
point="org.eclipse.ui.editors.templates">
<include
file="templates/default-templates.xml"
translations="$nl$/templates/default-templates.properties">
</include>
</extension>
<template name="debugout" description="%Templates.debugout" id="com.eclipse.jdt.ui.templates.debugout" context="java-statements" enabled="true" autoinsert="true">You can read about the available template variables in Eclipse help.
System.out.println("${enclosing_type}#${enclosing_method}(..)");${cursor}
</template>
I have also shared a plugin with the above code on GitHub.
Hi Deepak,
ReplyDeleteThe code you shared is really useful. It's working fine but I have some issue. When I run plugin project as "Eclipse Application", I am able to see new templates. But when I try to export the project as "Deployable plug-ins and features" and add them to eclipse folder and restarts the eclipse, still I am not seeing the new templates.
Please help !!!
Thanks Deepak, Your blog helped me :)
ReplyDelete