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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/source_file_provider.dart

Issue 17588005: Warn about overriding operator== but not hashCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update comments (according to my dictionary whitelist is a word). Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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 source_file_provider; 5 library source_file_provider;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:utf'; 9 import 'dart:utf';
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 relativize(cwd, resourceUri, isWindows), source); 46 relativize(cwd, resourceUri, isWindows), source);
47 return new Future.value(source); 47 return new Future.value(source);
48 } 48 }
49 49
50 Future<String> call(Uri resourceUri) => readStringFromUri(resourceUri); 50 Future<String> call(Uri resourceUri) => readStringFromUri(resourceUri);
51 } 51 }
52 52
53 class FormattingDiagnosticHandler { 53 class FormattingDiagnosticHandler {
54 final SourceFileProvider provider; 54 final SourceFileProvider provider;
55 bool showWarnings = true; 55 bool showWarnings = true;
56 bool showHints = true;
56 bool verbose = false; 57 bool verbose = false;
57 bool isAborting = false; 58 bool isAborting = false;
58 bool enableColors = false; 59 bool enableColors = false;
59 bool throwOnError = false; 60 bool throwOnError = false;
61 api.Diagnostic lastKind = null;
60 62
61 final int FATAL = api.Diagnostic.CRASH.ordinal | api.Diagnostic.ERROR.ordinal; 63 final int FATAL = api.Diagnostic.CRASH.ordinal | api.Diagnostic.ERROR.ordinal;
62 final int INFO = 64 final int INFO =
63 api.Diagnostic.INFO.ordinal | api.Diagnostic.VERBOSE_INFO.ordinal; 65 api.Diagnostic.INFO.ordinal | api.Diagnostic.VERBOSE_INFO.ordinal;
64 66
65 FormattingDiagnosticHandler([SourceFileProvider provider]) 67 FormattingDiagnosticHandler([SourceFileProvider provider])
66 : this.provider = 68 : this.provider =
67 (provider == null) ? new SourceFileProvider() : provider; 69 (provider == null) ? new SourceFileProvider() : provider;
68 70
69 void info(var message, [api.Diagnostic kind = api.Diagnostic.VERBOSE_INFO]) { 71 void info(var message, [api.Diagnostic kind = api.Diagnostic.VERBOSE_INFO]) {
70 if (!verbose && identical(kind, api.Diagnostic.VERBOSE_INFO)) return; 72 if (!verbose && kind == api.Diagnostic.VERBOSE_INFO) return;
71 if (enableColors) { 73 if (enableColors) {
72 print('${colors.green("info:")} $message'); 74 print('${colors.green("info:")} $message');
73 } else { 75 } else {
74 print('info: $message'); 76 print('info: $message');
75 } 77 }
76 } 78 }
77 79
78 void diagnosticHandler(Uri uri, int begin, int end, String message, 80 void diagnosticHandler(Uri uri, int begin, int end, String message,
79 api.Diagnostic kind) { 81 api.Diagnostic kind) {
80 // TODO(ahe): Remove this when source map is handled differently. 82 // TODO(ahe): Remove this when source map is handled differently.
81 if (identical(kind.name, 'source map')) return; 83 if (identical(kind.name, 'source map')) return;
82 84
83 if (isAborting) return; 85 if (isAborting) return;
84 isAborting = identical(kind, api.Diagnostic.CRASH); 86 isAborting = (kind == api.Diagnostic.CRASH);
85 bool fatal = (kind.ordinal & FATAL) != 0; 87 bool fatal = (kind.ordinal & FATAL) != 0;
86 bool isInfo = (kind.ordinal & INFO) != 0; 88 bool isInfo = (kind.ordinal & INFO) != 0;
87 if (isInfo && uri == null && !identical(kind, api.Diagnostic.INFO)) { 89 if (isInfo && uri == null && kind != api.Diagnostic.INFO) {
88 info(message, kind); 90 info(message, kind);
89 return; 91 return;
90 } 92 }
93 // [previousKind]/[lastKind] records the previous non-INFO kind we saw.
94 // This is used to suppress info about a warning when warnings are
95 // suppressed, and similar for hints.
96 var previousKind = lastKind;
97 if (previousKind != api.Diagnostic.INFO) {
98 lastKind = kind;
99 }
91 var color; 100 var color;
92 if (!enableColors) { 101 if (kind == api.Diagnostic.ERROR) {
93 color = (x) => x;
94 } else if (identical(kind, api.Diagnostic.ERROR)) {
95 color = colors.red; 102 color = colors.red;
96 } else if (identical(kind, api.Diagnostic.WARNING)) { 103 } else if (kind == api.Diagnostic.WARNING) {
104 if (!showWarnings) return;
97 color = colors.magenta; 105 color = colors.magenta;
98 } else if (identical(kind, api.Diagnostic.LINT)) { 106 } else if (kind == api.Diagnostic.HINT) {
99 color = colors.magenta; 107 if (!showHints) return;
100 } else if (identical(kind, api.Diagnostic.CRASH)) { 108 color = colors.cyan;
109 } else if (kind == api.Diagnostic.CRASH) {
101 color = colors.red; 110 color = colors.red;
102 } else if (identical(kind, api.Diagnostic.INFO)) { 111 } else if (kind == api.Diagnostic.INFO) {
112 if (lastKind == api.Diagnostic.WARNING && !showWarnings) return;
113 if (lastKind == api.Diagnostic.HINT && !showHints) return;
103 color = colors.green; 114 color = colors.green;
104 } else { 115 } else {
105 throw 'Unknown kind: $kind (${kind.ordinal})'; 116 throw 'Unknown kind: $kind (${kind.ordinal})';
106 } 117 }
118 if (!enableColors) {
119 color = (x) => x;
120 }
107 if (uri == null) { 121 if (uri == null) {
108 assert(fatal); 122 assert(fatal);
109 print(color(message)); 123 print(color(message));
110 } else if (fatal || showWarnings) { 124 } else {
111 SourceFile file = provider.sourceFiles[uri.toString()]; 125 SourceFile file = provider.sourceFiles[uri.toString()];
112 if (file == null) { 126 if (file == null) {
113 throw '$uri: file is null'; 127 throw '$uri: file is null';
114 } 128 }
115 print(file.getLocationMessage(color(message), begin, end, true, color)); 129 print(file.getLocationMessage(color(message), begin, end, true, color));
116 } 130 }
117 if (fatal && throwOnError) { 131 if (fatal && throwOnError) {
118 isAborting = true; 132 isAborting = true;
119 throw new AbortLeg(message); 133 throw new AbortLeg(message);
120 } 134 }
121 } 135 }
122 136
123 void call(Uri uri, int begin, int end, String message, api.Diagnostic kind) { 137 void call(Uri uri, int begin, int end, String message, api.Diagnostic kind) {
124 return diagnosticHandler(uri, begin, end, message, kind); 138 return diagnosticHandler(uri, begin, end, message, kind);
125 } 139 }
126 } 140 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698