Making Eclipse's Java code formatter ignore block comments

后端 未结 11 542
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 13:20

Is there a way to make Eclipse\'s built-in Java code formatter ignore comments? Whenever I run it, it turns this:

    /*
     * PSEUDOCODE
     * Read in us         


        
11条回答
  •  醉话见心
    2020-12-04 14:03

    I just learned from a co-worker that Eclipse offers special formatting tags that can be used for this:

    // @formatter:off
    /*
     * ╔════════╦═══════╦══════════╗
     * ║ Month  ║ Sales ║ Position ║
     * ╠════════╬═══════╬══════════╣
     * ║ June   ║ 44k   ║ 2nd      ║
     * ║ July   ║ 39k   ║ 2nd      ║
     * ║ August ║ 49k   ║ 4th      ║
     * ╚════════╩═══════╩══════════╝
     *
     * This comment shouldn't be formatted, and will now be ignored by the formatter.
     */
    // @formatter:on
    

    Note that you may need to manually enable this feature through the Preferences menu → Java > Code Style > Formatter, clicking on Edit, selecting the Off/On Tags tab and checking Enable Off/On tags (source).

    A quick Google for the string @formatter:off brought me to this other SO answer, which mentioned this feature in the context of disabling the formatter for code blocks. I've confirmed that it works for line comments, "normal" block comments and Javadoc block comments as well.

提交回复
热议问题