Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library error_formatter; | 5 library error_formatter; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'generated/java_io.dart'; | 10 import 'generated/java_io.dart'; |
| 11 import 'generated/engine.dart'; | 11 import 'generated/engine.dart'; |
| 12 import 'generated/error.dart'; | 12 import 'generated/error.dart'; |
| 13 import 'generated/source_io.dart'; | 13 import 'generated/source_io.dart'; |
| 14 import 'generated/sdk.dart'; | 14 import 'generated/sdk.dart'; |
| 15 import 'generated/sdk_io.dart'; | 15 import 'generated/sdk_io.dart'; |
| 16 import 'generated/ast.dart'; | 16 import 'generated/ast.dart'; |
| 17 import 'generated/element.dart'; | 17 import 'generated/element.dart'; |
| 18 import '../options.dart'; | 18 import '../options.dart'; |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Helper for formatting [AnalysisError]s. | 21 * Helper for formatting [AnalysisError]s. |
| 22 * The two format options are a user consumable format and a machine consumable format. | 22 * The two format options are a user consumable format and a machine consumable format. |
| 23 */ | 23 */ |
| 24 class ErrorFormatter { | 24 class ErrorFormatter { |
| 25 StringSink out; | 25 StringSink out; |
| 26 CommandLineOptions options; | 26 CommandLineOptions options; |
| 27 | 27 |
| 28 ErrorFormatter(this.out, this.options); | 28 ErrorFormatter(this.out, this.options); |
| 29 | 29 |
| 30 void startAnalysis() { | |
| 31 if (!options.machineFormat) { | |
| 32 out.writeln("Analyzing ${options.sourceFiles}..."); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 void formatErrors(List<AnalysisErrorInfo> errorInfos) { | 30 void formatErrors(List<AnalysisErrorInfo> errorInfos) { |
| 37 var errors = new List<AnalysisError>(); | 31 var errors = new List<AnalysisError>(); |
| 38 var errorToLine = new Map<AnalysisError, LineInfo>(); | 32 var errorToLine = new Map<AnalysisError, LineInfo>(); |
| 39 for (AnalysisErrorInfo errorInfo in errorInfos) { | 33 for (AnalysisErrorInfo errorInfo in errorInfos) { |
| 40 for (AnalysisError error in errorInfo.errors) { | 34 for (AnalysisError error in errorInfo.errors) { |
| 41 errors.add(error); | 35 errors.add(error); |
| 42 errorToLine[error] = errorInfo.lineInfo; | 36 errorToLine[error] = errorInfo.lineInfo; |
| 43 } | 37 } |
| 44 } | 38 } |
| 45 // sort errors | 39 // sort errors |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 out.write(error.errorCode); | 109 out.write(error.errorCode); |
| 116 out.write('|'); | 110 out.write('|'); |
| 117 out.write(escapePipe(source.fullName)); | 111 out.write(escapePipe(source.fullName)); |
| 118 out.write('|'); | 112 out.write('|'); |
| 119 out.write(location.lineNumber); | 113 out.write(location.lineNumber); |
| 120 out.write('|'); | 114 out.write('|'); |
| 121 out.write(location.columnNumber); | 115 out.write(location.columnNumber); |
| 122 out.write('|'); | 116 out.write('|'); |
| 123 out.write(length); | 117 out.write(length); |
| 124 out.write('|'); | 118 out.write('|'); |
| 125 out.writeln(escapePipe(error.message)); | 119 out.write(escapePipe(error.message)); |
| 126 } else { | 120 } else { |
| 127 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2) | 121 // [warning] 'foo' is not a... (/Users/.../tmp/foo.dart, line 1, col 2) |
| 128 out.write('[${severity.displayName}] ${error.message} '); | 122 out.write('[${severity.displayName}] ${error.message} '); |
| 129 out.write('(${source.fullName}'); | 123 out.write('(${source.fullName}'); |
| 130 out.write(', line ${location.lineNumber}, col ${location.columnNumber})'); | 124 out.write(', line ${location.lineNumber}, col ${location.columnNumber})'); |
| 131 } | 125 } |
| 126 out.write('\n'); | |
|
Brian Wilkerson
2013/06/04 15:56:47
Does writeln produce platform specific end-of-line
scheglov
2013/06/04 16:08:52
Every implementation I see write \n, but may be th
| |
| 132 } | 127 } |
| 133 | 128 |
| 134 static String escapePipe(String input) { | 129 static String escapePipe(String input) { |
| 135 var result = new StringBuffer(); | 130 var result = new StringBuffer(); |
| 136 for (var c in input.codeUnits) { | 131 for (var c in input.codeUnits) { |
| 137 if (c == '\\' || c == '|') { | 132 if (c == '\\' || c == '|') { |
| 138 result.write('\\'); | 133 result.write('\\'); |
| 139 } | 134 } |
| 140 result.writeCharCode(c); | 135 result.writeCharCode(c); |
| 141 } | 136 } |
| 142 return result.toString(); | 137 return result.toString(); |
| 143 } | 138 } |
| 144 | 139 |
| 145 static String pluralize(String word, int count) { | 140 static String pluralize(String word, int count) { |
| 146 if (count == 1) { | 141 if (count == 1) { |
| 147 return word; | 142 return word; |
| 148 } else { | 143 } else { |
| 149 return word + "s"; | 144 return word + "s"; |
| 150 } | 145 } |
| 151 } | 146 } |
| 152 } | 147 } |
| OLD | NEW |