Apache Camel 和 Intellij Idea 代码格式

2022-09-04 21:19:29

Intellij Idea将骆驼溃败中的代码格式化为如下所示:

from("direct:loop")
     .log("Loop: ${header[loopCount]}")
     .choice()
     .when(simple("header[loopCount] < 10"))
     .process(exchange -> {
         Message in = exchange.getIn();
         in.setHeader("loopCount", in.getHeader("loopCount", Integer.class) + 1);
     })
     .to("direct:loop")
     .otherwise()
     .log("Exiting loop")
     .end();

是否有任何插件或其他方法可以做到这一点:

from("direct:loop")
 .log("Loop: ${header[loopCount]}")
 .choice()
     .when(simple("header[loopCount] < 10"))
         .process(exchange -> {
             Message in = exchange.getIn();
             in.setHeader("loopCount", in.getHeader("loopCount", Integer.class) + 1);
         })
         .to("direct:loop")
     .otherwise()
         .log("Exiting loop")
 .end();

?


答案 1

我不认为有一个很好的插件可以根据需要格式化Java DSL代码。

充其量,我们只能禁用 Java 代码中特定 DSL 部分的格式设置。我建议在IntelliJ IDEA中对Camel DSL路由使用格式化程序开/关功能:

// @formatter:off
...
// @formatter:on

您可以在 -> -> 中找到设置(截至 2017.2.3)。Formatter ControlPreferences...EditorCode Style

有关 IntelliJ 功能的更多详细信息,请参阅其他 StackOverflow 问题,例如:
如何使用注释禁用代码的某些部分的代码格式化?


答案 2

Camel IDEA插件有一个关于此的票证:https://github.com/camel-idea-plugin/camel-idea-plugin/issues/309

您可以使用 +1 来指示所需的内容。

我个人也希望有这样的功能,但没有太多的空闲时间来做这件事,因为我忙于常规工作,也完成了我的骆驼书。


推荐