如何获取“重新格式化代码” IntelliJ IDEA 的功能?
我喜欢 IntelliJ IDEA 的“重新格式化代码...”(Ctrl+Alt+L) 功能。
现在我有很多 XML 文件需要查看。我现在要做的是,我打开一个xml文件,全选,复制并粘贴到IntelliJ IDEA打开的xml文件中,然后使用“重新格式化代码...”来美化xml文件,之后,我复制将格式化的 xml 文件恢复为原始 xml 文件。
这很耗时而且一点也不有趣。
如果“重新格式化代码...”功能可以从 IntelliJ IDEA 中取出到命令行工具中来一次性美化我的所有 xml 文件(任何其他文件,如 java、...),那就太好了。
于是我开始研究ideaIC-99.18的源码。并找到 CodeFormatterFacade 类和包 com.intellij.formatting。但在我看来,仍然需要做很多工作。
有没有人想到过或者以前做过?任何建议表示赞赏。多谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IntelliJ IDEA 格式化程序与其余代码紧密耦合。让它独立运行的最简单方法是编写一个实现 ApplicationStarter 接口的插件,该插件允许创建基于 IntelliJ IDEA 的基于命令行的工具。这种方法的一大缺点是运行该工具仍会初始化 IntelliJ IDEA 的大部分内部结构,因此速度不会很快。
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.