diff --git a/idea/performanceTests/test/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt b/idea/performanceTests/test/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt index c8173ce4dac..94fa6c8f5b9 100644 --- a/idea/performanceTests/test/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt +++ b/idea/performanceTests/test/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt @@ -25,7 +25,6 @@ import com.intellij.psi.impl.PsiDocumentManagerBase import com.intellij.testFramework.ExtensionTestUtil import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.ui.UIUtil -import org.jetbrains.kotlin.idea.codeInsight.hints.HintType import org.jetbrains.kotlin.idea.perf.util.logMessage import org.jetbrains.kotlin.idea.test.runPostStartupActivitiesOnce import java.nio.file.Paths @@ -61,9 +60,6 @@ fun saveDocument(document: Document) { } } -fun enableHints(enable: Boolean) = - HintType.values().forEach { it.option.set(enable) } - fun dispatchAllInvocationEvents() { runInEdtAndWait { UIUtil.dispatchAllInvocationEvents() diff --git a/idea/performanceTests/test/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.202 b/idea/performanceTests/test/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.202 index d40d0ee9315..367b68ab33e 100644 --- a/idea/performanceTests/test/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.202 +++ b/idea/performanceTests/test/org/jetbrains/kotlin/idea/testFramework/projectRoutines.kt.202 @@ -27,9 +27,7 @@ import com.intellij.psi.impl.PsiDocumentManagerBase import com.intellij.testFramework.ExtensionTestUtil import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.ui.UIUtil -import org.jetbrains.kotlin.idea.parameterInfo.HintType import org.jetbrains.kotlin.idea.perf.util.logMessage -import org.jetbrains.kotlin.idea.test.runPostStartupActivitiesOnce import java.nio.file.Paths fun commitAllDocuments() { @@ -63,9 +61,6 @@ fun saveDocument(document: Document) { } } -fun enableHints(enable: Boolean) = - HintType.values().forEach { it.option.set(enable) } - fun dispatchAllInvocationEvents() { runInEdtAndWait { UIUtil.dispatchAllInvocationEvents() diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/HintsCompat.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/HintsCompat.kt new file mode 100644 index 00000000000..4f03fa94b0d --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/HintsCompat.kt @@ -0,0 +1,72 @@ +/* + * 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. + */ + +@file:Suppress("UnstableApiUsage") + +package org.jetbrains.kotlin.idea.codeInsight.hints + +import com.intellij.codeInsight.hints.ChangeListener +import com.intellij.codeInsight.hints.ImmediateConfigurable +import com.intellij.codeInsight.hints.settings.InlayHintsConfigurable +import com.intellij.ui.layout.panel +import org.jetbrains.kotlin.idea.KotlinBundle +import javax.swing.JComponent + + +typealias CompatibleInlayHintsConfigurable = InlayHintsConfigurable + +fun createLambdaHintsImmediateConfigurable(settings: KotlinLambdasHintsProvider.Settings): ImmediateConfigurable { + return object : ImmediateConfigurable { + override fun createComponent(listener: ChangeListener): JComponent = panel {} + + override val mainCheckboxText: String = KotlinBundle.message("hints.settings.common.items") + + override val cases: List + get() = listOf( + ImmediateConfigurable.Case( + KotlinBundle.message("hints.settings.lambda.return"), + "hints.lambda.return", + settings::returnExpressions + ), + ImmediateConfigurable.Case( + KotlinBundle.message("hints.settings.lambda.receivers.parameters"), + "hints.lambda.receivers.parameters", + settings::implicitReceiversAndParams + ) + ) + } +} + +fun createTypeHintsImmediateConfigurable(settings: KotlinReferencesTypeHintsProvider.Settings): ImmediateConfigurable { + return object : ImmediateConfigurable { + override fun createComponent(listener: ChangeListener): JComponent = panel {} + + override val mainCheckboxText: String = KotlinBundle.message("hints.settings.common.items") + + override val cases: List + get() = listOf( + ImmediateConfigurable.Case( + KotlinBundle.message("hints.settings.types.property"), + "hints.type.property", + settings::propertyType + ), + ImmediateConfigurable.Case( + KotlinBundle.message("hints.settings.types.variable"), + "hints.type.variable", + settings::localVariableType + ), + ImmediateConfigurable.Case( + KotlinBundle.message("hints.settings.types.return"), + "hints.type.function.return", + settings::functionReturnType + ), + ImmediateConfigurable.Case( + KotlinBundle.message("hints.settings.types.parameter"), + "hints.type.function.parameter", + settings::parameterType + ), + ) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/HintsCompat.kt.192 b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/HintsCompat.kt.192 new file mode 100644 index 00000000000..642e0043f42 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/HintsCompat.kt.192 @@ -0,0 +1,73 @@ +/* + * 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.codeInsight.hints + +import com.intellij.codeInsight.hints.ChangeListener +import com.intellij.codeInsight.hints.ImmediateConfigurable +import com.intellij.codeInsight.hints.config.InlayHintsConfigurable +import com.intellij.ui.components.JBCheckBox +import com.intellij.ui.layout.panel +import org.jetbrains.kotlin.idea.KotlinBundle +import javax.swing.JComponent + + +typealias CompatibleInlayHintsConfigurable = InlayHintsConfigurable + +fun createLambdaHintsImmediateConfigurable(settings: KotlinLambdasHintsProvider.Settings): ImmediateConfigurable { + return object : ImmediateConfigurable { + + private val returnExprField = JBCheckBox(KotlinBundle.message("hints.settings.lambda.return"), settings.returnExpressions) + + private val receiversAndParamsField = JBCheckBox( + KotlinBundle.message("hints.settings.lambda.receivers.parameters"), + settings.implicitReceiversAndParams + ) + + override fun createComponent(listener: ChangeListener): JComponent { + returnExprField.isSelected = settings.returnExpressions + returnExprField.addActionListener { settings.returnExpressions = returnExprField.isSelected } + + receiversAndParamsField.isSelected = settings.implicitReceiversAndParams + receiversAndParamsField.addActionListener { settings.implicitReceiversAndParams = receiversAndParamsField.isSelected } + + return panel { + row { returnExprField(pushX) } + row { receiversAndParamsField(pushX) } + } + } + } +} + +fun createTypeHintsImmediateConfigurable(settings: KotlinReferencesTypeHintsProvider.Settings): ImmediateConfigurable { + return object : ImmediateConfigurable { + + private val propertyTypeField = JBCheckBox(KotlinBundle.message("hints.settings.types.property"), settings.propertyType) + private val variableTypeField = JBCheckBox(KotlinBundle.message("hints.settings.types.variable"), settings.localVariableType) + private val funReturnTypeField = JBCheckBox(KotlinBundle.message("hints.settings.types.return"), settings.functionReturnType) + private val paramTypeField = JBCheckBox(KotlinBundle.message("hints.settings.types.parameter"), settings.parameterType) + + override fun createComponent(listener: ChangeListener): JComponent { + propertyTypeField.isSelected = settings.propertyType + propertyTypeField.addActionListener { settings.propertyType = propertyTypeField.isSelected } + + variableTypeField.isSelected = settings.localVariableType + variableTypeField.addActionListener { settings.localVariableType = variableTypeField.isSelected } + + funReturnTypeField.isSelected = settings.functionReturnType + funReturnTypeField.addActionListener { settings.functionReturnType = funReturnTypeField.isSelected } + + paramTypeField.isSelected = settings.parameterType + paramTypeField.addActionListener { settings.parameterType = paramTypeField.isSelected } + + return panel { + row { propertyTypeField(pushX) } + row { variableTypeField(pushX) } + row { funReturnTypeField(pushX) } + row { paramTypeField(pushX) } + } + } + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinLambdasHintsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinLambdasHintsProvider.kt index 8b9b5c9fe72..0db01dbca73 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinLambdasHintsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinLambdasHintsProvider.kt @@ -5,17 +5,12 @@ package org.jetbrains.kotlin.idea.codeInsight.hints -import com.intellij.codeInsight.hints.ChangeListener import com.intellij.codeInsight.hints.ImmediateConfigurable import com.intellij.codeInsight.hints.InlayHintsSink import com.intellij.codeInsight.hints.presentation.PresentationRenderer -import com.intellij.openapi.application.TransactionGuard -import com.intellij.openapi.application.invokeLater import com.intellij.openapi.editor.Editor -import com.intellij.ui.layout.panel -import com.sun.glass.ui.Application import org.jetbrains.kotlin.idea.KotlinBundle -import javax.swing.JComponent +import org.jetbrains.kotlin.idea.util.application.invokeLater /** * Please note that the executable test class is currently not generated. The thing is that [KotlinLambdasHintsProvider] utilizes a hack @@ -61,25 +56,7 @@ class KotlinLambdasHintsProvider : KotlinAbstractHintsProvider - get() = listOf( - ImmediateConfigurable.Case( - KotlinBundle.message("hints.settings.lambda.return"), - "hints.lambda.return", - settings::returnExpressions - ), - ImmediateConfigurable.Case( - KotlinBundle.message("hints.settings.lambda.receivers.parameters"), - "hints.lambda.receivers.parameters", - settings::implicitReceiversAndParams - ) - ) - } + return createLambdaHintsImmediateConfigurable(settings) } override fun createSettings(): Settings = Settings() diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferencesTypeHintsProvider.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferencesTypeHintsProvider.kt index 53ec870ade0..38774517bec 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferencesTypeHintsProvider.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferencesTypeHintsProvider.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.idea.codeInsight.hints import com.intellij.codeInsight.hints.ChangeListener import com.intellij.codeInsight.hints.ImmediateConfigurable +import com.intellij.ui.components.JBCheckBox import com.intellij.ui.layout.panel import org.jetbrains.kotlin.idea.KotlinBundle import javax.swing.JComponent @@ -24,35 +25,7 @@ class KotlinReferencesTypeHintsProvider : KotlinAbstractHintsProvider - get() = listOf( - ImmediateConfigurable.Case( - KotlinBundle.message("hints.settings.types.property"), - "hints.type.property", - settings::propertyType - ), - ImmediateConfigurable.Case( - KotlinBundle.message("hints.settings.types.variable"), - "hints.type.variable", - settings::localVariableType - ), - ImmediateConfigurable.Case( - KotlinBundle.message("hints.settings.types.return"), - "hints.type.function.return", - settings::functionReturnType - ), - ImmediateConfigurable.Case( - KotlinBundle.message("hints.settings.types.parameter"), - "hints.type.function.parameter", - settings::parameterType - ), - ) - } + return createTypeHintsImmediateConfigurable(settings) } override fun createSettings(): Settings = Settings() diff --git a/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/ShowInlayHintsSettings.kt b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/ShowInlayHintsSettings.kt index 6165e874793..c5c2c340b4c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/ShowInlayHintsSettings.kt +++ b/idea/src/org/jetbrains/kotlin/idea/codeInsight/hints/ShowInlayHintsSettings.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.idea.codeInsight.hints -import com.intellij.codeInsight.hints.settings.InlayHintsConfigurable import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys @@ -14,7 +13,7 @@ class ShowInlayHintsSettings : AnAction("Hints Settings...") { override fun actionPerformed(e: AnActionEvent) { val file = CommonDataKeys.PSI_FILE.getData(e.dataContext) ?: return val fileLanguage = file.language - InlayHintsConfigurable.showSettingsDialogForLanguage( + CompatibleInlayHintsConfigurable.showSettingsDialogForLanguage( file.project, fileLanguage ) diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinLambdasHintsProviderTest.kt.192 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinLambdasHintsProviderTest.kt.192 new file mode 100644 index 00000000000..bd95a065cae --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinLambdasHintsProviderTest.kt.192 @@ -0,0 +1,6 @@ +/* + * 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.codeInsight.hints \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinReferenceTypeHintsProviderTest.kt.192 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinReferenceTypeHintsProviderTest.kt.192 new file mode 100644 index 00000000000..bd95a065cae --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/AbstractKotlinReferenceTypeHintsProviderTest.kt.192 @@ -0,0 +1,6 @@ +/* + * 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.codeInsight.hints \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferenceTypeHintsProviderTestGenerated.java.192 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferenceTypeHintsProviderTestGenerated.java.192 new file mode 100644 index 00000000000..9c764ffd2c2 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/hints/KotlinReferenceTypeHintsProviderTestGenerated.java.192 @@ -0,0 +1,6 @@ +/* + * 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.codeInsight.hints; \ No newline at end of file