Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse and curly braces

Tags:

java

eclipse

Is there a quick way to make Eclipse put curly brace on the next line (by itself) on a block of code?

like image 683
Venus Avatar asked Aug 06 '09 01:08

Venus


People also ask

How do I fix brackets in Eclipse?

In your case: Window->Preferences->Keys -> ctrl+alt+b Unbind Command should do the trick. It also the same in Spring Tool Suite 4(It is an Eclipse-based development environment.)

How do you make a curly bracket in Java?

Always include curly brackets, even for one-line if statements or for loops. Java has a "feature" which allows you to omit curly brackets when writing if statements, for loops, or while loops containing only a single statement. You should never use this feature – always include curly brackets.

Are curly braces necessary in JavaScript?

No. But they are recommended. If you ever expand the statement you will need them. if (cond) alert("Condition met!") else alert("Condition not met!")

What do curly braces mean in JavaScript?

Curly braces { } are special syntax in JSX. It is used to evaluate a JavaScript expression during compilation. A JavaScript expression can be a variable, function, an object, or any code that resolves into a value.


4 Answers

Yes, edit your active profile (Java...Code Style...Formatter), and change the brace positions to the next line. Also, in Java..Editor..Typing, you can have it automatically insert your braces at the correct position.

like image 99
Don Branson Avatar answered Oct 19 '22 12:10

Don Branson


For pre-written block of code, first do the settings as suggested by Don and then select that piece of code and right click Source Code->Format and the formatting would take place as per the settings done in the preferences.

like image 24
techzen Avatar answered Oct 19 '22 11:10

techzen


Current versions of eclipse have a more convenient way of doing this.

Go to Preferences->Java->Code Style->Formatter

Click on edit, and on the new opened window, go to the Braces tab. Here you can choose how different types of blocks of code organize their curly braces.

Hope this helps any who google this, and find this post. (Like myself)

Regards to all!

like image 30
chamakits Avatar answered Oct 19 '22 13:10

chamakits


The simplest and global way: Go to Window -> Preferences. Then in search put: "brace". enter image description here

Select -> Java -> Code Style-> Formatter After opening new window go to brace tab and change it as you prefer.

like image 3
truthseeker Avatar answered Oct 19 '22 13:10

truthseeker