| 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 analyze_helper; | 5 library analyze_helper; |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 9 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| 10 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart'; | 10 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart'; |
| 11 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 11 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| 12 hide Compiler; | 12 hide Compiler; |
| 13 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
| 14 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart'; | 14 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart'; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Map of white-listed warnings and errors. | 17 * Map of white-listed warnings and errors. |
| 18 * | 18 * |
| 19 * Only add a white-listing together with a bug report to dartbug.com and add | 19 * Only add a white-listing together with a bug report to dartbug.com and add |
| 20 * the bug issue number as a comment on the white-listing. | 20 * the bug issue number as a comment on the white-listing. |
| 21 * | 21 * |
| 22 * Use an identifiable suffix of the file uri as key. Use a fixed substring of | 22 * Use an identifiable suffix of the file uri as key. Use a fixed substring of |
| 23 * the error/warning message in the list of white-listings for each file. | 23 * the error/warning message in the list of white-listings for each file. |
| 24 */ | 24 */ |
| 25 // TODO(johnniwinther): Support canonical URIs as keys and message kinds as | 25 // TODO(johnniwinther): Support canonical URIs as keys and message kinds as |
| 26 // values. | 26 // values. |
| 27 | 27 |
| 28 class CollectingDiagnosticHandler extends FormattingDiagnosticHandler { | 28 class CollectingDiagnosticHandler extends FormattingDiagnosticHandler { |
| 29 bool hasWarnings = false; | 29 bool hasWarnings = false; |
| 30 bool hasLint = false; |
| 30 bool hasErrors = false; | 31 bool hasErrors = false; |
| 31 | 32 |
| 32 Map<String, Map<String, int>> whiteListMap | 33 Map<String, Map<String, int>> whiteListMap |
| 33 = new Map<String, Map<String, int>>(); | 34 = new Map<String, Map<String, int>>(); |
| 34 | 35 |
| 35 CollectingDiagnosticHandler(Map<String, List<String>> whiteList, | 36 CollectingDiagnosticHandler(Map<String, List<String>> whiteList, |
| 36 SourceFileProvider provider) | 37 SourceFileProvider provider) |
| 37 : super(provider) { | 38 : super(provider) { |
| 38 whiteList.forEach((String file, List<String> messageParts) { | 39 whiteList.forEach((String file, List<String> messageParts) { |
| 39 var useMap = new Map<String,int>(); | 40 var useMap = new Map<String,int>(); |
| 40 for (String messagePart in messageParts) { | 41 for (String messagePart in messageParts) { |
| 41 useMap[messagePart] = 0; | 42 useMap[messagePart] = 0; |
| 42 } | 43 } |
| 43 whiteListMap[file] = useMap; | 44 whiteListMap[file] = useMap; |
| 44 }); | 45 }); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void checkResults() { | 48 void checkResults() { |
| 48 Expect.isFalse(hasWarnings); | 49 Expect.isFalse(hasWarnings); |
| 50 Expect.isFalse(hasLint); |
| 49 Expect.isFalse(hasErrors); | 51 Expect.isFalse(hasErrors); |
| 50 Expect.isTrue(checkWhiteListUse()); | 52 Expect.isTrue(checkWhiteListUse()); |
| 51 reportWhiteListUse(); | 53 reportWhiteListUse(); |
| 52 } | 54 } |
| 53 | 55 |
| 54 bool checkWhiteListUse() { | 56 bool checkWhiteListUse() { |
| 55 bool allUsed = true; | 57 bool allUsed = true; |
| 56 for (String file in whiteListMap.keys) { | 58 for (String file in whiteListMap.keys) { |
| 57 for (String messagePart in whiteListMap[file].keys) { | 59 for (String messagePart in whiteListMap[file].keys) { |
| 58 if (whiteListMap[file][messagePart] == 0) { | 60 if (whiteListMap[file][messagePart] == 0) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 97 |
| 96 void diagnosticHandler(Uri uri, int begin, int end, String message, | 98 void diagnosticHandler(Uri uri, int begin, int end, String message, |
| 97 api.Diagnostic kind) { | 99 api.Diagnostic kind) { |
| 98 if (kind == api.Diagnostic.WARNING) { | 100 if (kind == api.Diagnostic.WARNING) { |
| 99 if (checkWhiteList(uri, message)) { | 101 if (checkWhiteList(uri, message)) { |
| 100 // Suppress white listed warnings. | 102 // Suppress white listed warnings. |
| 101 return; | 103 return; |
| 102 } | 104 } |
| 103 hasWarnings = true; | 105 hasWarnings = true; |
| 104 } | 106 } |
| 107 if (kind == api.Diagnostic.LINT) { |
| 108 if (checkWhiteList(uri, message)) { |
| 109 // Suppress white listed warnings. |
| 110 return; |
| 111 } |
| 112 hasLint = true; |
| 113 } |
| 105 if (kind == api.Diagnostic.ERROR) { | 114 if (kind == api.Diagnostic.ERROR) { |
| 106 if (checkWhiteList(uri, message)) { | 115 if (checkWhiteList(uri, message)) { |
| 107 // Suppress white listed warnings. | 116 // Suppress white listed warnings. |
| 108 return; | 117 return; |
| 109 } | 118 } |
| 110 hasErrors = true; | 119 hasErrors = true; |
| 111 } | 120 } |
| 112 super.diagnosticHandler(uri, begin, end, message, kind); | 121 super.diagnosticHandler(uri, begin, end, message, kind); |
| 113 } | 122 } |
| 114 } | 123 } |
| 115 | 124 |
| 116 void analyze(List<Uri> uriList, Map<String, List<String>> whiteList) { | 125 void analyze(List<Uri> uriList, Map<String, List<String>> whiteList) { |
| 117 var libraryRoot = currentDirectory.resolve('sdk/'); | 126 var libraryRoot = currentDirectory.resolve('sdk/'); |
| 118 var provider = new SourceFileProvider(); | 127 var provider = new SourceFileProvider(); |
| 119 var handler = new CollectingDiagnosticHandler(whiteList, provider); | 128 var handler = new CollectingDiagnosticHandler(whiteList, provider); |
| 120 var compiler = new Compiler( | 129 var compiler = new Compiler( |
| 121 provider.readStringFromUri, | 130 provider.readStringFromUri, |
| 122 null, | 131 null, |
| 123 handler.diagnosticHandler, | 132 handler.diagnosticHandler, |
| 124 libraryRoot, libraryRoot, | 133 libraryRoot, libraryRoot, |
| 125 <String>['--analyze-only', '--analyze-all', | 134 <String>['--analyze-only', '--analyze-all', |
| 126 '--categories=Client,Server']); | 135 '--categories=Client,Server']); |
| 127 compiler.librariesToAnalyzeWhenRun = uriList; | 136 compiler.librariesToAnalyzeWhenRun = uriList; |
| 128 compiler.run(null); | 137 compiler.run(null); |
| 129 handler.checkResults(); | 138 handler.checkResults(); |
| 130 } | 139 } |
| OLD | NEW |