diff --git a/idea/resources/intentionDescriptions/IfNullToElvisIntention/after.kt.template b/idea/resources/intentionDescriptions/IfNullToElvisIntention/after.kt.template index 0bd54fa1404..0ec5679d0ac 100644 --- a/idea/resources/intentionDescriptions/IfNullToElvisIntention/after.kt.template +++ b/idea/resources/intentionDescriptions/IfNullToElvisIntention/after.kt.template @@ -1 +1 @@ -val result = ... ?: return +val result = ... ?: return diff --git a/idea/resources/intentionDescriptions/IfNullToElvisIntention/before.kt.template b/idea/resources/intentionDescriptions/IfNullToElvisIntention/before.kt.template index 8b869ce9222..7fd7d70efd1 100644 --- a/idea/resources/intentionDescriptions/IfNullToElvisIntention/before.kt.template +++ b/idea/resources/intentionDescriptions/IfNullToElvisIntention/before.kt.template @@ -1,2 +1,2 @@ val result = ... -if (result == null) return +if (result == null) return diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt index b0d58479bc3..265fcf05a1a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceExplicitFunctionLiteralParamWithItIntention.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project +import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.codeStyle.CodeStyleManager import com.intellij.refactoring.rename.RenameProcessor @@ -27,7 +28,6 @@ import org.jetbrains.kotlin.descriptors.ParameterDescriptor import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.references.JetReference -import org.jetbrains.kotlin.psi.JetFile import org.jetbrains.kotlin.psi.JetFunctionLiteral import org.jetbrains.kotlin.psi.JetSimpleNameExpression import org.jetbrains.kotlin.psi.psiUtil.getParentOfType @@ -54,8 +54,6 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa } private fun targetFunctionLiteral(element: PsiElement, caretOffset: Int): JetFunctionLiteral? { - val innermostFunctionLiteral = element.getParentOfType(true) ?: return null - val expression = element.getParentOfType(true) if (expression != null) { val reference = expression.getReference() as JetReference? @@ -64,10 +62,10 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa return DescriptorToSourceUtils.descriptorToDeclaration(functionDescriptor) as? JetFunctionLiteral } - val arrow = innermostFunctionLiteral.getArrowNode() ?: return null + val functionLiteral = element.getParentOfType(true) ?: return null + val arrow = functionLiteral.getArrowNode() ?: return null if (caretOffset > arrow.getTextRange().getEndOffset()) return null - - return innermostFunctionLiteral + return functionLiteral } private class ParamRenamingProcessor( @@ -89,10 +87,9 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa editor.getCaretModel().moveToOffset(functionLiteral.getBodyExpression()!!.getTextOffset()) } - val range = functionLiteral.getTextRange() - CodeStyleManager.getInstance(functionLiteral.getProject()).reformatText(functionLiteral.getContainingFile(), - range.getStartOffset(), - range.getEndOffset()) + val project = functionLiteral.getProject() + PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument()) + CodeStyleManager.getInstance(project).adjustLineIndent(functionLiteral.getContainingFile(), functionLiteral.getTextRange()) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceItWithExplicitFunctionLiteralParamIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceItWithExplicitFunctionLiteralParamIntention.kt index 6fdcc82b4e7..4357f170fcd 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceItWithExplicitFunctionLiteralParamIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ReplaceItWithExplicitFunctionLiteralParamIntention.kt @@ -43,7 +43,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : JetSelfTarge override fun applyTo(element: JetSimpleNameExpression, editor: Editor) { val reference = element.getReference() as JetReference - val target = reference.resolveToDescriptors(element.analyze()).first() + val target = reference.resolveToDescriptors(element.analyze()).single() val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(target.getContainingDeclaration()!!) as JetFunctionLiteral diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt index 9043294289f..dd70ce5f567 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ToInfixCallIntention.kt @@ -36,6 +36,7 @@ public class ToInfixCallIntention : JetSelfTargetingIntention if (argument.isNamed()) return false if (argument.getArgumentExpression() == null) return false + // check that receiver has type to filter out calls with package/java class qualifier val receiver = dotQualified.getReceiverExpression() if (element.analyze().getType(receiver) == null) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt index bcebdedfba8..00d1baa9a14 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt @@ -56,6 +56,6 @@ fun isAutoCreatedItUsage(expression: JetSimpleNameExpression): Boolean { if (expression.getReferencedName() != "it") return false val context = expression.analyze() val reference = expression.getReference() as JetReference? - val target = reference?.resolveToDescriptors(context)?.firstOrNull() as? ValueParameterDescriptor? ?: return false + val target = reference?.resolveToDescriptors(context)?.singleOrNull() as? ValueParameterDescriptor? ?: return false return context[BindingContext.AUTO_CREATED_IT, target] }