Remove OptionsWorkManager and GenerateOptionsErrorsTask is not a task.

R=brianwilkerson@google.com

Change-Id: Ic257c13a553835f78bd7bc0778dd33c327097af9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97284
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/context_manager.dart b/pkg/analysis_server/lib/src/context_manager.dart
index b7312d6..f9ce8ac 100644
--- a/pkg/analysis_server/lib/src/context_manager.dart
+++ b/pkg/analysis_server/lib/src/context_manager.dart
@@ -846,11 +846,10 @@
     try {
       String content = _readFile(path);
       LineInfo lineInfo = _computeLineInfo(content);
-      List<AnalysisError> errors =
-          GenerateOptionsErrorsTask.analyzeAnalysisOptions(
-              resourceProvider.getFile(path).createSource(),
-              content,
-              driver.sourceFactory);
+      List<AnalysisError> errors = analyzeAnalysisOptions(
+          resourceProvider.getFile(path).createSource(),
+          content,
+          driver.sourceFactory);
       AnalyzerConverter converter = new AnalyzerConverter();
       convertedErrors = converter.convertAnalysisErrors(errors,
           lineInfo: lineInfo, options: driver.analysisOptions);
diff --git a/pkg/analyzer/lib/src/task/options.dart b/pkg/analyzer/lib/src/task/options.dart
index b195c6c..351daef 100644
--- a/pkg/analyzer/lib/src/task/options.dart
+++ b/pkg/analyzer/lib/src/task/options.dart
@@ -19,22 +19,93 @@
 import 'package:analyzer/src/lint/options_rule_validator.dart';
 import 'package:analyzer/src/lint/registry.dart';
 import 'package:analyzer/src/plugin/options.dart';
-import 'package:analyzer/src/task/api/general.dart';
-import 'package:analyzer/src/task/api/model.dart';
-import 'package:analyzer/src/task/general.dart';
 import 'package:analyzer/src/util/yaml.dart';
 import 'package:source_span/source_span.dart';
 import 'package:yaml/yaml.dart';
 
-/// The errors produced while parsing an analysis options file.
-///
-/// The list will be empty if there were no errors, but will not be `null`.
-final ListResultDescriptor<AnalysisError> ANALYSIS_OPTIONS_ERRORS =
-    new ListResultDescriptor<AnalysisError>(
-        'ANALYSIS_OPTIONS_ERRORS', AnalysisError.NO_ERRORS);
-
 final _OptionsProcessor _processor = new _OptionsProcessor();
 
+List<AnalysisError> analyzeAnalysisOptions(
+    Source source, String content, SourceFactory sourceFactory) {
+  List<AnalysisError> errors = <AnalysisError>[];
+  Source initialSource = source;
+  SourceSpan initialIncludeSpan;
+  AnalysisOptionsProvider optionsProvider =
+      new AnalysisOptionsProvider(sourceFactory);
+
+  // Validate the specified options and any included option files
+  void validate(Source source, YamlMap options) {
+    List<AnalysisError> validationErrors =
+        new OptionsFileValidator(source).validate(options);
+    if (initialIncludeSpan != null && validationErrors.isNotEmpty) {
+      for (AnalysisError error in validationErrors) {
+        var args = [
+          source.fullName,
+          error.offset.toString(),
+          (error.offset + error.length - 1).toString(),
+          error.message,
+        ];
+        errors.add(new AnalysisError(
+            initialSource,
+            initialIncludeSpan.start.column + 1,
+            initialIncludeSpan.length,
+            AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING,
+            args));
+      }
+    } else {
+      errors.addAll(validationErrors);
+    }
+
+    YamlNode node = getValue(options, AnalyzerOptions.include);
+    if (node == null) {
+      return;
+    }
+    SourceSpan span = node.span;
+    initialIncludeSpan ??= span;
+    String includeUri = span.text;
+    Source includedSource = sourceFactory.resolveUri(source, includeUri);
+    if (includedSource == null || !includedSource.exists()) {
+      errors.add(new AnalysisError(
+          initialSource,
+          initialIncludeSpan.start.column + 1,
+          initialIncludeSpan.length,
+          AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND,
+          [includeUri, source.fullName]));
+      return;
+    }
+    try {
+      YamlMap options =
+          optionsProvider.getOptionsFromString(includedSource.contents.data);
+      validate(includedSource, options);
+    } on OptionsFormatException catch (e) {
+      var args = [
+        includedSource.fullName,
+        e.span.start.offset.toString(),
+        e.span.end.offset.toString(),
+        e.message,
+      ];
+      // Report errors for included option files
+      // on the include directive located in the initial options file.
+      errors.add(new AnalysisError(
+          initialSource,
+          initialIncludeSpan.start.column + 1,
+          initialIncludeSpan.length,
+          AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR,
+          args));
+    }
+  }
+
+  try {
+    YamlMap options = optionsProvider.getOptionsFromString(content);
+    validate(source, options);
+  } on OptionsFormatException catch (e) {
+    SourceSpan span = e.span;
+    errors.add(new AnalysisError(source, span.start.column + 1, span.length,
+        AnalysisOptionsErrorCode.PARSE_ERROR, [e.message]));
+  }
+  return errors;
+}
+
 void applyToAnalysisOptions(AnalysisOptionsImpl options, YamlMap optionMap) {
   _processor.applyToAnalysisOptions(options, optionMap);
 }
@@ -273,153 +344,6 @@
   }
 }
 
-/// A task that generates errors for an analysis options file.
-class GenerateOptionsErrorsTask extends SourceBasedAnalysisTask {
-  /// The name of the input whose value is the content of the file.
-  static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME';
-
-  /// The task descriptor describing this kind of task.
-  static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
-      'GenerateOptionsErrorsTask',
-      createTask,
-      buildInputs,
-      <ResultDescriptor>[ANALYSIS_OPTIONS_ERRORS, LINE_INFO],
-      suitabilityFor: suitabilityFor);
-
-  AnalysisOptionsProvider optionsProvider;
-
-  GenerateOptionsErrorsTask(AnalysisContext context, AnalysisTarget target)
-      : super(context, target) {
-    optionsProvider = new AnalysisOptionsProvider(context?.sourceFactory);
-  }
-
-  @override
-  TaskDescriptor get descriptor => DESCRIPTOR;
-
-  Source get source => target.source;
-
-  @override
-  void internalPerform() {
-    String content = getRequiredInput(CONTENT_INPUT_NAME);
-    //
-    // Record outputs.
-    //
-    outputs[ANALYSIS_OPTIONS_ERRORS] =
-        analyzeAnalysisOptions(source, content, context?.sourceFactory);
-    outputs[LINE_INFO] = computeLineInfo(content);
-  }
-
-  static List<AnalysisError> analyzeAnalysisOptions(
-      Source source, String content, SourceFactory sourceFactory) {
-    List<AnalysisError> errors = <AnalysisError>[];
-    Source initialSource = source;
-    SourceSpan initialIncludeSpan;
-    AnalysisOptionsProvider optionsProvider =
-        new AnalysisOptionsProvider(sourceFactory);
-
-    // Validate the specified options and any included option files
-    void validate(Source source, YamlMap options) {
-      List<AnalysisError> validationErrors =
-          new OptionsFileValidator(source).validate(options);
-      if (initialIncludeSpan != null && validationErrors.isNotEmpty) {
-        for (AnalysisError error in validationErrors) {
-          var args = [
-            source.fullName,
-            error.offset.toString(),
-            (error.offset + error.length - 1).toString(),
-            error.message,
-          ];
-          errors.add(new AnalysisError(
-              initialSource,
-              initialIncludeSpan.start.column + 1,
-              initialIncludeSpan.length,
-              AnalysisOptionsWarningCode.INCLUDED_FILE_WARNING,
-              args));
-        }
-      } else {
-        errors.addAll(validationErrors);
-      }
-
-      YamlNode node = getValue(options, AnalyzerOptions.include);
-      if (node == null) {
-        return;
-      }
-      SourceSpan span = node.span;
-      initialIncludeSpan ??= span;
-      String includeUri = span.text;
-      Source includedSource = sourceFactory.resolveUri(source, includeUri);
-      if (includedSource == null || !includedSource.exists()) {
-        errors.add(new AnalysisError(
-            initialSource,
-            initialIncludeSpan.start.column + 1,
-            initialIncludeSpan.length,
-            AnalysisOptionsWarningCode.INCLUDE_FILE_NOT_FOUND,
-            [includeUri, source.fullName]));
-        return;
-      }
-      try {
-        YamlMap options =
-            optionsProvider.getOptionsFromString(includedSource.contents.data);
-        validate(includedSource, options);
-      } on OptionsFormatException catch (e) {
-        var args = [
-          includedSource.fullName,
-          e.span.start.offset.toString(),
-          e.span.end.offset.toString(),
-          e.message,
-        ];
-        // Report errors for included option files
-        // on the include directive located in the initial options file.
-        errors.add(new AnalysisError(
-            initialSource,
-            initialIncludeSpan.start.column + 1,
-            initialIncludeSpan.length,
-            AnalysisOptionsErrorCode.INCLUDED_FILE_PARSE_ERROR,
-            args));
-      }
-    }
-
-    try {
-      YamlMap options = optionsProvider.getOptionsFromString(content);
-      validate(source, options);
-    } on OptionsFormatException catch (e) {
-      SourceSpan span = e.span;
-      errors.add(new AnalysisError(source, span.start.column + 1, span.length,
-          AnalysisOptionsErrorCode.PARSE_ERROR, [e.message]));
-    }
-    return errors;
-  }
-
-  /// Return a map from the names of the inputs of this kind of task to the
-  /// task input descriptors describing those inputs for a task with the
-  /// given [target].
-  static Map<String, TaskInput> buildInputs(AnalysisTarget source) =>
-      <String, TaskInput>{CONTENT_INPUT_NAME: CONTENT.of(source)};
-
-  /// Compute [LineInfo] for the given [content].
-  static LineInfo computeLineInfo(String content) {
-    List<int> lineStarts = StringUtilities.computeLineStarts(content);
-    return new LineInfo(lineStarts);
-  }
-
-  /// Create a task based on the given [target] in the given [context].
-  static GenerateOptionsErrorsTask createTask(
-          AnalysisContext context, AnalysisTarget target) =>
-      new GenerateOptionsErrorsTask(context, target);
-
-  /**
-   * Return an indication of how suitable this task is for the given [target].
-   */
-  static TaskSuitability suitabilityFor(AnalysisTarget target) {
-    if (target is Source &&
-        (target.shortName == AnalysisEngine.ANALYSIS_OPTIONS_FILE ||
-            target.shortName == AnalysisEngine.ANALYSIS_OPTIONS_YAML_FILE)) {
-      return TaskSuitability.HIGHEST;
-    }
-    return TaskSuitability.NONE;
-  }
-}
-
 /// Validates `analyzer` language configuration options.
 class LanguageOptionValidator extends OptionsValidator {
   ErrorBuilder builder = new ErrorBuilder(AnalyzerOptions.languageOptions);
diff --git a/pkg/analyzer/lib/src/task/options_work_manager.dart b/pkg/analyzer/lib/src/task/options_work_manager.dart
deleted file mode 100644
index fab4ebe..0000000
--- a/pkg/analyzer/lib/src/task/options_work_manager.dart
+++ /dev/null
@@ -1,167 +0,0 @@
-// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-import 'dart:collection';
-
-import 'package:analyzer/error/error.dart';
-import 'package:analyzer/src/context/cache.dart';
-import 'package:analyzer/src/generated/engine.dart'
-    show AnalysisEngine, AnalysisErrorInfo, CacheState, InternalAnalysisContext;
-import 'package:analyzer/src/generated/source.dart';
-import 'package:analyzer/src/task/api/model.dart';
-import 'package:analyzer/src/task/options.dart';
-
-/// The manager for analysis options specific analysis.
-class OptionsWorkManager implements WorkManager {
-  /// The context for which work is being managed.
-  final InternalAnalysisContext context;
-
-  /// The options file sources.
-  final LinkedHashSet<Source> sourceQueue = new LinkedHashSet<Source>();
-
-  /// The [TargetedResult]s that should be computed with priority.
-  final LinkedHashSet<TargetedResult> priorityResultQueue =
-      new LinkedHashSet<TargetedResult>();
-
-  /// Initialize a newly created manager.
-  OptionsWorkManager(this.context) {
-    analysisCache.onResultInvalidated.listen(onResultInvalidated);
-  }
-
-  /// Returns the correctly typed result of `context.analysisCache`.
-  AnalysisCache get analysisCache => context.analysisCache;
-
-  /// Specifies that the client wants the given [result] of the given [target]
-  /// to be computed with priority.
-  void addPriorityResult(AnalysisTarget target, ResultDescriptor result) {
-    priorityResultQueue.add(new TargetedResult(target, result));
-  }
-
-  @override
-  void applyChange(List<Source> addedSources, List<Source> changedSources,
-      List<Source> removedSources) {
-    addedSources = addedSources.where(_isOptionsSource).toList();
-    changedSources = changedSources.where(_isOptionsSource).toList();
-    removedSources = removedSources.where(_isOptionsSource).toList();
-    // source queue
-    sourceQueue.addAll(addedSources);
-    sourceQueue.addAll(changedSources);
-    sourceQueue.removeAll(removedSources);
-  }
-
-  @override
-  void applyPriorityTargets(List<AnalysisTarget> targets) {
-    // Unschedule the old targets.
-    List<TargetedResult> resultsToUnschedule = <TargetedResult>[];
-    for (TargetedResult result in priorityResultQueue) {
-      if (result.result == ANALYSIS_OPTIONS_ERRORS) {
-        resultsToUnschedule.add(result);
-      }
-    }
-    priorityResultQueue.removeAll(resultsToUnschedule);
-    // Schedule new targets.
-    for (AnalysisTarget target in targets) {
-      if (_isOptionsSource(target)) {
-        addPriorityResult(target, ANALYSIS_OPTIONS_ERRORS);
-      }
-    }
-  }
-
-  @override
-  List<AnalysisError> getErrors(Source source) {
-    if (!_isOptionsSource(source)) {
-      return AnalysisError.NO_ERRORS;
-    }
-    // If analysis is finished, use all the errors.
-    if (analysisCache.getState(source, ANALYSIS_OPTIONS_ERRORS) ==
-        CacheState.VALID) {
-      return analysisCache.getValue(source, ANALYSIS_OPTIONS_ERRORS);
-    }
-    // No partial results.
-    return AnalysisError.NO_ERRORS;
-  }
-
-  @override
-  TargetedResult getNextResult() {
-    // Try to find a priority result to compute.
-    while (priorityResultQueue.isNotEmpty) {
-      TargetedResult result = priorityResultQueue.first;
-      if (!_needsComputing(result.target, result.result)) {
-        priorityResultQueue.remove(result);
-        continue;
-      }
-      return result;
-    }
-    // Try to find a new options file to analyze.
-    while (sourceQueue.isNotEmpty) {
-      Source optionsSource = sourceQueue.first;
-      if (!_needsComputing(optionsSource, ANALYSIS_OPTIONS_ERRORS)) {
-        sourceQueue.remove(optionsSource);
-        continue;
-      }
-      return new TargetedResult(optionsSource, ANALYSIS_OPTIONS_ERRORS);
-    }
-    // No results to compute.
-    return null;
-  }
-
-  @override
-  WorkOrderPriority getNextResultPriority() {
-    if (priorityResultQueue.isNotEmpty) {
-      return WorkOrderPriority.PRIORITY;
-    }
-    if (sourceQueue.isNotEmpty) {
-      return WorkOrderPriority.NORMAL;
-    }
-    return WorkOrderPriority.NONE;
-  }
-
-  @override
-  void onAnalysisOptionsChanged() {
-    // Do nothing.
-  }
-
-  /// Notifies the manager that a result has been invalidated.
-  void onResultInvalidated(InvalidatedResult event) {
-    ResultDescriptor descriptor = event.descriptor;
-    if (descriptor == ANALYSIS_OPTIONS_ERRORS) {
-      sourceQueue.add(event.entry.target);
-    }
-  }
-
-  @override
-  void onSourceFactoryChanged() {
-    // Do nothing.
-  }
-
-  @override
-  void resultsComputed(
-      AnalysisTarget target, Map<ResultDescriptor, dynamic> outputs) {
-    // Update notice.
-    if (_isOptionsSource(target)) {
-      bool shouldSetErrors = false;
-      outputs.forEach((ResultDescriptor descriptor, value) {
-        if (descriptor == ANALYSIS_OPTIONS_ERRORS) {
-          shouldSetErrors = true;
-        }
-      });
-      if (shouldSetErrors) {
-        AnalysisErrorInfo info = context.getErrors(target);
-        context.getNotice(target).setErrors(info.errors, info.lineInfo);
-      }
-    }
-  }
-
-  /// Returns `true` if the given [result] of the given [target] needs
-  /// computing, i.e. it is not in the valid and not in the error state.
-  bool _needsComputing(AnalysisTarget target, ResultDescriptor result) {
-    CacheState state = analysisCache.getState(target, result);
-    return state != CacheState.VALID && state != CacheState.ERROR;
-  }
-
-  /// Return `true` if the given target is an analysis options source.
-  static bool _isOptionsSource(AnalysisTarget target) =>
-      target is Source &&
-      AnalysisEngine.isAnalysisOptionsFileName(target.fullName);
-}
diff --git a/pkg/analyzer/test/src/task/options_test.dart b/pkg/analyzer/test/src/task/options_test.dart
index 8032e06..10a1934 100644
--- a/pkg/analyzer/test/src/task/options_test.dart
+++ b/pkg/analyzer/test/src/task/options_test.dart
@@ -36,9 +36,6 @@
   });
 }
 
-final isGenerateOptionsErrorsTask =
-    new TypeMatcher<GenerateOptionsErrorsTask>();
-
 @reflectiveTest
 class ContextConfigurationTest {
   final AnalysisOptions analysisOptions = AnalysisOptionsImpl();
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart
index dea039b..7e910dc 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/driver.dart
@@ -347,9 +347,8 @@
           File file = resourceProvider.getFile(path);
           String content = file.readAsStringSync();
           LineInfo lineInfo = new LineInfo.fromContent(content);
-          List<AnalysisError> errors =
-              GenerateOptionsErrorsTask.analyzeAnalysisOptions(
-                  file.createSource(), content, analysisDriver.sourceFactory);
+          List<AnalysisError> errors = analyzeAnalysisOptions(
+              file.createSource(), content, analysisDriver.sourceFactory);
           formatter.formatErrors([new AnalysisErrorInfoImpl(errors, lineInfo)]);
           for (AnalysisError error in errors) {
             ErrorSeverity severity = determineProcessedSeverity(