简体   繁体   English

如何在 IntelliJ 中禁用 Java 关闭注释注入?

[英]How can I disable Java close comment injection in IntelliJ?

In IntelliJ, when I comment code in Java using the multiline comment, IntelliJ automatically closes the comment at an arbitrary line below the start of the comment.在 IntelliJ 中,当我使用多行注释在 Java 中注释代码时,IntelliJ 会自动在注释开头下方的任意行关闭注释。 How can I disable this behaviour?如何禁用此行为?

I have unchecked every box in Editor > General > Smart Keys but that didn't stop this behaviour.我已取消选中Editor > General > Smart Keys 中的每个框,但这并没有阻止这种行为。

I did a search for "comment" in settings and deactivated everything shown, with no luck.我在设置中搜索了“评论”并停用了显示的所有内容,但没有运气。

Example: Taking this simple code snippet as an example示例:以这个简单的代码片段为例

public class Foo {
    public void doSomething(List<Object> list) {
        for(int i=0; i<list.size(); i++) {
            Object obj = list.get(i);
            System.out.println(obj.getClass());
        }
    }
}

I add an opening of a multiline comment before the for loop to temporarily replace it with a "for each" style loop.我在 for 循环之前添加了一个多行注释的开头,以暂时用“for each”样式循环替换它。 I don't want to delete the original code before I have tested the new loop:我不想在测试新循环之前删除原始代码:

public class Foo {
    public void doSomething(List<Object> list) {
/*
        for(int i=0; i<list.size(); i++) {
            Object obj = list.get(i);
            System.out.println(obj.getClass());
        }
    }
}

I position the cursor at the end of the obj declaration line and press "Enter" to create a new line for my closing comment.我将光标定位在obj声明行的末尾,然后按“Enter”为我的结束注释创建一个新行。 IntelliJ injects a new line with indentation and a second new line with a close multi-comment tag. IntelliJ 注入带有缩进的新行和带有关闭多注释标记的第二行。

public class Foo {
    public void doSomething(List<Object> list) {
/*
        for(int i=0; i<list.size(); i++) {
            Object obj = list.get(i);

 */
            System.out.println(obj.getClass());
        }
    }
}

In this example, the injected close comment is obviously breaking the code.在这个例子中,注入的关闭注释显然破坏了代码。 Sometime, that's what I want, but nearly 100% of the time, the close comment injection just breaks everything by, for example, injecting it out of sight.有时,这就是我想要的,但几乎 100% 的时间,关闭评论注入只会破坏一切,例如,将其注入视线之外。 It's then a pain to find out what is broken in the code and why that bit of code had magically appear where it was not wanted.然后,很难找出代码中有什么问题以及为什么那段代码会神奇地出现在不需要的地方。

Expected result: IntelliJ doesn't inject anything unless I purposely ask it to do so (with right-click, choose from the menu or keyboard shortcut).预期结果: IntelliJ 不会注入任何内容,除非我故意要求它这样做(右键单击,从菜单或键盘快捷键中进行选择)。

Actual result: IntelliJ injects */ at an arbitrary line in the code, which generates compilation errors, headaches and hair lost.实际结果: IntelliJ 在代码中的任意行注入*/ ,这会产生编译错误、头痛和脱发。

不可能,有相关功能请求: https : //youtrack.jetbrains.com/issue/IDEA-141574

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM