Code Style formatting for Java ~ local variables and if-checks
I am trying to teach the Java Code Style Formatter to format my code like this:
RequirementSupplierStatusInformation information
= reqIfMongoDbSupplierStatusAdapter.getSupplierStatus(
requirementId,
organizationID
);
if (
!workspaceAdministrationService.hasWorkspaceReadRight(
token,
requirementProjectId.getWorkspaceId()
)
) {
throw new NotEnoughRightsException();
}
The rules I want it to follow are quite simple:
* If a line is too long, wrap it in front of the next operator or after the next brace and indent it once
* Keep operators, arguments & co on the same indentation level
* After the end of the operation or after the brace closes, un-indent it once
* Have the closing brace on a new line
However, thus far, having experimented with IntelliJ IDEA's settings for quite a bit, this is the best I could achieve:
RequirementSupplierStatusInformation
information
= reqIfMongoDbSupplierStatusAdapter.getSupplierStatus(
requirementId,
organizationID
);
if (!workspaceAdministrationService.hasWorkspaceReadRight(
token,
requirementProjectId.getWorkspaceId()
)) {
throw new NotEnoughRightsException();
}
As you can see, this has multiple issues:
* The variable name `information` wraps around for no apparent reason, and I can't find a setting that would seem to affect this
* The assignment operator after the `information` is not indented
* The parameters and closing brace ofthe `getSupplierStatus` method call are not indented
* In the if-condition, the statement should wrap because the statement is too long to fit into one line, and then wrap again to give it that clear, nested nature, and avoid the double-closing braces on one line
Is there a way to achieve this? And if yes, how can I do it?
Thanks in advance,
Kira
=^,^=
Please sign in to leave a comment.
I've by now managed to get it at least a little bit better. However, it still looks like this:
...where it should look like this:
In Eclipse, I can get this behaviour by setting the following code style settings:
However, in IntelliJ, I can't find any options that seem to have the same effect. Is this really impossible in IntelliJ?
For reference, here is the exported template from Eclipse, which creates the desired behaviour. I tried importing it into IntelliJ, but I had to make some adjustments to get it to work even as "fairly" as described above.
I now solved this "brute force" by installing the Eclipse Code Formatter plugin for IntelliJ (https://plugins.jetbrains.com/plugin/6546-eclipse-code-formatter). It's a shame that IntelliJ does not provide adequate code style natively, but I suppose if it has plugins like that it doesn't matter. =^,~'=