Use null instead of CompilerMessageLocation.NO_LOCATION in MessageCollector
This commit is contained in:
@@ -42,6 +42,7 @@ import java.util.function.Predicate;
|
||||
|
||||
import static org.jetbrains.kotlin.cli.common.ExitCode.*;
|
||||
import static org.jetbrains.kotlin.cli.common.environment.UtilKt.setIdeaIoUseFallback;
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
|
||||
|
||||
public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
|
||||
@@ -76,11 +77,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
Usage.print(errStream, createArguments(), false);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
errStream.println(messageRenderer.render(
|
||||
CompilerMessageSeverity.EXCEPTION,
|
||||
OutputMessageUtil.renderException(t),
|
||||
CompilerMessageLocation.NO_LOCATION)
|
||||
);
|
||||
errStream.println(messageRenderer.render(EXCEPTION, OutputMessageUtil.renderException(t), CompilerMessageLocation.NO_LOCATION));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -137,7 +134,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
printVersionIfNeeded(messageCollector, arguments);
|
||||
|
||||
if (arguments.suppressWarnings) {
|
||||
messageCollector = new FilteringMessageCollector(messageCollector, Predicate.isEqual(CompilerMessageSeverity.WARNING));
|
||||
messageCollector = new FilteringMessageCollector(messageCollector, Predicate.isEqual(WARNING));
|
||||
}
|
||||
|
||||
reportUnknownExtraFlags(messageCollector, arguments);
|
||||
@@ -176,14 +173,13 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
exitCode = groupingCollector.hasErrors() ? COMPILATION_ERROR : code;
|
||||
}
|
||||
catch (CompilationCanceledException e) {
|
||||
messageCollector.report(CompilerMessageSeverity.INFO, "Compilation was canceled", CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(INFO, "Compilation was canceled", null);
|
||||
return ExitCode.OK;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (cause instanceof CompilationCanceledException) {
|
||||
messageCollector
|
||||
.report(CompilerMessageSeverity.INFO, "Compilation was canceled", CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(INFO, "Compilation was canceled", null);
|
||||
return ExitCode.OK;
|
||||
}
|
||||
else {
|
||||
@@ -197,8 +193,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
return exitCode;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
groupingCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t),
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
MessageCollectorUtil.reportException(groupingCollector, t);
|
||||
return INTERNAL_ERROR;
|
||||
}
|
||||
finally {
|
||||
@@ -243,19 +238,19 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
|
||||
if (apiVersion.compareTo(languageVersion) > 0) {
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
CompilerMessageSeverity.ERROR,
|
||||
ERROR,
|
||||
"-api-version (" + apiVersion.getVersionString() + ") cannot be greater than " +
|
||||
"-language-version (" + languageVersion.getVersionString() + ")",
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
if (!languageVersion.isStable()) {
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
STRONG_WARNING,
|
||||
"Language version " + languageVersion.getVersionString() + " is experimental, there are " +
|
||||
"no backwards compatibility guarantees for new language and library features",
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -292,10 +287,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
}
|
||||
else {
|
||||
String message = "The -Xcoroutines can only have one value";
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION
|
||||
);
|
||||
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(ERROR, message, null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -314,10 +306,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
List<String> versionStrings = ArraysKt.map(LanguageVersion.values(), LanguageVersion::getDescription);
|
||||
String message = "Unknown " + versionOf + " version: " + value + "\n" +
|
||||
"Supported " + versionOf + " versions: " + StringsKt.join(versionStrings, ", ");
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION
|
||||
);
|
||||
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(ERROR, message, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -327,11 +316,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
|
||||
private void reportUnknownExtraFlags(@NotNull MessageCollector collector, @NotNull A arguments) {
|
||||
for (String flag : arguments.unknownExtraFlags) {
|
||||
collector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
"Flag is not supported by this version of the compiler: " + flag,
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
);
|
||||
collector.report(STRONG_WARNING, "Flag is not supported by this version of the compiler: " + flag, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,9 +330,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
private void printVersionIfNeeded(@NotNull MessageCollector messageCollector, @NotNull A arguments) {
|
||||
if (!arguments.version) return;
|
||||
|
||||
messageCollector.report(CompilerMessageSeverity.INFO,
|
||||
"Kotlin Compiler version " + KotlinCompilerVersion.VERSION,
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(INFO, "Kotlin Compiler version " + KotlinCompilerVersion.VERSION, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
-12
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiErrorElement
|
||||
import com.intellij.psi.PsiModifierListOwner
|
||||
import com.intellij.psi.util.PsiFormatUtil
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
import org.jetbrains.kotlin.codegen.state.IncompatibleClassTrackerImpl
|
||||
import org.jetbrains.kotlin.diagnostics.*
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils.sortedDiagnostics
|
||||
@@ -54,7 +55,7 @@ class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector)
|
||||
assert(unresolved != null && !unresolved.isEmpty()) { "Incomplete hierarchy should be reported with names of unresolved superclasses: " + fqName }
|
||||
message.append(" class ").append(fqName).append(", unresolved supertypes: ").append(unresolved!!.joinToString()).append("\n")
|
||||
}
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, message.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +78,7 @@ class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector)
|
||||
message.append(" ").append(error).append("\n")
|
||||
}
|
||||
}
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, message.toString(), CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, message.toString())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +121,9 @@ class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector)
|
||||
companion object {
|
||||
|
||||
fun convertSeverity(severity: Severity): CompilerMessageSeverity = when (severity) {
|
||||
Severity.INFO -> CompilerMessageSeverity.INFO
|
||||
Severity.ERROR -> CompilerMessageSeverity.ERROR
|
||||
Severity.WARNING -> CompilerMessageSeverity.WARNING
|
||||
Severity.INFO -> INFO
|
||||
Severity.ERROR -> ERROR
|
||||
Severity.WARNING -> WARNING
|
||||
else -> throw IllegalStateException("Unknown severity: " + severity)
|
||||
}
|
||||
|
||||
@@ -160,10 +161,9 @@ class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector)
|
||||
|
||||
if (hasIncompatibleClassErrors) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR,
|
||||
ERROR,
|
||||
"Incompatible classes were found in dependencies. " +
|
||||
"Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors",
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
"Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -205,10 +205,9 @@ class AnalyzerWithCompilerReport(private val messageCollector: MessageCollector)
|
||||
}
|
||||
|
||||
fun reportBytecodeVersionErrors(bindingContext: BindingContext, messageCollector: MessageCollector) {
|
||||
val severity = if (System.getProperty("kotlin.jvm.disable.bytecode.version.error") == "true")
|
||||
CompilerMessageSeverity.STRONG_WARNING
|
||||
else
|
||||
CompilerMessageSeverity.ERROR
|
||||
val severity =
|
||||
if (System.getProperty("kotlin.jvm.disable.bytecode.version.error") == "true") STRONG_WARNING
|
||||
else ERROR
|
||||
|
||||
val locations = bindingContext.getKeys(IncompatibleClassTrackerImpl.BYTECODE_VERSION_ERRORS)
|
||||
if (locations.isEmpty()) return
|
||||
|
||||
@@ -30,9 +30,9 @@ import static com.intellij.openapi.util.io.FileUtil.toSystemDependentName;
|
||||
public class MessageUtil {
|
||||
private MessageUtil() {}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public static CompilerMessageLocation psiElementToMessageLocation(@Nullable PsiElement element) {
|
||||
if (element == null) return CompilerMessageLocation.NO_LOCATION;
|
||||
if (element == null) return null;
|
||||
PsiFile file = element.getContainingFile();
|
||||
return psiFileToMessageLocation(file, "<no path>", DiagnosticUtils.getLineAndColumnInPsiFile(file, element.getTextRange()));
|
||||
}
|
||||
|
||||
+3
-2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.cli.common.messages;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
@@ -41,13 +42,13 @@ public class PrintingMessageCollector implements MessageCollector {
|
||||
public void report(
|
||||
@NotNull CompilerMessageSeverity severity,
|
||||
@NotNull String message,
|
||||
@NotNull CompilerMessageLocation location
|
||||
@Nullable CompilerMessageLocation location
|
||||
) {
|
||||
if (!verbose && CompilerMessageSeverity.VERBOSE.contains(severity)) return;
|
||||
|
||||
hasErrors |= severity.isError();
|
||||
|
||||
errStream.println(messageRenderer.render(severity, message, location));
|
||||
errStream.println(messageRenderer.render(severity, message, location != null ? location : CompilerMessageLocation.NO_LOCATION));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.output.outputUtils
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import java.io.File
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFile
|
||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
|
||||
import java.io.File
|
||||
|
||||
fun OutputFileCollection.writeAll(outputDir: File, report: (file: OutputFile, sources: List<File>, output: File) -> Unit) {
|
||||
for (file in asList()) {
|
||||
@@ -42,6 +41,6 @@ fun OutputFileCollection.writeAllTo(outputDir: File) {
|
||||
|
||||
fun OutputFileCollection.writeAll(outputDir: File, messageCollector: MessageCollector) {
|
||||
writeAll(outputDir) { _, sources, output ->
|
||||
messageCollector.report(CompilerMessageSeverity.OUTPUT, OutputMessageUtil.formatOutputMessage(sources, output), CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(CompilerMessageSeverity.OUTPUT, OutputMessageUtil.formatOutputMessage(sources, output))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.js;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -35,8 +34,6 @@ import org.jetbrains.kotlin.cli.common.ExitCode;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants;
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation;
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.OutputUtilsKt;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
||||
@@ -58,6 +55,7 @@ import org.jetbrains.kotlin.psi.KtFile;
|
||||
import org.jetbrains.kotlin.serialization.js.ModuleKind;
|
||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||
import org.jetbrains.kotlin.utils.PathUtil;
|
||||
import org.jetbrains.kotlin.utils.StringsKt;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
@@ -66,7 +64,7 @@ import java.util.Map;
|
||||
import static org.jetbrains.kotlin.cli.common.ExitCode.COMPILATION_ERROR;
|
||||
import static org.jetbrains.kotlin.cli.common.ExitCode.OK;
|
||||
import static org.jetbrains.kotlin.cli.common.UtilsKt.checkKotlinPackageUsage;
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
|
||||
|
||||
public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
private static final Map<String, ModuleKind> moduleKindMap = new HashMap<>();
|
||||
@@ -99,7 +97,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
if (arguments.version) {
|
||||
return OK;
|
||||
}
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify at least one source file or directory", NO_LOCATION);
|
||||
messageCollector.report(ERROR, "Specify at least one source file or directory", null);
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
@@ -115,7 +113,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
if (!checkKotlinPackageUsage(environmentForJS, sourcesFiles)) return ExitCode.COMPILATION_ERROR;
|
||||
|
||||
if (arguments.outputFile == null) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Specify output file via -output", CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(ERROR, "Specify output file via -output", null);
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
@@ -124,7 +122,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
}
|
||||
|
||||
if (sourcesFiles.isEmpty()) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(ERROR, "No source files", null);
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
@@ -140,12 +138,12 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
if (config.checkLibFilesAndReportErrors(new JsConfig.Reporter() {
|
||||
@Override
|
||||
public void error(@NotNull String message) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(ERROR, message, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warning(@NotNull String message) {
|
||||
messageCollector.report(CompilerMessageSeverity.STRONG_WARNING, message, CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(STRONG_WARNING, message, null);
|
||||
}
|
||||
})) {
|
||||
return COMPILATION_ERROR;
|
||||
@@ -166,9 +164,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
if (arguments.outputPrefix != null) {
|
||||
outputPrefixFile = new File(arguments.outputPrefix);
|
||||
if (!outputPrefixFile.exists()) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"Output prefix file '" + arguments.outputPrefix + "' not found",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(ERROR, "Output prefix file '" + arguments.outputPrefix + "' not found", null);
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -177,9 +173,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
if (arguments.outputPostfix != null) {
|
||||
outputPostfixFile = new File(arguments.outputPostfix);
|
||||
if (!outputPostfixFile.exists()) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"Output postfix file '" + arguments.outputPostfix + "' not found",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(ERROR, "Output postfix file '" + arguments.outputPostfix + "' not found", null);
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
}
|
||||
}
|
||||
@@ -206,9 +200,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
OutputFileCollection outputFiles = successResult.getOutputFiles(outputFile, outputPrefixFile, outputPostfixFile);
|
||||
|
||||
if (outputFile.isDirectory()) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"Cannot open output file '" + outputFile.getPath() + "': is a directory",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(ERROR, "Cannot open output file '" + outputFile.getPath() + "': is a directory", null);
|
||||
return ExitCode.COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
@@ -232,8 +224,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
}
|
||||
return file.getName() + "(no virtual file)";
|
||||
});
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Compiling source files: " + Joiner.on(", ").join(fileNames),
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(LOGGING, "Compiling source files: " + StringsKt.join(fileNames, ", "), null);
|
||||
}
|
||||
|
||||
private static AnalyzerWithCompilerReport analyzeAndReportErrors(
|
||||
@@ -291,9 +282,9 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
String moduleKindName = arguments.moduleKind;
|
||||
ModuleKind moduleKind = moduleKindName != null ? moduleKindMap.get(moduleKindName) : ModuleKind.PLAIN;
|
||||
if (moduleKind == null) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Unknown module kind: " + moduleKindName + ". " +
|
||||
"Valid values are: plain, amd, commonjs, umd",
|
||||
CompilerMessageLocation.NO_LOCATION);
|
||||
messageCollector.report(
|
||||
ERROR, "Unknown module kind: " + moduleKindName + ". Valid values are: plain, amd, commonjs, umd", null
|
||||
);
|
||||
}
|
||||
configuration.put(JSConfigurationKeys.MODULE_KIND, moduleKind);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode.*
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentUtil
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
@@ -59,7 +60,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
else
|
||||
PathUtil.getKotlinPathsForCompiler()
|
||||
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Using Kotlin home directory " + paths.homePath, CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(LOGGING, "Using Kotlin home directory ${paths.homePath}")
|
||||
PerformanceCounter.setTimeCounterEnabled(arguments.reportPerf)
|
||||
|
||||
setupJdkClasspathRoots(arguments, configuration, messageCollector).let {
|
||||
@@ -71,11 +72,11 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
catch (e: PluginCliOptionProcessingException) {
|
||||
val message = e.message + "\n\n" + cliPluginUsageString(e.pluginId, e.options)
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, message, CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, message)
|
||||
return INTERNAL_ERROR
|
||||
}
|
||||
catch (e: CliOptionProcessingException) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, e.message!!, CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, e.message!!)
|
||||
return INTERNAL_ERROR
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
@@ -85,9 +86,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
|
||||
if (arguments.script) {
|
||||
if (arguments.freeArgs.isEmpty()) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR, "Specify script source path to evaluate", CompilerMessageLocation.NO_LOCATION
|
||||
)
|
||||
messageCollector.report(ERROR, "Specify script source path to evaluate")
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
configuration.addKotlinSourceRoot(arguments.freeArgs[0])
|
||||
@@ -126,9 +125,8 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
configuration.put(JVMConfigurationKeys.JVM_TARGET, jvmTarget)
|
||||
}
|
||||
else {
|
||||
val errorMessage = "Unknown JVM target version: ${arguments.jvmTarget}\n" +
|
||||
"Supported versions: ${JvmTarget.values().joinToString { it.description }}"
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, errorMessage, CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, "Unknown JVM target version: ${arguments.jvmTarget}\n" +
|
||||
"Supported versions: ${JvmTarget.values().joinToString { it.description }}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,19 +134,18 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
|
||||
putAdvancedOptions(configuration, arguments)
|
||||
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, "Configuring the compilation environment", CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(LOGGING, "Configuring the compilation environment")
|
||||
try {
|
||||
val destination = arguments.destination
|
||||
|
||||
if (arguments.module != null) {
|
||||
val sanitizedCollector = FilteringMessageCollector(messageCollector, CompilerMessageSeverity.VERBOSE::contains)
|
||||
val sanitizedCollector = FilteringMessageCollector(messageCollector, VERBOSE::contains)
|
||||
val moduleScript = CompileEnvironmentUtil.loadModuleDescriptions(arguments.module, sanitizedCollector)
|
||||
|
||||
if (destination != null) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
"The '-d' option with a directory destination is ignored because '-module' is specified",
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
STRONG_WARNING,
|
||||
"The '-d' option with a directory destination is ignored because '-module' is specified"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -190,7 +187,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
if (arguments.version) {
|
||||
return OK
|
||||
}
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, "No source files")
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
|
||||
@@ -206,7 +203,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
catch (e: CompilationException) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.EXCEPTION,
|
||||
EXCEPTION,
|
||||
OutputMessageUtil.renderException(e),
|
||||
MessageUtil.psiElementToMessageLocation(e.element)
|
||||
)
|
||||
@@ -285,8 +282,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
fun reportPerf(configuration: CompilerConfiguration, message: String) {
|
||||
if (!configuration.getBoolean(CLIConfigurationKeys.REPORT_PERF)) return
|
||||
|
||||
val collector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
collector.report(CompilerMessageSeverity.INFO, "PERF: " + message, CompilerMessageLocation.NO_LOCATION)
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(INFO, "PERF: $message")
|
||||
}
|
||||
|
||||
fun reportGCTime(configuration: CompilerConfiguration) {
|
||||
@@ -342,14 +338,10 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
try {
|
||||
if (!arguments.noJdk) {
|
||||
if (arguments.jdkHome != null) {
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING,
|
||||
"Using JDK home directory ${arguments.jdkHome}",
|
||||
CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(LOGGING, "Using JDK home directory ${arguments.jdkHome}")
|
||||
val classesRoots = PathUtil.getJdkClassesRoots(File(arguments.jdkHome))
|
||||
if (classesRoots.isEmpty()) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"No class roots are found in the JDK path: ${arguments.jdkHome}",
|
||||
CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, "No class roots are found in the JDK path: ${arguments.jdkHome}")
|
||||
return COMPILATION_ERROR
|
||||
}
|
||||
configuration.addJvmClasspathRoots(classesRoots)
|
||||
@@ -360,9 +352,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
else {
|
||||
if (arguments.jdkHome != null) {
|
||||
messageCollector.report(CompilerMessageSeverity.STRONG_WARNING,
|
||||
"The '-jdk-home' option is ignored because '-no-jdk' is specified",
|
||||
CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(STRONG_WARNING, "The '-jdk-home' option is ignored because '-no-jdk' is specified")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -388,29 +378,23 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
val def = KotlinScriptDefinitionFromAnnotatedTemplate(cls.kotlin, null, null, scriptResolverEnv)
|
||||
configuration.add(JVMConfigurationKeys.SCRIPT_DEFINITIONS, def)
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.INFO,
|
||||
"Added script definition $template to configuration: files pattern = \"${def.scriptFilePattern}\", resolver = ${def.resolver?.javaClass?.name}",
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
INFO,
|
||||
"Added script definition $template to configuration: files pattern = \"${def.scriptFilePattern}\", " +
|
||||
"resolver = ${def.resolver?.javaClass?.name}"
|
||||
)
|
||||
}
|
||||
catch (ex: ClassNotFoundException) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR, "Cannot find script definition template class $template", CompilerMessageLocation.NO_LOCATION
|
||||
)
|
||||
messageCollector.report(ERROR, "Cannot find script definition template class $template")
|
||||
hasErrors = true
|
||||
}
|
||||
catch (ex: Exception) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.ERROR, "Error processing script definition template $template: ${ex.message}", CompilerMessageLocation.NO_LOCATION
|
||||
)
|
||||
messageCollector.report(ERROR, "Error processing script definition template $template: ${ex.message}")
|
||||
hasErrors = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (hasErrors) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.LOGGING, "(Classpath used for templates loading: $classpath)", CompilerMessageLocation.NO_LOCATION
|
||||
)
|
||||
messageCollector.report(LOGGING, "(Classpath used for templates loading: $classpath)")
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -429,7 +413,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
for (envParam in arguments.scriptResolverEnvironment) {
|
||||
val match = envParseRe.matchEntire(envParam)
|
||||
if (match == null || match.groupValues.size < 4 || match.groupValues[1].isBlank()) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Unable to parse script-resolver-environment argument $envParam", CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, "Unable to parse script-resolver-environment argument $envParam")
|
||||
return null
|
||||
}
|
||||
scriptResolverEnv.put(match.groupValues[1], match.groupValues.drop(2).firstOrNull { it.isNotEmpty() }?.let { unescapeRe.replace(it, "\$1") })
|
||||
|
||||
@@ -54,7 +54,6 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.jar.*;
|
||||
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR;
|
||||
|
||||
public class CompileEnvironmentUtil {
|
||||
@@ -64,14 +63,14 @@ public class CompileEnvironmentUtil {
|
||||
public static ModuleScriptData loadModuleDescriptions(String moduleDefinitionFile, MessageCollector messageCollector) {
|
||||
File file = new File(moduleDefinitionFile);
|
||||
if (!file.exists()) {
|
||||
messageCollector.report(ERROR, "Module definition file does not exist: " + moduleDefinitionFile, NO_LOCATION);
|
||||
messageCollector.report(ERROR, "Module definition file does not exist: " + moduleDefinitionFile, null);
|
||||
return ModuleScriptData.EMPTY;
|
||||
}
|
||||
String extension = FileUtilRt.getExtension(moduleDefinitionFile);
|
||||
if ("xml".equalsIgnoreCase(extension)) {
|
||||
return ModuleXmlParser.parseModuleScript(moduleDefinitionFile, messageCollector);
|
||||
}
|
||||
messageCollector.report(ERROR, "Unknown module definition type: " + moduleDefinitionFile, NO_LOCATION);
|
||||
messageCollector.report(ERROR, "Unknown module definition type: " + moduleDefinitionFile, null);
|
||||
return ModuleScriptData.EMPTY;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,6 @@ import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.CliModuleVisibilityManagerImpl
|
||||
import org.jetbrains.kotlin.cli.common.KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.STRONG_WARNING
|
||||
@@ -325,8 +324,7 @@ class KotlinCoreEnvironment private constructor(
|
||||
fun getSourceFiles(): List<KtFile> = sourceFiles
|
||||
|
||||
private fun report(severity: CompilerMessageSeverity, message: String) {
|
||||
val messageCollector = configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY)
|
||||
messageCollector.report(severity, message, CompilerMessageLocation.NO_LOCATION)
|
||||
configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(severity, message)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+9
-6
@@ -32,7 +32,11 @@ import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.checkKotlinPackageUsage
|
||||
import org.jetbrains.kotlin.cli.common.messages.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.OUTPUT
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
|
||||
import org.jetbrains.kotlin.cli.common.output.outputUtils.writeAll
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.cli.jvm.config.*
|
||||
@@ -88,8 +92,9 @@ object KotlinToJVMBytecodeCompiler {
|
||||
if (jarPath != null) {
|
||||
val includeRuntime = configuration.get(JVMConfigurationKeys.INCLUDE_RUNTIME, false)
|
||||
CompileEnvironmentUtil.writeToJar(jarPath, includeRuntime, mainClass, outputFiles)
|
||||
messageCollector.report(CompilerMessageSeverity.OUTPUT,
|
||||
OutputMessageUtil.formatOutputMessage(outputFiles.asList().flatMap { it.sourceFiles }.distinct(), jarPath), CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(
|
||||
OUTPUT, OutputMessageUtil.formatOutputMessage(outputFiles.asList().flatMap { it.sourceFiles }.distinct(), jarPath)
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -466,9 +471,7 @@ object KotlinToJVMBytecodeCompiler {
|
||||
}
|
||||
|
||||
if (runtimeVersions.toSet().size > 1) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR,
|
||||
"Conflicting versions of Kotlin runtime on classpath: " + runtimes.joinToString { it.path },
|
||||
CompilerMessageLocation.NO_LOCATION)
|
||||
messageCollector.report(ERROR, "Conflicting versions of Kotlin runtime on classpath: " + runtimes.joinToString { it.path })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageUtil
|
||||
import org.jetbrains.kotlin.cli.common.messages.OutputMessageUtil
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
@@ -64,11 +63,7 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
|
||||
if (destination != null) {
|
||||
if (destination.endsWith(".jar")) {
|
||||
// TODO: support .jar destination
|
||||
collector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
".jar destination is not yet supported, results will be written to the directory with the given name",
|
||||
CompilerMessageLocation.NO_LOCATION
|
||||
)
|
||||
collector.report(STRONG_WARNING, ".jar destination is not yet supported, results will be written to the directory with the given name")
|
||||
}
|
||||
configuration.put(CLIConfigurationKeys.METADATA_DESTINATION_DIRECTORY, File(destination))
|
||||
}
|
||||
@@ -79,7 +74,7 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
|
||||
if (arguments.version) {
|
||||
return ExitCode.OK
|
||||
}
|
||||
collector.report(CompilerMessageSeverity.ERROR, "No source files", CompilerMessageLocation.NO_LOCATION)
|
||||
collector.report(ERROR, "No source files")
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
|
||||
@@ -87,11 +82,7 @@ class K2MetadataCompiler : CLICompiler<K2MetadataCompilerArguments>() {
|
||||
MetadataSerializer(true).serialize(environment)
|
||||
}
|
||||
catch (e: CompilationException) {
|
||||
collector.report(
|
||||
CompilerMessageSeverity.EXCEPTION,
|
||||
OutputMessageUtil.renderException(e),
|
||||
MessageUtil.psiElementToMessageLocation(e.element)
|
||||
)
|
||||
collector.report(EXCEPTION, OutputMessageUtil.renderException(e), MessageUtil.psiElementToMessageLocation(e.element))
|
||||
return ExitCode.INTERNAL_ERROR
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user