Jump to: navigation, search

Difference between revisions of "MoDisco/Components/Java/Documentation/0.8"

(Description)
Line 1: Line 1:
{{MoDiscoJavaTabs}}
+
{{MoDiscoJavaTabs}}  
  
== Java metamodel ==
+
== Java metamodel ==
  
The Java metamodel : it is the reflection of the Java language, as defined in version 3 of "Java Language Specification" from Sun Microsystems ("JLS3" corresponds to JDK 5).
+
The Java metamodel : it is the reflection of the Java language, as defined in version 3 of "Java Language Specification" from Sun Microsystems ("JLS3" corresponds to JDK 5).  
  
The Java metamodel contains 126 metaclasses.
+
The Java metamodel contains 126 metaclasses. To better understand it, this page will introduce its main features (metaclasses and links).  
To better understand it, this page will introduce its main features (metaclasses and links).
+
  
You could also browse the model definition, java.ecore available in sources (see [[#Install| install section]]).
+
You could also browse the model definition, java.ecore available in sources (see [[#Install|install section]]).  
  
A good tip is also to see the [http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/package-summary.html javadoc] associated to the metamodel implemented by the Eclipse team in the [[JDT| JDT (Java Development Tool)]] project. This metamodel and Java are very similar.
+
A good tip is also to see the [http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/package-summary.html javadoc] associated to the metamodel implemented by the Eclipse team in the [[JDT|JDT (Java Development Tool)]] project. This metamodel and Java are very similar.  
  
 +
<br>
  
=== Main metaclasses ===
+
=== Main metaclasses ===
  
==== ASTNode ====
+
==== ASTNode ====
  
Every metaclass (apart from the '''Model''' metaclass) inherits from ASTNode.
+
Every metaclass (apart from the '''Model''' metaclass) inherits from ASTNode. As its name indicates, ASTNode represents a graph node. ASTNode has a reference to the Comment metaclass because almost every java element can be associated to a comment (block or line comment and Javadoc). More details in the [[#Zoom_on_comments|"Comment" section]].  
As its name indicates, ASTNode represents a graph node.
+
ASTNode has a reference to the Comment metaclass because almost every java element can be associated to a comment (block or line comment and Javadoc). More details in the [[#Zoom on comments| "Comment" section]].
+
  
[[Image:MoDisco-Java metaclass ASTNode.png|frame|center|ASTNode metaclass]]
+
[[Image:MoDisco-Java metaclass ASTNode.png|frame|center|ASTNode metaclass]]  
  
==== Model, Package, AbstractTypeDeclaration ====
+
==== Model, Package, AbstractTypeDeclaration ====
  
The root element of each Java model is an instance of the "Model" metaclass. It is a translation of the concept of java application, so it contains package declarations (instances of the Package metaclass). And package declarations contain type declarations (instances compatible with the AbstractTypeDeclaration metaclass), and so on...
+
The root element of each Java model is an instance of the "Model" metaclass. It is a translation of the concept of java application, so it contains package declarations (instances of the Package metaclass). And package declarations contain type declarations (instances compatible with the AbstractTypeDeclaration metaclass), and so on...  
  
[[Image:MoDisco-Java metaclass Model Package.jpg|frame|center|Model, Package & type declaration superclass]]
+
[[Image:MoDisco-Java metaclass Model Package.jpg|frame|center|Model, Package & type declaration superclass]]  
  
==== NamedElement & notion of Proxy ====
+
==== NamedElement &amp; notion of Proxy ====
  
A lot of java elements are "named", and this name could be considered as an identifier : methods, packages, types, variables, fields, ...
+
A lot of java elements are "named", and this name could be considered as an identifier&nbsp;: methods, packages, types, variables, fields, ... So all the corresponding metaclasses inherit from the NamedElement metaclass.  
So all the corresponding metaclasses inherit from the NamedElement metaclass.
+
  
Another goal of this metaclass is to indicate whether an element is part of the current Java application or not (element from an external library of from the JDK). So, external elements are tagged as proxy through a dedicated attribute and can be easily filtered.
+
Another goal of this metaclass is to indicate whether an element is part of the current Java application or not (element from an external library of from the JDK). So, external elements are tagged as proxy through a dedicated attribute and can be easily filtered. For example, instruction "System.out.println" has been decomposed into three named elements (one class, one variable and one method) the definitions of which are not part of the current Java application. So attribute "proxy" of these elements has been initialized to true.  
For example, instruction "System.out.println" has been decomposed into three named elements (one class, one variable and one method) the definitions of which are not part of the current Java application. So attribute "proxy" of these elements has been initialized to true.
+
  
[[Image:MoDisco-Java metaclass NamedElement and its hierarchy.png|frame|center|NamedElement and its hierarchy]]
+
[[Image:MoDisco-Java metaclass NamedElement and its hierarchy.png|frame|center|NamedElement and its hierarchy]]  
  
==== TypeAccess, PackageAccess, SingleVariableAccess, UnresolvedItemAccess ====
+
==== TypeAccess, PackageAccess, SingleVariableAccess, UnresolvedItemAccess ====
  
To represent links between Java elements, metaclasses TypeAccess, PackageAccess, SingleVariableAccess and UnresolvedItemAccess were introduced. Each allows to navigate directly to a NamedElement (proxy or not) in the graph.
+
To represent links between Java elements, metaclasses TypeAccess, PackageAccess, SingleVariableAccess and UnresolvedItemAccess were introduced. Each allows to navigate directly to a NamedElement (proxy or not) in the graph.  
  
A TypeAccess represents a reference on a type.
+
A TypeAccess represents a reference on a type. [[Image:MoDisco-Java metaclass TypeAccess.png|frame|center|TypeAccess]]  
[[Image:MoDisco-Java metaclass TypeAccess.png|center|frame|TypeAccess]]
+
  
A PackageAccess represents a reference on a package.
+
A PackageAccess represents a reference on a package. [[Image:MoDisco-Java metaclass PackageAccess.png|frame|center|PackageAccess]]  
[[Image:MoDisco-Java metaclass PackageAccess.png|center|frame|PackageAccess]]
+
  
A SingleVariableAccess represents a reference on a variable.
+
A SingleVariableAccess represents a reference on a variable. [[Image:MoDisco-Java metaclass SingleVariableAccess.png|frame|center|SingleVariableAccess]]  
[[Image:MoDisco-Java metaclass SingleVariableAccess.png|center|frame|SingleVariableAccess]]
+
  
On the contrary, references to methods are direct.
+
On the contrary, references to methods are direct. [[Image:MoDisco-Java metaclass MethodDeclaration MethodInvocation.png|frame|center|MethodInvocation]]  
[[Image:MoDisco-Java metaclass MethodDeclaration MethodInvocation.png |frame|center|MethodInvocation]]
+
  
==== BodyDeclaration ====
+
==== BodyDeclaration ====
  
A type declaration has different kinds of contents : fields, methods, static block, initialization block or other type declarations. All of these elements are of type BodyDeclaration metaclass.
+
A type declaration has different kinds of contents&nbsp;: fields, methods, static block, initialization block or other type declarations. All of these elements are of type BodyDeclaration metaclass.  
  
[[Image:MoDisco-Java metaclass BodyDeclaration and its hierarchy.png|frame|center|BodyDeclaration and its hierarchy]]
+
[[Image:MoDisco-Java metaclass BodyDeclaration and its hierarchy.png|frame|center|BodyDeclaration and its hierarchy]]  
  
==== Expressions ====
+
==== Expressions ====
  
Like in many languages, the concept of expression exists in Java : it is a portion of code, without declarations, and its evaluation returns a value, numerical or boolean or other ...
+
Like in many languages, the concept of expression exists in Java&nbsp;: it is a portion of code, without declarations, and its evaluation returns a value, numerical or boolean or other ... For example, <source lang="java">++i</source> is an expression and it will be translated to the concept of PrefixExpression metaclass. All types of expressions shall inherit from the Expression metaclass.  
For example, <source lang="java">++i</source> is an expression and it will be translated to the concept of PrefixExpression metaclass.
+
All types of expressions shall inherit from the Expression metaclass.
+
  
[[Image:MoDisco-J2SE5 metaclass Expression and its hierarchy.jpg|frame|center|Expression and its hierarchy]]
+
[[Image:MoDisco-J2SE5 metaclass Expression and its hierarchy.jpg|frame|center|Expression and its hierarchy]]  
  
==== Statements ====
+
==== Statements ====
  
An "instruction" in Java is represented by the Statement metaclass. A block of code (Block metaclass) contains a collection of statements, and a block of code may be contained by a method.
+
An "instruction" in Java is represented by the Statement metaclass. A block of code (Block metaclass) contains a collection of statements, and a block of code may be contained by a method. Some examples of statements in java&nbsp;: <source lang="java">if, while, for, do, ...</source> All of their definitions use the concept of expression to separate the value from the instruction keyword.  
Some examples of statements in java : <source lang="java">if, while, for, do, ...</source>
+
All of their definitions use the concept of expression to separate the value from the instruction keyword.
+
  
[[Image:MoDisco-J2SE5 metaclass Statement and its hierarchy.jpg|frame|center|Statement and its hierarchy]]
+
[[Image:MoDisco-J2SE5 metaclass Statement and its hierarchy.jpg|frame|center|Statement and its hierarchy]]  
  
==== Zoom on comments ====
+
==== Zoom on comments ====
  
There are three kinds of comments : line comments (//), block comments (/* */) and javadoc comments (/** */).
+
There are three kinds of comments&nbsp;: line comments (//), block comments (/* */) and javadoc comments (/** */). Every comment contains text fragments, but we can have more information on javadoc comments (Javadoc metaclass): they can also contain javadoc tags that are identified and collected through instances of the TagElement metaclass.  
Every comment contains text fragments, but we can have more information on javadoc comments (Javadoc metaclass): they can also contain javadoc tags that are identified and collected through instances of the TagElement metaclass.
+
  
[[Image:MoDisco-Java metaclass Comment and its hierarchy.png|frame|center|Comment and its hierarchy]]
+
[[Image:MoDisco-Java metaclass Comment and its hierarchy.png|frame|center|Comment and its hierarchy]]  
  
==== Zoom on annotations ====
+
==== Zoom on annotations ====
  
Official usage of annotations has been introduced in version 5 of the JDK.
+
Official usage of annotations has been introduced in version 5 of the JDK. To handle them, annotation declarations are managed as type declarations (AnnotationTypeDeclaration metaclass) with specific attributes (AnnotationTypeMemberDeclaration metaclass). And annotation usages are translated into instances of the Annotation metaclass, which reference corresponding annotation declarations. And parameters are translated into instances of the MemberValuePair metaclass. Some statements also have a list of annotations.  
To handle them, annotation declarations are managed as type declarations (AnnotationTypeDeclaration metaclass) with specific attributes (AnnotationTypeMemberDeclaration metaclass).
+
And annotation usages are translated into instances of the Annotation metaclass, which reference corresponding annotation declarations. And parameters are translated into instances of the MemberValuePair metaclass.
+
Some statements also have a list of annotations.
+
  
[[Image:MoDisco-Java metaclass AnnotationTypeDeclaration and Annotation.png|frame|center|Annotation]]
+
[[Image:MoDisco-Java metaclass AnnotationTypeDeclaration and Annotation.png|frame|center|Annotation]]  
  
==== Zoom on generics ====
+
==== Zoom on generics ====
  
Version 5 of the JDK also introduced the concept of "generics".
+
Version 5 of the JDK also introduced the concept of "generics". Generic types of method declarations are translated into instances of TypeDeclaration of AbstractMethodDeclaration metaclass with arguments as instances of the TypeParameter metaclass. Uses of these generics are translated into instances of the ParameterizedType metaclass which reference concrete elements (type and type arguments).  
Generic types of method declarations are translated into instances of TypeDeclaration of AbstractMethodDeclaration metaclass with arguments as instances of the TypeParameter metaclass.
+
Uses of these generics are translated into instances of the ParameterizedType metaclass which reference concrete elements (type and type arguments).
+
  
A specific case of type argument is the "wildcard" (for example "<? extends X>"). There is a specific metaclass to handle it : WildCardType.
+
A specific case of type argument is the "wildcard" (for example "&lt;? extends X&gt;"). There is a specific metaclass to handle it&nbsp;: WildCardType.  
  
[[Image:MoDisco-Java generics declarations and usages.png|frame|center|Generics]]
+
[[Image:MoDisco-Java generics declarations and usages.png|frame|center|Generics]]  
  
=== Requirements ===
+
=== Requirements ===
  
To use the plug-in you need:
+
To use the plug-in you need:  
* JDK 1.5 or above
+
* a version of Eclipse 3.3 or above with the following set of plug-ins installed
+
:* [[EMF|EMF]] 2.3.0 or higher
+
  
=== Source Repository ===
+
*JDK 1.5 or above
 +
*a version of Eclipse 3.3 or above with the following set of plug-ins installed
  
All of the source code is stored in a public source repository, which you can access at:
+
:*[[EMF|EMF]] 2.3.0 or higher
  
[https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java/ https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java/]
+
=== Source Repository  ===
  
=== Associated Discoverers ===
+
All of the source code is stored in a public source repository, which you can access at:
  
The main discoverer available for this metamodel : [[MoDisco/Java/Documentation/0.8#Java_Discoverer|Java Discoverer]]
+
[https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java/ https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java/]  
  
== Java Discoverer ==
+
=== Associated Discoverers  ===
  
The goal of the Java Discoverer plug-in is to allow practical extractions of [[MoDisco/Java|Java models]] from Java projects.
+
The main discoverer available for this metamodel&nbsp;: [[MoDisco/Java/Documentation/0.8#Java_Discoverer|Java Discoverer]]  
  
=== Description ===
+
== Java Discoverer  ==
  
This plug-in aims at analyzing Java source code compliant with version 3 of "Java Language Specification" from Sun Microsystems and providing a model describing the information found, conforming to the [[MoDisco/Java|Java metamodel]].
+
The goal of the Java Discoverer plug-in is to allow practical extractions of [[MoDisco/Java|Java models]] from Java projects.  
  
A [[MoDisco/Java|Java model]] contains the full abstract syntax tree of the Java program: each statement such as attribute definition, method invocation or loop is described. In addition, links between elements are resolved (by resolved link we mean for instance a link between a method invocation and the declaration of this method, or between the usage of a variable and its declaration). The model can thus be seen as an abstract syntax graph (ASG).
+
=== Description  ===
  
=== Requirements ===
+
This plug-in aims at analyzing Java source code compliant with version 3 of "Java Language Specification" from Sun Microsystems and providing a model describing the information found, conforming to the [[MoDisco/Java|Java metamodel]].
  
To use the plug-in you need:
+
A [[MoDisco/Java|Java model]] contains the full abstract syntax tree of the Java program: each statement such as attribute definition, method invocation or loop is described. In addition, links between elements are resolved (by resolved link we mean for instance a link between a method invocation and the declaration of this method, or between the usage of a variable and its declaration). The model can thus be seen as an abstract syntax graph (ASG).  
* JDK 1.5 or above
+
* a version of Eclipse 3.3 or above with the following set of plug-ins installed
+
:* [[EMF|EMF]] 2.3.0 or higher
+
:* [[ATL|ATL]] 2.0.0 or higher
+
:* [[MoDisco/Java|Java metamodel]]
+
  
=== Source Repository ===
+
=== Requirements  ===
  
All of the source code is stored in a public source repository, which you can access at:
+
To use the plug-in you need:  
  
[https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java.discoverer/ https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java.discoverer/]
+
*JDK 1.5 or above
 +
*a version of Eclipse 3.3 or above with the following set of plug-ins installed
  
=== User manual ===
+
:*[[EMF|EMF]] 2.3.0 or higher
 +
:*[[ATL|ATL]] 2.0.0 or higher
 +
:*[[MoDisco/Java|Java metamodel]]
  
The plug-in provides the user with a contextual menu to easily create models.
+
=== Source Repository  ===
  
By right-clicking on a Java Project in the Eclipse Package Explorer view, you can quickly create the Java model of your application (see next Figure).
+
All of the source code is stored in a public source repository, which you can access at:
  
[[Image:MoDisco-JavaDiscoverer popup.png|frame|center|Menus in Eclipse to create model from source code]]
+
[https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java.discoverer/ https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java.discoverer/]  
  
A progress bar will appear at the bottom of the window as soon as the operation begins. Depending on the size of your application, the reverse engineering process might take some time to complete (see next Figure).
+
=== User manual  ===
  
[[Image:MoDisco-JavaDiscoverer progress bar model creation.png|frame|center|Progress bar during model creation]]
+
The plug-in provides the user with a contextual menu to easily create models.  
  
At the end of the process, the newly created model files are added to the root of your project and are automatically opened in the default editor (see next Figure).
+
By right-clicking on a Java Project in the Eclipse Package Explorer view, you can quickly create the Java model of your application (see next Figure).
 +
 
 +
[[Image:MoDisco-JavaDiscoverer popup.png|frame|center|Menus in Eclipse to create model from source code]]
 +
 
 +
A discovery parameter window proposes to
 +
 
 +
  * indicate to extend the analysis to required Java projects and libraries
 +
  * indicate to limit the analysis to types/fields/methods declarations (no Java statements/expressions analysis)
 +
  * indicate a filter to exclude some Java packages from analysis
 +
 
 +
[[Image:DiscoveryParameters.PNG|center]]
 +
 
 +
Once launched, a progress bar will appear at the bottom of the window as soon as the operation begins. Depending on the size of your application, the reverse engineering process might take some time to complete (see next Figure).
 +
 
 +
[[Image:MoDisco-JavaDiscoverer progress bar model creation.png|frame|center|Progress bar during model creation]]
 +
 
 +
At the end of the process, the newly created model files are added to the root of your project and are automatically opened in the default editor (see next Figure).  
  
 
[[Image:MoDisco-JavaDiscoverer Java model.png|frame|center|Java model in the package explorer]]  
 
[[Image:MoDisco-JavaDiscoverer Java model.png|frame|center|Java model in the package explorer]]  
  
.javaxmi files can be opened in the Sample Ecore Model Editor (see next Figure).
+
.javaxmi files can be opened in the Sample Ecore Model Editor (see next Figure).  
 +
 
 +
[[Image:MoDisco-JavaDiscoverer Java in EMF browser.png|frame|center|Java model viewed with EMF browser]]
  
[[Image:MoDisco-JavaDiscoverer Java in EMF browser.png|frame|center|Java model viewed with EMF browser]]
+
They can also be opened in the MoDisco model browser (see next Figure) which brings some graphical improvements.  
  
They can also be opened in the MoDisco model browser (see next Figure) which brings some graphical improvements.
+
[[Image:MoDisco-JavaDiscoverer example Java SimpleModel.jpg|frame|center|Java model viewed with MoDisco browser]]
  
[[Image:MoDisco-JavaDiscoverer example Java SimpleModel.jpg|frame|center|Java model viewed with MoDisco browser]]
+
== Java Generation  ==
  
== Java Generation ==
+
The goal of the Java Generation plug-in is to allow Java code generation from a Java model. Such a generation will fulfill some of the requirements for Legacy refactoring &amp; migration.
  
The goal of the Java Generation plug-in is to allow Java code generation from a Java model. Such a generation will fulfill some of the requirements for Legacy refactoring & migration.
+
=== Description  ===
  
=== Description ===
+
[[Image:JavaM2T.PNG|frame|center]]
  
[[Image:JavaM2T.PNG|frame|center|]]
+
This plug-in proposes [[Acceleo|Acceleo MTL]] modules for generating Java files conforming to Java models. Templates are contained in two modules&nbsp;:
  
This plug-in proposes [[Acceleo|Acceleo MTL]] modules for generating Java files conforming to Java models.
+
*Structures modules&nbsp;: top level templates for generating classes/method/field declarations  
Templates are contained in two modules :
+
*Statements modules
* Structures modules : top level templates for generating classes/method/field declarations
+
* Statements modules
+
  
Java models are obtained with [[MoDisco/Java/Documentation/0.8#Java_Discoverer|Java Discoverer]] component.
+
Java models are obtained with [[MoDisco/Java/Documentation/0.8#Java_Discoverer|Java Discoverer]] component.  
  
Considering a Java legacy, a minimal migration/refactoring chain will involve :
+
Considering a Java legacy, a minimal migration/refactoring chain will involve&nbsp;:  
  
* A Java model discovery step
+
*A Java model discovery step  
* A m2m transformation step
+
*A m2m transformation step  
* A Java generation code step with the current component
+
*A Java generation code step with the current component
  
=== User manual ===
+
=== User manual ===
  
A prerequisite is a Java model. Please refer to the Java Discoverer user manual.
+
A prerequisite is a Java model. Please refer to the Java Discoverer user manual.  
  
To launch Java generation :
+
To launch Java generation&nbsp;:  
  
* Create an Accelo launch configuration pointing to ''Generate_JavaStructures'' java class, and specify the input model and target folder (require a checkout or import of the ''org.eclipse.gmt.modisco.java.generation'' into the workspace).
+
*Create an Accelo launch configuration pointing to ''Generate_JavaStructures'' java class, and specify the input model and target folder (require a checkout or import of the ''org.eclipse.gmt.modisco.java.generation'' into the workspace).
  
Or
+
Or  
  
* Add ''org.eclipse.gmt.modisco.java.generation'' in your plugin dependencies and use the ''Generate_JavaStructures'' main method with input model and target folder as parameters.
+
*Add ''org.eclipse.gmt.modisco.java.generation'' in your plugin dependencies and use the ''Generate_JavaStructures'' main method with input model and target folder as parameters.
  
 
[[Category:MoDisco]]
 
[[Category:MoDisco]]

Revision as of 08:55, 2 February 2010

DEPRECATED use Template:MoDiscoTabs and Template:MoDiscoTab as explain here : Wiki Template for MoDisco

Java metamodel

The Java metamodel : it is the reflection of the Java language, as defined in version 3 of "Java Language Specification" from Sun Microsystems ("JLS3" corresponds to JDK 5).

The Java metamodel contains 126 metaclasses. To better understand it, this page will introduce its main features (metaclasses and links).

You could also browse the model definition, java.ecore available in sources (see install section).

A good tip is also to see the javadoc associated to the metamodel implemented by the Eclipse team in the JDT (Java Development Tool) project. This metamodel and Java are very similar.


Main metaclasses

ASTNode

Every metaclass (apart from the Model metaclass) inherits from ASTNode. As its name indicates, ASTNode represents a graph node. ASTNode has a reference to the Comment metaclass because almost every java element can be associated to a comment (block or line comment and Javadoc). More details in the "Comment" section.

ASTNode metaclass

Model, Package, AbstractTypeDeclaration

The root element of each Java model is an instance of the "Model" metaclass. It is a translation of the concept of java application, so it contains package declarations (instances of the Package metaclass). And package declarations contain type declarations (instances compatible with the AbstractTypeDeclaration metaclass), and so on...

Model, Package & type declaration superclass

NamedElement & notion of Proxy

A lot of java elements are "named", and this name could be considered as an identifier : methods, packages, types, variables, fields, ... So all the corresponding metaclasses inherit from the NamedElement metaclass.

Another goal of this metaclass is to indicate whether an element is part of the current Java application or not (element from an external library of from the JDK). So, external elements are tagged as proxy through a dedicated attribute and can be easily filtered. For example, instruction "System.out.println" has been decomposed into three named elements (one class, one variable and one method) the definitions of which are not part of the current Java application. So attribute "proxy" of these elements has been initialized to true.

NamedElement and its hierarchy

TypeAccess, PackageAccess, SingleVariableAccess, UnresolvedItemAccess

To represent links between Java elements, metaclasses TypeAccess, PackageAccess, SingleVariableAccess and UnresolvedItemAccess were introduced. Each allows to navigate directly to a NamedElement (proxy or not) in the graph.

A TypeAccess represents a reference on a type.
TypeAccess
A PackageAccess represents a reference on a package.
PackageAccess
A SingleVariableAccess represents a reference on a variable.
SingleVariableAccess
On the contrary, references to methods are direct.
MethodInvocation

BodyDeclaration

A type declaration has different kinds of contents : fields, methods, static block, initialization block or other type declarations. All of these elements are of type BodyDeclaration metaclass.

BodyDeclaration and its hierarchy

Expressions

Like in many languages, the concept of expression exists in Java : it is a portion of code, without declarations, and its evaluation returns a value, numerical or boolean or other ... For example,
++i
is an expression and it will be translated to the concept of PrefixExpression metaclass. All types of expressions shall inherit from the Expression metaclass.
Expression and its hierarchy

Statements

An "instruction" in Java is represented by the Statement metaclass. A block of code (Block metaclass) contains a collection of statements, and a block of code may be contained by a method. Some examples of statements in java :
if, while, for, do, ...
All of their definitions use the concept of expression to separate the value from the instruction keyword.
Statement and its hierarchy

Zoom on comments

There are three kinds of comments : line comments (//), block comments (/* */) and javadoc comments (/** */). Every comment contains text fragments, but we can have more information on javadoc comments (Javadoc metaclass): they can also contain javadoc tags that are identified and collected through instances of the TagElement metaclass.

Comment and its hierarchy

Zoom on annotations

Official usage of annotations has been introduced in version 5 of the JDK. To handle them, annotation declarations are managed as type declarations (AnnotationTypeDeclaration metaclass) with specific attributes (AnnotationTypeMemberDeclaration metaclass). And annotation usages are translated into instances of the Annotation metaclass, which reference corresponding annotation declarations. And parameters are translated into instances of the MemberValuePair metaclass. Some statements also have a list of annotations.

Annotation

Zoom on generics

Version 5 of the JDK also introduced the concept of "generics". Generic types of method declarations are translated into instances of TypeDeclaration of AbstractMethodDeclaration metaclass with arguments as instances of the TypeParameter metaclass. Uses of these generics are translated into instances of the ParameterizedType metaclass which reference concrete elements (type and type arguments).

A specific case of type argument is the "wildcard" (for example "<? extends X>"). There is a specific metaclass to handle it : WildCardType.

Generics

Requirements

To use the plug-in you need:

  • JDK 1.5 or above
  • a version of Eclipse 3.3 or above with the following set of plug-ins installed
  • EMF 2.3.0 or higher

Source Repository

All of the source code is stored in a public source repository, which you can access at:

https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java/

Associated Discoverers

The main discoverer available for this metamodel : Java Discoverer

Java Discoverer

The goal of the Java Discoverer plug-in is to allow practical extractions of Java models from Java projects.

Description

This plug-in aims at analyzing Java source code compliant with version 3 of "Java Language Specification" from Sun Microsystems and providing a model describing the information found, conforming to the Java metamodel.

A Java model contains the full abstract syntax tree of the Java program: each statement such as attribute definition, method invocation or loop is described. In addition, links between elements are resolved (by resolved link we mean for instance a link between a method invocation and the declaration of this method, or between the usage of a variable and its declaration). The model can thus be seen as an abstract syntax graph (ASG).

Requirements

To use the plug-in you need:

  • JDK 1.5 or above
  • a version of Eclipse 3.3 or above with the following set of plug-ins installed

Source Repository

All of the source code is stored in a public source repository, which you can access at:

https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.java.discoverer/

User manual

The plug-in provides the user with a contextual menu to easily create models.

By right-clicking on a Java Project in the Eclipse Package Explorer view, you can quickly create the Java model of your application (see next Figure).

Menus in Eclipse to create model from source code

A discovery parameter window proposes to

 * indicate to extend the analysis to required Java projects and libraries
 * indicate to limit the analysis to types/fields/methods declarations (no Java statements/expressions analysis)
 * indicate a filter to exclude some Java packages from analysis
DiscoveryParameters.PNG

Once launched, a progress bar will appear at the bottom of the window as soon as the operation begins. Depending on the size of your application, the reverse engineering process might take some time to complete (see next Figure).

Progress bar during model creation

At the end of the process, the newly created model files are added to the root of your project and are automatically opened in the default editor (see next Figure).

Java model in the package explorer

.javaxmi files can be opened in the Sample Ecore Model Editor (see next Figure).

Java model viewed with EMF browser

They can also be opened in the MoDisco model browser (see next Figure) which brings some graphical improvements.

Java model viewed with MoDisco browser

Java Generation

The goal of the Java Generation plug-in is to allow Java code generation from a Java model. Such a generation will fulfill some of the requirements for Legacy refactoring & migration.

Description

JavaM2T.PNG

This plug-in proposes Acceleo MTL modules for generating Java files conforming to Java models. Templates are contained in two modules :

  • Structures modules : top level templates for generating classes/method/field declarations
  • Statements modules

Java models are obtained with Java Discoverer component.

Considering a Java legacy, a minimal migration/refactoring chain will involve :

  • A Java model discovery step
  • A m2m transformation step
  • A Java generation code step with the current component

User manual

A prerequisite is a Java model. Please refer to the Java Discoverer user manual.

To launch Java generation :

  • Create an Accelo launch configuration pointing to Generate_JavaStructures java class, and specify the input model and target folder (require a checkout or import of the org.eclipse.gmt.modisco.java.generation into the workspace).

Or

  • Add org.eclipse.gmt.modisco.java.generation in your plugin dependencies and use the Generate_JavaStructures main method with input model and target folder as parameters.