独立的 Java 代码格式化程序/美化程序/漂亮的打印机? [英] Stand-alone Java code formatter/beautifier/pretty printer?

查看:39
本文介绍了独立的 Java 代码格式化程序/美化程序/漂亮的打印机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣了解高质量、独立的 Java 源代码格式化程序的可用选择.

格式化程序必须是独立的,也就是说,它必须支持批处理"模式,即<强>与任何特定的开发环境分离.理想情况下,它也应该独立于任何特定的操作系统.因此,IDE du jour 的内置格式化程序在这里没什么意义(除非 IDE 支持批处理模式格式化程序调用,可能是从命令行调用).用闭源 C/C++ 编写的格式化程序只能在 Windows 上运行,虽然并不理想,但有点有趣.

The formatter must be stand-alone, that is, it must support a "batch" mode that is decoupled from any particular development environment. Ideally, it should be independent of any particular operating system as well. So, a built-in formatter for the IDE du jour is of little interest here (unless that IDE supports batch mode formatter invocation, perhaps from the command line). A formatter written in closed-source C/C++ that only runs on, say, Windows is not ideal, but is somewhat interesting.

需要明确的是,格式化程序"(或美化器")与样式检查器"不同.格式化程序接受源代码作为输入,应用样式规则并生成样式在语义上等同于原始源代码的源代码.语法修改仅限于修改代码布局(如更改空格)或组织 import 语句.很少(如果有的话)执行其他重构.样式检查器也应用样式规则,但它只是报告违反规则而不产生修改的源代码作为输出.所以图片看起来是这样的:

To be clear, a "formatter" (or "beautifier") is not the same as a "style checker." A formatter accepts source code as input, applies styling rules, and produces styled source code that is semantically equivalent to the original source code. Syntactic modifications are limited to things like modifying code layout as in changing whitespace, or organizing import statements. Very little, if any, other refactoring is performed. A style checker also applies styling rules, but it simply reports rule violations without producing modified source code as output. So the picture looks like this:

Formatter(生成符合样式规则的修改后的源代码)

Formatter (produces modified source code that conforms to styling rules)

阅读源代码 →应用样式规则 →编写样式化的源代码

Read Source Code → Apply Styling Rules → Write Styled Source Code

样式检查器(不产生修改的源代码)

Style Checker (does not produce modified source code)

阅读源代码 →应用样式规则 →写入规则违规

Read Source Code → Apply Styling Rules → Write Rule Violations

进一步说明

解决方案必须是高度可配置的.我希望能够指定我自己的风格,而不是简单地从预设列表中选择.

Solutions must be highly configurable. I want to be able to specify my own style, not simply select from a preset list.

另外,我不寻找用Java编写的通用漂亮打印机可以漂亮地打印很多东西.我想设计 Java 代码的样式.

Also, I'm not looking for a general purpose pretty-printer written in Java that can pretty-print many things. I want to style Java code.

我也不一定大统一格式化程序感兴趣强> 适用于多种语言.我想解决方案支持 Java 以外的语言可能会很好,但这不是必需的.

I'm also not necessarily interested in a grand-unified formatter for many languages. I suppose it might be nice for a solution to have support for languages other than Java, but that is not a requirement.

此外,仅执行代码突出显示的工具正确 退出.

Furthermore, tools that only perform code highlighting are right out.

我也对网络服务不感兴趣.我想要一个可以在本地运行的工具.

I'm also not interested in a web service. I want a tool that I can run locally.

最后,解决方案不必局限于开源、公共领域、共享软件、免费软件、商业或其他任何东西.所有形式的许可都是可以接受的.

Finally, solutions need not be restricted to open source, public domain, shareware, free software, commercial, or anything else. All forms of licensing are acceptable.

推荐答案

JIndent (Commercial) 为所欲为:

JIndent (Commercial) does what you want:

http://www.jindent.com/

我过去也使用过 Jalopy 来做这件事,它是开源的:

I've also used Jalopy in the past to do this, it's open source:

http://jalopy.sourceforge.net/

我会注意到 Jalopy 相当古老,而且最近似乎没有任何更新.我不太确定它是否适用于 Java 5/6.你可能想看看雅各布:

I will note that Jalopy is fairly old and there doesn't seem to be any recent updates to it. I'm not quite sure if it will work with Java 5/6. You might want to look at Jacobe instead:

http://www.tiobe.com/index.php/content/products/jacobe/Jacobe.html

在 Roedy Green 的网站上还有更完整的格式化程序列表:

There's also a more complete list of formatters here on Roedy Green's site:

http://mindprod.com/jgloss/beautifier.html

这篇关于独立的 Java 代码格式化程序/美化程序/漂亮的打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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