From e5eaaed240c8d4beaf21c646c9b4b7ccbd418f70 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Wed, 8 Mar 2023 20:10:37 +0100 Subject: [PATCH] choose isMethodNameOneOf for the API The reason - it is less error-prone for clients. The code will likely resolve method ref twice, but the second one shall be fast due to caching (~0.0X% overhead). GitOrigin-RevId: ff7e689884406c0325ef0679767da81f39084b6a --- .../KotlinUFunctionCallExpression.kt | 2 +- .../kotlin/UastResolveApiFixtureTestBase.kt | 3 ++- .../uast/expressions/UCallExpression.kt | 19 +------------------ 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt b/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt index f53d49eb32b7..d5e8c999c3bc 100644 --- a/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt +++ b/plugins/kotlin/uast/uast-kotlin-base/src/org/jetbrains/uast/kotlin/expressions/KotlinUFunctionCallExpression.kt @@ -213,7 +213,7 @@ class KotlinUFunctionCallExpression( return false } - override fun methodNameCanBeOneOf(names: Collection): Boolean { + fun methodNameCanBeOneOf(names: Collection): Boolean { if (isMethodNameOneOfWithoutConsideringImportAliases(names)) return true val ktFile = sourcePsi.containingKtFile val aliasedNames = collectAliasedNamesForName(ktFile, names) diff --git a/plugins/kotlin/uast/uast-kotlin-base/test/org/jetbrains/uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt b/plugins/kotlin/uast/uast-kotlin-base/test/org/jetbrains/uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt index fa30cb294a98..425ab64621c2 100644 --- a/plugins/kotlin/uast/uast-kotlin-base/test/org/jetbrains/uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt +++ b/plugins/kotlin/uast/uast-kotlin-base/test/org/jetbrains/uast/test/common/kotlin/UastResolveApiFixtureTestBase.kt @@ -1381,7 +1381,8 @@ interface UastResolveApiFixtureTestBase : UastPluginSelection { "Call should be present in the test" } TestCase.assertTrue(call is KotlinUFunctionCallExpression) - TestCase.assertTrue("expected method name to be one of ${names}", call!!.methodNameCanBeOneOf(names)) + val ktCall = call as KotlinUFunctionCallExpression + TestCase.assertTrue("expected method name to be one of ${names}", ktCall.methodNameCanBeOneOf(names)) } } diff --git a/uast/uast-common/src/org/jetbrains/uast/expressions/UCallExpression.kt b/uast/uast-common/src/org/jetbrains/uast/expressions/UCallExpression.kt index 40e69517641e..1ff67996d7d1 100644 --- a/uast/uast-common/src/org/jetbrains/uast/expressions/UCallExpression.kt +++ b/uast/uast-common/src/org/jetbrains/uast/expressions/UCallExpression.kt @@ -116,9 +116,8 @@ interface UCallExpression : UExpression, UResolvable { /** * Tries to perform optimized name checking for cases when [methodName] requires reference resolution. * - * May perform some heavy resolution inside for some languages (e.g., for Kotlin). For a lightweight check (with weaker guaranties), see [methodNameCanBeOneOf]. + * May perform some heavy resolution inside for some languages (e.g., for Kotlin). * - * @see methodNameCanBeOneOf * @see methodName */ @ApiStatus.Experimental @@ -126,22 +125,6 @@ interface UCallExpression : UExpression, UResolvable { return names.contains(methodName ?: return false) } - /** - * Tries to check if the call can be resolved to some method with name from [names]. - * - * It may return false-positive results, so an additional resolution check is needed in the case of [methodNameCanBeOneOf] returns `true`. - * - * Usually do not perform heavy resolution at the cost of sacrificing accuracy (may return false-positive results). For an accurate version which may perform heavy resolve see [isMethodNameOneOf]. - * - * @param names list of method names we want to check it the call can be resolved to - * @return `false` if the call can definitely not be resolved to the method with name from [names]. Returns `true` if the call is resolved to the method with name from [names] or this is a false-positive result. - * @see isMethodNameOneOf - * @see methodName - */ - @ApiStatus.Experimental - fun methodNameCanBeOneOf(names: Collection): Boolean { - return isMethodNameOneOf(names) - } } @Deprecated("useless since IDEA 2019.2, because getArgumentForParameter moved to UCallExpression", ReplaceWith("UCallExpression"))