Minor, move utility method out of an interface

This commit is contained in:
Alexander Udalov
2014-07-22 22:25:50 +04:00
parent 97e57e3e3d
commit 1d2dbca27a
8 changed files with 23 additions and 27 deletions
@@ -20,8 +20,7 @@ import org.jetbrains.annotations.NotNull;
public class MessageCollectorUtil {
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);
}
}
@@ -51,11 +51,6 @@ public interface MessageRenderer {
return StringUtil.escapeXml(str);
}
@Override
public String renderException(@NotNull Throwable e) {
return render(CompilerMessageSeverity.EXCEPTION, PLAIN.renderException(e), CompilerMessageLocation.NO_LOCATION);
}
@Override
public String renderConclusion() {
return "</MESSAGES>";
@@ -75,14 +70,6 @@ public interface MessageRenderer {
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
public String renderConclusion() {
return "";
@@ -91,6 +78,5 @@ public interface MessageRenderer {
String renderPreamble();
String render(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location);
String renderException(@NotNull Throwable e);
String renderConclusion();
}
@@ -22,12 +22,21 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
public class OutputMessageUtil {
private static final String SOURCE_FILES_PREFIX = "Sources:";
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
public static String formatOutputMessage(Collection<File> sourceFiles, File outputFile) {
return OUTPUT_FILES_PREFIX + "\n" + outputFile.getPath() + "\n" +
@@ -23,7 +23,7 @@ import kotlin.modules.ModuleBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.cli.common.messages.MessageCollector;
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.SAXException;
import org.xml.sax.helpers.DefaultHandler;
@@ -99,7 +99,7 @@ public class ModuleXmlParser {
MessageCollectorUtil.reportException(messageCollector, e);
}
catch (SAXException e) {
messageCollector.report(ERROR, MessageRenderer.PLAIN.renderException(e), NO_LOCATION);
messageCollector.report(ERROR, OutputMessageUtil.renderException(e), NO_LOCATION);
}
catch (IOException e) {
MessageCollectorUtil.reportException(messageCollector, e);
@@ -69,7 +69,11 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
}
catch (Throwable t) {
// Always use tags
errStream.println(MessageRenderer.TAGS.renderException(t));
errStream.println(MessageRenderer.TAGS.render(
CompilerMessageSeverity.EXCEPTION,
OutputMessageUtil.renderException(t),
CompilerMessageLocation.NO_LOCATION)
);
}
return false;
}
@@ -136,7 +140,7 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
}
}
catch (Throwable t) {
groupingCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(t),
groupingCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t),
CompilerMessageLocation.NO_LOCATION);
return INTERNAL_ERROR;
}
@@ -154,7 +154,7 @@ public class K2JVMCompiler extends CLICompiler<K2JVMCompilerArguments> {
return OK;
}
catch (CompilationException e) {
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e),
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e),
MessageUtil.psiElementToMessageLocation(e.getElement()));
return INTERNAL_ERROR;
}
@@ -38,7 +38,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.OutputFile;
import org.jetbrains.jet.cli.common.CLIConfigurationKeys;
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.ModuleXmlParser;
import org.jetbrains.jet.cli.common.output.outputUtils.OutputUtilsPackage;
@@ -240,14 +240,12 @@ public class CompileEnvironmentUtil {
// Used for debug output only
private static String loadModuleScriptText(String moduleScriptFile) {
String moduleScriptText;
try {
moduleScriptText = FileUtil.loadFile(new File(moduleScriptFile));
return FileUtil.loadFile(new File(moduleScriptFile));
}
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(
@@ -89,7 +89,7 @@ public class ScriptTest {
return KotlinToJVMBytecodeCompiler.compileScript(paths, environment);
}
catch (CompilationException e) {
messageCollector.report(CompilerMessageSeverity.EXCEPTION, MessageRenderer.PLAIN.renderException(e),
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(e),
MessageUtil.psiElementToMessageLocation(e.getElement()));
return null;
}