Apache Camel and Intellij Idea code format

Viewed 2982

Intellij Idea formats code in camel routs like this:

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();

Is there any plugins or other ways to do like this:

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();

?

2 Answers

I don't think there is yet a nice plugin that can format Java DSL code as desired.

At best we can only disable formatting the specific DSL parts in Java code. I would recommend to use the formatter on/off feature in IntelliJ IDEA for Camel DSL routes:

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

You can find the Formatter Control settings in Preferences... -> Editor -> Code Style (as of 2017.2.3).

Refer to other StackOverflow questions such as this for more details on the IntelliJ feature:
How to disable code formatting for some part of the code using comments?

There is a ticket about this for the Camel IDEA plugin: https://github.com/camel-idea-plugin/camel-idea-plugin/issues/309

You can use the +1 to indicate its something desired.

I personally would also like to have such feature but haven't had much spare time to work on this as I am busy with regular work, and also finishing my Camel book.

Related