eclipse - 使 Eclipse 的 Java 代码格式化程序忽略 block 注释

标签 eclipse comments formatter

有没有办法让 Eclipse 的内置 Java 代码格式化程序忽略注释?每当我运行它时,它就会变成这样:

    /*
     * PSEUDOCODE
     * Read in user's string/paragraph
     * 
     * Three cases are possible
     * Case 1: foobar
     *         do case 1 things
     * Case 2: fred hacker
     *         do case 2 things
     * Case 3: cowboyneal
     *         do case 3 things
     *         
     * In all cases, do some other thing
     */

进入此:

    /*
     * PSEUDOCODE Read in user's string/paragraph
     * 
     * Three cases are possible Case 1: foobar do case 1 things Case 2: fred
     * hacker do case 2 things Case 3: cowboyneal do case 3 things
     * 
     * In all cases, do some other thing
     */

我已经尝试过 Windows > 首选项 > Java > 代码样式 > 格式化程序设置,但找不到用于保留注释格式的设置。我使用的是 Eclipse 3.4.0。

最佳答案

还有另一种解决方案可用于抑制特定 block 注释的格式。在 block 注释的开头使用 /*- (注意连字符),并格式化 如果您格式化文件的其余部分,则不会受到影响。

/*-
 * Here is a block comment with some very special
 * formatting that I want indent(1) to ignore.
 *
 *    one
 *        two
 *            three
 */

来源:http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141999.html#350

关于eclipse - 使 Eclipse 的 Java 代码格式化程序忽略 block 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1024886/

相关文章:

java - java.util.Formattable 上的示例是否不正确?

java - 如何在 Spring MVC Web 应用程序中注册格式化程序?

java - Eclipse 上的 Alfresco Mobile Android 错误

java - 如何找到 "Plug-in Project"向导的源代码?

comments - Soundcloud 轨道评论按时间戳排序

java - mvn clean install 抛出错误 - 文件之前未被格式化。请在运行验证之前格式化文件并提交

java - 在Android上使用mockito加速编译

java - 在 IDEA 中解决工作区项目的依赖关系

Python:我在函数下的注释的最后 3 个引号 'indented block' ") 中收到 (""错误。怎么了?

php - Mysql中如何配置用户评论?