Eclipse 切换注释缩进

标签 eclipse

我有以下代码:

public int doBam(int bam) {
    if(foo) {
        bam += 1;
        if(bar) {
            bam += 1;
        }
    }
    return bam;
}

我想注释掉 if(bar) ...

当我在 Eclipse 3.6 中切换注释时,我会得到这个:

public int doBam(int bam) {
    if(foo) {
        bam += 1;
//        if(bar) {
//            bam += 1;
//        }
    }
    return bam;
}

我可以让 Eclipse 像这样切换注释吗?

public int doBam(int bam) {
    if(foo) {
        bam += 1;
        //if(bar) {
        //    bam += 1;
        //}
    }
    return bam;
}

最佳答案

Can I make Eclipse to toggle comment like this instead?

这是一个三步过程..

第 1 步:- 选择所需的代码。

if(bar) {
  bam += 1;
}

第 2 步:- 按 Control + 7Control +/

//    if(bar) {
//      bam += 1;
//    }

第 3 步:- 按 Control + Shift + F

   // if(bar) {
   // bam += 1;
   // }

更新

Also, when uncommenting, the Eclipse autoformatter does not restore the previous indentation

与评论一样,取消评论也是三步过程:-

  1. 选择
  2. 控制 +/
  3. Control + Shift + F

it applies it's own formatting rules instead.

您可以更改这些格式规则。 Windows --> 首选项 --> Java --> 代码样式 --> 格式化程序 --> 编辑 --> 注释选项卡。

Eclipse 不允许编辑默认的内置配置文件。创建新的配置文件并继承内置配置文件的所有属性,然后您可以自定义新创建的配置文件。

关于Eclipse 切换注释缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4225951/

相关文章:

java - Spring 框架 - 超时 java.net.SocketTimeoutException : timeout

java - 防止 Eclipse Java Builder 编译类 Java 源代码

c++ - Eclipse 调试错误 : No such file or directory\n

java - org.apache.tomcat.util.bcel.classfile.ClassFormatException : Invalid byte tag in constant pool: 15

eclipse - java.lang.ClassNotFoundException : com. ebank.rajeev.controller.Login 登录

android - 创建上下文失败 0x3005

java - 源代码管理基础 Eclipse 配置

android - Calendar.getInstance 无法解析为类型

eclipse - 如何在 Eclipse 中从 CVS 恢复以前的更新

java - 在 Eclipse 中重构 "package structure"以将包的子包重定位到其父包