| 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 analyzer.src.command_line.arguments; | 5 library analyzer.src.command_line.arguments; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
| 10 import 'package:analyzer/src/context/builder.dart'; | 10 import 'package:analyzer/src/context/builder.dart'; |
| 11 import 'package:analyzer/src/dart/sdk/sdk.dart'; | 11 import 'package:analyzer/src/dart/sdk/sdk.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/sdk.dart'; | 13 import 'package:analyzer/src/generated/sdk.dart'; |
| 14 import 'package:args/args.dart'; | 14 import 'package:args/args.dart'; |
| 15 import 'package:path/path.dart'; | 15 import 'package:path/path.dart'; |
| 16 | 16 |
| 17 const String analysisOptionsFileOption = 'options'; | 17 const String analysisOptionsFileOption = 'options'; |
| 18 const String bazelAnalysisOptionsPath = | 18 const String bazelAnalysisOptionsPath = |
| 19 'package:dart.analysis_options/default.yaml'; | 19 'package:dart.analysis_options/default.yaml'; |
| 20 const String declarationCastsFlag = 'declaration-casts'; |
| 20 const String defineVariableOption = 'D'; | 21 const String defineVariableOption = 'D'; |
| 21 const String enableInitializingFormalAccessFlag = 'initializing-formal-access'; | 22 const String enableInitializingFormalAccessFlag = 'initializing-formal-access'; |
| 22 const String enableStrictCallChecksFlag = 'enable-strict-call-checks'; | 23 const String enableStrictCallChecksFlag = 'enable-strict-call-checks'; |
| 23 const String enableSuperMixinFlag = 'supermixin'; | 24 const String enableSuperMixinFlag = 'supermixin'; |
| 24 const String flutterAnalysisOptionsPath = | 25 const String flutterAnalysisOptionsPath = |
| 25 'package:flutter/analysis_options_user.yaml'; | 26 'package:flutter/analysis_options_user.yaml'; |
| 26 const String ignoreUnrecognizedFlagsFlag = 'ignore-unrecognized-flags'; | 27 const String ignoreUnrecognizedFlagsFlag = 'ignore-unrecognized-flags'; |
| 28 const String implicitCastsFlag = 'implicit-casts'; |
| 27 const String lintsFlag = 'lints'; | 29 const String lintsFlag = 'lints'; |
| 28 const String noImplicitCastsFlag = 'no-implicit-casts'; | |
| 29 const String noImplicitDynamicFlag = 'no-implicit-dynamic'; | 30 const String noImplicitDynamicFlag = 'no-implicit-dynamic'; |
| 30 const String packageDefaultAnalysisOptions = 'package-default-analysis-options'; | 31 const String packageDefaultAnalysisOptions = 'package-default-analysis-options'; |
| 31 const String packageRootOption = 'package-root'; | 32 const String packageRootOption = 'package-root'; |
| 32 const String packagesOption = 'packages'; | 33 const String packagesOption = 'packages'; |
| 33 const String sdkPathOption = 'dart-sdk'; | 34 const String sdkPathOption = 'dart-sdk'; |
| 34 | 35 |
| 35 const String sdkSummaryPathOption = 'dart-sdk-summary'; | 36 const String sdkSummaryPathOption = 'dart-sdk-summary'; |
| 36 const String strongModeFlag = 'strong'; | 37 const String strongModeFlag = 'strong'; |
| 37 | 38 |
| 38 /** | 39 /** |
| 39 * Update [options] with the value of each analysis option command line flag. | 40 * Update [options] with the value of each analysis option command line flag. |
| 40 */ | 41 */ |
| 41 void applyAnalysisOptionFlags(AnalysisOptionsImpl options, ArgResults args, | 42 void applyAnalysisOptionFlags(AnalysisOptionsImpl options, ArgResults args, |
| 42 {void verbosePrint(String text)}) { | 43 {void verbosePrint(String text)}) { |
| 43 void verbose(String text) { | 44 void verbose(String text) { |
| 44 if (verbosePrint != null) { | 45 if (verbosePrint != null) { |
| 45 verbosePrint('Analysis options: $text'); | 46 verbosePrint('Analysis options: $text'); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 49 if (args.wasParsed(enableStrictCallChecksFlag)) { | 50 if (args.wasParsed(enableStrictCallChecksFlag)) { |
| 50 options.enableStrictCallChecks = args[enableStrictCallChecksFlag]; | 51 options.enableStrictCallChecks = args[enableStrictCallChecksFlag]; |
| 51 verbose('$enableStrictCallChecksFlag = ${options.enableStrictCallChecks}'); | 52 verbose('$enableStrictCallChecksFlag = ${options.enableStrictCallChecks}'); |
| 52 } | 53 } |
| 53 if (args.wasParsed(enableSuperMixinFlag)) { | 54 if (args.wasParsed(enableSuperMixinFlag)) { |
| 54 options.enableSuperMixins = args[enableSuperMixinFlag]; | 55 options.enableSuperMixins = args[enableSuperMixinFlag]; |
| 55 verbose('$enableSuperMixinFlag = ${options.enableSuperMixins}'); | 56 verbose('$enableSuperMixinFlag = ${options.enableSuperMixins}'); |
| 56 } | 57 } |
| 57 if (args.wasParsed(noImplicitCastsFlag)) { | 58 if (args.wasParsed(implicitCastsFlag)) { |
| 58 options.implicitCasts = !args[noImplicitCastsFlag]; | 59 options.implicitCasts = args[implicitCastsFlag]; |
| 59 verbose('$noImplicitCastsFlag = ${options.implicitCasts}'); | 60 verbose('$implicitCastsFlag = ${options.implicitCasts}'); |
| 61 } |
| 62 if (args.wasParsed(declarationCastsFlag)) { |
| 63 options.declarationCasts = args[declarationCastsFlag]; |
| 64 verbose('$declarationCastsFlag = ${options.declarationCasts}'); |
| 65 } else if (args.wasParsed(implicitCastsFlag)) { |
| 66 options.declarationCasts = args[implicitCastsFlag]; |
| 67 verbose('$declarationCastsFlag = ${options.declarationCasts}'); |
| 60 } | 68 } |
| 61 if (args.wasParsed(noImplicitDynamicFlag)) { | 69 if (args.wasParsed(noImplicitDynamicFlag)) { |
| 62 options.implicitDynamic = !args[noImplicitDynamicFlag]; | 70 options.implicitDynamic = !args[noImplicitDynamicFlag]; |
| 63 verbose('$noImplicitDynamicFlag = ${options.implicitDynamic}'); | 71 verbose('$noImplicitDynamicFlag = ${options.implicitDynamic}'); |
| 64 } | 72 } |
| 65 if (args.wasParsed(strongModeFlag)) { | 73 if (args.wasParsed(strongModeFlag)) { |
| 66 options.strongMode = args[strongModeFlag]; | 74 options.strongMode = args[strongModeFlag]; |
| 67 verbose('$strongModeFlag = ${options.strongMode}'); | 75 verbose('$strongModeFlag = ${options.strongMode}'); |
| 68 } | 76 } |
| 69 try { | 77 try { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 void defineAnalysisArguments(ArgParser parser, {bool hide: true, ddc: false}) { | 175 void defineAnalysisArguments(ArgParser parser, {bool hide: true, ddc: false}) { |
| 168 parser.addOption(sdkPathOption, help: 'The path to the Dart SDK.'); | 176 parser.addOption(sdkPathOption, help: 'The path to the Dart SDK.'); |
| 169 parser.addOption(analysisOptionsFileOption, | 177 parser.addOption(analysisOptionsFileOption, |
| 170 help: 'Path to an analysis options file.'); | 178 help: 'Path to an analysis options file.'); |
| 171 parser.addOption(packageRootOption, | 179 parser.addOption(packageRootOption, |
| 172 help: 'The path to a package root directory (deprecated). ' | 180 help: 'The path to a package root directory (deprecated). ' |
| 173 'This option cannot be used with --packages.'); | 181 'This option cannot be used with --packages.'); |
| 174 parser.addFlag(strongModeFlag, | 182 parser.addFlag(strongModeFlag, |
| 175 help: 'Enable strong static checks (https://goo.gl/DqcBsw).', | 183 help: 'Enable strong static checks (https://goo.gl/DqcBsw).', |
| 176 defaultsTo: ddc); | 184 defaultsTo: ddc); |
| 177 parser.addFlag(noImplicitCastsFlag, | 185 parser.addFlag(declarationCastsFlag, |
| 178 negatable: false, | 186 negatable: true, |
| 187 help: |
| 188 'Disable declaration casts in strong mode (https://goo.gl/cTLz40).'); |
| 189 parser.addFlag(implicitCastsFlag, |
| 190 negatable: true, |
| 179 help: 'Disable implicit casts in strong mode (https://goo.gl/cTLz40).'); | 191 help: 'Disable implicit casts in strong mode (https://goo.gl/cTLz40).'); |
| 180 parser.addFlag(noImplicitDynamicFlag, | 192 parser.addFlag(noImplicitDynamicFlag, |
| 181 negatable: false, | 193 negatable: false, |
| 182 help: 'Disable implicit dynamic (https://goo.gl/m0UgXD).'); | 194 help: 'Disable implicit dynamic (https://goo.gl/m0UgXD).'); |
| 183 | 195 |
| 184 // | 196 // |
| 185 // Hidden flags and options. | 197 // Hidden flags and options. |
| 186 // | 198 // |
| 187 parser.addOption(defineVariableOption, | 199 parser.addOption(defineVariableOption, |
| 188 abbr: 'D', | 200 abbr: 'D', |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 .replaceAll('\r\n', '\n') | 361 .replaceAll('\r\n', '\n') |
| 350 .replaceAll('\r', '\n') | 362 .replaceAll('\r', '\n') |
| 351 .split('\n') | 363 .split('\n') |
| 352 .where((String line) => line.isNotEmpty)); | 364 .where((String line) => line.isNotEmpty)); |
| 353 } on FileSystemException catch (e) { | 365 } on FileSystemException catch (e) { |
| 354 throw new Exception('Failed to read file specified by $lastArg : $e'); | 366 throw new Exception('Failed to read file specified by $lastArg : $e'); |
| 355 } | 367 } |
| 356 } | 368 } |
| 357 return args; | 369 return args; |
| 358 } | 370 } |
| OLD | NEW |