Eclipse 3.7 formatting in class

There is code in Eclipse 3.7:

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

Where in Formatter can I say that there should be an empty string before static ?

+4
source share
2 answers

There is no separate formatting setting for a static block. For formatting purposes, it appears to be treated like 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. If you set the format parameter Blank Lines-> Existing Blank Lines-> Number of empty lines to 1, then you can manually add an empty line in front of the static block, and the formatter will not delete it.

enter image description here

0
source

As the other answers indicate, this cannot be done for static blocks through the Eclipse formatter. Another way to achieve this would be to search / replace in File Search in Eclipse:

From:

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

To:

 \n\2 

with Regular Expression enabled

0
source

All Articles