October 22, 2024
Chicago 12, Melborne City, USA
templates

How to correctly include an Eclipse PlugIn Project in Eclipse Committers?


I wrote a PlugIn Project in Eclipse which should Resolve Variables in a custom way.
The idea came for faster implementaion of getter/setter methods:

public ${type} get${varNameUpper}(${type}${varNameLower}){
    return ${varNameLower};
}

This template should take the "varNameUpper/Lower" Variable and adjust it simultaneously. For this I wrote the PlugIn-Classes:

public class Lower extends SimpleTemplateVariableResolver {
    
    public Lower() {
        super("varNameLower", "Converts first letter to lower");
    }
    
    @Override
    protected String resolve(TemplateContext context) {
        String variableName = context.getVariable("variableName");
        if (variableName != null && !variableName.isEmpty()) {
            return variableName.substring(0, 1).toLowerCase() + variableName.substring(1);
        }
        
        return "";
    }

And

public class Context extends TemplateContextType {

    public Context() {
        super("de.s231371.plugin.context");
        
        // Register variable resolvers
        addResolver(new Lower());
        addResolver(new Upper());
    }
}

The issue is, that I am able to include the PlugIn into Eclipse so that Eclipse lists it under "Installed Software", but in the Template Section where I can set the context for my Template Resolver it is not listet.

I exported it as .jar File and added it to the eclipse/dropins folder, which at least seems to integrate it into eclipse.

My Manifest and Plugin.xml:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Automatic-Module-Name: de.s231371.plugin
Bundle-Name: templateHandler
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-SymbolicName: de.s231371.plugin;singleton:=true
Bundle-Version: 1.1.1
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.jface.text;bundle-version="3.25.0"

<?xml version="1.0" encoding="UTF-8"?>
<plugin>
   <!-- Template Context Registration -->
   <extension
         point="org.eclipse.ui.editors.templates">
      <contextType
            class="de.s231371.plugin.Context"
            id="de.s231371.plugin.context"
            name="Custom Plugin Template Context">
      </contextType>
      <!-- Template Definition -->
      <template
         id="de.s231371.plugin.template"
         name="Custom Template"
         contextTypeId="de.s231371.plugin.context"
         description="A custom template for demonstration purposes">
         <pattern>
            <![CDATA[
            public ${type} get${varNameUpper}(${type} ${varNameLower}) {
               return ${varNameLower};
            }
            public void set${varNameUpper}(${type} ${varNameLower}) {
               this.${varNameLower} = ${varNameLower};
            }
            ]]>
         </pattern>
      </template>
   </extension>
</plugin>

I also tried to launch the PlugIn directly in DebugMode, which again includes it in Eclipse, but doesn’t list it in the TemplateContext-Menue.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video