Search code examples
javaeclipseparenthesesautoformat

Eclipse Autoformat Parenthesis


I have a problem whenever I use the Scanner class in my java code: Say I type

Scanner in = new Scanner(System.in)

As soon as I press the semicolon, it becomes/autoformats to this:

Scanner in = new Scanner(System.in;

This is the only case where this issue occurs, I have never seen it happen anywhere else when coding. I also haven't found anything in the autoformat preferences that sounds like a solution to this.

I would like to know how to fix this.


Solution

  • I can reproduce this behaviour both in Eclipse Mars and Eclipse Neon, and for me it looks like a bug.

    In particular, when I press ) to over-type the auto-inserted ), the content assist window suggesting System.in stays open, and ; then selects it and eats the ).

    Therefore I opened a bug report for it:

    https://bugs.eclipse.org/bugs/show_bug.cgi?id=506729

    To work around it (until it is fixed), you can disable one of the involved features: auto-inserting closing parenthesis, content assist (i. e. auto completion) or that content assist triggers on typing a semicolon. (All of these are available in the global preferences unter Java -> Editor). Alternatively you can live with the bug and close content assist either by accepting System.in with Enter, or by pressing Esc any time after the suggestion window opens but before typing the semicolon.