Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Unable to link cross-referenced entities across grammars
Unable to link cross-referenced entities across grammars [message #646805] Fri, 31 December 2010 12:25 Go to next message
vaibhav  is currently offline vaibhav Friend
Messages: 22
Registered: September 2010
Junior Member
Hi,

The Department.xtext grammar has been defined using imported metamodel:

Department.xtext
	
grammar org.xtext.example.Department with org.eclipse.xtext.common.Terminals

import "http://www.eclipse.org/emf/2002/Ecore" as ecore
import "platform:/resource/org.xtext.example.department/model/department.ecore" 

Department returns Department:
	{Department}
	('DeptID:' description=Description)?;

Description: name=ID;


The Company.xtext grammar references the department name field as shown below:

Company.xtext

grammar org.xtext.example.Company with org.eclipse.xtext.common.Terminals

import "platform:/resource/org.xtext.example.company/model/company.ecore"
import "platform:/resource/org.xtext.example.department/model/department.ecore" as dept
import "http://www.eclipse.org/emf/2002/Ecore" as ecore

Company returns Company:
	{Company}
	'Company'
	'{'
	('title' title=STRING)?
	('deptID' '(' name=[dept::Department]')')?
	'}';


When the application is run,the reference to Department name is not resolved.
However, this issue exists only with imported ecore models.

If I use the grammar defined above to generate an ecore instead of importing an existing ecore, then the references work fine as expected.

Is there some additional configuration required to make cross-references work with imported metamodel?

Best Regards,
Vaibhav.
Re: Unable to link cross-referenced entities across grammars [message #646806 is a reply to message #646805] Fri, 31 December 2010 12:56 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
Hi,

This has nothing todo with importiung or not importing the ecore. it is how Elements are referenced in Xtext / how the Scopting is done. Your Department has no Name Attribute and thereby no QualifiedName and is not exported to global scope.

Bind a IQualifiedNameProvider to give your Departments a name.

/*
 * generated by Xtext
 */
package org.xtext.example.departmentdsl;

import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.xtext.example.departmentdsl.scoping.DepartmentQNP;

/**
 * Use this class to register components to be used at runtime / without the Equinox extension registry.
 */
public class DepartmentDslRuntimeModule extends org.xtext.example.departmentdsl.AbstractDepartmentDslRuntimeModule {

	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return DepartmentQNP.class;
	}
	
}


package org.xtext.example.departmentdsl.scoping;

import org.eclipse.xtext.naming.DefaultDeclarativeQualifiedNameProvider;

import department.Department;

public class DepartmentQNP extends DefaultDeclarativeQualifiedNameProvider {
	
	public String qualifiedName(Department department) {
		return department.getDescription().getName();
	}
}



~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:problem with the generated project wizard
Next Topic:crossreference to other file
Goto Forum:
  


Current Time: Fri Sep 20 03:25:32 GMT 2024

Powered by FUDForum. Page generated in 0.04778 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top