Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Linking for a cross-reference-less grammar?(Validation that utilizes multiple eResources needs to revalidate related resources but how to associate)
Linking for a cross-reference-less grammar? [message #1047201] Mon, 22 April 2013 19:01 Go to next message
Chris Ainsley is currently offline Chris Ainsley
Messages: 74
Registered: March 2010
Location: UK
Member

I'm making good progress with XText having resolved my lexing issues and I've managed to get the content assist working as I expect.

Now I'm trying to tacking the issue of linking and scoping. This thread is with regard to linking specifically.

I have a language which doesn't have any traditional cross references.

There are however, many validation rules. Some of these validation rules involve loading the contents of DSL files (via eResource) in subfolders, recursively, and then applying a validation.

Now, as far as I can understand, the validation framework calls a validate on each model item in a resource that has changed, and triggers a recalculation on items linked to the model items that have changed.

So, my question is, how and where do I explicitly create links between model elements in different files without using the cross reference grammar in my .xtext file?

A secondary question, is it possible to manually trigger a validation on the root model element of a given list of eResources programmatically? Is this a good idea?
Re: Linking for a cross-reference-less grammar? [message #1047268 is a reply to message #1047201] Mon, 22 April 2013 21:40 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2498
Registered: July 2009
Senior Member
On 2013-23-04 1:01, Chris Ainsley wrote:
> I'm making good progress with XText having resolved my lexing issues and
> I've managed to get the content assist working as I expect.
>
> Now I'm trying to tacking the issue of linking and scoping. This thread
> is with regard to linking specifically.
>
> I have a language which doesn't have any traditional cross references.
>
> There are however, many validation rules. Some of these validation rules
> involve loading the contents of DSL files (via eResource) in subfolders,
> recursively, and then applying a validation.
>
You are probably better of letting builders deal with all the content
creating EObjectDescriptions that gets indexed by Xtext. You then search
this index in your linking instead of rescanning the content over and
over. (More below).

Anything that is already an Xtext DSL is automatically added to the
index (and it is just a matter of visibility), and anything that is EMF
is easily also added to the index. If you have some other type of
resources, create a model for it and write your own data to EMF to Xtext
indexing (I do this for Ruby logic parsed a special way).

> Now, as far as I can understand, the validation framework calls a
> validate on each model item in a resource that has changed, and triggers
> a recalculation on items linked to the model items that have changed.
>
> So, my question is, how and where do I explicitly create links between
> model elements in different files without using the cross reference
> grammar in my .xtext file?
>
Take a look at cloudsmith / geppetto @ github. I do not use the regular
linking support provided by EMF Xtext and instead use a different
mechanism (I use an adapter at the referencing end instead of an
EReference). This required quite a lot of work throughout the system,
you can probably borrow quite a lot from my implementation.

Look at the PPLinker and PPResourceLinker classes they adapt my special
linker to the normal LazyLinker. It then does the special linking in a
callback; issues linkage errors and computes various things later needed
in quick fixes (to avoid yet another attempt at resolving a reference at
a later point) etc.

The implementation makes heavy use of the index and does several
optimizations in searching for things.

It is important to record all names that are used, as well as names of
things not found, and names investigated (that if they appear later will
change the resolution). This data is recorded at the resource level and
is used by the Xtext builders to figure out the transitive hull of build
changes / the build order to use.

> A secondary question, is it possible to manually trigger a validation on
> the root model element of a given list of eResources programmatically?
> Is this a good idea?

That can be done. That is what the builder is doing. If this is a good
idea or not depends on why and where you want to do this :) It is quite
different when you are editing things (you want validation and linking
to take place on the content that is in dirty state in the editors to
give users immediate feedback.

Hope this helps
Regards
- henrik
Re: Linking for a cross-reference-less grammar? [message #1047304 is a reply to message #1047268] Mon, 22 April 2013 23:09 Go to previous messageGo to next message
Chris Ainsley is currently offline Chris Ainsley
Messages: 74
Registered: March 2010
Location: UK
Member

Thanks Henrik.

PPResourceLinker is a very complex piece of code and it will take a long time to understand how it actually works.

I've been looking for code that deals with "the index" as you stated before. I've heard a lot about the index, but I can't see the code where this index is interrogated.

I assume the index comes in through the use of an @Inject annotation plus an interface. The name of the interface that deals with the index would help me out here.

Henrik Lindberg wrote on Tue, 23 April 2013 10:40
On 2013-23-04 1:01, Chris Ainsley wrote:
> I'm making good progress with XText having resolved my lexing issues and
> I've managed to get the content assist working as I expect.
>
> Now I'm trying to tacking the issue of linking and scoping. This thread
> is with regard to linking specifically.
>
> I have a language which doesn't have any traditional cross references.
>
> There are however, many validation rules. Some of these validation rules
> involve loading the contents of DSL files (via eResource) in subfolders,
> recursively, and then applying a validation.
>
You are probably better of letting builders deal with all the content
creating EObjectDescriptions that gets indexed by Xtext. You then search
this index in your linking instead of rescanning the content over and
over. (More below).

Anything that is already an Xtext DSL is automatically added to the
index (and it is just a matter of visibility), and anything that is EMF
is easily also added to the index. If you have some other type of
resources, create a model for it and write your own data to EMF to Xtext
indexing (I do this for Ruby logic parsed a special way).

> Now, as far as I can understand, the validation framework calls a
> validate on each model item in a resource that has changed, and triggers
> a recalculation on items linked to the model items that have changed.
>
> So, my question is, how and where do I explicitly create links between
> model elements in different files without using the cross reference
> grammar in my .xtext file?
>
Take a look at cloudsmith / geppetto @ github. I do not use the regular
linking support provided by EMF Xtext and instead use a different
mechanism (I use an adapter at the referencing end instead of an
EReference). This required quite a lot of work throughout the system,
you can probably borrow quite a lot from my implementation.

Look at the PPLinker and PPResourceLinker classes they adapt my special
linker to the normal LazyLinker. It then does the special linking in a
callback; issues linkage errors and computes various things later needed
in quick fixes (to avoid yet another attempt at resolving a reference at
a later point) etc.

The implementation makes heavy use of the index and does several
optimizations in searching for things.

It is important to record all names that are used, as well as names of
things not found, and names investigated (that if they appear later will
change the resolution). This data is recorded at the resource level and
is used by the Xtext builders to figure out the transitive hull of build
changes / the build order to use.

> A secondary question, is it possible to manually trigger a validation on
> the root model element of a given list of eResources programmatically?
> Is this a good idea?

That can be done. That is what the builder is doing. If this is a good
idea or not depends on why and where you want to do this Smile It is quite
different when you are editing things (you want validation and linking
to take place on the content that is in dirty state in the editors to
give users immediate feedback.

Hope this helps
Regards
- henrik

Re: Linking for a cross-reference-less grammar? [message #1047641 is a reply to message #1047304] Tue, 23 April 2013 09:19 Go to previous message
Henrik Lindberg is currently offline Henrik Lindberg
Messages: 2498
Registered: July 2009
Senior Member
Getting stuff from the index

/**
* Access to the global index maintained by Xtext, is made via a
special (non guice) provider
* that is aware of the context (builder, dirty editors, etc.). It is
used to obtain the
* index for a particular resource. This special provider is obtained here.
*/
@Inject
private org.eclipse.xtext.resource.impl.ResourceDescriptionsProvider
indexProvider;

IResourceDescriptions descriptionIndex =
indexProvider.getResourceDescriptions(resource);
IResourceDescription descr =
descriptionIndex.getResourceDescription(resource.getURI());


Snippets from the class PPFinder which is used by the PPResourceLinker
to find references.

Regards
- henrik

On 2013-23-04 5:09, Chris Ainsley wrote:
> Thanks Henrik.
>
> PPResourceLinker is a very complex piece of code and it will take a long
> time to understand how it actually works.
>
> I've been looking for code that deals with "the index" as you stated
> before. I've heard a lot about the index, but I can't see the code where
> this index is interrogated.
>
> I assume the index comes in through the use of an @Inject annotation
> plus an interface. The name of the interface that deals with the index
> would help me out here.
>
> Henrik Lindberg wrote on Tue, 23 April 2013 10:40
>> On 2013-23-04 1:01, Chris Ainsley wrote:
>> > I'm making good progress with XText having resolved my lexing issues
>> and
>> > I've managed to get the content assist working as I expect.
>> >
>> > Now I'm trying to tacking the issue of linking and scoping. This thread
>> > is with regard to linking specifically.
>> >
>> > I have a language which doesn't have any traditional cross references.
>> >
>> > There are however, many validation rules. Some of these validation
>> rules
>> > involve loading the contents of DSL files (via eResource) in
>> subfolders,
>> > recursively, and then applying a validation.
>> >
>> You are probably better of letting builders deal with all the content
>> creating EObjectDescriptions that gets indexed by Xtext. You then
>> search this index in your linking instead of rescanning the content
>> over and over. (More below).
>>
>> Anything that is already an Xtext DSL is automatically added to the
>> index (and it is just a matter of visibility), and anything that is
>> EMF is easily also added to the index. If you have some other type of
>> resources, create a model for it and write your own data to EMF to
>> Xtext indexing (I do this for Ruby logic parsed a special way).
>>
>> > Now, as far as I can understand, the validation framework calls a
>> > validate on each model item in a resource that has changed, and
>> triggers
>> > a recalculation on items linked to the model items that have changed.
>> >
>> > So, my question is, how and where do I explicitly create links between
>> > model elements in different files without using the cross reference
>> > grammar in my .xtext file?
>> >
>> Take a look at cloudsmith / geppetto @ github. I do not use the
>> regular linking support provided by EMF Xtext and instead use a
>> different mechanism (I use an adapter at the referencing end instead
>> of an EReference). This required quite a lot of work throughout the
>> system, you can probably borrow quite a lot from my implementation.
>>
>> Look at the PPLinker and PPResourceLinker classes they adapt my
>> special linker to the normal LazyLinker. It then does the special
>> linking in a callback; issues linkage errors and computes various
>> things later needed in quick fixes (to avoid yet another attempt at
>> resolving a reference at a later point) etc.
>>
>> The implementation makes heavy use of the index and does several
>> optimizations in searching for things.
>>
>> It is important to record all names that are used, as well as names of
>> things not found, and names investigated (that if they appear later
>> will change the resolution). This data is recorded at the resource
>> level and is used by the Xtext builders to figure out the transitive
>> hull of build changes / the build order to use.
>>
>> > A secondary question, is it possible to manually trigger a
>> validation on
>> > the root model element of a given list of eResources programmatically?
>> > Is this a good idea?
>>
>> That can be done. That is what the builder is doing. If this is a good
>> idea or not depends on why and where you want to do this :) It is
>> quite different when you are editing things (you want validation and
>> linking to take place on the content that is in dirty state in the
>> editors to give users immediate feedback.
>>
>> Hope this helps
>> Regards
>> - henrik
>
>
Previous Topic:Cannot serialize a Boolean false value
Next Topic:JFace data binding between swt to Xtext model
Goto Forum:
  


Current Time: Thu Jul 24 02:41:56 EDT 2014

Powered by FUDForum. Page generated in 0.15095 seconds