java - google-java-format eclipse 插件忽略格式化程序 :off comments

标签 java eclipse formatter

我在这里使用 google-java-format 插件:https://github.com/google/google-java-format 在我的 Eclipse STS 中(版本:4.5.0.RELEASE)

在定义 Camel Java DSL Route 时,我试图忽略格式化程序,这样我就可以获得以下缩进代码:

@Component
public class MyRoute extends SpringRouteBuilder
{

  @Override
  public void configure() throws Exception
  {
   super.configure();
   from("direct:myendpointh").routeId("foo")
    .setBody().method(MyClass.class, "calc(${body})")
    .setHeader("bar").method(BarCalc.class, "compute(${body})")
    .choice()
       .when().ognl("request.body.isConditionMet")
       .to("direct:ConditionalRoute").endChoice()
    .otherwise()
       .routingSlip(header("mySlip"))
    .end();
  }
}

现在,如果我将格式化程序从 eclipse 更改为 google-java-format:

enter image description here

按照 this post 中的说明添加忽略格式注释

仍然格式化为每行1个方法调用,并且丢失了choice()缩进:

@Component
public class MyRoute extends SpringRouteBuilder
{
  //@formatter:off
  @Override
  public void configure() throws Exception
  {
   super.configure();
   from("direct:myendpointh")
    .routeId("foo")
    .setBody()
    .method(MyClass.class, "calc(${body})")
    .setHeader("bar")
    .method(BarCalc.class, "compute(${body})")
    .choice()
    .when()
    .ognl("request.body.isConditionMet")
    .to("direct:ConditionalRoute")
    .endChoice()
    .otherwise()
    .routingSlip(header("mySlip"))
    .end();
  }
  //@formatter:on
}

有没有办法切换特定文件的格式化程序...例如对某些需要方法链式缩进的文件禁用 google-java-format?

最佳答案

关于java - google-java-format eclipse 插件忽略格式化程序 :off comments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60834277/

相关文章:

java - 在Eclipse中,调试时如何附加不同的源文件

java - OpenCV Grabcut 仅输出标记为 GC_FGD 的内容

java - 在循环中清空数组列表

java - 在 Eclipse (3.6 Helios) 中使用 Spring (3.0.5)

python - 问候程序

java - 更改 eclipse 格式化程序如何包装长字符串

java - Eclipse - 每次保存时,换行的缩进都会出现和消失

java - 当我运行 .jar 时,除命令提示符外,Swing 不会重新绘制

java - lambda 从映射中检索整数

使用文件和格式化程序时,java txt 文件被覆盖