Chromium Code Reviews

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

Issue 8949055: Issue 250: Allow for GNU formatted errors (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Nits Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
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 898cb322e9b0f4a40e9447932747680394fc43de..f38dde89ece35840a47ac01af35a958484903fc2 100644
--- a/compiler/java/com/google/dart/compiler/DefaultErrorFormatter.java
+++ b/compiler/java/com/google/dart/compiler/DefaultErrorFormatter.java
@@ -4,6 +4,8 @@
package com.google.dart.compiler;
+import com.google.dart.compiler.CompilerConfiguration.ErrorFormat;
+
import java.io.PrintStream;
/**
@@ -12,18 +14,38 @@ import java.io.PrintStream;
*/
public class DefaultErrorFormatter implements ErrorFormatter {
protected final PrintStream outputStream;
+ protected final ErrorFormat errorFormat;
- public DefaultErrorFormatter(PrintStream outputStream) {
+ public DefaultErrorFormatter(PrintStream outputStream, ErrorFormat errorFormat) {
this.outputStream = outputStream;
+ this.errorFormat = errorFormat;
}
@Override
public void format(DartCompilationError event) {
- outputStream.printf("%s:%d:%d: %s\n",
- (event.getSource() != null)
- ? event.getSource().getName() : "<unknown-source-file>",
+ String sourceName = "<unknown-source-file>";
+ Source sourceFile = event.getSource();
+ String includeFrom = getImportString(sourceFile);
+
+ if (sourceFile != null) {
+ sourceName = sourceFile.getUri().toString();
+ }
+ outputStream.printf("%s:%d:%d: %s%s\n",
+ sourceName,
event.getLineNumber(),
event.getColumnNumber(),
- event.getMessage());
+ event.getMessage(),
+ includeFrom);
+ }
+
+ public String getImportString(Source sourceFile) {
+ String includeFrom = "";
+ if (sourceFile instanceof DartSource) {
+ LibrarySource lib = ((DartSource) sourceFile).getLibrary();
+ if (!sourceFile.getUri().equals(lib.getUri())) {
+ includeFrom = " (sourced from " + lib.getUri() + ")";
+ }
+ }
+ return includeFrom;
}
}

Powered by Google App Engine