阻止 Eclipse 破坏我的评论

发布于 2024-08-08 02:59:17 字数 554 浏览 5 评论 0原文

有没有办法阻止 Eclipse 破坏我的源文件中的注释?

我的主要问题是阻止它自动换行。我已经设法将 Eclipse 配置为不自动换行任何代码,但它似乎仍然对注释执行此操作。

我输入的代码如下:

public int myVariable = 100; // this variable is a very interesting variable and it does lots of stuff

最终结果如下:

public int myVariable = 100; // this variable
                             // is a very
                             // interesting
                             // variable and
                             // it does lots
                             // of stuff

Is there a way to stop eclipse from mangling the comments in my source files?

My main issue is stopping it from word wrapping them. I've managed to configure eclipse to not word wrap any code but it still seems to do it to comments.

Code that I enter like this:

public int myVariable = 100; // this variable is a very interesting variable and it does lots of stuff

End up like this:

public int myVariable = 100; // this variable
                             // is a very
                             // interesting
                             // variable and
                             // it does lots
                             // of stuff

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

童话里做英雄 2024-08-15 02:59:17

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

/*-
 * 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#680

There is another solution that you can use to suppress the formatting of specific block comments. Use /*- (note the hyphen) at the beginning of the block comment, and the formatting
won't be affected if you format the rest of the file.

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

Source: http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141999.html#680

辞取 2024-08-15 02:59:17

转到“窗口”菜单->偏好
从左侧列表中选择您感兴趣的编辑器。(例如Java)
那么应该有一个名为“代码样式”的小节,在“格式化程序”下。

然后您需要创建一个新的格式化程序配置文件。 (内置配置文件无法编辑)
配置文件配置的最后一个选项卡是注释格式选项

Go to the "Window" menu -> preferences
choose the editor you're interested in from the list on the left.(e.g. Java)
then there should be a subsection called "Code Style", and under that "Formatter".

Then you'll need to create a new formatter profile. (The built-in profile can't be edited)
On the last tab of the profile configuration is options for comment formatting

微暖i 2024-08-15 02:59:17
  1. 转到首选项 -> Java->代码风格->格式化程序
  2. 在那里编辑配置文件并切换到最后一个名为“注释”的选项
  3. 卡取消选中“启用行注释格式”
  1. Go to Preferences -> Java -> Code Style -> Formatter
  2. There edit the profile and switch to the last tab called "Comments"
  3. Uncheck the "Enable line comment formatting"
白龙吟 2024-08-15 02:59:17

窗口->首选项->Java->代码样式->格式化程序。创建新的格式化程序。单击“编辑”,然后选择“注释”选项卡,取消选中“启用行注释格式”和“启用块注释格式”

Window->Preferences->Java->Code Style->Formatter. Create new formatter. Click on edit and then pick tab Comments unchecked Enable Line comment formatting and Enable block comment formatting

×眷恋的温暖 2024-08-15 02:59:17

您可以使用

 包裹,该块不会格式化。

/*
 * <pre class="prettyprint">
 * public class Activity extends ApplicationContext {
 *     protected void onCreate(Bundle savedInstanceState);
 *
 *     protected void onStart();
 *
 *     protected void onRestart();
 *
 *     protected void onResume();
 *
 *     protected void onPause();
 *
 *     protected void onStop();
 *
 *     protected void onDestroy();
 * }
 * </pre>
 */

You can use <pre></pre> wrapped, this block will not format.

/*
 * <pre class="prettyprint">
 * public class Activity extends ApplicationContext {
 *     protected void onCreate(Bundle savedInstanceState);
 *
 *     protected void onStart();
 *
 *     protected void onRestart();
 *
 *     protected void onResume();
 *
 *     protected void onPause();
 *
 *     protected void onStop();
 *
 *     protected void onDestroy();
 * }
 * </pre>
 */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文