Skip to main content
Jump to: navigation, search

Difference between revisions of "Xtext Project Plan/Features/CrossReferencing"

(New page: The cross referencing features allows for specification of cross references within an xtext grammar. To do the linking several things are required: 1) the derived/referenced ecore model c...)
 
Line 2: Line 2:
  
 
To do the linking several things are required:
 
To do the linking several things are required:
1) the derived/referenced ecore model contains a respective cross reference (containment=false).
+
1. the derived/referenced ecore model contains a respective cross reference (containment=false).
2) the syntax of a crossreference is expressed by a lexer rule. usually an identifier or a fully qualified name
+
2. the syntax of a crossreference is expressed by a lexer rule. usually an identifier or a fully qualified name
3) there is a linking phase right after parsing
+
3. there is a linking phase right after parsing
4) there is linking semantics provided for a specific link.
+
4. there is linking semantics provided for a specific link.
  
 
In the grammar a cross reference is specified using square brackets.
 
In the grammar a cross reference is specified using square brackets.

Revision as of 07:56, 24 July 2008

The cross referencing features allows for specification of cross references within an xtext grammar.

To do the linking several things are required: 1. the derived/referenced ecore model contains a respective cross reference (containment=false). 2. the syntax of a crossreference is expressed by a lexer rule. usually an identifier or a fully qualified name 3. there is a linking phase right after parsing 4. there is linking semantics provided for a specific link.

In the grammar a cross reference is specified using square brackets.

CrossReference :
  '[' ReferencedEClass ('|' lexerRuleName)? ']'

Example:

Reference :
  type=[Entity|ID] name=ID;

That results in a Type 'Reference' with an EReference 'type' of type 'Entity' and an EAttribute 'name' of type 'EString' (because ID is of type EString).

For each grammar a linking service can be implemented/configured, which implements the following interface:

interface ILinkingService {
   /**
    * is called to compute the URI of the EObject referenced by 
    * the given text in the given model. 
    *
    * returns the computed URI or null if it couldn't be computed
    */
   URI getLink(LeafNode text, CrossReference ref, EObject model);  
   
   /**
    * is called to compute the URI of the EObject referenced by 
    * the given text in the given model. 
    */
   URI[] getLinks(LeafNode text, CrossReference ref, EObject model);  
}

Back to the top