18

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

?

3
  • See jetbrains.com/help/idea/configuring-code-style.html.
    – Namphibian
    Commented Oct 4, 2017 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. Commented Oct 5, 2017 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. Commented Oct 5, 2017 at 10:58

2 Answers 2

9

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.

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?

1
  • Yes, I have found this solution before, but I thought there should be a better way to do it. Thanks for answer.
    – well
    Commented Oct 5, 2017 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.