How to get the “Reformat code” function out of IntelliJ IDEA?

眉间皱痕 提交于 2019-12-22 04:37:13

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/5805960/how-to-get-the-reformat-code-function-out-of-intellij-idea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!