Editing generated files
Overview
Objecteering
provides a service that maintains consistency between external text editors and
the model.
It is
possible to automatically open a dialog box on the
corresponding element in text visualizers, by double-clicking on a
generated file zone, providing that specific markers have been generated.
In the external editors, the same markers allow the Objecteering repository to be updated according to the modifications made by the user on the generated file.
Markers
You must define markers, in order to use the
edition mechanisms mentioned in the above paragraph. Without a
marker, the visualizer cannot be used to edit a generated element by
double-clicking, and it is impossible to retrieve the contents of the generated
files that have been modified by an external editor.
Markers are used to:
· call the dialog boxes from the internal view
· retrieve notes from the generated files, after external edition or during recursive retrieval
The purpose of a marker is to keep:
· the line number concerned in the generated code
· the model element that has given rise to the part of generated code
· the "style" of the identifier
Marker styles
|
The ... style |
corresponds to ... |
|
IdGen |
a text completely generated by the tool. |
|
IdBox |
a model element (Element) entered in a dialog box. |
|
IdTxt |
a text the user can modify in the generated files. |
|
IdEnd |
the end of a marker zone. There is no particular meaning attached to the corresponding type of code. |
Marker primitives
|
The ... method |
returns an identifier ... |
|
String idGen () |
which cannot be used to modify the model element in a visualizer. |
|
String idBox () |
which allows the model element to be edited thanks to a dialog box. |
|
String idTxt () |
used to modify the model element in an external editor. |
|
String idEnd () |
indicating the end of the zone containing the model element. |
|
String marker (inString depName, inString textTypeName) |
which allows the automatic creation of text on the current element during the retrieval of code after using an external editor. The "depName" parameter is the name of the dependency which points to the text we wish to create from the current element (example "Descriptor"); "textTypeName" is the name of the text type to be created (for example, "C++"). |
The markers
inserted into the text are formatted when the "mngFile()" method is called. This method
uses the following feature, which must be redefined according to the language
targeted by the generator:
MpGenProduct:default#external#MpGenProduct:getIdLineComment () return String
This method returns the string that indicates the beginning of a comment line (for example, in Java, it returns "//").
Internal visualization
MpGenProduct:default#external#MpGenProduct:intVisuFileName (in String fileName)
This method is used to call an internal visualizer in the context of the generation work product and to display a file managed by this generation work product. The "fileName" parameter is the complete name of the concerned file, including the path and suffix.
External edition
MpGenProduct:default#external#MpGenProduct:extEditFileName (in String fileName;)
This is used
to call an external visualizer in the
context of the generation work product and to thus display a file managed by
this generation work product. The
"fileName" parameter is the complete name of the concerned file,
including the path and suffix.
The extEditFileName method uses the following method to retrieve the command used to launch the editor:
String Object:default#external#Object:getEditorCommandLine ()
By default, this method returns the value of the ExtEditorCommandLine parameter. For more complex editors, the user can redefine this method on the work product.
Updating the visualizers
The visualizers contain a generated file. The user may wish to update these visualizers following a new generation, in order to update the files.
MpGenProduct:default#external#updateAllEditors ()
This is used to update all the open graphic editors.
Example 1: idGen () method
To generate the comment preceeding a class declaration:
Class:default#Code#MyGen#generateClass ()
{
String Marker;
Marker=idGen () +
" //Class declaration" +
NL +
idEnd ();
return Marker
}
Thus, during the internal visualization of the file containing this class, double-clicking on the comment will remain without effect.
Example 2: idBox () method
To generate the attributes of a class:
Attribute:default#Code#MyGen#generateAttribute ()
{
String Marker;
PartAttribute
{
Marker=Marker + idBox ()
+ getType()
+ " ; "
+ NL
+ idEnd ();
}
Return Marker
}
Therefore, when a file containing this class is being visualized internally, it will be possible to open the edition dialog box of the corresponding attribute, by double-clicking on each declaration string of an attribute.
Example 3: idTxt ()method
To generate the method code from the context of this method:
Operation:default#Code#MyProd#generateMethod ()
{
String Marker;
PartOperation
{
getOneNoteOfType ("C++")
{
Marker=Marker + idTxt ()
+ Content
+ NL
+ idEnd ();
}
}
if (Marker = "") {
Marker=marker("Descriptor" + "C++");
}
Return Marker;
}
|
If the C++ text... |
during the internal visualization ... |
during the external visualization ... |
|
existed before generation |
double-clicking on the generated code opens the edition dialog box of the "C++" text |
the code appears surrounded by the markers. It is possible to modify it, and the "C++" type text will be updated at the end of the edition in the Objecteering repository |
|
did not exist before generation |
only the markers appear, double-clicking is not effective |
Only the markers appear. If the user inserts code between the markers, a C++ type text will be automatically created at the end of the edition. |
Example 4: Internal visualization of a file
MyProduct:default#external#Code#MyGen#visualize ()
{
String fileName;
Filename=getAttributeVal("path")
+ Name,
+ getAttributeVal("suffix");
intVisuFileName (fileName);
}
Example 5: External edition of a file
MyProduct:default#external#Code#MyGen#edit ()
{
String fileName;
Filename=getAttributeVal("path")
+ Name,
+ getAttributeVal("suffix");
extEditFileName(fileName);
}