格式化时如何阻止 Eclipse 删除空格

How do I stop eclipse from removing whitespace when formatting

我正在使用 eclipse 进行一些 LWJGL 编程,当我创建用于保存顶点的数组时,我倾向于使用大量空白来显示哪组浮点数保存一个顶点。

//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

};

我还应该注意,我正在使用元素数组缓冲区,所以这就是为什么只有 7 个顶点的原因。

当我使用菜单栏“源代码”选项卡中的“格式”选项时,它会去除所有这些空白。我如何阻止它这样做?我在首选项编辑器中找不到选项。

我正在使用 Windows 8.1 和 Eclipse Java Neon。不,我不会使用不同版本的 Eclipse,因为最初定制 Eclipse 花了我大约 5 个小时,所以...如果有更新的版本允许完成此操作,我将不会更改版本。安装和东西也需要一段时间......是的。

为要忽略格式化程序的代码部分禁用 Eclipse 格式化程序,然后以这种方式重新启用它:

//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

如果尚未启用此功能,则必须启用它。
首选项->Java->代码样式->格式化程序->编辑->Off/On 标签

前往Preferences->Java->Code Style->Formatter->Edit,修改相关选项。