Commit 0a145a17 authored by Ilya Kirillov's avatar Ilya Kirillov Committed by intellij-monorepo-bot
Browse files

[kotlin] changes usages of hardcoded "it" parameter to StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME

GitOrigin-RevId: c33aafb26a5264d11793452d92ebb28d6ce9cf70
parent c5403965
Showing with 51 additions and 31 deletions
+51 -31
......@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.Modality
......@@ -286,7 +287,7 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() {
type.isArrayOrPrimitiveArray() -> {
val canUseArrayContentFunctions = targetClass.canUseArrayContentFunctions()
val shouldWrapInLet = isNullable && !canUseArrayContentFunctions
val hashCodeArg = if (shouldWrapInLet) "it" else ref
val hashCodeArg = if (shouldWrapInLet) StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier else ref
val hashCodeCall = generateArrayHashCodeCall(type, canUseArrayContentFunctions, hashCodeArg)
if (shouldWrapInLet) "$ref?.let { $hashCodeCall }" else hashCodeCall
}
......
......@@ -6,6 +6,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.SmartPsiElementPointer
import org.jetbrains.kotlin.analysis.api.KtAnalysisSession
import org.jetbrains.kotlin.analysis.api.symbols.KtFunctionSymbol
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.AbstractKotlinApplicableIntentionWithContext
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.KotlinApplicabilityRange
......@@ -164,7 +165,7 @@ internal class ConvertForEachToForLoopIntention
} else {
factory.createExpressionByPattern(
"for($0 in $1){ $2 }",
parameters.singleOrNull() ?: "it",
parameters.singleOrNull() ?: StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier,
loopRange,
body.allChildren
)
......
......@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.markers.KtNamedSymbol
import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.KotlinIcons
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.kdoc.*
......@@ -83,7 +84,7 @@ internal class KotlinDocumentationTarget(val element: PsiElement, private val or
private fun computeLocalDocumentation(element: PsiElement, originalElement: PsiElement?, quickNavigation: Boolean): String? {
when {
element is KtFunctionLiteral -> {
val itElement = findElementWithText(originalElement, "it")
val itElement = findElementWithText(originalElement, StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier)
val itReference = itElement?.getParentOfType<KtNameReferenceExpression>(false)
if (itReference != null) {
return buildString {
......
......@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.analysis.api.calls.*
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KtFirDiagnostic
import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol
import org.jetbrains.kotlin.analysis.api.symbols.receiverType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.KotlinApplicator
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.KotlinApplicatorInput
......@@ -76,7 +77,7 @@ object WrapWithSafeLetCallFixFactories {
fun getNewExpression(nullableExpressionText: String, expressionUnderLetText: String): KtExpression {
return when (suggestedVariableName) {
"it" -> psiFactory.createExpressionByPattern("$0?.let { $1 }", nullableExpressionText, expressionUnderLetText)
StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier -> psiFactory.createExpressionByPattern("$0?.let { $1 }", nullableExpressionText, expressionUnderLetText)
else -> psiFactory.createExpressionByPattern(
"$0?.let { $1 -> $2 }",
nullableExpressionText,
......@@ -211,7 +212,7 @@ object WrapWithSafeLetCallFixFactories {
// Note, the order of the candidate matters. We would prefer the default `it` so the generated code won't need to declare the
// variable explicitly.
val candidateNames = listOfNotNull("it", getDeclaredParameterNameForArgument(nullableExpression))
val candidateNames = listOfNotNull(StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier, getDeclaredParameterNameForArgument(nullableExpression))
val suggestedName = FirKotlinNameSuggester.suggestNameByMultipleNames(candidateNames) { it !in existingNames }
return listOf(
KotlinApplicatorBasedQuickFix(
......
......@@ -28,6 +28,7 @@ import com.intellij.util.io.HttpRequests
import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.asJava.elements.KtLightDeclaration
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.base.util.KotlinPlatformUtils
......@@ -337,7 +338,7 @@ class KotlinDocumentationProvider : AbstractDocumentationProvider(), ExternalDoc
@Nls
private fun getTextImpl(element: PsiElement, originalElement: PsiElement?, quickNavigation: Boolean): String? {
if (element is PsiWhiteSpace) {
val itElement = findElementWithText(originalElement, "it")
val itElement = findElementWithText(originalElement, StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier)
val itReference = itElement?.getParentOfType<KtNameReferenceExpression>(false)
if (itReference != null) {
return getTextImpl(itReference, originalElement, quickNavigation)
......@@ -377,7 +378,7 @@ class KotlinDocumentationProvider : AbstractDocumentationProvider(), ExternalDoc
}
} else if (element is KtDeclaration) {
return renderKotlinDeclaration(element, quickNavigation)
} else if (element is KtNameReferenceExpression && element.getReferencedName() == "it") {
} else if (element is KtNameReferenceExpression && element.getReferencedNameAsName() == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME) {
return renderKotlinImplicitLambdaParameter(element, quickNavigation)
} else if (element is KtLightDeclaration<*, *>) {
val origin = element.kotlinOrigin ?: return null
......
......@@ -10,6 +10,7 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiNameIdentifierOwner
import com.intellij.util.IncorrectOperationException
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.config.ApiVersion
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.ClassDescriptor
......@@ -267,7 +268,7 @@ class KotlinGenerateEqualsAndHashcodeAction : KotlinGenerateMemberActionBase<Kot
KotlinBuiltIns.isArrayOrPrimitiveArray(type) -> {
val canUseArrayContentFunctions = targetClass.canUseArrayContentFunctions()
val shouldWrapInLet = isNullable && !canUseArrayContentFunctions
val hashCodeArg = if (shouldWrapInLet) "it" else ref
val hashCodeArg = if (shouldWrapInLet) StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier else ref
val hashCodeCall = generateArrayHashCodeCall(this, canUseArrayContentFunctions, hashCodeArg)
if (shouldWrapInLet) "$ref?.let { $hashCodeCall }" else hashCodeCall
}
......
......@@ -3,6 +3,7 @@
package org.jetbrains.kotlin.idea.codeInliner
import com.intellij.psi.util.elementType
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.diagnostics.Errors
......@@ -225,7 +226,7 @@ class CodeToInlineBuilder(
last = KtFunctionLiteral::class
)
val hasUnresolvedItOrThis = factory == Errors.UNRESOLVED_REFERENCE &&
element.text == "it" &&
element.text == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier &&
element.getStrictParentOfType<KtFunctionLiteral>() == functionLiteral
hasCantInferParameter || hasUnresolvedItOrThis
......
......@@ -2,6 +2,7 @@
package org.jetbrains.kotlin.idea.codeInliner
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.idea.base.fe10.codeInsight.newDeclaration.Fe10KotlinNameSuggester
import org.jetbrains.kotlin.idea.caches.resolve.computeTypeInContext
......@@ -94,8 +95,8 @@ internal fun MutableCodeToInline.introduceValue(
statementsBefore.add(0, value)
}
} else {
val useIt = !isNameUsed("it")
val name = if (useIt) Name.identifier("it") else suggestName { !isNameUsed(it) }
val useIt = !isNameUsed(StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier)
val name = if (useIt) StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME else suggestName { !isNameUsed(it) }
replaceUsages(name)
mainExpression = psiFactory.buildExpression {
......
......@@ -6,6 +6,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.usages.similarity.bag.Bag
import com.intellij.usages.similarity.features.UsageSimilarityFeaturesRecorder
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.psi.*
class KotlinSimilarityFeaturesExtractor(element: PsiElement, private val context: PsiElement) : KtTreeVisitorVoid() {
......@@ -127,7 +128,7 @@ class KotlinSimilarityFeaturesExtractor(element: PsiElement, private val context
private fun collectFunctionParametersNames(function: KtFunction) {
if (function is KtFunctionLiteral) {
variableNames += "it"
variableNames += StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier
}
for (valueParameter in function.valueParameters) {
......
......@@ -8,6 +8,7 @@ import com.intellij.openapi.editor.colors.TextAttributesKey
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors.*
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.search.ideaExtensions.FE10KotlinTargetElementEvaluator
......@@ -47,7 +48,7 @@ class KotlinRainbowVisitor : RainbowVisitor() {
if (targetElement.isRainbowDeclaration()) {
addRainbowHighlight(targetElement, element)
}
} else if (element.getReferencedName() == "it") {
} else if (element.getReferencedNameAsName() == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME) {
val itTargetElement =
KOTLIN_TARGET_ELEMENT_EVALUATOR.getElementByReference(reference, TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED)
......
......@@ -6,6 +6,7 @@ import com.intellij.codeInspection.*
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElementVisitor
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
......@@ -46,7 +47,7 @@ class NestedLambdaShadowedImplicitParameterInspection : AbstractKotlinInspection
if (qualifiedExpression != null) {
val receiver = qualifiedExpression.receiverExpression
val call = qualifiedExpression.callExpression
if (receiver.text == "it" && call?.isCalling(scopeFunctions, context) == true) return
if (receiver.text == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier && call?.isCalling(scopeFunctions, context) == true) return
}
val containingFile = lambda.containingFile
......@@ -74,7 +75,7 @@ class NestedLambdaShadowedImplicitParameterInspection : AbstractKotlinInspection
val lambda = implicitParameterReference.getStrictParentOfType<KtLambdaExpression>() ?: return
val parentLambda = lambda.getParentImplicitParameterLambda() ?: return
val parameter = parentLambda.functionLiteral.getOrCreateParameterList().addParameterBefore(
KtPsiFactory(project).createLambdaParameterList("it").parameters.first(), null
KtPsiFactory(project).createLambdaParameterList(StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier).parameters.first(), null
)
val editor = parentLambda.findExistingEditor() ?: return
PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(editor.document)
......@@ -103,7 +104,7 @@ private fun KtNameReferenceExpression.isImplicitParameterReference(
implicitParameter: ValueParameterDescriptor,
context: BindingContext
): Boolean {
return text == "it"
return text == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier
&& getStrictParentOfType<KtLambdaExpression>() == lambda
&& getResolvedCall(context)?.resultingDescriptor == implicitParameter
}
\ No newline at end of file
......@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.psi.psiUtil.startOffset
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
import org.jetbrains.kotlin.builtins.StandardNames
class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
......@@ -32,7 +33,7 @@ class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
val parameters = functionLiteral.valueParameters
val singleParameter = parameters.singleOrNull()
if (singleParameter?.typeReference != null) return
if (parameters.isNotEmpty() && singleParameter?.name != "it") {
if (parameters.isNotEmpty() && singleParameter?.nameAsName != StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME) {
return
}
......@@ -42,7 +43,7 @@ class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
val callExpression = lambdaExpression.parent?.parent as? KtCallExpression
if (callExpression != null) {
val callee = callExpression.calleeExpression as? KtNameReferenceExpression
if (callee != null && callee.getReferencedName() == "forEach" && singleParameter?.name != "it") return
if (callee != null && callee.getReferencedName() == "forEach" && singleParameter?.nameAsName != StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME) return
}
val lambdaContext = lambdaExpression.analyze()
......@@ -55,7 +56,7 @@ class RedundantLambdaArrowInspection : AbstractKotlinInspection() {
val functionLiteralDescriptor = functionLiteral.descriptor
if (functionLiteralDescriptor != null) {
if (functionLiteral.anyDescendantOfType<KtNameReferenceExpression> {
it.text == "it" && it.resolveToCall()?.resultingDescriptor?.containingDeclaration != functionLiteralDescriptor
it.text == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier && it.resolveToCall()?.resultingDescriptor?.containingDeclaration != functionLiteralDescriptor
}) return
}
......
......@@ -6,6 +6,7 @@ import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.idea.base.psi.isMultiLine
......@@ -227,7 +228,7 @@ private fun KtDotQualifiedExpression.hasLambdaExpression() = selectorExpression?
private fun KtLambdaExpression.getParameterName(): String? {
val parameters = valueParameters
if (parameters.size > 1) return null
return if (parameters.size == 1) parameters[0].text else "it"
return if (parameters.size == 1) parameters[0].text else StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier
}
private fun KtExpression.nameUsed(name: String, except: KtNameReferenceExpression? = null): Boolean =
......
......@@ -9,6 +9,7 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.SmartPsiElementPointer
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
......@@ -188,7 +189,7 @@ class ConvertScopeFunctionToParameter(counterpartName: String) : ConvertScopeFun
val lambdaExtensionReceiver = lambdaDescriptor.extensionReceiverParameter
val lambdaDispatchReceiver = lambdaDescriptor.dispatchReceiverParameter
var parameterName = "it"
var parameterName = StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier
val scopes = mutableSetOf<LexicalScope>()
if (functionLiteral != null && needUniqueNameForParameter(lambda, scopes)) {
val parameterType = lambdaExtensionReceiver?.type ?: lambdaDispatchReceiver?.type
......@@ -255,7 +256,7 @@ class ConvertScopeFunctionToParameter(counterpartName: String) : ConvertScopeFun
val resolutionScope = lambdaArgument.getResolutionScope()
scopes.add(resolutionScope)
var needUniqueName = false
if (resolutionScope.findVariable(Name.identifier("it"), NoLookupLocation.FROM_IDE) != null) {
if (resolutionScope.findVariable(StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME, NoLookupLocation.FROM_IDE) != null) {
needUniqueName = true
// Don't return here - we still need to gather the list of nested scopes
}
......@@ -274,7 +275,7 @@ class ConvertScopeFunctionToParameter(counterpartName: String) : ConvertScopeFun
private fun checkNeedUniqueName(dcl: KtElement) {
val nestedResolutionScope = dcl.getResolutionScope()
scopes.add(nestedResolutionScope)
if (nestedResolutionScope.findVariable(Name.identifier("it"), NoLookupLocation.FROM_IDE) != null) {
if (nestedResolutionScope.findVariable(StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME, NoLookupLocation.FROM_IDE) != null) {
needUniqueName = true
}
}
......@@ -310,7 +311,7 @@ class ConvertScopeFunctionToReceiver(counterpartName: String) : ConvertScopeFunc
lambda.accept(object : KtTreeVisitorVoid() {
override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) {
super.visitSimpleNameExpression(expression)
if (expression.getReferencedName() == "it") {
if (expression.getReferencedNameAsName() == StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME) {
val result = expression.resolveMainReferenceToDescriptors().singleOrNull()
if (result is ValueParameterDescriptor && result.containingDeclaration == lambdaDescriptor) {
replacements.add(expression) { createThisExpression() }
......
......@@ -7,6 +7,7 @@ import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
......@@ -133,10 +134,10 @@ class SimplifyNestedEachInScopeFunctionInspection : AbstractKotlinInspection() {
if (innerExpression !is KtDotQualifiedExpression) return
val receiverExpression = innerExpression.receiverExpression
if (receiverExpression !is KtReferenceExpression) return
val parameterName = lambdaExpression.valueParameters.singleOrNull()?.name ?: "it"
val parameterName = lambdaExpression.valueParameters.singleOrNull()?.name ?: StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier
if (!receiverExpression.textMatches(parameterName)) return
if (forEachLambda != null && (forEachLambda.valueParameters.singleOrNull()?.name ?: "it") == parameterName) {
if (forEachLambda != null && (forEachLambda.valueParameters.singleOrNull()?.name ?: StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier) == parameterName) {
null // Parameter from outer lambda is shadowed
} else {
val lambdaDescriptor = lambdaExpression.descriptor(context) ?: return
......
......@@ -10,6 +10,7 @@ import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.isArray
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.isPrimitiveArray
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
......@@ -143,7 +144,7 @@ private fun KtLambdaExpression.singleStatement(): KtExpression? = bodyExpression
private fun KtLambdaExpression.singleLambdaParameterName(): String? {
val lambdaParameters = valueParameters
return if (lambdaParameters.isNotEmpty()) lambdaParameters.singleOrNull()?.name else "it"
return if (lambdaParameters.isNotEmpty()) lambdaParameters.singleOrNull()?.name else StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier
}
private fun KtExpression.isNameReferenceTo(name: String): Boolean =
......
......@@ -8,6 +8,7 @@ import com.intellij.codeInspection.dataFlow.value.DfaVariableValue
import com.intellij.psi.PsiElement
import com.intellij.psi.util.CachedValuesManager
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
......@@ -151,7 +152,7 @@ class KtVariableDescriptor(val variable: KtCallableDeclaration) : JvmVariableDes
}
}
}
if (expr.textMatches("it")) {
if (expr.textMatches(StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier)) {
val descriptor = expr.resolveMainReferenceToDescriptors().singleOrNull()
if (descriptor is ValueParameterDescriptor) {
val fn = (descriptor.containingDeclaration.toSourceElement as? KotlinSourceElement)?.psi
......
......@@ -3,6 +3,7 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.codeinsight.api.classic.intentions.SelfTargetingOffsetIndependentIntention
......@@ -120,7 +121,7 @@ class ConvertForEachToForLoopIntention : SelfTargetingOffsetIndependentIntention
} else {
psiFactory.createExpressionByPattern(
"for($0 in $1){ $2 }",
parameters.singleOrNull() ?: "it",
parameters.singleOrNull() ?: StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier,
loopRange,
body.allChildren
)
......
......@@ -13,6 +13,7 @@ import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.searches.ReferencesSearch
import com.intellij.refactoring.util.RefactoringUIUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
......@@ -155,7 +156,7 @@ class ConvertFunctionTypeReceiverToParameterIntention : SelfTargetingRangeIntent
val lambdaParameterList = lambda.getOrCreateParameterList()
if (lambda.valueParameters.isEmpty() && lambdaDescriptor.valueParameters.isNotEmpty()) {
val parameterToAdd = psiFactory.createLambdaParameterList("it").parameters.first()
val parameterToAdd = psiFactory.createLambdaParameterList(StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier).parameters.first()
lambdaParameterList.addParameterBefore(parameterToAdd, lambdaParameterList.parameters.firstOrNull())
}
......
......@@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import com.intellij.psi.util.elementType
import org.jetbrains.kotlin.KtNodeTypes
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.StandardNames.KOTLIN_REFLECT_FQ_NAME
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
......@@ -110,7 +111,7 @@ class ConvertReferenceToLambdaIntention : SelfTargetingOffsetIndependentIntentio
val lambdaExpression = if (valueArgumentParent != null &&
lambdaParameterNamesAndTypes.size == 1 &&
receiverExpression?.text != "it"
receiverExpression?.text != StandardNames.IMPLICIT_LAMBDA_PARAMETER_NAME.identifier
) {
val body = if (acceptsReceiverAsParameter) {
if (targetDescriptor is PropertyDescriptor) "it.$targetName"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment