camel-idea-plugin
camel-idea-plugin copied to clipboard
Code-reformat to indent routes in RouteBuilders
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".
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.
This was also asked on SO https://stackoverflow.com/questions/46572048/apache-camel-and-intellij-idea-code-format/46582611#46582611
Yes, code format for camel routes would be a really good thing
I'm working on this issue.
@bennetelli could you assign your self to the issue
@fharms I think I don't have the rights to assign myself to the issue
I added you as contributer to the project, so you should have received an invitation
thx
Welcome on-board @bennetelli
@davsclaus :)
You can manually turn code formatting off as shown here https://twitter.com/JavaGuyUA/status/969963553817092096
nice to see the link to my tweet here, thanks =)
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 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 can we see what you tried anywhere? I also think this would be a great feature.
@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
@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