Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(522)

Unified Diff: compiler/java/com/google/dart/compiler/DefaultErrorFormatter.java

Issue 11418190: Issue 6969. Fix for reporting machine format for EOS error. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/PrettyErrorFormatter.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/DefaultErrorFormatter.java
diff --git a/compiler/java/com/google/dart/compiler/DefaultErrorFormatter.java b/compiler/java/com/google/dart/compiler/DefaultErrorFormatter.java
index bbf38517f972c044c5efff6a1a1b873aab3945a4..a908369d1b6c326cd4dca4ee9bb1cd0696e21d6a 100644
--- a/compiler/java/com/google/dart/compiler/DefaultErrorFormatter.java
+++ b/compiler/java/com/google/dart/compiler/DefaultErrorFormatter.java
@@ -24,22 +24,42 @@ public class DefaultErrorFormatter implements ErrorFormatter {
@Override
public void format(DartCompilationError event) {
- String sourceName = "<unknown-source-file>";
- Source sourceFile = event.getSource();
- String includeFrom = getImportString(sourceFile);
+ StringBuilder buf = new StringBuilder();
+ appendError(buf, event);
+ outputStream.print(buf);
+ outputStream.print("\n");
+ }
- if (sourceFile != null) {
- sourceName = sourceFile.getUri().toString();
+ protected void appendError(StringBuilder buf, DartCompilationError error) {
+ Source source = error.getSource();
+ String sourceName = getSourceName(source);
+ int line = error.getLineNumber();
+ int col = error.getColumnNumber();
+ int length = error.getLength();
+ if (errorFormat == ErrorFormat.MACHINE) {
+ buf.append(String.format(
+ "%s|%s|%s|%s|%d|%d|%d|%s",
+ escapePipe(error.getErrorCode().getErrorSeverity().toString()),
+ escapePipe(error.getErrorCode().getSubSystem().toString()),
+ escapePipe(error.getErrorCode().toString()),
+ escapePipe(sourceName),
+ line,
+ col,
+ length,
+ escapePipe(error.getMessage())));
+ } else {
+ String includeFrom = getImportString(source);
+ buf.append(String.format(
+ "%s:%d:%d: %s%s",
+ sourceName,
+ line,
+ col,
+ error.getMessage(),
+ includeFrom));
}
- outputStream.printf("%s:%d:%d: %s%s\n",
- sourceName,
- event.getLineNumber(),
- event.getColumnNumber(),
- event.getMessage(),
- includeFrom);
}
- public String getImportString(Source sourceFile) {
+ protected static String getImportString(Source sourceFile) {
String includeFrom = "";
if (sourceFile instanceof DartSource) {
LibrarySource lib = ((DartSource) sourceFile).getLibrary();
@@ -49,4 +69,25 @@ public class DefaultErrorFormatter implements ErrorFormatter {
}
return includeFrom;
}
+
+ protected static String getSourceName(Source source) {
+ if (source instanceof UrlDartSource) {
+ return source.getUri().toString();
+ }
+ if (source != null) {
+ return source.getName();
+ }
+ return "<unknown-source-file>";
+ }
+
+ protected static String escapePipe(String input) {
+ StringBuilder result = new StringBuilder();
+ for (char c : input.toCharArray()) {
+ if (c == '\\' || c == '|') {
+ result.append('\\');
+ }
+ result.append(c);
+ }
+ return result.toString();
+ }
}
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/PrettyErrorFormatter.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698