17

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

?

well
  • 571
  • 7
  • 13
  • See https://www.jetbrains.com/help/idea/configuring-code-style.html. – Namphibian Oct 04 '17 at 21:49
  • 1
    close voter - why is this off-topic? it's a clear question about a DSL and a programming tool. If you don't understand the question, please ask why. – vikingsteve Oct 05 '17 at 10:57
  • @well - I never found a way to do this, so just don't format the code. It's nice to have the indenting in the DSL code... just never use the auto format feature. – vikingsteve Oct 05 '17 at 10:58

2 Answers2

8

Starting from Camel IDEA plugin v 0.9.9, it is now possible to reformat your routes written with the Java DSL thanks to the shortcut Ctrl + Alt + L / Cmd + Option + L on a complete file or on a specific text range as shown in the screenshot below:

Reformat a route in Java


Original Answer

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.

Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122
Claus Ibsen
  • 56,060
  • 7
  • 50
  • 65
7

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?

Tadayoshi Sato
  • 1,401
  • 11
  • 18
  • Yes, I have found this solution before, but I thought there should be a better way to do it. Thanks for answer. – well Oct 05 '17 at 17:43