James Yeoman
James Yeoman

Reputation: 675

How do I stop eclipse from removing whitespace when formatting

I am using eclipse to do some LWJGL programming and when I create arrays for holding the vertices, I tend to use a lot of whitespace to show what group of floats hold a vertex.

//Array for holding the vertices of a hexagon
float [ ] Vertices = {
    // Vertex 0
    -0.5f ,  1.0f , 0.0f ,
    // Vertex 1
    -1.0f ,  0.0f , 0.0f ,
    // Vertex 2
    -0.5f , -1.0f , 0.0f ,
    // Vertex 3
    0.5f , -1.0f , 0.0f ,
    // Vertex 4
    1.0f ,  0.0f , 0.0f ,
    // Vertex 5
    0.5f ,  1.0f , 0.0f ,
    // Center Vertex ( 6 )
    0.0f ,  0.0f , 0.0f

};

I should also note that I am using element array buffers so that is why there are only 7 vertices.

When I use the Format option in the Source tab of the menu bar, it strips all of this whitespace. How do I stop it from doing that? I cannot find an option in the preferences editor.

I am using Windows 8.1 and Eclipse Java Neon. And no, I won't use a different version of Eclipse as it took me about 5 hours customizing eclipse initially so... If there is a newer version that allows this to be done, I will not be changing the version. It would also take a while to install and stuff so... yeah.

Upvotes: 4

Views: 373

Answers (2)

SamTebbs33
SamTebbs33

Reputation: 5647

Go to Preferences->Java->Code Style->Formatter->Edit and change the relevant options.

Upvotes: 1

davidxxx
davidxxx

Reputation: 131536

Disable the Eclipse formatter for the part of code where you want to ignore the formatter and re-enable it in this way :

//Array for holding the vertices of a hexagon
// @formatter:off
float [ ] Vertices = {
    // Vertex 0
    -0.5f ,  1.0f , 0.0f ,
    // Vertex 1
    -1.0f ,  0.0f , 0.0f ,
    // Vertex 2
    -0.5f , -1.0f , 0.0f ,
    // Vertex 3
    0.5f , -1.0f , 0.0f ,
    // Vertex 4
    1.0f ,  0.0f , 0.0f ,
    // Vertex 5
    0.5f ,  1.0f , 0.0f ,
    // Center Vertex ( 6 )
    0.0f ,  0.0f , 0.0f      
}; 
// @formatter:on

You must enable this feature if it is not already done.
Preferences->Java->Code Style->Formatter->Edit->Off/On Tags

Upvotes: 5

Related Questions