Implement modules in IDE
IDE: Rewrite AnalyzerFacade and implementations for JS and JVM to support creating separate analyzers for each module Introduce ModuleInfo which is an intermediate entity between configuration (tests or idea modules) and ModuleDescriptor Implement IdeaModuleInfos which represent IDEA modules, sdks and libraries Add (somewhat thin) test checking their behaviour Implement getModuleInfo() - utility to obtain IdeaModuleInfo for PsiElement Drop Project.getLazyResolveSession() - not possible to obtain resolve session for the whole project any more Adjust JavaResolveExtension accordingly KotlinSignature Intention/Marker - make sure that analyzed element is cls element (he's not in resolve scope otherwise) LightClasses: Create separate package light classes for each module Java code can only reference light class from the first module among it's dependencies Duplicate jvm signature is only reported on package declarations inside one module Injectors: Receive GlobalSearchScope as paramer for VirtualFileFinder and JavaClassFinder which allows to narrow analyzer scope JDR: Introduce ModuleClassResolver resolves java classes in correct java descriptor resolver (corresponding ModuleDescriptor) Add test checking that java classes belong to correct module Debugger: Provide context to analyze files created by debugger in Converter: Postprocessor now needs a context to analyze resulting code in JetPsiFactory: Add verification that files created by psi factory are not analyzed without context (that is almost never a good idea) Other: Use new API in various tests, utilities, run configuration producers and builtin serializers Various "TODO: (module refactoring)" which mark the unfinished parts
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="cli" />
|
||||
<orderEntry type="module" module-name="frontend" />
|
||||
<orderEntry type="module" module-name="frontend.java" />
|
||||
<orderEntry type="module" module-name="serialization" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
|
||||
@@ -36,12 +36,16 @@ import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys
|
||||
import org.jetbrains.jet.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.utils.recursePostOrder
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnalyzerFacade
|
||||
import org.jetbrains.jet.context.GlobalContext
|
||||
import org.jetbrains.jet.analyzer.ModuleInfo
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPlatformParameters
|
||||
import org.jetbrains.jet.analyzer.ModuleContent
|
||||
|
||||
public class BuiltInsSerializer(val out: PrintStream?) {
|
||||
private var totalSize = 0
|
||||
@@ -57,6 +61,12 @@ public class BuiltInsSerializer(val out: PrintStream?) {
|
||||
}
|
||||
}
|
||||
|
||||
private class BuiltinsSourcesModule : ModuleInfo {
|
||||
override val name: Name = Name.special("<module for resolving builtin source files>")
|
||||
override fun dependencies() = listOf(this)
|
||||
override fun dependencyOnBuiltins(): ModuleInfo.DependencyOnBuiltins = ModuleInfo.DependenciesOnBuiltins.NONE
|
||||
}
|
||||
|
||||
fun serialize(disposable: Disposable, destDir: File, srcDirs: Collection<File>) {
|
||||
val configuration = CompilerConfiguration()
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
|
||||
@@ -68,8 +78,14 @@ public class BuiltInsSerializer(val out: PrintStream?) {
|
||||
|
||||
val files = environment.getSourceFiles()
|
||||
|
||||
val session = AnalyzerFacadeForJVM.createLazyResolveSession(environment.getProject(), files, BindingTraceContext(), false)
|
||||
val module = session.getModuleDescriptor()
|
||||
val builtInModule = BuiltinsSourcesModule()
|
||||
val resolver = JvmAnalyzerFacade.setupResolverForProject(
|
||||
GlobalContext(), environment.getProject(), listOf(builtInModule),
|
||||
{ ModuleContent(files, GlobalSearchScope.EMPTY_SCOPE) },
|
||||
platformParameters = JvmPlatformParameters { throw IllegalStateException() }
|
||||
)
|
||||
|
||||
val moduleDescriptor = resolver.descriptorForModule(builtInModule)
|
||||
|
||||
// We don't use FileUtil because it spawns JNA initialization, which fails because we don't have (and don't want to have) its
|
||||
// native libraries in the compiler jar (libjnidispatch.so / jnidispatch.dll / ...)
|
||||
@@ -81,7 +97,7 @@ public class BuiltInsSerializer(val out: PrintStream?) {
|
||||
|
||||
files.map { it.getPackageFqName() }.toSet().forEach {
|
||||
fqName ->
|
||||
serializePackage(module, fqName, destDir)
|
||||
serializePackage(moduleDescriptor, fqName, destDir)
|
||||
}
|
||||
|
||||
out?.println("Total bytes written: $totalSize to $totalFiles files")
|
||||
|
||||
+9
-3
@@ -45,9 +45,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This class solves the problem of interdependency between analyzing Kotlin code and generating JetLightClasses
|
||||
@@ -192,6 +190,14 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<KotlinLightPackageClassInfo> findPackageClassesInfos(
|
||||
@NotNull FqName fqName, @NotNull GlobalSearchScope wholeScope
|
||||
) {
|
||||
return Collections.singletonList(new KotlinLightPackageClassInfo(findFilesForPackage(fqName, wholeScope), wholeScope));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean packageExists(@NotNull FqName fqName, @NotNull GlobalSearchScope scope) {
|
||||
return getModule().getPackage(fqName) != null;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<orderEntry type="library" name="javax.inject" level="project" />
|
||||
<orderEntry type="module" module-name="serialization" />
|
||||
<orderEntry type="module" module-name="serialization.java" />
|
||||
<orderEntry type="module" module-name="descriptor.loader.java" />
|
||||
<orderEntry type="module" module-name="descriptor.loader.java" exported="" />
|
||||
<orderEntry type="module" module-name="util.runtime" />
|
||||
<orderEntry type="module" module-name="util" />
|
||||
</component>
|
||||
|
||||
+10
-1
@@ -23,6 +23,7 @@ import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaClassFinderImpl;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedExternalSignatureResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedJavaResolverCache;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedErrorReporter;
|
||||
@@ -30,6 +31,7 @@ import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedMethodSignatureCheck
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedExternalAnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaPropertyInitializerEvaluatorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaSourceElementFactoryImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.SingleModuleClassResolver;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaPackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.GlobalJavaResolverContext;
|
||||
@@ -53,6 +55,7 @@ public class InjectorForJavaDescriptorResolver {
|
||||
private final ModuleDescriptorImpl module;
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
private final JavaClassFinderImpl javaClassFinder;
|
||||
private final GlobalSearchScope globalSearchScope;
|
||||
private final TraceBasedExternalSignatureResolver traceBasedExternalSignatureResolver;
|
||||
private final TraceBasedJavaResolverCache traceBasedJavaResolverCache;
|
||||
private final TraceBasedErrorReporter traceBasedErrorReporter;
|
||||
@@ -60,6 +63,7 @@ public class InjectorForJavaDescriptorResolver {
|
||||
private final PsiBasedExternalAnnotationResolver psiBasedExternalAnnotationResolver;
|
||||
private final JavaPropertyInitializerEvaluatorImpl javaPropertyInitializerEvaluator;
|
||||
private final JavaSourceElementFactoryImpl javaSourceElementFactory;
|
||||
private final SingleModuleClassResolver singleModuleClassResolver;
|
||||
private final VirtualFileFinder virtualFileFinder;
|
||||
private final LazyJavaPackageFragmentProvider lazyJavaPackageFragmentProvider;
|
||||
private final GlobalJavaResolverContext globalJavaResolverContext;
|
||||
@@ -89,9 +93,11 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.traceBasedJavaResolverCache = new TraceBasedJavaResolverCache();
|
||||
this.javaPropertyInitializerEvaluator = new JavaPropertyInitializerEvaluatorImpl();
|
||||
this.javaSourceElementFactory = new JavaSourceElementFactoryImpl();
|
||||
this.globalJavaResolverContext = new GlobalJavaResolverContext(lockBasedStorageManager, getJavaClassFinder(), virtualFileFinder, deserializedDescriptorResolver, psiBasedExternalAnnotationResolver, traceBasedExternalSignatureResolver, traceBasedErrorReporter, psiBasedMethodSignatureChecker, traceBasedJavaResolverCache, javaPropertyInitializerEvaluator, javaSourceElementFactory);
|
||||
this.singleModuleClassResolver = new SingleModuleClassResolver();
|
||||
this.globalJavaResolverContext = new GlobalJavaResolverContext(lockBasedStorageManager, getJavaClassFinder(), virtualFileFinder, deserializedDescriptorResolver, psiBasedExternalAnnotationResolver, traceBasedExternalSignatureResolver, traceBasedErrorReporter, psiBasedMethodSignatureChecker, traceBasedJavaResolverCache, javaPropertyInitializerEvaluator, javaSourceElementFactory, singleModuleClassResolver);
|
||||
this.lazyJavaPackageFragmentProvider = new LazyJavaPackageFragmentProvider(globalJavaResolverContext, getModule());
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver(lazyJavaPackageFragmentProvider, getModule());
|
||||
this.globalSearchScope = com.intellij.psi.search.GlobalSearchScope.allScope(project);
|
||||
this.javaClassDataFinder = new JavaClassDataFinder(virtualFileFinder, deserializedDescriptorResolver);
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader();
|
||||
this.constantDescriptorLoader = new ConstantDescriptorLoader();
|
||||
@@ -99,6 +105,7 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.descriptorLoadersStorage = new DescriptorLoadersStorage(lockBasedStorageManager);
|
||||
|
||||
this.javaClassFinder.setProject(project);
|
||||
this.javaClassFinder.setScope(globalSearchScope);
|
||||
|
||||
traceBasedExternalSignatureResolver.setExternalAnnotationResolver(psiBasedExternalAnnotationResolver);
|
||||
traceBasedExternalSignatureResolver.setProject(project);
|
||||
@@ -111,6 +118,8 @@ public class InjectorForJavaDescriptorResolver {
|
||||
psiBasedMethodSignatureChecker.setExternalAnnotationResolver(psiBasedExternalAnnotationResolver);
|
||||
psiBasedMethodSignatureChecker.setExternalSignatureResolver(traceBasedExternalSignatureResolver);
|
||||
|
||||
singleModuleClassResolver.setResolver(javaDescriptorResolver);
|
||||
|
||||
deserializedDescriptorResolver.setContext(deserializationGlobalContextForJava);
|
||||
deserializedDescriptorResolver.setErrorReporter(traceBasedErrorReporter);
|
||||
|
||||
|
||||
+34
-28
@@ -17,12 +17,14 @@
|
||||
package org.jetbrains.jet.di;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.context.GlobalContextImpl;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.context.GlobalContext;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.ModuleClassResolver;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||
@@ -70,12 +72,14 @@ import javax.annotation.PreDestroy;
|
||||
public class InjectorForLazyResolveWithJava {
|
||||
|
||||
private final Project project;
|
||||
private final GlobalContextImpl globalContext;
|
||||
private final LockBasedStorageManager lockBasedStorageManager;
|
||||
private final DeclarationProviderFactory declarationProviderFactory;
|
||||
private final BindingTrace bindingTrace;
|
||||
private final GlobalContext globalContext;
|
||||
private final StorageManager storageManager;
|
||||
private final ModuleDescriptorImpl module;
|
||||
private final PlatformToKotlinClassMap platformToKotlinClassMap;
|
||||
private final GlobalSearchScope moduleContentScope;
|
||||
private final BindingTrace bindingTrace;
|
||||
private final DeclarationProviderFactory declarationProviderFactory;
|
||||
private final ModuleClassResolver moduleClassResolver;
|
||||
private final ResolveSession resolveSession;
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
private final VirtualFileFinder virtualFileFinder;
|
||||
@@ -118,20 +122,25 @@ public class InjectorForLazyResolveWithJava {
|
||||
|
||||
public InjectorForLazyResolveWithJava(
|
||||
@NotNull Project project,
|
||||
@NotNull GlobalContextImpl globalContext,
|
||||
@NotNull GlobalContext globalContext,
|
||||
@NotNull ModuleDescriptorImpl module,
|
||||
@NotNull GlobalSearchScope moduleContentScope,
|
||||
@NotNull BindingTrace bindingTrace,
|
||||
@NotNull DeclarationProviderFactory declarationProviderFactory,
|
||||
@NotNull BindingTrace bindingTrace
|
||||
@NotNull ModuleClassResolver moduleClassResolver
|
||||
) {
|
||||
this.project = project;
|
||||
this.globalContext = globalContext;
|
||||
this.lockBasedStorageManager = globalContext.getStorageManager();
|
||||
this.declarationProviderFactory = declarationProviderFactory;
|
||||
this.bindingTrace = bindingTrace;
|
||||
this.module = org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM.createJavaModule("<fake-jdr-module>");
|
||||
this.storageManager = globalContext.getStorageManager();
|
||||
this.module = module;
|
||||
this.platformToKotlinClassMap = module.getPlatformToKotlinClassMap();
|
||||
this.resolveSession = new ResolveSession(project, globalContext, getModule(), declarationProviderFactory, bindingTrace);
|
||||
this.moduleContentScope = moduleContentScope;
|
||||
this.bindingTrace = bindingTrace;
|
||||
this.declarationProviderFactory = declarationProviderFactory;
|
||||
this.moduleClassResolver = moduleClassResolver;
|
||||
this.resolveSession = new ResolveSession(project, globalContext, module, declarationProviderFactory, bindingTrace);
|
||||
this.javaClassFinder = new JavaClassFinderImpl();
|
||||
this.virtualFileFinder = org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder.SERVICE.getInstance(project);
|
||||
this.virtualFileFinder = org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinderFactory.SERVICE.getInstance(project).create(moduleContentScope);
|
||||
this.deserializedDescriptorResolver = new DeserializedDescriptorResolver();
|
||||
this.psiBasedExternalAnnotationResolver = new PsiBasedExternalAnnotationResolver();
|
||||
this.traceBasedExternalSignatureResolver = new TraceBasedExternalSignatureResolver();
|
||||
@@ -140,9 +149,9 @@ public class InjectorForLazyResolveWithJava {
|
||||
this.lazyResolveBasedCache = new LazyResolveBasedCache();
|
||||
this.javaPropertyInitializerEvaluator = new JavaPropertyInitializerEvaluatorImpl();
|
||||
this.javaSourceElementFactory = new JavaSourceElementFactoryImpl();
|
||||
this.globalJavaResolverContext = new GlobalJavaResolverContext(lockBasedStorageManager, javaClassFinder, virtualFileFinder, deserializedDescriptorResolver, psiBasedExternalAnnotationResolver, traceBasedExternalSignatureResolver, traceBasedErrorReporter, psiBasedMethodSignatureChecker, lazyResolveBasedCache, javaPropertyInitializerEvaluator, javaSourceElementFactory);
|
||||
this.lazyJavaPackageFragmentProvider = new LazyJavaPackageFragmentProvider(globalJavaResolverContext, getModule());
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver(lazyJavaPackageFragmentProvider, getModule());
|
||||
this.globalJavaResolverContext = new GlobalJavaResolverContext(storageManager, javaClassFinder, virtualFileFinder, deserializedDescriptorResolver, psiBasedExternalAnnotationResolver, traceBasedExternalSignatureResolver, traceBasedErrorReporter, psiBasedMethodSignatureChecker, lazyResolveBasedCache, javaPropertyInitializerEvaluator, javaSourceElementFactory, moduleClassResolver);
|
||||
this.lazyJavaPackageFragmentProvider = new LazyJavaPackageFragmentProvider(globalJavaResolverContext, module);
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver(lazyJavaPackageFragmentProvider, module);
|
||||
this.annotationResolver = new AnnotationResolver();
|
||||
this.callResolver = new CallResolver();
|
||||
this.argumentTypeResolver = new ArgumentTypeResolver();
|
||||
@@ -151,7 +160,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
this.controlStructureTypingUtils = new ControlStructureTypingUtils(expressionTypingServices);
|
||||
this.expressionTypingUtils = new ExpressionTypingUtils(expressionTypingServices, callResolver);
|
||||
this.forLoopConventionsChecker = new ForLoopConventionsChecker();
|
||||
this.reflectionTypes = new ReflectionTypes(getModule());
|
||||
this.reflectionTypes = new ReflectionTypes(module);
|
||||
this.callExpressionResolver = new CallExpressionResolver();
|
||||
this.descriptorResolver = new DescriptorResolver();
|
||||
this.delegatedPropertyResolver = new DelegatedPropertyResolver();
|
||||
@@ -166,8 +175,8 @@ public class InjectorForLazyResolveWithJava {
|
||||
this.javaClassDataFinder = new JavaClassDataFinder(virtualFileFinder, deserializedDescriptorResolver);
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader();
|
||||
this.constantDescriptorLoader = new ConstantDescriptorLoader();
|
||||
this.deserializationGlobalContextForJava = new DeserializationGlobalContextForJava(lockBasedStorageManager, getModule(), javaClassDataFinder, annotationDescriptorLoader, constantDescriptorLoader, lazyJavaPackageFragmentProvider);
|
||||
this.descriptorLoadersStorage = new DescriptorLoadersStorage(lockBasedStorageManager);
|
||||
this.deserializationGlobalContextForJava = new DeserializationGlobalContextForJava(storageManager, module, javaClassDataFinder, annotationDescriptorLoader, constantDescriptorLoader, lazyJavaPackageFragmentProvider);
|
||||
this.descriptorLoadersStorage = new DescriptorLoadersStorage(storageManager);
|
||||
|
||||
this.resolveSession.setAnnotationResolve(annotationResolver);
|
||||
this.resolveSession.setDescriptorResolver(descriptorResolver);
|
||||
@@ -178,6 +187,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
this.resolveSession.setTypeResolver(typeResolver);
|
||||
|
||||
javaClassFinder.setProject(project);
|
||||
javaClassFinder.setScope(moduleContentScope);
|
||||
|
||||
traceBasedExternalSignatureResolver.setExternalAnnotationResolver(psiBasedExternalAnnotationResolver);
|
||||
traceBasedExternalSignatureResolver.setProject(project);
|
||||
@@ -191,7 +201,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
psiBasedMethodSignatureChecker.setExternalSignatureResolver(traceBasedExternalSignatureResolver);
|
||||
|
||||
annotationResolver.setCallResolver(callResolver);
|
||||
annotationResolver.setStorageManager(lockBasedStorageManager);
|
||||
annotationResolver.setStorageManager(storageManager);
|
||||
annotationResolver.setTypeResolver(typeResolver);
|
||||
|
||||
callResolver.setArgumentTypeResolver(argumentTypeResolver);
|
||||
@@ -229,7 +239,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
descriptorResolver.setAnnotationResolver(annotationResolver);
|
||||
descriptorResolver.setDelegatedPropertyResolver(delegatedPropertyResolver);
|
||||
descriptorResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
descriptorResolver.setStorageManager(lockBasedStorageManager);
|
||||
descriptorResolver.setStorageManager(storageManager);
|
||||
descriptorResolver.setTypeResolver(typeResolver);
|
||||
|
||||
delegatedPropertyResolver.setCallResolver(callResolver);
|
||||
@@ -268,10 +278,6 @@ public class InjectorForLazyResolveWithJava {
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public ModuleDescriptorImpl getModule() {
|
||||
return this.module;
|
||||
}
|
||||
|
||||
public ResolveSession getResolveSession() {
|
||||
return this.resolveSession;
|
||||
}
|
||||
|
||||
+10
-1
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.LazyTopDownAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.MutablePackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.DeserializationGlobalContextForJava;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaClassFinderImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedExternalSignatureResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.TraceBasedJavaResolverCache;
|
||||
@@ -35,6 +36,7 @@ import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedMethodSignatureCheck
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedExternalAnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaPropertyInitializerEvaluatorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaSourceElementFactoryImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.SingleModuleClassResolver;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinder;
|
||||
import org.jetbrains.jet.lang.resolve.BodyResolver;
|
||||
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
|
||||
@@ -90,6 +92,7 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
private final MutablePackageFragmentProvider mutablePackageFragmentProvider;
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
private final DeserializationGlobalContextForJava deserializationGlobalContextForJava;
|
||||
private final GlobalSearchScope globalSearchScope;
|
||||
private final JavaClassFinderImpl javaClassFinder;
|
||||
private final TraceBasedExternalSignatureResolver traceBasedExternalSignatureResolver;
|
||||
private final TraceBasedJavaResolverCache traceBasedJavaResolverCache;
|
||||
@@ -98,6 +101,7 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
private final PsiBasedExternalAnnotationResolver psiBasedExternalAnnotationResolver;
|
||||
private final JavaPropertyInitializerEvaluatorImpl javaPropertyInitializerEvaluator;
|
||||
private final JavaSourceElementFactoryImpl javaSourceElementFactory;
|
||||
private final SingleModuleClassResolver singleModuleClassResolver;
|
||||
private final VirtualFileFinder virtualFileFinder;
|
||||
private final BodyResolver bodyResolver;
|
||||
private final AnnotationResolver annotationResolver;
|
||||
@@ -161,13 +165,15 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.traceBasedJavaResolverCache = new TraceBasedJavaResolverCache();
|
||||
this.javaPropertyInitializerEvaluator = new JavaPropertyInitializerEvaluatorImpl();
|
||||
this.javaSourceElementFactory = new JavaSourceElementFactoryImpl();
|
||||
this.globalJavaResolverContext = new GlobalJavaResolverContext(storageManager, javaClassFinder, virtualFileFinder, deserializedDescriptorResolver, psiBasedExternalAnnotationResolver, traceBasedExternalSignatureResolver, traceBasedErrorReporter, psiBasedMethodSignatureChecker, traceBasedJavaResolverCache, javaPropertyInitializerEvaluator, javaSourceElementFactory);
|
||||
this.singleModuleClassResolver = new SingleModuleClassResolver();
|
||||
this.globalJavaResolverContext = new GlobalJavaResolverContext(storageManager, javaClassFinder, virtualFileFinder, deserializedDescriptorResolver, psiBasedExternalAnnotationResolver, traceBasedExternalSignatureResolver, traceBasedErrorReporter, psiBasedMethodSignatureChecker, traceBasedJavaResolverCache, javaPropertyInitializerEvaluator, javaSourceElementFactory, singleModuleClassResolver);
|
||||
this.lazyJavaPackageFragmentProvider = new LazyJavaPackageFragmentProvider(globalJavaResolverContext, getModuleDescriptor());
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver(lazyJavaPackageFragmentProvider, getModuleDescriptor());
|
||||
this.javaClassDataFinder = new JavaClassDataFinder(virtualFileFinder, deserializedDescriptorResolver);
|
||||
this.annotationDescriptorLoader = new AnnotationDescriptorLoader();
|
||||
this.constantDescriptorLoader = new ConstantDescriptorLoader();
|
||||
this.deserializationGlobalContextForJava = new DeserializationGlobalContextForJava(storageManager, getModuleDescriptor(), javaClassDataFinder, annotationDescriptorLoader, constantDescriptorLoader, lazyJavaPackageFragmentProvider);
|
||||
this.globalSearchScope = com.intellij.psi.search.GlobalSearchScope.allScope(project);
|
||||
this.bodyResolver = new BodyResolver();
|
||||
this.annotationResolver = new AnnotationResolver();
|
||||
this.callResolver = new CallResolver();
|
||||
@@ -218,6 +224,7 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
this.lazyTopDownAnalyzer.setTrace(bindingTrace);
|
||||
|
||||
javaClassFinder.setProject(project);
|
||||
javaClassFinder.setScope(globalSearchScope);
|
||||
|
||||
traceBasedExternalSignatureResolver.setExternalAnnotationResolver(psiBasedExternalAnnotationResolver);
|
||||
traceBasedExternalSignatureResolver.setProject(project);
|
||||
@@ -230,6 +237,8 @@ public class InjectorForTopDownAnalyzerForJvm implements InjectorForTopDownAnaly
|
||||
psiBasedMethodSignatureChecker.setExternalAnnotationResolver(psiBasedExternalAnnotationResolver);
|
||||
psiBasedMethodSignatureChecker.setExternalSignatureResolver(traceBasedExternalSignatureResolver);
|
||||
|
||||
singleModuleClassResolver.setResolver(javaDescriptorResolver);
|
||||
|
||||
bodyResolver.setAnnotationResolver(annotationResolver);
|
||||
bodyResolver.setCallResolver(callResolver);
|
||||
bodyResolver.setControlFlowAnalyzer(controlFlowAnalyzer);
|
||||
|
||||
+4
-91
@@ -19,41 +19,30 @@ package org.jetbrains.jet.lang.resolve.java;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade;
|
||||
import org.jetbrains.jet.context.ContextPackage;
|
||||
import org.jetbrains.jet.context.GlobalContext;
|
||||
import org.jetbrains.jet.context.GlobalContextImpl;
|
||||
import org.jetbrains.jet.di.InjectorForLazyResolveWithJava;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.CompositePackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalPackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.IncrementalCache;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.IncrementalCacheProvider;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
public enum AnalyzerFacadeForJVM {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -64,85 +53,9 @@ public enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
new ImportPath("kotlin.io.*")
|
||||
);
|
||||
|
||||
public static class JvmSetup extends BasicSetup {
|
||||
|
||||
private final JavaDescriptorResolver javaDescriptorResolver;
|
||||
|
||||
public JvmSetup(@NotNull ResolveSession session, @NotNull JavaDescriptorResolver javaDescriptorResolver) {
|
||||
super(session);
|
||||
this.javaDescriptorResolver = javaDescriptorResolver;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JavaDescriptorResolver getJavaDescriptorResolver() {
|
||||
return javaDescriptorResolver;
|
||||
}
|
||||
}
|
||||
|
||||
private AnalyzerFacadeForJVM() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JvmSetup createSetup(
|
||||
@NotNull Project fileProject,
|
||||
@NotNull Collection<JetFile> syntheticFiles,
|
||||
@NotNull GlobalSearchScope filesScope
|
||||
) {
|
||||
return createSetup(fileProject, syntheticFiles, filesScope, new BindingTraceContext(), true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolveSession createLazyResolveSession(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull BindingTrace trace,
|
||||
boolean addBuiltIns
|
||||
) {
|
||||
List<VirtualFile> virtualFiles = KotlinPackage.map(files, new Function1<JetFile, VirtualFile>() {
|
||||
@Override
|
||||
public VirtualFile invoke(JetFile file) {
|
||||
return file.getVirtualFile();
|
||||
}
|
||||
});
|
||||
return createSetup(project, Collections.<JetFile>emptyList(),
|
||||
GlobalSearchScope.filesScope(project, virtualFiles), trace, addBuiltIns).getLazyResolveSession();
|
||||
}
|
||||
|
||||
public static JvmSetup createSetup(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> syntheticFiles,
|
||||
@NotNull GlobalSearchScope filesScope,
|
||||
@NotNull BindingTrace trace,
|
||||
boolean addBuiltIns
|
||||
) {
|
||||
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
|
||||
|
||||
DeclarationProviderFactory declarationProviderFactory = DeclarationProviderFactoryService.OBJECT$
|
||||
.createDeclarationProviderFactory(project, globalContext.getStorageManager(), syntheticFiles, filesScope);
|
||||
|
||||
InjectorForLazyResolveWithJava resolveWithJava = new InjectorForLazyResolveWithJava(
|
||||
project,
|
||||
globalContext,
|
||||
declarationProviderFactory,
|
||||
trace);
|
||||
|
||||
ModuleDescriptorImpl module = resolveWithJava.getModule();
|
||||
module.initialize(
|
||||
new CompositePackageFragmentProvider(
|
||||
Arrays.asList(
|
||||
resolveWithJava.getResolveSession().getPackageFragmentProvider(),
|
||||
resolveWithJava.getJavaDescriptorResolver().getPackageFragmentProvider()
|
||||
)));
|
||||
|
||||
module.addDependencyOnModule(module);
|
||||
if (addBuiltIns) {
|
||||
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule());
|
||||
}
|
||||
module.seal();
|
||||
return new JvmSetup(resolveWithJava.getResolveSession(), resolveWithJava.getJavaDescriptorResolver());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
|
||||
Project project,
|
||||
|
||||
+9
-1
@@ -38,6 +38,8 @@ import javax.inject.Inject;
|
||||
public class JavaClassFinderImpl implements JavaClassFinder {
|
||||
@NotNull
|
||||
private Project project;
|
||||
@NotNull
|
||||
private GlobalSearchScope baseScope;
|
||||
|
||||
private GlobalSearchScope javaSearchScope;
|
||||
private JavaPsiFacadeKotlinHacks javaFacade;
|
||||
@@ -47,9 +49,14 @@ public class JavaClassFinderImpl implements JavaClassFinder {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setScope(@NotNull GlobalSearchScope scope) {
|
||||
this.baseScope = scope;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
||||
javaSearchScope = new DelegatingGlobalSearchScope(baseScope) {
|
||||
@Override
|
||||
public boolean contains(VirtualFile file) {
|
||||
return myBaseScope.contains(file) && file.getFileType() != JetFileType.INSTANCE;
|
||||
@@ -57,6 +64,7 @@ public class JavaClassFinderImpl implements JavaClassFinder {
|
||||
|
||||
@Override
|
||||
public int compare(VirtualFile file1, VirtualFile file2) {
|
||||
//TODO_r: delete this code?
|
||||
// TODO: this is a hackish workaround for the following problem:
|
||||
// since we are working with the allScope(), if the same class FqName
|
||||
// to be on the class path twice, because it is included into different libraries
|
||||
|
||||
+7
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.resolve.java;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.core.CoreJavaFileManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider;
|
||||
import com.intellij.openapi.project.Project;
|
||||
@@ -41,9 +42,11 @@ public class JavaPsiFacadeKotlinHacks {
|
||||
|
||||
private final JavaFileManager javaFileManager;
|
||||
private final List<PsiElementFinder> extensionPsiElementFinders;
|
||||
private final boolean isCoreJavaFileManager;
|
||||
|
||||
public JavaPsiFacadeKotlinHacks(@NotNull Project project) {
|
||||
this.javaFileManager = findJavaFileManager(project);
|
||||
this.isCoreJavaFileManager = javaFileManager instanceof CoreJavaFileManager;
|
||||
this.extensionPsiElementFinders = Lists.newArrayList();
|
||||
for (PsiElementFinder finder : project.getExtensions(PsiElementFinder.EP_NAME)) {
|
||||
if (!(finder instanceof KotlinFinderMarker)) {
|
||||
@@ -82,7 +85,10 @@ public class JavaPsiFacadeKotlinHacks {
|
||||
|
||||
PsiClass aClass = javaFileManager.findClass(qualifiedName, scope);
|
||||
if (aClass != null) {
|
||||
return aClass;
|
||||
//TODO: (module refactoring) CoreJavaFileManager should check scope
|
||||
if (!isCoreJavaFileManager || scope.contains(aClass.getContainingFile().getOriginalFile().getVirtualFile())) {
|
||||
return aClass;
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiElementFinder finder : extensionPsiElementFinders) {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.resolve.java
|
||||
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacade
|
||||
import org.jetbrains.jet.analyzer.ResolverForModule
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.jet.analyzer.PlatformAnalysisParameters
|
||||
import org.jetbrains.jet.analyzer.ResolverForProject
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactoryService
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jet.context.GlobalContext
|
||||
import org.jetbrains.jet.lang.descriptors.impl.CompositePackageFragmentProvider
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.ModuleClassResolverImpl
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.jet.analyzer.ModuleInfo
|
||||
import org.jetbrains.jet.analyzer.ModuleContent
|
||||
import org.jetbrains.jet.di.InjectorForLazyResolveWithJava
|
||||
|
||||
public class JvmResolverForModule(
|
||||
override val lazyResolveSession: ResolveSession,
|
||||
public val javaDescriptorResolver: JavaDescriptorResolver
|
||||
) : ResolverForModule
|
||||
|
||||
public class JvmPlatformParameters(
|
||||
public val moduleByJavaClass: (JavaClass) -> ModuleInfo
|
||||
) : PlatformAnalysisParameters
|
||||
|
||||
|
||||
public object JvmAnalyzerFacade : AnalyzerFacade<JvmResolverForModule, JvmPlatformParameters> {
|
||||
override fun <M : ModuleInfo> createResolverForModule(
|
||||
project: Project,
|
||||
globalContext: GlobalContext,
|
||||
moduleDescriptor: ModuleDescriptorImpl,
|
||||
moduleContent: ModuleContent,
|
||||
platformParameters: JvmPlatformParameters,
|
||||
resolverForProject: ResolverForProject<M, JvmResolverForModule>
|
||||
): JvmResolverForModule {
|
||||
val (syntheticFiles, moduleContentScope) = moduleContent
|
||||
val declarationProviderFactory = DeclarationProviderFactoryService.createDeclarationProviderFactory(
|
||||
project, globalContext.storageManager, syntheticFiles, moduleContentScope
|
||||
)
|
||||
|
||||
val moduleClassResolver = ModuleClassResolverImpl { javaClass ->
|
||||
val moduleInfo = platformParameters.moduleByJavaClass(javaClass)
|
||||
resolverForProject.resolverForModule(moduleInfo as M).javaDescriptorResolver
|
||||
}
|
||||
val injector = InjectorForLazyResolveWithJava(
|
||||
project, globalContext, moduleDescriptor, moduleContentScope, BindingTraceContext(), declarationProviderFactory, moduleClassResolver
|
||||
)
|
||||
|
||||
val resolveSession = injector.getResolveSession()!!
|
||||
val javaDescriptorResolver = injector.getJavaDescriptorResolver()!!
|
||||
val providersForModule = listOf(resolveSession.getPackageFragmentProvider(), javaDescriptorResolver.packageFragmentProvider)
|
||||
moduleDescriptor.initialize(CompositePackageFragmentProvider(providersForModule))
|
||||
return JvmResolverForModule(resolveSession, javaDescriptorResolver)
|
||||
}
|
||||
|
||||
override val defaultImports = AnalyzerFacadeForJVM.DEFAULT_IMPORTS
|
||||
override val platformToKotlinClassMap = JavaToKotlinClassMap.getInstance()
|
||||
|
||||
}
|
||||
+9
@@ -16,10 +16,19 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.kotlin;
|
||||
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface VirtualFileFinderFactory {
|
||||
@NotNull
|
||||
VirtualFileFinder create(@NotNull GlobalSearchScope scope);
|
||||
|
||||
class SERVICE {
|
||||
@NotNull
|
||||
public static VirtualFileFinderFactory getInstance(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, VirtualFileFinderFactory.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.analyzer;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface AnalyzerFacade {
|
||||
|
||||
interface Setup {
|
||||
@NotNull
|
||||
ResolveSession getLazyResolveSession();
|
||||
}
|
||||
|
||||
class BasicSetup implements Setup {
|
||||
|
||||
private final ResolveSession resolveSession;
|
||||
|
||||
public BasicSetup(@NotNull ResolveSession session) {
|
||||
resolveSession = session;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ResolveSession getLazyResolveSession() {
|
||||
return resolveSession;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Setup createSetup(
|
||||
@NotNull Project project,
|
||||
@NotNull Collection<JetFile> syntheticFiles,
|
||||
@NotNull GlobalSearchScope filesScope
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.analyzer
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import java.util.HashMap
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jet.context.GlobalContext
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
public trait ResolverForModule {
|
||||
public val lazyResolveSession: ResolveSession
|
||||
}
|
||||
|
||||
public trait ResolverForProject<M : ModuleInfo, R : ResolverForModule> {
|
||||
public fun resolverForModule(moduleInfo: M): R
|
||||
public fun descriptorForModule(moduleInfo: M): ModuleDescriptor
|
||||
}
|
||||
|
||||
public class ResolverForProjectImpl<M : ModuleInfo, R : ResolverForModule>(
|
||||
val descriptorByModule: Map<M, ModuleDescriptorImpl>
|
||||
) : ResolverForProject<M, R> {
|
||||
val resolverByModuleDescriptor: MutableMap<ModuleDescriptor, R> = HashMap()
|
||||
|
||||
private val allModules: Collection<M> by Delegates.lazy {
|
||||
descriptorByModule.keySet()
|
||||
}
|
||||
|
||||
private fun assertCorrectModuleInfo(moduleInfo: M) {
|
||||
if (moduleInfo !in allModules) {
|
||||
throw AssertionError("Requested data for $moduleInfo not contained in this resolver.\nThis resolver was created for following infos:\n${allModules.joinToString("\n")}")
|
||||
}
|
||||
}
|
||||
|
||||
override fun resolverForModule(moduleInfo: M): R {
|
||||
assertCorrectModuleInfo(moduleInfo)
|
||||
val descriptor = descriptorByModule[moduleInfo]!!
|
||||
return resolverByModuleDescriptor[descriptor]!!
|
||||
}
|
||||
|
||||
override fun descriptorForModule(moduleInfo: M): ModuleDescriptorImpl {
|
||||
assertCorrectModuleInfo(moduleInfo)
|
||||
return descriptorByModule[moduleInfo]!!
|
||||
}
|
||||
}
|
||||
|
||||
public data class ModuleContent(
|
||||
public val syntheticFiles: Collection<JetFile>,
|
||||
public val moduleContentScope: GlobalSearchScope
|
||||
)
|
||||
|
||||
public trait PlatformAnalysisParameters
|
||||
|
||||
public trait ModuleInfo {
|
||||
public val name: Name
|
||||
public fun dependencies(): List<ModuleInfo>
|
||||
public fun dependencyOnBuiltins(): DependencyOnBuiltins = DependenciesOnBuiltins.LAST
|
||||
|
||||
//TODO: (module refactoring) provide dependency on builtins after runtime in IDEA
|
||||
public trait DependencyOnBuiltins {
|
||||
public fun adjustDependencies(builtinsModule: ModuleDescriptorImpl, dependencies: MutableList<ModuleDescriptorImpl>)
|
||||
}
|
||||
|
||||
public enum class DependenciesOnBuiltins : DependencyOnBuiltins {
|
||||
|
||||
override fun adjustDependencies(builtinsModule: ModuleDescriptorImpl, dependencies: MutableList<ModuleDescriptorImpl>) {
|
||||
//TODO: KT-5457
|
||||
}
|
||||
|
||||
NONE {
|
||||
override fun adjustDependencies(builtinsModule: ModuleDescriptorImpl, dependencies: MutableList<ModuleDescriptorImpl>) {
|
||||
//do nothing
|
||||
}
|
||||
}
|
||||
LAST {
|
||||
override fun adjustDependencies(builtinsModule: ModuleDescriptorImpl, dependencies: MutableList<ModuleDescriptorImpl>) {
|
||||
dependencies.add(builtinsModule)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: (module refactoring) extract project context
|
||||
public trait AnalyzerFacade<out A : ResolverForModule, in P : PlatformAnalysisParameters> {
|
||||
public fun <M : ModuleInfo> setupResolverForProject(
|
||||
globalContext: GlobalContext,
|
||||
project: Project,
|
||||
modules: Collection<M>,
|
||||
modulesContent: (M) -> ModuleContent,
|
||||
platformParameters: P
|
||||
): ResolverForProject<M, A> {
|
||||
|
||||
fun createResolverForProject(): ResolverForProjectImpl<M, A> {
|
||||
val descriptorByModule = HashMap<M, ModuleDescriptorImpl>()
|
||||
modules.forEach {
|
||||
module ->
|
||||
descriptorByModule[module] = ModuleDescriptorImpl(module.name, defaultImports, platformToKotlinClassMap)
|
||||
}
|
||||
return ResolverForProjectImpl(descriptorByModule)
|
||||
}
|
||||
|
||||
val resolverForProject = createResolverForProject()
|
||||
|
||||
fun setupModuleDependencies() {
|
||||
modules.forEach {
|
||||
module ->
|
||||
val currentModule = resolverForProject.descriptorForModule(module)
|
||||
val dependenciesDescriptors = module.dependencies().mapTo(ArrayList<ModuleDescriptorImpl>()) {
|
||||
dependencyInfo ->
|
||||
resolverForProject.descriptorForModule(dependencyInfo as M)
|
||||
}
|
||||
|
||||
val builtinsModule = KotlinBuiltIns.getInstance().getBuiltInsModule()
|
||||
module.dependencyOnBuiltins().adjustDependencies(builtinsModule, dependenciesDescriptors)
|
||||
dependenciesDescriptors.forEach { currentModule.addDependencyOnModule(it) }
|
||||
}
|
||||
|
||||
resolverForProject.descriptorByModule.values().forEach { it.seal() }
|
||||
}
|
||||
|
||||
setupModuleDependencies()
|
||||
|
||||
fun initializeResolverForProject() {
|
||||
modules.forEach {
|
||||
module ->
|
||||
val descriptor = resolverForProject.descriptorForModule(module)
|
||||
val resolverForModule = createResolverForModule(
|
||||
project, globalContext, descriptor, modulesContent(module), platformParameters, resolverForProject
|
||||
)
|
||||
assert(descriptor.isInitialized, "ModuleDescriptorImpl#initialize() should be called in createResolverForModule")
|
||||
resolverForProject.resolverByModuleDescriptor[descriptor] = resolverForModule
|
||||
}
|
||||
}
|
||||
|
||||
initializeResolverForProject()
|
||||
return resolverForProject
|
||||
}
|
||||
|
||||
protected fun <M : ModuleInfo> createResolverForModule(
|
||||
project: Project,
|
||||
globalContext: GlobalContext,
|
||||
moduleDescriptor: ModuleDescriptorImpl,
|
||||
moduleContent: ModuleContent,
|
||||
platformParameters: P,
|
||||
resolverForProject: ResolverForProject<M, A>
|
||||
): A
|
||||
|
||||
public val defaultImports: List<ImportPath>
|
||||
public val platformToKotlinClassMap: PlatformToKotlinClassMap
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.jetbrains.jet.di;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.jet.context.GlobalContextImpl;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.jet.context.GlobalContext;
|
||||
import org.jetbrains.jet.storage.StorageManager;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProviderFactory;
|
||||
@@ -52,8 +52,8 @@ import javax.annotation.PreDestroy;
|
||||
public class InjectorForLazyResolve {
|
||||
|
||||
private final Project project;
|
||||
private final GlobalContextImpl globalContext;
|
||||
private final LockBasedStorageManager lockBasedStorageManager;
|
||||
private final GlobalContext globalContext;
|
||||
private final StorageManager storageManager;
|
||||
private final ModuleDescriptorImpl moduleDescriptor;
|
||||
private final PlatformToKotlinClassMap platformToKotlinClassMap;
|
||||
private final DeclarationProviderFactory declarationProviderFactory;
|
||||
@@ -82,14 +82,14 @@ public class InjectorForLazyResolve {
|
||||
|
||||
public InjectorForLazyResolve(
|
||||
@NotNull Project project,
|
||||
@NotNull GlobalContextImpl globalContext,
|
||||
@NotNull GlobalContext globalContext,
|
||||
@NotNull ModuleDescriptorImpl moduleDescriptor,
|
||||
@NotNull DeclarationProviderFactory declarationProviderFactory,
|
||||
@NotNull BindingTrace bindingTrace
|
||||
) {
|
||||
this.project = project;
|
||||
this.globalContext = globalContext;
|
||||
this.lockBasedStorageManager = globalContext.getStorageManager();
|
||||
this.storageManager = globalContext.getStorageManager();
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
this.platformToKotlinClassMap = moduleDescriptor.getPlatformToKotlinClassMap();
|
||||
this.declarationProviderFactory = declarationProviderFactory;
|
||||
@@ -125,7 +125,7 @@ public class InjectorForLazyResolve {
|
||||
this.resolveSession.setTypeResolver(typeResolver);
|
||||
|
||||
annotationResolver.setCallResolver(callResolver);
|
||||
annotationResolver.setStorageManager(lockBasedStorageManager);
|
||||
annotationResolver.setStorageManager(storageManager);
|
||||
annotationResolver.setTypeResolver(typeResolver);
|
||||
|
||||
callResolver.setArgumentTypeResolver(argumentTypeResolver);
|
||||
@@ -163,7 +163,7 @@ public class InjectorForLazyResolve {
|
||||
descriptorResolver.setAnnotationResolver(annotationResolver);
|
||||
descriptorResolver.setDelegatedPropertyResolver(delegatedPropertyResolver);
|
||||
descriptorResolver.setExpressionTypingServices(expressionTypingServices);
|
||||
descriptorResolver.setStorageManager(lockBasedStorageManager);
|
||||
descriptorResolver.setStorageManager(storageManager);
|
||||
descriptorResolver.setTypeResolver(typeResolver);
|
||||
|
||||
delegatedPropertyResolver.setCallResolver(callResolver);
|
||||
|
||||
@@ -26,10 +26,17 @@ import org.jetbrains.jet.lang.resolve.ImportPath
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken
|
||||
import org.jetbrains.jet.plugin.JetFileType
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory.CallableBuilder.Target
|
||||
import com.intellij.openapi.util.Key
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
|
||||
public fun JetPsiFactory(project: Project?): JetPsiFactory = JetPsiFactory(project!!)
|
||||
public fun JetPsiFactory(contextElement: JetElement): JetPsiFactory = JetPsiFactory(contextElement.getProject())
|
||||
|
||||
public var JetFile.doNotAnalyze: String? by UserDataProperty(Key.create("DO_NOT_ANALYZE"))
|
||||
public var JetFile.analysisContext: PsiElement? by UserDataProperty(Key.create("ANALYSIS_CONTEXT"))
|
||||
|
||||
public class JetPsiFactory(private val project: Project) {
|
||||
|
||||
public fun createValNode(): ASTNode {
|
||||
@@ -114,10 +121,33 @@ public class JetPsiFactory(private val project: Project) {
|
||||
return createFile("dummy.kt", text)
|
||||
}
|
||||
|
||||
public fun createFile(fileName: String, text: String): JetFile {
|
||||
private fun doCreateFile(fileName: String, text: String): JetFile {
|
||||
return PsiFileFactory.getInstance(project).createFileFromText(fileName, JetFileType.INSTANCE, text, LocalTimeCounter.currentTime(), false) as JetFile
|
||||
}
|
||||
|
||||
public fun createFile(fileName: String, text: String): JetFile {
|
||||
val file = doCreateFile(fileName, text)
|
||||
//TODO: KotlinInternalMode should be used here
|
||||
if (ApplicationManager.getApplication()!!.isInternal()) {
|
||||
val sw = StringWriter()
|
||||
Exception().printStackTrace(PrintWriter(sw))
|
||||
file.doNotAnalyze = "This file was created by JetPsiFactory and should not be analyzed. It was created at:\n" + sw.toString()
|
||||
}
|
||||
else {
|
||||
file.doNotAnalyze = "This file was created by JetPsiFactory and should not be analyzed\n" +
|
||||
"Enable kotlin internal mode get more info for debugging\n" +
|
||||
"Use createAnalyzableFile to create file that can be analyzed\n"
|
||||
}
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
public fun createAnalyzableFile(fileName: String, text: String, contextToAnalyzeIn: PsiElement): JetFile {
|
||||
val file = doCreateFile(fileName, text)
|
||||
file.analysisContext = contextToAnalyzeIn
|
||||
return file
|
||||
}
|
||||
|
||||
public fun createPhysicalFile(fileName: String, text: String): JetFile {
|
||||
return PsiFileFactory.getInstance(project).createFileFromText(fileName, JetFileType.INSTANCE, text, LocalTimeCounter.currentTime(), true) as JetFile
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.psi
|
||||
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
import com.intellij.openapi.util.Key
|
||||
|
||||
public class UserDataProperty<T : Any>(val key: Key<T>) : ReadWriteProperty<JetFile, T?> {
|
||||
override fun get(thisRef: JetFile, desc: kotlin.PropertyMetadata): T? {
|
||||
return thisRef.getUserData(key)
|
||||
}
|
||||
|
||||
override fun set(thisRef: JetFile, desc: kotlin.PropertyMetadata, value: T?) {
|
||||
thisRef.putUserData(key, value)
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import kotlin.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.jet.context.GlobalContextImpl;
|
||||
import org.jetbrains.jet.context.GlobalContext;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -111,12 +111,13 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
@Deprecated
|
||||
public ResolveSession(
|
||||
@NotNull Project project,
|
||||
@NotNull GlobalContextImpl globalContext,
|
||||
@NotNull GlobalContext globalContext,
|
||||
@NotNull ModuleDescriptorImpl rootDescriptor,
|
||||
@NotNull DeclarationProviderFactory declarationProviderFactory,
|
||||
@NotNull BindingTrace delegationTrace
|
||||
) {
|
||||
LockBasedLazyResolveStorageManager lockBasedLazyResolveStorageManager = new LockBasedLazyResolveStorageManager(globalContext.getStorageManager());
|
||||
LockBasedLazyResolveStorageManager lockBasedLazyResolveStorageManager = new LockBasedLazyResolveStorageManager(
|
||||
(LockBasedStorageManager) globalContext.getStorageManager());
|
||||
this.storageManager = lockBasedLazyResolveStorageManager;
|
||||
this.exceptionTracker = globalContext.getExceptionTracker();
|
||||
this.trace = lockBasedLazyResolveStorageManager.createSafeTrace(delegationTrace);
|
||||
|
||||
@@ -53,15 +53,8 @@ public class MainFunctionDetector {
|
||||
};
|
||||
}
|
||||
|
||||
/** Uses the {@code resolveSession} to resolve the function declaration. Suitable when the function declaration is not resolved yet. */
|
||||
public MainFunctionDetector(@NotNull final ResolveSession resolveSession) {
|
||||
this.getFunctionDescriptor = new NotNullFunction<JetNamedFunction, FunctionDescriptor>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor fun(JetNamedFunction function) {
|
||||
return (FunctionDescriptor) resolveSession.resolveToDescriptor(function);
|
||||
}
|
||||
};
|
||||
public MainFunctionDetector(@NotNull NotNullFunction<JetNamedFunction, FunctionDescriptor> functionResolver) {
|
||||
this.getFunctionDescriptor = functionResolver;
|
||||
}
|
||||
|
||||
public boolean hasMain(@NotNull List<JetDeclaration> declarations) {
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
* <p/>
|
||||
* See {@link LineBreakpoint#findClassCandidatesInSourceContent} for the primary usage this was introduced
|
||||
*/
|
||||
/* package */ class FakeLightClassForFileOfPackage extends AbstractLightClass implements KotlinLightClass, JetJavaMirrorMarker {
|
||||
public class FakeLightClassForFileOfPackage extends AbstractLightClass implements KotlinLightClass, JetJavaMirrorMarker {
|
||||
private final KotlinLightClassForPackage delegate;
|
||||
private final JetFile file;
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaPsiFacadeKotlinHacks;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.PackagePartClassUtils;
|
||||
@@ -141,17 +143,21 @@ public class JavaElementFinder extends PsiElementFinder implements JavaPsiFacade
|
||||
}
|
||||
|
||||
private void findPackageClass(FqName qualifiedName, GlobalSearchScope scope, List<PsiClass> answer) {
|
||||
Collection<JetFile> filesForPackage = lightClassGenerationSupport.findFilesForPackage(qualifiedName, scope);
|
||||
if (PackagePartClassUtils.getPackageFilesWithCallables(filesForPackage).isEmpty()) return;
|
||||
List<LightClassGenerationSupport.KotlinLightPackageClassInfo>
|
||||
packageClassesInfos = lightClassGenerationSupport.findPackageClassesInfos(qualifiedName, scope);
|
||||
for (LightClassGenerationSupport.KotlinLightPackageClassInfo info : packageClassesInfos) {
|
||||
Collection<JetFile> files = info.getFiles();
|
||||
if (PackagePartClassUtils.getPackageFilesWithCallables(files).isEmpty()) continue;
|
||||
KotlinLightClassForPackage lightClass =
|
||||
KotlinLightClassForPackage.create(psiManager, qualifiedName, info.getScope(), files);
|
||||
if (lightClass == null) continue;
|
||||
|
||||
KotlinLightClassForPackage lightClass = KotlinLightClassForPackage.create(psiManager, qualifiedName, scope, filesForPackage);
|
||||
if (lightClass == null) return;
|
||||
answer.add(lightClass);
|
||||
|
||||
answer.add(lightClass);
|
||||
|
||||
if (filesForPackage.size() > 1) {
|
||||
for (JetFile file : filesForPackage) {
|
||||
answer.add(new FakeLightClassForFileOfPackage(psiManager, lightClass, file));
|
||||
if (files.size() > 1) {
|
||||
for (JetFile file : files) {
|
||||
answer.add(new FakeLightClassForFileOfPackage(psiManager, lightClass, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import com.intellij.util.containers.SLRUCache;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
|
||||
@@ -424,4 +425,11 @@ public class KotlinLightClassForPackage extends KotlinWrappingLightClass impleme
|
||||
return KotlinLightClassForPackage.class.getSimpleName() + ":" + e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
//NOTE: this is only needed to compute plugin module info
|
||||
@NotNull
|
||||
@ReadOnly
|
||||
public final Collection<JetFile> getFiles() {
|
||||
return files;
|
||||
}
|
||||
}
|
||||
|
||||
+27
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class LightClassGenerationSupport {
|
||||
|
||||
@@ -54,6 +55,12 @@ public abstract class LightClassGenerationSupport {
|
||||
@NotNull
|
||||
public abstract Collection<JetFile> findFilesForPackage(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope);
|
||||
|
||||
@NotNull
|
||||
public abstract List<KotlinLightPackageClassInfo> findPackageClassesInfos(
|
||||
@NotNull FqName fqName,
|
||||
@NotNull GlobalSearchScope wholeScope
|
||||
);
|
||||
|
||||
// Returns only immediately declared classes/objects, package classes are not included (they have no declarations)
|
||||
@NotNull
|
||||
public abstract Collection<JetClassOrObject> findClassOrObjectDeclarationsInPackage(
|
||||
@@ -68,4 +75,24 @@ public abstract class LightClassGenerationSupport {
|
||||
|
||||
@Nullable
|
||||
public abstract PsiClass getPsiClass(@NotNull JetClassOrObject classOrObject);
|
||||
|
||||
public final class KotlinLightPackageClassInfo {
|
||||
private final Collection<JetFile> files;
|
||||
private final GlobalSearchScope scope;
|
||||
|
||||
public KotlinLightPackageClassInfo(@NotNull Collection<JetFile> files, @NotNull GlobalSearchScope scope) {
|
||||
this.files = files;
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<JetFile> getFiles() {
|
||||
return files;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public GlobalSearchScope getScope() {
|
||||
return scope;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-12
@@ -32,9 +32,18 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory.*
|
||||
import org.jetbrains.jet.lang.psi.JetParameter
|
||||
import org.jetbrains.jet.lang.psi.JetClass
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory
|
||||
import org.jetbrains.jet.lang.psi.JetClassObject
|
||||
|
||||
public fun getJvmSignatureDiagnostics(element: PsiElement, otherDiagnostics: Diagnostics): Diagnostics? {
|
||||
public fun getJvmSignatureDiagnostics(element: PsiElement, otherDiagnostics: Diagnostics, moduleScope: GlobalSearchScope): Diagnostics? {
|
||||
fun getDiagnosticsForPackage(file: JetFile): Diagnostics? {
|
||||
val project = file.getProject()
|
||||
val cache = KotlinLightClassForPackage.FileStubCache.getInstance(project)
|
||||
return cache[file.getPackageFqName(), moduleScope].getValue()?.extraDiagnostics
|
||||
}
|
||||
|
||||
fun getDiagnosticsForClass(jetClassOrObject: JetClassOrObject): Diagnostics {
|
||||
return KotlinLightClassForExplicitDeclaration.getLightClassData(jetClassOrObject).extraDiagnostics
|
||||
}
|
||||
|
||||
fun doGetDiagnostics(): Diagnostics? {
|
||||
var parent = element.getParent()
|
||||
if (element is JetPropertyAccessor) {
|
||||
@@ -134,13 +143,3 @@ private fun ConflictingJvmDeclarationsData.higherThan(other: ConflictingJvmDecla
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDiagnosticsForPackage(file: JetFile): Diagnostics? {
|
||||
val project = file.getProject()
|
||||
val cache = KotlinLightClassForPackage.FileStubCache.getInstance(project)
|
||||
return cache[file.getPackageFqName(), GlobalSearchScope.allScope(project)].getValue()?.extraDiagnostics
|
||||
}
|
||||
|
||||
private fun getDiagnosticsForClass(jetClassOrObject: JetClassOrObject): Diagnostics {
|
||||
return KotlinLightClassForExplicitDeclaration.getLightClassData(jetClassOrObject).extraDiagnostics
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package test
|
||||
|
||||
import custom.*
|
||||
|
||||
public class KotlinA: AClass() {
|
||||
fun returnA(): AClass {}
|
||||
|
||||
fun paramA(p: AClass) {}
|
||||
|
||||
AAnnotation fun annoA() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package custom;
|
||||
|
||||
public @interface AAnnotation {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package custom;
|
||||
|
||||
public class AClass {
|
||||
public AClass returnA() {}
|
||||
public void paramA(AClass a) {}
|
||||
@AAnnotation
|
||||
public void annoA() {}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package test
|
||||
|
||||
import custom.*
|
||||
|
||||
public class KotlinB: AClass() {
|
||||
public fun returnA(): AClass {}
|
||||
|
||||
public fun paramA(a: AClass) {}
|
||||
|
||||
public fun paramB(b: BClass) {}
|
||||
|
||||
public fun returnB(): BClass { }
|
||||
|
||||
AAnnotation fun annoA() {}
|
||||
|
||||
BAnnotation fun annoB() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package custom;
|
||||
|
||||
public @interface BAnnotation {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package custom;
|
||||
|
||||
public class BClass extends AClass {
|
||||
public AClass returnA() {}
|
||||
public void paramA(AClass a) {}
|
||||
@AAnnotation
|
||||
public void annoA() {}
|
||||
public BClass returnB() {}
|
||||
public void paramB(BClass b) {}
|
||||
@BAnnotation
|
||||
public void annoB() {}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package test
|
||||
|
||||
import custom.*
|
||||
|
||||
public class KotlinC: AClass() {
|
||||
public fun returnA(): AClass {}
|
||||
|
||||
public fun paramA(a: AClass) {}
|
||||
|
||||
public fun paramB(b: BClass) {}
|
||||
|
||||
public fun returnB(): BClass { }
|
||||
|
||||
AAnnotation fun annoA() {}
|
||||
|
||||
BAnnotation fun annoB() {}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package custom;
|
||||
|
||||
public class CClass extends BClass {
|
||||
public AClass returnA() {}
|
||||
public void paramA(AClass a) {}
|
||||
@AAnnotation
|
||||
public void annoA() {}
|
||||
public BClass returnB() {}
|
||||
public void paramB(BClass b) {}
|
||||
@BAnnotation
|
||||
public void annoB() {}
|
||||
}
|
||||
@@ -809,6 +809,7 @@ public class JetTestUtils {
|
||||
return generatorClassFqName.substring(generatorClassFqName.lastIndexOf(".") + 1);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetFile loadJetFile(@NotNull Project project, @NotNull File ioFile) throws IOException {
|
||||
String text = FileUtil.loadFile(ioFile, true);
|
||||
return JetPsiFactory(project).createPhysicalFile(ioFile.getName(), text);
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileFactory;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -355,7 +356,8 @@ public abstract class BaseDiagnosticsTest extends JetLiteFixture {
|
||||
Set<Diagnostic> jvmSignatureDiagnostics = new HashSet<Diagnostic>();
|
||||
Collection<JetDeclaration> declarations = PsiTreeUtil.findChildrenOfType(jetFile, JetDeclaration.class);
|
||||
for (JetDeclaration declaration : declarations) {
|
||||
Diagnostics diagnostics = AsJavaPackage.getJvmSignatureDiagnostics(declaration, bindingContext.getDiagnostics());
|
||||
Diagnostics diagnostics = AsJavaPackage.getJvmSignatureDiagnostics(declaration, bindingContext.getDiagnostics(),
|
||||
GlobalSearchScope.allScope(getProject()));
|
||||
if (diagnostics == null) continue;
|
||||
jvmSignatureDiagnostics.addAll(diagnostics.forElement(declaration));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.jvm.compiler
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnalyzerFacade
|
||||
import org.jetbrains.jet.context.GlobalContext
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPlatformParameters
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import java.io.File
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.junit.Assert
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
|
||||
import org.jetbrains.jet.config.CompilerConfiguration
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
|
||||
import com.intellij.psi.search.DelegatingGlobalSearchScope
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmResolverForModule
|
||||
import org.jetbrains.jet.analyzer.ResolverForProject
|
||||
import org.jetbrains.jet.analyzer.ModuleInfo
|
||||
import java.util.HashMap
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.jet.analyzer.ModuleContent
|
||||
|
||||
public class MultiModuleJavaAnalysisCustomTest : UsefulTestCase() {
|
||||
|
||||
private class TestModule(val _name: String, val kotlinFiles: List<JetFile>, val javaFilesScope: GlobalSearchScope,
|
||||
val _dependencies: TestModule.() -> List<TestModule>) :
|
||||
ModuleInfo {
|
||||
override fun dependencies() = _dependencies()
|
||||
override val name = Name.special("<$_name>")
|
||||
}
|
||||
|
||||
fun testJavaEntitiesBelongToCorrectModule() {
|
||||
val moduleDirs = File(PATH_TO_TEST_ROOT_DIR).listFiles { it.isDirectory() }!!
|
||||
val environment = createEnvironment(moduleDirs)
|
||||
val modules = setupModules(environment, moduleDirs)
|
||||
val resolverForProject = JvmAnalyzerFacade.setupResolverForProject(
|
||||
GlobalContext(), environment.getProject(), modules,
|
||||
{ m -> ModuleContent(m.kotlinFiles, m.javaFilesScope) },
|
||||
JvmPlatformParameters {
|
||||
javaClass ->
|
||||
val moduleName = javaClass.getName().asString().toLowerCase().first().toString()
|
||||
modules.first { it._name == moduleName }
|
||||
}
|
||||
)
|
||||
|
||||
performChecks(resolverForProject, modules)
|
||||
}
|
||||
|
||||
private fun createEnvironment(moduleDirs: Array<File>): JetCoreEnvironment {
|
||||
val configuration = CompilerConfiguration()
|
||||
configuration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, moduleDirs.toList())
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration)
|
||||
}
|
||||
|
||||
private fun setupModules(environment: JetCoreEnvironment, moduleDirs: Array<File>): List<TestModule> {
|
||||
val project = environment.getProject()
|
||||
val modules = HashMap<String, TestModule>()
|
||||
for (dir in moduleDirs) {
|
||||
val name = dir.getName()
|
||||
val kotlinFiles = JetTestUtils.loadToJetFiles(environment, dir.listFiles { it.extension == "kt" }?.toList().orEmpty())
|
||||
val javaFilesScope = object : DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
|
||||
override fun contains(file: VirtualFile): Boolean {
|
||||
if (file !in myBaseScope!!) return false
|
||||
if (file.isDirectory()) return true
|
||||
return file.getParent()!!.getParent()!!.getName() == name
|
||||
}
|
||||
}
|
||||
modules[name] = TestModule(name, kotlinFiles, javaFilesScope) {
|
||||
when (this._name) {
|
||||
"a" -> listOf(this)
|
||||
"b" -> listOf(this, modules["a"]!!)
|
||||
"c" -> listOf(this, modules["b"]!!, modules["a"]!!)
|
||||
else -> throw IllegalStateException("$_name")
|
||||
}
|
||||
}
|
||||
}
|
||||
return modules.values().toList()
|
||||
}
|
||||
|
||||
private fun performChecks(resolverForProject: ResolverForProject<TestModule, JvmResolverForModule>, modules: List<TestModule>) {
|
||||
modules.forEach {
|
||||
module ->
|
||||
val moduleDescriptor = resolverForProject.descriptorForModule(module)
|
||||
|
||||
checkClassInPackage(moduleDescriptor, "test", "Kotlin${module._name.toUpperCase()}")
|
||||
checkClassInPackage(moduleDescriptor, "custom", "${module._name.toUpperCase()}Class")
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkClassInPackage(moduleDescriptor: ModuleDescriptor, packageName: String, className: String) {
|
||||
val kotlinPackage = moduleDescriptor.getPackage(FqName(packageName))!!
|
||||
val kotlinClassName = Name.identifier(className)
|
||||
val kotlinClass = kotlinPackage.getMemberScope().getClassifier(kotlinClassName) as ClassDescriptor
|
||||
checkClass(kotlinClass)
|
||||
}
|
||||
|
||||
private fun checkClass(classDescriptor: ClassDescriptor) {
|
||||
classDescriptor.getDefaultType().getMemberScope().getAllDescriptors().filterIsInstance(javaClass<CallableDescriptor>()).forEach {
|
||||
checkCallable(it, classDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkCallable(callable: CallableDescriptor, classDescriptor: ClassDescriptor) {
|
||||
val returnType = callable.getReturnType()!!
|
||||
if (!KotlinBuiltIns.getInstance().isUnit(returnType)) {
|
||||
checkDescriptor(returnType.getConstructor().getDeclarationDescriptor()!!, callable)
|
||||
}
|
||||
|
||||
callable.getValueParameters().map {
|
||||
it.getType().getConstructor().getDeclarationDescriptor()!!
|
||||
}.forEach { checkDescriptor(it, callable) }
|
||||
|
||||
callable.getAnnotations().map {
|
||||
it.getType().getConstructor().getDeclarationDescriptor()!!
|
||||
}.forEach { checkDescriptor(it, callable) }
|
||||
|
||||
checkSupertypes(classDescriptor)
|
||||
}
|
||||
|
||||
private fun checkSupertypes(classDescriptor: ClassDescriptor) {
|
||||
classDescriptor.getDefaultType().getConstructor().getSupertypes().filter {
|
||||
!KotlinBuiltIns.getInstance().isAnyOrNullableAny(it)
|
||||
}.map {
|
||||
it.getConstructor().getDeclarationDescriptor()!!
|
||||
}.forEach {
|
||||
checkDescriptor(it, classDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkDescriptor(referencedDescriptor: ClassifierDescriptor, context: DeclarationDescriptor) {
|
||||
val descriptorName = referencedDescriptor.getName().asString()
|
||||
val expectedModuleName = "<${descriptorName.toLowerCase().first().toString()}>"
|
||||
val moduleName = DescriptorUtils.getContainingModule(referencedDescriptor).getName().asString()
|
||||
Assert.assertEquals(
|
||||
"Java class $descriptorName in $context should be in module $expectedModuleName, but instead was in $moduleName",
|
||||
expectedModuleName, moduleName
|
||||
)
|
||||
}
|
||||
|
||||
class object {
|
||||
val PATH_TO_TEST_ROOT_DIR = "compiler/testData/multiModule/java/custom"
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
@@ -33,14 +32,14 @@ import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.lazy.LazyPackage.createResolveSessionForFiles;
|
||||
|
||||
public class LazyResolveTestUtil {
|
||||
private LazyResolveTestUtil() {
|
||||
}
|
||||
@@ -61,16 +60,18 @@ public class LazyResolveTestUtil {
|
||||
return injector.getModuleDescriptor();
|
||||
}
|
||||
|
||||
public static KotlinCodeAnalyzer resolveLazilyWithSession(List<JetFile> files, JetCoreEnvironment environment, boolean addBuiltIns) {
|
||||
@NotNull
|
||||
public static KotlinCodeAnalyzer resolveLazilyWithSession(
|
||||
@NotNull List<JetFile> files,
|
||||
@NotNull JetCoreEnvironment environment,
|
||||
boolean addBuiltIns
|
||||
) {
|
||||
JetTestUtils.newTrace(environment);
|
||||
|
||||
Project project = environment.getProject();
|
||||
CliLightClassGenerationSupport support = CliLightClassGenerationSupport.getInstanceForCli(project);
|
||||
BindingTrace sharedTrace = support.getTrace();
|
||||
|
||||
ResolveSession lazyResolveSession = AnalyzerFacadeForJVM.createSetup(project, files, GlobalSearchScope.EMPTY_SCOPE,
|
||||
sharedTrace, addBuiltIns).getLazyResolveSession();
|
||||
support.setModule((ModuleDescriptorImpl)lazyResolveSession.getModuleDescriptor());
|
||||
ResolveSession lazyResolveSession = createResolveSessionForFiles(project, files, addBuiltIns);
|
||||
support.setModule((ModuleDescriptorImpl) lazyResolveSession.getModuleDescriptor());
|
||||
|
||||
return lazyResolveSession;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.lang.resolve.lazy
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.jet.context.GlobalContext
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAnalyzerFacade
|
||||
import org.jetbrains.jet.analyzer.ModuleInfo
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmPlatformParameters
|
||||
import org.jetbrains.jet.analyzer.ModuleContent
|
||||
|
||||
public fun createResolveSessionForFiles(
|
||||
project: Project,
|
||||
syntheticFiles: Collection<JetFile>,
|
||||
addBuiltIns: Boolean
|
||||
): ResolveSession {
|
||||
val globalContext = GlobalContext()
|
||||
val testModule = TestModule(addBuiltIns)
|
||||
val resolverForProject = JvmAnalyzerFacade.setupResolverForProject(
|
||||
globalContext, project, listOf(testModule),
|
||||
{ ModuleContent(syntheticFiles, GlobalSearchScope.allScope(project)) },
|
||||
JvmPlatformParameters { testModule }
|
||||
)
|
||||
return resolverForProject.resolverForModule(testModule).lazyResolveSession
|
||||
}
|
||||
|
||||
private class TestModule(val dependsOnBuiltins: Boolean) : ModuleInfo {
|
||||
override val name: Name = Name.special("<Test module for lazy resolve>")
|
||||
override fun dependencies() = listOf(this)
|
||||
override fun dependencyOnBuiltins() =
|
||||
if (dependsOnBuiltins)
|
||||
ModuleInfo.DependenciesOnBuiltins.LAST
|
||||
else
|
||||
ModuleInfo.DependenciesOnBuiltins.NONE
|
||||
}
|
||||
Reference in New Issue
Block a user