Minor changes on code review
This commit is contained in:
@@ -1 +1 @@
|
|||||||
val result = ... ?: return
|
val result = ... <spot>?: return</spot>
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
val result = ...
|
val result = ...
|
||||||
if (result == null) return
|
<spot>if (result == null) return</spot>
|
||||||
|
|||||||
+7
-10
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
|
|||||||
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
|
import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
|
||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.codeStyle.CodeStyleManager
|
import com.intellij.psi.codeStyle.CodeStyleManager
|
||||||
import com.intellij.refactoring.rename.RenameProcessor
|
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.descriptors.impl.AnonymousFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.idea.references.JetReference
|
import org.jetbrains.kotlin.idea.references.JetReference
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
|
||||||
import org.jetbrains.kotlin.psi.JetFunctionLiteral
|
import org.jetbrains.kotlin.psi.JetFunctionLiteral
|
||||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
@@ -54,8 +54,6 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun targetFunctionLiteral(element: PsiElement, caretOffset: Int): JetFunctionLiteral? {
|
private fun targetFunctionLiteral(element: PsiElement, caretOffset: Int): JetFunctionLiteral? {
|
||||||
val innermostFunctionLiteral = element.getParentOfType<JetFunctionLiteral>(true) ?: return null
|
|
||||||
|
|
||||||
val expression = element.getParentOfType<JetSimpleNameExpression>(true)
|
val expression = element.getParentOfType<JetSimpleNameExpression>(true)
|
||||||
if (expression != null) {
|
if (expression != null) {
|
||||||
val reference = expression.getReference() as JetReference?
|
val reference = expression.getReference() as JetReference?
|
||||||
@@ -64,10 +62,10 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa
|
|||||||
return DescriptorToSourceUtils.descriptorToDeclaration(functionDescriptor) as? JetFunctionLiteral
|
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
|
if (caretOffset > arrow.getTextRange().getEndOffset()) return null
|
||||||
|
return functionLiteral
|
||||||
return innermostFunctionLiteral
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ParamRenamingProcessor(
|
private class ParamRenamingProcessor(
|
||||||
@@ -89,10 +87,9 @@ public class ReplaceExplicitFunctionLiteralParamWithItIntention() : PsiElementBa
|
|||||||
editor.getCaretModel().moveToOffset(functionLiteral.getBodyExpression()!!.getTextOffset())
|
editor.getCaretModel().moveToOffset(functionLiteral.getBodyExpression()!!.getTextOffset())
|
||||||
}
|
}
|
||||||
|
|
||||||
val range = functionLiteral.getTextRange()
|
val project = functionLiteral.getProject()
|
||||||
CodeStyleManager.getInstance(functionLiteral.getProject()).reformatText(functionLiteral.getContainingFile(),
|
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.getDocument())
|
||||||
range.getStartOffset(),
|
CodeStyleManager.getInstance(project).adjustLineIndent(functionLiteral.getContainingFile(), functionLiteral.getTextRange())
|
||||||
range.getEndOffset())
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : JetSelfTarge
|
|||||||
|
|
||||||
override fun applyTo(element: JetSimpleNameExpression, editor: Editor) {
|
override fun applyTo(element: JetSimpleNameExpression, editor: Editor) {
|
||||||
val reference = element.getReference() as JetReference
|
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
|
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(target.getContainingDeclaration()!!) as JetFunctionLiteral
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public class ToInfixCallIntention : JetSelfTargetingIntention<JetCallExpression>
|
|||||||
if (argument.isNamed()) return false
|
if (argument.isNamed()) return false
|
||||||
if (argument.getArgumentExpression() == null) 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()
|
val receiver = dotQualified.getReceiverExpression()
|
||||||
if (element.analyze().getType(receiver) == null) return false
|
if (element.analyze().getType(receiver) == null) return false
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,6 @@ fun isAutoCreatedItUsage(expression: JetSimpleNameExpression): Boolean {
|
|||||||
if (expression.getReferencedName() != "it") return false
|
if (expression.getReferencedName() != "it") return false
|
||||||
val context = expression.analyze()
|
val context = expression.analyze()
|
||||||
val reference = expression.getReference() as JetReference?
|
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]
|
return context[BindingContext.AUTO_CREATED_IT, target]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user