Use CompileEnvironmentConfiguretion instead of its components
This commit is contained in:
@@ -173,7 +173,7 @@ public class CompileEnvironmentUtil {
|
|||||||
scriptEnvironment.addSources(moduleFile);
|
scriptEnvironment.addSources(moduleFile);
|
||||||
|
|
||||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||||
.analyzeAndGenerate(scriptEnvironment, dependencies, messageCollector, false);
|
.analyzeAndGenerate(new CompileEnvironmentConfiguration(scriptEnvironment, dependencies, messageCollector), false);
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
|||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.FqName;
|
import org.jetbrains.jet.lang.resolve.FqName;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
|
||||||
import org.jetbrains.jet.lang.resolve.java.CompilerDependencies;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.plugin.JetLanguage;
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||||
@@ -219,19 +218,16 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) {
|
public static GenerationState analyzeAndGenerate(CompileEnvironmentConfiguration configuration) {
|
||||||
return analyzeAndGenerate(configuration.getEnvironment(), configuration.getCompilerDependencies(), configuration.getMessageCollector(), configuration.getCompilerDependencies().getCompilerSpecialMode().isStubs());
|
return analyzeAndGenerate(configuration, configuration.getCompilerDependencies().getCompilerSpecialMode().isStubs());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static GenerationState analyzeAndGenerate(
|
public static GenerationState analyzeAndGenerate(
|
||||||
JetCoreEnvironment environment,
|
CompileEnvironmentConfiguration configuration,
|
||||||
CompilerDependencies dependencies,
|
|
||||||
|
|
||||||
final MessageCollector messageCollector,
|
|
||||||
|
|
||||||
boolean stubs
|
boolean stubs
|
||||||
) {
|
) {
|
||||||
AnalyzeExhaust exhaust = analyze(environment, dependencies, messageCollector, stubs);
|
AnalyzeExhaust exhaust = analyze(configuration, stubs);
|
||||||
|
|
||||||
if (exhaust == null) {
|
if (exhaust == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -239,14 +235,13 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
|
|
||||||
exhaust.throwIfError();
|
exhaust.throwIfError();
|
||||||
|
|
||||||
return generate(environment, dependencies, messageCollector, exhaust, stubs);
|
return generate(configuration, exhaust, stubs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static AnalyzeExhaust analyze(
|
private static AnalyzeExhaust analyze(
|
||||||
JetCoreEnvironment environment,
|
final CompileEnvironmentConfiguration configuration,
|
||||||
CompilerDependencies dependencies,
|
|
||||||
final MessageCollector messageCollector,
|
|
||||||
boolean stubs) {
|
boolean stubs) {
|
||||||
final Ref<Boolean> hasErrors = new Ref<Boolean>(false);
|
final Ref<Boolean> hasErrors = new Ref<Boolean>(false);
|
||||||
final MessageCollector messageCollectorWrapper = new MessageCollector() {
|
final MessageCollector messageCollectorWrapper = new MessageCollector() {
|
||||||
@@ -258,10 +253,12 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
if (CompilerMessageSeverity.ERRORS.contains(severity)) {
|
if (CompilerMessageSeverity.ERRORS.contains(severity)) {
|
||||||
hasErrors.set(true);
|
hasErrors.set(true);
|
||||||
}
|
}
|
||||||
messageCollector.report(severity, message, location);
|
configuration.getMessageCollector().report(severity, message, location);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
JetCoreEnvironment environment = configuration.getEnvironment();
|
||||||
|
|
||||||
// Report syntax errors
|
// Report syntax errors
|
||||||
for (JetFile file : environment.getSourceFiles()) {
|
for (JetFile file : environment.getSourceFiles()) {
|
||||||
file.accept(new PsiRecursiveElementWalkingVisitor() {
|
file.accept(new PsiRecursiveElementWalkingVisitor() {
|
||||||
@@ -280,7 +277,7 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
|
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
|
||||||
AnalyzeExhaust exhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
AnalyzeExhaust exhaust = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
|
||||||
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY,
|
environment.getProject(), environment.getSourceFiles(), filesToAnalyzeCompletely, JetControlFlowDataTraceFactory.EMPTY,
|
||||||
dependencies);
|
configuration.getCompilerDependencies());
|
||||||
|
|
||||||
for (Diagnostic diagnostic : exhaust.getBindingContext().getDiagnostics()) {
|
for (Diagnostic diagnostic : exhaust.getBindingContext().getDiagnostics()) {
|
||||||
reportDiagnostic(messageCollectorWrapper, diagnostic);
|
reportDiagnostic(messageCollectorWrapper, diagnostic);
|
||||||
@@ -293,26 +290,24 @@ public class KotlinToJVMBytecodeCompiler {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static GenerationState generate(
|
private static GenerationState generate(
|
||||||
JetCoreEnvironment environment,
|
final CompileEnvironmentConfiguration configuration,
|
||||||
CompilerDependencies dependencies,
|
|
||||||
|
|
||||||
final MessageCollector messageCollector,
|
|
||||||
|
|
||||||
AnalyzeExhaust exhaust,
|
AnalyzeExhaust exhaust,
|
||||||
|
|
||||||
boolean stubs) {
|
boolean stubs) {
|
||||||
|
JetCoreEnvironment environment = configuration.getEnvironment();
|
||||||
Project project = environment.getProject();
|
Project project = environment.getProject();
|
||||||
Progress backendProgress = new Progress() {
|
Progress backendProgress = new Progress() {
|
||||||
@Override
|
@Override
|
||||||
public void log(String message) {
|
public void log(String message) {
|
||||||
messageCollector.report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
|
configuration.getMessageCollector().report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
|
||||||
exhaust, environment.getSourceFiles(), dependencies.getCompilerSpecialMode());
|
exhaust, environment.getSourceFiles(), configuration.getCompilerDependencies().getCompilerSpecialMode());
|
||||||
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
generationState.compileCorrectFiles(CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
|
|
||||||
List<CompilerPlugin> plugins = environment.getCompilerPlugins();
|
List<CompilerPlugin> plugins = configuration.getCompilerPlugins();
|
||||||
if (plugins != null) {
|
if (plugins != null) {
|
||||||
CompilerPluginContext context = new CompilerPluginContext(project, exhaust.getBindingContext(), environment.getSourceFiles());
|
CompilerPluginContext context = new CompilerPluginContext(project, exhaust.getBindingContext(), environment.getSourceFiles());
|
||||||
for (CompilerPlugin plugin : plugins) {
|
for (CompilerPlugin plugin : plugins) {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import junit.framework.TestCase;
|
|||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
import org.jetbrains.jet.CompileCompilerDependenciesTest;
|
||||||
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime;
|
||||||
|
import org.jetbrains.jet.compiler.CompileEnvironmentConfiguration;
|
||||||
import org.jetbrains.jet.compiler.KotlinToJVMBytecodeCompiler;
|
import org.jetbrains.jet.compiler.KotlinToJVMBytecodeCompiler;
|
||||||
import org.jetbrains.jet.compiler.messages.MessageCollector;
|
import org.jetbrains.jet.compiler.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
@@ -37,7 +38,6 @@ import org.jetbrains.jet.lang.types.JetType;
|
|||||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -75,7 +75,6 @@ public class TestlibTest extends CodegenTestCase {
|
|||||||
|
|
||||||
private TestSuite doBuildSuite() {
|
private TestSuite doBuildSuite() {
|
||||||
try {
|
try {
|
||||||
PrintStream err = System.err;
|
|
||||||
CompilerDependencies compilerDependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR);
|
CompilerDependencies compilerDependencies = CompileCompilerDependenciesTest.compilerDependenciesForTests(CompilerSpecialMode.REGULAR);
|
||||||
File junitJar = new File("libraries/lib/junit-4.9.jar");
|
File junitJar = new File("libraries/lib/junit-4.9.jar");
|
||||||
|
|
||||||
@@ -92,7 +91,7 @@ public class TestlibTest extends CodegenTestCase {
|
|||||||
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src"));
|
myEnvironment.addSources(localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src"));
|
||||||
|
|
||||||
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
GenerationState generationState = KotlinToJVMBytecodeCompiler
|
||||||
.analyzeAndGenerate(myEnvironment, compilerDependencies, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR, false);
|
.analyzeAndGenerate(new CompileEnvironmentConfiguration(myEnvironment, compilerDependencies, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR), false);
|
||||||
|
|
||||||
if (generationState == null) {
|
if (generationState == null) {
|
||||||
throw new RuntimeException("There were compilation errors");
|
throw new RuntimeException("There were compilation errors");
|
||||||
|
|||||||
Reference in New Issue
Block a user