stubs for new components
This commit is contained in:
+1
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.context.ProjectContext
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.CompilerEnvironment
|
import org.jetbrains.kotlin.resolve.CompilerEnvironment
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.lazy
|
||||||
|
|
||||||
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.config.JvmClasspathRoot
|
||||||
|
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
||||||
|
|
||||||
|
public class JvmPackageMappingProvider(val env: KotlinCoreEnvironment) : PackageMappingProvider {
|
||||||
|
override fun findPackageMembers(packageName: String): List<String> {
|
||||||
|
val res = env.configuration.getList(CommonConfigurationKeys.CONTENT_ROOTS).
|
||||||
|
filterIsInstance<JvmClasspathRoot>().
|
||||||
|
map {
|
||||||
|
env.contentRootToVirtualFile(it);
|
||||||
|
}.filterNotNull()
|
||||||
|
|
||||||
|
//TODO additional filtering by package existing
|
||||||
|
//val path = packageName.split("/")
|
||||||
|
|
||||||
|
val mappings = res.map {
|
||||||
|
it.findChild("META-INF")
|
||||||
|
}.filterNotNull().flatMap {
|
||||||
|
it.children.filter { it.name.endsWith(ModuleMapping.MAPPING_FILE_EXT) }.toList<VirtualFile>()
|
||||||
|
}.map {
|
||||||
|
ModuleMapping(String(it.contentsToByteArray(), "UTF-8"))
|
||||||
|
}
|
||||||
|
|
||||||
|
return mappings.map { it.findPackageParts(packageName) }.filterNotNull().flatMap { it.parts }.distinct()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -190,7 +190,7 @@ public class KotlinCoreEnvironment private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun contentRootToVirtualFile(root: JvmContentRoot): VirtualFile? {
|
fun contentRootToVirtualFile(root: JvmContentRoot): VirtualFile? {
|
||||||
when (root) {
|
when (root) {
|
||||||
is JvmClasspathRoot -> {
|
is JvmClasspathRoot -> {
|
||||||
return if (root.file.isFile()) findJarRoot(root) else findLocalDirectory(root)
|
return if (root.file.isFile()) findJarRoot(root) else findLocalDirectory(root)
|
||||||
@@ -242,6 +242,10 @@ public class KotlinCoreEnvironment private constructor(
|
|||||||
messageCollector.report(severity, message, CompilerMessageLocation.NO_LOCATION)
|
messageCollector.report(severity, message, CompilerMessageLocation.NO_LOCATION)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun getJavaRoots() : List<JavaRoot> {
|
||||||
|
return javaRoots
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private val APPLICATION_LOCK = Object()
|
private val APPLICATION_LOCK = Object()
|
||||||
|
|||||||
+3
-1
@@ -57,6 +57,7 @@ import org.jetbrains.kotlin.resolve.BindingTraceContext;
|
|||||||
import org.jetbrains.kotlin.resolve.ScriptNameUtil;
|
import org.jetbrains.kotlin.resolve.ScriptNameUtil;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.JvmPackageMappingProvider;
|
||||||
import org.jetbrains.kotlin.util.PerformanceCounter;
|
import org.jetbrains.kotlin.util.PerformanceCounter;
|
||||||
import org.jetbrains.kotlin.utils.KotlinPaths;
|
import org.jetbrains.kotlin.utils.KotlinPaths;
|
||||||
|
|
||||||
@@ -326,7 +327,8 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
environment.getSourceFiles(),
|
environment.getSourceFiles(),
|
||||||
sharedTrace,
|
sharedTrace,
|
||||||
environment.getConfiguration().get(JVMConfigurationKeys.MODULE_IDS),
|
environment.getConfiguration().get(JVMConfigurationKeys.MODULE_IDS),
|
||||||
environment.getConfiguration().get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS)
|
environment.getConfiguration().get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS),
|
||||||
|
new JvmPackageMappingProvider(environment)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.load.java.JavaClassFinderImpl
|
|||||||
import org.jetbrains.kotlin.load.java.JavaFlexibleTypeCapabilitiesProvider
|
import org.jetbrains.kotlin.load.java.JavaFlexibleTypeCapabilitiesProvider
|
||||||
import org.jetbrains.kotlin.load.java.components.*
|
import org.jetbrains.kotlin.load.java.components.*
|
||||||
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
|
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolver
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
||||||
import org.jetbrains.kotlin.load.java.sam.SamConversionResolverImpl
|
import org.jetbrains.kotlin.load.java.sam.SamConversionResolverImpl
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaPropertyInitializerEvaluatorImpl
|
import org.jetbrains.kotlin.load.java.structure.impl.JavaPropertyInitializerEvaluatorImpl
|
||||||
@@ -69,8 +70,13 @@ public fun StorageComponentContainer.configureJavaTopDownAnalysis(moduleContentS
|
|||||||
|
|
||||||
public fun createContainerForLazyResolveWithJava(
|
public fun createContainerForLazyResolveWithJava(
|
||||||
moduleContext: ModuleContext, bindingTrace: BindingTrace, declarationProviderFactory: DeclarationProviderFactory,
|
moduleContext: ModuleContext, bindingTrace: BindingTrace, declarationProviderFactory: DeclarationProviderFactory,
|
||||||
moduleContentScope: GlobalSearchScope, moduleClassResolver: ModuleClassResolver, targetEnvironment: TargetEnvironment = CompilerEnvironment
|
moduleContentScope: GlobalSearchScope, moduleClassResolver: ModuleClassResolver,
|
||||||
|
targetEnvironment: TargetEnvironment = CompilerEnvironment,
|
||||||
|
packageMappingProvider: PackageMappingProvider
|
||||||
): ComponentProvider = createContainer("LazyResolveWithJava") {
|
): ComponentProvider = createContainer("LazyResolveWithJava") {
|
||||||
|
//TODO: idea specific code
|
||||||
|
useInstance(packageMappingProvider)
|
||||||
|
|
||||||
configureModule(moduleContext, JvmPlatform, bindingTrace)
|
configureModule(moduleContext, JvmPlatform, bindingTrace)
|
||||||
configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, LookupTracker.DO_NOTHING)
|
configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, LookupTracker.DO_NOTHING)
|
||||||
|
|
||||||
@@ -92,8 +98,11 @@ public fun createContainerForTopDownAnalyzerForJvm(
|
|||||||
bindingTrace: BindingTrace,
|
bindingTrace: BindingTrace,
|
||||||
declarationProviderFactory: DeclarationProviderFactory,
|
declarationProviderFactory: DeclarationProviderFactory,
|
||||||
moduleContentScope: GlobalSearchScope,
|
moduleContentScope: GlobalSearchScope,
|
||||||
lookupTracker: LookupTracker
|
lookupTracker: LookupTracker,
|
||||||
|
packageMappingProvider: PackageMappingProvider
|
||||||
): ContainerForTopDownAnalyzerForJvm = createContainer("TopDownAnalyzerForJvm") {
|
): ContainerForTopDownAnalyzerForJvm = createContainer("TopDownAnalyzerForJvm") {
|
||||||
|
useInstance(packageMappingProvider)
|
||||||
|
|
||||||
configureModule(moduleContext, JvmPlatform, bindingTrace)
|
configureModule(moduleContext, JvmPlatform, bindingTrace)
|
||||||
configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, lookupTracker)
|
configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, lookupTracker)
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.extensions.ExternalDeclarationsProvider
|
import org.jetbrains.kotlin.extensions.ExternalDeclarationsProvider
|
||||||
import org.jetbrains.kotlin.frontend.java.di.createContainerForLazyResolveWithJava
|
import org.jetbrains.kotlin.frontend.java.di.createContainerForLazyResolveWithJava
|
||||||
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolverImpl
|
import org.jetbrains.kotlin.load.java.lazy.ModuleClassResolverImpl
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
|
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
|
||||||
@@ -49,7 +50,8 @@ public object JvmAnalyzerFacade : AnalyzerFacade<JvmPlatformParameters>() {
|
|||||||
moduleContent: ModuleContent,
|
moduleContent: ModuleContent,
|
||||||
platformParameters: JvmPlatformParameters,
|
platformParameters: JvmPlatformParameters,
|
||||||
targetEnvironment: TargetEnvironment,
|
targetEnvironment: TargetEnvironment,
|
||||||
resolverForProject: ResolverForProject<M>
|
resolverForProject: ResolverForProject<M>,
|
||||||
|
packageMappingProvider: PackageMappingProvider
|
||||||
): ResolverForModule {
|
): ResolverForModule {
|
||||||
val (syntheticFiles, moduleContentScope) = moduleContent
|
val (syntheticFiles, moduleContentScope) = moduleContent
|
||||||
val project = moduleContext.project
|
val project = moduleContext.project
|
||||||
@@ -69,7 +71,8 @@ public object JvmAnalyzerFacade : AnalyzerFacade<JvmPlatformParameters>() {
|
|||||||
declarationProviderFactory,
|
declarationProviderFactory,
|
||||||
moduleContentScope,
|
moduleContentScope,
|
||||||
moduleClassResolver,
|
moduleClassResolver,
|
||||||
targetEnvironment
|
targetEnvironment,
|
||||||
|
packageMappingProvider
|
||||||
)
|
)
|
||||||
val resolveSession = container.get<ResolveSession>()
|
val resolveSession = container.get<ResolveSession>()
|
||||||
val javaDescriptorResolver = container.get<JavaDescriptorResolver>()
|
val javaDescriptorResolver = container.get<JavaDescriptorResolver>()
|
||||||
|
|||||||
+12
-7
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap;
|
|||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
import org.jetbrains.kotlin.resolve.*;
|
import org.jetbrains.kotlin.resolve.*;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisCompletedHandlerExtension;
|
import org.jetbrains.kotlin.resolve.jvm.extensions.AnalysisCompletedHandlerExtension;
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
|
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||||
@@ -91,9 +92,10 @@ public enum TopDownAnalyzerFacadeForJVM {
|
|||||||
@NotNull ModuleContext moduleContext,
|
@NotNull ModuleContext moduleContext,
|
||||||
@NotNull Collection<JetFile> files,
|
@NotNull Collection<JetFile> files,
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull TopDownAnalysisMode topDownAnalysisMode
|
@NotNull TopDownAnalysisMode topDownAnalysisMode,
|
||||||
|
PackageMappingProvider packageMappingProvider
|
||||||
) {
|
) {
|
||||||
return analyzeFilesWithJavaIntegration(moduleContext, files, trace, topDownAnalysisMode, null, null);
|
return analyzeFilesWithJavaIntegration(moduleContext, files, trace, topDownAnalysisMode, null, null, packageMappingProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -102,11 +104,12 @@ public enum TopDownAnalyzerFacadeForJVM {
|
|||||||
@NotNull Collection<JetFile> files,
|
@NotNull Collection<JetFile> files,
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@Nullable List<String> moduleIds,
|
@Nullable List<String> moduleIds,
|
||||||
@Nullable IncrementalCompilationComponents incrementalCompilationComponents
|
@Nullable IncrementalCompilationComponents incrementalCompilationComponents,
|
||||||
|
@NotNull PackageMappingProvider packageMappingProvider
|
||||||
) {
|
) {
|
||||||
return analyzeFilesWithJavaIntegration(
|
return analyzeFilesWithJavaIntegration(
|
||||||
moduleContext, files, trace, TopDownAnalysisMode.TopLevelDeclarations, moduleIds, incrementalCompilationComponents
|
moduleContext, files, trace, TopDownAnalysisMode.TopLevelDeclarations, moduleIds, incrementalCompilationComponents,
|
||||||
);
|
packageMappingProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -116,7 +119,8 @@ public enum TopDownAnalyzerFacadeForJVM {
|
|||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull TopDownAnalysisMode topDownAnalysisMode,
|
@NotNull TopDownAnalysisMode topDownAnalysisMode,
|
||||||
@Nullable List<String> moduleIds,
|
@Nullable List<String> moduleIds,
|
||||||
@Nullable IncrementalCompilationComponents incrementalCompilationComponents
|
@Nullable IncrementalCompilationComponents incrementalCompilationComponents,
|
||||||
|
@NotNull PackageMappingProvider packageMappingProvider
|
||||||
) {
|
) {
|
||||||
Project project = moduleContext.getProject();
|
Project project = moduleContext.getProject();
|
||||||
List<JetFile> allFiles = JvmAnalyzerFacade.getAllFilesToAnalyze(project, null, files);
|
List<JetFile> allFiles = JvmAnalyzerFacade.getAllFilesToAnalyze(project, null, files);
|
||||||
@@ -132,7 +136,8 @@ public enum TopDownAnalyzerFacadeForJVM {
|
|||||||
trace,
|
trace,
|
||||||
providerFactory,
|
providerFactory,
|
||||||
GlobalSearchScope.allScope(project),
|
GlobalSearchScope.allScope(project),
|
||||||
lookupTracker
|
lookupTracker,
|
||||||
|
packageMappingProvider
|
||||||
);
|
);
|
||||||
|
|
||||||
List<PackageFragmentProvider> additionalProviders = new ArrayList<PackageFragmentProvider>();
|
List<PackageFragmentProvider> additionalProviders = new ArrayList<PackageFragmentProvider>();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||||
import org.jetbrains.kotlin.descriptors.impl.LazyModuleDependencies
|
import org.jetbrains.kotlin.descriptors.impl.LazyModuleDependencies
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.JetFile
|
import org.jetbrains.kotlin.psi.JetFile
|
||||||
@@ -128,9 +129,9 @@ public abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
|||||||
modulesContent: (M) -> ModuleContent,
|
modulesContent: (M) -> ModuleContent,
|
||||||
platformParameters: P,
|
platformParameters: P,
|
||||||
targetEnvironment: TargetEnvironment,
|
targetEnvironment: TargetEnvironment,
|
||||||
delegateResolver: ResolverForProject<M> = EmptyResolverForProject()
|
delegateResolver: ResolverForProject<M> = EmptyResolverForProject(),
|
||||||
|
packageMappingProviderFactory: (M, ModuleContent) -> PackageMappingProvider = { (m, c) -> PackageMappingProvider.EMPTY }
|
||||||
): ResolverForProject<M> {
|
): ResolverForProject<M> {
|
||||||
|
|
||||||
val storageManager = projectContext.storageManager
|
val storageManager = projectContext.storageManager
|
||||||
fun createResolverForProject(): ResolverForProjectImpl<M> {
|
fun createResolverForProject(): ResolverForProjectImpl<M> {
|
||||||
val descriptorByModule = HashMap<M, ModuleDescriptorImpl>()
|
val descriptorByModule = HashMap<M, ModuleDescriptorImpl>()
|
||||||
@@ -182,9 +183,11 @@ public abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
|||||||
module ->
|
module ->
|
||||||
val descriptor = resolverForProject.descriptorForModule(module)
|
val descriptor = resolverForProject.descriptorForModule(module)
|
||||||
val computeResolverForModule = storageManager.createLazyValue {
|
val computeResolverForModule = storageManager.createLazyValue {
|
||||||
|
val content = modulesContent(module)
|
||||||
createResolverForModule(
|
createResolverForModule(
|
||||||
module, descriptor, projectContext.withModule(descriptor), modulesContent(module),
|
module, descriptor, projectContext.withModule(descriptor), modulesContent(module),
|
||||||
platformParameters, targetEnvironment, resolverForProject
|
platformParameters, targetEnvironment, resolverForProject,
|
||||||
|
packageMappingProviderFactory(module, content)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +207,8 @@ public abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
|
|||||||
moduleContent: ModuleContent,
|
moduleContent: ModuleContent,
|
||||||
platformParameters: P,
|
platformParameters: P,
|
||||||
targetEnvironment: TargetEnvironment,
|
targetEnvironment: TargetEnvironment,
|
||||||
resolverForProject: ResolverForProject<M>
|
resolverForProject: ResolverForProject<M>,
|
||||||
|
packageMappingProvider: PackageMappingProvider
|
||||||
): ResolverForModule
|
): ResolverForModule
|
||||||
|
|
||||||
public abstract val moduleParameters: ModuleParameters
|
public abstract val moduleParameters: ModuleParameters
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
|||||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider;
|
||||||
import org.jetbrains.kotlin.storage.ExceptionTracker;
|
import org.jetbrains.kotlin.storage.ExceptionTracker;
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||||
import org.jetbrains.kotlin.storage.StorageManager;
|
import org.jetbrains.kotlin.storage.StorageManager;
|
||||||
@@ -246,7 +247,8 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
|||||||
jetFiles,
|
jetFiles,
|
||||||
moduleTrace,
|
moduleTrace,
|
||||||
null,
|
null,
|
||||||
null
|
null,
|
||||||
|
PackageMappingProvider.EMPTY
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
|||||||
import org.jetbrains.kotlin.resolve.TopDownAnalysisMode;
|
import org.jetbrains.kotlin.resolve.TopDownAnalysisMode;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider;
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor;
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor;
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||||
import org.jetbrains.kotlin.test.JetTestUtils;
|
import org.jetbrains.kotlin.test.JetTestUtils;
|
||||||
@@ -154,7 +155,8 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
|||||||
moduleContext,
|
moduleContext,
|
||||||
environment.getSourceFiles(),
|
environment.getSourceFiles(),
|
||||||
trace,
|
trace,
|
||||||
TopDownAnalysisMode.TopLevelDeclarations
|
TopDownAnalysisMode.TopLevelDeclarations,
|
||||||
|
PackageMappingProvider.EMPTY
|
||||||
);
|
);
|
||||||
|
|
||||||
PackageViewDescriptor packageView = moduleContext.getModule().getPackage(TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = moduleContext.getModule().getPackage(TEST_PACKAGE_FQNAME);
|
||||||
|
|||||||
+3
-1
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.resolve.BindingContext;
|
|||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.kotlin.resolve.jvm.kotlinSignature.TypeTransformingVisitor;
|
import org.jetbrains.kotlin.resolve.jvm.kotlinSignature.TypeTransformingVisitor;
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.JvmPackageMappingProvider;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||||
|
|
||||||
@@ -78,7 +79,8 @@ public abstract class AbstractSdkAnnotationsValidityTest extends UsefulTestCase
|
|||||||
|
|
||||||
BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace();
|
BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace();
|
||||||
ModuleDescriptor module = LazyResolveTestUtil.resolve(
|
ModuleDescriptor module = LazyResolveTestUtil.resolve(
|
||||||
commonEnvironment.getProject(), trace, Collections.<JetFile>emptyList()
|
commonEnvironment.getProject(), trace, Collections.<JetFile>emptyList(),
|
||||||
|
new JvmPackageMappingProvider(commonEnvironment)
|
||||||
);
|
);
|
||||||
|
|
||||||
AlternativeSignatureErrorFindingVisitor visitor =
|
AlternativeSignatureErrorFindingVisitor visitor =
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.name.Name;
|
|||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.JvmPackageMappingProvider;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||||
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||||
@@ -102,7 +103,8 @@ public final class LoadDescriptorUtil {
|
|||||||
KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||||
|
|
||||||
BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace();
|
BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace();
|
||||||
ModuleDescriptor module = LazyResolveTestUtil.resolve(environment.getProject(), trace, Collections.<JetFile>emptyList());
|
ModuleDescriptor module = LazyResolveTestUtil
|
||||||
|
.resolve(environment.getProject(), trace, Collections.<JetFile>emptyList(), new JvmPackageMappingProvider(environment));
|
||||||
|
|
||||||
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
||||||
return Pair.create(packageView, trace.getBindingContext());
|
return Pair.create(packageView, trace.getBindingContext());
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||||
import org.jetbrains.kotlin.context.ModuleContext;
|
import org.jetbrains.kotlin.context.ModuleContext;
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
|
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||||
@@ -71,6 +72,6 @@ public class JvmResolveUtil {
|
|||||||
|
|
||||||
BindingTrace trace = new CliLightClassGenerationSupport.CliBindingTrace();
|
BindingTrace trace = new CliLightClassGenerationSupport.CliBindingTrace();
|
||||||
|
|
||||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(moduleContext, files, trace, null, null);
|
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(moduleContext, files, trace, null, null, PackageMappingProvider.EMPTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.CliLightClassGenerationSupport;
|
|||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
||||||
import org.jetbrains.kotlin.context.ModuleContext;
|
import org.jetbrains.kotlin.context.ModuleContext;
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor;
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider;
|
||||||
import org.jetbrains.kotlin.name.Name;
|
import org.jetbrains.kotlin.name.Name;
|
||||||
import org.jetbrains.kotlin.name.SpecialNames;
|
import org.jetbrains.kotlin.name.SpecialNames;
|
||||||
import org.jetbrains.kotlin.psi.JetFile;
|
import org.jetbrains.kotlin.psi.JetFile;
|
||||||
@@ -47,15 +48,21 @@ public class LazyResolveTestUtil {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ModuleDescriptor resolve(@NotNull Project project, @NotNull List<JetFile> sourceFiles) {
|
public static ModuleDescriptor resolve(@NotNull Project project, @NotNull List<JetFile> sourceFiles) {
|
||||||
return resolve(project, new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), sourceFiles);
|
return resolve(project, new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(), sourceFiles, PackageMappingProvider.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static ModuleDescriptor resolve(@NotNull Project project, @NotNull BindingTrace trace, @NotNull List<JetFile> sourceFiles) {
|
public static ModuleDescriptor resolve(
|
||||||
|
@NotNull Project project,
|
||||||
|
@NotNull BindingTrace trace,
|
||||||
|
@NotNull List<JetFile> sourceFiles,
|
||||||
|
@NotNull PackageMappingProvider packageMappingProvider
|
||||||
|
) {
|
||||||
ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, "test");
|
ModuleContext moduleContext = TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(project, "test");
|
||||||
|
|
||||||
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental(
|
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental(
|
||||||
moduleContext, sourceFiles, trace, TopDownAnalysisMode.TopLevelDeclarations
|
moduleContext, sourceFiles, trace, TopDownAnalysisMode.TopLevelDeclarations,
|
||||||
|
packageMappingProvider
|
||||||
);
|
);
|
||||||
|
|
||||||
return moduleContext.getModule();
|
return moduleContext.getModule();
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.frontend.java.di.createContainerForTopDownAnalyzerFo
|
|||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||||
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil
|
import org.jetbrains.kotlin.jvm.compiler.LoadDescriptorUtil
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
import org.jetbrains.kotlin.load.java.structure.reflect.classId
|
import org.jetbrains.kotlin.load.java.structure.reflect.classId
|
||||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
||||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||||
@@ -59,7 +60,7 @@ public abstract class AbstractLocalClassProtoTest : TestCaseWithTmpdir() {
|
|||||||
|
|
||||||
val container = createContainerForTopDownAnalyzerForJvm(
|
val container = createContainerForTopDownAnalyzerForJvm(
|
||||||
moduleContext, CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(),
|
moduleContext, CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace(),
|
||||||
providerFactory, GlobalSearchScope.allScope(environment.project), LookupTracker.DO_NOTHING
|
providerFactory, GlobalSearchScope.allScope(environment.project), LookupTracker.DO_NOTHING, PackageMappingProvider.EMPTY
|
||||||
)
|
)
|
||||||
moduleContext.initializeModuleContents(container.javaDescriptorResolver.packageFragmentProvider)
|
moduleContext.initializeModuleContents(container.javaDescriptorResolver.packageFragmentProvider)
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -30,7 +30,8 @@ import org.jetbrains.kotlin.utils.emptyOrSingletonList
|
|||||||
public class LazyJavaPackageFragmentProvider(
|
public class LazyJavaPackageFragmentProvider(
|
||||||
components: JavaResolverComponents,
|
components: JavaResolverComponents,
|
||||||
module: ModuleDescriptor,
|
module: ModuleDescriptor,
|
||||||
reflectionTypes: ReflectionTypes
|
reflectionTypes: ReflectionTypes,
|
||||||
|
packageMapper: PackageMappingProvider
|
||||||
) : PackageFragmentProvider {
|
) : PackageFragmentProvider {
|
||||||
|
|
||||||
private val c =
|
private val c =
|
||||||
@@ -41,7 +42,7 @@ public class LazyJavaPackageFragmentProvider(
|
|||||||
fqName ->
|
fqName ->
|
||||||
val jPackage = c.components.finder.findPackage(fqName)
|
val jPackage = c.components.finder.findPackage(fqName)
|
||||||
if (jPackage != null) {
|
if (jPackage != null) {
|
||||||
LazyJavaPackageFragment(c, jPackage)
|
LazyJavaPackageFragment(c, jPackage, packageMapper)
|
||||||
}
|
}
|
||||||
else null
|
else null
|
||||||
}
|
}
|
||||||
|
|||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.load.java.lazy
|
||||||
|
|
||||||
|
//interface PackageMappingProvider {
|
||||||
|
//
|
||||||
|
// fun findPackageMembers(packageName: String): List<String>
|
||||||
|
//
|
||||||
|
// companion object {
|
||||||
|
// val EMPTY = object : PackageMappingProvider {
|
||||||
|
// override fun findPackageMembers(packageName: String): List<String> {
|
||||||
|
// return emptyList()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//}
|
||||||
+4
-1
@@ -19,7 +19,9 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors
|
|||||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
||||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||||
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
import org.jetbrains.kotlin.load.java.structure.JavaPackage
|
||||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
||||||
import org.jetbrains.kotlin.resolve.scopes.DecapitalizedAnnotationScope
|
import org.jetbrains.kotlin.resolve.scopes.DecapitalizedAnnotationScope
|
||||||
@@ -27,7 +29,8 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope
|
|||||||
|
|
||||||
class LazyJavaPackageFragment(
|
class LazyJavaPackageFragment(
|
||||||
private val c: LazyJavaResolverContext,
|
private val c: LazyJavaResolverContext,
|
||||||
private val jPackage: JavaPackage
|
private val jPackage: JavaPackage,
|
||||||
|
val packageMapper: PackageMappingProvider
|
||||||
) : PackageFragmentDescriptorImpl(c.module, jPackage.getFqName()) {
|
) : PackageFragmentDescriptorImpl(c.module, jPackage.getFqName()) {
|
||||||
val scope: LazyJavaPackageScope by lazy { LazyJavaPackageScope(c, jPackage, this) }
|
val scope: LazyJavaPackageScope by lazy { LazyJavaPackageScope(c, jPackage, this) }
|
||||||
// Just a temporary hack to inject deprecated decapitalized annotation
|
// Just a temporary hack to inject deprecated decapitalized annotation
|
||||||
|
|||||||
+8
-2
@@ -52,8 +52,14 @@ public class LazyJavaPackageScope(
|
|||||||
val kotlinBinaryClass = kotlinBinaryClass
|
val kotlinBinaryClass = kotlinBinaryClass
|
||||||
if (kotlinBinaryClass == null)
|
if (kotlinBinaryClass == null)
|
||||||
JetScope.Empty
|
JetScope.Empty
|
||||||
else
|
else {
|
||||||
c.components.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClass) ?: JetScope.Empty
|
val pakage = jPackage.getFqName().asString()
|
||||||
|
val files = containingDeclaration.packageMapper.findPackageMembers(pakage.replace("\\.", "/"))
|
||||||
|
// println("package:" + pakage)
|
||||||
|
// println(files.join())
|
||||||
|
val jetScope = c.components.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClass) ?: JetScope.Empty
|
||||||
|
jetScope
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val packageFragment: LazyJavaPackageFragment get() = getContainingDeclaration() as LazyJavaPackageFragment
|
private val packageFragment: LazyJavaPackageFragment get() = getContainingDeclaration() as LazyJavaPackageFragment
|
||||||
|
|||||||
@@ -30,15 +30,49 @@ public class ModuleMapping(val moduleMapping: String) {
|
|||||||
miniFacades.parts.add(facade)
|
miniFacades.parts.add(facade)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun findPackageParts(internalPackageName: String): PackageFacades? {
|
||||||
|
return package2MiniFacades[internalPackageName]
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
public val MAPPING_FILE_EXT: String = "kotlin_module";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PackageFacades(val internalName: String) {
|
public class PackageFacades(val internalName: String) {
|
||||||
|
|
||||||
val parts = hashSetOf<String>()
|
val parts = linkedSetOf<String>()
|
||||||
|
|
||||||
fun serialize(out: Writer) {
|
fun serialize(out: Writer) {
|
||||||
for (i in parts) {
|
for (i in parts) {
|
||||||
out.write("$internalName->$i\n")
|
out.write("$internalName->$i\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other !is PackageFacades) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other.internalName != internalName) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other.parts.size() != parts.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (part in other.parts) {
|
||||||
|
if (!parts.contains(part)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return internalName.hashCode() / 3 + parts.size() / 3+ (parts.firstOrNull()?.hashCode() ?: 0) /3
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.load.java.components.*
|
import org.jetbrains.kotlin.load.java.components.*
|
||||||
import org.jetbrains.kotlin.load.java.lazy.JavaResolverComponents
|
import org.jetbrains.kotlin.load.java.lazy.JavaResolverComponents
|
||||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaPackageFragmentProvider
|
import org.jetbrains.kotlin.load.java.lazy.LazyJavaPackageFragmentProvider
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
import org.jetbrains.kotlin.load.java.lazy.SingleModuleClassResolver
|
||||||
import org.jetbrains.kotlin.load.java.reflect.ReflectJavaClassFinder
|
import org.jetbrains.kotlin.load.java.reflect.ReflectJavaClassFinder
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaPropertyInitializerEvaluator
|
import org.jetbrains.kotlin.load.java.structure.JavaPropertyInitializerEvaluator
|
||||||
@@ -56,7 +57,8 @@ public class RuntimeModuleData private constructor(public val deserialization: D
|
|||||||
ExternalAnnotationResolver.EMPTY, ExternalSignatureResolver.DO_NOTHING, RuntimeErrorReporter, JavaResolverCache.EMPTY,
|
ExternalAnnotationResolver.EMPTY, ExternalSignatureResolver.DO_NOTHING, RuntimeErrorReporter, JavaResolverCache.EMPTY,
|
||||||
JavaPropertyInitializerEvaluator.DoNothing, SamConversionResolver, RuntimeSourceElementFactory, singleModuleClassResolver
|
JavaPropertyInitializerEvaluator.DoNothing, SamConversionResolver, RuntimeSourceElementFactory, singleModuleClassResolver
|
||||||
)
|
)
|
||||||
val lazyJavaPackageFragmentProvider = LazyJavaPackageFragmentProvider(globalJavaResolverContext, module, ReflectionTypes(module))
|
val lazyJavaPackageFragmentProvider =
|
||||||
|
LazyJavaPackageFragmentProvider(globalJavaResolverContext, module, ReflectionTypes(module), PackageMappingProvider.EMPTY)
|
||||||
val javaDescriptorResolver = JavaDescriptorResolver(lazyJavaPackageFragmentProvider, module)
|
val javaDescriptorResolver = JavaDescriptorResolver(lazyJavaPackageFragmentProvider, module)
|
||||||
val javaClassDataFinder = JavaClassDataFinder(reflectKotlinClassFinder, deserializedDescriptorResolver)
|
val javaClassDataFinder = JavaClassDataFinder(reflectKotlinClassFinder, deserializedDescriptorResolver)
|
||||||
val binaryClassAnnotationAndConstantLoader = BinaryClassAnnotationAndConstantLoaderImpl(module, storageManager, reflectKotlinClassFinder, RuntimeErrorReporter)
|
val binaryClassAnnotationAndConstantLoader = BinaryClassAnnotationAndConstantLoaderImpl(module, storageManager, reflectKotlinClassFinder, RuntimeErrorReporter)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 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.load.java.lazy
|
||||||
|
|
||||||
|
interface PackageMappingProvider {
|
||||||
|
|
||||||
|
fun findPackageMembers(packageName: String): List<String>
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val EMPTY = object : PackageMappingProvider {
|
||||||
|
override fun findPackageMembers(packageName: String): List<String> {
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.idea.caches.resolve
|
||||||
|
|
||||||
|
import com.intellij.psi.search.GlobalSearchScope
|
||||||
|
import com.intellij.util.indexing.FileBasedIndex
|
||||||
|
import org.jetbrains.kotlin.idea.vfilefinder.KotlinModuleMappingIndex
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.PackageFacades
|
||||||
|
|
||||||
|
public class IDEPackageMappingProvider(val scope: GlobalSearchScope) : PackageMappingProvider {
|
||||||
|
|
||||||
|
override fun findPackageMembers(packageName: String): List<String> {
|
||||||
|
val values: MutableList<PackageFacades> = FileBasedIndex.getInstance().getValues(KotlinModuleMappingIndex.KEY, packageName, scope)
|
||||||
|
return values.flatMap { it.parts }.distinct()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.frontend.di.createContainerForLazyResolve
|
|||||||
import org.jetbrains.kotlin.idea.framework.KotlinJavaScriptLibraryDetectionUtil
|
import org.jetbrains.kotlin.idea.framework.KotlinJavaScriptLibraryDetectionUtil
|
||||||
import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS
|
import org.jetbrains.kotlin.js.analyze.TopDownAnalyzerFacadeForJS
|
||||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||||
import org.jetbrains.kotlin.resolve.TargetEnvironment
|
import org.jetbrains.kotlin.resolve.TargetEnvironment
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||||
@@ -45,7 +46,8 @@ public object JsAnalyzerFacade : AnalyzerFacade<PlatformAnalysisParameters>() {
|
|||||||
moduleContent: ModuleContent,
|
moduleContent: ModuleContent,
|
||||||
platformParameters: PlatformAnalysisParameters,
|
platformParameters: PlatformAnalysisParameters,
|
||||||
targetEnvironment: TargetEnvironment,
|
targetEnvironment: TargetEnvironment,
|
||||||
resolverForProject: ResolverForProject<M>
|
resolverForProject: ResolverForProject<M>,
|
||||||
|
packageMappingProvider: PackageMappingProvider
|
||||||
): ResolverForModule {
|
): ResolverForModule {
|
||||||
val (syntheticFiles, moduleContentScope) = moduleContent
|
val (syntheticFiles, moduleContentScope) = moduleContent
|
||||||
val project = moduleContext.project
|
val project = moduleContext.project
|
||||||
|
|||||||
+2
-1
@@ -63,7 +63,8 @@ fun createModuleResolverProvider(
|
|||||||
|
|
||||||
val resolverForProject = analyzerFacade.setupResolverForProject(
|
val resolverForProject = analyzerFacade.setupResolverForProject(
|
||||||
globalContext.withProject(project), modulesToCreateResolversFor, modulesContent,
|
globalContext.withProject(project), modulesToCreateResolversFor, modulesContent,
|
||||||
jvmPlatformParameters, IdeaEnvironment, delegateResolver
|
jvmPlatformParameters, IdeaEnvironment, delegateResolver,
|
||||||
|
{ (m, c) -> IDEPackageMappingProvider(c.moduleContentScope) }
|
||||||
)
|
)
|
||||||
return resolverForProject
|
return resolverForProject
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* 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.idea.vfilefinder
|
||||||
|
|
||||||
|
import com.intellij.openapi.diagnostic.Logger
|
||||||
|
import com.intellij.util.indexing.*
|
||||||
|
import com.intellij.util.io.DataExternalizer
|
||||||
|
import com.intellij.util.io.KeyDescriptor
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.ModuleMapping
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.PackageFacades
|
||||||
|
import java.io.DataInput
|
||||||
|
import java.io.DataOutput
|
||||||
|
|
||||||
|
class PackageData(val data: List<String>) {
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return super.equals(other)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return data.size() + (data.firstOrNull()?.hashCode() ?: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public object KotlinModuleMappingIndex : FileBasedIndexExtension<String, PackageFacades>() {
|
||||||
|
|
||||||
|
private val classOfIndex = javaClass<KotlinModuleMappingIndex>().getCanonicalName()
|
||||||
|
|
||||||
|
public val KEY: ID<String, PackageFacades> = ID.create(classOfIndex)
|
||||||
|
|
||||||
|
private val KEY_DESCRIPTOR = object : KeyDescriptor<String> {
|
||||||
|
override fun save(output: DataOutput, value: String) = output.writeUTF(value)
|
||||||
|
|
||||||
|
override fun read(input: DataInput) = input.readUTF()
|
||||||
|
|
||||||
|
override fun getHashCode(value: String) = value.hashCode()
|
||||||
|
|
||||||
|
override fun isEqual(val1: String?, val2: String?) = val1 == val2
|
||||||
|
}
|
||||||
|
|
||||||
|
private val VALUE_EXTERNALIZER = object : DataExternalizer<PackageFacades> {
|
||||||
|
override fun read(`in`: DataInput): PackageFacades? {
|
||||||
|
val internalName = `in`.readUTF()
|
||||||
|
val facades = PackageFacades(internalName)
|
||||||
|
val size = `in`.readInt()
|
||||||
|
(1..size).forEach {
|
||||||
|
facades.parts.add(`in`.readUTF())
|
||||||
|
}
|
||||||
|
|
||||||
|
return facades
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun save(out: DataOutput, value: PackageFacades?) {
|
||||||
|
out.writeUTF(value!!.internalName)
|
||||||
|
out.writeInt(value.parts.size())
|
||||||
|
value.parts.forEach { out.writeUTF(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private val LOG = Logger.getInstance(classOfIndex)
|
||||||
|
|
||||||
|
override fun getName() = KEY
|
||||||
|
|
||||||
|
override fun dependsOnFileContent() = true
|
||||||
|
|
||||||
|
override fun getKeyDescriptor() = KEY_DESCRIPTOR
|
||||||
|
|
||||||
|
override fun getValueExternalizer() = VALUE_EXTERNALIZER
|
||||||
|
|
||||||
|
override fun getInputFilter(): FileBasedIndex.InputFilter {
|
||||||
|
return FileBasedIndex.InputFilter { file -> file.extension == ModuleMapping.MAPPING_FILE_EXT }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getVersion(): Int = 1
|
||||||
|
|
||||||
|
override fun getIndexer(): DataIndexer<String, PackageFacades, FileContent> {
|
||||||
|
return object : DataIndexer<String, PackageFacades, FileContent> {
|
||||||
|
override fun map(inputData: FileContent): MutableMap<String, PackageFacades> {
|
||||||
|
val content = String(inputData.getContent())
|
||||||
|
val moduleMapping = ModuleMapping(content)
|
||||||
|
return moduleMapping.package2MiniFacades
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -506,6 +506,7 @@
|
|||||||
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.versions.KotlinJavaScriptAbiVersionIndex"/>
|
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.versions.KotlinJavaScriptAbiVersionIndex"/>
|
||||||
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.vfilefinder.KotlinClassFileIndex"/>
|
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.vfilefinder.KotlinClassFileIndex"/>
|
||||||
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.vfilefinder.KotlinJavaScriptMetaFileIndex"/>
|
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.vfilefinder.KotlinJavaScriptMetaFileIndex"/>
|
||||||
|
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.vfilefinder.KotlinModuleMappingIndex"/>
|
||||||
|
|
||||||
<idIndexer filetype="Kotlin" implementationClass="org.jetbrains.kotlin.idea.search.KotlinIdIndexer"/>
|
<idIndexer filetype="Kotlin" implementationClass="org.jetbrains.kotlin.idea.search.KotlinIdIndexer"/>
|
||||||
<todoIndexer filetype="Kotlin" implementationClass="org.jetbrains.kotlin.idea.search.KotlinTodoIndexer"/>
|
<todoIndexer filetype="Kotlin" implementationClass="org.jetbrains.kotlin.idea.search.KotlinTodoIndexer"/>
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import com.intellij.util.indexing.FileBasedIndex
|
|||||||
import org.jetbrains.kotlin.idea.JetPluginUtil
|
import org.jetbrains.kotlin.idea.JetPluginUtil
|
||||||
import org.jetbrains.kotlin.idea.vfilefinder.KotlinClassFileIndex
|
import org.jetbrains.kotlin.idea.vfilefinder.KotlinClassFileIndex
|
||||||
import org.jetbrains.kotlin.idea.vfilefinder.KotlinJavaScriptMetaFileIndex
|
import org.jetbrains.kotlin.idea.vfilefinder.KotlinJavaScriptMetaFileIndex
|
||||||
|
import org.jetbrains.kotlin.idea.vfilefinder.KotlinModuleMappingIndex
|
||||||
import org.jetbrains.kotlin.utils.PathUtil
|
import org.jetbrains.kotlin.utils.PathUtil
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ class KotlinUpdatePluginComponent : ApplicationComponent {
|
|||||||
fileBasedIndex.requestRebuild(KotlinJavaScriptAbiVersionIndex.getName())
|
fileBasedIndex.requestRebuild(KotlinJavaScriptAbiVersionIndex.getName())
|
||||||
fileBasedIndex.requestRebuild(KotlinClassFileIndex.KEY)
|
fileBasedIndex.requestRebuild(KotlinClassFileIndex.KEY)
|
||||||
fileBasedIndex.requestRebuild(KotlinJavaScriptMetaFileIndex.KEY)
|
fileBasedIndex.requestRebuild(KotlinJavaScriptMetaFileIndex.KEY)
|
||||||
|
fileBasedIndex.requestRebuild(KotlinModuleMappingIndex.KEY)
|
||||||
|
|
||||||
PropertiesComponent.getInstance()?.setValue(INSTALLED_KOTLIN_VERSION, JetPluginUtil.getPluginVersion())
|
PropertiesComponent.getInstance()?.setValue(INSTALLED_KOTLIN_VERSION, JetPluginUtil.getPluginVersion())
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
import org.jetbrains.kotlin.resolve.BindingTraceContext
|
||||||
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
|
||||||
|
|
||||||
public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
||||||
|
|
||||||
@@ -41,7 +42,7 @@ public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() {
|
|||||||
override fun getModuleDescriptor(): ModuleDescriptor =
|
override fun getModuleDescriptor(): ModuleDescriptor =
|
||||||
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
|
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
|
||||||
TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(getProject(), "test"),
|
TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(getProject(), "test"),
|
||||||
listOf(), BindingTraceContext(), null, null
|
listOf(), BindingTraceContext(), null, null, PackageMappingProvider.EMPTY
|
||||||
).moduleDescriptor
|
).moduleDescriptor
|
||||||
|
|
||||||
override fun getProjectDescriptor() = object : JetWithJdkAndRuntimeLightProjectDescriptor() {
|
override fun getProjectDescriptor() = object : JetWithJdkAndRuntimeLightProjectDescriptor() {
|
||||||
|
|||||||
Reference in New Issue
Block a user