简体   繁体   中英

Eclipse 3.7 formatting static in class

In Eclipse 3.7 is code:

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

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

Where in Formatter is possible to say that before static should be empty line?

There is no separate formatting setting for the static block. For formatting purposes it appears to be treated as any other member variable (as opposed to a function or some other construct).

There is another way to end up with the formatting you want though. If you set the formatting option Blank Lines->Existing Blank Lines->Number of empty lines to preserve to be 1, then you can manually add a blank line before the static block and the formatter will not remove it.

在此输入图像描述

As other answers point out, this is not possible to do for static blocks through the Eclipse formatter. One other way to accomplish this would be through search/replace in File Search in Eclipse:

From:

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

To:

\n\2

with Regular Expression enabled

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM