From 10dfa05277c27ec4876e0f4e417a8689c3f4ba1e Mon Sep 17 00:00:00 2001 From: Nicolay Mitropolsky Date: Thu, 9 Nov 2017 11:09:48 +0100 Subject: [PATCH] Uast: `findPlugin` relies on `containingFile` first and uses workaround for KT-18054 --- uast/uast-common/src/org/jetbrains/uast/UastContext.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/uast/uast-common/src/org/jetbrains/uast/UastContext.kt b/uast/uast-common/src/org/jetbrains/uast/UastContext.kt index e59220ce4762..d999879eb0d2 100644 --- a/uast/uast-common/src/org/jetbrains/uast/UastContext.kt +++ b/uast/uast-common/src/org/jetbrains/uast/UastContext.kt @@ -42,7 +42,11 @@ class UastContext(val project: Project) : UastLanguagePlugin { get() = UastLanguagePlugin.getInstances() fun findPlugin(element: PsiElement): UastLanguagePlugin? { - val language = element.language + // we're searching for plugin for file because sometimes java elements are used in another languages (see Drools) + val containingFile = element.containingFile?.takeIf { + it !is PsiCompiledFile // Don't trust compiled files because of KT-18054 + } + val language = (containingFile ?: element).language return languagePlugins.firstOrNull { it.language == language } }