Passing message collector via CompilerConfiguration.
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
+1
-3
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -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()));
|
||||
|
||||
Reference in New Issue
Block a user