Passing message collector via CompilerConfiguration.

This commit is contained in:
Evgeny Gerashchenko
2012-07-23 20:41:15 +04:00
parent 33c661e7f3
commit 940c09fc8a
9 changed files with 26 additions and 27 deletions
@@ -79,9 +79,9 @@ public class BytecodeCompiler {
}
configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(sourceRoots));
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
JetCoreEnvironment environment = new JetCoreEnvironment(CompileEnvironmentUtil.createMockDisposable(), configuration);
K2JVMCompileEnvironmentConfiguration env = new K2JVMCompileEnvironmentConfiguration(environment,
MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
K2JVMCompileEnvironmentConfiguration env = new K2JVMCompileEnvironmentConfiguration(environment);
// lets register any compiler plugins
configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
@@ -17,6 +17,7 @@
package org.jetbrains.jet.cli.common;
import com.intellij.openapi.util.Key;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import java.util.List;
@@ -25,6 +26,7 @@ import java.util.List;
* @since 7/23/12
*/
public class CLIConfigurationKeys {
public static final Key<MessageCollector> MESSAGE_COLLECTOR_KEY = Key.create("message collector");
public static final Key<List<CompilerPlugin>> COMPILER_PLUGINS = Key.create("compiler plugins");
private CLIConfigurationKeys() {
@@ -25,20 +25,11 @@ import org.jetbrains.jet.cli.common.messages.MessageCollector;
*/
public abstract class CompileEnvironmentConfiguration {
@NotNull
private final MessageCollector messageCollector;
/**
* NOTE: It's very important to call dispose for every object of this class or there will be memory leaks.
*
* @see Disposer
*/
public CompileEnvironmentConfiguration(@NotNull MessageCollector messageCollector) {
this.messageCollector = messageCollector;
}
@NotNull
public MessageCollector getMessageCollector() {
return messageCollector;
public CompileEnvironmentConfiguration() {
}
}
@@ -30,7 +30,7 @@ public class K2JSCompileEnvironmentConfiguration extends CompileEnvironmentConfi
*
* @see Disposer
*/
public K2JSCompileEnvironmentConfiguration(@NotNull MessageCollector messageCollector) {
super(messageCollector);
public K2JSCompileEnvironmentConfiguration() {
super();
}
}
@@ -22,6 +22,7 @@ import com.intellij.openapi.Disposable;
import jet.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.CLICompiler;
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
import org.jetbrains.jet.cli.common.ExitCode;
import org.jetbrains.jet.cli.common.messages.*;
import org.jetbrains.jet.cli.common.util.CompilerPathUtil;
@@ -103,7 +104,9 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
compilerConfiguration.put(JVMConfigurationKeys.BUILTIN_TO_JAVA_TYPES_MAPPING_KEY,
builtins ? BuiltinToJavaTypesMapping.DISABLED : BuiltinToJavaTypesMapping.ENABLED);
K2JVMCompileEnvironmentConfiguration configuration = new K2JVMCompileEnvironmentConfiguration(environment, messageCollector);
compilerConfiguration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
K2JVMCompileEnvironmentConfiguration configuration = new K2JVMCompileEnvironmentConfiguration(environment);
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment",
CompilerMessageLocation.NO_LOCATION);
@@ -24,6 +24,7 @@ import jet.modules.AllModules;
import jet.modules.Module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.common.util.CompilerPathUtil;
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
@@ -98,10 +99,12 @@ public class CompileEnvironmentUtil {
configuration.add(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, jdkAnnotationsPath);
}
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, moduleScriptFile);
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
JetCoreEnvironment scriptEnvironment = JetCoreEnvironment.createCoreEnvironmentForJVM(disposable, configuration);
GenerationState generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(
new K2JVMCompileEnvironmentConfiguration(scriptEnvironment, messageCollector), false);
new K2JVMCompileEnvironmentConfiguration(scriptEnvironment), false);
if (generationState == null) {
throw new CompileEnvironmentException("Module script " + moduleScriptFile + " analyze failed");
}
@@ -32,9 +32,7 @@ public class K2JVMCompileEnvironmentConfiguration extends CompileEnvironmentConf
*
* @see Disposer
*/
public K2JVMCompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment,
@NotNull MessageCollector messageCollector) {
super(messageCollector);
public K2JVMCompileEnvironmentConfiguration(@NotNull JetCoreEnvironment environment) {
this.environment = environment;
}
@@ -116,9 +116,7 @@ public class KotlinToJVMBytecodeCompiler {
compilerConfiguration);
K2JVMCompileEnvironmentConfiguration currentK2JVMConfiguration = new K2JVMCompileEnvironmentConfiguration(
environment, configuration.getMessageCollector()
);
K2JVMCompileEnvironmentConfiguration currentK2JVMConfiguration = new K2JVMCompileEnvironmentConfiguration(environment);
GenerationState generationState = analyzeAndGenerate(currentK2JVMConfiguration);
if (generationState == null) {
return null;
@@ -316,7 +314,8 @@ public class KotlinToJVMBytecodeCompiler {
final List<AnalyzerScriptParameter> scriptParameters,
boolean stubs) {
final JetCoreEnvironment environment = configuration.getEnvironment();
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getMessageCollector());
AnalyzerWithCompilerReport analyzerWithCompilerReport = new AnalyzerWithCompilerReport(configuration.getEnvironment().getConfiguration().get(
CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY));
final Predicate<PsiFile> filesToAnalyzeCompletely =
stubs ? Predicates.<PsiFile>alwaysFalse() : Predicates.<PsiFile>alwaysTrue();
analyzerWithCompilerReport.analyzeAndReport(
@@ -340,15 +339,15 @@ public class KotlinToJVMBytecodeCompiler {
@NotNull
private static GenerationState generate(
final K2JVMCompileEnvironmentConfiguration configuration,
K2JVMCompileEnvironmentConfiguration configuration,
AnalyzeExhaust exhaust,
boolean stubs) {
JetCoreEnvironment environment = configuration.getEnvironment();
final JetCoreEnvironment environment = configuration.getEnvironment();
Project project = environment.getProject();
Progress backendProgress = new Progress() {
@Override
public void log(String message) {
configuration.getMessageCollector().report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
environment.getConfiguration().get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(CompilerMessageSeverity.LOGGING, message, CompilerMessageLocation.NO_LOCATION);
}
};
GenerationState generationState = new GenerationState(project, ClassBuilderFactories.binaries(stubs), backendProgress,
@@ -375,6 +374,7 @@ public class KotlinToJVMBytecodeCompiler {
Disposable rootDisposable = CompileEnvironmentUtil.createMockDisposable();
try {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
compilerConfiguration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector);
compilerConfiguration.addAll(JVMConfigurationKeys.CLASSPATH_KEY, getClasspath(parentLoader));
compilerConfiguration.addAll(JVMConfigurationKeys.ANNOTATIONS_PATH_KEY, Collections.singletonList(
CompilerPathUtil.getJdkAnnotationsPath()));
@@ -24,6 +24,7 @@ import org.jetbrains.jet.CompileCompilerDependenciesTest;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
@@ -79,7 +80,7 @@ public class TestlibTest extends CodegenTestCase {
private TestSuite doBuildSuite() {
try {
GenerationState generationState = KotlinToJVMBytecodeCompiler.analyzeAndGenerate(
new K2JVMCompileEnvironmentConfiguration(myEnvironment, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR), false);
new K2JVMCompileEnvironmentConfiguration(myEnvironment), false);
if (generationState == null) {
throw new RuntimeException("There were compilation errors");
@@ -164,6 +165,7 @@ public class TestlibTest extends CodegenTestCase {
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetParsingTest.getTestDataDir() + "/../../libraries/stdlib/test");
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetParsingTest.getTestDataDir() + "/../../libraries/kunit/src");
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.PLAIN_TEXT_TO_SYSTEM_ERR);
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), configuration);
}