Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Java Code to UML Class Diagram(How to take existing Java code and create UML Class Diagram)
Java Code to UML Class Diagram [message #1752866] Mon, 30 January 2017 05:53 Go to next message
Sean Liming is currently offline Sean LimingFriend
Messages: 2
Registered: January 2017
Junior Member
This may seem like a silly question, but if I have a Java project created through the Java perspective, how do I generate the UML Class Diagram in the Papyrus perspective?
Re: Java Code to UML Class Diagram [message #1753384 is a reply to message #1752866] Sun, 05 February 2017 14:18 Go to previous messageGo to next message
Roland Petrasch is currently offline Roland PetraschFriend
Messages: 10
Registered: September 2010
Junior Member
Just to make sure I understand you: You want to reverse engineer the java code, i.e. from the existing Java code you would like to "generate" the Class diagram, right?
May I also ask you why you want to do this? If you do something like this then you just get a visual view of the code - not more and not less. This can be helpful, but keep in mind that Java code is semantically poor in terms of software design. Example: It is sometimes hard to "detect" design patterns in reverse engineered code since the code itself provides no dedicated information about applied patterns (identifier names or comments are not analyzed by the reverse engineering tool). So you might be disappointed.

Anyway, this link might help you:
https://hudson.eclipse.org/papyrus/view/Designer/job/papyrus-designer-neon-papyrusnightly/ws/releng/org.eclipse.papyrus.designer.p2/target/repository/

[Updated on: Sun, 05 February 2017 14:20]

Report message to a moderator

Re: Java Code to UML Class Diagram [message #1753393 is a reply to message #1753384] Sun, 05 February 2017 18:46 Go to previous messageGo to next message
Sean Liming is currently offline Sean LimingFriend
Messages: 2
Registered: January 2017
Junior Member
Thanks for the reply. I just wanted to get the Class diagram to get a picture of the code. Nothing else. I just found the steps to setup Papyrus to reverse the code to UML, and it appears to be working: https://wiki.eclipse.org/Java_reverse_engineering

[Updated on: Sun, 05 February 2017 18:47]

Report message to a moderator

Re: Java Code to UML Class Diagram [message #1778953 is a reply to message #1753393] Tue, 26 December 2017 10:59 Go to previous messageGo to next message
elliott addi is currently offline elliott addiFriend
Messages: 2
Registered: December 2017
Junior Member
May i ask how you managed to do so?
I tried drag-drop of a package in a papyrus diagram. all the classes were imported, but without any links to other classes, no attributes, no methods...
Re: Java Code to UML Class Diagram [message #1779147 is a reply to message #1778953] Wed, 03 January 2018 09:02 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 461
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Hi Elliot,

which version did you use? Please note that the update site posted above (a neon nightly) is no longer supported.
For Eclipse neon, use
http://download.eclipse.org/modeling/mdt/papyrus/components/designer/neon
For oxygen
http://download.eclipse.org/modeling/mdt/papyrus/components/designer/oxygen
and an oxygen nightly build can be found here
https://hudson.eclipse.org/papyrus/job/papyrus-designer-oxygen/lastSuccessfulBuild/artifact/releng/org.eclipse.papyrus.designer.p2/target/repository/
Re: Java Code to UML Class Diagram [message #1779151 is a reply to message #1779147] Wed, 03 January 2018 09:25 Go to previous messageGo to next message
elliott addi is currently offline elliott addiFriend
Messages: 2
Registered: December 2017
Junior Member
Hi Ansgar,

Thank you for updated links. I use Eclipse Oxygen.
I'll try to reinstall papyrus tonight, hoping it work.

Happy new year btw :)
Re: Java Code to UML Class Diagram [message #1779396 is a reply to message #1752866] Sat, 06 January 2018 03:47 Go to previous message
Ri Fr is currently offline Ri FrFriend
Messages: 134
Registered: July 2015
Senior Member
Hello

below is the text of a tutorial I wrote for a UML class I teach at local university. At that time we were using Neon I think? Anyway this worked for us, hope it can help you too!
(p.s. anyone welcome to post feedback or improvements to the tutorial!)

____________________________________________________________________
System analysis with UML: an industry perspective
Tutorial on round trip engineering

Richard Freggi
Senior Supply Chain Architect
Supply Chain Strategy and Development
HP Inc.

Background
Reverse engineering means to import a software source code into a tool like Papyrus and see the software structure in Model Explorer and diagrams.
Forward engineering means to generate software source code from a model, like a Papyrus class diagram.
Round trip engineering means to go full circle starting with reverse engineering, changing the model (class diagram), then forward engineering the new source code.

Preparation
You need to install an additional module in Papyrus. A working internet connection is needed.
1. Start Papyrus, then on menu Help / Install Papyrus Additional Components
a. It takes a few minutes for papyrus to show the available components
2. Select Designer Java
a. This installs all the components needed for Java round trip engineering
b. (Note: a different component is available for C++ ((Designer-CPP))
c. Incubation means that the component is still under development: some bugs are possible
3. Click Finish or OK to all buttons including Papyrus restart
a. After restart the installation is complete

Reverse engineering a Java program
1. Make a new folder in a new location on your hard disk, call it "Engineering"
2. Inside Engineering make another folder called "Code"
3. Download the file "Code.zip" into the "Engineering" folder and unzip it
4. Papyrus Java reverse engineering works only in a Java package. To have a clear, easy to use structure we will create one Papyrus workspace containing two Papyrus projects: a Java project for reverse engineering and a Papyrus project for editing and forward engineering
a. Start Papyrus / File / Switch workspace / Other / Browse
b. Select your Engineering folder
c. Papyrus will shut down and restart in the Engineering workspace
5. File / New / Project / Java / Java Project. Call it "Reverse". Click "No" on the "Open associated perspective" menu.
6. File / New / Papyrus / Papyrus Project / UML call it "Forward" / Finish
a. We now have 2 Projects in our Project explorer
7. Import the Java source code into Papyrus. Note that you must import *.java source code, not *.class compiled binaries
a. Create a Java package in Reverse. Right click in src package in Reverse / New / Package, call it "Import"
b. Right click on the new Import package / Import / General / File system / Next / From directory / find and select the Code directory / Select all / Deselect loggerControl.txt / Finish
8. The imported classes appear on Project Explorer. They have not yet been reverse engineered (Papyrus cannot use them yet).
a. To reverse engineer, right click on the Import package / Java / Java Reverse
b. The reverse engineer menu appears. Rename the default creation package to "Forward" and click OK. The reverse engineered classes appear in a package in the Forward project. Papyrus can use these reversed classes now!
c. (Note: it is also possible to reverse engineer one class at a time by right clicking on the class)
9. Click "Save all" in menu to save your work
10. Take a look at the imported classes via Model Explorer. See the classes, associations, operations and attributes.
11. Now look at your reverse engineered classes in a class diagram
a. Right click on the Forward package / New Diagram / Class diagram
b. Select all classes and drag them to the diagram
12. Click anywhere on the diagram, press CTRL-A to select all classes on the diagram, and using Papyrus menu select Arrange All. The classes line up on the diagram
13. Making sure all classes are still selected, press CTRL-F5 or use Papyrus menu Diagram / Filters / Show/Hide compartments
a. On the first class, expand and select only attributes and operations
b. Click on Propagate selection to make all other classes the same. Click OK.
14. Now classes show the right compartments but we must tell Papyrus to show contents.
a. Making sure all classes are still selected, press F4 or use Papyrus menu Diagram / Filters / Select the elements to show. Click Select All and OK.
b. Making sure all classes are still selected, use Papyrus menu Arrange All to clean up the diagram
15. We still don't see the associations.
a. Right click anywhere on diagram / Filters / Show All Related Links
b. Now we see a generalization and an interface realization association



Forward engineering a Papyrus Java model
1. Modify the classes as you like, either via the class diagram or the Model Explorer, and Save All
2. Right click on the Forward package / Designer / Generate Java Code
3. Leave everything on the code generation menu unchanged, click Finish
4. Done! The Java class source code had been generated in a new folder in your project workspace
a. With Windows explorer go to your workspace, there will be a new folder called "org.eclipse.papyrus.javagen.RootElement"
b. Navigate into this folder to "src" folder and you will find your forward engineered Java source code there.
c. (Note: it is also possible to forward engineer one class at a time by right clicking on the class)
Previous Topic:Papyrus Java Code Generation
Next Topic:sysml palette associations
Goto Forum:
  


Current Time: Sat Apr 20 02:34:15 GMT 2024

Powered by FUDForum. Page generated in 0.03186 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top