diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinObsoleteCodeStyle.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinObsoleteCodeStyle.kt new file mode 100644 index 00000000000..2b868bb1265 --- /dev/null +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinObsoleteCodeStyle.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.formatter + +import com.intellij.psi.codeStyle.CodeStyleSettings +import com.intellij.psi.codeStyle.CommonCodeStyleSettings +import com.intellij.psi.codeStyle.PredefinedCodeStyle +import org.jetbrains.kotlin.idea.KotlinLanguage +import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings + +class KotlinObsoleteCodeStyle : PredefinedCodeStyle(CODE_STYLE_TITLE, KotlinLanguage.INSTANCE) { + override fun apply(settings: CodeStyleSettings) { + Companion.apply(settings) + } + + companion object { + const val CODE_STYLE_ID = "KOTLIN_OBSOLETE" + const val CODE_STYLE_TITLE = "Kotlin obsolete IntelliJ IDEA codestyle" + + fun apply(settings: CodeStyleSettings) { + applyToKotlinCustomSettings(settings.kotlinCustomSettings) + applyToCommonSettings(settings.kotlinCommonSettings) + } + + fun applyToKotlinCustomSettings(kotlinCustomSettings: KotlinCodeStyleSettings, modifyCodeStyle: Boolean = true) { + kotlinCustomSettings.apply { + if (modifyCodeStyle) { + CODE_STYLE_DEFAULTS = CODE_STYLE_ID + } + + CONTINUATION_INDENT_IN_PARAMETER_LISTS = true + CONTINUATION_INDENT_IN_ARGUMENT_LISTS = true + CONTINUATION_INDENT_FOR_EXPRESSION_BODIES = true + CONTINUATION_INDENT_FOR_CHAINED_CALLS = true + CONTINUATION_INDENT_IN_SUPERTYPE_LISTS = true + CONTINUATION_INDENT_IN_IF_CONDITIONS = true + CONTINUATION_INDENT_IN_ELVIS = true + WRAP_EXPRESSION_BODY_FUNCTIONS = CodeStyleSettings.DO_NOT_WRAP + IF_RPAREN_ON_NEW_LINE = false + } + } + + fun applyToCommonSettings(commonSettings: CommonCodeStyleSettings, modifyCodeStyle: Boolean = true) { + commonSettings.apply { + CALL_PARAMETERS_WRAP = CodeStyleSettings.DO_NOT_WRAP + CALL_PARAMETERS_LPAREN_ON_NEXT_LINE = false + CALL_PARAMETERS_RPAREN_ON_NEXT_LINE = false + + METHOD_PARAMETERS_WRAP = CodeStyleSettings.DO_NOT_WRAP + METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = false + METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE = false + + EXTENDS_LIST_WRAP = CodeStyleSettings.DO_NOT_WRAP + METHOD_CALL_CHAIN_WRAP = CodeStyleSettings.DO_NOT_WRAP + ASSIGNMENT_WRAP = CodeStyleSettings.DO_NOT_WRAP + } + + if (modifyCodeStyle && commonSettings is KotlinCommonCodeStyleSettings) { + commonSettings.CODE_STYLE_DEFAULTS = CODE_STYLE_ID + } + } + } +} diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 12200cc0362..27a16ef9d79 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -453,6 +453,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. + + + + + +