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 import 'dart:io'; | 5 import 'dart:io'; |
6 import 'package:analyzer/src/command_line/arguments.dart' | 6 import 'package:analyzer/src/command_line/arguments.dart' |
7 show | 7 show |
8 defineAnalysisArguments, | 8 defineAnalysisArguments, |
9 filterUnknownArguments, | 9 filterUnknownArguments, |
10 ignoreUnrecognizedFlagsFlag; | 10 ignoreUnrecognizedFlagsFlag; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 /// Thrown when the input source code has errors. | 274 /// Thrown when the input source code has errors. |
275 class CompileErrorException implements Exception { | 275 class CompileErrorException implements Exception { |
276 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; | 276 toString() => '\nPlease fix all errors before compiling (warnings are okay).'; |
277 } | 277 } |
278 | 278 |
279 /// Thrown when force compilation failed (probably due to static errors). | 279 /// Thrown when force compilation failed (probably due to static errors). |
280 class ForceCompileErrorException extends CompileErrorException { | 280 class ForceCompileErrorException extends CompileErrorException { |
281 toString() => | 281 toString() => |
282 '\nForce-compilation not successful. Please check static errors.'; | 282 '\nForce-compilation not successful. Please check static errors.'; |
283 } | 283 } |
284 | |
285 // TODO(jmesserly): fix this function in analyzer | |
286 List<String> filterUnknownArguments(List<String> args, ArgParser parser) { | |
287 Set<String> knownOptions = new Set<String>(); | |
288 Set<String> knownAbbreviations = new Set<String>(); | |
Bob Nystrom
2017/08/03 18:28:04
No "var"?
Jennifer Messerly
2017/08/03 19:43:06
this is just copied code from Analyzer; obviously
| |
289 parser.options.forEach((String name, option) { | |
290 knownOptions.add(name); | |
291 String abbreviation = option.abbreviation; | |
292 if (abbreviation != null) { | |
293 knownAbbreviations.add(abbreviation); | |
294 } | |
295 }); | |
296 List<String> filtered = <String>[]; | |
297 for (int i = 0; i < args.length; i++) { | |
Bob Nystrom
2017/08/03 18:28:04
Use a for-in loop?
Jennifer Messerly
2017/08/03 19:43:06
same as above. See TODO, I plan to remove this fun
| |
298 String argument = args[i]; | |
299 if (argument.startsWith('--') && argument.length > 2) { | |
300 int equalsOffset = argument.lastIndexOf('='); | |
301 int end = equalsOffset < 0 ? argument.length : equalsOffset; | |
302 if (knownOptions.contains(argument.substring(2, end))) { | |
303 filtered.add(argument); | |
304 } | |
305 } else if (argument.startsWith('-') && argument.length > 1) { | |
306 // TODO(jmesserly): fix this line in analyzer | |
307 // It was discarding abbreviations such as -Da=b | |
308 // Abbreviations must be 1-character (this is enforced by ArgParser), | |
309 // so we don't need to use `optionName` | |
310 if (knownAbbreviations.contains(argument[1])) { | |
311 filtered.add(argument); | |
312 } | |
313 } else { | |
314 filtered.add(argument); | |
315 } | |
316 } | |
317 return filtered; | |
318 } | |
OLD | NEW |