Simplify JavaClassFinderPostConstruct, inline javaAnalysisInit
This commit is contained in:
@@ -36,11 +36,10 @@ import org.jetbrains.kotlin.load.kotlin.DeserializationComponentsForJava
|
|||||||
import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinderFactory
|
import org.jetbrains.kotlin.load.kotlin.JvmVirtualFileFinderFactory
|
||||||
import org.jetbrains.kotlin.platform.JvmBuiltIns
|
import org.jetbrains.kotlin.platform.JvmBuiltIns
|
||||||
import org.jetbrains.kotlin.resolve.*
|
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.JavaDescriptorResolver
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JavaLazyAnalyzerPostConstruct
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||||
import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl
|
import org.jetbrains.kotlin.resolve.lazy.FileScopeProviderImpl
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||||
|
|
||||||
@@ -71,7 +70,6 @@ fun StorageComponentContainer.configureJavaTopDownAnalysis(
|
|||||||
useImpl<JavaPropertyInitializerEvaluatorImpl>()
|
useImpl<JavaPropertyInitializerEvaluatorImpl>()
|
||||||
useInstance(SamConversionResolverImpl)
|
useInstance(SamConversionResolverImpl)
|
||||||
useImpl<JavaSourceElementFactoryImpl>()
|
useImpl<JavaSourceElementFactoryImpl>()
|
||||||
useImpl<JavaLazyAnalyzerPostConstruct>()
|
|
||||||
useInstance(InternalFlexibleTypeTransformer)
|
useInstance(InternalFlexibleTypeTransformer)
|
||||||
|
|
||||||
useInstance(languageVersionSettings)
|
useInstance(languageVersionSettings)
|
||||||
@@ -102,7 +100,7 @@ fun createContainerForLazyResolveWithJava(
|
|||||||
useImpl<LazyResolveToken>()
|
useImpl<LazyResolveToken>()
|
||||||
}
|
}
|
||||||
}.apply {
|
}.apply {
|
||||||
javaAnalysisInit()
|
get<JavaClassFinderImpl>().initialize(bindingTrace, get<KotlinCodeAnalyzer>())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,13 +119,6 @@ fun createContainerForTopDownAnalyzerForJvm(
|
|||||||
initJvmBuiltInsForTopDownAnalysis(moduleContext.module, languageVersionSettings)
|
initJvmBuiltInsForTopDownAnalysis(moduleContext.module, languageVersionSettings)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun StorageComponentContainer.javaAnalysisInit() {
|
|
||||||
get<JavaClassFinderImpl>().initialize()
|
|
||||||
get<JavaClassFinderPostConstruct>().postCreate()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'initBuiltIns' body cannot be merged with 'javaAnalysisInit' because the latter is used in IDE,
|
|
||||||
// where built-ins instances are shared between modules and manual initialization is necessary (to avoid multiple initialization)
|
|
||||||
fun ComponentProvider.initJvmBuiltInsForTopDownAnalysis(module: ModuleDescriptor, languageVersionSettings: LanguageVersionSettings) {
|
fun ComponentProvider.initJvmBuiltInsForTopDownAnalysis(module: ModuleDescriptor, languageVersionSettings: LanguageVersionSettings) {
|
||||||
get<JvmBuiltIns>().initialize(module, languageVersionSettings.supportsFeature(LanguageFeature.AdditionalBuiltInsMembers))
|
get<JvmBuiltIns>().initialize(module, languageVersionSettings.supportsFeature(LanguageFeature.AdditionalBuiltInsMembers))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,8 +32,10 @@ import org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl;
|
|||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaPackageImpl;
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaPackageImpl;
|
||||||
import org.jetbrains.kotlin.name.ClassId;
|
import org.jetbrains.kotlin.name.ClassId;
|
||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JavaClassFinderPostConstruct;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade;
|
import org.jetbrains.kotlin.resolve.jvm.KotlinJavaPsiFacade;
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -42,7 +44,6 @@ import java.util.Set;
|
|||||||
public class JavaClassFinderImpl implements JavaClassFinder {
|
public class JavaClassFinderImpl implements JavaClassFinder {
|
||||||
private Project project;
|
private Project project;
|
||||||
private GlobalSearchScope baseScope;
|
private GlobalSearchScope baseScope;
|
||||||
|
|
||||||
private GlobalSearchScope javaSearchScope;
|
private GlobalSearchScope javaSearchScope;
|
||||||
private KotlinJavaPsiFacade javaFacade;
|
private KotlinJavaPsiFacade javaFacade;
|
||||||
|
|
||||||
@@ -56,11 +57,6 @@ public class JavaClassFinderImpl implements JavaClassFinder {
|
|||||||
this.baseScope = scope;
|
this.baseScope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
public void setComponentPostConstruct(@NotNull JavaClassFinderPostConstruct finderPostConstruct) {
|
|
||||||
// Only activate post create
|
|
||||||
}
|
|
||||||
|
|
||||||
public class FilterOutKotlinSourceFilesScope extends DelegatingGlobalSearchScope {
|
public class FilterOutKotlinSourceFilesScope extends DelegatingGlobalSearchScope {
|
||||||
public FilterOutKotlinSourceFilesScope(@NotNull GlobalSearchScope baseScope) {
|
public FilterOutKotlinSourceFilesScope(@NotNull GlobalSearchScope baseScope) {
|
||||||
super(baseScope);
|
super(baseScope);
|
||||||
@@ -90,9 +86,10 @@ public class JavaClassFinderImpl implements JavaClassFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void initialize() {
|
public void initialize(@NotNull BindingTrace trace, @NotNull KotlinCodeAnalyzer codeAnalyzer) {
|
||||||
javaSearchScope = new FilterOutKotlinSourceFilesScope(baseScope);
|
javaSearchScope = new FilterOutKotlinSourceFilesScope(baseScope);
|
||||||
javaFacade = KotlinJavaPsiFacade.getInstance(project);
|
javaFacade = KotlinJavaPsiFacade.getInstance(project);
|
||||||
|
CodeAnalyzerInitializer.Companion.getInstance(project).initialize(trace, codeAnalyzer.getModuleDescriptor(), codeAnalyzer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
-44
@@ -1,44 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.jvm
|
|
||||||
|
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.annotation.PostConstruct
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
|
||||||
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
|
|
||||||
|
|
||||||
open class JavaClassFinderPostConstruct {
|
|
||||||
@PostConstruct
|
|
||||||
open fun postCreate() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
class JavaLazyAnalyzerPostConstruct : JavaClassFinderPostConstruct() {
|
|
||||||
var project: Project? = null
|
|
||||||
@Inject set
|
|
||||||
|
|
||||||
var trace: BindingTrace? = null
|
|
||||||
@Inject set
|
|
||||||
|
|
||||||
var codeAnalyzer: KotlinCodeAnalyzer? = null
|
|
||||||
@Inject set
|
|
||||||
|
|
||||||
@PostConstruct override fun postCreate() {
|
|
||||||
CodeAnalyzerInitializer.getInstance(project!!).initialize(trace!!, codeAnalyzer!!.moduleDescriptor, codeAnalyzer!!)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user