Minor changes on code review

This commit is contained in:
Valentin Kipyatkov
2015-04-30 18:45:31 +03:00
parent d1afff1612
commit 73f764abd0
6 changed files with 12 additions and 14 deletions
@@ -1 +1 @@
val result = ... ?: return
val result = ... <spot>?: return</spot>
@@ -1,2 +1,2 @@
val result = ...
if (result == null) return
<spot>if (result == null) return</spot>
@@ -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<JetFunctionLiteral>(true) ?: return null
val expression = element.getParentOfType<JetSimpleNameExpression>(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<JetFunctionLiteral>(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())
}
}
@@ -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
@@ -36,6 +36,7 @@ public class ToInfixCallIntention : JetSelfTargetingIntention<JetCallExpression>
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
@@ -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]
}