LTDA: Initialize project components with resolve session after injector construction is finished
This commit is contained in:
+63
-56
@@ -18,6 +18,7 @@ package org.jetbrains.jet.cli.jvm.compiler;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
@@ -29,25 +30,21 @@ import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.asJava.KotlinLightClassForExplicitDeclaration;
|
||||
import org.jetbrains.jet.asJava.LightClassConstructionContext;
|
||||
import org.jetbrains.jet.asJava.LightClassGenerationSupport;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||
import org.jetbrains.jet.lang.resolve.java.TopDownAnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -66,60 +63,40 @@ import java.util.List;
|
||||
*
|
||||
* To mitigate this, CliLightClassGenerationSupport hold a trace that is shared between the analyzer and JetLightClasses
|
||||
*/
|
||||
public class CliLightClassGenerationSupport extends LightClassGenerationSupport {
|
||||
|
||||
public class CliLightClassGenerationSupport extends LightClassGenerationSupport implements CodeAnalyzerInitializer {
|
||||
public static CliLightClassGenerationSupport getInstanceForCli(@NotNull Project project) {
|
||||
return ServiceManager.getService(project, CliLightClassGenerationSupport.class);
|
||||
}
|
||||
|
||||
private BindingTrace trace;
|
||||
private ModuleDescriptorImpl module;
|
||||
private BindingContext bindingContext = null;
|
||||
private ModuleDescriptor module = null;
|
||||
|
||||
public CliLightClassGenerationSupport() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BindingTrace getTrace() {
|
||||
if (trace == null) {
|
||||
trace = new BindingTraceContextWithoutScopeRecording();
|
||||
}
|
||||
return trace;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ModuleDescriptorImpl newModule() {
|
||||
assert this.module == null : "module already configured: " + module;
|
||||
module = TopDownAnalyzerFacadeForJVM.createJavaModule("<shared-module-for-cli-light-classes>");
|
||||
module.addDependencyOnModule(module);
|
||||
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule());
|
||||
module.seal();
|
||||
return module;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ModuleDescriptorImpl getModule() {
|
||||
if (module == null) {
|
||||
return newModule();
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
@Nullable
|
||||
public ModuleDescriptorImpl getLightClassModule() {
|
||||
return module;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void setModule(@NotNull ModuleDescriptorImpl module) {
|
||||
assert this.module == null : "module already configured: " + module;
|
||||
@Override
|
||||
public void initialize(@NotNull BindingTrace trace, @NotNull ModuleDescriptor module, @Nullable KotlinCodeAnalyzer analyzer) {
|
||||
this.bindingContext = trace.getBindingContext();
|
||||
this.module = module;
|
||||
|
||||
if (trace instanceof CliBindingTrace) {
|
||||
((CliBindingTrace) trace).setKotlinCodeAnalyzer(analyzer);
|
||||
}
|
||||
else {
|
||||
assert ApplicationManager.getApplication().isUnitTestMode();
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void newBindingTrace() {
|
||||
trace = null;
|
||||
module = null;
|
||||
@NotNull
|
||||
private BindingContext getBindingContext() {
|
||||
assert bindingContext != null : "Call initialize() first";
|
||||
return bindingContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ModuleDescriptor getModule() {
|
||||
assert module != null : "Call initialize() first";
|
||||
return module;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -136,13 +113,13 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
|
||||
@NotNull
|
||||
private LightClassConstructionContext getContext() {
|
||||
return new LightClassConstructionContext(getTrace().getBindingContext(), getModule());
|
||||
return new LightClassConstructionContext(bindingContext, getModule());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetClassOrObject> findClassOrObjectDeclarations(@NotNull FqName fqName, @NotNull GlobalSearchScope searchScope) {
|
||||
ClassDescriptor classDescriptor = getTrace().get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, fqName.toUnsafe());
|
||||
ClassDescriptor classDescriptor = getBindingContext().get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, fqName.toUnsafe());
|
||||
if (classDescriptor != null) {
|
||||
PsiElement element = DescriptorToSourceUtils.classDescriptorToDeclaration(classDescriptor);
|
||||
if (element != null && PsiSearchScopeUtil.isInScope(searchScope, element)) {
|
||||
@@ -174,7 +151,7 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<JetFile> findFilesForPackage(@NotNull FqName fqName, @NotNull final GlobalSearchScope searchScope) {
|
||||
Collection<JetFile> files = getTrace().get(BindingContext.PACKAGE_TO_FILES, fqName);
|
||||
Collection<JetFile> files = getBindingContext().get(BindingContext.PACKAGE_TO_FILES, fqName);
|
||||
if (files != null) {
|
||||
return Collections2.filter(files, new Predicate<JetFile>() {
|
||||
@Override
|
||||
@@ -240,7 +217,13 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
return KotlinLightClassForExplicitDeclaration.create(classOrObject.getManager(), classOrObject);
|
||||
}
|
||||
|
||||
public static class BindingTraceContextWithoutScopeRecording extends BindingTraceContext {
|
||||
public static BindingTrace createTrace() {
|
||||
return new CliBindingTrace();
|
||||
}
|
||||
|
||||
public static class CliBindingTrace extends BindingTraceContext {
|
||||
private KotlinCodeAnalyzer kotlinCodeAnalyzer;
|
||||
|
||||
@Override
|
||||
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
|
||||
if (slice == BindingContext.RESOLUTION_SCOPE || slice == BindingContext.TYPE_RESOLUTION_SCOPE) {
|
||||
@@ -252,7 +235,31 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Filtering trace for the CLI compiler: does not save scopes";
|
||||
return CliBindingTrace.class.getName();
|
||||
}
|
||||
|
||||
public void setKotlinCodeAnalyzer(KotlinCodeAnalyzer kotlinCodeAnalyzer) {
|
||||
this.kotlinCodeAnalyzer = kotlinCodeAnalyzer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
V value = super.get(slice, key);
|
||||
|
||||
if (value == null) {
|
||||
if (BindingContext.FUNCTION == slice || BindingContext.VARIABLE == slice) {
|
||||
if (key instanceof JetDeclaration) {
|
||||
JetDeclaration jetDeclaration = (JetDeclaration) key;
|
||||
if (!JetPsiUtil.isLocal(jetDeclaration)) {
|
||||
kotlinCodeAnalyzer.resolveToDescriptor(jetDeclaration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.get(slice, key);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ import org.jetbrains.jet.config.CompilerConfiguration;
|
||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||
import org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.CodeAnalyzerInitializer;
|
||||
import org.jetbrains.jet.lang.resolve.DiagnosticsWithSuppression;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinBinaryClassCache;
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.VirtualFileFinderFactory;
|
||||
@@ -236,6 +237,7 @@ public class JetCoreEnvironment {
|
||||
CliLightClassGenerationSupport cliLightClassGenerationSupport = new CliLightClassGenerationSupport();
|
||||
project.registerService(LightClassGenerationSupport.class, cliLightClassGenerationSupport);
|
||||
project.registerService(CliLightClassGenerationSupport.class, cliLightClassGenerationSupport);
|
||||
project.registerService(CodeAnalyzerInitializer.class, cliLightClassGenerationSupport);
|
||||
Extensions.getArea(project)
|
||||
.getExtensionPoint(PsiElementFinder.EP_NAME)
|
||||
.registerExtension(new JavaElementFinder(project, cliLightClassGenerationSupport));
|
||||
|
||||
+7
-6
@@ -282,23 +282,24 @@ public class KotlinToJVMBytecodeCompiler {
|
||||
|
||||
@Nullable
|
||||
private static AnalysisResult analyze(@NotNull final JetCoreEnvironment environment) {
|
||||
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(
|
||||
environment.getConfiguration().get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY));
|
||||
MessageCollector collector = environment.getConfiguration().get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY);
|
||||
assert collector != null;
|
||||
|
||||
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(collector);
|
||||
analyzerWithCompilerReport.analyzeAndReport(
|
||||
environment.getSourceFiles(), new Function0<AnalysisResult>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public AnalysisResult invoke() {
|
||||
CliLightClassGenerationSupport support = CliLightClassGenerationSupport.getInstanceForCli(environment.getProject());
|
||||
BindingTrace sharedTrace = support.getTrace();
|
||||
ModuleDescriptorImpl sharedModule = support.newModule();
|
||||
BindingTrace sharedTrace = CliLightClassGenerationSupport.createTrace();
|
||||
ModuleDescriptorImpl analyzeModule = TopDownAnalyzerFacadeForJVM.createAnalyzeModule();
|
||||
|
||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
environment.getProject(),
|
||||
environment.getSourceFiles(),
|
||||
sharedTrace,
|
||||
Predicates.<PsiFile>alwaysTrue(),
|
||||
sharedModule,
|
||||
analyzeModule,
|
||||
environment.getConfiguration().get(JVMConfigurationKeys.MODULE_IDS),
|
||||
environment.getConfiguration().get(JVMConfigurationKeys.INCREMENTAL_CACHE_PROVIDER)
|
||||
);
|
||||
|
||||
+10
@@ -33,6 +33,7 @@ import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaPropertyInitialize
|
||||
import org.jetbrains.jet.lang.resolve.java.sam.SamConversionResolverImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaSourceElementFactoryImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.SingleModuleClassResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolverPostConstruct;
|
||||
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;
|
||||
@@ -64,6 +65,7 @@ public class InjectorForJavaDescriptorResolver {
|
||||
private final SamConversionResolverImpl samConversionResolver;
|
||||
private final JavaSourceElementFactoryImpl javaSourceElementFactory;
|
||||
private final SingleModuleClassResolver singleModuleClassResolver;
|
||||
private final JavaDescriptorResolverPostConstruct javaDescriptorResolverPostConstruct;
|
||||
private final VirtualFileFinder virtualFileFinder;
|
||||
private final LazyJavaPackageFragmentProvider lazyJavaPackageFragmentProvider;
|
||||
private final GlobalJavaResolverContext globalJavaResolverContext;
|
||||
@@ -97,10 +99,12 @@ public class InjectorForJavaDescriptorResolver {
|
||||
this.lazyJavaPackageFragmentProvider = new LazyJavaPackageFragmentProvider(globalJavaResolverContext, getModule());
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver(lazyJavaPackageFragmentProvider, getModule());
|
||||
this.globalSearchScope = com.intellij.psi.search.GlobalSearchScope.allScope(project);
|
||||
this.javaDescriptorResolverPostConstruct = new JavaDescriptorResolverPostConstruct();
|
||||
this.javaClassDataFinder = new JavaClassDataFinder(virtualFileFinder, deserializedDescriptorResolver);
|
||||
this.binaryClassAnnotationAndConstantLoader = new BinaryClassAnnotationAndConstantLoaderImpl(getModule(), lockBasedStorageManager, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.deserializationComponentsForJava = new DeserializationComponentsForJava(lockBasedStorageManager, getModule(), javaClassDataFinder, binaryClassAnnotationAndConstantLoader, lazyJavaPackageFragmentProvider);
|
||||
|
||||
this.javaClassFinder.setComponentPostConstruct(javaDescriptorResolverPostConstruct);
|
||||
this.javaClassFinder.setProject(project);
|
||||
this.javaClassFinder.setScope(globalSearchScope);
|
||||
|
||||
@@ -117,10 +121,16 @@ public class InjectorForJavaDescriptorResolver {
|
||||
|
||||
singleModuleClassResolver.setResolver(javaDescriptorResolver);
|
||||
|
||||
javaDescriptorResolverPostConstruct.setModule(module);
|
||||
javaDescriptorResolverPostConstruct.setProject(project);
|
||||
javaDescriptorResolverPostConstruct.setTrace(bindingTrace);
|
||||
|
||||
deserializedDescriptorResolver.setComponents(deserializationComponentsForJava);
|
||||
|
||||
javaClassFinder.initialize();
|
||||
|
||||
javaDescriptorResolverPostConstruct.postCreate();
|
||||
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ public class InjectorForJavaDescriptorResolverUtil {
|
||||
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule());
|
||||
}
|
||||
module.seal();
|
||||
|
||||
return injector;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.jetbrains.jet.lang.resolve.java.sam.SamConversionResolverImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaSourceElementFactoryImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaFlexibleTypeCapabilitiesProvider;
|
||||
import org.jetbrains.jet.context.LazyResolveToken;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaLazyAnalyzerPostConstruct;
|
||||
import org.jetbrains.jet.lang.resolve.AdditionalCheckerProvider;
|
||||
import org.jetbrains.jet.lang.resolve.AnnotationResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
@@ -98,6 +99,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
private final JavaSourceElementFactoryImpl javaSourceElementFactory;
|
||||
private final JavaFlexibleTypeCapabilitiesProvider javaFlexibleTypeCapabilitiesProvider;
|
||||
private final LazyResolveToken lazyResolveToken;
|
||||
private final JavaLazyAnalyzerPostConstruct javaLazyAnalyzerPostConstruct;
|
||||
private final AdditionalCheckerProvider additionalCheckerProvider;
|
||||
private final AnnotationResolver annotationResolver;
|
||||
private final CallResolver callResolver;
|
||||
@@ -163,6 +165,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
this.javaDescriptorResolver = new JavaDescriptorResolver(lazyJavaPackageFragmentProvider, module);
|
||||
this.javaFlexibleTypeCapabilitiesProvider = new JavaFlexibleTypeCapabilitiesProvider();
|
||||
this.lazyResolveToken = new LazyResolveToken();
|
||||
this.javaLazyAnalyzerPostConstruct = new JavaLazyAnalyzerPostConstruct();
|
||||
this.additionalCheckerProvider = org.jetbrains.jet.lang.resolve.kotlin.JavaDeclarationCheckerProvider.INSTANCE$;
|
||||
this.annotationResolver = new AnnotationResolver();
|
||||
this.callResolver = new CallResolver();
|
||||
@@ -198,6 +201,7 @@ public class InjectorForLazyResolveWithJava {
|
||||
this.resolveSession.setScriptBodyResolver(scriptBodyResolver);
|
||||
this.resolveSession.setTypeResolver(typeResolver);
|
||||
|
||||
javaClassFinder.setComponentPostConstruct(javaLazyAnalyzerPostConstruct);
|
||||
javaClassFinder.setProject(project);
|
||||
javaClassFinder.setScope(moduleContentScope);
|
||||
|
||||
@@ -212,6 +216,10 @@ public class InjectorForLazyResolveWithJava {
|
||||
psiBasedMethodSignatureChecker.setExternalAnnotationResolver(psiBasedExternalAnnotationResolver);
|
||||
psiBasedMethodSignatureChecker.setExternalSignatureResolver(traceBasedExternalSignatureResolver);
|
||||
|
||||
javaLazyAnalyzerPostConstruct.setCodeAnalyzer(resolveSession);
|
||||
javaLazyAnalyzerPostConstruct.setProject(project);
|
||||
javaLazyAnalyzerPostConstruct.setTrace(bindingTrace);
|
||||
|
||||
annotationResolver.setCallResolver(callResolver);
|
||||
annotationResolver.setStorageManager(storageManager);
|
||||
annotationResolver.setTypeResolver(typeResolver);
|
||||
@@ -270,6 +278,8 @@ public class InjectorForLazyResolveWithJava {
|
||||
|
||||
javaClassFinder.initialize();
|
||||
|
||||
javaLazyAnalyzerPostConstruct.postCreate();
|
||||
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaPropertyInitialize
|
||||
import org.jetbrains.jet.lang.resolve.java.sam.SamConversionResolverImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.JavaSourceElementFactoryImpl;
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.SingleModuleClassResolver;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaLazyAnalyzerPostConstruct;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaFlexibleTypeCapabilitiesProvider;
|
||||
import org.jetbrains.jet.lang.resolve.AdditionalCheckerProvider;
|
||||
import org.jetbrains.jet.lang.resolve.BodyResolver;
|
||||
@@ -108,6 +109,7 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
private final SamConversionResolverImpl samConversionResolver;
|
||||
private final JavaSourceElementFactoryImpl javaSourceElementFactory;
|
||||
private final SingleModuleClassResolver singleModuleClassResolver;
|
||||
private final JavaLazyAnalyzerPostConstruct javaLazyAnalyzerPostConstruct;
|
||||
private final JavaFlexibleTypeCapabilitiesProvider javaFlexibleTypeCapabilitiesProvider;
|
||||
private final AdditionalCheckerProvider additionalCheckerProvider;
|
||||
private final BodyResolver bodyResolver;
|
||||
@@ -184,6 +186,7 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
this.javaClassDataFinder = new JavaClassDataFinder(virtualFileFinder, deserializedDescriptorResolver);
|
||||
this.binaryClassAnnotationAndConstantLoader = new BinaryClassAnnotationAndConstantLoaderImpl(module, storageManager, virtualFileFinder, traceBasedErrorReporter);
|
||||
this.deserializationComponentsForJava = new DeserializationComponentsForJava(storageManager, module, javaClassDataFinder, binaryClassAnnotationAndConstantLoader, lazyJavaPackageFragmentProvider);
|
||||
this.javaLazyAnalyzerPostConstruct = new JavaLazyAnalyzerPostConstruct();
|
||||
this.javaFlexibleTypeCapabilitiesProvider = new JavaFlexibleTypeCapabilitiesProvider();
|
||||
this.additionalCheckerProvider = org.jetbrains.jet.lang.resolve.kotlin.JavaDeclarationCheckerProvider.INSTANCE$;
|
||||
this.bodyResolver = new BodyResolver();
|
||||
@@ -235,6 +238,7 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
this.resolveSession.setScriptBodyResolver(scriptBodyResolver);
|
||||
this.resolveSession.setTypeResolver(typeResolver);
|
||||
|
||||
javaClassFinder.setComponentPostConstruct(javaLazyAnalyzerPostConstruct);
|
||||
javaClassFinder.setProject(project);
|
||||
javaClassFinder.setScope(moduleContentScope);
|
||||
|
||||
@@ -251,6 +255,10 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
|
||||
singleModuleClassResolver.setResolver(javaDescriptorResolver);
|
||||
|
||||
javaLazyAnalyzerPostConstruct.setCodeAnalyzer(resolveSession);
|
||||
javaLazyAnalyzerPostConstruct.setProject(project);
|
||||
javaLazyAnalyzerPostConstruct.setTrace(bindingTrace);
|
||||
|
||||
bodyResolver.setAnnotationResolver(annotationResolver);
|
||||
bodyResolver.setCallResolver(callResolver);
|
||||
bodyResolver.setControlFlowAnalyzer(controlFlowAnalyzer);
|
||||
@@ -341,6 +349,8 @@ public class InjectorForTopDownAnalyzerForJvm {
|
||||
|
||||
javaClassFinder.initialize();
|
||||
|
||||
javaLazyAnalyzerPostConstruct.postCreate();
|
||||
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
||||
+5
@@ -53,6 +53,11 @@ public class JavaClassFinderImpl implements JavaClassFinder {
|
||||
this.baseScope = scope;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setComponentPostConstruct(@NotNull JavaClassFinderPostConstruct finderPostConstruct) {
|
||||
// Only activate post create
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initialize() {
|
||||
javaSearchScope = new DelegatingGlobalSearchScope(baseScope) {
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* 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 com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import javax.inject.Inject
|
||||
import javax.annotation.PostConstruct
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace
|
||||
import org.jetbrains.jet.lang.resolve.CodeAnalyzerInitializer
|
||||
|
||||
public open class JavaClassFinderPostConstruct {
|
||||
PostConstruct public open fun postCreate() {}
|
||||
}
|
||||
|
||||
public class JavaLazyAnalyzerPostConstruct : JavaClassFinderPostConstruct() {
|
||||
public var project: Project? = null
|
||||
[Inject] set
|
||||
|
||||
public var trace: BindingTrace? = null
|
||||
[Inject] set
|
||||
|
||||
public var codeAnalyzer: KotlinCodeAnalyzer? = null
|
||||
[Inject] set
|
||||
|
||||
[PostConstruct] override fun postCreate() {
|
||||
CodeAnalyzerInitializer.getInstance(project!!).initialize(trace!!, codeAnalyzer!!.getModuleDescriptor(), codeAnalyzer)
|
||||
}
|
||||
}
|
||||
|
||||
public class JavaDescriptorResolverPostConstruct : JavaClassFinderPostConstruct() {
|
||||
public var project: Project? = null
|
||||
[Inject] set
|
||||
|
||||
public var trace: BindingTrace? = null
|
||||
[Inject] set
|
||||
|
||||
public var module: ModuleDescriptor? = null
|
||||
[Inject] set
|
||||
|
||||
[PostConstruct] override fun postCreate() {
|
||||
CodeAnalyzerInitializer.getInstance(project!!).initialize(trace!!, module!!, null)
|
||||
}
|
||||
}
|
||||
|
||||
+16
-9
@@ -40,6 +40,7 @@ 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.declarations.FileBasedDeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -68,11 +69,7 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
@NotNull TopDownAnalysisParameters topDownAnalysisParameters,
|
||||
@NotNull ModuleDescriptorImpl module
|
||||
) {
|
||||
GlobalContext globalContext = new GlobalContextImpl(
|
||||
(LockBasedStorageManager) topDownAnalysisParameters.getStorageManager(),
|
||||
topDownAnalysisParameters.getExceptionTracker());
|
||||
|
||||
return analyzeFilesWithJavaIntegration(project, files, trace, topDownAnalysisParameters, module, globalContext, null, null);
|
||||
return analyzeFilesWithJavaIntegration(project, files, trace, topDownAnalysisParameters, module, null, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -112,7 +109,7 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
|
||||
return analyzeFilesWithJavaIntegration(
|
||||
project, files, trace, topDownAnalysisParameters, module,
|
||||
globalContext, moduleIds, incrementalCacheProvider);
|
||||
moduleIds, incrementalCacheProvider);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -122,7 +119,6 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
BindingTrace trace,
|
||||
TopDownAnalysisParameters topDownAnalysisParameters,
|
||||
ModuleDescriptorImpl module,
|
||||
GlobalContext globalContext,
|
||||
@Nullable List<String> moduleIds,
|
||||
@Nullable IncrementalCacheProvider incrementalCacheProvider
|
||||
) {
|
||||
@@ -131,7 +127,7 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
|
||||
InjectorForTopDownAnalyzerForJvm injector = new InjectorForTopDownAnalyzerForJvm(
|
||||
project,
|
||||
globalContext,
|
||||
topDownAnalysisParameters,
|
||||
trace,
|
||||
module,
|
||||
GlobalSearchScope.allScope(project),
|
||||
@@ -166,6 +162,17 @@ public enum TopDownAnalyzerFacadeForJVM {
|
||||
|
||||
@NotNull
|
||||
public static ModuleDescriptorImpl createJavaModule(@NotNull String name) {
|
||||
return new ModuleDescriptorImpl(Name.special(name), DEFAULT_IMPORTS, JavaToKotlinClassMap.getInstance());
|
||||
return new ModuleDescriptorImpl(Name.special(name),
|
||||
DEFAULT_IMPORTS,
|
||||
JavaToKotlinClassMap.getInstance());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ModuleDescriptorImpl createAnalyzeModule() {
|
||||
ModuleDescriptorImpl module = createJavaModule("<shared-module>");
|
||||
module.addDependencyOnModule(module);
|
||||
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule());
|
||||
module.seal();
|
||||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer
|
||||
import kotlin.platform.platformStatic
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import javax.annotation.PostConstruct
|
||||
|
||||
public trait CodeAnalyzerInitializer {
|
||||
public fun initialize(trace: BindingTrace, module: ModuleDescriptor, codeAnalyzer: KotlinCodeAnalyzer?)
|
||||
|
||||
class object {
|
||||
public fun getInstance(project: Project): CodeAnalyzerInitializer =
|
||||
ServiceManager.getService<CodeAnalyzerInitializer>(project, javaClass<CodeAnalyzerInitializer>())!!
|
||||
}
|
||||
}
|
||||
|
||||
public class DummyCodeAnalyzerInitializer: CodeAnalyzerInitializer {
|
||||
public override fun initialize(trace: BindingTrace, module: ModuleDescriptor, codeAnalyzer: KotlinCodeAnalyzer?) {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,6 @@ import com.intellij.psi.util.PsiTreeUtil;
|
||||
import kotlin.KotlinPackage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.context.GlobalContextImpl;
|
||||
import org.jetbrains.jet.di.InjectorForLazyResolve;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.CompositePackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
@@ -33,11 +31,8 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallsPackage;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.LazyImportScope;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.FileBasedDeclarationProviderFactory;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.storage.LockBasedStorageManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -416,11 +416,6 @@ public class JetTestUtils {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public static void newTrace(@NotNull JetCoreEnvironment environment) {
|
||||
// let the next analysis use another trace
|
||||
CliLightClassGenerationSupport.getInstanceForCli(environment.getProject()).newBindingTrace();
|
||||
}
|
||||
|
||||
public static void resolveAllKotlinFiles(JetCoreEnvironment environment) throws IOException {
|
||||
List<String> paths = environment.getConfiguration().get(CommonConfigurationKeys.SOURCE_ROOTS_KEY);
|
||||
if (paths == null) return;
|
||||
|
||||
@@ -32,8 +32,6 @@ import org.jetbrains.jet.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
import org.jetbrains.jet.context.GlobalContext;
|
||||
import org.jetbrains.jet.context.SimpleGlobalContext;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentProvider;
|
||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.diagnostics.*;
|
||||
@@ -86,9 +84,6 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
}
|
||||
);
|
||||
|
||||
CliLightClassGenerationSupport support = CliLightClassGenerationSupport.getInstanceForCli(getProject());
|
||||
BindingTrace supportTrace = support.getTrace();
|
||||
|
||||
List<JetFile> allJetFiles = new ArrayList<JetFile>();
|
||||
Map<TestModule, ModuleDescriptorImpl> modules = createModules(groupedByModule);
|
||||
Map<TestModule, BindingContext> moduleBindings = new HashMap<TestModule, BindingContext>();
|
||||
@@ -103,19 +98,9 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
allJetFiles.addAll(jetFiles);
|
||||
|
||||
ModuleDescriptorImpl module = modules.get(testModule);
|
||||
BindingTrace moduleTrace = groupedByModule.size() > 1
|
||||
? new DelegatingBindingTrace(supportTrace.getBindingContext(), "Trace for module " + module)
|
||||
: supportTrace;
|
||||
moduleBindings.put(testModule, moduleTrace.getBindingContext());
|
||||
BindingTrace moduleTrace = CliLightClassGenerationSupport.createTrace();
|
||||
|
||||
if (module == null) {
|
||||
module = support.newModule();
|
||||
modules.put(entry.getKey(), module);
|
||||
}
|
||||
else {
|
||||
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule());
|
||||
module.seal();
|
||||
}
|
||||
moduleBindings.put(testModule, moduleTrace.getBindingContext());
|
||||
|
||||
ExceptionTracker tracker = new ExceptionTracker();
|
||||
GlobalContext context = new SimpleGlobalContext(
|
||||
@@ -149,7 +134,7 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
Throwable exceptionFromDescriptorValidation = null;
|
||||
try {
|
||||
File expectedFile = new File(FileUtil.getNameWithoutExtension(testDataFile.getAbsolutePath()) + ".txt");
|
||||
validateAndCompareDescriptorWithFile(expectedFile, testFiles, support, modules);
|
||||
validateAndCompareDescriptorWithFile(expectedFile, testFiles, modules);
|
||||
}
|
||||
catch (Throwable e) {
|
||||
exceptionFromDescriptorValidation = e;
|
||||
@@ -167,8 +152,6 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
|
||||
assertTrue("Diagnostics mismatch. See the output above", ok);
|
||||
|
||||
checkAllResolvedCallsAreCompleted(allJetFiles, supportTrace.getBindingContext());
|
||||
|
||||
// now we throw a previously found error, if any
|
||||
if (exceptionFromDescriptorValidation != null) {
|
||||
throw UtilsPackage.rethrow(exceptionFromDescriptorValidation);
|
||||
@@ -246,28 +229,8 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
private void validateAndCompareDescriptorWithFile(
|
||||
File expectedFile,
|
||||
List<TestFile> testFiles,
|
||||
CliLightClassGenerationSupport support,
|
||||
Map<TestModule, ModuleDescriptorImpl> modules
|
||||
) {
|
||||
ModuleDescriptorImpl lightClassModule = support.getLightClassModule();
|
||||
if (lightClassModule == null) {
|
||||
ModuleDescriptorImpl cliModule = support.newModule();
|
||||
cliModule.initialize(new PackageFragmentProvider() {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<PackageFragmentDescriptor> getPackageFragments(@NotNull FqName fqName) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<FqName> getSubPackagesOf(
|
||||
@NotNull FqName fqName, @NotNull Function1<? super Name, ? extends Boolean> nameFilter) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RecursiveDescriptorComparator comparator = new RecursiveDescriptorComparator(createdAffectedPackagesConfiguration(testFiles));
|
||||
|
||||
boolean isMultiModuleTest = modules.size() != 1;
|
||||
@@ -275,13 +238,13 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
|
||||
for (TestModule module : KotlinPackage.sort(modules.keySet())) {
|
||||
ModuleDescriptorImpl moduleDescriptor = modules.get(module);
|
||||
DeclarationDescriptor aPackage = moduleDescriptor.getPackage(FqName.ROOT);
|
||||
assertNotNull(aPackage);
|
||||
|
||||
if (isMultiModuleTest) {
|
||||
rootPackageText.append(String.format("// -- Module: %s --\n", moduleDescriptor.getName()));
|
||||
}
|
||||
|
||||
DeclarationDescriptor aPackage = moduleDescriptor.getPackage(FqName.ROOT);
|
||||
assertNotNull(aPackage);
|
||||
|
||||
String actualSerialized = comparator.serializeRecursively(aPackage);
|
||||
rootPackageText.append(actualSerialized);
|
||||
|
||||
@@ -319,8 +282,11 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
Map<TestModule, ModuleDescriptorImpl> modules = new HashMap<TestModule, ModuleDescriptorImpl>();
|
||||
|
||||
for (TestModule testModule : groupedByModule.keySet()) {
|
||||
if (testModule == null) continue;
|
||||
ModuleDescriptorImpl module = createModule(testModule);
|
||||
ModuleDescriptorImpl module =
|
||||
testModule == null ?
|
||||
TopDownAnalyzerFacadeForJVM.createAnalyzeModule() :
|
||||
createModule(testModule);
|
||||
|
||||
modules.put(testModule, module);
|
||||
}
|
||||
|
||||
@@ -332,7 +298,11 @@ public abstract class AbstractJetDiagnosticsTest extends BaseDiagnosticsTest {
|
||||
for (TestModule dependency : testModule.getDependencies()) {
|
||||
module.addDependencyOnModule(modules.get(dependency));
|
||||
}
|
||||
|
||||
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule());
|
||||
module.seal();
|
||||
}
|
||||
|
||||
return modules;
|
||||
}
|
||||
|
||||
|
||||
@@ -145,10 +145,8 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, new File("compiler/tests")); // for @ExpectLoadError annotation
|
||||
JetCoreEnvironment environment = JetCoreEnvironment.createForTests(getTestRootDisposable(), configuration);
|
||||
|
||||
// we need the same binding trace for resolve from Java and Kotlin
|
||||
CliLightClassGenerationSupport support = CliLightClassGenerationSupport.getInstanceForCli(environment.getProject());
|
||||
BindingTrace trace = support.getTrace();
|
||||
ModuleDescriptorImpl module = support.newModule();
|
||||
BindingTrace trace = CliLightClassGenerationSupport.createTrace();
|
||||
ModuleDescriptorImpl module = TopDownAnalyzerFacadeForJVM.createAnalyzeModule();
|
||||
|
||||
TopDownAnalysisParameters parameters = TopDownAnalysisParameters.create(
|
||||
new LockBasedStorageManager(),
|
||||
@@ -163,8 +161,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
environment.getSourceFiles(),
|
||||
trace,
|
||||
parameters,
|
||||
module
|
||||
);
|
||||
module);
|
||||
|
||||
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
||||
assert packageView != null : "Test package not found";
|
||||
|
||||
@@ -95,7 +95,6 @@ public final class LoadDescriptorUtil {
|
||||
InjectorForJavaDescriptorResolverUtil.create(jetCoreEnvironment.getProject(), trace, true);
|
||||
ModuleDescriptorImpl module = injector.getModule();
|
||||
|
||||
CliLightClassGenerationSupport.getInstanceForCli(jetCoreEnvironment.getProject()).setModule(module);
|
||||
PackageViewDescriptor packageView = module.getPackage(TEST_PACKAGE_FQNAME);
|
||||
assert packageView != null;
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.jet.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.TopDownAnalyzerFacadeForJVM;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -74,17 +75,15 @@ public class JvmResolveUtil {
|
||||
@NotNull Collection<JetFile> files,
|
||||
@NotNull Predicate<PsiFile> filesToAnalyzeCompletely
|
||||
) {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
|
||||
ModuleDescriptorImpl module = TopDownAnalyzerFacadeForJVM.createJavaModule("<module>");
|
||||
module.addDependencyOnModule(module);
|
||||
module.addDependencyOnModule(KotlinBuiltIns.getInstance().getBuiltInsModule());
|
||||
module.seal();
|
||||
|
||||
CliLightClassGenerationSupport lightClassGenerationSupport = CliLightClassGenerationSupport.getInstanceForCli(project);
|
||||
if (lightClassGenerationSupport != null) {
|
||||
lightClassGenerationSupport.setModule(module);
|
||||
}
|
||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(project, files, bindingTraceContext, filesToAnalyzeCompletely,
|
||||
module, null, null);
|
||||
BindingTrace trace = lightClassGenerationSupport != null ? CliLightClassGenerationSupport.createTrace() : new BindingTraceContext();
|
||||
|
||||
return TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
project, files, trace, filesToAnalyzeCompletely, module, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,8 @@ package org.jetbrains.jet.lang.resolve.lazy;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.CliLightClassGenerationSupport;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.context.ContextPackage;
|
||||
@@ -49,22 +47,19 @@ public class LazyResolveTestUtil {
|
||||
}
|
||||
|
||||
private static ModuleDescriptor doResolve(List<JetFile> files, JetCoreEnvironment environment) {
|
||||
JetTestUtils.newTrace(environment);
|
||||
|
||||
GlobalContextImpl globalContext = ContextPackage.GlobalContext();
|
||||
TopDownAnalysisParameters params = TopDownAnalysisParameters.create(
|
||||
globalContext.getStorageManager(),
|
||||
globalContext.getExceptionTracker(),
|
||||
Predicates.<PsiFile>alwaysTrue(),
|
||||
false, false);
|
||||
CliLightClassGenerationSupport support = CliLightClassGenerationSupport.getInstanceForCli(environment.getProject());
|
||||
BindingTrace sharedTrace = support.getTrace();
|
||||
ModuleDescriptorImpl sharedModule = support.newModule();
|
||||
BindingTrace trace = CliLightClassGenerationSupport.createTrace();
|
||||
ModuleDescriptorImpl sharedModule = TopDownAnalyzerFacadeForJVM.createAnalyzeModule();
|
||||
|
||||
TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||
environment.getProject(),
|
||||
files,
|
||||
sharedTrace,
|
||||
files,
|
||||
trace,
|
||||
params, sharedModule);
|
||||
|
||||
return sharedModule;
|
||||
@@ -76,14 +71,7 @@ public class LazyResolveTestUtil {
|
||||
@NotNull JetCoreEnvironment environment,
|
||||
boolean addBuiltIns
|
||||
) {
|
||||
JetTestUtils.newTrace(environment);
|
||||
|
||||
Project project = environment.getProject();
|
||||
CliLightClassGenerationSupport support = CliLightClassGenerationSupport.getInstanceForCli(project);
|
||||
ResolveSession lazyResolveSession = createResolveSessionForFiles(project, files, addBuiltIns);
|
||||
support.setModule((ModuleDescriptorImpl) lazyResolveSession.getModuleDescriptor());
|
||||
|
||||
return lazyResolveSession;
|
||||
return createResolveSessionForFiles(environment.getProject(), files, addBuiltIns);
|
||||
}
|
||||
|
||||
public static ModuleDescriptor resolveLazily(List<JetFile> files, JetCoreEnvironment environment) {
|
||||
|
||||
@@ -45,6 +45,8 @@ import org.jetbrains.jet.lang.resolve.kotlin.JavaDeclarationCheckerProvider
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaFlexibleTypeCapabilitiesProvider
|
||||
import org.jetbrains.jet.context.LazyResolveToken
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaLazyAnalyzerPostConstruct
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolverPostConstruct
|
||||
|
||||
// NOTE: After making changes, you need to re-generate the injectors.
|
||||
// To do that, you can run main in this file.
|
||||
@@ -172,8 +174,9 @@ private fun generatorForTopDownAnalyzerForJvm() =
|
||||
javaClass<JavaPropertyInitializerEvaluatorImpl>(),
|
||||
javaClass<SamConversionResolverImpl>(),
|
||||
javaClass<JavaSourceElementFactoryImpl>(),
|
||||
javaClass<SingleModuleClassResolver>(),
|
||||
javaClass<MutablePackageFragmentProvider>(),
|
||||
javaClass<SingleModuleClassResolver>(),
|
||||
javaClass<JavaLazyAnalyzerPostConstruct>(),
|
||||
javaClass<JavaFlexibleTypeCapabilitiesProvider>()
|
||||
)
|
||||
|
||||
@@ -209,7 +212,8 @@ private fun generatorForJavaDescriptorResolver() =
|
||||
javaClass<JavaPropertyInitializerEvaluatorImpl>(),
|
||||
javaClass<SamConversionResolverImpl>(),
|
||||
javaClass<JavaSourceElementFactoryImpl>(),
|
||||
javaClass<SingleModuleClassResolver>()
|
||||
javaClass<SingleModuleClassResolver>(),
|
||||
javaClass<JavaDescriptorResolverPostConstruct>()
|
||||
)
|
||||
field(javaClass<VirtualFileFinder>(),
|
||||
init = GivenExpression(javaClass<VirtualFileFinder>().getName() + ".SERVICE.getInstance(project)"))
|
||||
@@ -247,7 +251,8 @@ private fun generatorForLazyResolveWithJava() =
|
||||
javaClass<SamConversionResolverImpl>(),
|
||||
javaClass<JavaSourceElementFactoryImpl>(),
|
||||
javaClass<JavaFlexibleTypeCapabilitiesProvider>(),
|
||||
javaClass<LazyResolveToken>()
|
||||
javaClass<LazyResolveToken>(),
|
||||
javaClass<JavaLazyAnalyzerPostConstruct>()
|
||||
)
|
||||
field(javaClass<AdditionalCheckerProvider>(),
|
||||
init = GivenExpression(javaClass<JavaDeclarationCheckerProvider>().getName() + ".INSTANCE$"))
|
||||
|
||||
@@ -247,8 +247,6 @@ private object KotlinResolveDataProvider {
|
||||
TargetPlatformDetector.getPlatform(analyzableElement.getContainingJetFile()).getAdditionalCheckerProvider()
|
||||
).getLazyTopDownAnalyzer()!!
|
||||
|
||||
lazyTopDownAnalyzer.setKotlinCodeAnalyzer(resolveSession);
|
||||
|
||||
lazyTopDownAnalyzer.analyzeDeclarations(
|
||||
TopDownAnalysisParameters.createForLazy(
|
||||
resolveSession.getStorageManager(),
|
||||
|
||||
@@ -158,6 +158,9 @@
|
||||
<projectService serviceInterface="org.jetbrains.jet.asJava.LightClassGenerationSupport"
|
||||
serviceImplementation="org.jetbrains.jet.plugin.caches.resolve.IDELightClassGenerationSupport"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.lang.resolve.CodeAnalyzerInitializer"
|
||||
serviceImplementation="org.jetbrains.jet.lang.resolve.DummyCodeAnalyzerInitializer"/>
|
||||
|
||||
<projectService serviceInterface="org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider"
|
||||
serviceImplementation="org.jetbrains.jet.lang.parsing.JetScriptDefinitionProvider"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user