Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » setting information in ScopeProvider and Validator from outsite
setting information in ScopeProvider and Validator from outsite [message #674335] Thu, 26 May 2011 14:48 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1813
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I'm in the situation where I create an XtextEditor programmatically (for
my dsl) and upon creation I also create an object (let's say, a symbol
table) which is valid only for the program edited by that instance of
the editor; I need this object in the ScopeProvider and Validator, but I
don't know how to communicate this object to them (I also need it for
the content assist, but I think the procedure might be the same).

Any suggestion please?

many thanks in advance
Lore

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: setting information in ScopeProvider and Validator from outsite [message #674356 is a reply to message #674335] Thu, 26 May 2011 15:32 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
You can use an EMF adapter to associate data with the semantic objects.
I do that when computing documentation. The data in the adapter will
stay there as the EObject it is associated with is still valid (if
things are reparsed as a consequence of editing, quick fixes etc. the
data needs to be recomputed and set in an adapter in the new Eobjects
instances).

Hope that helps.
- henrik

On 5/26/11 4:48 PM, Lorenzo Bettini wrote:
> Hi
>
> I'm in the situation where I create an XtextEditor programmatically (for
> my dsl) and upon creation I also create an object (let's say, a symbol
> table) which is valid only for the program edited by that instance of
> the editor; I need this object in the ScopeProvider and Validator, but I
> don't know how to communicate this object to them (I also need it for
> the content assist, but I think the procedure might be the same).
>
> Any suggestion please?
>
> many thanks in advance
> Lore
>
Re: setting information in ScopeProvider and Validator from outsite [message #674369 is a reply to message #674356] Thu, 26 May 2011 16:25 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1813
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi Henrik

I'm not sure I understand... can you share your implementation/use please?

thanks in advance
Lorenzo

On 05/26/2011 05:32 PM, Henrik Lindberg wrote:
> You can use an EMF adapter to associate data with the semantic objects.
> I do that when computing documentation. The data in the adapter will
> stay there as the EObject it is associated with is still valid (if
> things are reparsed as a consequence of editing, quick fixes etc. the
> data needs to be recomputed and set in an adapter in the new Eobjects
> instances).
>
> Hope that helps.
> - henrik
>
> On 5/26/11 4:48 PM, Lorenzo Bettini wrote:
>> Hi
>>
>> I'm in the situation where I create an XtextEditor programmatically (for
>> my dsl) and upon creation I also create an object (let's say, a symbol
>> table) which is valid only for the program edited by that instance of
>> the editor; I need this object in the ScopeProvider and Validator, but I
>> don't know how to communicate this object to them (I also need it for
>> the content assist, but I think the procedure might be the same).
>>
>> Any suggestion please?
>>
>> many thanks in advance
>> Lore
>>
>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: setting information in ScopeProvider and Validator from outsite [message #674431 is a reply to message #674369] Thu, 26 May 2011 21:42 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
When you create your "XtextEditor programatically", I assumed you give
it input in the source form of your language, and that it gets parsed
and that you compute some information meaningful in that context. You
then want to find this information when xtext calls out for scoping,
validation, etc. etc. Any mechanism that makes it possible to associate
your information with "what is in the editor" is fine - there are
several ways:

- the parsed content is in a Resource, and this Resource is in a
ResourceSet - you can navigate from any object in the model to the
resource and then to the resource set. Simply add an additional resource
and you can find it.

- Xtext has scopes, but also containers, and containers have visibility
into other containers (how depends on which implementation that is bound
in your runtime). You can configure this so that things are visible to
only the things you are interested in (i.e. use java classpath, osgi
bundles, project dependencies, imports, etc). OTOH, if your visibility
is really "special stuff for a resource", than it is probably much
easier to use the first approach.

- you can associate information with individual objects in your model -
this is good for attaching information (as I said, I use this to
associate documentation that is parsed and processed from comments in
the source text), now I am working with some UI graph things were I need
to associate pieces of UI related material to model nodes.

Which of these seems to most resemble what you want to do? Can you
describe your "symbol table" a bit more (what is needed to compute it,
what makes it apply to only a single resource, etc...) as this helps
when answering your question.

I used all three approaches for different things, but I don't really
understand which code or documentation I should recommend you to look at
- at least not yet :)

- henrik

On 5/26/11 6:25 PM, Lorenzo Bettini wrote:
> Hi Henrik
>
> I'm not sure I understand... can you share your implementation/use please?
>
> thanks in advance
> Lorenzo
>
> On 05/26/2011 05:32 PM, Henrik Lindberg wrote:
>> You can use an EMF adapter to associate data with the semantic objects.
>> I do that when computing documentation. The data in the adapter will
>> stay there as the EObject it is associated with is still valid (if
>> things are reparsed as a consequence of editing, quick fixes etc. the
>> data needs to be recomputed and set in an adapter in the new Eobjects
>> instances).
>>
>> Hope that helps.
>> - henrik
>>
>> On 5/26/11 4:48 PM, Lorenzo Bettini wrote:
>>> Hi
>>>
>>> I'm in the situation where I create an XtextEditor programmatically (for
>>> my dsl) and upon creation I also create an object (let's say, a symbol
>>> table) which is valid only for the program edited by that instance of
>>> the editor; I need this object in the ScopeProvider and Validator, but I
>>> don't know how to communicate this object to them (I also need it for
>>> the content assist, but I think the procedure might be the same).
>>>
>>> Any suggestion please?
>>>
>>> many thanks in advance
>>> Lore
>>>
>>
>
>
Re: setting information in ScopeProvider and Validator from outsite [message #675069 is a reply to message #674431] Mon, 30 May 2011 08:01 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1813
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 05/26/2011 11:42 PM, Henrik Lindberg wrote:
> When you create your "XtextEditor programatically", I assumed you give
> it input in the source form of your language, and that it gets parsed
> and that you compute some information meaningful in that context. You
> then want to find this information when xtext calls out for scoping,
> validation, etc. etc. Any mechanism that makes it possible to associate
> your information with "what is in the editor" is fine - there are
> several ways:

well actually the information I need to pass to xtexteditor of my DSL is
a list of EMF objects that belong to another ecore (not the one of my
DSL), and that I'll use in my dsl just to check that some names in my
program can be found in that list

>
> - the parsed content is in a Resource, and this Resource is in a
> ResourceSet - you can navigate from any object in the model to the
> resource and then to the resource set. Simply add an additional resource
> and you can find it.

that's the solution I had originally thought of; actually, at the
moment, I'm inserting the additional information in the same resource of
the model of my DSL; you're saying it would be better to put it in the
resource set, right?

>
> - Xtext has scopes, but also containers, and containers have visibility
> into other containers (how depends on which implementation that is bound
> in your runtime). You can configure this so that things are visible to
> only the things you are interested in (i.e. use java classpath, osgi
> bundles, project dependencies, imports, etc). OTOH, if your visibility
> is really "special stuff for a resource", than it is probably much
> easier to use the first approach.
>
> - you can associate information with individual objects in your model -
> this is good for attaching information (as I said, I use this to
> associate documentation that is parsed and processed from comments in
> the source text), now I am working with some UI graph things were I need
> to associate pieces of UI related material to model nodes.
>

this might be another solution!

> Which of these seems to most resemble what you want to do? Can you
> describe your "symbol table" a bit more (what is needed to compute it,
> what makes it apply to only a single resource, etc...) as this helps
> when answering your question.

is it clear now from the first sentence of my answer? otherwise I can
get into more details.

>
> I used all three approaches for different things, but I don't really
> understand which code or documentation I should recommend you to look at
> - at least not yet :)
>

well all of them would be useful, especially the first and the third :)

many thanks in advance
Lorenzo

> - henrik
>
> On 5/26/11 6:25 PM, Lorenzo Bettini wrote:
>> Hi Henrik
>>
>> I'm not sure I understand... can you share your implementation/use
>> please?
>>
>> thanks in advance
>> Lorenzo
>>
>> On 05/26/2011 05:32 PM, Henrik Lindberg wrote:
>>> You can use an EMF adapter to associate data with the semantic objects.
>>> I do that when computing documentation. The data in the adapter will
>>> stay there as the EObject it is associated with is still valid (if
>>> things are reparsed as a consequence of editing, quick fixes etc. the
>>> data needs to be recomputed and set in an adapter in the new Eobjects
>>> instances).
>>>
>>> Hope that helps.
>>> - henrik
>>>
>>> On 5/26/11 4:48 PM, Lorenzo Bettini wrote:
>>>> Hi
>>>>
>>>> I'm in the situation where I create an XtextEditor programmatically
>>>> (for
>>>> my dsl) and upon creation I also create an object (let's say, a symbol
>>>> table) which is valid only for the program edited by that instance of
>>>> the editor; I need this object in the ScopeProvider and Validator,
>>>> but I
>>>> don't know how to communicate this object to them (I also need it for
>>>> the content assist, but I think the procedure might be the same).
>>>>
>>>> Any suggestion please?
>>>>
>>>> many thanks in advance
>>>> Lore
>>>>
>>>
>>
>>
>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: setting information in ScopeProvider and Validator from outsite [message #675089 is a reply to message #675069] Mon, 30 May 2011 09:32 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1813
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 05/30/2011 10:01 AM, Lorenzo Bettini wrote:
> On 05/26/2011 11:42 PM, Henrik Lindberg wrote:
>> When you create your "XtextEditor programatically", I assumed you give
>> it input in the source form of your language, and that it gets parsed
>> and that you compute some information meaningful in that context. You
>> then want to find this information when xtext calls out for scoping,
>> validation, etc. etc. Any mechanism that makes it possible to associate
>> your information with "what is in the editor" is fine - there are
>> several ways:
>
> well actually the information I need to pass to xtexteditor of my DSL is
> a list of EMF objects that belong to another ecore (not the one of my
> DSL), and that I'll use in my dsl just to check that some names in my
> program can be found in that list
>
>>
>> - the parsed content is in a Resource, and this Resource is in a
>> ResourceSet - you can navigate from any object in the model to the
>> resource and then to the resource set. Simply add an additional resource
>> and you can find it.
>
> that's the solution I had originally thought of; actually, at the
> moment, I'm inserting the additional information in the same resource of
> the model of my DSL; you're saying it would be better to put it in the
> resource set, right?
>

Hi

I tried to use the resource set instead of the resource itself, but I'm
experiencing some problems with this approach (even with the approach
modifying the resource directly):

I can update the resource set with the additional information ONLY after
the xtext editor contents is already set, and thus the validator of my
DSL is invoked when the editor is opened and it still hasn't access to
additional information...

I was wondering whether it would be possible to temporarily disable
validation and to enable it again after I set the additional information...

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Previous Topic:Error while validation
Next Topic:Scope Provider is not deterministic.
Goto Forum:
  


Current Time: Tue Sep 24 23:44:15 GMT 2024

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

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

Back to the top