我在这里使用 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:
和按照 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/