Chromium Code Reviews| Index: pkg/analyzer_cli/lib/src/driver.dart |
| diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart |
| index 4942015e2c192b1339f78f610338d0d1cbfd69f7..c48eab53d4366559c1b7aba03ca8058fa69b7265 100644 |
| --- a/pkg/analyzer_cli/lib/src/driver.dart |
| +++ b/pkg/analyzer_cli/lib/src/driver.dart |
| @@ -73,9 +73,6 @@ class Driver implements CommandLineStarter { |
| /// The plugins that are defined outside the `analyzer_cli` package. |
| List<Plugin> _userDefinedPlugins = <Plugin>[]; |
| - /// Indicates whether the analyzer is running in batch mode. |
| - bool _isBatch; |
| - |
| /// The context that was most recently created by a call to [_analyzeAll], or |
| /// `null` if [_analyzeAll] hasn't been called yet. |
| AnalysisContext _context; |
| @@ -93,6 +90,9 @@ class Driver implements CommandLineStarter { |
| @override |
| ResolverProvider packageResolverProvider; |
| + /// SDK instance. |
| + DirectoryBasedDartSdk sdk; |
| + |
| /// Collected analysis statistics. |
| final AnalysisStats stats = new AnalysisStats(); |
| @@ -120,9 +120,6 @@ class Driver implements CommandLineStarter { |
| // Parse commandline options. |
| CommandLineOptions options = CommandLineOptions.parse(args); |
| - // Cache options of interest to inform analysis. |
| - _setupEnv(options); |
| - |
| // Do analysis. |
| if (options.buildMode) { |
| ErrorSeverity severity = _buildModeAnalyze(options); |
| @@ -130,7 +127,7 @@ class Driver implements CommandLineStarter { |
| if (severity == ErrorSeverity.ERROR) { |
| exitCode = severity.ordinal; |
| } |
| - } else if (_isBatch) { |
| + } else if (options.shouldBatch) { |
| _BatchRunner.runAsBatch(args, (List<String> args) { |
| CommandLineOptions options = CommandLineOptions.parse(args); |
| return _analyzeAll(options); |
| @@ -306,7 +303,7 @@ class Driver implements CommandLineStarter { |
| /// [AnalyzeFunctionBodiesPredicate] that implements this policy. |
| AnalyzeFunctionBodiesPredicate _chooseDietParsingPolicy( |
| CommandLineOptions options) { |
| - if (_isBatch) { |
| + if (options.shouldBatch) { |
| // As analyzer is currently implemented, once a file has been diet |
| // parsed, it can't easily be un-diet parsed without creating a brand new |
| // context and losing caching. In batch mode, we can't predict which |
| @@ -507,19 +504,22 @@ class Driver implements CommandLineStarter { |
| // Create a context. |
| _context = AnalysisEngine.instance.createAnalysisContext(); |
| - // Choose a package resolution policy and a diet parsing policy based on |
| - // the command-line options. |
| - SourceFactory sourceFactory = _chooseUriResolutionPolicy( |
| - options, (_context as InternalAnalysisContext).embedderYamlLocator); |
| AnalyzeFunctionBodiesPredicate dietParsingPolicy = |
| _chooseDietParsingPolicy(options); |
| - |
| - _context.sourceFactory = sourceFactory; |
| - |
| setAnalysisContextOptions(_context, options, |
| (AnalysisOptionsImpl contextOptions) { |
| contextOptions.analyzeFunctionBodiesPredicate = dietParsingPolicy; |
| }); |
| + |
| + // Once options are processed, setup the SDK. |
| + _setupSdk(path: options.dartSdkPath); |
| + |
| + // Choose a package resolution policy and a diet parsing policy based on |
| + // the command-line options. |
| + SourceFactory sourceFactory = _chooseUriResolutionPolicy( |
| + options, (_context as InternalAnalysisContext).embedderYamlLocator); |
| + |
| + _context.sourceFactory = sourceFactory; |
| } |
| /// Return discovered packagespec, or `null` if none is found. |
| @@ -582,16 +582,12 @@ class Driver implements CommandLineStarter { |
| return errorSeverity; |
| } |
| - void _setupEnv(CommandLineOptions options) { |
| - // In batch mode, SDK is specified on the main command line rather than in |
| - // the command lines sent to stdin. So process it before deciding whether |
| - // to activate batch mode. |
| + void _setupSdk({String path}) { |
|
Paul Berry
2016/05/10 18:33:24
Nit: it seems weird for [path] to be an optional p
pquitslund
2016/05/10 21:22:39
Yeah. I just really like named params! Would that
|
| if (sdk == null) { |
| - sdk = new DirectoryBasedDartSdk(new JavaFile(options.dartSdkPath)); |
| + sdk = new DirectoryBasedDartSdk(new JavaFile(path)); |
| sdk.useSummary = true; |
| - sdk.analysisOptions = createAnalysisOptionsForCommandLineOptions(options); |
| + sdk.analysisOptions = context.analysisOptions; |
| } |
| - _isBatch = options.shouldBatch; |
| } |
| static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions( |