Chromium Code Reviews| 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 defineVariableOption = 'D'; | 18 const String defineVariableOption = 'D'; |
| 19 const String enableInitializingFormalAccessFlag = 'initializing-formal-access'; | 19 const String enableInitializingFormalAccessFlag = 'initializing-formal-access'; |
| 20 const String enableStrictCallChecksFlag = 'enable-strict-call-checks'; | 20 const String enableStrictCallChecksFlag = 'enable-strict-call-checks'; |
| 21 const String enableSuperInMixinFlag = 'supermixin'; | 21 const String enableSuperMixinFlag = 'supermixin'; |
| 22 const String ignoreUnrecognizedFlagsFlag = 'ignore-unrecognized-flags'; | 22 const String ignoreUnrecognizedFlagsFlag = 'ignore-unrecognized-flags'; |
| 23 const String noImplicitCastsFlag = 'no-implicit-casts'; | 23 const String noImplicitCastsFlag = 'no-implicit-casts'; |
| 24 const String noImplicitDynamicFlag = 'no-implicit-dynamic'; | 24 const String noImplicitDynamicFlag = 'no-implicit-dynamic'; |
| 25 const String packageRootOption = 'package-root'; | 25 const String packageRootOption = 'package-root'; |
| 26 const String packagesOption = 'packages'; | 26 const String packagesOption = 'packages'; |
| 27 const String sdkPathOption = 'dart-sdk'; | 27 const String sdkPathOption = 'dart-sdk'; |
| 28 const String sdkSummaryPathOption = 'dart-sdk-summary'; | 28 const String sdkSummaryPathOption = 'dart-sdk-summary'; |
| 29 const String strongModeFlag = 'strong'; | 29 const String strongModeFlag = 'strong'; |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Update [options] with the value of each analysis option command line flag, | |
|
Brian Wilkerson
2016/12/21 21:48:06
"," --> "."
danrubel
2016/12/23 01:32:03
Done.
| |
| 33 */ | |
| 34 void applyAnalysisOptionFlags(AnalysisOptions options, ArgResults args) { | |
|
Brian Wilkerson
2016/12/21 21:48:06
Something to consider: The only call site I see is
danrubel
2016/12/23 01:32:03
Good point. Done.
| |
| 35 if (args.wasParsed(enableStrictCallChecksFlag)) { | |
| 36 (options as AnalysisOptionsImpl).enableStrictCallChecks = | |
| 37 args[enableStrictCallChecksFlag]; | |
| 38 } | |
| 39 if (args.wasParsed(enableSuperMixinFlag)) { | |
| 40 (options as AnalysisOptionsImpl).enableSuperMixins = | |
| 41 args[enableSuperMixinFlag]; | |
| 42 } | |
| 43 if (args.wasParsed(noImplicitCastsFlag)) { | |
| 44 (options as AnalysisOptionsImpl).implicitCasts = !args[noImplicitCastsFlag]; | |
| 45 } | |
| 46 if (args.wasParsed(noImplicitDynamicFlag)) { | |
| 47 (options as AnalysisOptionsImpl).implicitDynamic = | |
| 48 !args[noImplicitDynamicFlag]; | |
| 49 } | |
| 50 if (args.wasParsed(strongModeFlag)) { | |
| 51 (options as AnalysisOptionsImpl).strongMode = args[strongModeFlag]; | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 /** | |
| 32 * Use the given [resourceProvider], [contentCache] and command-line [args] to | 56 * Use the given [resourceProvider], [contentCache] and command-line [args] to |
| 33 * create a context builder. | 57 * create a context builder. |
| 34 */ | 58 */ |
| 35 ContextBuilderOptions createContextBuilderOptions(ArgResults args) { | 59 ContextBuilderOptions createContextBuilderOptions(ArgResults args) { |
| 36 ContextBuilderOptions builderOptions = new ContextBuilderOptions(); | 60 ContextBuilderOptions builderOptions = new ContextBuilderOptions(); |
| 61 builderOptions.argResults = args; | |
| 37 // | 62 // |
| 38 // File locations. | 63 // File locations. |
| 39 // | 64 // |
| 40 builderOptions.dartSdkSummaryPath = args[sdkSummaryPathOption]; | 65 builderOptions.dartSdkSummaryPath = args[sdkSummaryPathOption]; |
| 41 builderOptions.defaultAnalysisOptionsFilePath = | 66 builderOptions.defaultAnalysisOptionsFilePath = |
| 42 args[analysisOptionsFileOption]; | 67 args[analysisOptionsFileOption]; |
| 43 builderOptions.defaultPackageFilePath = args[packagesOption]; | 68 builderOptions.defaultPackageFilePath = args[packagesOption]; |
| 44 builderOptions.defaultPackagesDirectoryPath = args[packageRootOption]; | 69 builderOptions.defaultPackagesDirectoryPath = args[packageRootOption]; |
| 45 // | 70 // |
| 46 // Analysis options. | 71 // Analysis options. |
| 47 // | 72 // |
| 48 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); | 73 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
| 49 defaultOptions.enableStrictCallChecks = args[enableStrictCallChecksFlag]; | 74 applyAnalysisOptionFlags(defaultOptions, args); |
| 50 defaultOptions.enableSuperMixins = args[enableSuperInMixinFlag]; | |
| 51 defaultOptions.implicitCasts = !args[noImplicitCastsFlag]; | |
| 52 defaultOptions.implicitDynamic = !args[noImplicitDynamicFlag]; | |
| 53 defaultOptions.strongMode = args[strongModeFlag]; | |
| 54 builderOptions.defaultOptions = defaultOptions; | 75 builderOptions.defaultOptions = defaultOptions; |
| 55 // | 76 // |
| 56 // Declared variables. | 77 // Declared variables. |
| 57 // | 78 // |
| 58 Map<String, String> declaredVariables = <String, String>{}; | 79 Map<String, String> declaredVariables = <String, String>{}; |
| 59 List<String> variables = args[defineVariableOption] as List<String>; | 80 List<String> variables = args[defineVariableOption] as List<String>; |
| 60 for (String variable in variables) { | 81 for (String variable in variables) { |
| 61 int index = variable.indexOf('='); | 82 int index = variable.indexOf('='); |
| 62 if (index < 0) { | 83 if (index < 0) { |
| 63 // TODO (brianwilkerson) Decide the semantics we want in this case. | 84 // TODO (brianwilkerson) Decide the semantics we want in this case. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 defaultsTo: false, | 177 defaultsTo: false, |
| 157 negatable: false, | 178 negatable: false, |
| 158 hide: hide || ddc); | 179 hide: hide || ddc); |
| 159 parser.addFlag(enableInitializingFormalAccessFlag, | 180 parser.addFlag(enableInitializingFormalAccessFlag, |
| 160 help: | 181 help: |
| 161 'Enable support for allowing access to field formal parameters in a ' | 182 'Enable support for allowing access to field formal parameters in a ' |
| 162 'constructor\'s initializer list', | 183 'constructor\'s initializer list', |
| 163 defaultsTo: false, | 184 defaultsTo: false, |
| 164 negatable: false, | 185 negatable: false, |
| 165 hide: hide || ddc); | 186 hide: hide || ddc); |
| 166 parser.addFlag(enableSuperInMixinFlag, | 187 parser.addFlag(enableSuperMixinFlag, |
| 167 help: 'Relax restrictions on mixins (DEP 34).', | 188 help: 'Relax restrictions on mixins (DEP 34).', |
| 168 defaultsTo: false, | 189 defaultsTo: false, |
| 169 negatable: false, | 190 negatable: false, |
| 170 hide: hide || ddc); | 191 hide: hide || ddc); |
| 171 // parser.addFlag('enable_type_checks', | 192 // parser.addFlag('enable_type_checks', |
| 172 // help: 'Check types in constant evaluation.', | 193 // help: 'Check types in constant evaluation.', |
| 173 // defaultsTo: false, | 194 // defaultsTo: false, |
| 174 // negatable: false, | 195 // negatable: false, |
| 175 // hide: hide || ddc); | 196 // hide: hide || ddc); |
| 176 } | 197 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 .replaceAll('\r\n', '\n') | 314 .replaceAll('\r\n', '\n') |
| 294 .replaceAll('\r', '\n') | 315 .replaceAll('\r', '\n') |
| 295 .split('\n') | 316 .split('\n') |
| 296 .where((String line) => line.isNotEmpty)); | 317 .where((String line) => line.isNotEmpty)); |
| 297 } on FileSystemException catch (e) { | 318 } on FileSystemException catch (e) { |
| 298 throw new Exception('Failed to read file specified by $lastArg : $e'); | 319 throw new Exception('Failed to read file specified by $lastArg : $e'); |
| 299 } | 320 } |
| 300 } | 321 } |
| 301 return args; | 322 return args; |
| 302 } | 323 } |
| OLD | NEW |