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.
Papyrus-RT/Developer/Design/0.8/Codegen Extension
Contents
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
- Go to File → New → Other... → Plug-in Project
- 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.
- If not already open, opern the new project's META-INF/MANIFEST.MF file.
- Click on the "Dependencies" tab.
- Click the [Add...] button, search for
org.eclipse.papyrusrt.codegen.cpp
, select it and click [OK].
- Click the [Add...] button, search for
org.eclipse.papyrusrt.codegen.xtumlrt.common.model
, select it and click [OK]. - Click the [Add...] button, search for
org.eclipse.papyrusrt.codegen.lang.cpp
, select it and click [OK].
- 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
.
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: