Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resolving references changed with 1.0?
Resolving references changed with 1.0? [message #554375] Sun, 22 August 2010 16:28 Go to next message
Heiko Tappe is currently offline Heiko TappeFriend
Messages: 18
Registered: March 2010
Junior Member
I used to have something like

Datamodule:
	'datamodule' name=ID '{' entities+=Entity* '}';

Entity:
	'entity' name=ID ('extends' extends=[Entity])?
	 '{' properties+=Property* '}';

Property:
	'property' name=ID ':' type=[Type];
	
Type:	
	'type' name=ID ('extends' extends=[Type])?;


in xtext 0.7 which worked fine for the example below.

With xtext 1.0 I get a "cannot resolve reference" error when trying to reference an entity from another datamodule - e.g.:

datamodule m1 {
	entity test1 {
		property p1: String
	}
	entity test1_1 extends test1 {
		property p2: String
	}
}
datamodule m2 {
	entity test2_1 extends test1 {
		property p2: Integer
	}
}


What do I have to do to make it work with 1.0? Are there any other pitfalls? Is there a migration guide (already)?

--Heiko
Re: Resolving references changed with 1.0? [message #554376 is a reply to message #554375] Sun, 22 August 2010 16:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hello Heiko,

with Xtext 1.0 a new default behavour for Qualified Names was introduced.

to adapt your grammar to the new behaviour the grammar has to look like this:

ModelPart:
	elements+=Datamodule*
	types+=Type*
	;
	
Datamodule:
	'datamodule' name=ID '{' entities+=Entity* '}';

Entity:
	'entity' name=ID ('extends' extends=[Entity|FQN])?
	 '{' properties+=Property* '}';

Property:
	'property' name=ID ':' type=[Type];
	
Type:	
	'type' name=ID ('extends' extends=[Type])?;
	
FQN: ID ("." ID)*;


the model then will look like this

datamodule m1 {
	entity test1 {
		property p1: String
	}
	entity test1_1 extends test1 {
		property p2: String
	}
	
}
datamodule m2 {
	entity test2_1 extends m1.test1 {
		property p2: Integer
	}
}


(note the full qualified reference m1.test1.

Or you customize the used IQualifiedNameProvider by using the old behavoiurous SimpleNameProvider

public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
	
	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return SimpleNameProvider.class;
	}

}


but this may lead to problems with your duplicate p2 property since the name has to be unique.

you have to switch off duplicates checks too.

//composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"


or you don't use simplesameprovider but rather change the default provider

public class MyQNP extends DefaultDeclarativeQualifiedNameProvider {
	
	public String qualifiedName(Entity entity) {
		return entity.getName();
	}

}


public class MyDslRuntimeModule extends org.xtext.example.mydsl.AbstractMyDslRuntimeModule {
	
	@Override
	public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() {
		return MyQNP.class;
	}

}


For more background have a look at the docs

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Resolving references changed with 1.0? [message #554397 is a reply to message #554375] Sun, 22 August 2010 19:32 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Heiko,

the documentation contains a migration guide and detailed information
about the scoping semantics.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com

Am 22.08.10 18:28, schrieb Heiko Tappe:
> I used to have something like
>
> Datamodule:
> 'datamodule' name=ID '{' entities+=Entity* '}';
>
> Entity:
> 'entity' name=ID ('extends' extends=[Entity])?
> '{' properties+=Property* '}';
>
> Property:
> 'property' name=ID ':' type=[Type];
>
> Type:
> 'type' name=ID ('extends' extends=[Type])?;
>
> in xtext 0.7 which worked fine for the example below.
>
> With xtext 1.0 I get a "cannot resolve reference" error when trying to
> reference an entity from another datamodule - e.g.:
>
> datamodule m1 {
> entity test1 {
> property p1: String
> }
> entity test1_1 extends test1 {
> property p2: String
> }
> }
> datamodule m2 {
> entity test2_1 extends test1 {
> property p2: Integer
> }
> }
>
>
> What do I have to do to make it work with 1.0? Are there any other
> pitfalls? Is there a migration guide (already)?
>
> --Heiko
Re: Resolving references changed with 1.0? [message #554529 is a reply to message #554375] Mon, 23 August 2010 13:44 Go to previous message
Heiko Tappe is currently offline Heiko TappeFriend
Messages: 18
Registered: March 2010
Junior Member
Thanks Christian and Sebastian!
I must have been blind. I somehow overlooked the migration part in the documentation.

Works like a charm now Smile

--Heiko
Previous Topic:Creating Jackrabbit's CND file editor
Next Topic:Code generation from editor
Goto Forum:
  


Current Time: Fri Apr 26 03:16:50 GMT 2024

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

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

Back to the top