From 01804a8853d913038d9ed0ee8a38d6313c5d9505 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Wed, 10 Dec 2014 18:30:48 +0300 Subject: [PATCH] Use module file index in getModuleInfo to determine source/test module info Do not include files that are in content of module but are not in source content Do not log error in case there is compiled kotlin file in source content --- .../jet/plugin/caches/resolve/getModuleInfo.kt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/jet/plugin/caches/resolve/getModuleInfo.kt b/idea/idea-analysis/src/org/jetbrains/jet/plugin/caches/resolve/getModuleInfo.kt index 34e67a28dfd..7701b178a03 100644 --- a/idea/idea-analysis/src/org/jetbrains/jet/plugin/caches/resolve/getModuleInfo.kt +++ b/idea/idea-analysis/src/org/jetbrains/jet/plugin/caches/resolve/getModuleInfo.kt @@ -26,6 +26,7 @@ import org.jetbrains.jet.asJava.FakeLightClassForFileOfPackage import org.jetbrains.jet.asJava.KotlinLightClassForPackage import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile +import com.intellij.openapi.roots.ModuleRootManager fun PsiElement.getModuleInfo(): IdeaModuleInfo { fun logAndReturnDefault(message: String): IdeaModuleInfo { @@ -66,13 +67,19 @@ private fun getModuleInfoByVirtualFile(project: Project, virtualFile: VirtualFil val module = projectFileIndex.getModuleForFile(virtualFile) if (module != null) { - if (isDecompiledFile) { - LOG.error("Decompiled file for ${virtualFile.getCanonicalPath()} is in content of $module") + fun warnIfDecompiled() { + if (isDecompiledFile) { + LOG.warn("Decompiled file for ${virtualFile.getCanonicalPath()} is in content of $module") + } } - if (projectFileIndex.isInTestSourceContent(virtualFile)) { + + val moduleFileIndex = ModuleRootManager.getInstance(module).getFileIndex() + if (moduleFileIndex.isInTestSourceContent(virtualFile)) { + warnIfDecompiled() return module.testSourceInfo() } - else { + else if (moduleFileIndex.isInSourceContent(virtualFile)) { + warnIfDecompiled() return module.productionSourceInfo() } }