Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Papyrus-RT/Developer/Design/0.8/Codegen Extension

< Papyrus-RT‎ | Developer‎ | Design
Revision as of 16:52, 4 September 2015 by Unnamed Poltroon (Talk)

Extending the code generator

The PapyrusRT code generator can be extended using the Eclipse plugin extension mechanism. The org.eclipse.papyrusrt.codegen.cpp plugin defines an extension point called generator to provide generator classes. A plugin for a custom generator needs to define an extension linked to this generator extension point, and specify a custom generator class implementing this extension. The custom generator must be a subclass of AbstractCppGenerator, defined in the same org.eclipse.papyrusrt.codegen.cpp plugin.

In the definition of the extension, the type must be one of the following:

  • ClassGenerator
  • CapsuleGenerator
  • ProtocolGenerator
  • StateMachineGenerator
  • StructureGenerator

The class associated to the extension must implement the AbstractCppGenerator.Factory interface, which is used by the generator to create instances of each specific generator.

Extending the code generator

The PapyrusRT code generator can be extended using the Eclipse plugin extension mechanism. The org.eclipse.papyrusrt.codegen.cpp plugin defines an extension point called generator to provide generator classes. A plugin for a custom generator needs to define an extension linked to this generator extension point, and specify a custom generator class implementing this extension. The custom generator must be a subclass of AbstractCppGenerator, defined in the same org.eclipse.papyrusrt.codegen.cpp plugin.

In the definition of the extension, the type must be one of the following:

  • ClassGenerator
  • CapsuleGenerator
  • ProtocolGenerator
  • StateMachineGenerator
  • StructureGenerator

The class associated to the extension must implement the AbstractCppGenerator.Factory interface, which is used by the generator to create instances of each specific generator.


The following example describes the usual steps required to create a custom generator and provide the extension.

This assumes that you have installed a PapyrusRT development environment as described in Mars Development Environment.

Create a Plug-in Project

  1. Go to File → New → Other... → Plug-in Project
  2. Enter the name of the project and all relevant fields. In this example we will use the name "myproject.mygen"

{{Note|In the "Content" dialog, uncheck the "Generate an activator" and the "This plug-in will make contributions to the UI" options.|}

Configure the new plug-in dependencies

The new plug-in needs at least the following three plug-ins:

  • org.eclipse.papyrusrt.codegen.cpp: the code generator which provides the base generators and extension point.
  • org.eclipse.papyrusrt.codegen.xtumlrt.common.model: the meta-model of the intermediate representation (xtUMLrt)
  • org.eclipse.papyrusrt.codegen.lang.cpp: the meta-model of the target C++ subset.
  1. If not already open, opern the new project's META-INF/MANIFEST.MF file.

Genext-1-new-plugin-proj.png

  1. Click on the "Dependencies" tab.

Genext-2-dep-tab.png

  1. Click the [Add...] button, search for org.eclipse.papyrusrt.codegen.cpp, select it and click [OK].

Genext-3-add-dep.png

  1. Click the [Add...] button, search for org.eclipse.papyrusrt.codegen.xtumlrt.common.model, select it and click [OK].
  2. Click the [Add...] button, search for org.eclipse.papyrusrt.codegen.lang.cpp, select it and click [OK].

Genext-4-deps-added.png

  1. Save.

Note: you may add other dependencies that you need.

Create a generator class

In the Project Explorer navigate to the plug-in's source folder (usually called "src") and create a new class there. The new class must be a subclass of org.eclipse.papyrusrt.codegen.cpp.AbstractCppGenerator.

Note.png
You may extend the built-in generators found in org.eclipse.papyrusrt.codegen.cpp.internal, but beware that they are not part of the official API and their interface is subject to change. These generators are:
  • BasicClassGenerator
  • CapsuleGenerator
  • SerializableClassGenerator
  • ProtocolGenerator
  • StateMachineGenerator
  • CompositionGenerator


In this example we are going to extend the BasicClassGenerator. After creating the class, its source code should look like this:

package myproject.mygen;

import org.eclipse.papyrusrt.codegen.cpp.internal.BasicClassGenerator;

public class MyClassGenerator extends BasicClassGenerator
{
// ...
}

The generator needs to provide a factory class which the PapyrusRT code generator manager (GeneratorManager and EclipseGeneratorManager) will use to obtain instances of your generator. This factory must implement the AbstractCppGenerator.Factory interface. The most natural location for this is within your own generator class:


Back to the top