From 7bef560b6bd0afe188d9fe684a5ad3b50483b26c Mon Sep 17 00:00:00 2001 From: Bart van Helvert Date: Mon, 13 Jun 2022 12:12:43 +0200 Subject: [PATCH] KTIJ-21986 Don't log non-kotlin code fragment context when it's null This warning shouldn't be logged when the context is null. --- compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt index 645d6c3f1ea..4a8a97e3467 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtCodeFragment.kt @@ -83,8 +83,8 @@ abstract class KtCodeFragment( override fun getContext(): PsiElement? { if (fakeContextForJavaFile != null) return fakeContextForJavaFile - if (context !is KtElement) { - val logInfoForContextElement = (context as? PsiFile)?.virtualFile?.path ?: context?.getElementTextWithContext() + if (context != null && context !is KtElement) { + val logInfoForContextElement = (context as? PsiFile)?.virtualFile?.path ?: context.getElementTextWithContext() LOG.warn("CodeFragment with non-kotlin context should have fakeContextForJavaFile set: \noriginalContext = $logInfoForContextElement") return null }