Home » Modeling » TMF (Xtext) » Loading model objects(About importing models in xtext)
Loading model objects [message #643899] |
Wed, 08 December 2010 16:14 |
Darie Moldovan Messages: 67 Registered: November 2010 Location: Darmstadt, Germany |
Member |
|
|
Hi everyone,
I have a question regarding XText and some Ecore. I hope I'm submitting this topic into the right category
The xtext grammar is not so important regarding my question, you will understand why.
I built an xtext editor for a special language and want to implement some features, like a context-sensitive autocomplete.
Please read the following extract from a file, which I open with my xtext editor:
reference ref1 ( uri "file1.isr" )
reference ref2 ( uri "file2.bpmn2" )
endpoint A (
reference ref1
object obj1
)
endpoint B (
reference ref1
object obj2
)
endpoint C (
reference ref2
object obj3
)
As you can see, I loaded two models (which are two separate files located in the same project as the file I'm editing) via the reference keyword, which is defined in my xtext grammar as follows:
Reference:
'reference' name=ID '('
'uri' importURI=STRING
')'
;
No big deal, it's all about loading some resources and using them as data models.
As you can see in the example in the beginning of this topic, I have several endpoint elements with some properties. The reference property tells me: "hey, this object has something to do with ref1, for example", where ref1 is defined at the top of the file as "file1.isr". When the user hits Ctrl+space in the second property, namely object, I want the autocompleter to only suggest things from the file1.isr model (let's say only obj1 and obj2 are defined in file1.isr, obj3 is defined in file2.bpmn2).
By default, Xtext adds to the suggestion list of the autocompleter everything it finds from both referenced models, file1.isr and file2.bpmn2, which is not what I want. For example, Xtext makes no difference if I write nonsense, like
endpoint A (
reference ref1
object obj3
)
although obj3 is defined in ref2 and not in ref1. The context sensitivity, if I may name it like that, is important to me.
I've tried some things which are pretty hard to explain, especially if I'm not even sure, someone is gonna read/reply to this topic.
But I can give more details if someone is interested. Until then, my question is: HOW can I acces the objects in a referenced model?
I think this is pretty much Ecore and only little Xtext. May be. I'm not interesting in basics, like in which class to customize the autocompleter. I'm more interested in hints like where to look in order to understand how xtext and ecore communicate to manage imported models.
Thank you in advance.
|
|
|
Re: Loading model objects [message #643933 is a reply to message #643899] |
Wed, 08 December 2010 17:51 |
Sven Efftinge Messages: 1823 Registered: July 2009 |
Senior Member |
|
|
You have to implement scoping for the object reference.
That should navigate to the referenced 'reference' model and only add
elements contained therein to scope.
It's all explained in the documentation (section scoping).
Sven
Am 12/8/10 5:14 PM, schrieb Darie:
> Hi everyone,
>
> I have a question regarding XText and some Ecore. I hope I'm submitting
> this topic into the right category :)
> The xtext grammar is not so important regarding my question, you will
> understand why.
>
> I built an xtext editor for a special language and want to implement
> some features, like a context-sensitive autocomplete.
> Please read the following extract from a file, which I open with my
> xtext editor:
>
> reference ref1 ( uri "file1.isr" )
> reference ref2 ( uri "file2.bpmn2" )
>
> endpoint A (
> reference ref1
> object obj1
> )
>
> endpoint B (
> reference ref1
> object obj2
> )
>
> endpoint C (
> reference ref2
> object obj3
> )
>
> As you can see, I loaded two models (which are two separate files
> located in the same project as the file I'm editing) via the reference
> keyword, which is defined in my xtext grammar as follows:
>
> Reference:
> 'reference' name=ID '('
> 'uri' importURI=STRING
> ')'
> ;
>
> No big deal, it's all about loading some resources and using them as
> data models.
> As you can see in the example in the beginning of this topic, I have
> several endpoint elements with some properties. The reference property
> tells me: "hey, this object has something to do with ref1, for example",
> where ref1 is defined at the top of the file as "file1.isr". When the
> user hits Ctrl+space in the second property, namely object, I want the
> autocompleter to only suggest things from the file1.isr model (let's say
> only obj1 and obj2 are defined in file1.isr, obj3 is defined in
> file2.bpmn2).
> By default, Xtext adds to the suggestion list of the autocompleter
> everything it finds from both referenced models, file1.isr and
> file2.bpmn2, which is not what I want. For example, Xtext makes no
> difference if I write nonsense, like
> endpoint A (
> reference ref1
> object obj3
> )
>
> although obj3 is defined in ref2 and not in ref1. The context
> sensitivity, if I may name it like that, is important to me.
>
> I've tried some things which are pretty hard to explain, especially if
> I'm not even sure, someone is gonna read/reply to this topic.
>
> But I can give more details if someone is interested. Until then, my
> question is: HOW can I acces the objects in a referenced model?
> I think this is pretty much Ecore and only little Xtext. May be. I'm not
> interesting in basics, like in which class to customize the
> autocompleter. I'm more interested in hints like where to look in order
> to understand how xtext and ecore communicate to manage imported models.
>
> Thank you in advance.
--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
|
|
| | |
Goto Forum:
Current Time: Sat Apr 27 02:00:51 GMT 2024
Powered by FUDForum. Page generated in 0.04120 seconds
|