From 0542ef30e3d4c53b359b5a34da9ba3fdd1e8535c Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 14 Oct 2015 17:49:51 +0300 Subject: [PATCH] Converted to Kotlin --- .../ChangeFunctionLiteralSignatureFix.java | 92 ------------------- .../ChangeFunctionLiteralSignatureFix.kt | 61 ++++++++++++ 2 files changed, 61 insertions(+), 92 deletions(-) delete mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionLiteralSignatureFix.java create mode 100644 idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionLiteralSignatureFix.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionLiteralSignatureFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionLiteralSignatureFix.java deleted file mode 100644 index 310c0a9f387..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionLiteralSignatureFix.java +++ /dev/null @@ -1,92 +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.quickfix; - -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import kotlin.Unit; -import kotlin.jvm.functions.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.descriptors.FunctionDescriptor; -import org.jetbrains.kotlin.idea.JetBundle; -import org.jetbrains.kotlin.idea.caches.resolve.ResolutionUtils; -import org.jetbrains.kotlin.idea.core.CollectingNameValidator; -import org.jetbrains.kotlin.idea.core.KotlinNameSuggester; -import org.jetbrains.kotlin.idea.refactoring.changeSignature.*; -import org.jetbrains.kotlin.psi.JetFile; -import org.jetbrains.kotlin.psi.JetFunctionLiteral; -import org.jetbrains.kotlin.resolve.BindingContext; -import org.jetbrains.kotlin.types.JetType; - -import java.util.Collection; -import java.util.List; - -public class ChangeFunctionLiteralSignatureFix extends ChangeFunctionSignatureFix { - private final List parameterTypes; - - public ChangeFunctionLiteralSignatureFix( - @NotNull JetFunctionLiteral functionLiteral, - @NotNull FunctionDescriptor functionDescriptor, - @NotNull List parameterTypes) { - super(functionLiteral, functionDescriptor); - this.parameterTypes = parameterTypes; - } - - @NotNull - @Override - public String getText() { - return JetBundle.message("change.function.literal.signature"); - } - - @Override - protected void invoke(@NotNull Project project, Editor editor, JetFile file) { - JetChangeSignatureKt.runChangeSignature(project, getFunctionDescriptor(), new JetChangeSignatureConfiguration() { - @NotNull - @Override - public JetMethodDescriptor configure(@NotNull JetMethodDescriptor originalDescriptor) { - return JetChangeSignatureKt.modify( - originalDescriptor, - new Function1() { - @Override - public Unit invoke(JetMutableMethodDescriptor descriptor) { - CollectingNameValidator validator = new CollectingNameValidator(); - descriptor.clearNonReceiverParameters(); - for (JetType type : parameterTypes) { - String name = KotlinNameSuggester.INSTANCE$.suggestNamesByType(type, validator, "param").get(0); - descriptor.addParameter( - new JetParameterInfo(getFunctionDescriptor(), -1, name, type, null, null, JetValVar.None, null) - ); - } - return null; - } - } - ); - } - - @Override - public boolean performSilently(@NotNull Collection elements) { - return false; - } - - @Override - public boolean forcePerformForSelectedFunctionOnly() { - return false; - } - }, getContext(), getText()); - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionLiteralSignatureFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionLiteralSignatureFix.kt new file mode 100644 index 00000000000..d2e53c0031f --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeFunctionLiteralSignatureFix.kt @@ -0,0 +1,61 @@ +/* + * 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.quickfix + +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.idea.JetBundle +import org.jetbrains.kotlin.idea.core.CollectingNameValidator +import org.jetbrains.kotlin.idea.core.KotlinNameSuggester +import org.jetbrains.kotlin.idea.refactoring.changeSignature.* +import org.jetbrains.kotlin.psi.JetFile +import org.jetbrains.kotlin.psi.JetFunctionLiteral +import org.jetbrains.kotlin.types.JetType + +class ChangeFunctionLiteralSignatureFix( + functionLiteral: JetFunctionLiteral, + functionDescriptor: FunctionDescriptor, + private val parameterTypes: List +) : ChangeFunctionSignatureFix(functionLiteral, functionDescriptor) { + + override fun getText() = JetBundle.message("change.function.literal.signature") + + override fun invoke(project: Project, editor: Editor?, file: JetFile) { + runChangeSignature( + project, + functionDescriptor, + object : JetChangeSignatureConfiguration { + override fun configure(originalDescriptor: JetMethodDescriptor): JetMethodDescriptor { + return originalDescriptor.modify { descriptor -> + val validator = CollectingNameValidator() + descriptor.clearNonReceiverParameters() + for (type in parameterTypes) { + val name = KotlinNameSuggester.suggestNamesByType(type, validator, "param").get(0) + descriptor.addParameter(JetParameterInfo(functionDescriptor, -1, name, type, null, null, JetValVar.None, null)) + } + } + } + + override fun performSilently(affectedFunctions: Collection) = false + override fun forcePerformForSelectedFunctionOnly() = false + }, + context, + text) + } +}