Turn off Eclipse formatter for selected code area? [duplicate]

淺唱寂寞╮ 提交于 2019-11-27 15:42:49

问题


This question already has an answer here:

  • How to turn off the Eclipse code formatter for certain sections of Java code? 12 answers

When I ctrl+shift+f up the project code, its doing its job just fine, everywhere.

But its messing the CSS, specially those filter parts and adding bunch of spaces.

Also how do I specify some portion of Java code to not be formated by that command ?


回答1:


To prevent specific portions of Java code from being formatted, go to "Window > Preferences > Java > Code Style > Formatter". Click the "Edit..." button, go to the "Off/On Tags" tab and enable the tags. Afterwards, you can simply embed those tags in Java code to disable the formatting in-between them. If you don't change the default tags, something like this will do :

//@formatter:off
this.
    portion.of(code
); // will not be touched by the formatter
//@formatter:on
but this will be
       reformatted.

IIRC, this option only exists since Eclipse 3.6.

As for css code, if you have installed Eclipse WTP, go to "Window > Preferences > Web > CSS Files > Editor" and you will find some basic formatting options there.




回答2:


You cannot configure the formatting at class level, but you can configure at the project level. To do the configuration follow this path in eclipse

window->preferences-> java -> code style -> formatter

now select the configure project specific settings and do your changes.



来源:https://stackoverflow.com/questions/5115088/turn-off-eclipse-formatter-for-selected-code-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!