How to get the "Reformat code" function out of IntelliJ IDEA?
Asked Answered
K

1

7

I love the "Reformat code..." (Ctrl+Alt+L) function of IntelliJ IDEA.

Now I have a lot of XML files to look through. What I am doing now is, I open a xml file, select all, copy and paste into a xml file opened by IntelliJ IDEA, then use the "Reformat code..." to beautify the xml file, after that, I copy the formatted xml file back to the original xml file.

It is time consuming and not fun at all.

It would be great if the "Reformat code..." function can be taken out of IntelliJ IDEA into a command line tool to beautify all my xml files (any other files like java, ...) all at once.

So I begin to study the source code of ideaIC-99.18. And find the CodeFormatterFacade class and package com.intellij.formatting. But it still looks like, to me, will need a lot of work to do.

Does anyone ever think of it of have done it before? Any suggestions are appreciated. Thanks a lot!

Karikaria answered 27/4, 2011 at 14:44 Comment(1)
Found this looking for the IdeaU shortcut for XML Cleanup (Thank you btw)... and it might be a little out of the left field, since you asked this question 3 years ago... but if you are still interested, you should try Notepad++ with the plugin XML Tools. Cntrl-Shift-Alt-B and XML File gets cleaned up/reformatted.Cheryle
H
7

The IntelliJ IDEA formatter is pretty tightly coupled to the rest of the code. The easiest way to have it run standalone is to write a plugin implementing the ApplicationStarter interface, which allows to create command line-based tools based on IntelliJ IDEA. The big downside of this approach is that running the tool will still initialize most of IntelliJ IDEA's internals, so it will not be very fast.

Hoban answered 27/4, 2011 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.