From 1cb3af902c8f2e3f73e7c78781373f1ab5788772 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Mon, 13 Oct 2014 20:14:45 +0400 Subject: Remove BindingContext and migrate to ResolveSession, discover symbols for {code ...} directive. --- src/Analysis/AnalysisEnvironment.kt | 37 ++++++++++++++----------------------- src/Analysis/CommentsAPI.kt | 4 ++-- src/Analysis/CompilerAPI.kt | 4 +--- 3 files changed, 17 insertions(+), 28 deletions(-) (limited to 'src/Analysis') diff --git a/src/Analysis/AnalysisEnvironment.kt b/src/Analysis/AnalysisEnvironment.kt index 90231b84..3c7f6767 100644 --- a/src/Analysis/AnalysisEnvironment.kt +++ b/src/Analysis/AnalysisEnvironment.kt @@ -11,6 +11,7 @@ import org.jetbrains.jet.cli.common.* import org.jetbrains.jet.cli.jvm.* import com.intellij.openapi.util.* import org.jetbrains.jet.lang.descriptors.ModuleDescriptor +import org.jetbrains.jet.lang.resolve.lazy.ResolveSession /** * Kotlin as a service entry point @@ -30,28 +31,28 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A * Executes [processor] when analysis is complete. * $processor is a function to receive compiler environment, module and context for symbol resolution */ - public fun withContext(processor: (JetCoreEnvironment, ModuleDescriptor, BindingContext) -> T): T { + public fun withContext(processor: (JetCoreEnvironment, ResolveSession) -> T): T { val environment = JetCoreEnvironment.createForProduction(this, configuration) val resolveSession = environment.analyze() resolveSession.forceResolveAll() - return processor(environment, resolveSession.getModuleDescriptor(), resolveSession.getBindingContext()) + return processor(environment, resolveSession) } /** * Executes [processor] when analysis is complete. * $processor is a function to receive compiler module and context for symbol resolution */ - public fun withContext(processor: (ModuleDescriptor, BindingContext) -> T): T { - return withContext { environment, module, context -> processor(module, context) } + public fun withContext(processor: (ResolveSession) -> T): T { + return withContext { environment, session -> processor(session) } } /** * Streams files into [processor] and returns a stream of its results * $processor is a function to receive context for symbol resolution and file for processing */ - public fun streamFiles(processor: (BindingContext, JetFile) -> T): Stream { - return withContext { environment, module, context -> - environment.getSourceFiles().stream().map { file -> processor(context, file) } + public fun streamFiles(processor: (ResolveSession, JetFile) -> T): Stream { + return withContext { environment, session -> + environment.getSourceFiles().stream().map { file -> processor(session, file) } } } @@ -59,19 +60,9 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A * Runs [processor] for each file and collects its results into single list * $processor is a function to receive context for symbol resolution and file for processing */ - public fun processFiles(processor: (BindingContext, JetFile) -> T): List { - return withContext { environment, module, context -> - environment.getSourceFiles().map { file -> processor(context, file) } - } - } - - /** - * Runs [processor] for each file and collects its results into single list - * $processor is a function to receive context for symbol resolution, module and file for processing - */ - public fun processFiles(processor: (BindingContext, ModuleDescriptor, JetFile) -> T): List { - return withContext { environment, module, context -> - environment.getSourceFiles().map { file -> processor(context, module, file) } + public fun processFiles(processor: (ResolveSession, JetFile) -> T): List { + return withContext { environment, session -> + environment.getSourceFiles().map { file -> processor(session, file) } } } @@ -79,9 +70,9 @@ public class AnalysisEnvironment(val messageCollector: MessageCollector, body: A * Runs [processor] for each file and collects its results into single list * $processor is a function to receive context for symbol resolution and file for processing */ - public fun processFilesFlat(processor: (BindingContext, JetFile) -> List): List { - return withContext { environment, module, context -> - environment.getSourceFiles().flatMap { file -> processor(context, file) } + public fun processFilesFlat(processor: (ResolveSession, JetFile) -> List): List { + return withContext { environment, session -> + environment.getSourceFiles().flatMap { file -> processor(session, file) } } } diff --git a/src/Analysis/CommentsAPI.kt b/src/Analysis/CommentsAPI.kt index a17b6aa4..2407de76 100644 --- a/src/Analysis/CommentsAPI.kt +++ b/src/Analysis/CommentsAPI.kt @@ -5,8 +5,8 @@ import org.jetbrains.jet.lang.resolve.* import org.jetbrains.jet.kdoc.psi.api.* import org.jetbrains.jet.lang.psi.* -fun BindingContext.getDocumentationElements(descriptor: DeclarationDescriptor): List { - val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) +fun DeclarationDescriptor.getDocumentationElements(): List { + val psiElement = DescriptorToSourceUtils.descriptorToDeclaration(this) if (psiElement == null) return listOf() diff --git a/src/Analysis/CompilerAPI.kt b/src/Analysis/CompilerAPI.kt index 43d0304e..8216c549 100644 --- a/src/Analysis/CompilerAPI.kt +++ b/src/Analysis/CompilerAPI.kt @@ -46,8 +46,6 @@ fun JetCoreEnvironment.analyze(): ResolveSession { return resolverForProject.resolverForModule(module).lazyResolveSession } -fun BindingContext.getPackageFragment(file: JetFile): PackageFragmentDescriptor? = get(BindingContext.FILE_TO_PACKAGE_FRAGMENT, file) - fun DeclarationDescriptor.isUserCode() = when (this) { is PackageViewDescriptor -> false @@ -122,7 +120,7 @@ public fun getPropertyInnerScope(outerScope: JetScope, descriptor: PropertyDescr return propertyScope } -fun BindingContext.getResolutionScope(descriptor: DeclarationDescriptor): JetScope { +fun getResolutionScope(descriptor: DeclarationDescriptor): JetScope { when (descriptor) { is PackageFragmentDescriptor -> return getPackageInnerScope(descriptor) -- cgit