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

Side by Side Diff: lib/src/messages.dart

Issue 22962005: Merge pull request #581 from kevmoo/polymer (Closed) Base URL: https://github.com/dart-lang/web-ui.git@polymer
Patch Set: Created 7 years, 4 months 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 unified diff | Download patch
« no previous file with comments | « lib/src/info.dart ('k') | lib/src/observable_transform.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 messages; 5 library messages;
6 6
7 import 'dart:json' as json; 7 import 'dart:json' as json;
8 8
9 import 'package:barback/barback.dart' show TransformLogger;
9 import 'package:source_maps/span.dart' show Span; 10 import 'package:source_maps/span.dart' show Span;
10 import 'package:logging/logging.dart' show Level; 11 import 'package:logging/logging.dart' show Level;
11 12
12 import 'compiler_options.dart'; 13 import 'compiler_options.dart';
13 import 'utils.dart'; 14 import 'utils.dart';
14 15
15 /** Map between error levels and their display color. */ 16 /** Map between error levels and their display color. */
16 final Map<Level, String> _ERROR_COLORS = (() { 17 final Map<Level, String> _ERROR_COLORS = (() {
17 var colorsMap = new Map<Level, String>(); 18 var colorsMap = new Map<Level, String>();
18 colorsMap[Level.SEVERE] = RED_COLOR; 19 colorsMap[Level.SEVERE] = RED_COLOR;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 'charEnd': span.end.offset, 64 'charEnd': span.end.offset,
64 } 65 }
65 }]); 66 }]);
66 } 67 }
67 } 68 }
68 69
69 /** 70 /**
70 * This class tracks and prints information, warnings, and errors emitted by the 71 * This class tracks and prints information, warnings, and errors emitted by the
71 * compiler. 72 * compiler.
72 */ 73 */
73 class Messages { 74 class Messages implements TransformLogger {
74 final CompilerOptions options; 75 final CompilerOptions options;
75 final bool shouldPrint; 76 final bool shouldPrint;
76 77
77 final List<Message> messages = <Message>[]; 78 final List<Message> messages = <Message>[];
78 79
79 Messages({CompilerOptions options, this.shouldPrint: true}) 80 Messages({CompilerOptions options, this.shouldPrint: true})
80 : options = options != null ? options : new CompilerOptions(); 81 : options = options != null ? options : new CompilerOptions();
81 82
82 /** 83 /**
83 * Creates a new instance of [Messages] which doesn't write messages to 84 * Creates a new instance of [Messages] which doesn't write messages to
(...skipping 10 matching lines...) Expand all
94 // Convenience methods for testing 95 // Convenience methods for testing
95 int get length => messages.length; 96 int get length => messages.length;
96 97
97 Message operator[](int index) => messages[index]; 98 Message operator[](int index) => messages[index];
98 99
99 void clear() { 100 void clear() {
100 messages.clear(); 101 messages.clear();
101 } 102 }
102 103
103 /** [message] is considered a static compile-time error by the Dart lang. */ 104 /** [message] is considered a static compile-time error by the Dart lang. */
104 void error(String message, Span span) { 105 void error(String message, [Span span]) {
105 var msg = new Message(Level.SEVERE, message, span: span, 106 var msg = new Message(Level.SEVERE, message, span: span,
106 useColors: options.useColors); 107 useColors: options.useColors);
107 108
108 messages.add(msg); 109 messages.add(msg);
109 printMessage(msg); 110 printMessage(msg);
110 } 111 }
111 112
112 /** [message] is considered a type warning by the Dart lang. */ 113 /** [message] is considered a type warning by the Dart lang. */
113 void warning(String message, Span span) { 114 void warning(String message, [Span span]) {
114 if (options.warningsAsErrors) { 115 if (options.warningsAsErrors) {
115 error(message, span); 116 error(message, span);
116 } else { 117 } else {
117 var msg = new Message(Level.WARNING, message, 118 var msg = new Message(Level.WARNING, message,
118 span: span, useColors: options.useColors); 119 span: span, useColors: options.useColors);
119 120
120 messages.add(msg); 121 messages.add(msg);
121 printMessage(msg); 122 printMessage(msg);
122 } 123 }
123 } 124 }
124 125
125 /// the list of error messages. Empty list, if there are no error messages. 126 /// the list of error messages. Empty list, if there are no error messages.
126 List<Message> get errors => 127 List<Message> get errors =>
127 messages.where((m) => m.level == Level.SEVERE).toList(); 128 messages.where((m) => m.level == Level.SEVERE).toList();
128 129
129 /// the list of warning messages. Empty list if there are no warning messages. 130 /// the list of warning messages. Empty list if there are no warning messages.
130 List<Message> get warnings => 131 List<Message> get warnings =>
131 messages.where((m) => m.level == Level.WARNING).toList(); 132 messages.where((m) => m.level == Level.WARNING).toList();
132 133
133 /** 134 /**
134 * [message] at [span] will tell the user about what the compiler 135 * [message] at [span] will tell the user about what the compiler
135 * is doing. 136 * is doing.
136 */ 137 */
137 void info(String message, Span span) { 138 void info(String message, [Span span]) {
138 var msg = new Message(Level.INFO, message, span: span, 139 var msg = new Message(Level.INFO, message, span: span,
139 useColors: options.useColors); 140 useColors: options.useColors);
140 141
141 messages.add(msg); 142 messages.add(msg);
142 if (options.verbose) printMessage(msg); 143 if (options.verbose) printMessage(msg);
143 } 144 }
144 145
145 void printMessage(msg) { 146 void printMessage(msg) {
146 if (shouldPrint) print(options.jsonFormat ? msg.toJson() : msg); 147 if (shouldPrint) print(options.jsonFormat ? msg.toJson() : msg);
147 } 148 }
148 } 149 }
OLDNEW
« no previous file with comments | « lib/src/info.dart ('k') | lib/src/observable_transform.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698