keen
keen

Reputation: 3011

customize organize import in eclipse

I am using organize import in eclipse and this is one of the best features of eclipse.

But can i customize organize import the way i want to.

Ex.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

But I want it to be something like this.

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

}

It organizes opening brace in same line as function. But I want it to be at the next line.

Can I customize to have this opening bracket in next line ? So whenever I do organize import it automatically changes to opening bracket in the next line.

Thanks in advance.

Upvotes: 0

Views: 140

Answers (2)

Arnaud Potier
Arnaud Potier

Reputation: 1780

I guess you mean "format code" instead of organize import.

You can achieve what you want easily:

click on

window > preferences 

and then

Java > Code Style > Formatter

Eclipse has base formatters that you cannot modify. However you can copy them and modify them to create your own based on the default eclipse included ones.

You need to create yours and then edit it.

under the tab "braces" you'll find what you want

Upvotes: 1

greg-449
greg-449

Reputation: 111142

You do this with the Source > Format command (Ctrl+Shift+F, on a Mac this is Cmd+Shift+F).

How the code is formatted is set in Preferences > Java > Code Style > Formatter. Edit an existing profile or create a new one and look at the Braces section.

You can set formatting to be done automatically when you save a file in Preferences > Java > Editor > Save Actions.

Upvotes: 1

Related Questions