Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Accessing model context in quickfix
Accessing model context in quickfix [message #987066] Fri, 23 November 2012 04:32 Go to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 269
Registered: August 2009
Senior Member
Hello,

In one of my quickfix rules, I need to supply multiple fixes depending on my model (calling the accept method on the acceptor several times depending on the current state of my model). The only problem is that I have no clue how to access the model element which is in error/warning.
The only arguments which are passed to the quickfix method are an Issue and a IssueResolutionAcceptor. I can pass custom arguments to the Issue while creating it in my validator class but those can only be Strings.

Is there a way to retrieve my model element in the quickfix method ?

Thanks
Re: Accessing model context in quickfix [message #987214 is a reply to message #987066] Sat, 24 November 2012 09:36 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo Bettini
Messages: 1260
Registered: July 2009
Senior Member
On 11/23/2012 10:32 AM, Cedric Moonen wrote:
> Hello,
>
> In one of my quickfix rules, I need to supply multiple fixes depending
> on my model (calling the accept method on the acceptor several times
> depending on the current state of my model). The only problem is that I
> have no clue how to access the model element which is in error/warning.
> The only arguments which are passed to the quickfix method are an Issue
> and a IssueResolutionAcceptor. I can pass custom arguments to the Issue
> while creating it in my validator class but those can only be Strings.
>
> Is there a way to retrieve my model element in the quickfix method ?
>
> Thanks

it's documented here

http://www.eclipse.org/Xtext/documentation.html#quickfixes

in particular in the second example

cheers
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
Re: Accessing model context in quickfix [message #987328 is a reply to message #987066] Mon, 26 November 2012 02:26 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 269
Registered: August 2009
Senior Member
Lorenzo,

Thanks for your reply. However, I'm not sure you understood what I want to do. What I really want is to be access some 'model context' (so, similar as the IModificationContext) but not within the 'apply' method of a ISemanticModification.

I want to access that context within the fix method itself: at the beginning of my method I would like to retrieve some information from the model to be able to know how many quick fixes I have to create (and the text I have to display for each of them).

Unfortunately, I didn't find a way to access that information. I tried to look at how Xtext creates the IModificationContext object supplied to the ISemanticModification but it is incredibly complex and I'm not too sure how to implement this...
Re: Accessing model context in quickfix [message #987362 is a reply to message #987328] Mon, 26 November 2012 04:57 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 655
Registered: July 2009
Senior Member
Cedric,

in the Quickfix API there is a strict separation on whether the model is
available or not. We have to make that separation because some of the
elements, e.g. the Issues and the IModifcation objects, are persisted
and available without any editor opened. The are needed e.g. to show the
lightbulbs in the problems view.

In the method annotated with @Fix is called when there it is *not*
available, so all decisions you want not make here must be based on
what's in the Issue. The issue has a String array "data" that can be
populated by the validation rule creating the issue to transfer more
information. It is of type String, as it has to be persisted in the
absence of any model.

Hope that clarifies things a bit
Jan


Am 26.11.12 08:26, schrieb Cedric Moonen:
> Lorenzo,
> Thanks for your reply. However, I'm not sure you understood what I want
> to do. What I really want is to be access some 'model context' (so,
> similar as the IModificationContext) but not within the 'apply' method
> of a ISemanticModification.
>
> I want to access that context within the fix method itself: at the
> beginning of my method I would like to retrieve some information from
> the model to be able to know how many quick fixes I have to create (and
> the text I have to display for each of them).
>
> Unfortunately, I didn't find a way to access that information. I tried
> to look at how Xtext creates the IModificationContext object supplied to
> the ISemanticModification but it is incredibly complex and I'm not too
> sure how to implement this...
>


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Accessing model context in quickfix [message #987373 is a reply to message #987362] Mon, 26 November 2012 05:48 Go to previous message
Cedric Moonen is currently offline Cedric Moonen
Messages: 269
Registered: August 2009
Senior Member
Jan,

Thanks for the reply. I understand now why this context information is not available in the quick fix method. I found a workaround by using the string array that you can pass in the issue.
Previous Topic:Unit testing hidden terminal - ParseHelper returning null model
Next Topic:Running the Xtext machinery outside the builder
Goto Forum:
  


Current Time: Sun Apr 20 09:41:32 EDT 2014

Powered by FUDForum. Page generated in 0.04614 seconds