From 2b77f37dd5e06226f77d664a6a912af991513ca4 Mon Sep 17 00:00:00 2001 From: "Victoria.Petrakovich" Date: Thu, 10 Oct 2024 19:29:49 +0200 Subject: [PATCH] Revert "[kotlin] Remove useless check for `android` DSL" This reverts commit f5cde819c0f65fef7adaa3bf3197573796f7c2f4. GitOrigin-RevId: 8bc869641fbec3bc35171c1729e8a96cd3e0dd7d --- ...nsToCompilerOptionsInGradleScriptInspection.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/KotlinOptionsToCompilerOptionsInGradleScriptInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/KotlinOptionsToCompilerOptionsInGradleScriptInspection.kt index 09463c3966fe..138fe36d7e34 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/KotlinOptionsToCompilerOptionsInGradleScriptInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/KotlinOptionsToCompilerOptionsInGradleScriptInspection.kt @@ -61,6 +61,10 @@ internal class KotlinOptionsToCompilerOptionsInGradleScriptInspection : Abstract return object : KtVisitorVoid() { override fun visitReferenceExpression(expression: KtReferenceExpression) { val referencedName = (expression as? KtNameReferenceExpression)?.getReferencedName() ?: return + // ATM, we don't have proper dependencies for tests to perform `analyze` in Gradle build scripts + if (referencedName == "android" && !isUnitTestMode()) { + if (elementIsAndroidDsl(expression)) return + } if (referencedName != "kotlinOptions") return val expressionParent = expression.parent @@ -133,6 +137,17 @@ internal class KotlinOptionsToCompilerOptionsInGradleScriptInspection : Abstract } } + private fun elementIsAndroidDsl(expression: KtExpression): Boolean { + val importableFqName = analyze(expression) { + val symbol = expression.resolveToCall() + ?.successfulFunctionCallOrNull()?.partiallyAppliedSymbol?.signature?.symbol + val kaSymbol = + (symbol?.containingDeclaration as? KaClassLikeSymbol) ?: expression.resolveExpression() + kaSymbol?.importableFqName?.toString() + } + return importableFqName == "org.gradle.kotlin.dsl.android" + } + private fun expressionsContainForbiddenOperations(element: PsiElement): Boolean { if (element is KtBinaryExpression) { // for sth like `kotlinOptions.sourceMapEmbedSources = "inlining"` if (expressionContainsOperationForbiddenToReplace(element)) return true