Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: pkg/analyzer_cli/lib/src/driver.dart

Issue 2710313002: rework analyzer_cli to use ContextBuilder getAnalysisOptions (Closed)
Patch Set: remove commented code Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer_cli/lib/src/build_mode.dart ('k') | pkg/analyzer_cli/test/all.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 26ddb0073b8efa83a48b497a027d54af88412e89..4fac0ba3d1893c6c71a7f7c399cf759b7080c379 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/driver.dart
@@ -561,13 +561,8 @@ class Driver implements CommandLineStarter {
SummaryDataStore summaryDataStore = new SummaryDataStore(
useSummaries ? options.buildSummaryInputs : <String>[]);
- // Create a temporary source factory without an SDK resolver
- // for resolving "include:" directives in analysis options files.
- SourceFactory tempSourceFactory = _chooseUriResolutionPolicy(
- options, embedderMap, packageInfo, summaryDataStore, false, null);
-
AnalysisOptionsImpl analysisOptions =
- createAnalysisOptions(resourceProvider, tempSourceFactory, options);
+ createAnalysisOptionsForCommandLineOptions(resourceProvider, options);
analysisOptions.analyzeFunctionBodiesPredicate =
_chooseDietParsingPolicy(options);
@@ -740,45 +735,40 @@ class Driver implements CommandLineStarter {
}
}
- static AnalysisOptionsImpl createAnalysisOptions(
- file_system.ResourceProvider resourceProvider,
- SourceFactory sourceFactory,
- CommandLineOptions options) {
- // Prepare context options.
- AnalysisOptionsImpl analysisOptions =
- createAnalysisOptionsForCommandLineOptions(options);
+ static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions(
+ ResourceProvider resourceProvider, CommandLineOptions options) {
+ if (options.analysisOptionsFile != null) {
+ file_system.File file =
+ resourceProvider.getFile(options.analysisOptionsFile);
+ if (!file.exists) {
+ printAndFail('Options file not found: ${options.analysisOptionsFile}',
+ exitCode: ErrorSeverity.ERROR.ordinal);
+ }
+ }
- // Process analysis options file (and notify all interested parties).
- _processAnalysisOptions(
- resourceProvider, sourceFactory, analysisOptions, options);
- return analysisOptions;
- }
+ AnalysisOptionsImpl contextOptions = new ContextBuilder(
+ resourceProvider, null, null,
+ options: options.contextBuilderOptions)
+ .getAnalysisOptions(options.sourceFiles.isNotEmpty
+ ? options.sourceFiles[0]
+ : path.current);
- static AnalysisOptionsImpl createAnalysisOptionsForCommandLineOptions(
- CommandLineOptions options) {
- AnalysisOptionsImpl contextOptions = new AnalysisOptionsImpl();
contextOptions.trackCacheDependencies = false;
contextOptions.disableCacheFlushing = options.disableCacheFlushing;
contextOptions.hint = !options.disableHints;
- contextOptions.enableStrictCallChecks = options.enableStrictCallChecks;
- contextOptions.enableSuperMixins = options.enableSuperMixins;
contextOptions.generateImplicitErrors = options.showPackageWarnings;
contextOptions.generateSdkErrors = options.showSdkWarnings;
- contextOptions.lint = options.lints;
- contextOptions.strongMode = options.strongMode;
- contextOptions.implicitCasts = options.implicitCasts;
- contextOptions.implicitDynamic = options.implicitDynamic;
+
return contextOptions;
}
static void setAnalysisContextOptions(
file_system.ResourceProvider resourceProvider,
- SourceFactory sourceFactory,
AnalysisContext context,
CommandLineOptions options,
void configureContextOptions(AnalysisOptionsImpl contextOptions)) {
AnalysisOptionsImpl analysisOptions =
- createAnalysisOptions(resourceProvider, sourceFactory, options);
+ createAnalysisOptionsForCommandLineOptions(resourceProvider, options);
configureContextOptions(analysisOptions);
setupAnalysisContext(context, options, analysisOptions);
}
@@ -827,55 +817,9 @@ class Driver implements CommandLineStarter {
return true;
}
- static file_system.File _getOptionsFile(
- file_system.ResourceProvider resourceProvider,
- CommandLineOptions options) {
- file_system.File file;
- String filePath = options.analysisOptionsFile;
- if (filePath != null) {
- file = resourceProvider.getFile(filePath);
- if (!file.exists) {
- printAndFail('Options file not found: $filePath',
- exitCode: ErrorSeverity.ERROR.ordinal);
- }
- } else {
- filePath = AnalysisEngine.ANALYSIS_OPTIONS_FILE;
- file = resourceProvider.getFile(filePath);
- if (!file.exists) {
- filePath = AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE;
- file = resourceProvider.getFile(filePath);
- }
- }
- return file;
- }
-
/// Convert [sourcePath] into an absolute path.
static String _normalizeSourcePath(String sourcePath) =>
path.normalize(new io.File(sourcePath).absolute.path);
-
- static void _processAnalysisOptions(
- file_system.ResourceProvider resourceProvider,
- SourceFactory sourceFactory,
- AnalysisOptionsImpl analysisOptions,
- CommandLineOptions options) {
- file_system.File file = _getOptionsFile(resourceProvider, options);
-
- AnalysisOptionsProvider analysisOptionsProvider =
- new AnalysisOptionsProvider(sourceFactory);
- Map<String, YamlNode> optionMap =
- analysisOptionsProvider.getOptionsFromFile(file);
-
- // Fill in lint rule defaults in case lints are enabled and rules are
- // not specified in an options file.
- if (options.lints && !containsLintRuleEntry(optionMap)) {
- analysisOptions.lintRules = Registry.ruleRegistry.defaultRules;
- }
-
- // Ask engine to further process options.
- if (optionMap != null) {
- applyToAnalysisOptions(analysisOptions, optionMap);
- }
- }
}
/// Provides a framework to read command line options from stdin and feed them
« no previous file with comments | « pkg/analyzer_cli/lib/src/build_mode.dart ('k') | pkg/analyzer_cli/test/all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698