From decbe99391353ee3570e49da0cb5227d91316d99 Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Fri, 10 Apr 2020 23:30:33 +0700 Subject: [PATCH] Merge KotlinCodeStyleSettingsProvider to KotlinLanguageCodeStyleSettingsProvider --- idea/resources/META-INF/plugin-common.xml | 3 +- .../messages/KotlinBundle.properties | 3 +- .../idea/formatter/ImportSettingsPanel.kt | 3 +- .../idea/formatter/KotlinCodeStylePanel.kt | 27 + .../KotlinCodeStyleSettingsProvider.java | 81 --- ...KotlinLanguageCodeStyleSettingsProvider.kt | 501 +++++++++--------- .../idea/formatter/KotlinSaveStylePanel.kt | 3 +- 7 files changed, 293 insertions(+), 328 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStylePanel.kt delete mode 100644 idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleSettingsProvider.java diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 1816c87d04c..60f2a0a5324 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -415,9 +415,8 @@ - - + diff --git a/idea/resources/messages/KotlinBundle.properties b/idea/resources/messages/KotlinBundle.properties index a1ad3885d0c..e7b0926c41e 100644 --- a/idea/resources/messages/KotlinBundle.properties +++ b/idea/resources/messages/KotlinBundle.properties @@ -2194,4 +2194,5 @@ fix.move.file.to.package.dir.name.text=source root move.refactoring.error.text.cannot.perform.refactoring.since.the.following.files.already.exist=Cannot perform refactoring since the following files already exist:\n\n kotlin.script.definitions.model.name.is.enabled=Is Enabled kotlin.script.definitions.model.name.pattern.extension=Pattern/Extension -kotlin.script.definitions.model.name.name=Name \ No newline at end of file +kotlin.script.definitions.model.name.name=Name +codestyle.name.kotlin=Kotlin \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/ImportSettingsPanel.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/ImportSettingsPanel.kt index 7ee4d968953..79d732c571c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/ImportSettingsPanel.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/ImportSettingsPanel.kt @@ -15,6 +15,7 @@ import com.intellij.psi.codeStyle.PackageEntryTable import com.intellij.ui.OptionGroup import com.intellij.ui.components.JBScrollPane import org.jetbrains.kotlin.idea.KotlinBundle +import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings import java.awt.BorderLayout import java.awt.GridBagConstraints @@ -23,7 +24,7 @@ import java.awt.Insets import javax.swing.* import javax.swing.table.AbstractTableModel -class ImportSettingsPanelWrapper(settings: CodeStyleSettings) : CodeStyleAbstractPanel(settings) { +class ImportSettingsPanelWrapper(settings: CodeStyleSettings) : CodeStyleAbstractPanel(KotlinLanguage.INSTANCE, null, settings) { private val importsPanel = ImportSettingsPanel(settings) private fun CodeStyleSettings.kotlinSettings() = getCustomSettings(KotlinCodeStyleSettings::class.java) diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStylePanel.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStylePanel.kt new file mode 100644 index 00000000000..cc54a708cd8 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStylePanel.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * 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.application.options.TabbedLanguageCodeStylePanel +import com.intellij.psi.codeStyle.CodeStyleSettings +import com.intellij.psi.codeStyle.CodeStyleSettingsProvider +import org.jetbrains.kotlin.idea.KotlinLanguage + +class KotlinCodeStylePanel(currentSettings: CodeStyleSettings, settings: CodeStyleSettings) : + TabbedLanguageCodeStylePanel(KotlinLanguage.INSTANCE, currentSettings, settings) { + override fun initTabs(settings: CodeStyleSettings) { + super.initTabs(settings) + + addTab(ImportSettingsPanelWrapper(settings)) + for (provider in CodeStyleSettingsProvider.EXTENSION_POINT_NAME.extensions) { + if (provider.language == KotlinLanguage.INSTANCE && !provider.hasSettingsPage()) { + createTab(provider) + } + } + + addTab(KotlinSaveStylePanel(settings)) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleSettingsProvider.java b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleSettingsProvider.java deleted file mode 100644 index 2c8c347682e..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinCodeStyleSettingsProvider.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.formatter; - -import com.intellij.application.options.CodeStyleAbstractConfigurable; -import com.intellij.application.options.CodeStyleAbstractPanel; -import com.intellij.application.options.TabbedLanguageCodeStylePanel; -import com.intellij.lang.Language; -import com.intellij.psi.codeStyle.CodeStyleConfigurable; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.psi.codeStyle.CodeStyleSettingsProvider; -import com.intellij.psi.codeStyle.CustomCodeStyleSettings; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.KotlinLanguage; -import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings; - -public class KotlinCodeStyleSettingsProvider extends CodeStyleSettingsProvider { - - @Override - public String getConfigurableDisplayName() { - return KotlinLanguage.NAME; - } - - @Override - public Language getLanguage() { - return KotlinLanguage.INSTANCE; - } - - @Override - public CustomCodeStyleSettings createCustomSettings(CodeStyleSettings settings) { - return new KotlinCodeStyleSettings(settings); - } - - @NotNull - @Override - public CodeStyleConfigurable createConfigurable(@NotNull CodeStyleSettings settings, @NotNull CodeStyleSettings modelSettings) { - return new CodeStyleAbstractConfigurable(settings, modelSettings, KotlinLanguage.NAME) { - @Override - protected CodeStyleAbstractPanel createPanel(CodeStyleSettings settings) { - return new TabbedLanguageCodeStylePanel(KotlinLanguage.INSTANCE, getCurrentSettings(), settings) { - @Override - protected void initTabs(CodeStyleSettings settings) { - // TODO: activate all parent tabs - addIndentOptionsTab(settings); - addSpacesTab(settings); - addWrappingAndBracesTab(settings); - addBlankLinesTab(settings); - addTab(new ImportSettingsPanelWrapper(settings)); - - for (CodeStyleSettingsProvider provider : CodeStyleSettingsProvider.EXTENSION_POINT_NAME.getExtensions()) { - if (provider.getLanguage() == KotlinLanguage.INSTANCE && !provider.hasSettingsPage()) { - createTab(provider); - } - } - - addTab(new KotlinSaveStylePanel(settings)); - } - }; - } - - @Override - public String getHelpTopic() { - return null; - } - }; - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt index bc34b18c797..c36fde771a5 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinLanguageCodeStyleSettingsProvider.kt @@ -1,23 +1,276 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * 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.application.options.CodeStyleAbstractConfigurable +import com.intellij.application.options.CodeStyleAbstractPanel import com.intellij.application.options.IndentOptionsEditor import com.intellij.application.options.SmartIndentOptionsEditor +import com.intellij.lang.Language import com.intellij.openapi.application.ApplicationBundle -import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable -import com.intellij.psi.codeStyle.CommonCodeStyleSettings -import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider +import com.intellij.psi.codeStyle.* import org.jetbrains.kotlin.idea.KotlinBundle import org.jetbrains.kotlin.idea.KotlinLanguage import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings import kotlin.reflect.KProperty class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvider() { - override fun getLanguage() = KotlinLanguage.INSTANCE + override fun getLanguage(): Language = KotlinLanguage.INSTANCE + override fun getConfigurableDisplayName(): String = KotlinBundle.message("codestyle.name.kotlin") + override fun getDisplayPriority(): DisplayPriority = DisplayPriority.COMMON_SETTINGS + override fun createConfigurable(settings: CodeStyleSettings, modelSettings: CodeStyleSettings): CodeStyleConfigurable = + object : CodeStyleAbstractConfigurable(settings, modelSettings, KotlinLanguage.NAME) { + override fun createPanel(settings: CodeStyleSettings): CodeStyleAbstractPanel = + KotlinCodeStylePanel(currentSettings, settings) + + override fun getHelpTopic(): String = "reference.settingsdialog.codestyle.kotlin" + } + + override fun getIndentOptionsEditor(): IndentOptionsEditor = SmartIndentOptionsEditor() + + override fun getDefaultCommonSettings(): CommonCodeStyleSettings = KotlinCommonCodeStyleSettings().apply { + initIndentOptions() + } + + override fun createCustomSettings(settings: CodeStyleSettings?): CustomCodeStyleSettings = KotlinCodeStyleSettings(settings) + + override fun customizeSettings(consumer: CodeStyleSettingsCustomizable, settingsType: SettingsType) { + fun showCustomOption(field: KProperty<*>, title: String, groupName: String? = null, vararg options: Any) { + consumer.showCustomOption(KotlinCodeStyleSettings::class.java, field.name, title, groupName, *options) + } + + when (settingsType) { + SettingsType.SPACING_SETTINGS -> { + consumer.showStandardOptions( + "SPACE_AROUND_ASSIGNMENT_OPERATORS", + "SPACE_AROUND_LOGICAL_OPERATORS", + "SPACE_AROUND_EQUALITY_OPERATORS", + "SPACE_AROUND_RELATIONAL_OPERATORS", + "SPACE_AROUND_ADDITIVE_OPERATORS", + "SPACE_AROUND_MULTIPLICATIVE_OPERATORS", + "SPACE_AROUND_UNARY_OPERATOR", + "SPACE_AFTER_COMMA", + "SPACE_BEFORE_COMMA", + "SPACE_BEFORE_IF_PARENTHESES", + "SPACE_BEFORE_WHILE_PARENTHESES", + "SPACE_BEFORE_FOR_PARENTHESES", + "SPACE_BEFORE_CATCH_PARENTHESES" + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_AROUND_RANGE, + KotlinBundle.message("formatter.title.range.operator"), + CodeStyleSettingsCustomizable.SPACES_AROUND_OPERATORS + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_BEFORE_TYPE_COLON, + KotlinBundle.message("formatter.title.before.colon.after.declaration.name"), + CodeStyleSettingsCustomizable.SPACES_OTHER + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_AFTER_TYPE_COLON, + KotlinBundle.message("formatter.title.after.colon.before.declaration.type"), + CodeStyleSettingsCustomizable.SPACES_OTHER + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_BEFORE_EXTEND_COLON, + KotlinBundle.message("formatter.title.before.colon.in.new.type.definition"), + CodeStyleSettingsCustomizable.SPACES_OTHER + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_AFTER_EXTEND_COLON, + KotlinBundle.message("formatter.title.after.colon.in.new.type.definition"), + CodeStyleSettingsCustomizable.SPACES_OTHER + ) + + showCustomOption( + KotlinCodeStyleSettings::INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD, + KotlinBundle.message("formatter.title.in.simple.one.line.methods"), + CodeStyleSettingsCustomizable.SPACES_OTHER + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_AROUND_FUNCTION_TYPE_ARROW, + KotlinBundle.message("formatter.title.around.arrow.in.function.types"), + CodeStyleSettingsCustomizable.SPACES_OTHER + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_AROUND_WHEN_ARROW, + KotlinBundle.message("formatter.title.around.arrow.in"), + CodeStyleSettingsCustomizable.SPACES_OTHER + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_BEFORE_LAMBDA_ARROW, + KotlinBundle.message("formatter.title.before.lambda.arrow"), + CodeStyleSettingsCustomizable.SPACES_OTHER + ) + + showCustomOption( + KotlinCodeStyleSettings::SPACE_BEFORE_WHEN_PARENTHESES, + KotlinBundle.message("formatter.title.when.parentheses"), + CodeStyleSettingsCustomizable.SPACES_BEFORE_PARENTHESES + ) + } + SettingsType.WRAPPING_AND_BRACES_SETTINGS -> { + consumer.showStandardOptions( + // "ALIGN_MULTILINE_CHAINED_METHODS", + "RIGHT_MARGIN", + "WRAP_ON_TYPING", + "KEEP_FIRST_COLUMN_COMMENT", + "KEEP_LINE_BREAKS", + "ALIGN_MULTILINE_EXTENDS_LIST", + "ALIGN_MULTILINE_PARAMETERS", + "ALIGN_MULTILINE_PARAMETERS_IN_CALLS", + "ALIGN_MULTILINE_METHOD_BRACKETS", + "ALIGN_MULTILINE_BINARY_OPERATION", + "ELSE_ON_NEW_LINE", + "WHILE_ON_NEW_LINE", + "CATCH_ON_NEW_LINE", + "FINALLY_ON_NEW_LINE", + "CALL_PARAMETERS_WRAP", + "METHOD_PARAMETERS_WRAP", + "EXTENDS_LIST_WRAP", + "METHOD_ANNOTATION_WRAP", + "CLASS_ANNOTATION_WRAP", + "PARAMETER_ANNOTATION_WRAP", + "VARIABLE_ANNOTATION_WRAP", + "FIELD_ANNOTATION_WRAP", + "METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE", + "METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE", + "CALL_PARAMETERS_LPAREN_ON_NEXT_LINE", + "CALL_PARAMETERS_RPAREN_ON_NEXT_LINE", + "ENUM_CONSTANTS_WRAP", + "METHOD_CALL_CHAIN_WRAP", + "WRAP_FIRST_METHOD_IN_CALL_CHAIN", + "ASSIGNMENT_WRAP", + ) + + consumer.renameStandardOption( + CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT, + KotlinBundle.message("formatter.title.when.statements") + ) + + consumer.renameStandardOption("FIELD_ANNOTATION_WRAP", KotlinBundle.message("formatter.title.property.annotations")) + consumer.renameStandardOption( + "METHOD_PARAMETERS_WRAP", + KotlinBundle.message("formatter.title.function.declaration.parameters") + ) + + consumer.renameStandardOption("CALL_PARAMETERS_WRAP", KotlinBundle.message("formatter.title.function.call.arguments")) + consumer.renameStandardOption("METHOD_CALL_CHAIN_WRAP", KotlinBundle.message("formatter.title.chained.function.calls")) + consumer.renameStandardOption("METHOD_ANNOTATION_WRAP", KotlinBundle.message("formatter.title.function.annotations")) + consumer.renameStandardOption( + CodeStyleSettingsCustomizable.WRAPPING_METHOD_PARENTHESES, + KotlinBundle.message("formatter.title.function.parentheses") + ) + + showCustomOption(KotlinCodeStyleSettings::ALLOW_TRAILING_COMMA, "Use trailing comma") + + showCustomOption( + KotlinCodeStyleSettings::ALIGN_IN_COLUMNS_CASE_BRANCH, + KotlinBundle.message("formatter.title.align.when.branches.in.columns"), + CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT + ) + + showCustomOption( + KotlinCodeStyleSettings::LBRACE_ON_NEXT_LINE, + KotlinBundle.message("formatter.title.put.left.brace.on.new.line"), + CodeStyleSettingsCustomizable.WRAPPING_BRACES + ) + + showCustomOption( + KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_PARAMETER_LISTS, + KotlinBundle.message("formatter.title.use.continuation.indent"), + CodeStyleSettingsCustomizable.WRAPPING_METHOD_PARAMETERS + ) + + showCustomOption( + KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_ARGUMENT_LISTS, + KotlinBundle.message("formatter.title.use.continuation.indent"), + CodeStyleSettingsCustomizable.WRAPPING_METHOD_ARGUMENTS_WRAPPING + ) + + showCustomOption( + KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_CHAINED_CALLS, + KotlinBundle.message("formatter.title.use.continuation.indent"), + CodeStyleSettingsCustomizable.WRAPPING_CALL_CHAIN + ) + + showCustomOption( + KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_SUPERTYPE_LISTS, + KotlinBundle.message("formatter.title.use.continuation.indent"), + CodeStyleSettingsCustomizable.WRAPPING_EXTENDS_LIST + ) + + showCustomOption( + KotlinCodeStyleSettings::WRAP_EXPRESSION_BODY_FUNCTIONS, + KotlinBundle.message("formatter.title.expression.body.functions"), + options = *arrayOf( + CodeStyleSettingsCustomizable.WRAP_OPTIONS_FOR_SINGLETON, + CodeStyleSettingsCustomizable.WRAP_VALUES_FOR_SINGLETON + ) + ) + + showCustomOption( + KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_EXPRESSION_BODIES, + KotlinBundle.message("formatter.title.use.continuation.indent"), + KotlinBundle.message("formatter.title.expression.body.functions") + ) + + showCustomOption( + KotlinCodeStyleSettings::WRAP_ELVIS_EXPRESSIONS, + KotlinBundle.message("formatter.title.elvis.expressions"), + options = *arrayOf( + CodeStyleSettingsCustomizable.WRAP_OPTIONS_FOR_SINGLETON, + CodeStyleSettingsCustomizable.WRAP_VALUES_FOR_SINGLETON + ) + ) + showCustomOption( + KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_ELVIS, + title = KotlinBundle.message("formatter.title.use.continuation.indent"), + groupName = KotlinBundle.message("formatter.title.elvis.expressions") + ) + + showCustomOption( + KotlinCodeStyleSettings::IF_RPAREN_ON_NEW_LINE, + ApplicationBundle.message("wrapping.rpar.on.new.line"), + CodeStyleSettingsCustomizable.WRAPPING_IF_STATEMENT + ) + + showCustomOption( + KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_IF_CONDITIONS, + KotlinBundle.message("formatter.title.use.continuation.indent.in.conditions"), + CodeStyleSettingsCustomizable.WRAPPING_IF_STATEMENT + ) + } + SettingsType.BLANK_LINES_SETTINGS -> { + consumer.showStandardOptions( + "KEEP_BLANK_LINES_IN_CODE", + "KEEP_BLANK_LINES_IN_DECLARATIONS", + "KEEP_BLANK_LINES_BEFORE_RBRACE", + "BLANK_LINES_AFTER_CLASS_HEADER" + ) + showCustomOption( + KotlinCodeStyleSettings::BLANK_LINES_AROUND_BLOCK_WHEN_BRANCHES, + KotlinBundle.message("formatter.title.around.when.branches.with"), + CodeStyleSettingsCustomizable.BLANK_LINES + ) + } + SettingsType.COMMENTER_SETTINGS -> { + consumer.showAllStandardOptions() + } + else -> consumer.showStandardOptions() + } + } override fun getCodeSample(settingsType: SettingsType): String = when (settingsType) { SettingsType.WRAPPING_AND_BRACES_SETTINGS -> @@ -167,240 +420,4 @@ class KotlinLanguageCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvide class AnotherClass : Some() """.trimIndent() } - - override fun getLanguageName(): String = KotlinLanguage.NAME - - override fun customizeSettings(consumer: CodeStyleSettingsCustomizable, settingsType: SettingsType) { - fun showCustomOption(field: KProperty<*>, title: String, groupName: String? = null, vararg options: Any) { - consumer.showCustomOption(KotlinCodeStyleSettings::class.java, field.name, title, groupName, *options) - } - - when (settingsType) { - SettingsType.SPACING_SETTINGS -> { - consumer.showStandardOptions( - "SPACE_AROUND_ASSIGNMENT_OPERATORS", - "SPACE_AROUND_LOGICAL_OPERATORS", - "SPACE_AROUND_EQUALITY_OPERATORS", - "SPACE_AROUND_RELATIONAL_OPERATORS", - "SPACE_AROUND_ADDITIVE_OPERATORS", - "SPACE_AROUND_MULTIPLICATIVE_OPERATORS", - "SPACE_AROUND_UNARY_OPERATOR", - "SPACE_AFTER_COMMA", - "SPACE_BEFORE_COMMA", - "SPACE_BEFORE_IF_PARENTHESES", - "SPACE_BEFORE_WHILE_PARENTHESES", - "SPACE_BEFORE_FOR_PARENTHESES", - "SPACE_BEFORE_CATCH_PARENTHESES" - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_AROUND_RANGE, - KotlinBundle.message("formatter.title.range.operator"), - CodeStyleSettingsCustomizable.SPACES_AROUND_OPERATORS - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_BEFORE_TYPE_COLON, - KotlinBundle.message("formatter.title.before.colon.after.declaration.name"), - CodeStyleSettingsCustomizable.SPACES_OTHER - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_AFTER_TYPE_COLON, - KotlinBundle.message("formatter.title.after.colon.before.declaration.type"), - CodeStyleSettingsCustomizable.SPACES_OTHER - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_BEFORE_EXTEND_COLON, - KotlinBundle.message("formatter.title.before.colon.in.new.type.definition"), - CodeStyleSettingsCustomizable.SPACES_OTHER - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_AFTER_EXTEND_COLON, - KotlinBundle.message("formatter.title.after.colon.in.new.type.definition"), - CodeStyleSettingsCustomizable.SPACES_OTHER - ) - - showCustomOption( - KotlinCodeStyleSettings::INSERT_WHITESPACES_IN_SIMPLE_ONE_LINE_METHOD, - KotlinBundle.message("formatter.title.in.simple.one.line.methods"), - CodeStyleSettingsCustomizable.SPACES_OTHER - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_AROUND_FUNCTION_TYPE_ARROW, - KotlinBundle.message("formatter.title.around.arrow.in.function.types"), - CodeStyleSettingsCustomizable.SPACES_OTHER - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_AROUND_WHEN_ARROW, - KotlinBundle.message("formatter.title.around.arrow.in"), - CodeStyleSettingsCustomizable.SPACES_OTHER - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_BEFORE_LAMBDA_ARROW, - KotlinBundle.message("formatter.title.before.lambda.arrow"), - CodeStyleSettingsCustomizable.SPACES_OTHER - ) - - showCustomOption( - KotlinCodeStyleSettings::SPACE_BEFORE_WHEN_PARENTHESES, - KotlinBundle.message("formatter.title.when.parentheses"), - CodeStyleSettingsCustomizable.SPACES_BEFORE_PARENTHESES - ) - } - SettingsType.WRAPPING_AND_BRACES_SETTINGS -> { - consumer.showStandardOptions( - // "ALIGN_MULTILINE_CHAINED_METHODS", - "RIGHT_MARGIN", - "WRAP_ON_TYPING", - "KEEP_FIRST_COLUMN_COMMENT", - "KEEP_LINE_BREAKS", - "ALIGN_MULTILINE_EXTENDS_LIST", - "ALIGN_MULTILINE_PARAMETERS", - "ALIGN_MULTILINE_PARAMETERS_IN_CALLS", - "ALIGN_MULTILINE_METHOD_BRACKETS", - "ALIGN_MULTILINE_BINARY_OPERATION", - "ELSE_ON_NEW_LINE", - "WHILE_ON_NEW_LINE", - "CATCH_ON_NEW_LINE", - "FINALLY_ON_NEW_LINE", - "CALL_PARAMETERS_WRAP", - "METHOD_PARAMETERS_WRAP", - "EXTENDS_LIST_WRAP", - "METHOD_ANNOTATION_WRAP", - "CLASS_ANNOTATION_WRAP", - "PARAMETER_ANNOTATION_WRAP", - "VARIABLE_ANNOTATION_WRAP", - "FIELD_ANNOTATION_WRAP", - "METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE", - "METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE", - "CALL_PARAMETERS_LPAREN_ON_NEXT_LINE", - "CALL_PARAMETERS_RPAREN_ON_NEXT_LINE", - "ENUM_CONSTANTS_WRAP", - "METHOD_CALL_CHAIN_WRAP", - "WRAP_FIRST_METHOD_IN_CALL_CHAIN", - "ASSIGNMENT_WRAP" - ) - consumer.renameStandardOption( - CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT, - KotlinBundle.message("formatter.title.when.statements") - ) - consumer.renameStandardOption("FIELD_ANNOTATION_WRAP", KotlinBundle.message("formatter.title.property.annotations")) - consumer.renameStandardOption( - "METHOD_PARAMETERS_WRAP", - KotlinBundle.message("formatter.title.function.declaration.parameters") - ) - consumer.renameStandardOption("CALL_PARAMETERS_WRAP", KotlinBundle.message("formatter.title.function.call.arguments")) - consumer.renameStandardOption("METHOD_CALL_CHAIN_WRAP", KotlinBundle.message("formatter.title.chained.function.calls")) - consumer.renameStandardOption("METHOD_ANNOTATION_WRAP", KotlinBundle.message("formatter.title.function.annotations")) - consumer.renameStandardOption( - CodeStyleSettingsCustomizable.WRAPPING_METHOD_PARENTHESES, - KotlinBundle.message("formatter.title.function.parentheses") - ) - - showCustomOption(KotlinCodeStyleSettings::ALLOW_TRAILING_COMMA, "Use trailing comma") - - showCustomOption( - KotlinCodeStyleSettings::ALIGN_IN_COLUMNS_CASE_BRANCH, - KotlinBundle.message("formatter.title.align.when.branches.in.columns"), - CodeStyleSettingsCustomizable.WRAPPING_SWITCH_STATEMENT - ) - - showCustomOption( - KotlinCodeStyleSettings::LBRACE_ON_NEXT_LINE, - KotlinBundle.message("formatter.title.put.left.brace.on.new.line"), - CodeStyleSettingsCustomizable.WRAPPING_BRACES - ) - - showCustomOption( - KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_PARAMETER_LISTS, - KotlinBundle.message("formatter.title.use.continuation.indent"), - CodeStyleSettingsCustomizable.WRAPPING_METHOD_PARAMETERS - ) - showCustomOption( - KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_ARGUMENT_LISTS, - KotlinBundle.message("formatter.title.use.continuation.indent"), - CodeStyleSettingsCustomizable.WRAPPING_METHOD_ARGUMENTS_WRAPPING - ) - showCustomOption( - KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_CHAINED_CALLS, - KotlinBundle.message("formatter.title.use.continuation.indent"), - CodeStyleSettingsCustomizable.WRAPPING_CALL_CHAIN - ) - showCustomOption( - KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_SUPERTYPE_LISTS, - KotlinBundle.message("formatter.title.use.continuation.indent"), - CodeStyleSettingsCustomizable.WRAPPING_EXTENDS_LIST - ) - - showCustomOption( - KotlinCodeStyleSettings::WRAP_EXPRESSION_BODY_FUNCTIONS, - KotlinBundle.message("formatter.title.expression.body.functions"), - options = *arrayOf( - CodeStyleSettingsCustomizable.WRAP_OPTIONS_FOR_SINGLETON, - CodeStyleSettingsCustomizable.WRAP_VALUES_FOR_SINGLETON - ) - ) - showCustomOption( - KotlinCodeStyleSettings::CONTINUATION_INDENT_FOR_EXPRESSION_BODIES, - KotlinBundle.message("formatter.title.use.continuation.indent"), - KotlinBundle.message("formatter.title.expression.body.functions") - ) - showCustomOption( - KotlinCodeStyleSettings::WRAP_ELVIS_EXPRESSIONS, - KotlinBundle.message("formatter.title.elvis.expressions"), - options = *arrayOf( - CodeStyleSettingsCustomizable.WRAP_OPTIONS_FOR_SINGLETON, - CodeStyleSettingsCustomizable.WRAP_VALUES_FOR_SINGLETON - ) - ) - showCustomOption( - KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_ELVIS, - title = KotlinBundle.message("formatter.title.use.continuation.indent"), - groupName = KotlinBundle.message("formatter.title.elvis.expressions") - ) - @Suppress("InvalidBundleOrProperty") - showCustomOption( - KotlinCodeStyleSettings::IF_RPAREN_ON_NEW_LINE, - ApplicationBundle.message("wrapping.rpar.on.new.line"), - CodeStyleSettingsCustomizable.WRAPPING_IF_STATEMENT - ) - showCustomOption( - KotlinCodeStyleSettings::CONTINUATION_INDENT_IN_IF_CONDITIONS, - KotlinBundle.message("formatter.title.use.continuation.indent.in.conditions"), - CodeStyleSettingsCustomizable.WRAPPING_IF_STATEMENT - ) - } - SettingsType.BLANK_LINES_SETTINGS -> { - consumer.showStandardOptions( - "KEEP_BLANK_LINES_IN_CODE", - "KEEP_BLANK_LINES_IN_DECLARATIONS", - "KEEP_BLANK_LINES_BEFORE_RBRACE", - "BLANK_LINES_AFTER_CLASS_HEADER" - ) - showCustomOption( - KotlinCodeStyleSettings::BLANK_LINES_AROUND_BLOCK_WHEN_BRANCHES, - KotlinBundle.message("formatter.title.around.when.branches.with"), - CodeStyleSettingsCustomizable.BLANK_LINES - ) - } - SettingsType.COMMENTER_SETTINGS -> { - consumer.showAllStandardOptions() - } - else -> consumer.showStandardOptions() - } - } - - override fun getIndentOptionsEditor(): IndentOptionsEditor = SmartIndentOptionsEditor() - - override fun getDefaultCommonSettings(): CommonCodeStyleSettings { - return KotlinCommonCodeStyleSettings().apply { - initIndentOptions() - } - } -} \ No newline at end of file +} diff --git a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinSaveStylePanel.kt b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinSaveStylePanel.kt index 3d3e8bcfa37..eefcc968687 100644 --- a/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinSaveStylePanel.kt +++ b/idea/src/org/jetbrains/kotlin/idea/formatter/KotlinSaveStylePanel.kt @@ -16,13 +16,14 @@ import com.intellij.ui.components.panels.VerticalLayout import com.intellij.util.ui.JBUI import com.intellij.util.ui.UIUtil import org.jetbrains.kotlin.idea.KotlinBundle +import org.jetbrains.kotlin.idea.KotlinLanguage import java.awt.BorderLayout import javax.swing.BorderFactory import javax.swing.JLabel import javax.swing.JList import javax.swing.JPanel -class KotlinSaveStylePanel(settings: CodeStyleSettings) : CodeStyleAbstractPanel(settings) { +class KotlinSaveStylePanel(settings: CodeStyleSettings) : CodeStyleAbstractPanel(KotlinLanguage.INSTANCE, null, settings) { override fun getRightMargin() = throw UnsupportedOperationException() override fun createHighlighter(scheme: EditorColorsScheme) = throw UnsupportedOperationException() override fun getFileType() = throw UnsupportedOperationException()