diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt index 5152908d29b..d57bcd007cb 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.lexer.KtTokens.* import org.jetbrains.kotlin.psi.KtBlockExpression import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtExpression +import org.jetbrains.kotlin.psi.KtSuperTypeListEntry import java.util.* private val QUALIFIED_OPERATION = TokenSet.create(DOT, SAFE_ACCESS) @@ -272,7 +273,7 @@ abstract class KotlinCommonBlock( private fun buildSubBlock(child: ASTNode, alignmentStrategy: CommonAlignmentStrategy, wrappingStrategy: WrappingStrategy): Block { - val childWrap = wrappingStrategy.getWrap(child.elementType) + val childWrap = wrappingStrategy.getWrap(child) // Skip one sub-level for operators, so type of block node is an element type of operator if (child.elementType === KtNodeTypes.OPERATION_REFERENCE) { @@ -334,6 +335,14 @@ abstract class KotlinCommonBlock( return getWrappingStrategyForItemList(commonSettings.METHOD_PARAMETERS_WRAP, KtNodeTypes.VALUE_PARAMETER) } } + + elementType === KtNodeTypes.SUPER_TYPE_LIST -> { + val wrap = Wrap.createWrap(commonSettings.EXTENDS_LIST_WRAP, false) + return object : WrappingStrategy { + override fun getWrap(childElement: ASTNode): Wrap? = + if (childElement.psi is KtSuperTypeListEntry) wrap else null + } + } } return WrappingStrategy.NoWrapping @@ -496,8 +505,8 @@ private fun getPrevWithoutWhitespaceAndComments(pNode: ASTNode?): ASTNode? { private fun getWrappingStrategyForItemList(wrapType: Int, itemType: IElementType): WrappingStrategy { val itemWrap = Wrap.createWrap(wrapType, false) return object : WrappingStrategy { - override fun getWrap(childElementType: IElementType): Wrap? { - return if (childElementType === itemType) itemWrap else null + override fun getWrap(childElement: ASTNode): Wrap? { + return if (childElement.elementType === itemType) itemWrap else null } } } diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/WrappingStrategy.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/WrappingStrategy.kt index 707737a4191..6c9a9ab8859 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/WrappingStrategy.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/WrappingStrategy.kt @@ -17,12 +17,12 @@ package org.jetbrains.kotlin.idea.formatter import com.intellij.formatting.Wrap -import com.intellij.psi.tree.IElementType +import com.intellij.lang.ASTNode interface WrappingStrategy { - fun getWrap(childElementType: IElementType): Wrap? + fun getWrap(childElement: ASTNode): Wrap? object NoWrapping: WrappingStrategy { - override fun getWrap(childElementType: IElementType): Wrap? = null + override fun getWrap(childElement: ASTNode): Wrap? = null } } diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt index 2191725f109..cd02a3d6dea 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt @@ -30,7 +30,7 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide override fun getCodeSample(settingsType: LanguageCodeStyleSettingsProvider.SettingsType): String = when (settingsType) { LanguageCodeStyleSettingsProvider.SettingsType.WRAPPING_AND_BRACES_SETTINGS -> """ - public class ThisIsASampleClass { + public class ThisIsASampleClass : Comparable<*>, Appendable { val test = 12 @@ -235,6 +235,7 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide "FINALLY_ON_NEW_LINE", "CALL_PARAMETERS_WRAP", "METHOD_PARAMETERS_WRAP", + "EXTENDS_LIST_WRAP", "METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE", "METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE", "CALL_PARAMETERS_LPAREN_ON_NEXT_LINE", diff --git a/idea/testData/formatter/ExtendsListWrap.after.kt b/idea/testData/formatter/ExtendsListWrap.after.kt new file mode 100644 index 00000000000..82cc0bc834a --- /dev/null +++ b/idea/testData/formatter/ExtendsListWrap.after.kt @@ -0,0 +1,7 @@ +class Foo : Comparable<*>, + Appendable { + +} + +// SET_INT: EXTENDS_LIST_WRAP = 2 +// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST diff --git a/idea/testData/formatter/ExtendsListWrap.kt b/idea/testData/formatter/ExtendsListWrap.kt new file mode 100644 index 00000000000..f01e2631689 --- /dev/null +++ b/idea/testData/formatter/ExtendsListWrap.kt @@ -0,0 +1,6 @@ +class Foo : Comparable<*>, Appendable { + +} + +// SET_INT: EXTENDS_LIST_WRAP = 2 +// SET_TRUE: ALIGN_MULTILINE_EXTENDS_LIST diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java index 7fdb3c0efdd..7b5a6e0cbcc 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatterTestGenerated.java @@ -308,6 +308,12 @@ public class FormatterTestGenerated extends AbstractFormatterTest { doTest(fileName); } + @TestMetadata("ExtendsListWrap.after.kt") + public void testExtendsListWrap() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ExtendsListWrap.after.kt"); + doTest(fileName); + } + @TestMetadata("ForLineBreak.after.kt") public void testForLineBreak() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/formatter/ForLineBreak.after.kt");