mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[kotlin k2] Make getValueArgumentName works for KtLambdaArgument
^KTIJ-21135 GitOrigin-RevId: c20d3f4e922d3580ad42edb994795c24ea728a0a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
58fe1f3f9a
commit
fc497fabbc
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.analysis.api.types.*
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.FqNames
|
||||
import org.jetbrains.kotlin.idea.base.codeInsight.KotlinNameSuggester.Case.CAMEL
|
||||
import org.jetbrains.kotlin.idea.base.psi.getCallElement
|
||||
import org.jetbrains.kotlin.idea.base.psi.unquoteKotlinIdentifier
|
||||
import org.jetbrains.kotlin.lexer.KotlinLexer
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
@@ -25,9 +26,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getOutermostParenthesizerOrThis
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isIdentifier
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.util.capitalizeDecapitalize.*
|
||||
import org.jetbrains.kotlin.util.match
|
||||
|
||||
@DslMarker
|
||||
private annotation class NameSuggesterDsl
|
||||
@@ -174,14 +173,6 @@ class KotlinNameSuggester(
|
||||
return suggestNameByValidIdentifierName(parameter.name.asString(), validator)?.let { sequenceOf(it) } ?: emptySequence()
|
||||
}
|
||||
|
||||
private fun getCallElement(valueArgument: KtValueArgument): KtCallElement? {
|
||||
return if (valueArgument is KtLambdaArgument) {
|
||||
valueArgument.parent as? KtCallElement
|
||||
} else {
|
||||
valueArgument.parents.match(KtValueArgumentList::class, last = KtCallElement::class)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns names based on a given type.
|
||||
* Examples:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
@file:JvmName("KotlinPsiUtils")
|
||||
|
||||
@@ -17,10 +17,8 @@ import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isTopLevelInFileOrScript
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.util.match
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
val KtClassOrObject.classIdIfNonLocal: ClassId?
|
||||
@@ -238,4 +236,12 @@ fun KtExpression.unwrapIfLabeled(): KtExpression {
|
||||
while (true) {
|
||||
statement = statement.parent as? KtLabeledExpression ?: return statement
|
||||
}
|
||||
}
|
||||
|
||||
fun getCallElement(argument: KtValueArgument): KtCallElement? {
|
||||
return if (argument is KtLambdaArgument) {
|
||||
argument.parent as? KtCallElement
|
||||
} else {
|
||||
argument.parents.match(KtValueArgumentList::class, last = KtCallElement::class)
|
||||
}
|
||||
}
|
||||
@@ -9,15 +9,14 @@ import org.jetbrains.kotlin.analysis.api.calls.singleFunctionCallOrNull
|
||||
import org.jetbrains.kotlin.analysis.api.calls.symbol
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.idea.base.projectStructure.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.base.psi.getCallElement
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtCallElement
|
||||
import org.jetbrains.kotlin.psi.KtLambdaArgument
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtValueArgument
|
||||
import org.jetbrains.kotlin.psi.KtValueArgumentList
|
||||
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespace
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.util.match
|
||||
|
||||
object AddArgumentNamesUtils {
|
||||
fun addArgumentName(element: KtValueArgument, argumentName: Name) {
|
||||
@@ -83,9 +82,14 @@ object AddArgumentNamesUtils {
|
||||
.mapKeys { it.key.createSmartPointer() }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the value argument if it can be used for calls.
|
||||
* The method also works for [KtValueArgument] that is [KtLambdaArgument], since
|
||||
* the argument name can be used after moving [KtLambdaArgument] inside parentheses.
|
||||
*/
|
||||
context(KtAnalysisSession)
|
||||
fun KtValueArgument.getValueArgumentName(): Name? {
|
||||
val callElement = parents.match(KtValueArgumentList::class, last = KtCallElement::class) ?: return null
|
||||
val callElement = getCallElement(this) ?: return null
|
||||
val resolvedCall = callElement.resolveCall()?.singleFunctionCallOrNull() ?: return null
|
||||
if (!resolvedCall.symbol.hasStableParameterNames) return null
|
||||
return getArgumentNameIfCanBeUsedForCalls(this, resolvedCall)
|
||||
|
||||
Reference in New Issue
Block a user