Search code examples
javaeclipseeclipse-plugineclipse-mars

Automatic code formatting for Eclipse IDE


I use many brackets and braces when I code. Be it casting multiple times, casting multiple times in if blocks, etc. I sometimes get lost in the brackets and also, hate putting a lot of them. Is there any short-cut key to format this selected part of code? I have tried Ctrl-Shift-F, but that doesn't give me what I want. Note: I work on Eclipse Mars.


Solution

  • What you want is Source menu | Cleanup, then customize the profile to add the remove extra parenthesis. From the Code Style tab check the Use parenthesis in expressions Only if necessary. And then complete the wizard:

    parens

    That changes:

    super.start(((BundleContext)(context)));
    

    to:

    super.start(context);
    

    As an extra you can set your project to do code cleanup tasks on save automatically if you desire.