google-java-格式化 eclipse 插件忽略 formatter:off 评论

google-java-format eclipse plugin ignoring formatter:off comments

我在这里使用 google-java-格式插件: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:

添加忽略格式注释,按照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-格式?

看起来他们没有实现。 https://github.com/google/google-java-format/wiki/FAQ#why-cant-i-use-magic-comments-to-disable-formatting-for-certain-sections-of-code