Formatter: fix line break after package & file annotation
#KT-23957 Fixed
This commit is contained in:
@@ -53,9 +53,6 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
return rules(kotlinCommonSettings, builderUtil) {
|
||||
simple {
|
||||
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)
|
||||
}
|
||||
@@ -98,7 +95,14 @@ fun createSpacingBuilder(settings: CodeStyleSettings, builderUtil: KotlinSpacing
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
simple {
|
||||
after(FILE_ANNOTATION_LIST).blankLines(1)
|
||||
after(PACKAGE_DIRECTIVE).blankLines(1)
|
||||
}
|
||||
|
||||
custom {
|
||||
inPosition(leftSet = DECLARATIONS, rightSet = DECLARATIONS).customRule(fun(
|
||||
_: ASTBlock,
|
||||
_: ASTBlock,
|
||||
|
||||
+4
@@ -5,12 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix.expectactual
|
||||
|
||||
import com.intellij.codeInsight.actions.ReformatCodeAction
|
||||
import com.intellij.ide.util.EditorHelper
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.DumbService
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import com.intellij.psi.formatter.FormatterUtil
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction
|
||||
import org.jetbrains.kotlin.idea.quickfix.TypeAccessibilityChecker
|
||||
@@ -18,6 +20,7 @@ import org.jetbrains.kotlin.idea.refactoring.introduce.showErrorHint
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import java.util.*
|
||||
|
||||
abstract class AbstractCreateDeclarationFix<D : KtNamedDeclaration>(
|
||||
declaration: D,
|
||||
@@ -71,6 +74,7 @@ abstract class AbstractCreateDeclarationFix<D : KtNamedDeclaration>(
|
||||
val oldPackageDirective = targetFile.packageDirective
|
||||
val newPackageDirective = packageDirective.copy() as KtPackageDirective
|
||||
if (oldPackageDirective != null) {
|
||||
if (oldPackageDirective.text.isEmpty()) targetFile.addAfter(factory.createNewLine(2), oldPackageDirective)
|
||||
oldPackageDirective.replace(newPackageDirective)
|
||||
} else {
|
||||
targetFile.add(newPackageDirective)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package one // tooo
|
||||
|
||||
val a = 42
|
||||
@@ -0,0 +1,3 @@
|
||||
package one // tooo
|
||||
|
||||
val a = 42
|
||||
@@ -0,0 +1,2 @@
|
||||
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // for common tests
|
||||
package foo
|
||||
@@ -0,0 +1,2 @@
|
||||
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") // for common tests
|
||||
package foo
|
||||
@@ -0,0 +1,3 @@
|
||||
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED")
|
||||
// for common tests
|
||||
package foo
|
||||
@@ -0,0 +1,3 @@
|
||||
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED")
|
||||
// for common tests
|
||||
package foo
|
||||
@@ -0,0 +1,2 @@
|
||||
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") /*for common tests*/
|
||||
package foo
|
||||
@@ -0,0 +1,2 @@
|
||||
@file:Suppress("NAMED_ARGUMENTS_NOT_ALLOWED") /*for common tests*/
|
||||
package foo
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
@file:Suppress("REDUNDANT_NULLABLE")
|
||||
|
||||
// "Suppress 'REDUNDANT_NULLABLE' for file ${file}" "true"
|
||||
|
||||
public fun foo(): String?<caret>? = null
|
||||
@@ -165,6 +165,11 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
runTest("idea/testData/formatter/ColonSpaces.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CommentAfterPackage.after.kt")
|
||||
public void testCommentAfterPackage() throws Exception {
|
||||
runTest("idea/testData/formatter/CommentAfterPackage.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("CommentInExpressionBodies.after.kt")
|
||||
public void testCommentInExpressionBodies() throws Exception {
|
||||
runTest("idea/testData/formatter/CommentInExpressionBodies.after.kt");
|
||||
@@ -955,6 +960,21 @@ public class FormatterTestGenerated extends AbstractFormatterTest {
|
||||
runTest("idea/testData/formatter/fileAnnotations/beforePackage.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("commentAfter.after.kt")
|
||||
public void testCommentAfter() throws Exception {
|
||||
runTest("idea/testData/formatter/fileAnnotations/commentAfter.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("commentAfter2.after.kt")
|
||||
public void testCommentAfter2() throws Exception {
|
||||
runTest("idea/testData/formatter/fileAnnotations/commentAfter2.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("commentAfter3.after.kt")
|
||||
public void testCommentAfter3() throws Exception {
|
||||
runTest("idea/testData/formatter/fileAnnotations/commentAfter3.after.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inEmptyFile.after.kt")
|
||||
public void testInEmptyFile() throws Exception {
|
||||
runTest("idea/testData/formatter/fileAnnotations/inEmptyFile.after.kt");
|
||||
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
// ERROR: Class 'A' is not abstract and does not implement abstract member public abstract fun run(): Unit defined in java.lang.Runnable
|
||||
package foo
|
||||
|
||||
// we use package 'foo'
|
||||
package foo // we use package 'foo'
|
||||
|
||||
// imports:
|
||||
import java.util.ArrayList // we need ArrayList
|
||||
|
||||
Reference in New Issue
Block a user