如何获得“重新格式化代码” IntelliJ IDEA的功能? [英] How to get the "Reformat code" function out of IntelliJ IDEA?

查看:899
本文介绍了如何获得“重新格式化代码” IntelliJ IDEA的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢IntelliJ IDEA的重新格式代码...(Ctrl + Alt + L)功能。

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

现在我有很多XML文件可供使用通过。我现在正在做的是,我打开一个xml文件,选择全部,复制并粘贴到IntelliJ IDEA打开的xml文件中,然后使用重新格式代码...来美化xml文件,之后,我复制了将格式化的xml文件恢复为原始的xml文件。

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.

如果可以将重新格式化代码...功能从IntelliJ IDEA中取出到命令行工具中,以便同时美化我的所有xml文件(任何其他文件,如java,...),那就太棒了。

所以我开始研究ideaIC-99.18的源代码。并找到CodeFormatterFacade类并打包com.intellij.formatting。但对我来说,看起来仍然需要做很多工作。

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!

推荐答案

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.

这篇关于如何获得“重新格式化代码” IntelliJ IDEA的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆