Add module dependencies to script module info
This commit is contained in:
@@ -17,12 +17,16 @@
|
||||
package org.jetbrains.kotlin.idea.caches.resolve
|
||||
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.module.impl.scopes.LibraryScopeBase
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.*
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryImpl
|
||||
import com.intellij.openapi.roots.libraries.Library
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
@@ -32,6 +36,7 @@ import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValuesManager
|
||||
import com.intellij.util.SmartList
|
||||
import com.intellij.util.io.URLUtil
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -207,7 +212,7 @@ private class ModuleTestSourceScope(module: Module) : ModuleSourceScope(module)
|
||||
override fun contains(file: VirtualFile) = moduleFileIndex.isInTestSourceContent(file)
|
||||
}
|
||||
|
||||
data class LibraryInfo(val project: Project, val library: Library) : IdeaModuleInfo {
|
||||
open class LibraryInfo(val project: Project, val library: Library) : IdeaModuleInfo {
|
||||
override val moduleOrigin: ModuleOrigin
|
||||
get() = ModuleOrigin.LIBRARY
|
||||
|
||||
@@ -231,6 +236,13 @@ data class LibraryInfo(val project: Project, val library: Library) : IdeaModuleI
|
||||
}
|
||||
|
||||
override fun toString() = "LibraryInfo(libraryName=${library.name})"
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
return (other is LibraryInfo && library == other.library)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = 43 * library.hashCode()
|
||||
}
|
||||
|
||||
internal data class LibrarySourceInfo(val project: Project, val library: Library) : IdeaModuleInfo {
|
||||
@@ -279,7 +291,7 @@ internal object NotUnderContentRootModuleInfo : IdeaModuleInfo {
|
||||
override fun dependencies(): List<IdeaModuleInfo> = listOf(this)
|
||||
}
|
||||
|
||||
internal data class CustomizedScriptModuleInfo(val project: Project, val virtualFile: VirtualFile, val scriptDefinition: KotlinScriptDefinition) : IdeaModuleInfo {
|
||||
internal data class CustomizedScriptModuleInfo(val project: Project, val module: Module?, val virtualFile: VirtualFile, val scriptDefinition: KotlinScriptDefinition) : IdeaModuleInfo {
|
||||
override val moduleOrigin: ModuleOrigin
|
||||
get() = ModuleOrigin.OTHER
|
||||
|
||||
@@ -298,7 +310,14 @@ internal data class CustomizedScriptModuleInfo(val project: Project, val virtual
|
||||
virtualFileManager.findFileByUrl("file://$it") ?: throw FileNotFoundException("Classpath entry points to a non-existent location: $it")
|
||||
}
|
||||
}
|
||||
override fun dependencies(): List<IdeaModuleInfo> = listOf(this)
|
||||
|
||||
override fun dependencies() =
|
||||
listOf(this) +
|
||||
(module?.cached(CachedValueProvider {
|
||||
CachedValueProvider.Result(
|
||||
ideaModelDependencies(module, productionOnly = false),
|
||||
ProjectRootModificationTracker.getInstance(module.project))
|
||||
}) ?: emptyList())
|
||||
}
|
||||
|
||||
private class FileLibraryScope(project: Project, private val libraryRoot: VirtualFile) : GlobalSearchScope(project) {
|
||||
@@ -318,15 +337,51 @@ private class FileLibraryScope(project: Project, private val libraryRoot: Virtua
|
||||
override fun hashCode() = libraryRoot.hashCode()
|
||||
}
|
||||
|
||||
private class FileLibraryModuleInfo(val project: Project, val libraryRoot: VirtualFile) :IdeaModuleInfo {
|
||||
private data class FakeFileLibrary(val libraryRoot: VirtualFile) : Library {
|
||||
override fun getFiles(rootType: OrderRootType): Array<out VirtualFile> = arrayOf(libraryRoot)
|
||||
|
||||
override fun getUrls(rootType: OrderRootType): Array<out String> = arrayOf(libraryRoot.url)
|
||||
|
||||
override fun getName(): String? = libraryRoot.name
|
||||
|
||||
override fun getModifiableModel(): Library.ModifiableModel { throw UnsupportedOperationException() }
|
||||
|
||||
override fun getTable(): LibraryTable? = null
|
||||
|
||||
override fun getRootProvider(): RootProvider { throw UnsupportedOperationException() }
|
||||
|
||||
override fun isJarDirectory(url: String): Boolean { throw UnsupportedOperationException() }
|
||||
|
||||
override fun isJarDirectory(url: String, rootType: OrderRootType): Boolean { throw UnsupportedOperationException() }
|
||||
|
||||
override fun isValid(url: String, rootType: OrderRootType): Boolean { throw UnsupportedOperationException() }
|
||||
|
||||
override fun readExternal(element: Element?) { throw UnsupportedOperationException() }
|
||||
|
||||
override fun writeExternal(element: Element?) { throw UnsupportedOperationException() }
|
||||
|
||||
override fun dispose() { }
|
||||
}
|
||||
|
||||
private class FileLibraryModuleInfo(project: Project, val libraryRoot: VirtualFile) : LibraryInfo(project, FakeFileLibrary(libraryRoot)) {
|
||||
|
||||
override val moduleOrigin: ModuleOrigin
|
||||
get() = ModuleOrigin.OTHER
|
||||
|
||||
override val name: Name = Name.special(libraryRoot.nameWithoutExtension)
|
||||
override val name: Name = Name.special("<$LIBRARY_NAME_PREFIX${libraryRoot.nameWithoutExtension}>")
|
||||
|
||||
override fun contentScope() = FileLibraryScope(project, libraryRoot)
|
||||
|
||||
override fun dependencies(): List<IdeaModuleInfo> = emptyList()
|
||||
|
||||
override fun toString() = "FileLibraryModuleInfo(root=${libraryRoot.name})"
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
return (other is FileLibraryModuleInfo && libraryRoot == other.libraryRoot)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = 47 * libraryRoot.hashCode()
|
||||
}
|
||||
|
||||
private class LibraryWithoutSourceScope(project: Project, private val library: Library) :
|
||||
|
||||
@@ -124,7 +124,7 @@ private fun getModuleInfoByVirtualFile(project: Project, virtualFile: VirtualFil
|
||||
|
||||
val scriptDefinition = KotlinScriptDefinitionProvider.getInstance(project).findScriptDefinition(virtualFile)
|
||||
if (scriptDefinition != null)
|
||||
return CustomizedScriptModuleInfo(project, virtualFile, scriptDefinition)
|
||||
return CustomizedScriptModuleInfo(project, module, virtualFile, scriptDefinition)
|
||||
|
||||
return NotUnderContentRootModuleInfo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user