Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add indentation to blank lines in Java code (Eclipse IDE)

Tags:

java

eclipse

Using Eclipse is it possible (via formatter or other setting) to automatically pre-indent blank lines in Java code with the appropriate number of tabs (or whitespace)?

(Not interested in arguing about others opinion that this is a bad idea or "wastes bytes" (hahaha) or any other such nonsense - just want to know if it's possible, thanks.)

Edit: Actually this may be a problem that can be fixed with templates (I've had no success so far), but when I generate a new class I get methods like this:

    @Override
    public void setData(Object data) {
//No indentation on first line :(
    }

The formatter, even with "Indent empty lines" checked, definitely doesn't add tabs there either. Maybe this is a bug?

like image 878
Manius Avatar asked Jan 21 '12 19:01

Manius


People also ask

How do you indent lines in eclipse?

5-In your Eclipse IDE, Go to: Window → Preferences → General → Editors → Text Editors → Indent Guide 6-Then enable indent guide checkbox. 7-Enjoy !

How do I get rid of blank lines in eclipse?

In eclipse preference setting you can remove all the unwanted blank lines. Eclipse: Window > Preferences > Java > Code Style > Formatter > Edit the formatter and following screen will pop up. And when you format the code all unwanted blank lines will be removed.

How do you change the indent in Java?

Indentation settings for Java Code style scheme settings are configured in Settings/Preferences | Editor | Code Style | Java. Use the tab or space character for indentation and code formatting.

How do you remove indentation in Java?

There specify the indentation level under : Displayed Tab Width. Select the formatter and press Edit . Use whatever suits you.


1 Answers

Yep, you can do that. Go to Preferences/Java/Code Style/Formatter and edit your active profile. Then on the Indentation tab tick empty lines.

enter image description here

like image 151
Dr G Avatar answered Sep 25 '22 00:09

Dr G