Eclipse code formatter missing rules

894 views Asked by At

I am unable to find these line wrapping rules for the Eclipse code formatter:

  • Not starting new lines with "throws" (since easily mistaken for "throw")
  • Not starting new lines with dots (e.g. when method chaining)

Have I missed those or don't they exist? Here are a few examples what the standard formatter produces and what i would like to have as a result:

Method definition: Line wrapping for closing parentheses in front of throws

Standard:

String someMethodWithARatherLongName(String someParameter) 
    throws Exception;

Desired:

String someMethodWithARatherLongName(String someParameter 
    ) throws Exception;

Method chaining: Line wrapping

Standard:

return new StringBuilder("Hello ").append(name)
    .append(", how are you today?").toString();

Desired:

return new StringBuilder("Hello ").append(name).append(
    ", how are you today?").toString();

or:

return new StringBuilder("Hello ").append(name
    ).append(", how are you today?").toString();

Any specific help regarding these settings would be much appreciated!

2

There are 2 answers

0
msrd0 On

Not starting new lines with "throws" (since easily mistaken for "throw")

You can achieve this with Line Wrapping -> Method Declaration -> 'throws' clause. Change Line Wrapping Policy to Do not wrap and the throws clause will be on the same line as the Method Declaration. You can do this for the Constructor Declaration too.

Not starting new lines with dots (e.g. when method chaining)

It seems like this isn't possible in Eclipse, but I'd appreciate such a setting too.

0
Aman On

I think above question was to insert new line after method declaration where we throw exceptions. I'm giving you example below.

public String methodWithLongName()
throws Technical Exception,Business Exception
{
    ...
}

I didn't find any solution so far in eclipse what you suggested was something else.