Minor, move utility method out of an interface
This commit is contained in:
+1
-2
@@ -20,8 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
public class MessageCollectorUtil {
|
public class MessageCollectorUtil {
|
||||||
public static void reportException(@NotNull MessageCollector messageCollector, @NotNull Throwable exception) {
|
public static void reportException(@NotNull MessageCollector messageCollector, @NotNull Throwable exception) {
|
||||||
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(exception),
|
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(exception),
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
-14
@@ -51,11 +51,6 @@ public interface MessageRenderer {
|
|||||||
return StringUtil.escapeXml(str);
|
return StringUtil.escapeXml(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String renderException(@NotNull Throwable e) {
|
|
||||||
return render(CompilerMessageSeverity.EXCEPTION, PLAIN.renderException(e), CompilerMessageLocation.NO_LOCATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String renderConclusion() {
|
public String renderConclusion() {
|
||||||
return "</MESSAGES>";
|
return "</MESSAGES>";
|
||||||
@@ -75,14 +70,6 @@ public interface MessageRenderer {
|
|||||||
return severity + ": " + position + message;
|
return severity + ": " + position + message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String renderException(@NotNull Throwable e) {
|
|
||||||
StringWriter out = new StringWriter();
|
|
||||||
//noinspection IOResourceOpenedButNotSafelyClosed
|
|
||||||
e.printStackTrace(new PrintWriter(out));
|
|
||||||
return out.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String renderConclusion() {
|
public String renderConclusion() {
|
||||||
return "";
|
return "";
|
||||||
@@ -91,6 +78,5 @@ public interface MessageRenderer {
|
|||||||
|
|
||||||
String renderPreamble();
|
String renderPreamble();
|
||||||
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
|
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
|
||||||
String renderException(@NotNull Throwable e);
|
|
||||||
String renderConclusion();
|
String renderConclusion();
|
||||||
}
|
}
|
||||||
|
|||||||
+9
@@ -22,12 +22,21 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class OutputMessageUtil {
|
public class OutputMessageUtil {
|
||||||
private static final String SOURCE_FILES_PREFIX = "Sources:";
|
private static final String SOURCE_FILES_PREFIX = "Sources:";
|
||||||
private static final String OUTPUT_FILES_PREFIX = "Output:";
|
private static final String OUTPUT_FILES_PREFIX = "Output:";
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String renderException(@NotNull Throwable e) {
|
||||||
|
StringWriter out = new StringWriter();
|
||||||
|
e.printStackTrace(new PrintWriter(out));
|
||||||
|
return out.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static String formatOutputMessage(Collection<File> sourceFiles, File outputFile) {
|
public static String formatOutputMessage(Collection<File> sourceFiles, File outputFile) {
|
||||||
return OUTPUT_FILES_PREFIX + "\n" + outputFile.getPath() + "\n" +
|
return OUTPUT_FILES_PREFIX + "\n" + outputFile.getPath() + "\n" +
|
||||||
|
|||||||
+2
-2
@@ -23,7 +23,7 @@ import kotlin.modules.ModuleBuilder;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollectorUtil;
|
import org.jetbrains.jet.cli.common.messages.MessageCollectorUtil;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageRenderer;
|
import org.jetbrains.jet.cli.common.messages.OutputMessageUtil;
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
@@ -99,7 +99,7 @@ public class ModuleXmlParser {
|
|||||||
MessageCollectorUtil.reportException(messageCollector, e);
|
MessageCollectorUtil.reportException(messageCollector, e);
|
||||||
}
|
}
|
||||||
catch (SAXException e) {
|
catch (SAXException e) {
|
||||||
messageCollector.report(ERROR, MessageRenderer.PLAIN.renderException(e), NO_LOCATION);
|
messageCollector.report(ERROR, OutputMessageUtil.renderException(e), NO_LOCATION);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
MessageCollectorUtil.reportException(messageCollector, e);
|
MessageCollectorUtil.reportException(messageCollector, e);
|
||||||
|
|||||||
@@ -69,7 +69,11 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
// Always use tags
|
// Always use tags
|
||||||
errStream.println(MessageRenderer.TAGS.renderException(t));
|
errStream.println(MessageRenderer.TAGS.render(
|
||||||
|
CompilerMessageSeverity.EXCEPTION,
|
||||||
|
OutputMessageUtil.renderException(t),
|
||||||
|
CompilerMessageLocation.NO_LOCATION)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -136,7 +140,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable t) {
|
catch (Throwable t) {
|
||||||
groupingCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t),
|
groupingCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t),
|
||||||
CompilerMessageLocation.NO_LOCATION);
|
CompilerMessageLocation.NO_LOCATION);
|
||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
catch (CompilationException e) {
|
catch (CompilationException e) {
|
||||||
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e),
|
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e),
|
||||||
MessageUtil.psiElementToMessageLocation(e.getElement()));
|
MessageUtil.psiElementToMessageLocation(e.getElement()));
|
||||||
return INTERNAL_ERROR;
|
return INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.jet.OutputFile;
|
import org.jetbrains.jet.OutputFile;
|
||||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
|
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.messages.MessageRenderer;
|
import org.jetbrains.jet.cli.common.messages.OutputMessageUtil;
|
||||||
import org.jetbrains.jet.cli.common.modules.ModuleScriptData;
|
import org.jetbrains.jet.cli.common.modules.ModuleScriptData;
|
||||||
import org.jetbrains.jet.cli.common.modules.ModuleXmlParser;
|
import org.jetbrains.jet.cli.common.modules.ModuleXmlParser;
|
||||||
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
|
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
|
||||||
@@ -240,14 +240,12 @@ public class CompileEnvironmentUtil {
|
|||||||
|
|
||||||
// Used for debug output only
|
// Used for debug output only
|
||||||
private static String loadModuleScriptText(String moduleScriptFile) {
|
private static String loadModuleScriptText(String moduleScriptFile) {
|
||||||
String moduleScriptText;
|
|
||||||
try {
|
try {
|
||||||
moduleScriptText = FileUtil.loadFile(new File(moduleScriptFile));
|
return FileUtil.loadFile(new File(moduleScriptFile));
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
moduleScriptText = "Can't load module script text:\n" + MessageRenderer.PLAIN.renderException(e);
|
return "Can't load module script text:\n" + OutputMessageUtil.renderException(e);
|
||||||
}
|
}
|
||||||
return moduleScriptText;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void writeOutputToDirOrJar(
|
static void writeOutputToDirOrJar(
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public class ScriptTest {
|
|||||||
return KotlinToJVMBytecodeCompiler.compileScript(paths, environment);
|
return KotlinToJVMBytecodeCompiler.compileScript(paths, environment);
|
||||||
}
|
}
|
||||||
catch (CompilationException e) {
|
catch (CompilationException e) {
|
||||||
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e),
|
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e),
|
||||||
MessageUtil.psiElementToMessageLocation(e.getElement()));
|
MessageUtil.psiElementToMessageLocation(e.getElement()));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user