diff options
author | Mateusz Matela | 2019-08-03 23:49:45 +0000 |
---|---|---|
committer | Mateusz Matela | 2019-08-03 23:49:45 +0000 |
commit | 9acb7086514502a716e3f5a9596c8a76f9aa0b8c (patch) | |
tree | 982cf38b4c32dd427c66a5d6c9c1a5910f1a5d14 | |
parent | d5ab917ba37be34f167c95a66058be3ba7693473 (diff) | |
download | eclipse.jdt.core-9acb7086514502a716e3f5a9596c8a76f9aa0b8c.tar.gz eclipse.jdt.core-9acb7086514502a716e3f5a9596c8a76f9aa0b8c.tar.xz eclipse.jdt.core-9acb7086514502a716e3f5a9596c8a76f9aa0b8c.zip |
Bug 549774 - [formatter] Change semantics of Blank lines before member
declarations: 'before' -> 'between'
Change-Id: Id1f4a36c205eb76f430b94902d61e1565d0cb071
Signed-off-by: Mateusz Matela <mateusz.matela@gmail.com>
5 files changed, 45 insertions, 19 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java index 91ba60c9c7..84fe6e8d28 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java @@ -11914,19 +11914,16 @@ public void testBug475791() { " String field2;\r\n" + " static {\r\n" + " }\r\n" + - "\r\n" + " static void staticMethod() {\r\n" + " };\r\n" + " static {\r\n" + " }\r\n" + - "\r\n" + " void method() {\r\n" + " }\r\n" + " static {\r\n" + " }\r\n" + " {\r\n" + " }\r\n" + - "\r\n" + " static class staticClass {\r\n" + " };\r\n" + " {\r\n" + diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java index 2f7925c726..b662f74118 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java @@ -15094,4 +15094,34 @@ public void testBug522089b() throws JavaModelException { String input = getCompilationUnit("Formatter", "", "test522089", "in.java").getSource(); formatSource(input, getCompilationUnit("Formatter", "", "test522089", "B_out.java").getSource()); } +/** + * https://bugs.eclipse.org/549774 - [formatter] Change semantics of Blank lines before member declarations: 'before' -> 'between' + */ +public void testBug549774() throws JavaModelException { + this.formatterPrefs.blank_lines_before_new_chunk = 1; + this.formatterPrefs.blank_lines_before_field = 2; + this.formatterPrefs.blank_lines_before_method = 3; + String input = + "class C {\n" + + " int a;\n" + + " String s;\n" + + " void foo() {}\n" + + " String bar(int a) {}\n" + + "}"; + formatSource(input, + "class C {\n" + + " int a;\n" + + "\n" + + "\n" + + " String s;\n" + + "\n" + + " void foo() {\n" + + " }\n" + + "\n" + + "\n" + + "\n" + + " String bar(int a) {\n" + + " }\n" + + "}"); +} } diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test549249/D_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test549249/D_out.java index 8b1a8552e5..5f63c02ad8 100644 --- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test549249/D_out.java +++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test549249/D_out.java @@ -60,6 +60,7 @@ public class Example { + private LinkedList fList; diff --git a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test549249/H_out.java b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test549249/H_out.java index 7ccb51dd20..3b680a3699 100644 --- a/org.eclipse.jdt.core.tests.model/workspace/Formatter/test549249/H_out.java +++ b/org.eclipse.jdt.core.tests.model/workspace/Formatter/test549249/H_out.java @@ -71,6 +71,7 @@ public class Example { + public Example(LinkedList list) { diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java index b3eaa23eb5..9a72f1f619 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java @@ -159,23 +159,20 @@ public class LineBreaksPreparator extends ASTVisitor { private void handleBodyDeclarations(List<BodyDeclaration> bodyDeclarations) { BodyDeclaration previous = null; for (BodyDeclaration bodyDeclaration : bodyDeclarations) { + int blankLines = 0; if (previous == null) { - putBlankLinesBefore(bodyDeclaration, this.options.blank_lines_before_first_class_body_declaration); - } else { - int blankLines = 0; - if (bodyDeclaration instanceof FieldDeclaration) { - blankLines = this.options.blank_lines_before_field; - } else if (bodyDeclaration instanceof AbstractTypeDeclaration) { - blankLines = this.options.blank_lines_before_member_type; - } else if (bodyDeclaration instanceof MethodDeclaration - || bodyDeclaration instanceof AnnotationTypeMemberDeclaration) { - blankLines = this.options.blank_lines_before_method; - } - - putBlankLinesBefore(bodyDeclaration, blankLines); - if (!sameChunk(previous, bodyDeclaration)) - putBlankLinesBefore(bodyDeclaration, this.options.blank_lines_before_new_chunk); + blankLines = this.options.blank_lines_before_first_class_body_declaration; + } else if (!sameChunk(previous, bodyDeclaration)) { + blankLines = this.options.blank_lines_before_new_chunk; + } else if (bodyDeclaration instanceof FieldDeclaration) { + blankLines = this.options.blank_lines_before_field; + } else if (bodyDeclaration instanceof AbstractTypeDeclaration) { + blankLines = this.options.blank_lines_before_member_type; + } else if (bodyDeclaration instanceof MethodDeclaration + || bodyDeclaration instanceof AnnotationTypeMemberDeclaration) { + blankLines = this.options.blank_lines_before_method; } + putBlankLinesBefore(bodyDeclaration, blankLines); previous = bodyDeclaration; } } @@ -187,7 +184,7 @@ public class LineBreaksPreparator extends ASTVisitor { return true; if ((bd1 instanceof FieldDeclaration || bd1 instanceof Initializer) && (bd2 instanceof FieldDeclaration || bd2 instanceof Initializer)) - return true; + return true; // special case: initializers are often related to fields, don't separate return false; } |