Bug 567714 - [15] Formatting record file moves annotation to the line of
record declaration

Change-Id: I919e96d7e91d4e035216be0160a8d00f55350606
Signed-off-by: Mateusz Matela <mateusz.matela@gmail.com>
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 fe3efb1..80a8a1d 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
@@ -13218,4 +13218,17 @@
 		"	);\n" +
 		"}");
 }
+/**
+ * https://bugs.eclipse.org/567714 - [15] Formatting record file moves annotation to the line of record declaration
+ */
+public void testBug567714() {
+	formatSource(
+		"@SuppressWarnings(\"preview\")\n" +
+		"@Deprecated\n" +
+		"public record X(int i) {\n" +
+		"	public X(int i) {\n" +
+		"		this.i = i;\n" +
+		"	}\n" +
+		"}");
+}
 }
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 9d034eb..9016c8e 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
@@ -274,6 +274,7 @@
 
 	@Override
 	public boolean visit(RecordDeclaration node) {
+		handleAnnotations(node.modifiers(), this.options.insert_new_line_after_annotation_on_type);
 		handleBracedCode(node, node.getName(), this.options.brace_position_for_record_declaration,
 				this.options.indent_body_declarations_compare_to_record_header);
 		handleBodyDeclarations(node.bodyDeclarations());
diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
index e207ce2..bb33014 100644
--- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
+++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/linewrap/WrapPreparator.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2019 Mateusz Matela and others.
+ * Copyright (c) 2014, 2020 Mateusz Matela and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -345,6 +345,8 @@
 
 	@Override
 	public boolean visit(RecordDeclaration node) {
+		handleAnnotations(node.modifiers(), this.options.alignment_for_annotations_on_type);
+
 		int lParen = this.tm.firstIndexAfter(node.getName(), TokenNameLPAREN);
 		List<SingleVariableDeclaration> components = node.recordComponents();
 		int rParen = this.tm.firstIndexAfter(