Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » create object if no ref found
create object if no ref found [message #634090] Wed, 20 October 2010 13:42 Go to next message
Eclipse UserFriend
Originally posted by: marcel-groups.troos-online.de

Hi,

is there a way to automatically create a new object if no ref could be
found?

Currently this is my .xtext:

Root:
systems+=System+;

System:
'The sys ' SystemTerminal ' consists of:' (subsystems+=SystemPart ',')*
(subsystems+=SystemPart '.');

SystemTerminal returns System:
name=ID;

SystemPart:
type=[System] name=ID;

Id like to use something like:


The sys X consists of: Y part1, Z part2.

The sys Y consists of: Z part3.

The sys OVERALL consists of: X foo.


X,Y,Z and OVERALL should be 'systems', that will be either referenced or
-if no reference was found- created.

I tried something like...

SystemPart:
(type=[System] | type=SystemTerminal) name=ID;


.... but obviously it's not working that way.

Thanks

Best regards

Marcel
Re: create object if no ref found [message #634115 is a reply to message #634090] Wed, 20 October 2010 14:32 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Yeah it's possible.
You should do it in the linker, whenerver a broken link
is found (i.e. there is no System for a given name), you could
create a new System. You should add those systems somewhere where it
doesn't get into the way of Xtext.

Maybe as additional eobjects in the Resource.eContents() list or even a
dedicated synthetic resource.

Sven

Am 10/20/10 3:42 PM, schrieb Marcel Sander:
> Hi,
>
> is there a way to automatically create a new object if no ref could be
> found?
>
> Currently this is my .xtext:
>
> Root:
> systems+=System+;
>
> System:
> 'The sys ' SystemTerminal ' consists of:' (subsystems+=SystemPart ',')*
> (subsystems+=SystemPart '.');
>
> SystemTerminal returns System:
> name=ID;
>
> SystemPart:
> type=[System] name=ID;
>
> Id like to use something like:
>
>
> The sys X consists of: Y part1, Z part2.
>
> The sys Y consists of: Z part3.
>
> The sys OVERALL consists of: X foo.
>
>
> X,Y,Z and OVERALL should be 'systems', that will be either referenced or
> -if no reference was found- created.
>
> I tried something like...
>
> SystemPart:
> (type=[System] | type=SystemTerminal) name=ID;
>
>
> ... but obviously it's not working that way.
>
> Thanks
>
> Best regards
>
> Marcel


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: create object if no ref found [message #634182 is a reply to message #634115] Wed, 20 October 2010 17:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: marcel-groups.troos-online.de

Thanks for your response.

Am I right to hook into

public IScope scope_System(EObject ctx, EReference ref)

?
If yes: How would I create the IScope for the new object?

Marcel

Am 20.10.2010 16:32, schrieb Sven Efftinge:
> Yeah it's possible.
> You should do it in the linker, whenerver a broken link
> is found (i.e. there is no System for a given name), you could
> create a new System. You should add those systems somewhere where it
> doesn't get into the way of Xtext.
>
> Maybe as additional eobjects in the Resource.eContents() list or even a
> dedicated synthetic resource.
>
> Sven
>
> Am 10/20/10 3:42 PM, schrieb Marcel Sander:
>> Hi,
>>
>> is there a way to automatically create a new object if no ref could be
>> found?
>>
>> Currently this is my .xtext:
>>
>> Root:
>> systems+=System+;
>>
>> System:
>> 'The sys ' SystemTerminal ' consists of:' (subsystems+=SystemPart ',')*
>> (subsystems+=SystemPart '.');
>>
>> SystemTerminal returns System:
>> name=ID;
>>
>> SystemPart:
>> type=[System] name=ID;
>>
>> Id like to use something like:
>>
>>
>> The sys X consists of: Y part1, Z part2.
>>
>> The sys Y consists of: Z part3.
>>
>> The sys OVERALL consists of: X foo.
>>
>>
>> X,Y,Z and OVERALL should be 'systems', that will be either referenced or
>> -if no reference was found- created.
>>
>> I tried something like...
>>
>> SystemPart:
>> (type=[System] | type=SystemTerminal) name=ID;
>>
>>
>> ... but obviously it's not working that way.
>>
>> Thanks
>>
>> Best regards
>>
>> Marcel
>
>
Re: create object if no ref found [message #634532 is a reply to message #634182] Fri, 22 October 2010 06:48 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Am 10/20/10 7:12 PM, schrieb Marcel Sander:
> Thanks for your response.
>
> Am I right to hook into
>
> public IScope scope_System(EObject ctx, EReference ref)
>
> ?
> If yes: How would I create the IScope for the new object?


No I meant overriding DefaultLinkingService
and therein getLinkedObjects()

If it returns an empty list for an EReference to system.
create one and call the method again.

Sven

--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: create object if no ref found [message #636930 is a reply to message #634115] Wed, 03 November 2010 12:09 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi Sven,

I get a ConcurrentModificationException when adding generated objects in Resource.eContents while linking.

It works to put it in a list of Model. But this brings some issues.

Can you suggest another place?

How can I delete the generated object when all references are removed?

Thx,
Marco
Re: create object if no ref found [message #650394 is a reply to message #634090] Mon, 24 January 2011 17:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Stefan-Isele.gmx.de

Hi Marcel, did you find a solution for this problem ?
I also had some trouble to create/delete/reference objects. It works somehow but its everything else than elegant.

with best regards

Stefan Isele

This is my post from today :
Hello,
I want to calculate derived properties in my model and reference them, without changing the dsl-file.

My dsl contains a dto that is based on a table:
Dto:
'dto' name=ID 'basedOn' basedOn=[sql::Table|QualifiedName]
includeAll?='includeAll'
('properties' '{' properties+=Property* '}')?;

When 'includeAll' is entered, I want to calculate the properties of the Dto using the tables columns.
Other elements that reference a dtos properties should be able to use these calculated properties as well.

Where and how would you do that ?

So far I added an attribute Dto.calculatedProperties using a postprocessor. I put the calculated properties there. This
works more or less, but every now and than I get some race conditions. I know that changing the model should be done in
IUnitOfWork using IXtextDocument but how can I find the IXtextDocument of an EObject ?
Anyway this would only work in the gui. How would it be done in the generator ?

Any help would be appreciated,

Stefan Isele


Marcel Sander schrieb:
> Hi,
>
> is there a way to automatically create a new object if no ref could be
> found?
>
> Currently this is my .xtext:
>
> Root:
> systems+=System+;
>
> System:
> 'The sys ' SystemTerminal ' consists of:' (subsystems+=SystemPart ',')*
> (subsystems+=SystemPart '.');
>
> SystemTerminal returns System:
> name=ID;
>
> SystemPart:
> type=[System] name=ID;
>
> Id like to use something like:
>
>
> The sys X consists of: Y part1, Z part2.
>
> The sys Y consists of: Z part3.
>
> The sys OVERALL consists of: X foo.
>
>
> X,Y,Z and OVERALL should be 'systems', that will be either referenced or
> -if no reference was found- created.
>
> I tried something like...
>
> SystemPart:
> (type=[System] | type=SystemTerminal) name=ID;
>
>
> ... but obviously it's not working that way.
>
> Thanks
>
> Best regards
>
> Marcel
icon5.gif  Re: create object if no ref found [message #652754 is a reply to message #650394] Sun, 06 February 2011 11:53 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi,

I followed Sven's suggestion and implicitly create variable declarations (var x) in a dummy resource. That way my model can have multiple variable definitions (x=1, x=2) belonging to the same variable object without the need of an explicit variable declaration.

That works. But how can I remove the variable declaration after all its definitions have be removed or renamed?

I need a hook for my custom code. I know that I could register listeners for the variable definitions. But is this really the simplest way?

Thanks,
Marco
Re: create object if no ref found [message #652776 is a reply to message #652754] Sun, 06 February 2011 16:29 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Marco,

one would usually remove all demand-created objects in
AbstractCleaningLinker#beforeModelLinked.

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

Am 06.02.11 12:53, schrieb Marco:
> Hi,
>
> I followed Sven's suggestion and implicitly create variable declarations
> (var x) in a dummy resource. That way my model can have multiple
> variable definitions (x=1, x=2) belonging to the same variable object
> without the need of an explicit variable declaration.
>
> That works. But how can I remove the variable declaration after all its
> definitions have be removed or renamed?
>
> I need a hook for my custom code. I know that I could register listeners
> for the variable definitions. But is this really the simplest way?
>
> Thanks,
> Marco
Re: create object if no ref found [message #656596 is a reply to message #652776] Sun, 27 February 2011 11:10 Go to previous message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi,

There is still one limitation with forward or cyclic references. As I create variable declaration objects only for references in variable definition (left of the =):
def x  =  ref y +1
def y  = ref x - 1


The parser just creates the definition objects. But the references refer to declaration objects.

Linking def x creates dec x. Linking ref y fails because def y not yet linked, and therefore dec y not created.

I could include a code in the scoping of ref which after finding nothing the normal way checks all the resources for all defs, and if successful there run the same creation of creation of a dec and request scope again. But this would not be very smart nor fast.

It would be better if I could control that first all linking for defs is done, and then the linking of the rest, ie linking of refs.

Another nice way would be if I could defer a failed linking of refs until all other linking.

But I think both options would fail again if the model is spread in multiple resources, right?

So what is a clever approach?

Thanks,
Marco
Previous Topic:Best practices / performance for Scoping / Object iteration?
Next Topic:#a, #b, #c, #d, #f are not recognized by the parser
Goto Forum:
  


Current Time: Thu Apr 25 18:02:03 GMT 2024

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

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

Back to the top