camel-idea-plugin icon indicating copy to clipboard operation
camel-idea-plugin copied to clipboard

Code-reformat to indent routes in RouteBuilders

Open haraldfw opened this issue 7 years ago • 17 comments

Configure IDEA's code reformat feature (standard keybind: Ctrl + Alt + L) to correctly indent things like choices to reflect their functionality, like code-blocks are formatted in standard Java.

An example in a RouteBuilder

This is how IDEA wants to indent this code:

from("direct:getBgUser")
        .process(buildBGAuthRequest)
        .to("direct:bgmock")
        .choice()
        .when(credentialsValid)
        .process(createNumbersResponseFromBGResponse)
        .otherwise()
        .setHeader(Exchange.HTTP_RESPONSE_CODE).constant(401)
        .end()
;

And this is how IDEA should indent it:

from("direct:getBgUser")
        .process(buildBGAuthRequest)
        .to("direct:bgmock")
        .choice()
        .when(credentialsValid)
            .process(createNumbersResponseFromBGResponse)
        .otherwise()
            .setHeader(Exchange.HTTP_RESPONSE_CODE).constant(401)
        .end()
;

How the correct indentation is done in this example is purely my opinion and should be worked on further. But making it configurable would be the best way to avoid anyone calling it out as "wrong".

haraldfw avatar Jun 19 '17 09:06 haraldfw

Yes this bothers me also as well. I am not sure at this point how / if that is possible. Maybe we can hook into IDEAs auto formatter and control it somehow.

davsclaus avatar Jul 08 '17 07:07 davsclaus

This was also asked on SO https://stackoverflow.com/questions/46572048/apache-camel-and-intellij-idea-code-format/46582611#46582611

davsclaus avatar Oct 05 '17 11:10 davsclaus

Yes, code format for camel routes would be a really good thing

wellusion avatar Oct 05 '17 18:10 wellusion

I'm working on this issue.

bennetelli avatar Oct 08 '17 08:10 bennetelli

@bennetelli could you assign your self to the issue

fharms avatar Oct 08 '17 18:10 fharms

@fharms I think I don't have the rights to assign myself to the issue

bennetelli avatar Oct 09 '17 05:10 bennetelli

I added you as contributer to the project, so you should have received an invitation

fharms avatar Oct 09 '17 05:10 fharms

thx

bennetelli avatar Oct 09 '17 05:10 bennetelli

Welcome on-board @bennetelli

davsclaus avatar Oct 09 '17 06:10 davsclaus

@davsclaus :)

bennetelli avatar Oct 09 '17 08:10 bennetelli

You can manually turn code formatting off as shown here https://twitter.com/JavaGuyUA/status/969963553817092096

davsclaus avatar Mar 04 '18 14:03 davsclaus

nice to see the link to my tweet here, thanks =)

afrunt avatar Mar 04 '18 15:03 afrunt

Is there any progress on actually making the formatter indent routes? @bennetelli

I would love for there to be a standard on how to indent routes. It would increase readability across projects you haven't written yourself, because they would all be indented in the same way.

haraldfw avatar Mar 09 '18 11:03 haraldfw

@haraldfw I tried it three times, but didn't get it up and running yet. I also would like to have this feature as soon as possible because of your reasons. Unfortunately it's not that straightforward :(

bennetelli avatar Mar 09 '18 11:03 bennetelli

@bennetelli can we see what you tried anywhere? I also think this would be a great feature.

gdubya avatar Apr 19 '18 11:04 gdubya

@gdubya unfortunately I deleted the branch :( I took the IntellIJ handlebars or mustache plugin as reference. Maybe you can take a look there and adapt it a bit

bennetelli avatar Apr 19 '18 11:04 bennetelli

@davsclaus

You can manually turn code formatting off as shown here https://twitter.com/JavaGuyUA/status/969963553817092096

As suggested i used disable formatter but still intellij format for choice

I want to keep like below

    // @formatter:off
    @Override
    public void configure() throws Exception {
        from("timer://ipc?repeatCount=1&delay=60000")
                .routeId("main-route")
                .choice()
                      .when(simple("mycondition"))
                                .setHeader("var", simple("val"))
                .end();
    }
    // @formatter:on

But after reformat intellij shows like below

// @formatter:off
@Override
public void configure() throws Exception {
    from("timer://ipc?repeatCount=1&delay=60000")
            .routeId("main-route")
            .choice()
            .when(simple("mycondition"))
            .setHeader("var", simple("val"))
            .end();
}
// @formatter:on

imranrazakhan avatar Jan 15 '21 13:01 imranrazakhan