Adding New Patterns

The Pattern facility is designed to be easily enhanced using the standard Eclipse extension facilities.

General Procedure

The general procedure for adding a new pattern is as follows:

  1. Create a new plugin project using the PDE plugin wizard (File | New | Project | Plug-in Development | Plug-in Project). Detailed instructions on how to create an Eclipse plugin can be found in the "Tool Developer" section of the Eclipse on-line help.
  2. Import the "com.instantiations.assist.eclipse.pattern" plugin within your plugin.xml file.
  3. Create a pattern strategy file (in XML format using the pattern language and DTD) that defines the user interface and code generation of your pattern. Many examples are provided below. Feel free to use any pattern supplied with the product as a template for creating your own patterns.
  4. Extend the com.instantiations.assist.eclipse.pattern.pattern extension point to define the name, description, category and source of your new pattern within the plugin.xml file.
  5. Extend the com.instantiations.assist.eclipse.pattern.strategy extension point to define the actually implementation your new pattern within the plugin.xml file. Note that a single pattern may have one or more strategies that implement it.
  6. Optionally, if your pattern needs to collect external data (e.g., using a JDBC query or detailed AST model analysis), you can extend the com.instantiations.assist.eclipse.pattern.callOut extension point with a reference to your own call-out class which implements the com.instantiations.assist.eclipse.pattern.core.CallOutHandler interface. If you do this, you will need to compile your class into a jar file and reference it as a runtime library in your plugin.xml file. You will also need to add a classpath entry that references the CodeProPattern.jar library to your project's .classpath file.
  7. Build your plugin and install it into your \eclipse\plugins directory.
  8. Shutdown and re-start the IDE.
  9. Open the Pattern wizard and look for your pattern.

Sample Project

A sample pattern project has been provided for your convenience. It defines a sample pattern which you can use as you see fit. To use the sample, do the following:

  1. Unzip the sample project into your workspace directory.
  2. Import the "SamplePatternProject" project into your workspace using the "File | Import | Existing Project into Workspace" command.
  3. Select the "build.xml" file in the project, right click and select the "Run Ant..." command, and then choose the "export" target to build the project.
  4. Unzip the resulting SamplePatternPlugin.zip file into your Eclipse or <websphere>\eclipse directory (make sure to preserve the directory structure so that the plugin files themselves end up in your Eclipse \plugins directory)..
  5. Shutdown and re-start the IDE.
  6. Open the Pattern wizard and look for the "Sample" pattern.

Pattern Extension Point

Patterns are defined via an XML-based pattern language and DTD provided with CodePro. New or customized patterns may be easily added by a patterns extension point defined by Codepro. See:

<CODEPRO>\eclipse\plugins\com.instantiations.assist.eclipse.pattern.ui_X.X.X\plugin.xml

Pattern Extension Point

The pattern extension point provides two hooks for the pattern support. The first allows new patterns to be added to the list of patterns that can be generated. It is supported by the "pattern" tag, which defines the following attributes:

id
A string used to uniquely identify the pattern.

name
The localized name of the pattern. This is the name that will be displayed in the user interface.

description
A localized description of the pattern. This is the description that will be displayed in the user interface. This should generally be the "Intent" section from the pattern's definition.

category
The localized name of the category to which the pattern belongs.

source
The localized name of the source of the pattern.

For example:

<extension point="com.instantiations.assist.eclipse.pattern.pattern">
    <pattern
        id="com.xyz.pattern.myPattern"
        name="%myPatternName"
        description="%myPatternDescription"
        category="%myPatternCategory"
        source="%myPatternSource"/>
</extension>

Strategy Extension Point

The second allows new strategies to be added to the list of strategies that implement any particular pattern. It is supported by the "strategy" tag, which defines the following attributes:

pattern
The id of the pattern implemented by the strategy.

name
The localized name of the strategy. This is the name that will be displayed in the user interface.

description
A localized description of the strategy. This is the description that will be displayed in the user interface.

helpContext
The help context id used to link to the pattern help page.

file
(optional) The path to the XML-based strategy file defining the strategy. The XML-based pattern language is defined in the Pattern Support Implementation Guide and DTD.

class
(optional) The fully qualified name of the of the class that implements the strategy. The class must implement the interface com.instantiations.assist.eclipse.pattern.core.Strategy.

For example:

<extension point="com.instantiations.assist.eclipse.pattern.strategy">
    <strategy
        pattern="com.xyz.pattern.myPattern"
        name="%myStrategyName"
        class="com.xyz.pattern.MyPatternStrategy">
    <strategy/>
</extension>

Call-out Extension Point

The third allows new call-out handlers to be registered so that they can be used to compute values other than those entered directly by the user. It is supported by the "handler" tag, which defines the following attributes:

id
A string used to uniquely identify the call-out.

class
The fully qualified name of the of the class that implements the call-out. The class must implement the interface com.instantiations.assist.eclipse.pattern.core.CallOutHandler. See the details in the Pattern Support Implementation Guide and DTD.

For example:

<extension point="com.instantiations.assist.eclipse.pattern.callOut">
    <handler
        id="com.xyz.pattern.myHandler"
        class="com.xyz.pattern.MyCallOutHandler">
    <handler/>
</extension>

Pattern Examples

You can see lots of example patterns here:

<CODEPRO>\eclipse\plugins\com.instantiations.assist.eclipse.pattern_X.X.X\strategy

Some example patterns that can act as templates for any new patterns that you create include: