Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Extend QuickFix behaviour
Extend QuickFix behaviour [message #777509] Tue, 10 January 2012 16:07 Go to next message
Darie Moldovan is currently offline Darie MoldovanFriend
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
Hi, by default, QuickFix is enabled in Xtext editors and it's working fine. Now, I want to extend that behaviour and add my own "fixes", as can be seen in the following example:

object obj1 (
     ...
)

object obj2 extends obj15 (
                    ^^^^^
)


The underlined name in the above example points to an object that is not declared. This would automatically trigger the QuickFix mechanism of Xtext, which is right. It would then suggest something like "Change to obj1", which is nice.

But: I want to customize that behaviour and give the user the possibility to choose between several options, like:


  1. Change to ... (always shown, by default)
  2. Create object obj15 (my suggestion, how to add it here?)
  3. ...


I tried doing that following some tutorials I found on the web about implementing quickfix. The problem is that I cannot do the following two things:


  • I don't know how to access what the user wrote (in this case: obj15), so that I can then add a suggestion in the quickfix list like "Create object obj15"
  • I don't know how to add my own suggestions in the default list of the quickfix, as seen above


Quickfix works for me, I wrote the necessary classes in the validator and in the QuickFix class and they are called properly. the things that do not work are mentioned above.

Any help is kindly appreciated.
Re: Extend QuickFix behaviour [message #777534 is a reply to message #777509] Tue, 10 January 2012 16:36 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Hi Darie,

You may want to have a look at the Domainmodel example (File / New / Example / Xtext Examples), there is an implementation example for quickfixes.

Quote:
I don't know how to access what the user wrote (in this case: obj15)

You have to add everything that you need as context information in the user data when creating the validation issue in the validation class, e.g. the object name, and an issue code.
        if (!Character.isUpperCase(entity.getName().charAt(0))) {
            warning("Name should start with a capital", 
            		DomainmodelPackage.Literals.ENTITY__NAME,
            		ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
            		IssueCodes.INVALID_TYPE_NAME, 
            		entity.getName()); <-- the user data for quickfix!
        }


Quote:
I don't know how to add my own suggestions in the default list of the quickfix, as seen above

Just add @Fix methods for the same issue code to the quickfix provider.

Kind regards,
~Karsten


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Extend QuickFix behaviour [message #778311 is a reply to message #777509] Thu, 12 January 2012 10:11 Go to previous messageGo to next message
Darie Moldovan is currently offline Darie MoldovanFriend
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
Hey Karsten, thanks for the reply. I get your point, but how do I get the name of the inexisting object ("obj15" in my previous example) in the quickfix method, if the signature only contains an Issue-object and an IssueResolutionAcceptor?

@Fix(MyDSLJavaValidator.INEXISTING_OBJECT)
public void createObjectInModel(final Issue issue, IssueResolutionAcceptor acceptor)
{
     String nameOfInexistingObject = ... // should be "obj15", but how do I get this?
     warning(...);
}


Because we said we want to create a quick fix suggesting something like "Create object obj15".

For now I just print out some message in the console to test if the quick fix is working, and it does. I just cannot customize it as described above.

Best regards
Re: Extend QuickFix behaviour [message #778323 is a reply to message #778311] Thu, 12 January 2012 11:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

as Karsten said: you can ask the Issue for its user data (Issue.getData)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Extend QuickFix behaviour [message #778325 is a reply to message #778323] Thu, 12 January 2012 11:55 Go to previous messageGo to next message
Darie Moldovan is currently offline Darie MoldovanFriend
Messages: 67
Registered: November 2010
Location: Darmstadt, Germany
Member
I do agree with that, but first I must set some issue data in the MyDSLJavaValidator when I call

@Check
public void checkObject(Object object) {
     error("Some message", null, INEXISTING_OBJECT, "");
                                                    ^^^


I should here first determine what the user wrote (here: "obj15") and set this string as the issue data, to be able to get it's value in the quick fix method.

Otherwise the issueData won't contain anything (as it does right now in my case...).

But: I do not have access to what the user wrote. Do I have to search the document "by hand" for the incorrect text ("obj15")? If yes, do you have any suggestions for optimizing this search?

Thanks for your help.

Later edit: I took a look at the domain model example, I tried some of that code, it didn't help much. What concerns me is how you determine that entity.getName() in the MyDSLValidator (where you get it from), which Karsten mentioned in his first post.

[Updated on: Thu, 12 January 2012 11:58]

Report message to a moderator

Re: Extend QuickFix behaviour [message #778354 is a reply to message #778325] Thu, 12 January 2012 14:54 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

you are talking about not existing references. this is totally different from what karsten mentioned.
you can use NodeModelUtils to find the text of the reference
search the forum for details

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Xtext 2.2] How to wait for reconciler to finish its work?
Next Topic:JvmTypesBuilder.toConstructor does not set the body
Goto Forum:
  


Current Time: Tue Apr 23 06:37:36 GMT 2024

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

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

Back to the top