Book a Demo

Author Topic: Importing Gosu Code into Sparx EA  (Read 2960 times)

kajal

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Importing Gosu Code into Sparx EA
« on: May 30, 2022, 04:57:08 am »
Goal: To be able to import and reverse engineer Gosu code into Enterprise Architect. Gosu is a language based off of Java.

Method: Enterprise Architect provides reverse engineering support for a number of popular programming languages. However, if the language you are using is not supported, you can write your own grammar for it, using the in-built Grammar Editor. You can then incorporate the grammar into an MDG Technology to provide both reverse engineering support for your target language (source).

Problem: When I reverse engineer Gosu code, the classes get created correctly. The fields also get created in the diagram with the correct icon, type, and scope but the field’s name does not show up. It looks like this:

https://imgur.com/72z05E7 code being reverse engineered ----------> https://imgur.com/a/JVXzBv2

Steps Taken (not including debugging steps):
1.   Add Coding data types for the new language
2.   Create the grammar for the language
3.   Make the profiles and the model patterns
4.   Create the MDG
5.   Import the MDG into a new project. Create a diagram using the newly created MDG.
6.   Import Gosu code and reverse engineer.

How I’ve tried to debug:
-   I used the Grammar Debugger in EA’s grammar editor throughout the process.
-   Stepped through the ‘Profiler Results’ to make sure the correct sequence of events was taking place (it was).
-   Looked through the Sparx Forum for similar cases (couldn’t find anything).
-   Created a diagram to replicate the AST node information found here. Made sure the correct Nodes and sub-nodes are being created (with the multipolicy in mind).
-   I have been deleting and recreating the MDG xml after I update the grammar to make sure that it’s using the correct grammar file.
-   I’ve tried a lot of debugging strategies, including reaching out to a coworker. After all the debugging I think the AST is correct. Most notably because:
o   I imported the sample Java grammar provided by EA and used the Grammar Debugger to look at the AST. The ASTs created by the java grammar and the Gosu grammar were identical. When I reverse engineered the same piece of code (as the in the screenshot above) by selecting the Java option, the field’s name (and all other information) shows up as expected in the diagram.

My Conclusion:
-   As stated earlier, I think the grammar and AST tree is correct. The issue might be:
o   Occurring when the AST is converted into the diagram. Is there any way to get insight into this process?
o   There is a problem with the way my MDG is defined. I’m not sure what the link is between the MDG profiles and the reverse engineering. To my knowledge, the MDG just allows for a grammar to be defined but isn’t related to the reverse engineering process. Is this correct?

If you think you can help me then I can email you the:
-   xml for the MDG I created.
-   Gosu grammar file I created.

Please let me know if any further information would be useful. Thank you for your help!
« Last Edit: May 30, 2022, 05:01:50 am by kajal »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8105
  • Karma: +119/-20
    • View Profile
Re: Importing Gosu Code into Sparx EA
« Reply #1 on: May 30, 2022, 08:13:46 am »
The only real place it can be is that the AST doesn't match what EA is expecting. Can you share here what the AST from that sample looks like?

Edit: Just to be clear. I did read you saying that you believe it is right. That AST is the only thing EA looks at to create the model, so if the code parses completely and the model is wrong that's the only possible answer.
« Last Edit: May 30, 2022, 08:16:50 am by Eve »

kajal

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Importing Gosu Code into Sparx EA
« Reply #2 on: June 18, 2022, 06:10:16 am »
Hello Eve,

This is the resulting AST: https://imgur.com/a/VRZbPGF

Thank you for your help  :)

Jeff Hegedus

  • EA Novice
  • *
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: Importing Gosu Code into Sparx EA
« Reply #3 on: June 19, 2022, 12:28:58 am »
@kajal, I saw this in your post

Quote
There is a problem with the way my MDG is defined. I’m not sure what the link is between the MDG profiles and the reverse engineering. To my knowledge, the MDG just allows for a grammar to be defined but isn’t related to the reverse engineering process. Is this correct?

I hope I've understood your situation and am not telling you something you already know. Risking that, the link is that the MDG must include the grammar and a language definition using that grammar in order for the grammar to be available for reverse engineering. You can take a look at an MDG that I have here - https://github.com/jjhegedus/jaackd-ea. It is mostly working with an extension of the C# example grammar that comes with EA. At some point I'll write up some docs but hopefully it will help.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8105
  • Karma: +119/-20
    • View Profile
Re: Importing Gosu Code into Sparx EA
« Reply #4 on: June 21, 2022, 08:22:08 am »
https://sparxsystems.com/enterprise_architect_user_guide/16.0/modeling_domains/context_labels.html

The problem is the NAME/NAMEPART in the FIELD node. Changing that to a single NAME attribute should correct the problem.