Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Java Code Reverse Developer Guide"

(Created page with "== Overview == Papyrus provides an extra plugin named ''org.eclipse.papyrus.java.reverse'' which allows to generate papyrus model from java source code. It is divided in 3 pr...")
 
m (Capitalization, punctuation, spelling, and grammar edits.)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
== Overview ==
 
== Overview ==
Papyrus provides an extra plugin named ''org.eclipse.papyrus.java.reverse''  which allows to generate papyrus model from java source code.
+
Papyrus provides an extra plugin named ''org.eclipse.papyrus.java.reverse''  which can reverse-engineer a Papyrus model from Java source code.
 
It is divided in 3 projects:
 
It is divided in 3 projects:
  
 
*'''reverse''' : parse and visit the Eclipse AST of the reversed project.
 
*'''reverse''' : parse and visit the Eclipse AST of the reversed project.
*'''reverse.ui''' : provides user graphical interface to run the reverse plugin
+
*'''reverse.ui''' : provides the user graphical interface to run the reverse plugin
 
*'''reverse.utils''' : provides handlers for reverse.
 
*'''reverse.utils''' : provides handlers for reverse.
  
 
== Dependencies ==
 
== Dependencies ==
The following schema shows dependencies between java code reverse plugins:
+
The following schema shows dependencies between Java code reverse plugins:
  
 
[[Image:JavaCodeReverseDependenciesDiagram.png]]
 
[[Image:JavaCodeReverseDependenciesDiagram.png]]
  
 
== reverse ==
 
== reverse ==
The reverse project uses the japa parser to visit the Eclipse AST (Abstract Syntax Tree). This AST allows to plugin to add reverse action for each element (project, class, field, method etc.). For more details, please see the [https://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation_AST/index.html Eclipse AST]   
+
The reverse project uses the japa parser to visit the Eclipse AST (Abstract Syntax Tree). This AST allows the plugin to add reverse action for each element (project, class, field, method etc.). For more details, please see the [https://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation_AST/index.html Eclipse AST]   
  
In particular, it use a Catalog to find already existing uml components (for example a previous reverse result), and just add non existing components.   
+
In particular, it uses a Catalog to find preexisting UML components (for example from a previous reverse-engineering action), and only add the non-existing components.   
Note that, as it never remove any component, it leave components of a previous reverse, even if java source code doesn’t exist anymore (for example if user remove this code).
+
Note that, as it never removes any component, it leaves components of previous reverse-engineering actions, even if Java source code does not exist anymore (for example, if user removes this code).
  
 
== ui ==
 
== ui ==
The ui project provides Eclipse user interface for the entire plugin. It is divided in two parts:
+
The ui project provides the Eclipse user interface for the entire plugin. It is divided into two parts:
 
*Handlers, which call commands:
 
*Handlers, which call commands:
**ReverseCodeHandler, which call the reverse command,
+
**ReverseCodeHandler, which calls the reverse command,
**CreateAssociationFromPropertyHandler, which find association of a component.
+
**CreateAssociationFromPropertyHandler, which finds associations of a component.
*plugin.xml, which contains buttons, pop menu … . Each component call an handler. Morehover, there components are only available when selected resource is generable, according to xml « when » condition.
+
*plugin.xml, which contains buttons, pop menu … . Each component calls a handler. Moreover, the components are only available when the selected resource is generatable, according to XML « when » condition.
 +
 
 +
=== drag and drop ===
 +
A drag & drop way to reverse is implemented. It is decomposed into:
 +
* '''DndReverseCodeDialog''': a popup dialog extends from ReverseCodeDialog, which just adds some buttons to allow a user to display or not display reverse-engineered components in a diagram,
 +
* '''DndReverseCodeHandler''': a special handler which searches for reverse-engineered elements to display in a class diagram.
 +
* '''DropReverseCommand''' & '''DropReverseStrategy''', which checks if drag & drop is possible. It is possible if (please see DropReverseCommand.canExecute() ):
 +
** selected Java resources are only composed by Compilation Unit (Classes, Interfaces, Enumerations), packages, and Java source folder. Any other item (a Papyrus model file for example) automatically disables the drag and drop.
 +
** Selection is dropped into a Papyrus diagram.
  
 
== Class Diagram ==
 
== Class Diagram ==
 +
The following is a class diagram of this plugin. While it doesn't show every class of the project, it offers a good overview of the main classes.
 
[[Image:JavaCodeReverseClassDiagram.png]]
 
[[Image:JavaCodeReverseClassDiagram.png]]

Latest revision as of 18:29, 16 January 2015

Overview

Papyrus provides an extra plugin named org.eclipse.papyrus.java.reverse which can reverse-engineer a Papyrus model from Java source code. It is divided in 3 projects:

  • reverse : parse and visit the Eclipse AST of the reversed project.
  • reverse.ui : provides the user graphical interface to run the reverse plugin
  • reverse.utils : provides handlers for reverse.

Dependencies

The following schema shows dependencies between Java code reverse plugins:

JavaCodeReverseDependenciesDiagram.png

reverse

The reverse project uses the japa parser to visit the Eclipse AST (Abstract Syntax Tree). This AST allows the plugin to add reverse action for each element (project, class, field, method etc.). For more details, please see the Eclipse AST

In particular, it uses a Catalog to find preexisting UML components (for example from a previous reverse-engineering action), and only add the non-existing components. Note that, as it never removes any component, it leaves components of previous reverse-engineering actions, even if Java source code does not exist anymore (for example, if user removes this code).

ui

The ui project provides the Eclipse user interface for the entire plugin. It is divided into two parts:

  • Handlers, which call commands:
    • ReverseCodeHandler, which calls the reverse command,
    • CreateAssociationFromPropertyHandler, which finds associations of a component.
  • plugin.xml, which contains buttons, pop menu … . Each component calls a handler. Moreover, the components are only available when the selected resource is generatable, according to XML « when » condition.

drag and drop

A drag & drop way to reverse is implemented. It is decomposed into:

  • DndReverseCodeDialog: a popup dialog extends from ReverseCodeDialog, which just adds some buttons to allow a user to display or not display reverse-engineered components in a diagram,
  • DndReverseCodeHandler: a special handler which searches for reverse-engineered elements to display in a class diagram.
  • DropReverseCommand & DropReverseStrategy, which checks if drag & drop is possible. It is possible if (please see DropReverseCommand.canExecute() ):
    • selected Java resources are only composed by Compilation Unit (Classes, Interfaces, Enumerations), packages, and Java source folder. Any other item (a Papyrus model file for example) automatically disables the drag and drop.
    • Selection is dropped into a Papyrus diagram.

Class Diagram

The following is a class diagram of this plugin. While it doesn't show every class of the project, it offers a good overview of the main classes. JavaCodeReverseClassDiagram.png

Back to the top