making LambdaArgument methods nullable
overridden `LambdaArgument.getArgumentExpression` removed because it is already nullable in parent #EA-117013
This commit is contained in:
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.psi.psiUtil.canPlaceAfterSimpleNameEntry
|
||||
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
|
||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||
import java.util.*
|
||||
|
||||
internal abstract class ReplacementPerformer<TElement : KtElement>(
|
||||
@@ -210,7 +211,10 @@ internal class ExpressionReplacementPerformer(
|
||||
|
||||
val runExpression = psiFactory.createExpressionByPattern("run { $0 }", elementToBeReplaced) as KtCallExpression
|
||||
val runAfterReplacement = elementToBeReplaced.replaced(runExpression)
|
||||
val block = runAfterReplacement.lambdaArguments[0].getLambdaExpression().bodyExpression!!
|
||||
val ktLambdaArgument = runAfterReplacement.lambdaArguments[0]
|
||||
val block = ktLambdaArgument.getLambdaExpression()?.bodyExpression
|
||||
?: throw KotlinExceptionWithAttachments("cant get body expression for $ktLambdaArgument")
|
||||
.withAttachment("ktLambdaArgument", ktLambdaArgument.text)
|
||||
elementToBeReplaced = block.statements.single()
|
||||
return elementToBeReplaced
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ private fun UsageReplacementStrategy.specialUsageProcessing(usage: KtSimpleNameE
|
||||
val grandParent = usageParent.parent
|
||||
val specifySignature = SpecifyExplicitLambdaSignatureIntention()
|
||||
for (lambdaArgument in lambdaArguments) {
|
||||
val lambdaExpression = lambdaArgument.getLambdaExpression()
|
||||
val lambdaExpression = lambdaArgument.getLambdaExpression() ?: continue
|
||||
val functionDescriptor =
|
||||
lambdaExpression.functionLiteral.resolveToDescriptorIfAny() as? FunctionDescriptor ?: continue
|
||||
if (functionDescriptor.valueParameters.isNotEmpty()) {
|
||||
|
||||
+3
-1
@@ -217,7 +217,9 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
|
||||
List<KtLambdaArgument> functionLiterals = callExpression.getLambdaArguments();
|
||||
if (functionLiterals.isEmpty()) return null;
|
||||
|
||||
return functionLiterals.get(0).getLambdaExpression().getBodyExpression();
|
||||
KtLambdaExpression lambdaExpression = functionLiterals.get(0).getLambdaExpression();
|
||||
if (lambdaExpression == null) return null;
|
||||
return lambdaExpression.getBodyExpression();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -72,9 +72,9 @@ private fun getCounterpart(expression: KtCallExpression): String? {
|
||||
val callee = expression.calleeExpression as? KtNameReferenceExpression ?: return null
|
||||
val calleeName = callee.getReferencedName()
|
||||
val counterpartName = counterpartNames[calleeName]
|
||||
val lambdaArgument = expression.lambdaArguments.singleOrNull()
|
||||
if (counterpartName != null && lambdaArgument != null) {
|
||||
if (lambdaArgument.getLambdaExpression().valueParameters.isNotEmpty()) {
|
||||
val lambdaExpression = expression.lambdaArguments.singleOrNull()?.getLambdaExpression()
|
||||
if (counterpartName != null && lambdaExpression != null) {
|
||||
if (lambdaExpression.valueParameters.isNotEmpty()) {
|
||||
return null
|
||||
}
|
||||
val bindingContext = callee.analyze(BodyResolveMode.PARTIAL)
|
||||
@@ -151,7 +151,7 @@ abstract class ConvertScopeFunctionFix(private val counterpartName: String) : Lo
|
||||
val bindingContext = callExpression.analyze()
|
||||
|
||||
val lambda = callExpression.lambdaArguments.firstOrNull() ?: return
|
||||
val functionLiteral = lambda.getLambdaExpression().functionLiteral
|
||||
val functionLiteral = lambda.getLambdaExpression()?.functionLiteral ?: return
|
||||
val lambdaDescriptor = bindingContext[FUNCTION, functionLiteral] ?: return
|
||||
|
||||
val replacements = ReplacementCollection()
|
||||
@@ -186,13 +186,13 @@ class ConvertScopeFunctionToParameter(counterpartName: String) : ConvertScopeFun
|
||||
) {
|
||||
val project = lambda.project
|
||||
val factory = KtPsiFactory(project)
|
||||
val functionLiteral = lambda.getLambdaExpression().functionLiteral
|
||||
val functionLiteral = lambda.getLambdaExpression()?.functionLiteral
|
||||
val lambdaExtensionReceiver = lambdaDescriptor.extensionReceiverParameter
|
||||
val lambdaDispatchReceiver = lambdaDescriptor.dispatchReceiverParameter
|
||||
|
||||
var parameterName = "it"
|
||||
val scopes = mutableSetOf<LexicalScope>()
|
||||
if (needUniqueNameForParameter(lambda, scopes)) {
|
||||
if (functionLiteral != null && needUniqueNameForParameter(lambda, scopes)) {
|
||||
val parameterType = lambdaExtensionReceiver?.type ?: lambdaDispatchReceiver?.type
|
||||
parameterName = findUniqueParameterName(parameterType, scopes)
|
||||
replacements.createParameter = {
|
||||
|
||||
@@ -47,16 +47,16 @@ class SimplifyCallChainFix(val newName: String) : LocalQuickFix {
|
||||
val lastArgumentPrefix = if (newName.startsWith("joinTo")) "transform = " else ""
|
||||
val arguments = secondCallExpression.valueArgumentList?.arguments.orEmpty().map { it.text } +
|
||||
firstCallExpression.valueArgumentList?.arguments.orEmpty().map { "$lastArgumentPrefix${it.text}" }
|
||||
val lambdaArgument = firstCallExpression.lambdaArguments.singleOrNull()
|
||||
val lambdaExpression = firstCallExpression.lambdaArguments.singleOrNull()?.getLambdaExpression()
|
||||
|
||||
val argumentsText = arguments.ifNotEmpty { joinToString(prefix = "(", postfix = ")") } ?: ""
|
||||
val newQualifiedExpression = if (lambdaArgument != null) factory.createExpressionByPattern(
|
||||
"$0$1$2 $3 $4",
|
||||
receiverExpression ?: "",
|
||||
operationSign,
|
||||
newName,
|
||||
argumentsText,
|
||||
lambdaArgument.getLambdaExpression().text
|
||||
val newQualifiedExpression = if (lambdaExpression != null) factory.createExpressionByPattern(
|
||||
"$0$1$2 $3 $4",
|
||||
receiverExpression ?: "",
|
||||
operationSign,
|
||||
newName,
|
||||
argumentsText,
|
||||
lambdaExpression.text
|
||||
)
|
||||
else factory.createExpressionByPattern(
|
||||
"$0$1$2 $3",
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ class ConvertTryFinallyToUseCallIntention : SelfTargetingRangeIntention<KtTryExp
|
||||
else -> return
|
||||
}
|
||||
val lambda = call.lambdaArguments.firstOrNull() ?: return
|
||||
val lambdaParameter = lambda.getLambdaExpression().valueParameters.firstOrNull() ?: return
|
||||
val lambdaParameter = lambda.getLambdaExpression()?.valueParameters?.firstOrNull() ?: return
|
||||
editor?.selectionModel?.setSelection(lambdaParameter.startOffset, lambdaParameter.endOffset)
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -22,13 +22,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.core.moveInsideParentheses
|
||||
import org.jetbrains.kotlin.psi.KtLambdaArgument
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containsInside
|
||||
import org.jetbrains.kotlin.psi.unpackFunctionLiteral
|
||||
|
||||
class MoveLambdaInsideParenthesesIntention : SelfTargetingIntention<KtLambdaArgument>(
|
||||
KtLambdaArgument::class.java, "Move lambda argument into parentheses"
|
||||
), LowPriorityAction {
|
||||
override fun isApplicableTo(element: KtLambdaArgument, caretOffset: Int): Boolean {
|
||||
val body = element.getArgumentExpression().unpackFunctionLiteral()?.bodyExpression ?: return true
|
||||
val body = element.getLambdaExpression()?.bodyExpression ?: return true
|
||||
return !body.textRange.containsInside(caretOffset)
|
||||
}
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention<KtObjectLiter
|
||||
|
||||
val callee = replaced.getCalleeExpressionIfAny()!! as KtNameReferenceExpression
|
||||
val callExpression = callee.parent as KtCallExpression
|
||||
val functionLiteral = callExpression.lambdaArguments.single().getLambdaExpression()
|
||||
val functionLiteral = callExpression.lambdaArguments.single().getLambdaExpression()!!
|
||||
|
||||
val returnLabel = callee.getReferencedNameAsName()
|
||||
returnSaver.restore(functionLiteral, returnLabel)
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ abstract class WrapInWithReplacement : Replacement {
|
||||
val call = (e as? KtSimpleNameExpression)?.getQualifiedElement() ?: return e
|
||||
val replacingExpression = KtPsiFactory(e).createExpressionByPattern("with($0) { $1 }", argumentText, call)
|
||||
val replace = call.replace(replacingExpression)
|
||||
return (replace as KtCallExpression).lambdaArguments.first().getLambdaExpression().bodyExpression!!.statements.first()
|
||||
return (replace as KtCallExpression).lambdaArguments.first().getLambdaExpression()!!.bodyExpression!!.statements.first()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user