blob: f4382bbbbf7bd6e882c9ae7dab5f58373dc8efeb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package org.jetbrains.dokka
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.analyzer.ModuleContent
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.container.get
import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.CompilerEnvironment
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
fun KotlinCoreEnvironment.analyze(): ResolveSession {
val projectContext = ProjectContext(project)
val sourceFiles = getSourceFiles()
val module = object : ModuleInfo {
override val name: Name = Name.special("<module>")
override fun dependencies(): List<ModuleInfo> = listOf(this)
}
val resolverForProject = JvmAnalyzerFacade.setupResolverForProject(
projectContext,
listOf(module),
{ ModuleContent(sourceFiles, GlobalSearchScope.allScope(project)) },
JvmPlatformParameters { module },
CompilerEnvironment,
packagePartProviderFactory = { module, content -> JvmPackagePartProvider(this) }
)
return resolverForProject.resolverForModule(module).componentProvider.get<ResolveSession>()
}
|