From 8a95f23a2321f6e867a0ffe8dea13ccc5affe827 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 8 Dec 2015 19:06:16 +0300 Subject: [PATCH] Adjust formatting for FILE_ANNOTATION_LIST --- .../idea/formatter/kotlinSpacingRules.kt | 3 ++ .../fileAnnotations/afterComment.after.kt | 4 ++ .../formatter/fileAnnotations/afterComment.kt | 3 ++ .../beforeDeclaration.after.kt | 3 ++ .../fileAnnotations/beforeDeclaration.kt | 1 + .../fileAnnotations/beforeImportList.after.kt | 3 ++ .../fileAnnotations/beforeImportList.kt | 1 + .../fileAnnotations/beforePackage.after.kt | 3 ++ .../fileAnnotations/beforePackage.kt | 1 + .../fileAnnotations/inEmptyFile.after.kt | 1 + .../formatter/fileAnnotations/inEmptyFile.kt | 1 + .../manyLinesFromFileBegin.after.kt | 7 +++ .../fileAnnotations/manyLinesFromFileBegin.kt | 7 +++ .../formatter/FormatterTestGenerated.java | 45 +++++++++++++++++++ 14 files changed, 83 insertions(+) create mode 100644 idea/testData/formatter/fileAnnotations/afterComment.after.kt create mode 100644 idea/testData/formatter/fileAnnotations/afterComment.kt create mode 100644 idea/testData/formatter/fileAnnotations/beforeDeclaration.after.kt create mode 100644 idea/testData/formatter/fileAnnotations/beforeDeclaration.kt create mode 100644 idea/testData/formatter/fileAnnotations/beforeImportList.after.kt create mode 100644 idea/testData/formatter/fileAnnotations/beforeImportList.kt create mode 100644 idea/testData/formatter/fileAnnotations/beforePackage.after.kt create mode 100644 idea/testData/formatter/fileAnnotations/beforePackage.kt create mode 100644 idea/testData/formatter/fileAnnotations/inEmptyFile.after.kt create mode 100644 idea/testData/formatter/fileAnnotations/inEmptyFile.kt create mode 100644 idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.after.kt create mode 100644 idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt index 9b37be03be2..7c31c7a6590 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/kotlinSpacingRules.kt @@ -84,6 +84,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder { simple { // ============ Line breaks ============== + before(FILE_ANNOTATION_LIST).lineBreakInCode() + after(FILE_ANNOTATION_LIST).blankLines(1) + after(PACKAGE_DIRECTIVE).blankLines(1) between(IMPORT_DIRECTIVE, IMPORT_DIRECTIVE).lineBreakInCode() after(IMPORT_LIST).blankLines(1) diff --git a/idea/testData/formatter/fileAnnotations/afterComment.after.kt b/idea/testData/formatter/fileAnnotations/afterComment.after.kt new file mode 100644 index 00000000000..7f006cd832d --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/afterComment.after.kt @@ -0,0 +1,4 @@ +/* + * Comment + */ +@file:Some("Hi") \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/afterComment.kt b/idea/testData/formatter/fileAnnotations/afterComment.kt new file mode 100644 index 00000000000..f654739dfaf --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/afterComment.kt @@ -0,0 +1,3 @@ +/* + * Comment + */ @file:Some("Hi") \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/beforeDeclaration.after.kt b/idea/testData/formatter/fileAnnotations/beforeDeclaration.after.kt new file mode 100644 index 00000000000..f795f8e2fef --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/beforeDeclaration.after.kt @@ -0,0 +1,3 @@ +@file:Some() + +val test = 1 \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/beforeDeclaration.kt b/idea/testData/formatter/fileAnnotations/beforeDeclaration.kt new file mode 100644 index 00000000000..1acf42d38aa --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/beforeDeclaration.kt @@ -0,0 +1 @@ +@file:Some() val test = 1 \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/beforeImportList.after.kt b/idea/testData/formatter/fileAnnotations/beforeImportList.after.kt new file mode 100644 index 00000000000..e0465e7cdfd --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/beforeImportList.after.kt @@ -0,0 +1,3 @@ +@file:Some() + +import hi \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/beforeImportList.kt b/idea/testData/formatter/fileAnnotations/beforeImportList.kt new file mode 100644 index 00000000000..ace585cc9a7 --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/beforeImportList.kt @@ -0,0 +1 @@ +@file:Some() import hi \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/beforePackage.after.kt b/idea/testData/formatter/fileAnnotations/beforePackage.after.kt new file mode 100644 index 00000000000..2ca5bcaa353 --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/beforePackage.after.kt @@ -0,0 +1,3 @@ +@file:Some() + +package test \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/beforePackage.kt b/idea/testData/formatter/fileAnnotations/beforePackage.kt new file mode 100644 index 00000000000..a67e4f23536 --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/beforePackage.kt @@ -0,0 +1 @@ +@file:Some() package test \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/inEmptyFile.after.kt b/idea/testData/formatter/fileAnnotations/inEmptyFile.after.kt new file mode 100644 index 00000000000..53eabeae948 --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/inEmptyFile.after.kt @@ -0,0 +1 @@ +@file:Some() \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/inEmptyFile.kt b/idea/testData/formatter/fileAnnotations/inEmptyFile.kt new file mode 100644 index 00000000000..53eabeae948 --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/inEmptyFile.kt @@ -0,0 +1 @@ +@file:Some() \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.after.kt b/idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.after.kt new file mode 100644 index 00000000000..47a130758af --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.after.kt @@ -0,0 +1,7 @@ + + + + + + +@file:Some() \ No newline at end of file diff --git a/idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.kt b/idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.kt new file mode 100644 index 00000000000..47a130758af --- /dev/null +++ b/idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.kt @@ -0,0 +1,7 @@ + + + + + + +@file:Some() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index f3db7f014d6..aa54bb5a5af 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -565,6 +565,51 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("idea/testData/formatter/fileAnnotations") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class FileAnnotations extends AbstractFormatterTest { + @TestMetadata("afterComment.after.kt") + public void testAfterComment() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/fileAnnotations/afterComment.after.kt"); + doTest(fileName); + } + + public void testAllFilesPresentInFileAnnotations() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/formatter/fileAnnotations"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true); + } + + @TestMetadata("beforeDeclaration.after.kt") + public void testBeforeDeclaration() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/fileAnnotations/beforeDeclaration.after.kt"); + doTest(fileName); + } + + @TestMetadata("beforeImportList.after.kt") + public void testBeforeImportList() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/fileAnnotations/beforeImportList.after.kt"); + doTest(fileName); + } + + @TestMetadata("beforePackage.after.kt") + public void testBeforePackage() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/fileAnnotations/beforePackage.after.kt"); + doTest(fileName); + } + + @TestMetadata("inEmptyFile.after.kt") + public void testInEmptyFile() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/fileAnnotations/inEmptyFile.after.kt"); + doTest(fileName); + } + + @TestMetadata("manyLinesFromFileBegin.after.kt") + public void testManyLinesFromFileBegin() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/fileAnnotations/manyLinesFromFileBegin.after.kt"); + doTest(fileName); + } + } + @TestMetadata("idea/testData/formatter/modifierList") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)