CompilerDependencies

Holds reference to runtime.jar and jdk-headers.jar. Paths to these
jars are no longer hardcoded.

Many tests now compile runtime before execution. Because of this:
* Single test invocation is significantly slower now for some tests
* This can be fixed by making tests independent from runtime (this
must be done anyway)

Some tests still depend on runtime.jar built by "ant dist", this
is to be fixed.
This commit is contained in:
Stepan Koltsov
2012-04-09 03:04:50 +04:00
parent aae7ba734d
commit 10dd366216
48 changed files with 422 additions and 128 deletions
@@ -23,10 +23,12 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderForJvm;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import com.intellij.openapi.project.Project;
import org.jetbrains.jet.lang.resolve.java.JavaTypeTransformer;
import org.jetbrains.jet.lang.resolve.NamespaceFactoryImpl;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
@@ -40,6 +42,7 @@ public class InjectorForJavaSemanticServices {
private final Project project;
public InjectorForJavaSemanticServices(
@NotNull CompilerDependencies compilerDependencies,
@NotNull Project project
) {
this.javaSemanticServices = new JavaSemanticServices();
@@ -48,7 +51,7 @@ public class InjectorForJavaSemanticServices {
JavaBridgeConfiguration javaBridgeConfiguration = new JavaBridgeConfiguration();
this.psiClassFinderForJvm = new PsiClassFinderForJvm();
ModuleDescriptor moduleDescriptor = new org.jetbrains.jet.lang.descriptors.ModuleDescriptor("<dummy>");
CompilerSpecialMode compilerSpecialMode = CompilerSpecialMode.REGULAR;
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
this.project = project;
JavaTypeTransformer javaTypeTransformer = new JavaTypeTransformer();
NamespaceFactoryImpl namespaceFactoryImpl = new NamespaceFactoryImpl();
@@ -68,7 +71,7 @@ public class InjectorForJavaSemanticServices {
javaBridgeConfiguration.setMode(compilerSpecialMode);
javaBridgeConfiguration.setProject(project);
this.psiClassFinderForJvm.setCompilerSpecialMode(compilerSpecialMode);
this.psiClassFinderForJvm.setCompilerDependencies(compilerDependencies);
this.psiClassFinderForJvm.setProject(project);
javaTypeTransformer.setJavaSemanticServices(javaSemanticServices);
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
import org.jetbrains.jet.lang.resolve.java.PsiClassFinderForJvm;
@@ -52,7 +53,7 @@ import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
import org.jetbrains.annotations.NotNull;
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
@@ -75,7 +76,7 @@ public class InjectorForTopDownAnalyzerForJvm {
@NotNull ObservableBindingTrace observableBindingTrace,
@NotNull ModuleDescriptor moduleDescriptor,
JetControlFlowDataTraceFactory jetControlFlowDataTraceFactory,
@NotNull CompilerSpecialMode compilerSpecialMode
@NotNull CompilerDependencies compilerDependencies
) {
this.topDownAnalyzer = new TopDownAnalyzer();
this.topDownAnalysisContext = new TopDownAnalysisContext();
@@ -86,6 +87,7 @@ public class InjectorForTopDownAnalyzerForJvm {
this.project = project;
this.topDownAnalysisParameters = topDownAnalysisParameters;
this.observableBindingTrace = observableBindingTrace;
CompilerSpecialMode compilerSpecialMode = compilerDependencies.getCompilerSpecialMode();
this.javaBridgeConfiguration = new JavaBridgeConfiguration();
PsiClassFinderForJvm psiClassFinderForJvm = new PsiClassFinderForJvm();
DeclarationResolver declarationResolver = new DeclarationResolver();
@@ -144,7 +146,7 @@ public class InjectorForTopDownAnalyzerForJvm {
this.javaBridgeConfiguration.setMode(compilerSpecialMode);
this.javaBridgeConfiguration.setProject(project);
psiClassFinderForJvm.setCompilerSpecialMode(compilerSpecialMode);
psiClassFinderForJvm.setCompilerDependencies(compilerDependencies);
psiClassFinderForJvm.setProject(project);
declarationResolver.setAnnotationResolver(annotationResolver);
@@ -71,7 +71,9 @@ public class AnalyzerFacadeForJVM {
* @param declarationProvider
* @return
*/
public static AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file, @NotNull final Function<JetFile, Collection<JetFile>> declarationProvider) {
public static AnalyzeExhaust analyzeFileWithCache(@NotNull final JetFile file,
@NotNull final Function<JetFile, Collection<JetFile>> declarationProvider,
@NotNull final CompilerSpecialMode compilerSpecialMode, @NotNull final CompilerDependencies compilerDependencies) {
// Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously
synchronized (lock) {
CachedValue<AnalyzeExhaust> bindingContextCachedValue = file.getUserData(BINDING_CONTEXT);
@@ -80,12 +82,13 @@ public class AnalyzerFacadeForJVM {
@Override
public Result<AnalyzeExhaust> compute() {
try {
AnalyzeExhaust bindingContext = analyzeFilesWithJavaIntegration(
AnalyzeExhaust bindingContext;
bindingContext = analyzeFilesWithJavaIntegration(
file.getProject(),
declarationProvider.fun(file),
Predicates.<PsiFile>equalTo(file),
JetControlFlowDataTraceFactory.EMPTY,
CompilerSpecialMode.REGULAR);
compilerDependencies);
return new Result<AnalyzeExhaust>(bindingContext, PsiModificationTracker.MODIFICATION_COUNT);
}
catch (ProcessCanceledException e) {
@@ -111,7 +114,9 @@ public class AnalyzerFacadeForJVM {
* Analyze project with string cache for the whole project. All given files will be analyzed only for descriptors.
*/
public static AnalyzeExhaust analyzeProjectWithCache(@NotNull final Project project,
@NotNull final Collection<JetFile> files) {
@NotNull final Collection<JetFile> files,
@NotNull final CompilerSpecialMode compilerSpecialMode,
@NotNull final CompilerDependencies compilerDependencies) {
// Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously
synchronized (lock) {
CachedValue<AnalyzeExhaust> bindingContextCachedValue = project.getUserData(BINDING_CONTEXT);
@@ -125,7 +130,7 @@ public class AnalyzerFacadeForJVM {
files,
Predicates.<PsiFile>alwaysFalse(),
JetControlFlowDataTraceFactory.EMPTY,
CompilerSpecialMode.REGULAR);
compilerDependencies);
return new Result<AnalyzeExhaust>(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT);
}
catch (ProcessCanceledException e) {
@@ -147,25 +152,28 @@ public class AnalyzerFacadeForJVM {
}
public static AnalyzeExhaust analyzeOneFileWithJavaIntegrationAndCheckForErrors(
JetFile file, JetControlFlowDataTraceFactory flowDataTraceFactory) {
JetFile file, JetControlFlowDataTraceFactory flowDataTraceFactory,
@NotNull CompilerSpecialMode compilerSpecialMode, @NotNull CompilerDependencies compilerDependencies) {
AnalyzingUtils.checkForSyntacticErrors(file);
AnalyzeExhaust analyzeExhaust = analyzeOneFileWithJavaIntegration(file, flowDataTraceFactory);
AnalyzeExhaust analyzeExhaust = analyzeOneFileWithJavaIntegration(file, flowDataTraceFactory, compilerDependencies);
AnalyzingUtils.throwExceptionOnErrors(analyzeExhaust.getBindingContext());
return analyzeExhaust;
}
public static AnalyzeExhaust analyzeOneFileWithJavaIntegration(JetFile file, JetControlFlowDataTraceFactory flowDataTraceFactory) {
public static AnalyzeExhaust analyzeOneFileWithJavaIntegration(
JetFile file, JetControlFlowDataTraceFactory flowDataTraceFactory,
@NotNull CompilerDependencies compilerDependencies) {
return analyzeFilesWithJavaIntegration(file.getProject(), Collections.singleton(file),
Predicates.<PsiFile>alwaysTrue(), flowDataTraceFactory, CompilerSpecialMode.REGULAR);
Predicates.<PsiFile>alwaysTrue(), flowDataTraceFactory, compilerDependencies);
}
public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
Project project, Collection<JetFile> files, Predicate<PsiFile> filesToAnalyzeCompletely,
JetControlFlowDataTraceFactory flowDataTraceFactory,
CompilerSpecialMode compilerSpecialMode) {
@NotNull CompilerDependencies compilerDependencies) {
BindingTraceContext bindingTraceContext = new BindingTraceContext();
final ModuleDescriptor owner = new ModuleDescriptor("<module>");
@@ -177,19 +185,20 @@ public class AnalyzerFacadeForJVM {
InjectorForTopDownAnalyzerForJvm injector = new InjectorForTopDownAnalyzerForJvm(
project, topDownAnalysisParameters,
new ObservableBindingTrace(bindingTraceContext), owner, flowDataTraceFactory,
compilerSpecialMode);
compilerDependencies);
injector.getTopDownAnalyzer().analyzeFiles(files);
return new AnalyzeExhaust(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance());
}
public static AnalyzeExhaust shallowAnalyzeFiles(Collection<JetFile> files) {
public static AnalyzeExhaust shallowAnalyzeFiles(Collection<JetFile> files,
@NotNull CompilerSpecialMode compilerSpecialMode, @NotNull CompilerDependencies compilerDependencies) {
assert files.size() > 0;
Project project = files.iterator().next().getProject();
return analyzeFilesWithJavaIntegration(project, files, Predicates.<PsiFile>alwaysFalse(),
JetControlFlowDataTraceFactory.EMPTY, CompilerSpecialMode.REGULAR);
JetControlFlowDataTraceFactory.EMPTY, compilerDependencies);
}
}
@@ -0,0 +1,98 @@
/*
* Copyright 2010-2012 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.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.utils.PathUtil;
import java.io.File;
import java.util.Collections;
import java.util.List;
/**
* @author Stepan Koltsov
*/
public class CompilerDependencies {
@NotNull
private final CompilerSpecialMode compilerSpecialMode;
@Nullable
private final File jdkHeadersJar;
@Nullable
private final File runtimeJar;
public CompilerDependencies(@NotNull CompilerSpecialMode compilerSpecialMode, @Nullable File jdkHeadersJar, @Nullable File runtimeJar) {
this.compilerSpecialMode = compilerSpecialMode;
this.jdkHeadersJar = jdkHeadersJar;
this.runtimeJar = runtimeJar;
if (compilerSpecialMode.includeJdkHeaders()) {
if (jdkHeadersJar == null) {
throw new IllegalArgumentException("jdkHeaders must be included for mode " + compilerSpecialMode);
}
}
if (compilerSpecialMode.includeKotlinRuntime()) {
if (runtimeJar == null) {
throw new IllegalArgumentException("runtime must be include for mode " + compilerSpecialMode);
}
}
}
@NotNull
public CompilerSpecialMode getCompilerSpecialMode() {
return compilerSpecialMode;
}
@Nullable
public File getJdkHeadersJar() {
return jdkHeadersJar;
}
@Nullable
public File getRuntimeJar() {
return runtimeJar;
}
@NotNull
public List<VirtualFile> getJdkHeaderRoots() {
if (compilerSpecialMode.includeJdkHeaders()) {
return Collections.singletonList(PathUtil.jarFileToVirtualFile(jdkHeadersJar));
} else {
return Collections.emptyList();
}
}
@NotNull
public List<VirtualFile> getRuntimeRoots() {
if (compilerSpecialMode.includeKotlinRuntime()) {
return Collections.singletonList(PathUtil.jarFileToVirtualFile(runtimeJar));
} else {
return Collections.emptyList();
}
}
@NotNull
public static CompilerDependencies compilerDependenciesForProduction(@NotNull CompilerSpecialMode compilerSpecialMode) {
return new CompilerDependencies(
compilerSpecialMode,
compilerSpecialMode.includeJdkHeaders() ? PathUtil.getAltHeadersPath() : null,
compilerSpecialMode.includeKotlinRuntime() ? PathUtil.getDefaultRuntimePath() : null);
}
}
@@ -30,6 +30,10 @@ public enum CompilerSpecialMode {
return this == REGULAR || this == STDLIB;
}
public boolean includeKotlinRuntime() {
return this == REGULAR;
}
public boolean isStubs() {
return this == BUILTINS || this == JDK_HEADERS;
}
@@ -43,7 +43,7 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
@NotNull
private Project project;
@NotNull
private CompilerSpecialMode compilerSpecialMode;
private CompilerDependencies compilerDependencies;
private AltClassFinder altClassFinder;
private GlobalSearchScope javaSearchScope;
@@ -55,14 +55,13 @@ public class PsiClassFinderForJvm implements PsiClassFinder {
}
@Inject
public void setCompilerSpecialMode(@NotNull CompilerSpecialMode compilerSpecialMode) {
this.compilerSpecialMode = compilerSpecialMode;
public void setCompilerDependencies(@NotNull CompilerDependencies compilerDependencies) {
this.compilerDependencies = compilerDependencies;
}
@PostConstruct
public void initialize() {
this.altClassFinder = new AltClassFinder(project,
compilerSpecialMode.includeJdkHeaders() ? PathUtil.getAltHeadersRoots() : Collections.<VirtualFile>emptyList());
this.altClassFinder = new AltClassFinder(project, compilerDependencies.getJdkHeaderRoots());
this.javaSearchScope = new DelegatingGlobalSearchScope(GlobalSearchScope.allScope(project)) {
@Override
public boolean contains(VirtualFile file) {