diff options
author | Dmitry Jemerov <yole@jetbrains.com> | 2015-11-04 14:09:53 +0100 |
---|---|---|
committer | Dmitry Jemerov <yole@jetbrains.com> | 2015-11-04 14:09:53 +0100 |
commit | 3655b706ea22ab9d7ee02a8d5074aa583e848018 (patch) | |
tree | 461aa43e4dc1aa31b02b0bfd4ecfeeb23351a88f /src/Analysis/AnalysisEnvironment.kt | |
parent | 21dcc4a472f88dd3ce1a1e7d8406905552896d3c (diff) | |
download | dokka-3655b706ea22ab9d7ee02a8d5074aa583e848018.tar.gz dokka-3655b706ea22ab9d7ee02a8d5074aa583e848018.tar.bz2 dokka-3655b706ea22ab9d7ee02a8d5074aa583e848018.zip |
streamline setup code
Diffstat (limited to 'src/Analysis/AnalysisEnvironment.kt')
-rw-r--r-- | src/Analysis/AnalysisEnvironment.kt | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/Analysis/AnalysisEnvironment.kt b/src/Analysis/AnalysisEnvironment.kt index af9859d6..11bd7ac4 100644 --- a/src/Analysis/AnalysisEnvironment.kt +++ b/src/Analysis/AnalysisEnvironment.kt @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.config.ContentRoot import org.jetbrains.kotlin.config.KotlinSourceRoot -import org.jetbrains.kotlin.container.get import org.jetbrains.kotlin.container.getService import org.jetbrains.kotlin.context.ProjectContext import org.jetbrains.kotlin.descriptors.DeclarationDescriptor @@ -58,19 +57,14 @@ import java.io.File * $messageCollector: required by compiler infrastructure and will receive all compiler messages * $body: optional and can be used to configure environment without creating local variable */ -public class AnalysisEnvironment(val messageCollector: MessageCollector, body: AnalysisEnvironment.() -> Unit = {}) : Disposable { +public class AnalysisEnvironment(val messageCollector: MessageCollector) : Disposable { val configuration = CompilerConfiguration(); init { configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector) - body() } - /** - * Executes [processor] when analysis is complete. - * $processor: function to receive compiler environment, module and context for symbol resolution - */ - public fun <T> withContext(processor: (KotlinCoreEnvironment, ResolutionFacade, ResolveSession) -> T): T { + fun createCoreEnvironment(): KotlinCoreEnvironment { val environment = KotlinCoreEnvironment.createForProduction(this, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES) val projectComponentManager = environment.project as MockComponentManager @@ -98,7 +92,10 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A KotlinCacheService(environment.project)) projectComponentManager.registerService(KotlinOutOfBlockCompletionModificationTracker::class.java, KotlinOutOfBlockCompletionModificationTracker()) + return environment + } + fun createResolutionFacade(environment: KotlinCoreEnvironment): DokkaResolutionFacade { val projectContext = ProjectContext(environment.project) val sourceFiles = environment.getSourceFiles() @@ -116,9 +113,7 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A ) val resolverForModule = resolverForProject.resolverForModule(module) - val resolveSession = resolverForModule.componentProvider.get<ResolveSession>() - val facade = DokkaResolutionFacade(environment.project, resolverForProject.descriptorForModule(module), resolverForModule) - return processor(environment, facade, resolveSession) + return DokkaResolutionFacade(environment.project, resolverForProject.descriptorForModule(module), resolverForModule) } /** @@ -183,6 +178,8 @@ class DokkaResolutionFacade(override val project: Project, override val moduleDescriptor: ModuleDescriptor, val resolverForModule: ResolverForModule) : ResolutionFacade { + val resolveSession: ResolveSession get() = getFrontendService(ResolveSession::class.java) + override fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode): BindingContext { throw UnsupportedOperationException() } @@ -208,6 +205,6 @@ class DokkaResolutionFacade(override val project: Project, } override fun resolveToDescriptor(declaration: KtDeclaration): DeclarationDescriptor { - throw UnsupportedOperationException() + return resolveSession.resolveToDescriptor(declaration) } } |