Add extension point to recognize library kind
This commit is contained in:
committed by
Mikhail Glukhikh
parent
08a66b61c2
commit
6b5dcf6ae7
+11
@@ -5,15 +5,26 @@
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.analyzer.common.CommonAnalyzerFacade
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.context.ProjectContext
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
|
||||
import org.jetbrains.kotlin.platform.impl.CommonIdePlatformKind
|
||||
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment
|
||||
|
||||
class CommonPlatformKindResolution : IdePlatformKindResolution {
|
||||
override fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean {
|
||||
return virtualFile.extension == MetadataPackageFragment.METADATA_FILE_EXTENSION
|
||||
}
|
||||
|
||||
override val libraryKind: PersistentLibraryKind<*>?
|
||||
get() = CommonLibraryKind
|
||||
|
||||
override val kind get() = CommonIdePlatformKind
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
|
||||
+7
-1
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.context.ProjectContext
|
||||
import org.jetbrains.kotlin.extensions.ApplicationExtensionDescriptor
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||
|
||||
@@ -30,6 +32,10 @@ interface IdePlatformKindResolution {
|
||||
|
||||
fun createBuiltIns(settings: PlatformAnalysisSettings, projectContext: ProjectContext): KotlinBuiltIns
|
||||
|
||||
fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean
|
||||
|
||||
val libraryKind: PersistentLibraryKind<*>?
|
||||
|
||||
companion object : ApplicationExtensionDescriptor<IdePlatformKindResolution>(
|
||||
"org.jetbrains.kotlin.idePlatformKindResolution", IdePlatformKindResolution::class.java
|
||||
) {
|
||||
|
||||
+10
@@ -5,15 +5,25 @@
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.context.ProjectContext
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.JsAnalyzerFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.PlatformAnalysisSettings
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.platform.impl.JsIdePlatformKind
|
||||
|
||||
class JsPlatformKindResolution : IdePlatformKindResolution {
|
||||
override fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean {
|
||||
return virtualFile.extension == "js" || virtualFile.extension == "kjsm"
|
||||
}
|
||||
|
||||
override val libraryKind: PersistentLibraryKind<*>?
|
||||
get() = JSLibraryKind
|
||||
|
||||
override val kind get() = JsIdePlatformKind
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
|
||||
+9
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.caches.resolve
|
||||
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.analyzer.ResolverForModuleFactory
|
||||
import org.jetbrains.kotlin.builtins.DefaultBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
@@ -15,6 +17,13 @@ import org.jetbrains.kotlin.platform.impl.JvmIdePlatformKind
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
|
||||
|
||||
class JvmPlatformKindResolution : IdePlatformKindResolution {
|
||||
override fun isLibraryFileForPlatform(virtualFile: VirtualFile): Boolean {
|
||||
return false // TODO: No library kind for JVM
|
||||
}
|
||||
|
||||
override val libraryKind: PersistentLibraryKind<*>?
|
||||
get() = null
|
||||
|
||||
override val kind get() = JvmIdePlatformKind
|
||||
|
||||
override val resolverForModuleFactory: ResolverForModuleFactory
|
||||
|
||||
@@ -24,30 +24,37 @@ import com.intellij.openapi.roots.libraries.Library
|
||||
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
|
||||
import com.intellij.openapi.util.io.JarUtil
|
||||
import com.intellij.openapi.vfs.*
|
||||
import org.jetbrains.kotlin.caches.resolve.IdePlatformKindResolution
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.KnownLibraryKindForIndex
|
||||
import org.jetbrains.kotlin.idea.vfilefinder.getLibraryKindForJar
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.serialization.deserialization.MetadataPackageFragment
|
||||
import org.jetbrains.kotlin.utils.PathUtil
|
||||
import java.util.jar.Attributes
|
||||
import java.util.regex.Pattern
|
||||
|
||||
interface KotlinLibraryKind
|
||||
interface KotlinLibraryKind {
|
||||
val compilerPlatform: TargetPlatform
|
||||
}
|
||||
|
||||
object JSLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.js"), KotlinLibraryKind {
|
||||
override val compilerPlatform: TargetPlatform
|
||||
get() = JsPlatform
|
||||
|
||||
override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!!
|
||||
}
|
||||
|
||||
object CommonLibraryKind : PersistentLibraryKind<DummyLibraryProperties>("kotlin.common"), KotlinLibraryKind {
|
||||
override val compilerPlatform: TargetPlatform
|
||||
get() = TargetPlatform.Common
|
||||
|
||||
override fun createDefaultProperties() = DummyLibraryProperties.INSTANCE!!
|
||||
}
|
||||
|
||||
val PersistentLibraryKind<*>?.platform: TargetPlatform
|
||||
get() = when (this) {
|
||||
JSLibraryKind -> JsPlatform
|
||||
CommonLibraryKind -> TargetPlatform.Common
|
||||
is KotlinLibraryKind -> this.compilerPlatform
|
||||
else -> JvmPlatform
|
||||
}
|
||||
|
||||
@@ -68,11 +75,10 @@ fun detectLibraryKind(roots: Array<VirtualFile>): PersistentLibraryKind<*>? {
|
||||
}
|
||||
}
|
||||
|
||||
return when (jarFile.extension) {
|
||||
"js", "kjsm" -> JSLibraryKind
|
||||
MetadataPackageFragment.METADATA_FILE_EXTENSION -> CommonLibraryKind
|
||||
else -> null
|
||||
}
|
||||
return IdePlatformKindResolution
|
||||
.getInstances()
|
||||
.firstOrNull { it.isLibraryFileForPlatform(jarFile) }
|
||||
?.libraryKind
|
||||
}
|
||||
|
||||
fun getLibraryJar(roots: Array<VirtualFile>, jarPattern: Pattern): VirtualFile? {
|
||||
|
||||
Reference in New Issue
Block a user