Introduce TargetEnvironment and CompilerEnvironment

This commit is contained in:
Pavel V. Talanov
2015-07-24 18:38:24 +03:00
parent b3adf27b81
commit 2ef5e03f27
6 changed files with 71 additions and 10 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.load.java.JavaClassFinderImpl
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.BodyResolveCache
import org.jetbrains.kotlin.resolve.CompilerEnvironment
import org.jetbrains.kotlin.resolve.LazyTopDownAnalyzerForTopLevel
import org.jetbrains.kotlin.resolve.jvm.JavaClassFinderPostConstruct
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
@@ -44,7 +45,8 @@ public fun createContainerForReplWithJava(
useInstance(additionalFileScopeProvider)
useInstance(declarationProviderFactory)
useInstance(BodyResolveCache.ThrowException)
CompilerEnvironment.configure(this)
useImpl<FileScopeProviderImpl>()
useImpl<SingleModuleClassResolver>()
@@ -32,10 +32,7 @@ import org.jetbrains.kotlin.load.java.sam.SamConversionResolverImpl
import org.jetbrains.kotlin.load.java.structure.impl.JavaPropertyInitializerEvaluatorImpl
import org.jetbrains.kotlin.load.kotlin.DeserializationComponentsForJava
import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinderFactory
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.BodyResolveCache
import org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer
import org.jetbrains.kotlin.resolve.LazyTopDownAnalyzerForTopLevel
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.jvm.JavaClassFinderPostConstruct
import org.jetbrains.kotlin.resolve.jvm.JavaDescriptorResolver
import org.jetbrains.kotlin.resolve.jvm.JavaLazyAnalyzerPostConstruct
@@ -80,7 +77,9 @@ public fun createContainerForLazyResolveWithJava(
useInstance(moduleClassResolver)
useInstance(declarationProviderFactory)
useInstance(BodyResolveCache.ThrowException)
CompilerEnvironment.configure(this)
useImpl<FileScopeProviderImpl>()
useImpl<LazyResolveToken>()
}.let {
@@ -101,7 +100,8 @@ public fun createContainerForTopDownAnalyzerForJvm(
configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, lookupTracker)
useInstance(declarationProviderFactory)
useInstance(BodyResolveCache.ThrowException)
CompilerEnvironment.configure(this)
useImpl<SingleModuleClassResolver>()
useImpl<FileScopeProviderImpl>()
@@ -60,7 +60,9 @@ public fun createContainerForBodyResolve(
configureModule(moduleContext, platform, bindingTrace)
useInstance(statementFilter)
useInstance(BodyResolveCache.ThrowException)
CompilerEnvironment.configure(this)
useImpl<BodyResolver>()
}
@@ -90,7 +92,9 @@ public fun createContainerForLazyLocalClassifierAnalyzer(
useImpl<LazyTopDownAnalyzer>()
useInstance(NoTopLevelDescriptorProvider)
useInstance(BodyResolveCache.ThrowException)
CompilerEnvironment.configure(this)
useInstance(FileScopeProvider.ThrowException)
useImpl<DeclarationScopeProviderForLocalClassifierAnalyzer>()
@@ -0,0 +1,27 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.container.StorageComponentContainer
import org.jetbrains.kotlin.container.useImpl
import org.jetbrains.kotlin.container.useInstance
public object CompilerEnvironment : TargetEnvironment("Compiler") {
override fun configure(container: StorageComponentContainer) {
container.useInstance(BodyResolveCache.ThrowException)
}
}
@@ -0,0 +1,25 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.container.StorageComponentContainer
public abstract class TargetEnvironment(private val name: String) {
public abstract fun configure(container: StorageComponentContainer)
override fun toString() = name
}
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.js.resolve.JsPlatform
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.BodyResolveCache
import org.jetbrains.kotlin.resolve.CompilerEnvironment
import org.jetbrains.kotlin.resolve.LazyTopDownAnalyzerForTopLevel
import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
@@ -42,7 +43,9 @@ public fun createTopDownAnalyzerForJs(
useInstance(declarationProviderFactory)
useImpl<FileScopeProviderImpl>()
useInstance(BodyResolveCache.ThrowException)
CompilerEnvironment.configure(this)
useInstance(LookupTracker.DO_NOTHING)
useImpl<ResolveSession>()
useImpl<LazyTopDownAnalyzerForTopLevel>()