stubs for new components

This commit is contained in:
Michael Bogdanov
2015-08-05 13:00:53 +03:00
parent 6dcd059009
commit 1fcacecf93
29 changed files with 373 additions and 36 deletions
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.context.ProjectContext
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
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.Name
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) {
is JvmClasspathRoot -> {
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)
}
public fun getJavaRoots() : List<JavaRoot> {
return javaRoots
}
companion object {
private val APPLICATION_LOCK = Object()
@@ -57,6 +57,7 @@ import org.jetbrains.kotlin.resolve.BindingTraceContext;
import org.jetbrains.kotlin.resolve.ScriptNameUtil;
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM;
import org.jetbrains.kotlin.resolve.lazy.JvmPackageMappingProvider;
import org.jetbrains.kotlin.util.PerformanceCounter;
import org.jetbrains.kotlin.utils.KotlinPaths;
@@ -326,7 +327,8 @@ public class KotlinToJVMBytecodeCompiler {
environment.getSourceFiles(),
sharedTrace,
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.components.*
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.sam.SamConversionResolverImpl
import org.jetbrains.kotlin.load.java.structure.impl.JavaPropertyInitializerEvaluatorImpl
@@ -69,8 +70,13 @@ public fun StorageComponentContainer.configureJavaTopDownAnalysis(moduleContentS
public fun createContainerForLazyResolveWithJava(
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") {
//TODO: idea specific code
useInstance(packageMappingProvider)
configureModule(moduleContext, JvmPlatform, bindingTrace)
configureJavaTopDownAnalysis(moduleContentScope, moduleContext.project, LookupTracker.DO_NOTHING)
@@ -92,8 +98,11 @@ public fun createContainerForTopDownAnalyzerForJvm(
bindingTrace: BindingTrace,
declarationProviderFactory: DeclarationProviderFactory,
moduleContentScope: GlobalSearchScope,
lookupTracker: LookupTracker
lookupTracker: LookupTracker,
packageMappingProvider: PackageMappingProvider
): ContainerForTopDownAnalyzerForJvm = createContainer("TopDownAnalyzerForJvm") {
useInstance(packageMappingProvider)
configureModule(moduleContext, JvmPlatform, bindingTrace)
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.frontend.java.di.createContainerForLazyResolveWithJava
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.psi.JetFile
import org.jetbrains.kotlin.resolve.CodeAnalyzerInitializer
@@ -49,7 +50,8 @@ public object JvmAnalyzerFacade : AnalyzerFacade<JvmPlatformParameters>() {
moduleContent: ModuleContent,
platformParameters: JvmPlatformParameters,
targetEnvironment: TargetEnvironment,
resolverForProject: ResolverForProject<M>
resolverForProject: ResolverForProject<M>,
packageMappingProvider: PackageMappingProvider
): ResolverForModule {
val (syntheticFiles, moduleContentScope) = moduleContent
val project = moduleContext.project
@@ -69,7 +71,8 @@ public object JvmAnalyzerFacade : AnalyzerFacade<JvmPlatformParameters>() {
declarationProviderFactory,
moduleContentScope,
moduleClassResolver,
targetEnvironment
targetEnvironment,
packageMappingProvider
)
val resolveSession = container.get<ResolveSession>()
val javaDescriptorResolver = container.get<JavaDescriptorResolver>()
@@ -40,6 +40,7 @@ import org.jetbrains.kotlin.platform.PlatformToKotlinClassMap;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.resolve.*;
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.scopes.DescriptorKindFilter;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
@@ -91,9 +92,10 @@ public enum TopDownAnalyzerFacadeForJVM {
@NotNull ModuleContext moduleContext,
@NotNull Collection<JetFile> files,
@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
@@ -102,11 +104,12 @@ public enum TopDownAnalyzerFacadeForJVM {
@NotNull Collection<JetFile> files,
@NotNull BindingTrace trace,
@Nullable List<String> moduleIds,
@Nullable IncrementalCompilationComponents incrementalCompilationComponents
@Nullable IncrementalCompilationComponents incrementalCompilationComponents,
@NotNull PackageMappingProvider packageMappingProvider
) {
return analyzeFilesWithJavaIntegration(
moduleContext, files, trace, TopDownAnalysisMode.TopLevelDeclarations, moduleIds, incrementalCompilationComponents
);
moduleContext, files, trace, TopDownAnalysisMode.TopLevelDeclarations, moduleIds, incrementalCompilationComponents,
packageMappingProvider);
}
@NotNull
@@ -116,7 +119,8 @@ public enum TopDownAnalyzerFacadeForJVM {
@NotNull BindingTrace trace,
@NotNull TopDownAnalysisMode topDownAnalysisMode,
@Nullable List<String> moduleIds,
@Nullable IncrementalCompilationComponents incrementalCompilationComponents
@Nullable IncrementalCompilationComponents incrementalCompilationComponents,
@NotNull PackageMappingProvider packageMappingProvider
) {
Project project = moduleContext.getProject();
List<JetFile> allFiles = JvmAnalyzerFacade.getAllFilesToAnalyze(project, null, files);
@@ -132,7 +136,8 @@ public enum TopDownAnalyzerFacadeForJVM {
trace,
providerFactory,
GlobalSearchScope.allScope(project),
lookupTracker
lookupTracker,
packageMappingProvider
);
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.impl.LazyModuleDependencies
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.Name
import org.jetbrains.kotlin.psi.JetFile
@@ -128,9 +129,9 @@ public abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
modulesContent: (M) -> ModuleContent,
platformParameters: P,
targetEnvironment: TargetEnvironment,
delegateResolver: ResolverForProject<M> = EmptyResolverForProject()
delegateResolver: ResolverForProject<M> = EmptyResolverForProject(),
packageMappingProviderFactory: (M, ModuleContent) -> PackageMappingProvider = { (m, c) -> PackageMappingProvider.EMPTY }
): ResolverForProject<M> {
val storageManager = projectContext.storageManager
fun createResolverForProject(): ResolverForProjectImpl<M> {
val descriptorByModule = HashMap<M, ModuleDescriptorImpl>()
@@ -182,9 +183,11 @@ public abstract class AnalyzerFacade<in P : PlatformAnalysisParameters> {
module ->
val descriptor = resolverForProject.descriptorForModule(module)
val computeResolverForModule = storageManager.createLazyValue {
val content = modulesContent(module)
createResolverForModule(
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,
platformParameters: P,
targetEnvironment: TargetEnvironment,
resolverForProject: ResolverForProject<M>
resolverForProject: ResolverForProject<M>,
packageMappingProvider: PackageMappingProvider
): ResolverForModule
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.jvm.TopDownAnalyzerFacadeForJVM;
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.LockBasedStorageManager;
import org.jetbrains.kotlin.storage.StorageManager;
@@ -246,7 +247,8 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
jetFiles,
moduleTrace,
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.jvm.TopDownAnalyzerFacadeForJVM;
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.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetTestUtils;
@@ -154,7 +155,8 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
moduleContext,
environment.getSourceFiles(),
trace,
TopDownAnalysisMode.TopLevelDeclarations
TopDownAnalysisMode.TopLevelDeclarations,
PackageMappingProvider.EMPTY
);
PackageViewDescriptor packageView = moduleContext.getModule().getPackage(TEST_PACKAGE_FQNAME);
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
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.scopes.JetScope;
@@ -78,7 +79,8 @@ public abstract class AbstractSdkAnnotationsValidityTest extends UsefulTestCase
BindingTrace trace = new CliLightClassGenerationSupport.NoScopeRecordCliBindingTrace();
ModuleDescriptor module = LazyResolveTestUtil.resolve(
commonEnvironment.getProject(), trace, Collections.<JetFile>emptyList()
commonEnvironment.getProject(), trace, Collections.<JetFile>emptyList(),
new JvmPackageMappingProvider(commonEnvironment)
);
AlternativeSignatureErrorFindingVisitor visitor =
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.resolve.BindingContext;
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.LazyResolveTestUtil;
import org.jetbrains.kotlin.test.ConfigurationKind;
@@ -102,7 +103,8 @@ public final class LoadDescriptorUtil {
KotlinCoreEnvironment.createForTests(disposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
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);
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.cli.jvm.compiler.CliLightClassGenerationSupport;
import org.jetbrains.kotlin.context.ModuleContext;
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.resolve.AnalyzingUtils;
import org.jetbrains.kotlin.resolve.BindingTrace;
@@ -71,6 +72,6 @@ public class JvmResolveUtil {
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.context.ModuleContext;
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.SpecialNames;
import org.jetbrains.kotlin.psi.JetFile;
@@ -47,15 +48,21 @@ public class LazyResolveTestUtil {
@NotNull
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
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");
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationNoIncremental(
moduleContext, sourceFiles, trace, TopDownAnalysisMode.TopLevelDeclarations
moduleContext, sourceFiles, trace, TopDownAnalysisMode.TopLevelDeclarations,
packageMappingProvider
);
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.jvm.compiler.LoadDescriptorUtil
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.resolve.jvm.TopDownAnalyzerFacadeForJVM
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
@@ -59,7 +60,7 @@ public abstract class AbstractLocalClassProtoTest : TestCaseWithTmpdir() {
val container = createContainerForTopDownAnalyzerForJvm(
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)
@@ -30,7 +30,8 @@ import org.jetbrains.kotlin.utils.emptyOrSingletonList
public class LazyJavaPackageFragmentProvider(
components: JavaResolverComponents,
module: ModuleDescriptor,
reflectionTypes: ReflectionTypes
reflectionTypes: ReflectionTypes,
packageMapper: PackageMappingProvider
) : PackageFragmentProvider {
private val c =
@@ -41,7 +42,7 @@ public class LazyJavaPackageFragmentProvider(
fqName ->
val jPackage = c.components.finder.findPackage(fqName)
if (jPackage != null) {
LazyJavaPackageFragment(c, jPackage)
LazyJavaPackageFragment(c, jPackage, packageMapper)
}
else null
}
@@ -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()
// }
// }
// }
//}
@@ -19,7 +19,9 @@ package org.jetbrains.kotlin.load.java.lazy.descriptors
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
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.kotlin.KotlinJvmBinarySourceElement
import org.jetbrains.kotlin.resolve.scopes.DecapitalizedAnnotationScope
@@ -27,7 +29,8 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope
class LazyJavaPackageFragment(
private val c: LazyJavaResolverContext,
private val jPackage: JavaPackage
private val jPackage: JavaPackage,
val packageMapper: PackageMappingProvider
) : PackageFragmentDescriptorImpl(c.module, jPackage.getFqName()) {
val scope: LazyJavaPackageScope by lazy { LazyJavaPackageScope(c, jPackage, this) }
// Just a temporary hack to inject deprecated decapitalized annotation
@@ -52,8 +52,14 @@ public class LazyJavaPackageScope(
val kotlinBinaryClass = kotlinBinaryClass
if (kotlinBinaryClass == null)
JetScope.Empty
else
c.components.deserializedDescriptorResolver.createKotlinPackageScope(packageFragment, kotlinBinaryClass) ?: JetScope.Empty
else {
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
@@ -30,15 +30,49 @@ public class ModuleMapping(val moduleMapping: String) {
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) {
val parts = hashSetOf<String>()
val parts = linkedSetOf<String>()
fun serialize(out: Writer) {
for (i in parts) {
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
}
}
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.load.java.components.*
import org.jetbrains.kotlin.load.java.lazy.JavaResolverComponents
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.reflect.ReflectJavaClassFinder
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,
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 javaClassDataFinder = JavaClassDataFinder(reflectKotlinClassFinder, deserializedDescriptorResolver)
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()
}
}
}
}
@@ -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.js.analyze.TopDownAnalyzerFacadeForJS
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.TargetEnvironment
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
@@ -45,7 +46,8 @@ public object JsAnalyzerFacade : AnalyzerFacade<PlatformAnalysisParameters>() {
moduleContent: ModuleContent,
platformParameters: PlatformAnalysisParameters,
targetEnvironment: TargetEnvironment,
resolverForProject: ResolverForProject<M>
resolverForProject: ResolverForProject<M>,
packageMappingProvider: PackageMappingProvider
): ResolverForModule {
val (syntheticFiles, moduleContentScope) = moduleContent
val project = moduleContext.project
@@ -63,7 +63,8 @@ fun createModuleResolverProvider(
val resolverForProject = analyzerFacade.setupResolverForProject(
globalContext.withProject(project), modulesToCreateResolversFor, modulesContent,
jvmPlatformParameters, IdeaEnvironment, delegateResolver
jvmPlatformParameters, IdeaEnvironment, delegateResolver,
{ (m, c) -> IDEPackageMappingProvider(c.moduleContentScope) }
)
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
}
}
}
}
+1
View File
@@ -506,6 +506,7 @@
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.versions.KotlinJavaScriptAbiVersionIndex"/>
<fileBasedIndex implementation="org.jetbrains.kotlin.idea.vfilefinder.KotlinClassFileIndex"/>
<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"/>
<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.vfilefinder.KotlinClassFileIndex
import org.jetbrains.kotlin.idea.vfilefinder.KotlinJavaScriptMetaFileIndex
import org.jetbrains.kotlin.idea.vfilefinder.KotlinModuleMappingIndex
import org.jetbrains.kotlin.utils.PathUtil
import java.io.File
@@ -65,6 +66,7 @@ class KotlinUpdatePluginComponent : ApplicationComponent {
fileBasedIndex.requestRebuild(KotlinJavaScriptAbiVersionIndex.getName())
fileBasedIndex.requestRebuild(KotlinClassFileIndex.KEY)
fileBasedIndex.requestRebuild(KotlinJavaScriptMetaFileIndex.KEY)
fileBasedIndex.requestRebuild(KotlinModuleMappingIndex.KEY)
PropertiesComponent.getInstance()?.setValue(INSTALLED_KOTLIN_VERSION, JetPluginUtil.getPluginVersion())
}
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.BindingTraceContext
import org.jetbrains.kotlin.resolve.jvm.TopDownAnalyzerFacadeForJVM
import org.jetbrains.kotlin.load.java.lazy.PackageMappingProvider
public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() {
@@ -41,7 +42,7 @@ public class DecompiledTextConsistencyTest : TextConsistencyBaseTest() {
override fun getModuleDescriptor(): ModuleDescriptor =
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegrationWithCustomContext(
TopDownAnalyzerFacadeForJVM.createContextWithSealedModule(getProject(), "test"),
listOf(), BindingTraceContext(), null, null
listOf(), BindingTraceContext(), null, null, PackageMappingProvider.EMPTY
).moduleDescriptor
override fun getProjectDescriptor() = object : JetWithJdkAndRuntimeLightProjectDescriptor() {