Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Better alignment of fields declarations using Eclipse

Tags:

java

eclipse

Adding too many fields into a class it becomes a mess like this:

private static final int UNAVAILABLE = -1;
private static final int EXTERNAL_BUFFER_SIZE = 4000 * 4;
private static final int SKIP_INACCURACY_SIZE = 1200;
private Thread thread = null;
private Object dataSource;
private AudioInputStream audioInputStream;
private AudioInputStream encodedAudioInputStream;
private int encodedAudioLength = -1;
private AudioFileFormat audioFileFormat;
private SourceDataLine sourceDataLine;

I want Eclipse to reformat the code and make it better to read so I modified default formatter and have achieved this:

private static final int                UNAVAILABLE             = -1;
private static final int                EXTERNAL_BUFFER_SIZE    = 4000 * 4;
private static final int                SKIP_INACCURACY_SIZE    = 1200;
private Thread                          thread                  = null;
private Object                          dataSource;
private AudioInputStream                audioInputStream;
private AudioInputStream                encodedAudioInputStream;
private int                             encodedAudioLength      = -1;
private AudioFileFormat                 audioFileFormat;
private SourceDataLine                  sourceDataLine;

But it's still messy and I can't find how to modify the editor further to achieve this (you can see the difference in static)

(Found this piece of code here and I think it can be even more improved to create and an empty column for final):

enter image description here

Image of the Editor in Eclipse:

enter image description here

How can I do this?

like image 321
GOXR3PLUS Avatar asked Sep 30 '16 05:09

GOXR3PLUS


1 Answers

My suggestion would be to write your own formatting program that takes a file location as input and writes formatted content back to the same file. It can be made as an eclipse plugin that can run on a particular key stroke.
The upside is that you can customize the way you want.
The downside is that it would be re-inventing the wheel if someone already had done it.
like image 55
S R Chaitanya Avatar answered Oct 14 '22 17:10

S R Chaitanya