Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatter is triggered on quickfix
Formatter is triggered on quickfix [message #1804356] Sun, 24 March 2019 12:43 Go to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Hi all,

Is there a way to disable the formatter when quickfix is used?

I am having an issue where regionForEObject always returns null if the formatter was triggered by a quickfix. It works fine otherwise. Why does that occur?

I also noticed that the region of the request in case of quickfix is empty while normally it would be [0:length of file].

Re: Formatter is triggered on quickfix [message #1804357 is a reply to message #1804356] Sun, 24 March 2019 12:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13190
Registered: July 2009
Senior Member
Can you give more context about the kind and content of your QuickFix
Samefor the formatter


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sun, 24 March 2019 13:05]

Report message to a moderator

Re: Formatter is triggered on quickfix [message #1804358 is a reply to message #1804357] Sun, 24 March 2019 13:25 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
The quickfix modifies a feature within some EObject.

The formatter gives a NullPointerException when regionForEObject is used. The section where the regionForEObject is used though is for formatting a completely different EObject.
To clarify:
- Trigger quickfix on GreetingEObject
- Formatter gives NullPointerException when regionForEObject is used inside the format function for HelloEObject (HelloEObject is one that exists in the same file where the quickfix was applied)
Re: Formatter is triggered on quickfix [message #1804359 is a reply to message #1804358] Sun, 24 March 2019 13:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13190
Registered: July 2009
Senior Member
Can you please provide a complete minimal example


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Formatter is triggered on quickfix [message #1804360 is a reply to message #1804359] Sun, 24 March 2019 13:33 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
I will try to now.
Re: Formatter is triggered on quickfix [message #1805251 is a reply to message #1804360] Wed, 10 April 2019 12:19 Go to previous message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Fixed by forcing the use of the injected IFormatter found in the org.eclipse.xtext.serializer.impl.Serializer class by setting formatter2Provider to null using reflection.
The Serializer class null checks the formatter2Provider before formatting and if it is null it uses the IFormatter which is a basic OneWhitespaceFormatter.
public class MyDslSerializer extends Serializer {

   private boolean updatedFormatter2Provider = false; 

   /*
    * - Set formatter2Provider to null by using reflection
    */
   private void nullifyFormatter2Provider() {
      if (!updatedFormatter2Provider) {
         try {
            Field field = Serializer.class.getDeclaredField("formatter2Provider");
            field.setAccessible(true);
            field.set(this, null);
            updatedFormatter2Provider = true;
         } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
         }
      }
   }

   @Override
   public String serialize(EObject obj, SaveOptions options) {
      nullifyFormatter2Provider();
      return super.serialize(obj, options);
   }

   @Override
   public void serialize(EObject obj, Writer writer, SaveOptions options) throws IOException {
      nullifyFormatter2Provider();
      super.serialize(obj, writer, options);
   }
}
Previous Topic:How to validate through all objects
Next Topic:[Formatter2] append newLine + spaces
Goto Forum:
  


Current Time: Fri Nov 15 07:27:11 GMT 2019

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

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

Back to the top