Karidrgn
Karidrgn

Reputation: 157

java eclipse auto-formatting braces indentation

My problem with eclipse's auto format is that it's taking this:

public List<JSON> getIdentityQualifiers(String identity)
        throws DatabaseException
{
     //....code
}

to this:

public List<JSON> getIdentityQualifiers(String identity)
        throws DatabaseException
        {
    //....code
        }

Obviously, I want to keep the previous formatting, but I can't find where to control this.

Upvotes: 4

Views: 1634

Answers (3)

Karidrgn
Karidrgn

Reputation: 157

I think basically it may have been my version of Eclipse or something obscure as this stopped happening a long time ago.

Upvotes: 0

Manikant Gautam
Manikant Gautam

Reputation: 3591

You could also try like that , first select segment of code which one you want to indent for e.g

              if(true)
            {
                           System.out.println("INDENTED");
            }

select and type Ctrl + Shift + F. After that you get.

               if (true) {
                System.out.println("INDENTED");
            }

For customization you can find from there *Project --> Properties --> Java Code Style --> *

Upvotes: 1

Kon
Kon

Reputation: 10810

Go to Project -> Properties -> Java Code Style -> Formatter and you will see the formatting options. There are a lot of different styles.

My company provides us with a custom XML which defines exactly how they want things formatted, which was created internally. Eclipse allows you to define your formatting exactly in this format. There will certainly be tutorials online if this is important to you. You may be able to write your own or find many examples in Eclipse marketplace and online.

Upvotes: 2

Related Questions