ReformatCodeProcessor with custom settings

I create a file and want it to be formatted. For example, so that there are no empty lines. How can I use ReformatCodeProcessor with custom settings? Something like that:

CodeStyleSettings settings = CodeStyle.getSettings(project);
XmlCodeStyleSettings xmlCodeStyleSettings = settings.getCustomSettings(XmlCodeStyleSettings.class);
int xml_keep_blank_lines = xmlCodeStyleSettings.XML_KEEP_BLANK_LINES;
xmlCodeStyleSettings.XML_KEEP_BLANK_LINES = 0;
ReformatCodeProcessor reformatCodeProcessor = new ReformatCodeProcessor(project, xmlFile, null, false);
reformatCodeProcessor.run();
xmlCodeStyleSettings.XML_KEEP_BLANK_LINES = xml_keep_blank_lines;

but it doesn't work and looks scary.

Please sign in to leave a comment.