Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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

Line 22: Line 22:
  
 
  interface ILinkingService {
 
  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); 
 
 
      
 
      
 
     /**
 
     /**

Revision as of 09:48, 15 August 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. 
    */
   URI[] getLinks(LeafNode text, CrossReference ref, EObject model);  
}

A linking service is configured using the service framework shipped with xtext.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.