Home » Eclipse Projects » Papyrus for Real Time » Customizing code generator(How to beautify the tokens by the CodeGenerator)
|Re: Customizing code generator [message #1799105 is a reply to message #1799026]
||Thu, 29 November 2018 18:28
| Ernesto Posse
Registered: March 2011
Unfortunately this problem is a bit of a can of worms. It can be done, but it is not as easy as one would like.|
First of all, you should try to consider whether these formatting standards are truly necessary for you. The requirement that no underscores are allowed is particularly stringent, and as described bellow, if you want to change this, it will be quite difficult. If you have some automated quality testing tool that gives you warnings because it is not following the coding standards, then these would only be warnings, not show-stoppers. Furthermore, in most projects it is possible to disable such warnings or formatting standards tests for a subset of the code.
If you must apply those standards (perhaps because of mandated policy in your company) and there is no way around it, read on, but be warned that it is not trivial.
The first difficulty is that currently it is not possible to get the proper development environment for Papyrus-RT (including dependencies, target platform, build tools, etc.) so it is not possible to build a proper RCP, and at the moment all you can do is to clone the git repo (https://git.eclipse.org/r/papyrus-rt/org.eclipse.papyrus-rt.git), make the changes (outlined below) and then integrating them with one of two options:
1) compile the plugins you have changed, make them into jars with the same name and version number as the existing plugins, and add them to the "dropins" folder inside your Papyrus-RT Eclipse installation. There is a chance that Eclipse picks up the plugins under "plugins" instead of "dropins" if they have the exact same name/version/build number, in which case, delete the original ones from "plugins" and keep only the new ones under "dropins".
2) try to rebuild with Maven, but this will likely fail because of old dependencies, in which case, you are on your own to try to resolve them. (Unfortunately we are not currently maintaining it).
In either case it is not guaranteed that you will be able to compile because the proper target platform is not available anymore, so you will be on your own chasing missing/conflicting dependencies.
Ok, assuming that you still want to go ahead with the changes, here's what you need to modify:
1) To change the file extensions:
Search for ".hh" and ".cc" in the whole project, and make the changes where you find them. Currently these are the places that need to be updated:
So that means that the following plugins have to be recompiled and added to "dropins" (assuming you go for option 1 above):
Do not change the extensions found in
as these are the files of the C++ RTS (not generated), unless you change manually all those files in which case you will have to change the relevant Makefiles too.
These are in the git repo under
2) To update class/attribute/method names:
This is the really difficult one, because many of those names are built-in in the RTS, which means that if you change them, you would have to change not just the code generator, but the RTS itself (in C++), and that is a BIG task (including the fact that you have to rebuild the RTS). The RTS is in the git under
I would strongly recommend against modifying the names of the RTS, as it is a major task.
For other names, you can modify the following method:
in the following plugin:
If you change the names in the RTS you will need to change them as well in
But again, I strongly advice against making those changes, as the RTS expects certain structures with certain names in place.
So the change is not for the faint-hearted.
|Re: Customizing code generator [message #1799505 is a reply to message #1799503]
||Fri, 07 December 2018 19:30
| Ernesto Posse
Registered: March 2011
Suppose you want to use some library "mylib" with header "mylib.h". Then, in the Model Explorer select the capsule of class where you want to use it, go to the Properties view, select the "Profile" tab, and under "Applied Stereotypes" click the green [+] button. In the dialog you'll see several possible stereotypes. Select "CapsuleProperties" (or "PassiveClassProperties") and click [OK]. In the Properties view you should now see the new stereotype. Unfold it and you'll see several properties that can be customized. Select the "headerPreface" field and in the text box that appears type|
You can add any valid (header) C++ here as well.
You'll need to manually add this file (and the corresponding object file) to the generated Makefile.
There is a pattern that I like to use whenever I need to include many headers or add custom macros, which is to create a UML Artifact (right-click the Root element > New Child > Artifact), give it a name, and in the UML tab of the Properties view specify a file name for it (it will be a C++ compilation unit consisting of a header and source file). Then in the Profile tab add the "ArtifactProperties" stereotype. Once added, the stereotype has two fields "includeFile" and "sourceFile". They will be the contents of the generated header and source file respectively, so you can fill in there any C++. Once you have the Artifact, create a class diagram below the Root element (you may need to change to the "Advanced" viewpoint first by right-clicking the Root element > Switch Architecture Viewpoints > Advanced UML-RT Modeling Viewpoint). In the Advanced Viewpoint, the "New Diagram" menu will show standard UML diagrams, including the possibility of creating a Class diagram. This can be used to create inheritance relations, or in the case of Artifacts, Dependency relations: drag and drop the capsules or classes that you want to depend on the Artifact into the Class diagram, and create a Dependency edge from the relevant capsule/class to the Artifact. This will result in automatically adding the #include "Artifact.hh" in the capsule/class header.
Current Time: Fri Dec 06 22:34:53 GMT 2019
Powered by FUDForum
. Page generated in 0.02464 seconds