Java eclipse中`//@formatter:off`标签的格式化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19399190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Formatting of the `//@formatter:off` tag in eclipse
提问by fgysin reinstate Monica
As you may know, Eclips lets you disable the code formatter for certain sections of source code (see for example this question).
您可能知道,Eclips 允许您禁用源代码的某些部分的代码格式化程序(例如参见这个问题)。
Now, my problem is, that the formatter apparently stops formatting code at the very beginning of the line where the //@formatter:off
tag is found. This has the result, that the formatter tag itself (which is just a comment line essentially) is placed in a queer location, namely without indentationat the very beginning of the line.
现在,我的问题是,格式化程序显然会在//@formatter:off
找到标记的行的开头停止格式化代码。结果是,格式化程序标签本身(本质上只是一个注释行)被放置在一个奇怪的位置,即在行的开头没有缩进。
See this example.
请参阅此示例。
What I enter:
我输入的内容:
//@formatter:off
Some code {
with indentation
that I dont want to be formatted.
}
//@formatter:on
After hitting [Ctrl + F] it looks like this:
按 [Ctrl + F] 后,它看起来像这样:
//@formatter:off
Some code {
with indentation...
that I dont want to be formatted.
}
//@formatter:on
Ok, I realize that this is purely a cosmetic issue, but my OCD is driving me nuts when I see this everywhere in the code. Especially after specificallyusing the formatting tag to make the code look nicer.
好吧,我意识到这纯粹是一个表面问题,但是当我在代码中随处看到这个时,我的强迫症让我发疯。特别是在专门使用格式化标签使代码看起来更好之后。
采纳答案by Paul Wagland
What version of Eclipse are you using?
您使用的是什么版本的 Eclipse?
I just tried this in Eclipse 4.3.1, and it seems to work exactly as you want. Even better, if your code does end up like in your second code block, the formatter actually indents that first //@formatter:off
block to the correct indentation.
我刚刚在 Eclipse 4.3.1 中尝试过这个,它似乎完全按照你的意愿工作。更好的是,如果您的代码确实像在第二个代码块中那样结束,格式化程序实际上会将第一个//@formatter:off
块缩进到正确的缩进。
Perhaps you need to upgrade your version of Eclipse?
也许您需要升级您的 Eclipse 版本?