Search code examples
javaeclipseeclipse-photon

Eclipse: Adding Spaces to Parentheses


I am looking for a setting in Eclipse (using Photon) which will alter the auto-completion style of parentheses.

Eclipse's default looks like this:

function_call(arg1, arg2, arg3);

I prefer to write code like so, as I find it more readable:

function_call( arg1, arg2, arg3 );

Is there a setting under Window > Preferences which can edit auto-completion in this way? Editing them manually is a hassle, and I like my code to look consistent, stylistically.


Solution

  • Yes you can do it simply. Follow the following steps:

    1. From menu bar go to Window -> Preference
    2. A dialog will open as follow: enter image description here

    2.1. From the left tree styled menu, go to Java -> Code Style -> Formatter

    2.2. Now On the right you see the "Active Profile" combo box, click the Edit button

    1. Another dialog appears as follow: enter image description here

    3.1. In this dialog you may check the following check boxes:

    • After opening parenthesis
    • Before closing parenthesis

    (as shown in the above)

    1. Now you want to save these changes but the OK button seems disabled. You should change the Profile name on the top of this dialog to some name of your own. Then you can hit the OK button and all set.

    2. Then hit the Apply and Close button on the Preferences dialog.

    Now every time you format you codes (using menu or Ctrl+Shift+F) your code would be formatted you desired.

    As you might see in that preferences dialog there are so many other formatting options you can change and use as you want.

    Hope this would be helpful.