Functioning of the reverse tool
The scope of the Java reverse tool
The reverse tool makes it possible to parse Java source files and retrieve the model in Objecteering. The source code does not have to be compilable, but it must use valid Java language syntax. The following example should be able to be reversed:
public class MyClass {
int myAttribute = "10";
}
while this
example should not be able to be reversed:
public class MyClass {
int my Attribute = 10;
}
Classes used
A reversed class can have attributes, associations or operation parameters, whose type corresponds to the non-reversed class. If so, these classes are created empty in Objecteering, and can be reversed later.
Java/Objecteering correspondence
Certain relationships between Java and Objecteering are direct, whilst others require the creation of tagged values as shown in the list below.
|
Metaclass... |
Java
modifier... |
Tagged
value... |
|
Attribute, AssociationEnd |
final |
{JavaFinal} |
|
N/A |
transient
|
{JavaTransient} |
|
N/A |
volatile
|
{JavaVolatile}
|
|
Operation
|
synchronized
|
{JavaSynchronized}
|
|
N/A |
native |
{JavaNative} |
The constructors of a Java class, which have the name of this class in Java, are created with the <<create>> stereotype in Objecteering. As the passing mode of the parameters in Java is by reference, all the parameters of an operation, except the return parameter, have the In/Out type. A Java class may contain fields. Their type decides the reversed field that will be created as an attribute or an association. When the type is the primitive Java type or string, the field corresponds to an attribute. Otherwise, it is an association.
Correspondence with the Java primitive types
When you import an attribute or a parameter with a primitive Java type (there are eight of them), correspondence is established with Objecteering's predefined types. Certain Java type characteristics require the addition of a tagged value.
|
Primitive
Java type... |
Type in
the repository... |
Tagged
value... |
|
boolean |
boolean |
N/A |
|
char |
char |
N/A |
|
int |
integer |
N/A |
|
short |
integer |
{JavaShort}
|
|
long |
integer |
{JavaLong} |
|
byte |
integer |
{JavaByte} |
|
float |
real |
N/A |
|
double |
real |
{JavaLong} |
Automatic diagram creation
If the "Automatically create diagrams on initial reverse" parameter is active (if the tickbox has been checked), the reverse operation will automatically create the following diagrams:
· Inheritance view, showing a generalization tree for the classes of the package.
· Association view, showing associations from the classes of the package.
· Package view, showing the package and the other packages it uses.
· Class view, showing all the classes of the package.
Each time the "Java Developer/Reverse Java application from sources" command is run, new diagrams will be created after every round trip cycle, with the old diagrams being renamed using the "old" suffix.
Several classes in the same source file
Java source files can contain several classes. This type of file is retrieved in the model as follows:

Figure 96. Reverse of the "ArcTest" applet
The main class in the file is linked to other files by a use link stereotyped <<JavaFileGroup>>.
Note: If one of the classes in the file is public, it will be considered to be the main class of the file being reversed. If there is no public class, the main class is one whose name is the same as that of the file. If no class with a name corresponding to the file name is found, the first class of the file is considered to be the main class.
Processing comments during a reverse
The syntax of the Java language allows for great complexity in the positioning of comments in the source code.
Certain constructions cannot be reproduced in UML modeling. Comments present in the application source code are taken into account according to the following rules:
· All comments found before of the package directive are incorporated into the model in the form of a "JavaTop" note in the main class of the file.
· All comments preceding an import directive are incorporated in a "description" note.
· All comments preceding a class or an interface, as well as a class element, are recuperated into the corresponding model in the form of a "description" or "Javadoc" note, depending on the case.
· If the format of the comment is /** ... */ , a "Javadoc" note is created. If the format is /* ...*/ or //... a "description" note is created.
· Each comment following an attribute declaration is recuperated into a "JavaInitValueComment" note.
· Each comment preceding a static block or an initialization block is recuperated into a "JavaMembers" note with the block that it precedes.
· Each comment preceding the closure of a class is recuperated in the form of a "JavaMembers" note.
· All comments at the end of the file are recuperated in the form of a "JavaBottom" note.
· Comments present in the body of a method are recuperated with the rest of the method.
· All other comments are ignored by the reverse.
The following example illustrates all the possibilities:
/*
* This comment will be recuperated into a JavaTop note
*/
package p1.p2.p3;
/*
* This comment will be recuperated into a description
note
* on the use link that corresponds to the
import, if the
* imported element can be found.
*/
import
javax.swing.*;
/**
*This comment will be recuperated into a
Javadoc note on the
*class
*MyClass
*/
public
class MyClass {
/**
* This comment will be recuperated into a Javadoc
note on
*the attribute myAtt1
*/
int
myAtt1;
/*
* This comment will be recuperated into a
description note
*on the attribute myAtt2
*/
int
myAtt2 = 10; /* This comment will be recuperated into a
JavaInitValueComment note on myAtt2 */
/**
* This comment will be recuperated into a
Javadoc note on
*the operation method1
*/
void
myMethod1(){
// This comment will be recuperated with the method body.
}
/*
* This comment will be recuperated into a
description note
* on the
*operation method2
*/
void
myMethod2(){
/* This comment will be recuperated with the method body.
*/
}
/**
* This comment will be recuperated into a
JavaMember note
* with the static block
*/
static {
/* This comment will be recuperated with body of the static
* block. */
}
/*
* This comment will be recuperated into a
JavaMember note
* with the initialization block
*/
{
/* This comment will be recuperated with body of the
* initialization block.
*/
}
}
/**
* This comment will be recuperated into a
JavaBottom note
*/