3

I asked this same question about Android Studio, now I'm looking for an answer in Eclipse. I'd like the IDE to be able to "transform" this

public class While {
    public static void main(String[] args) {
    }
}

into this

public class While 
{
    public static void main(String[] args) 
    {
    }
}

In other words, I'd like that the first braces of any method, class etc starts at a new line. I know that in Android Studio it's possible (see this link), and I suppose that would be the same also for Eclipse.

Community
  • 1
  • 1
Fabio Cenni
  • 841
  • 3
  • 16
  • 30
  • check this http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fcodestyle%2Fref-preferences-formatter.htm – Salah Oct 19 '15 at 10:13
  • 1
    Possible duplicate of [Eclipse and curly braces](http://stackoverflow.com/questions/1236531/eclipse-and-curly-braces) – Stanislav Oct 19 '15 at 10:16

2 Answers2

6

You can configure the formatter that Eclipse uses.

In the "Windows > Preferences" dialog-box, go into "Java > Code Style > Formatter" and click "Edit". In the "Braces" tab, you will be able configure how braces are formatted for every type and methods.

For your use-case, you need to select "Next line" for classes and method declarations. Here's a picture:

enter image description here

If you are currently using the Eclipse built-in formatter, you will have to name this new formatter and then save it.

Skully
  • 2,882
  • 3
  • 20
  • 31
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • 1
    Moreover: If you turn on "Windows > Preferences > Java > Editor > Save Actions > Format source code", you'll find that Eclipse will format the code automatically every time you save a source file. – Little Santi Oct 19 '15 at 12:27
0

Window | Preferences | Java | Code Style | Formatter | New Profile | Braces | Position

Change "Same line" to "Next line"

At the New Profile stage -> You have to create a new profile, import existing profile.

a3.14_Infinity
  • 5,653
  • 7
  • 42
  • 66