Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Refer to elements of a derived model in IDerivedStateComputer
Refer to elements of a derived model in IDerivedStateComputer [message #1781138] Thu, 01 February 2018 20:20 Go to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi guys,

I have the following scenario:

Xtext generates automatically the AST of my DSL.

In the IDerivedStateComputer I transform this AST to another AST (derived AST from another metamodel) and put the derived AST to the XtextResource-Content-Slot1 with resource.contents.add(...).

In my dsl it's possible to refer to elements of the derived model. This works well so far.

But now we come to my problem:

In my dsl it's possible to call functions defined in another file. And these functions can contain elements with IDs (for instance requirements).

When main.mydsl (#1) calls the function f1 (#2) then the AST is transformed to a derived AST that would corresponds to the following code (#3). In main.mydsl it's possible to refer to elements of the derived model. Which works fine so far.

But now I have the following problem: If someone changes the ID (r1) of the requirement in library.mydsl for instance to (r2), then the file (main.mydsl) is not marked as faulty, because the IDerivedStateComputer sees only the model of library.mydsl in the resource and builds not the derivedmodel for the referencing file main.mydsl.

#1
// main.mydsl
main XY {
    f1;
    f1;

    ref r1_1;     // reference to an element of the derived model
    ref r1_2;     // reference to an element of the derived model
}


#2
// defined function library.mydsl
define function f1 {

    requirement r1 {

    }

}


#3
main XY {
    requirement r1_1 {

    }

    requirement r1_2 {

    }

    ref r1_1;    // reference to an element of the derived model
    ref r1_2;    // reference to an element of the derived model
}


Would anyone have an idea how I could solve the problem better?
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781148 is a reply to message #1781138] Fri, 02 February 2018 04:31 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 633
Registered: July 2009
Location: Dortmund, Germany
Senior Member

You may have to customize org.eclipse.xtext.resource.IResourceDescription.Manager.isAffected(Delta, IResourceDescription) to signal that main.mydsl (or any .mydsl) is affected by changes in library.mydsl.
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781150 is a reply to message #1781148] Fri, 02 February 2018 05:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12319
Registered: July 2009
Senior Member
This should work out if the box if you don't use xbase (https://bugs.eclipse.org/bugs/show_bug.cgi?id=483760)
And use the default scoping behaviour

Thus you should debug the isaffected calculation as proposed by Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781166 is a reply to message #1781148] Fri, 02 February 2018 09:21 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Hi Karsten and Christian,

many thanks for your help. Now I understand the problem!
Christian you are right normally it should work out of the box but not in my case because:

In my grammar the definition of the requirement looks like this:

Requirement:
    {Requirement} 'requirement' identifier = ID '{'
        elements += ContentElement*
    '}'


So I does not use the attribute name to avoid that requirements are listed in the Content Assist. In the derived model I create requirement elements with a name attribute and an ID. So that I can refer to the dynamically generated elements (r1_1 & r1_2).

But the side affect is that changes on the ID of requirements in library.proc will not trigger the IDerivedStateComputer and the Validator for main.mydsl. When I change identifier to name then it works well, which makes sense.

So I think the solution would be to use name for the requirement production rule and to hide the IDs of not dynamically generated requirements in the scoping.

Many thanks :)
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781173 is a reply to message #1781166] Fri, 02 February 2018 09:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12319
Registered: July 2009
Senior Member
how does your qualifiednameprovider look like?

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781176 is a reply to message #1781173] Fri, 02 February 2018 10:14 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
So far I m using the default one. I did no customizations yet.

Why you're asking?
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781177 is a reply to message #1781176] Fri, 02 February 2018 10:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12319
Registered: July 2009
Senior Member
But how can you reference Requirements then. the default will only look at objects with names

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781179 is a reply to message #1781177] Fri, 02 February 2018 10:33 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
In the IDerivedStateComputer I build a derived model of another meta model and in this derived model the element requirement has a name attribute, so that i can refer to it.
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781186 is a reply to message #1781177] Fri, 02 February 2018 11:32 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
So currently I believe that my approach is wrong ...

What I try:

When the user calls the function f1 for two times (see #1) then I will gernerate a unfolded model (derived model) in memory. The unfolded model would then corresponds to (#3).

At the end I plan to replace the function calls (f1) with the content of the function definition of f1 in the unfolded model. But additionally I have to gernerate unique IDs for the requirement to refer to them, because when I call f1 for two times, then I would have requirement r1 for two times in the derived model. And depending on the function arguments the content of the requirement block can be different.

So I want to generate one big unfolded model of mainXY.mydsl where all funtions calls are replaced by the content. Afterwards I want to do some addtional validation on this unfolded model.

What is the best way to implement such unfolded model in xtext. Maybe my approch is completelly wrong to do this in the IDerivedStateComputer...



Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781187 is a reply to message #1781186] Fri, 02 February 2018 11:34 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
Additonally I need the possibility to refer to elements of the unfolded model

[Updated on: Fri, 02 February 2018 11:35]

Report message to a moderator

Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781188 is a reply to message #1781187] Fri, 02 February 2018 11:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12319
Registered: July 2009
Senior Member
no usually i derivedstatecomputer is totally ok.
so i am not sure what exactly goes wrong in your case.
is this just about the "i change something" state or more.
have a look at

do did you debug the isAffectedCalcualtion



Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781195 is a reply to message #1781188] Fri, 02 February 2018 12:52 Go to previous messageGo to next message
Chris X is currently offline Chris XFriend
Messages: 60
Registered: November 2017
Member
When I use the name attribute for requirement, then it works fine.

But I have a general question:

Is it okay to refer to IDs of a derived model which is created in IDerivedStateComputer?
How works the Indexing, when I put the derived model to resource.contents.slot1 in IDerivedStateComputer?
Re: Refer to elements of a derived model in IDerivedStateComputer [message #1781196 is a reply to message #1781195] Fri, 02 February 2018 13:04 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12319
Registered: July 2009
Senior Member
the index works the very same so it ueses DefaultDeclarativeQualifiedNameProvider .

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[SOLVED] Confirming new renaming infracture is not for Xbase languages
Next Topic:Conflicting Regions for new line
Goto Forum:
  


Current Time: Tue Oct 16 16:30:57 GMT 2018

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

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

Back to the top