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

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

问题描述

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



格式化程序必须是独立的,也就是说,它必须支持批处理模式,即 与任何特定的开发环境 。理想情况下,它应独立于任何特定的操作系统。因此,IDE的内置格式化程序在这里没有什么兴趣(除非IDE支持批处理模式格式化程序调用,也许从命令行)。用闭源C / C ++编写的格式化程序只能在Windows上运行是不理想的,但是有些有趣。



formatter(或beautifier)与样式检查器不同。格式化程序接受源代码作为输入,应用样式规则,并生成语义上等同于原始源代码的样式源代码。语法修改仅限于修改代码布局,如更改空格或组织 import 语句。很少,如果有的话,执行其他重构。样式检查器还应用样式规则,但它只是报告违规规则,而不生成修改的源代码作为输出。因此,图片如下所示:



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



读取源代码→应用样式规则→编写风格源代码



样式检查(不生成修改后的源代码)



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



进一步澄清



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



此外,我不是查找用Java编写的通用目的漂亮打印机 可以打印许多内容。 stackoverflow.com/questions/251622\"> grand-unified formatter 。我认为一个解决方案可能会支持非Java语言,但这不是必需的。



此外, 只执行代码突出显示的工具权限



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



最后,解决方案不必限于开源,公共领域,共享软件,自由软件,商业或任何其他。 所有形式的许可均可接受

解决方案

JIndent / p>

http://www.jindent.com/



我也用过Jalopy来做这个,它是开源的:



http://jalopy.sourceforge.net/



编辑:我会注意到,Jalopy是相当老,似乎没有任何最近的更新。我不太确定如何使用Java 5/6。您可能想要查看Jacobe:



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



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



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


I'm interested in learning about the available choices of high-quality, stand-alone source code formatters for Java.

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.

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 (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

Further Clarifications

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

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.

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) does what you want want:

http://www.jindent.com/

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

http://jalopy.sourceforge.net/

EDIT: 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 how 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

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天全站免登陆