[Uml-devel] kdesdk/umbrello/umbrello/codegenerators
Brian Thomas
thomas at mail630.gsfc.nasa.gov
Thu Apr 3 12:47:06 UTC 2003
On Thursday 03 April 2003 02:51 pm, Gustavo wrote:
> [snip]
> modeller). The following is what we think regarding code generators.
>
> What do we expect from umbrello and codegenerators:
> 1- umbrello should be able to generate code in several languages
> (already done! :-D )
> 2- I should be able to make changes to the code with any editor/IDE
> I want to, and the changes should be reflected in my diagrams.
I agree. But see comments on this below.
> 3- I should be able to make changes to my diagrams and umbrello
> should reflect those changes in the code without overwriting any method
> bodies.
I agree again, but see below.
> 4- From a QA point of view, I am very interested in codegenerators
> because they would allow me to help standarize coding (required methods,
> documentation style, license info, templates, etc). For example if the
> companys standard for C++ requires every class to have a ToXML method I can
> write my own codegenerator to implement it, that way I will not need to
> write it myself in umbrello. Later I would synchronize the diagrams with
> the code. In the future some of this maybe can be move to a code generation
> preferences dialog, but that is for another wish list.
Well the preferences dialog/code editor tool is on my wish list too. Im
planing on implementing something soon. I hope to release my updated
code generator proposal to this list by the end of this week. I guess Im
still in the "gather requirements" stage.
> 5- It would be nice if I could write a codegenerator as an .so lib
> and add it to umbrello in runtime.
This is out of my department, but I tend to believe having runtime library
for code generation unnecessary feature of Umbrello. How many people
really want to have this over say, simply downloading the source, hacking
the code to your needs and recompiling? Shared library approach is
way overkill.
> 6- Advanced codegenerators could rely on third party software to do
> their work without imposing more dependencies to the main umbrello project.
>
This is true. I am trying to see if xmi2code has any overlap that might be
used. One possible approach is for Umbrello to simply invode an xmi2code
tool configured for Umbrello code generation.
> On Thursday 03 April 2003 01:41, Sebastian Stein wrote:
> > Brian Thomas [030403 09:19]:
> > > > I don't think the user should be able to edit anything within
> > > > Umbrello, there are already plenty of text editors and IDEs to be
> > > > able to do that. Just being able to select the configuration options
> > > > that the code generator provides would make sence. And if you could
> > > > get it so it doesn't overwrite code that's already there, that would
> > > > be quite impressive.
>
> I agree, you should not bind a user to a specific editor/IDE. Plus, there
> is no reason to reinvent the wheel.
>
> > I think there are different approaches. The perfect thing would be:
> >
> > - generate code in Umbrello
> > - edit the code with an editor/IDE
> > - Umbrello notices the code changes and updates the entire modell (maybe
> > add a new class or rename something)
> >
> > I'm not if we could do this, I think it might be impossible.
Well I've been very concerned with how this could be done and you are
right, its hard. The way that I concieve of the code generators of the
future is that they work to produce "code documents" and each of these
documents is linked back to the appropriate UMLObjects in Umbrello.
Each code generation language would have a different set of code
documents, so, for a given set of UMLClass diagrams, there would be
up to 12 sets of code documents (at this time Umbrello has 12 different
languages supported).
So you can see an immediate problem: a user may only be interested
in generating code for one (or two) languages, and not the others,
which, if all are loaded when the UML diagrams are, would be simply
wasting the memory of the user's computer.
My current thinking on how to solve this is to not create the code
documents until a particular language is selected by the user and the
code editor/inspector/configuator/generator invoked. When they are
done working with the code documents for that language, then the
code document objects are released from memory and changes saved
to disk. The problem In this approach is how do we propagate changes
to the save file when UMLObjects are changed? Very difficult, if not
impossible. At this time Im looking for some commonality in the code
document classes so I can lower the amount of memory used, and all
12 (or more) code generators may be loaded into the program and
accurately be linked back into the UMLObjects to which they are
related.
One alternative approach is to add in language-specific code generation
parameters to the UMLObject dialogs and eliminate the code generation
configuration in a separate tool. When the user selects a different active
language, then all of the dialogs of the UMLdiagram would change as
appropriate, to the new language parameters. For example, the user
starts with a UML class diagram and the active language of "C++". All
class diagrams have the current parameters you can control, plus C++
specific extentions, like the ability to declare an operation "virtual". If
the user changes the active language to "Java", you can no longer
specify "virtual" on an operation since that has no meaning in Java.
The problem with this approach is that its very difficult to implement
in the current code. I had hoped to delay until Umbrello 2 this sort of
thing.
>
> I think when umbrello loads up a project file it could check for the
> generated file timestamps and if necesary synchronize the diagrams (maybe
> ask the user before?). And also add a menu option to manually synchronize
> diagrams with code. The general CodeGenerator class can keep a file with
> the timestamp data for each generated file.
>
That solves changes in state of objects that existed between changes,
but what about if you change the name of a class, attribute or operation,
how do we find it again? How about things which are deleted and perhaps
moved to another class?
> When a diagram changes code needs to be upgraded without overwriting
> current method bodies. I can think a couple of methods to do this, but why
> not leave this up to the codegenerator itself. I have not read the specific
> umbrello code, but if a file has been generated before it should not be
> overwrited before telling the codegenerator to write classes or methodsa
> again, etc. That way the codegenerator can pick the method bodies and merge
> them with the new class and method definitions.
>
> Maybe we can use commented tags to identify methods, for example for c++:
>
> //@ClassIdentifier::MethodIdentifier_BEGIN@
> Method ... bla bla
> //@ClassIdentifier::MethodIdentifier_BEGIN@
> {
> ...
> }
I dont like the tags approach because it results in non-standard code files.
I'd rather have all the code to be saved stored in a separate template file,
perferably the XMI file for the project itself.
>[snip]
>
> > But there are other solutions as well. Like that one:
> >
> > - generate code in Umbrello
> > - edit the code with an editor/IDE
> > - reload code in Umbrello and diff it to the generated one
> >
I dont like this approach because alot of the time (at least for me) when
I am designing UML class diagrams, I like to see the code generated
to help me know the impact of my abstraction and to catch errors. Having
a separate editor would slow down the process. Perhaps paramount
to the problem of this approach is that you have to support code import
tools for each language which can translate code files into UMLObjects.
Not a robust approach in my opinion.
=b.t.
--
Of course it's possible to love a human being if you don't know them too well.
-- Charles Bukowski
More information about the umbrello-devel
mailing list