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. |
| 33 */ |
| 34 void applyAnalysisOptionFlags(AnalysisOptionsImpl options, ArgResults args) { |
| 35 if (args.wasParsed(enableStrictCallChecksFlag)) { |
| 36 options.enableStrictCallChecks = args[enableStrictCallChecksFlag]; |
| 37 } |
| 38 if (args.wasParsed(enableSuperMixinFlag)) { |
| 39 options.enableSuperMixins = args[enableSuperMixinFlag]; |
| 40 } |
| 41 if (args.wasParsed(noImplicitCastsFlag)) { |
| 42 options.implicitCasts = !args[noImplicitCastsFlag]; |
| 43 } |
| 44 if (args.wasParsed(noImplicitDynamicFlag)) { |
| 45 options.implicitDynamic = !args[noImplicitDynamicFlag]; |
| 46 } |
| 47 if (args.wasParsed(strongModeFlag)) { |
| 48 options.strongMode = args[strongModeFlag]; |
| 49 } |
| 50 } |
| 51 |
| 52 /** |
32 * Use the given [resourceProvider], [contentCache] and command-line [args] to | 53 * Use the given [resourceProvider], [contentCache] and command-line [args] to |
33 * create a context builder. | 54 * create a context builder. |
34 */ | 55 */ |
35 ContextBuilderOptions createContextBuilderOptions(ArgResults args) { | 56 ContextBuilderOptions createContextBuilderOptions(ArgResults args) { |
36 ContextBuilderOptions builderOptions = new ContextBuilderOptions(); | 57 ContextBuilderOptions builderOptions = new ContextBuilderOptions(); |
| 58 builderOptions.argResults = args; |
37 // | 59 // |
38 // File locations. | 60 // File locations. |
39 // | 61 // |
40 builderOptions.dartSdkSummaryPath = args[sdkSummaryPathOption]; | 62 builderOptions.dartSdkSummaryPath = args[sdkSummaryPathOption]; |
41 builderOptions.defaultAnalysisOptionsFilePath = | 63 builderOptions.defaultAnalysisOptionsFilePath = |
42 args[analysisOptionsFileOption]; | 64 args[analysisOptionsFileOption]; |
43 builderOptions.defaultPackageFilePath = args[packagesOption]; | 65 builderOptions.defaultPackageFilePath = args[packagesOption]; |
44 builderOptions.defaultPackagesDirectoryPath = args[packageRootOption]; | 66 builderOptions.defaultPackagesDirectoryPath = args[packageRootOption]; |
45 // | 67 // |
46 // Analysis options. | 68 // Analysis options. |
47 // | 69 // |
48 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); | 70 AnalysisOptionsImpl defaultOptions = new AnalysisOptionsImpl(); |
49 defaultOptions.enableStrictCallChecks = args[enableStrictCallChecksFlag]; | 71 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; | 72 builderOptions.defaultOptions = defaultOptions; |
55 // | 73 // |
56 // Declared variables. | 74 // Declared variables. |
57 // | 75 // |
58 Map<String, String> declaredVariables = <String, String>{}; | 76 Map<String, String> declaredVariables = <String, String>{}; |
59 List<String> variables = args[defineVariableOption] as List<String>; | 77 List<String> variables = args[defineVariableOption] as List<String>; |
60 for (String variable in variables) { | 78 for (String variable in variables) { |
61 int index = variable.indexOf('='); | 79 int index = variable.indexOf('='); |
62 if (index < 0) { | 80 if (index < 0) { |
63 // TODO (brianwilkerson) Decide the semantics we want in this case. | 81 // 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, | 174 defaultsTo: false, |
157 negatable: false, | 175 negatable: false, |
158 hide: hide || ddc); | 176 hide: hide || ddc); |
159 parser.addFlag(enableInitializingFormalAccessFlag, | 177 parser.addFlag(enableInitializingFormalAccessFlag, |
160 help: | 178 help: |
161 'Enable support for allowing access to field formal parameters in a ' | 179 'Enable support for allowing access to field formal parameters in a ' |
162 'constructor\'s initializer list', | 180 'constructor\'s initializer list', |
163 defaultsTo: false, | 181 defaultsTo: false, |
164 negatable: false, | 182 negatable: false, |
165 hide: hide || ddc); | 183 hide: hide || ddc); |
166 parser.addFlag(enableSuperInMixinFlag, | 184 parser.addFlag(enableSuperMixinFlag, |
167 help: 'Relax restrictions on mixins (DEP 34).', | 185 help: 'Relax restrictions on mixins (DEP 34).', |
168 defaultsTo: false, | 186 defaultsTo: false, |
169 negatable: false, | 187 negatable: false, |
170 hide: hide || ddc); | 188 hide: hide || ddc); |
171 // parser.addFlag('enable_type_checks', | 189 // parser.addFlag('enable_type_checks', |
172 // help: 'Check types in constant evaluation.', | 190 // help: 'Check types in constant evaluation.', |
173 // defaultsTo: false, | 191 // defaultsTo: false, |
174 // negatable: false, | 192 // negatable: false, |
175 // hide: hide || ddc); | 193 // hide: hide || ddc); |
176 } | 194 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 .replaceAll('\r\n', '\n') | 311 .replaceAll('\r\n', '\n') |
294 .replaceAll('\r', '\n') | 312 .replaceAll('\r', '\n') |
295 .split('\n') | 313 .split('\n') |
296 .where((String line) => line.isNotEmpty)); | 314 .where((String line) => line.isNotEmpty)); |
297 } on FileSystemException catch (e) { | 315 } on FileSystemException catch (e) { |
298 throw new Exception('Failed to read file specified by $lastArg : $e'); | 316 throw new Exception('Failed to read file specified by $lastArg : $e'); |
299 } | 317 } |
300 } | 318 } |
301 return args; | 319 return args; |
302 } | 320 } |
OLD | NEW |