From d37727185ea96c697a7ba709cb0087131164b20c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 28 Aug 2014 17:24:42 +0400 Subject: [PATCH] Fix IDEA plugin behavior with classes in library sources In case when some class was contained in sources of some library (in addition to classes of some library) we incorrectly assumed that its ModuleInfo is LibrarySourceInfo of that library, because we checked if the file was in library sources first. Now we check if the file is in library _classes_ first, and then sources #KT-5695 Fixed --- .../jet/plugin/caches/resolve/getModuleInfo.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 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 c1f80ffa2ef..28b02be3240 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 @@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightElement import org.jetbrains.jet.lang.psi.* import com.intellij.openapi.roots.ProjectFileIndex -import com.intellij.openapi.roots.LibraryOrSdkOrderEntry import com.intellij.openapi.roots.LibraryOrderEntry import com.intellij.openapi.roots.JdkOrderEntry import org.jetbrains.jet.asJava.FakeLightClassForFileOfPackage @@ -70,20 +69,19 @@ private fun getModuleInfoByVirtualFile(project: Project, virtualFile: VirtualFil val orderEntries = projectFileIndex.getOrderEntriesForFile(virtualFile) - val libraryOrSdkEntries = orderEntries.filterIsInstance(javaClass()) - @entries for (libraryOrSdkOrderEntry in libraryOrSdkEntries) { - when (libraryOrSdkOrderEntry) { + @entries for (orderEntry in orderEntries) { + when (orderEntry) { is LibraryOrderEntry -> { - val library = libraryOrSdkOrderEntry.getLibrary() ?: continue @entries - if (projectFileIndex.isInLibrarySource(virtualFile)) { - return LibrarySourceInfo(project, library) - } - else { + val library = orderEntry.getLibrary() ?: continue @entries + if (projectFileIndex.isInLibraryClasses(virtualFile)) { return LibraryInfo(project, library) } + else if (projectFileIndex.isInLibrarySource(virtualFile)) { + return LibrarySourceInfo(project, library) + } } is JdkOrderEntry -> { - val sdk = libraryOrSdkOrderEntry.getJdk() ?: continue @entries + val sdk = orderEntry.getJdk() ?: continue @entries return SdkInfo(project, sdk) } }