Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "MoDisco/CSharp"

Line 1: Line 1:
The CSharp meta model : it is the reflect of C# language, as it has been defined in version 2.0 of "C# Language Specification" from Microsoft Corporation.
+
The CSharp metamodel is the reflect of the C# language, as it has been defined in version 2.0 of "C# Language Specification" from Microsoft Corporation.
  
CSharp meta model contains 81 meta classes.
+
CSharp metamodel contains 81 metaclasses.
To better understand it, this page will introduce main features (meta classes and links).
+
To better understand it, this page will introduce the main features (metaclasses and links).
  
 
You could also browse definition model, csharp.ecore available in sources (see [[#Install| install section]]).
 
You could also browse definition model, csharp.ecore available in sources (see [[#Install| install section]]).
Line 11: Line 11:
 
=== ASTNode ===
 
=== ASTNode ===
  
Every meta classes (without meta class '''Fragment''') inherit from ASTNode.
+
Every metaclasses (except metaclass '''Fragment''') inherit from '''ASTNode'''.
As its name indicates it, ASTNode represents a graph node.
+
As its name indicates it, '''ASTNode''' represents a graph node.
ASTNode has a reference to Comment meta class because almost every csharp element could be associated to a comment (bloc or line comment).
+
'''ASTNode''' has a reference to '''Comment''' metaclass because almost every csharp element could be associated to a comment (bloc or line comment).
  
 
[[Image:MoDisco-CSharp metaclass ASTNode.jpg|frame|center|ASTNode meta class]]
 
[[Image:MoDisco-CSharp metaclass ASTNode.jpg|frame|center|ASTNode meta class]]
Line 19: Line 19:
 
=== Assembly, Namespace, Type ===
 
=== Assembly, Namespace, Type ===
  
Root element of each CSharp model in an instance of "Assembly" meta class. It is a translation of csharp application concept, so it contains namespace declarations (instances of Namespace meta class). And namespace declarations contain type declarations (instances compatible with Type meta class), and so on ...
+
Root element of each CSharp model in an instance of '''Assembly''' metaclass. It is a translation of csharp application concept, so it contains namespace declarations (instances of '''Namespace''' metaclass). And namespace declarations contain type declarations (instances compatible with '''Type''' metaclass), and so on ...
  
 
[[Image:MoDisco-CSharp Assembly Namespace and Type.jpg|frame|center|Assembly Namespace and Type]]
 
[[Image:MoDisco-CSharp Assembly Namespace and Type.jpg|frame|center|Assembly Namespace and Type]]
Line 26: Line 26:
  
 
A lot of csharp elements are "named", and this name could be considered as an identifier : methods, packages, types, variables, fields, ...
 
A lot of csharp elements are "named", and this name could be considered as an identifier : methods, packages, types, variables, fields, ...
So all of corresponding meta classes inherit from NamedElement meta class. It will be useful to resolve references in binding, see [[#NamedElementRef|NamedElementRef]] meta class.
+
So all of corresponding metaclasses inherit from '''NamedElement''' metaclass. It will be useful to resolve references in binding, see [[#NamedElementRef|NamedElementRef]] metaclass.
  
An other goal of this meta class is to indicate which element is a part of the current csharp application or not (element from an external library of .Net). Then external elements are tagged as proxy through dedicated attribute and could be easily filtered.
+
An other goal of this metaclass is to indicate which element is a part of the current csharp application or not (element from an external library of .Net). Then external elements are tagged as proxy through dedicated attribute and could be easily filtered.
For example, instruction "Trace.WriteLine" has been decomposed in two named elements (one class and one method) which definition are not part of current csharp application. So attribute "proxy" of these elements has been initialized with true.
+
For example, instruction "Trace.WriteLine" has been decomposed into two named elements (one class and one method) which definition are not part of current csharp application. So attribute '''proxy''' of these elements has been initialized with true.
  
 
[[Image:MoDisco-CSharp metaclass NamedElement and its hierarchy.jpg|frame|center|NamedElement and its hierarchy]]
 
[[Image:MoDisco-CSharp metaclass NamedElement and its hierarchy.jpg|frame|center|NamedElement and its hierarchy]]
Line 35: Line 35:
 
=== NamedElementRef ===
 
=== NamedElementRef ===
  
To represent links between csharp elements, as C# AST defines only string references, meta class NamedElementRef initially contained only this information.
+
To represent links between csharp elements, as C# AST defines only string references, metaclass NamedElementRef initially contained only this information.
But an important addition was to resolve binding between elements, so it is actually possible to navigate directly through elements graph. It has been represented through a relationship from a NamedElementRef to a NamedElement (proxy or not).
+
But an important addition was to resolve binding between elements, so it is actually possible to navigate directly through elements graph. It has been represented through a relationship from a '''NamedElementRef''' to a '''NamedElement''' (proxy or not).
  
 
[[Image:MoDisco-CSharp metaclass NamedElementRef.jpg|frame|center|NamedElementRef meta class]]
 
[[Image:MoDisco-CSharp metaclass NamedElementRef.jpg|frame|center|NamedElementRef meta class]]
Line 42: Line 42:
 
=== InternalDeclaration ===
 
=== InternalDeclaration ===
  
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 InternalDeclaration metaclass.
+
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 '''InternalDeclaration''' metaclass.
  
 
[[Image:MoDisco-CSharp metaclass InternalDeclaration and its hierarchy.jpg|frame|center|InternalDeclaration and its hierarchy]]
 
[[Image:MoDisco-CSharp metaclass InternalDeclaration and its hierarchy.jpg|frame|center|InternalDeclaration and its hierarchy]]
Line 49: Line 49:
  
 
Like in many languages, concept of expression exists in C# : it is a portion of code, without declarations, and its evaluation returns a value, numerical or boolean or other ...
 
Like in many languages, concept of expression exists in C# : it is a portion of code, without declarations, and its evaluation returns a value, numerical or boolean or other ...
For example, <source lang="csharp">++i</source> is an expression and will be translated into concept of InfixExpression metaclass.
+
For example, <source lang="csharp">++i</source> is an expression and will be translated into concept of '''InfixExpression''' metaclass.
All types of expressions shall inherit from Expression metaclass.
+
All types of expressions shall inherit from '''Expression''' metaclass.
  
 
[[Image:MoDisco-CSharp metaclass Expression and its hierarchy.jpg|frame|center|Expression and its hierarchy]]
 
[[Image:MoDisco-CSharp metaclass Expression and its hierarchy.jpg|frame|center|Expression and its hierarchy]]
Line 56: Line 56:
 
=== Statements ===
 
=== Statements ===
  
An "instruction" in C# is represented by 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 C# is represented by '''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 C# : <source lang="csharp">if, while, for, do, ...</source>
 
Some examples of statements in C# : <source lang="csharp">if, while, for, do, ...</source>
 
All of their definitions use concept of expression to separate value from instruction keyword.
 
All of their definitions use concept of expression to separate value from instruction keyword.

Revision as of 10:01, 23 February 2009

The CSharp metamodel is the reflect of the C# language, as it has been defined in version 2.0 of "C# Language Specification" from Microsoft Corporation.

CSharp metamodel contains 81 metaclasses. To better understand it, this page will introduce the main features (metaclasses and links).

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


Main meta classes

ASTNode

Every metaclasses (except metaclass Fragment) inherit from ASTNode. As its name indicates it, ASTNode represents a graph node. ASTNode has a reference to Comment metaclass because almost every csharp element could be associated to a comment (bloc or line comment).

ASTNode meta class

Assembly, Namespace, Type

Root element of each CSharp model in an instance of Assembly metaclass. It is a translation of csharp application concept, so it contains namespace declarations (instances of Namespace metaclass). And namespace declarations contain type declarations (instances compatible with Type metaclass), and so on ...

Assembly Namespace and Type

NamedElement & notion of Proxy

A lot of csharp elements are "named", and this name could be considered as an identifier : methods, packages, types, variables, fields, ... So all of corresponding metaclasses inherit from NamedElement metaclass. It will be useful to resolve references in binding, see NamedElementRef metaclass.

An other goal of this metaclass is to indicate which element is a part of the current csharp application or not (element from an external library of .Net). Then external elements are tagged as proxy through dedicated attribute and could be easily filtered. For example, instruction "Trace.WriteLine" has been decomposed into two named elements (one class and one method) which definition are not part of current csharp application. So attribute proxy of these elements has been initialized with true.

NamedElement and its hierarchy

NamedElementRef

To represent links between csharp elements, as C# AST defines only string references, metaclass NamedElementRef initially contained only this information. But an important addition was to resolve binding between elements, so it is actually possible to navigate directly through elements graph. It has been represented through a relationship from a NamedElementRef to a NamedElement (proxy or not).

NamedElementRef meta class

InternalDeclaration

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 InternalDeclaration metaclass.

InternalDeclaration and its hierarchy

Expressions

Like in many languages, concept of expression exists in C# : 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 will be translated into concept of InfixExpression metaclass.

All types of expressions shall inherit from Expression metaclass.

Expression and its hierarchy

Statements

An "instruction" in C# is represented by 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 C# :
if, while, for, do, ...

All of their definitions use concept of expression to separate value from instruction keyword.

Statement and its hierarchy




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 plugins installed
  • EMF 2.3.0 or higher


Install

You will find a version of this plug-in attached in following bug.

As IP review of this plugin 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 plugin (Deployable plugins 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 in account this plug-in

Associated Discoverers

A first version of C# discoverer : CSharpDiscoverer

Back to the top