[Uml-devel] Code generation with entered code fragments

Oliver Kellogg okellogg at users.sourceforge.net
Sun Nov 25 22:19:49 UTC 2007


On Sunday 25 November 2007 21:15, Andi Fischer wrote:
> Commit 741510 implements the possibility to add source code, code
> fragments, or pseudo code to every operation and not only documentation.
> The new elements are a tab widget and a text edit widget in the
> operations section.
> The entered code (the body of the operation) is stored into the xmi-file
> and when starting code generation written to the generated source file.
> For now only Python and C# are done, the other languages will follow soon.

Nice. Sounds like this could be the start of a reimplementation of the
Advanced Code Generators (which had been causing many headaches
in the past, see e.g. bugs 84739 and 126262)

> Note: I don't know yet the right tag for the xmi-file. Can you help,
> Oliver? As you can see in the following example I use <UML:SourceCode
> value=.... />

Hmm, that's non standard and may upset XMI interoperability.
I suggest using the <codegeneration> in the <XMI.extensions>.
For your example, instead of:
>        <UML:Operation visibility="public" isSpecification="false"
>        isQuery="false" isAbstract="false" isLeaf="false" isRoot="false"
>        xmi.id="aHo5uvcmFtyg" comment="gets the name of the person."
>        name="getName" >
> [...]
>          <UML:SourceCode value="if (name_ == "TEST") {&#xa;
> return;&#xa;}" />
>         </UML:Operation>

The <UML:SourceCode> would be in the XMI.extensions:

  <codegeneration>
   <codegenerator language="C#" >
    <sourecode id="aHo5uvcmFtyg" value="if (name_ == "TEST") {&#xa;  
return;&#xa;}" />

It may be a little more work (you need to UMLDoc::findObjectById() when
loading the <sourcecode>) but it's the clean way :)

Hope this helps

Oliver

> If you use this feature now then be warned, that this may change in the
> near future and could make your xmi-file unreadable.
> But I don't think that there are a lot of users working with KDE4 -
> umbrello right now ;-).
>
> Thanks!
>
> Andi




More information about the umbrello-devel mailing list