Don't use invalid entries (including disposed libraries) when crete module infos to avoid exceptions in the future (see #EA-81326)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2015 JetBrains s.r.o.
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -21,6 +21,7 @@ import com.intellij.openapi.module.impl.scopes.LibraryScopeBase
|
|||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.projectRoots.Sdk
|
import com.intellij.openapi.projectRoots.Sdk
|
||||||
import com.intellij.openapi.roots.*
|
import com.intellij.openapi.roots.*
|
||||||
|
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||||
import com.intellij.openapi.roots.libraries.Library
|
import com.intellij.openapi.roots.libraries.Library
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
import com.intellij.psi.search.GlobalSearchScope
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
@@ -78,6 +79,8 @@ interface IdeaModuleInfo : ModuleInfo {
|
|||||||
private fun orderEntryToModuleInfo(project: Project, orderEntry: OrderEntry, productionOnly: Boolean): List<IdeaModuleInfo> {
|
private fun orderEntryToModuleInfo(project: Project, orderEntry: OrderEntry, productionOnly: Boolean): List<IdeaModuleInfo> {
|
||||||
fun Module.toInfos() = if (productionOnly) listOf(productionSourceInfo()) else listOf(testSourceInfo(), productionSourceInfo())
|
fun Module.toInfos() = if (productionOnly) listOf(productionSourceInfo()) else listOf(testSourceInfo(), productionSourceInfo())
|
||||||
|
|
||||||
|
if (!orderEntry.isValid) return emptyList()
|
||||||
|
|
||||||
return when (orderEntry) {
|
return when (orderEntry) {
|
||||||
is ModuleSourceOrderEntry -> {
|
is ModuleSourceOrderEntry -> {
|
||||||
orderEntry.getOwnerModule().toInfos()
|
orderEntry.getOwnerModule().toInfos()
|
||||||
@@ -214,7 +217,7 @@ data class LibraryInfo(val project: Project, val library: Library) : IdeaModuleI
|
|||||||
val (libraries, sdks) = LibraryDependenciesCache(project).getLibrariesAndSdksUsedWith(library)
|
val (libraries, sdks) = LibraryDependenciesCache(project).getLibrariesAndSdksUsedWith(library)
|
||||||
|
|
||||||
sdks.mapTo(result) { SdkInfo(project, it) }
|
sdks.mapTo(result) { SdkInfo(project, it) }
|
||||||
libraries.mapTo(result) { LibraryInfo(project, it) }
|
libraries.filter { it is LibraryEx && !it.isDisposed }.mapTo(result) { LibraryInfo(project, it) }
|
||||||
|
|
||||||
return result.toList()
|
return result.toList()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,18 +16,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.caches.resolve
|
package org.jetbrains.kotlin.idea.caches.resolve
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.asJava.KtLightElement
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
|
||||||
import com.intellij.openapi.roots.ProjectFileIndex
|
|
||||||
import com.intellij.openapi.roots.LibraryOrderEntry
|
|
||||||
import com.intellij.openapi.roots.JdkOrderEntry
|
import com.intellij.openapi.roots.JdkOrderEntry
|
||||||
|
import com.intellij.openapi.roots.LibraryOrderEntry
|
||||||
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
|
import com.intellij.openapi.roots.ProjectFileIndex
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.asJava.FakeLightClassForFileOfPackage
|
import org.jetbrains.kotlin.asJava.FakeLightClassForFileOfPackage
|
||||||
import org.jetbrains.kotlin.asJava.KtLightClassForFacade
|
import org.jetbrains.kotlin.asJava.KtLightClassForFacade
|
||||||
import com.intellij.openapi.project.Project
|
import org.jetbrains.kotlin.asJava.KtLightElement
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
|
||||||
import com.intellij.openapi.roots.ModuleRootManager
|
|
||||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
|
||||||
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
import org.jetbrains.kotlin.utils.sure
|
import org.jetbrains.kotlin.utils.sure
|
||||||
|
|
||||||
@@ -102,6 +102,8 @@ private fun getModuleInfoByVirtualFile(project: Project, virtualFile: VirtualFil
|
|||||||
val orderEntries = projectFileIndex.getOrderEntriesForFile(virtualFile)
|
val orderEntries = projectFileIndex.getOrderEntriesForFile(virtualFile)
|
||||||
|
|
||||||
entries@ for (orderEntry in orderEntries) {
|
entries@ for (orderEntry in orderEntries) {
|
||||||
|
if (!orderEntry.isValid) continue@entries
|
||||||
|
|
||||||
when (orderEntry) {
|
when (orderEntry) {
|
||||||
is LibraryOrderEntry -> {
|
is LibraryOrderEntry -> {
|
||||||
val library = orderEntry.library ?: continue@entries
|
val library = orderEntry.library ?: continue@entries
|
||||||
|
|||||||
Reference in New Issue
Block a user