Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Formatter is triggered on quickfix
Formatter is triggered on quickfix [message #1804356] Sun, 24 March 2019 08:43 Go to next message
Eclipse UserFriend
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 08:53 Go to previous messageGo to next message
Eclipse UserFriend
Can you give more context about the kind and content of your QuickFix
Samefor the formatter

[Updated on: Sun, 24 March 2019 09:05] by Moderator

Re: Formatter is triggered on quickfix [message #1804358 is a reply to message #1804357] Sun, 24 March 2019 09:25 Go to previous messageGo to next message
Eclipse UserFriend
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 09:27 Go to previous messageGo to next message
Eclipse UserFriend
Can you please provide a complete minimal example
Re: Formatter is triggered on quickfix [message #1804360 is a reply to message #1804359] Sun, 24 March 2019 09:33 Go to previous messageGo to next message
Eclipse UserFriend
I will try to now.
Re: Formatter is triggered on quickfix [message #1805251 is a reply to message #1804360] Wed, 10 April 2019 08:19 Go to previous message
Eclipse UserFriend
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:Breakpoint in outside workspace model file
Goto Forum:
  


Current Time: Mon Mar 24 10:06:00 EDT 2025

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

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

Back to the top