Formatter is triggered on quickfix [message #1804356] |
Sun, 24 March 2019 08:43  |
Eclipse User |
|
|
|
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 #1805251 is a reply to message #1804360] |
Wed, 10 April 2019 08:19  |
Eclipse User |
|
|
|
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);
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.05378 seconds