Supported "initializer block" arrangement entry (IDEA-95115)

Previous behaviour was to treat initializer block as field and stick it with previous field, now it's eliminated with matching and rearranging according to matching rules. See comments also in [CR-IC-6618]
This commit is contained in:
Yaroslav Lepenkin
2014-10-27 22:19:07 +04:00
parent 31c8033856
commit 98b4ec43a6
8 changed files with 126 additions and 34 deletions
@@ -83,9 +83,10 @@ class Test {
expected: '''\
class Test {
public int j;
{ j = 1; }
protected int k;
private int i;
{ j = 1; }
}''',
rules: [rule(FIELD, PUBLIC), rule(FIELD, PROTECTED), rule(FIELD, PRIVATE)])
}
@@ -101,10 +102,11 @@ class Test {
}''',
expected: '''\
class Test {
{ j = 1; }
public int j;
protected int k;
private int i;
{ j = 1; }
}''',
rules: [rule(FIELD, PUBLIC), rule(FIELD, PROTECTED), rule(FIELD, PRIVATE)])
}
@@ -569,4 +569,85 @@ class B extends A {
rules: [rule(PUBLIC, METHOD), rule(PRIVATE, METHOD)]
)
}
void "test initializer block after fields"() {
doTest(
initial: '''\
public class NewOneClass {
{
a = 1;
}
int a;
{
b = 5;
}
int b;
}
''',
expected: '''\
public class NewOneClass {
int a;
int b;
{
a = 1;
}
{
b = 5;
}
}
''',
rules: [rule(FIELD), rule(INIT_BLOCK)]
)
}
void "test static initializer block"() {
doTest(
initial: '''\
public class NewOneClass {
static {
a = 1;
}
static int a;
{
b = 5;
}
int b;
}
''',
expected: '''\
public class NewOneClass {
static int a;
static {
a = 1;
}
int b;
{
b = 5;
}
}
''',
rules: [rule(STATIC, FIELD), rule(STATIC, INIT_BLOCK), rule(FIELD), rule(INIT_BLOCK)]
)
}
}
@@ -25,6 +25,7 @@ public class JavaFormatterBlankLinesTest extends AbstractJavaFormatterTest {
public void testBlankLinesAroundClassInitializationBlock() throws Exception {
getSettings().BLANK_LINES_AROUND_METHOD = 3;
getJavaSettings().BLANK_LINES_AROUND_INITIALIZER = 3;
doTextTest(
"class T {\n" +
" private final DecimalFormat fmt = new DecimalFormat();\n" +