Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Papyrus/Codegen/Adding a New Code Generator"

(The User Interface Project ("org.eclipse.papyrus.x.codegen.ui"))
(The User Interface Project ("org.eclipse.papyrus.x.codegen.ui"))
Line 107: Line 107:
 
* Careful readers has already noticed that there is a warning occuring after this step (see the Problems tab on the above figure). The reason for this warning is that we defined a default handler that does not exist yet. By double-clicking to the warning, we go to source of the problem and simply fix it by creating our new handler class (keep default properties in the create class dialog window).
 
* Careful readers has already noticed that there is a warning occuring after this step (see the Problems tab on the above figure). The reason for this warning is that we defined a default handler that does not exist yet. By double-clicking to the warning, we go to source of the problem and simply fix it by creating our new handler class (keep default properties in the create class dialog window).
 
[[File:CodeGen-Plugin-Project-UI-Creation-14.png]]
 
[[File:CodeGen-Plugin-Project-UI-Creation-14.png]]
 +
 +
* The created handler class should extend the "CmdHandler" class which is located in the "org.eclipse.papyrus.acceleo.ui" plug-in. Thus, this plug-in should be added to the dependencies and then the unimplemented methods should be implemented.
 +
[[File:CodeGen-Plugin-Project-UI-Creation-14-2.png]]
  
 
* The last extension we need to add is  "org.eclipse.ui.preferencePages". Upon creation, it comes with a default page. We need to set the properties of this page as follows: id as "org.eclipse.papyrus.x.codegen.ui.preferences.CodeGenPreferencePage", name as "X code generation", class as "org.eclipse.papyrus.x.codegen.ui.preferences.CodegenPreferencePage" and category as "org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory".
 
* The last extension we need to add is  "org.eclipse.ui.preferencePages". Upon creation, it comes with a default page. We need to set the properties of this page as follows: id as "org.eclipse.papyrus.x.codegen.ui.preferences.CodeGenPreferencePage", name as "X code generation", class as "org.eclipse.papyrus.x.codegen.ui.preferences.CodegenPreferencePage" and category as "org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory".

Revision as of 08:53, 21 October 2014

Papyrus has already have code generation support for C++ and Java programming languages. Besides, support for Ada and C programming languages are also on the way. However, it is possible to develop and integrate new code generators for other programming languages to Papyrus. In this article you will find how add a new code generator to Papyrus from scratch.

Preparing the Development Environment (Prerequisites)

This section provides a step-by-step guide to set up your development environment in order to be able to add a new code generator for Papyrus.

Assuming that you have already installed Papyrus, here are the steps you need to follow:

  • Install the "Qompass (Incubation)" modeler extension from the "Help > Install Papyrus Additional Components" menu.

Papyrus Additional Components Discovery.png

Preparing the Required Projects

To be able to develop a new code generator for a programming language (let's say the X programming language), three different (but interrelated) projects need to be created.

  • A main eclipse plug-in project for developing the code generator, which should be named as org.eclipse.papyrus.x.codegen
  • An eclipse plug-in project for connecting the code generator to the user interface of Qompass, which should be named as org.eclipse.papyrus.x.codegen.ui
  • Another eclipse plug-in project for developing the tests of the code generator, which should be name as org.eclipse.papyrus.x.codegen.tests

Now, let's create and prepare all these projects one by one.


The Main Code Generation Project for the Hypothetical X Programming Language ("org.eclipse.papyrus.x.codegen")

Here are the steps for creating and setting the "org.eclipse.papyrus.x.codegen" project:

  • Create an eclipse plug-in project. name it as "org.eclipse.papyrus.x.codegen" (as shown) and then click "Next >".

CodeGen-Plugin-Project-Creation.png

  • Do not make any changes on the default property values and click "Finish".

CodeGen-Plugin-Project-Creation-2.png

  • Upon a successful project creation, you will switch to the Plug-in Development perspective and see a window like below.

CodeGen-Plugin-Project-Creation-3.png

  • The project is created. Now, we need to do the required settings for integrating our project to Papyrus. Firstly, we need to add a dependency to the "org.eclipse.papyrus.codegen.extensionpoints" extension point.

CodeGen-Plugin-Project-Creation-4.png

  • Then we need to add a new language support extension called "org.eclipse.papyrus.codegen.extensionpoints.language".

CodeGen-Plugin-Project-Creation-5.png

  • After, create a client for this extension as shown.

CodeGen-Plugin-Project-Creation-6.png

  • And name this client's language property as as "X", and name its class as "org.eclipse.papyrus.x.codegen.XLanguageSupport".

CodeGen-Plugin-Project-Creation-7.png

  • Since we do not have such a class yet, we will see a warning like below.

CodeGen-Plugin-Project-Creation-8.png

  • Just double click on this warning. go to the warning icon on the opened editor and choose create the "org.eclipse.papyrus.x.codegen.XLanguageSupport" class.

CodeGen-Plugin-Project-Creation-9.png

  • On the upcoming dialog box, do not change anything and click "Finish".

CodeGen-Plugin-Project-Creation-10.png

  • Upon creation, we will see "XLanguageSupport.java" as below. To remove the errors, we just need to implement the methods coming from the "ILangSupport" interface.

CodeGen-Plugin-Project-Creation-11.png

  • However, there will now be other errors due to the new dependencies.

CodeGen-Plugin-Project-Creation-12.png

  • For importing the "PackageableElement" and "Class" classes, we need the "org.eclipse.uml2.uml" plug-in and, for importing the "IProject" interface, we need the "org.eclipse.core.resources" plug-in. Add them as dependencies as shown below.

CodeGen-Plugin-Project-Creation-13.png

  • Now, there must be no problem in our project.

CodeGen-Plugin-Project-Creation-14.png

The User Interface Project ("org.eclipse.papyrus.x.codegen.ui")

Here are the steps for creating and setting the "org.eclipse.papyrus.x.codegen.ui" project:

  • Create an eclipse plug-in project. name it as "org.eclipse.papyrus.x.codegen.ui" (as shown) and then click "Next >".

CodeGen-Plugin-Project-UI-Creation.png

  • Do not make any changes on the default property values and click "Finish".

CodeGen-Plugin-Project-UI-Creation-2.png

  • Upon a successful project creation, you will switch to the Plug-in Development perspective and see a window like below.

CodeGen-Plugin-Project-UI-Creation-3.png

  • The project is created. Now, we need to do the required settings for integrating this user interface project to the main code generation project. Firstly, we need to add a dependency to the "org.eclipse.papyrus.x.codegen" plug-in, in which we prepared in the previous step.

CodeGen-Plugin-Project-UI-Creation-4.png

  • Now we need to add some extensions for organizing our menus. Firstly, we add "org.eclipse.ui.menus".

CodeGen-Plugin-Project-UI-Creation-5.png

  • However, upon this addition, we may see a "No schema found for the 'org.eclipse.ui.menus' extension point" warning message as shown.

CodeGen-Plugin-Project-UI-Creation-6.png

  • In this case, we need to install "Eclipse RCP Target Components" to our eclipse.

CodeGen-Plugin-Project-UI-Creation-7.png

  • After following the installation instructions and restarting our eclipse, things will be fine.

CodeGen-Plugin-Project-UI-Creation-8.png

  • Now add a menu contribution to the extension we added and...

CodeGen-Plugin-Project-UI-Creation-9.png

  • ...set its locationURI property as "popup:org.eclipse.papyrus.views.modelexplorer.popup.codegen".

CodeGen-Plugin-Project-UI-Creation-10.png

  • Then create a command for this menu contribution and...

CodeGen-Plugin-Project-UI-Creation-11.png

  • ...set its commandID property as "org.eclipse.papyrus.x.codegen.command", label and tooltip properties as "Generate X Code".

CodeGen-Plugin-Project-UI-Creation-12.png

  • The second extension we need to add is "org.eclipse.ui.commands" and we need to create a command for it also, which has the following the properties: id as "org.eclipse.papyrus.x.codegen.command", name and description as "Generate X Code", categoryId as "org.eclipse.papyrus.editor.category" and defaultHandler as "org.eclipse.papyrus.x.codegen.ui.handlers.GenerateCodeHandler".

CodeGen-Plugin-Project-UI-Creation-13.png

  • Careful readers has already noticed that there is a warning occuring after this step (see the Problems tab on the above figure). The reason for this warning is that we defined a default handler that does not exist yet. By double-clicking to the warning, we go to source of the problem and simply fix it by creating our new handler class (keep default properties in the create class dialog window).

CodeGen-Plugin-Project-UI-Creation-14.png

  • The created handler class should extend the "CmdHandler" class which is located in the "org.eclipse.papyrus.acceleo.ui" plug-in. Thus, this plug-in should be added to the dependencies and then the unimplemented methods should be implemented.

CodeGen-Plugin-Project-UI-Creation-14-2.png

  • The last extension we need to add is "org.eclipse.ui.preferencePages". Upon creation, it comes with a default page. We need to set the properties of this page as follows: id as "org.eclipse.papyrus.x.codegen.ui.preferences.CodeGenPreferencePage", name as "X code generation", class as "org.eclipse.papyrus.x.codegen.ui.preferences.CodegenPreferencePage" and category as "org.eclipse.papyrus.infra.core.sasheditor.preferences.generalcategory".

CodeGen-Plugin-Project-UI-Creation-15.png

The Test Project ("org.eclipse.papyrus.x.codegen.tests")

Here are the steps for creating and setting the "org.eclipse.papyrus.x.codegen.tests" project:

Developing the New Code Generator

Integrating the New Code Generator to Papyrus

Back to the top