Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel and Intellij Idea code format

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

?

like image 464
well Avatar asked Oct 04 '17 18:10

well


2 Answers

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.

like image 124
Claus Ibsen Avatar answered Sep 20 '22 09:09

Claus Ibsen


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?

like image 37
Tadayoshi Sato Avatar answered Sep 21 '22 09:09

Tadayoshi Sato