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