Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "MoDisco/Components/J2SE5"
(→Team) |
(typos and rewording) |
||
Line 1: | Line 1: | ||
− | The J2SE5 metamodel : it is the | + | The J2SE5 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). |
− | J2SE5 metamodel contains 101 metaclasses. | + | The J2SE5 metamodel contains 101 metaclasses. |
− | To better understand it, this page will introduce main features (metaclasses and links). | + | To better understand it, this page will introduce its main features (metaclasses and links). |
− | You could also browse | + | You could also browse the model definition, j2se5.ecore available in sources (see [[#Install| install section]]). |
− | A good tip is also to see [http://help.eclipse.org/help31/index.jsp javadoc] associated to metamodel implemented by Eclipse team in | + | A good tip is also to see the [http://help.eclipse.org/help31/index.jsp javadoc] associated to the metamodel implemented by the Eclipse team in the [[JDT| JDT (Java Development Tool)]] project. This metamodel and J2SE5 are very similar. |
Line 13: | Line 13: | ||
=== ASTNode === | === ASTNode === | ||
− | Every | + | Every metaclass (apart from the '''Model''' metaclass) inherits from ASTNode. |
− | As its name | + | As its name indicates, ASTNode represents a graph node. |
− | ASTNode has a reference to Comment metaclass because almost every java element could be associated to a comment ( | + | ASTNode has a reference to the Comment metaclass because almost every java element could be associated to a comment (block or line comment and Javadoc). More details in [[#Zoom on comments| "Comment" section]]. |
[[Image:MoDisco-J2SE5 metaclass ASTNode.jpg|frame|center|ASTNode metaclass]] | [[Image:MoDisco-J2SE5 metaclass ASTNode.jpg|frame|center|ASTNode metaclass]] | ||
Line 21: | Line 21: | ||
=== Model, Package, AbstractTypeDeclaration === | === Model, Package, AbstractTypeDeclaration === | ||
− | + | The root element of each J2SE5 model is an instance of the "Model" metaclass. It is a translation of java application concept, so it contains package declarations (instances of the PackageDeclaration metaclass). And package declarations contain type declarations (instances compatible with AbstractTypeDeclaration metaclass), and so on ... | |
[[Image:MoDisco-J2SE5 metaclass Model PackageDeclaration.jpg|frame|center|Model, Package & type declaration superclass]] | [[Image:MoDisco-J2SE5 metaclass Model PackageDeclaration.jpg|frame|center|Model, Package & type declaration superclass]] | ||
Line 28: | Line 28: | ||
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 : methods, packages, types, variables, fields, ... | ||
− | So all | + | So all the corresponding metaclasses inherit from the NamedElement metaclass. It will be useful to resolve references in binding, see the [[#NamedElementRef|NamedElementRef]] 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). Then external elements are tagged as proxy through a dedicated attribute and can be easily filtered. | |
− | For example, instruction "System.out.println" has been decomposed | + | 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 as true. |
[[Image:MoDisco-J2SE5 metaclass NamedElement and its hierarchy.jpg|frame|center|NamedElement and its hierarchy]] | [[Image:MoDisco-J2SE5 metaclass NamedElement and its hierarchy.jpg|frame|center|NamedElement and its hierarchy]] | ||
Line 37: | Line 37: | ||
=== NamedElementRef === | === NamedElementRef === | ||
− | To represent links between | + | To represent links between Java elements, as java AST defines only string references, metaclass NamedElementRef initially contained only this information. |
− | But an important addition was to resolve | + | But an important addition was to resolve bindings between elements, so is is actually possible to navigate directly in the elements graph. It has been represented as a relationship from a NamedElementRef to a NamedElement (proxy or not). |
[[Image:MoDisco-J2SE5 metaclass NamedElementRef.jpg|frame|center|NamedElementRef]] | [[Image:MoDisco-J2SE5 metaclass NamedElementRef.jpg|frame|center|NamedElementRef]] | ||
Line 50: | Line 50: | ||
=== Expressions === | === Expressions === | ||
− | Like in many languages, 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 : 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 will be translated | + | 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 Expression metaclass. | All types of expressions shall inherit from Expression metaclass. | ||
Line 58: | Line 58: | ||
=== Statements === | === Statements === | ||
− | An "instruction" in Java is represented by Statement metaclass. A block of code (Block metaclass) contains a collection of statements, an 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, an a block of code may be contained by a method. |
− | Some | + | Some examples of statements in java : <source lang="java">if, while, for, do, ...</source> |
− | All of their definitions use concept of expression to separate value from instruction keyword. | + | 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]] | ||
Line 66: | Line 66: | ||
=== Zoom on comments === | === Zoom on comments === | ||
− | There | + | There are three kinds of comments : line comments (//), block comments (/* */) and javadoc comments (/** */). |
− | Every | + | 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-J2SE5 metaclass Comment and its hierarchy.jpg|frame|center|Comment and its hierarchy]] | [[Image:MoDisco-J2SE5 metaclass Comment and its hierarchy.jpg|frame|center|Comment and its hierarchy]] | ||
Line 73: | Line 73: | ||
=== Zoom on annotations === | === Zoom on annotations === | ||
− | Official usage of annotations has been introduced in version 5 of JDK. | + | Official usage of annotations has been introduced in version 5 of the JDK. |
− | To handle | + | To handle them, annotation declarations are managed as type declarations (AnnotationTypeDeclaration metaclass) with specific attributes (AnnotationTypeMemberDeclaration metaclass). |
− | And annotation usages are translated | + | 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. |
[[Image:MoDisco-J2SE5 metaclass AnnotationTypeDeclaration and Annotation.jpg|frame|center|Annotation]] | [[Image:MoDisco-J2SE5 metaclass AnnotationTypeDeclaration and Annotation.jpg|frame|center|Annotation]] | ||
Line 81: | Line 81: | ||
=== Zoom on generics === | === Zoom on generics === | ||
− | Version 5 of JDK | + | Version 5 of the JDK also introduces the concept of "generics". |
− | Generic types of | + | Generic types of method declarations are translated into instances of TypeDeclaration of MethodDeclaration 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 types arguments). | |
− | + | A specific case of type argument is the "wildcard" (for example <? extends X>. There is a specific metaclass to handle it : WildCardType. | |
[[Image:MoDisco-J2SE5 generics declarations and usages.jpg|frame|center|Generics]] | [[Image:MoDisco-J2SE5 generics declarations and usages.jpg|frame|center|Generics]] | ||
Line 93: | Line 93: | ||
To use the plug-in you need: | To use the plug-in you need: | ||
* JDK 1.5 or above | * JDK 1.5 or above | ||
− | * a version of Eclipse 3.3 or above with the following set of | + | * a version of Eclipse 3.3 or above with the following set of plug-ins installed |
:* [[EMF|EMF]] 2.3.0 or higher | :* [[EMF|EMF]] 2.3.0 or higher | ||
Line 106: | Line 106: | ||
== Install == | == Install == | ||
− | You will find a version of this plug-in attached in [https://bugs.eclipse.org/bugs/show_bug.cgi?id=258281 following bug]. | + | You will find a version of this plug-in attached in [https://bugs.eclipse.org/bugs/show_bug.cgi?id=258281 the following bug]. |
− | As IP review of this | + | As IP review of this plug-in is not finished, here are installation instructions : |
* Extract archive file in your Eclipse workspace, then use "import" menu to import this project. | * Extract archive file in your Eclipse workspace, then use "import" menu to import this project. | ||
− | * Use "export" menu to export this project as a | + | * Use "export" menu to export this project as a plug-in (Deployable plug-ins and fragments) in your Eclipse installation. Don't forget to choose "Package plug-ins as individual jar archives" option. |
− | * | + | * Re-start your Eclipse to take this plug-in into account |
== Associated Discoverers == | == Associated Discoverers == | ||
Line 118: | Line 118: | ||
The main discoverer available for this metamodel : [[MoDisco/JavaDiscoverer|JavaDiscoverer]] | The main discoverer available for this metamodel : [[MoDisco/JavaDiscoverer|JavaDiscoverer]] | ||
− | + | Another project also exists which produces a very similar model of Java applications : [http://www.eclipse.org/gmt/modisco/toolBox/JavaAbstractSyntax JavaAST] | |
− | I hope these two discoverers will be merged in | + | I hope these two discoverers will be merged in the future. |
Revision as of 05:08, 17 March 2009
The J2SE5 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 J2SE5 metamodel contains 101 metaclasses. To better understand it, this page will introduce its main features (metaclasses and links).
You could also browse the model definition, j2se5.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 J2SE5 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 could be associated to a comment (block or line comment and Javadoc). More details in "Comment" section.
Model, Package, AbstractTypeDeclaration
The root element of each J2SE5 model is an instance of the "Model" metaclass. It is a translation of java application concept, so it contains package declarations (instances of the PackageDeclaration metaclass). And package declarations contain type declarations (instances compatible with AbstractTypeDeclaration metaclass), and so on ...
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. It will be useful to resolve references in binding, see the NamedElementRef 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). Then 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 as true.
NamedElementRef
To represent links between Java elements, as java AST defines only string references, metaclass NamedElementRef initially contained only this information. But an important addition was to resolve bindings between elements, so is is actually possible to navigate directly in the elements graph. It has been represented as a relationship from a NamedElementRef to a NamedElement (proxy or not).
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.
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
All types of expressions shall inherit from Expression metaclass.
Statements
An "instruction" in Java is represented by the Statement metaclass. A block of code (Block metaclass) contains a collection of statements, an 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.
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.
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.
Zoom on generics
Version 5 of the JDK also introduces the concept of "generics". Generic types of method declarations are translated into instances of TypeDeclaration of MethodDeclaration 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 types arguments).
A specific case of type argument is the "wildcard" (for example <? extends X>. There is a specific metaclass to handle it : WildCardType.
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
Team
Gabriel Barbier (Mia-Software)
Fabien Giquel (Mia-Software)
Frédéric Madiot (Mia-Software)
Install
You will find a version of this plug-in attached in the following bug.
As IP review of this plug-in is not finished, here are installation instructions :
- Extract archive file in your Eclipse workspace, then use "import" menu to import this project.
- Use "export" menu to export this project as a plug-in (Deployable plug-ins and fragments) in your Eclipse installation. Don't forget to choose "Package plug-ins as individual jar archives" option.
- Re-start your Eclipse to take this plug-in into account
Associated Discoverers
The main discoverer available for this metamodel : JavaDiscoverer
Another project also exists which produces a very similar model of Java applications : JavaAST I hope these two discoverers will be merged in the future.