| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyze_helper; | 5 library analyze_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'package:compiler/compiler.dart' as api; | 9 import 'package:compiler/compiler.dart' as api; |
| 10 import 'package:compiler/src/apiimpl.dart'; | 10 import 'package:compiler/src/apiimpl.dart'; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // TODO(johnniwinther): Support canonical URIs as keys and message kinds as | 32 // TODO(johnniwinther): Support canonical URIs as keys and message kinds as |
| 33 // values. | 33 // values. |
| 34 | 34 |
| 35 class CollectingDiagnosticHandler extends FormattingDiagnosticHandler { | 35 class CollectingDiagnosticHandler extends FormattingDiagnosticHandler { |
| 36 bool hasWarnings = false; | 36 bool hasWarnings = false; |
| 37 bool hasHint = false; | 37 bool hasHint = false; |
| 38 bool hasErrors = false; | 38 bool hasErrors = false; |
| 39 bool lastWasWhitelisted = false; | 39 bool lastWasWhitelisted = false; |
| 40 bool showWhitelisted = true; | 40 bool showWhitelisted = true; |
| 41 | 41 |
| 42 Map<String, Map<dynamic /*String|MessageKind*/, int>> whiteListMap = | 42 Map<String, Map<dynamic /* String|MessageKind */, int>> whiteListMap = |
| 43 new Map<String, Map<dynamic /*String|MessageKind*/, int>>(); | 43 new Map<String, Map<dynamic /* String|MessageKind */, int>>(); |
| 44 List<MessageKind> skipList; | 44 List<MessageKind> skipList; |
| 45 List<CollectedMessage> collectedMessages = <CollectedMessage>[]; | 45 List<CollectedMessage> collectedMessages = <CollectedMessage>[]; |
| 46 | 46 |
| 47 CollectingDiagnosticHandler( | 47 CollectingDiagnosticHandler( |
| 48 Map<String, List/*<String|MessageKind>*/ > whiteList, | 48 Map<String, List /* <String|MessageKind> */ > whiteList, |
| 49 this.skipList, | 49 this.skipList, |
| 50 SourceFileProvider provider) | 50 SourceFileProvider provider) |
| 51 : super(provider) { | 51 : super(provider) { |
| 52 whiteList.forEach((String file, List/*<String|MessageKind>*/ messageParts) { | 52 whiteList |
| 53 var useMap = new Map<dynamic /*String|MessageKind*/, int>(); | 53 .forEach((String file, List /* <String|MessageKind> */ messageParts) { |
| 54 var useMap = new Map<dynamic /* String|MessageKind */, int>(); |
| 54 for (var messagePart in messageParts) { | 55 for (var messagePart in messageParts) { |
| 55 useMap[messagePart] = 0; | 56 useMap[messagePart] = 0; |
| 56 } | 57 } |
| 57 whiteListMap[file] = useMap; | 58 whiteListMap[file] = useMap; |
| 58 }); | 59 }); |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool checkResults() { | 62 bool checkResults() { |
| 62 bool validWhiteListUse = checkWhiteListUse(); | 63 bool validWhiteListUse = checkWhiteListUse(); |
| 63 reportWhiteListUse(); | 64 reportWhiteListUse(); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 /// Analyze all declarations reachable from the entry point. | 196 /// Analyze all declarations reachable from the entry point. |
| 196 TREE_SHAKING, | 197 TREE_SHAKING, |
| 197 } | 198 } |
| 198 | 199 |
| 199 /// Analyzes the file(s) in [uriList] using the provided [mode] and checks that | 200 /// Analyzes the file(s) in [uriList] using the provided [mode] and checks that |
| 200 /// no messages (errors, warnings or hints) are emitted. | 201 /// no messages (errors, warnings or hints) are emitted. |
| 201 /// | 202 /// |
| 202 /// Messages can be generally allowed using [skipList] or on a per-file basis | 203 /// Messages can be generally allowed using [skipList] or on a per-file basis |
| 203 /// using [whiteList]. | 204 /// using [whiteList]. |
| 204 Future analyze( | 205 Future analyze( |
| 205 List<Uri> uriList, Map<String, List/*<String|MessageKind>*/ > whiteList, | 206 List<Uri> uriList, Map<String, List /* <String|MessageKind> */ > whiteList, |
| 206 {AnalysisMode mode: AnalysisMode.ALL, | 207 {AnalysisMode mode: AnalysisMode.ALL, |
| 207 CheckResults checkResults, | 208 CheckResults checkResults, |
| 208 List<String> options: const <String>[], | 209 List<String> options: const <String>[], |
| 209 List<MessageKind> skipList: const <MessageKind>[]}) async { | 210 List<MessageKind> skipList: const <MessageKind>[]}) async { |
| 210 String testFileName = | 211 String testFileName = |
| 211 relativize(Uri.base, Platform.script, Platform.isWindows); | 212 relativize(Uri.base, Platform.script, Platform.isWindows); |
| 212 | 213 |
| 213 print(""" | 214 print(""" |
| 214 | 215 |
| 215 | 216 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 if (checkResults != null) { | 284 if (checkResults != null) { |
| 284 result = checkResults(compiler, handler); | 285 result = checkResults(compiler, handler); |
| 285 } else { | 286 } else { |
| 286 result = handler.checkResults(); | 287 result = handler.checkResults(); |
| 287 } | 288 } |
| 288 if (!result) { | 289 if (!result) { |
| 289 print(MESSAGE); | 290 print(MESSAGE); |
| 290 exit(1); | 291 exit(1); |
| 291 } | 292 } |
| 292 } | 293 } |
| OLD | NEW |