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

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

Issue 998843003: pkg/csslib: formatting (Closed) Base URL: https://github.com/dart-lang/csslib@master
Patch Set: Created 5 years, 9 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
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 csslib.src.messages; 5 library csslib.src.messages;
6 6
7 import 'package:logging/logging.dart' show Level; 7 import 'package:logging/logging.dart' show Level;
8 import 'package:source_span/source_span.dart'; 8 import 'package:source_span/source_span.dart';
9 9
10 import 'options.dart'; 10 import 'options.dart';
(...skipping 29 matching lines...) Expand all
40 })(); 40 })();
41 41
42 /** A single message from the compiler. */ 42 /** A single message from the compiler. */
43 class Message { 43 class Message {
44 final Level level; 44 final Level level;
45 final String message; 45 final String message;
46 final SourceSpan span; 46 final SourceSpan span;
47 final bool useColors; 47 final bool useColors;
48 48
49 Message(this.level, this.message, {SourceSpan span, bool useColors: false}) 49 Message(this.level, this.message, {SourceSpan span, bool useColors: false})
50 : this.span = span, this.useColors = useColors; 50 : this.span = span,
51 this.useColors = useColors;
51 52
52 String toString() { 53 String toString() {
53 var output = new StringBuffer(); 54 var output = new StringBuffer();
54 bool colors = useColors && _ERROR_COLORS.containsKey(level); 55 bool colors = useColors && _ERROR_COLORS.containsKey(level);
55 var levelColor = colors ? _ERROR_COLORS[level] : null; 56 var levelColor = colors ? _ERROR_COLORS[level] : null;
56 if (colors) output.write(levelColor); 57 if (colors) output.write(levelColor);
57 output..write(_ERROR_LABEL[level])..write(' '); 58 output
Jennifer Messerly 2015/03/19 20:25:30 another case of https://github.com/dart-lang/dart_
59 ..write(_ERROR_LABEL[level])
60 ..write(' ');
58 if (colors) output.write(NO_COLOR); 61 if (colors) output.write(NO_COLOR);
59 62
60 if (span == null) { 63 if (span == null) {
61 output.write(message); 64 output.write(message);
62 } else { 65 } else {
63 output.write('on '); 66 output.write('on ');
64 output.write(span.message(message, color: levelColor)); 67 output.write(span.message(message, color: levelColor));
65 } 68 }
66 69
67 return output.toString(); 70 return output.toString();
(...skipping 12 matching lines...) Expand all
80 83
81 final PreprocessorOptions options; 84 final PreprocessorOptions options;
82 85
83 final List<Message> messages = <Message>[]; 86 final List<Message> messages = <Message>[];
84 87
85 Messages({PreprocessorOptions options, this.printHandler: print}) 88 Messages({PreprocessorOptions options, this.printHandler: print})
86 : options = options != null ? options : new PreprocessorOptions(); 89 : options = options != null ? options : new PreprocessorOptions();
87 90
88 /** Report a compile-time CSS error. */ 91 /** Report a compile-time CSS error. */
89 void error(String message, SourceSpan span) { 92 void error(String message, SourceSpan span) {
90 var msg = new Message(Level.SEVERE, message, span: span, 93 var msg = new Message(Level.SEVERE, message,
91 useColors: options.useColors); 94 span: span, useColors: options.useColors);
92 95
93 messages.add(msg); 96 messages.add(msg);
94 97
95 printHandler(msg); 98 printHandler(msg);
96 } 99 }
97 100
98 /** Report a compile-time CSS warning. */ 101 /** Report a compile-time CSS warning. */
99 void warning(String message, SourceSpan span) { 102 void warning(String message, SourceSpan span) {
100 if (options.warningsAsErrors) { 103 if (options.warningsAsErrors) {
101 error(message, span); 104 error(message, span);
102 } else { 105 } else {
103 var msg = new Message(Level.WARNING, message, span: span, 106 var msg = new Message(Level.WARNING, message,
104 useColors: options.useColors); 107 span: span, useColors: options.useColors);
105 108
106 messages.add(msg); 109 messages.add(msg);
107 } 110 }
108 } 111 }
109 112
110 /** Report and informational message about what the compiler is doing. */ 113 /** Report and informational message about what the compiler is doing. */
111 void info(String message, SourceSpan span) { 114 void info(String message, SourceSpan span) {
112 var msg = new Message(Level.INFO, message, span: span, 115 var msg = new Message(Level.INFO, message,
113 useColors: options.useColors); 116 span: span, useColors: options.useColors);
114 117
115 messages.add(msg); 118 messages.add(msg);
116 119
117 if (options.verbose) printHandler(msg); 120 if (options.verbose) printHandler(msg);
118 } 121 }
119 122
120 /** Merge [newMessages] to this message lsit. */ 123 /** Merge [newMessages] to this message lsit. */
121 void mergeMessages(Messages newMessages) { 124 void mergeMessages(Messages newMessages) {
122 messages.addAll(newMessages.messages); 125 messages.addAll(newMessages.messages);
123 newMessages.messages.where((message) => 126 newMessages.messages
124 message.level.value == Level.SEVERE || options.verbose) 127 .where(
125 .forEach((message) { printHandler(message); }); 128 (message) => message.level.value == Level.SEVERE || options.verbose)
129 .forEach((message) {
130 printHandler(message);
131 });
126 } 132 }
127 } 133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698