Eclipse 3.7格式化静态类

时间:2013-03-27 17:21:27

标签: java eclipse formatting

在Eclipse 3.7中是代码:

public class AppResources
{
    private static Image titleIcon;
    static
    {
        AppResources.titleIcon = getIconImage();
    }

    public static Image getTitleIcon()
    {
        return AppResources.titleIcon;
    }
}

在格式化程序中可以说static之前应该是空行吗?

2 个答案:

答案 0 :(得分:0)

静态块没有单独的格式设置。出于格式化目的,它似乎被视为任何其他成员变量(而不是函数或其他一些构造)。

还有另一种方法可以结束您想要的格式。如果您设置格式化选项空行 - >现有空行 - >要保留的空行数为1,则可以在静态块之前手动添加空行,格式化程序不会将其删除。

enter image description here

答案 1 :(得分:0)

正如其他答案所指出的那样,通过Eclipse格式化程序对static块不可能做到这一点。实现此目的的另一种方法是在Eclipse中的File Search中搜索/替换:

自:

(^\s*\n)*(^\s*static\s*\{)

要:

\n\2

启用Regular Expression