简体   繁体   中英

Eclipse formatter inserts whitespace before method on linebreak

Using Eclipse Juno I've got the following issue using the Java code formatter:

If a method call leads to a line break, Eclipse inserts a whitespace before the "dot" of the method invocation (_ shall denote the whitespace)

int nbo = new Foo()//linebreak
    _.method();

Unfortunately this whitespace triggers a Checkstyle warning (NoWhitespaceBefore rule). Is there some possibility to stop eclipse inserting the whitespace? Or is it a Checkstyle configuration issue?

Thanks for your help in advance.

You can increase Maximum line width to 120 or bigger number.

  1. On menu Windows -> Preferences
  2. Navigate to Java -> Code Style -> Formatter
  3. Click on Edit button to open a new dialog
  4. On Line Wrapping tab, change Maximum line width
  5. Finally, change Profile name and click OK

You can resolve this either by changing the formatter settings or by changing the Checkstyle configuration.

Option 1 - Formatter Settings (for Eclipse 4.3, but should be the same for Juno)

  • Window → Preferences → Java → Code Style → Formatter → Edit
  • Line Wrapping → Function Calls → Qualified Invocations
  • Set to Do Not wrap

Option 2 - Checkstyle Config

  • Remove the DOT token from the NoWhitespaceBefore rule:
<module name="NoWhitespaceBefore">
    <property name="tokens" value="SEMI,POST_DEC,POST_INC"/>
</module>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM