Move IgnoreInfo out of the task model code base

Change-Id: Ib164e66ed96325042c9ab18de6489ab2d1c700ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96263
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
index 653c4b9..7a4b3d0 100644
--- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart
@@ -28,10 +28,10 @@
 import 'package:analyzer/src/generated/resolver.dart';
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/hint/sdk_constraint_verifier.dart';
+import 'package:analyzer/src/ignore_comments/ignore_info.dart';
 import 'package:analyzer/src/lint/linter.dart';
 import 'package:analyzer/src/lint/linter_visitor.dart';
 import 'package:analyzer/src/services/lint.dart';
-import 'package:analyzer/src/task/dart.dart' hide ConstantEvaluationTarget;
 import 'package:analyzer/src/task/strong/checker.dart';
 import 'package:pub_semver/pub_semver.dart';
 
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index d5e0a30..a43094a 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -29,7 +29,6 @@
 import 'package:analyzer/src/generated/resolver.dart';
 import 'package:analyzer/src/generated/sdk.dart' show DartSdk, SdkLibrary;
 import 'package:analyzer/src/generated/source.dart';
-import 'package:analyzer/src/task/dart.dart' hide ConstantEvaluationTarget;
 
 /**
  * A visitor used to traverse an AST structure looking for additional errors and
diff --git a/pkg/analyzer/lib/src/ignore_comments/ignore_info.dart b/pkg/analyzer/lib/src/ignore_comments/ignore_info.dart
new file mode 100644
index 0000000..2596ac9
--- /dev/null
+++ b/pkg/analyzer/lib/src/ignore_comments/ignore_info.dart
@@ -0,0 +1,105 @@
+// 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/source/line_info.dart';
+import 'package:analyzer/src/generated/source.dart';
+
+/// Information about analysis `//ignore:` and `//ignore_for_file` comments
+/// within a source file.
+class IgnoreInfo {
+  ///  Instance shared by all cases without matches.
+  static final IgnoreInfo _EMPTY_INFO = new IgnoreInfo();
+
+  /// A regular expression for matching 'ignore' comments.  Produces matches
+  /// containing 2 groups.  For example:
+  ///
+  ///     * ['//ignore: error_code', 'error_code']
+  ///
+  /// Resulting codes may be in a list ('error_code_1,error_code2').
+  static final RegExp _IGNORE_MATCHER =
+      new RegExp(r'//+[ ]*ignore:(.*)$', multiLine: true);
+
+  /// A regular expression for matching 'ignore_for_file' comments.  Produces
+  /// matches containing 2 groups.  For example:
+  ///
+  ///     * ['//ignore_for_file: error_code', 'error_code']
+  ///
+  /// Resulting codes may be in a list ('error_code_1,error_code2').
+  static final RegExp _IGNORE_FOR_FILE_MATCHER =
+      new RegExp(r'//[ ]*ignore_for_file:(.*)$', multiLine: true);
+
+  final Map<int, List<String>> _ignoreMap = new HashMap<int, List<String>>();
+
+  final Set<String> _ignoreForFileSet = new HashSet<String>();
+
+  /// Whether this info object defines any ignores.
+  bool get hasIgnores => ignores.isNotEmpty || _ignoreForFileSet.isNotEmpty;
+
+  /// Iterable of error codes ignored for the whole file.
+  Iterable<String> get ignoreForFiles => _ignoreForFileSet;
+
+  /// Map of line numbers to associated ignored error codes.
+  Map<int, Iterable<String>> get ignores => _ignoreMap;
+
+  /// Ignore this [errorCode] at [line].
+  void add(int line, String errorCode) {
+    _ignoreMap.putIfAbsent(line, () => new List<String>()).add(errorCode);
+  }
+
+  /// Ignore these [errorCodes] at [line].
+  void addAll(int line, Iterable<String> errorCodes) {
+    _ignoreMap.putIfAbsent(line, () => new List<String>()).addAll(errorCodes);
+  }
+
+  /// Ignore these [errorCodes] in the whole file.
+  void addAllForFile(Iterable<String> errorCodes) {
+    _ignoreForFileSet.addAll(errorCodes);
+  }
+
+  /// Test whether this [errorCode] is ignored at the given [line].
+  bool ignoredAt(String errorCode, int line) =>
+      _ignoreForFileSet.contains(errorCode) ||
+      _ignoreMap[line]?.contains(errorCode) == true;
+
+  /// Calculate ignores for the given [content] with line [info].
+  static IgnoreInfo calculateIgnores(String content, LineInfo info) {
+    Iterable<Match> matches = _IGNORE_MATCHER.allMatches(content);
+    Iterable<Match> fileMatches = _IGNORE_FOR_FILE_MATCHER.allMatches(content);
+    if (matches.isEmpty && fileMatches.isEmpty) {
+      return _EMPTY_INFO;
+    }
+
+    IgnoreInfo ignoreInfo = new IgnoreInfo();
+    for (Match match in matches) {
+      // See _IGNORE_MATCHER for format --- note the possibility of error lists.
+      Iterable<String> codes = match
+          .group(1)
+          .split(',')
+          .map((String code) => code.trim().toLowerCase());
+      CharacterLocation location = info.getLocation(match.start);
+      int lineNumber = location.lineNumber;
+      String beforeMatch = content.substring(
+          info.getOffsetOfLine(lineNumber - 1),
+          info.getOffsetOfLine(lineNumber - 1) + location.columnNumber - 1);
+
+      if (beforeMatch.trim().isEmpty) {
+        // The comment is on its own line, so it refers to the next line.
+        ignoreInfo.addAll(lineNumber + 1, codes);
+      } else {
+        // The comment sits next to code, so it refers to its own line.
+        ignoreInfo.addAll(lineNumber, codes);
+      }
+    }
+    for (Match match in fileMatches) {
+      Iterable<String> codes = match
+          .group(1)
+          .split(',')
+          .map((String code) => code.trim().toLowerCase());
+      ignoreInfo.addAllForFile(codes);
+    }
+    return ignoreInfo;
+  }
+}
diff --git a/pkg/analyzer/lib/src/plugin/engine_plugin.dart b/pkg/analyzer/lib/src/plugin/engine_plugin.dart
index 6f97315..6301049 100644
--- a/pkg/analyzer/lib/src/plugin/engine_plugin.dart
+++ b/pkg/analyzer/lib/src/plugin/engine_plugin.dart
@@ -7,7 +7,6 @@
     show InternalAnalysisContext;
 import 'package:analyzer/src/plugin/task.dart';
 import 'package:analyzer/src/task/api/model.dart';
-import 'package:analyzer/src/task/dart.dart';
 import 'package:analyzer/src/task/dart_work_manager.dart';
 import 'package:analyzer/src/task/options_work_manager.dart';
 import 'package:plugin/plugin.dart';
@@ -137,18 +136,6 @@
   @override
   void registerExtensions(RegisterExtension registerExtension) {
     _registerWorkManagerFactoryExtensions(registerExtension);
-    _registerDartErrorsForSource(registerExtension);
-    _registerDartErrorsForUnit(registerExtension);
-  }
-
-  void _registerDartErrorsForSource(RegisterExtension registerExtension) {
-    registerExtension(DART_ERRORS_FOR_SOURCE_EXTENSION_POINT_ID, PARSE_ERRORS);
-    registerExtension(DART_ERRORS_FOR_SOURCE_EXTENSION_POINT_ID, SCAN_ERRORS);
-  }
-
-  void _registerDartErrorsForUnit(RegisterExtension registerExtension) {
-    registerExtension(
-        DART_ERRORS_FOR_UNIT_EXTENSION_POINT_ID, LIBRARY_UNIT_ERRORS);
   }
 
   void _registerWorkManagerFactoryExtensions(
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index fccf23b..fecfa7a 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -45,6 +45,7 @@
 import 'package:analyzer/src/generated/sdk.dart';
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/generated/utilities_dart.dart';
+import 'package:analyzer/src/ignore_comments/ignore_info.dart';
 import 'package:analyzer/src/plugin/engine_plugin.dart';
 import 'package:analyzer/src/services/lint.dart';
 import 'package:analyzer/src/task/api/dart.dart';
@@ -59,6 +60,7 @@
 
 export 'package:analyzer/src/dart/constant/evaluation.dart'
     show ConstantEvaluationTarget;
+export 'package:analyzer/src/ignore_comments/ignore_info.dart';
 
 /**
  * The [ResultCachingPolicy] for ASTs.
@@ -2986,127 +2988,6 @@
 }
 
 /**
- * Information about analysis `//ignore:` and `//ignore_for_file` comments
- * within a source file.
- */
-class IgnoreInfo {
-  /**
-   *  Instance shared by all cases without matches.
-   */
-  static final IgnoreInfo _EMPTY_INFO = new IgnoreInfo();
-
-  /**
-   * A regular expression for matching 'ignore' comments.  Produces matches
-   * containing 2 groups.  For example:
-   *
-   *     * ['//ignore: error_code', 'error_code']
-   *
-   * Resulting codes may be in a list ('error_code_1,error_code2').
-   */
-  static final RegExp _IGNORE_MATCHER =
-      new RegExp(r'//+[ ]*ignore:(.*)$', multiLine: true);
-
-  /**
-   * A regular expression for matching 'ignore_for_file' comments.  Produces
-   * matches containing 2 groups.  For example:
-   *
-   *     * ['//ignore_for_file: error_code', 'error_code']
-   *
-   * Resulting codes may be in a list ('error_code_1,error_code2').
-   */
-  static final RegExp _IGNORE_FOR_FILE_MATCHER =
-      new RegExp(r'//[ ]*ignore_for_file:(.*)$', multiLine: true);
-
-  final Map<int, List<String>> _ignoreMap = new HashMap<int, List<String>>();
-
-  final Set<String> _ignoreForFileSet = new HashSet<String>();
-
-  /**
-   * Whether this info object defines any ignores.
-   */
-  bool get hasIgnores => ignores.isNotEmpty || _ignoreForFileSet.isNotEmpty;
-
-  /**
-   * Iterable of error codes ignored for the whole file.
-   */
-  Iterable<String> get ignoreForFiles => _ignoreForFileSet;
-
-  /**
-   * Map of line numbers to associated ignored error codes.
-   */
-  Map<int, Iterable<String>> get ignores => _ignoreMap;
-
-  /**
-   * Ignore this [errorCode] at [line].
-   */
-  void add(int line, String errorCode) {
-    _ignoreMap.putIfAbsent(line, () => new List<String>()).add(errorCode);
-  }
-
-  /**
-   * Ignore these [errorCodes] at [line].
-   */
-  void addAll(int line, Iterable<String> errorCodes) {
-    _ignoreMap.putIfAbsent(line, () => new List<String>()).addAll(errorCodes);
-  }
-
-  /**
-   * Ignore these [errorCodes] in the whole file.
-   */
-  void addAllForFile(Iterable<String> errorCodes) {
-    _ignoreForFileSet.addAll(errorCodes);
-  }
-
-  /**
-   * Test whether this [errorCode] is ignored at the given [line].
-   */
-  bool ignoredAt(String errorCode, int line) =>
-      _ignoreForFileSet.contains(errorCode) ||
-      _ignoreMap[line]?.contains(errorCode) == true;
-
-  /**
-   * Calculate ignores for the given [content] with line [info].
-   */
-  static IgnoreInfo calculateIgnores(String content, LineInfo info) {
-    Iterable<Match> matches = _IGNORE_MATCHER.allMatches(content);
-    Iterable<Match> fileMatches = _IGNORE_FOR_FILE_MATCHER.allMatches(content);
-    if (matches.isEmpty && fileMatches.isEmpty) {
-      return _EMPTY_INFO;
-    }
-
-    IgnoreInfo ignoreInfo = new IgnoreInfo();
-    for (Match match in matches) {
-      // See _IGNORE_MATCHER for format --- note the possibility of error lists.
-      Iterable<String> codes = match
-          .group(1)
-          .split(',')
-          .map((String code) => code.trim().toLowerCase());
-      CharacterLocation location = info.getLocation(match.start);
-      int lineNumber = location.lineNumber;
-      String beforeMatch = content.substring(
-          info.getOffsetOfLine(lineNumber - 1),
-          info.getOffsetOfLine(lineNumber - 1) + location.columnNumber - 1);
-
-      if (beforeMatch.trim().isEmpty) {
-        // The comment is on its own line, so it refers to the next line.
-        ignoreInfo.addAll(lineNumber + 1, codes);
-      } else {
-        // The comment sits next to code, so it refers to its own line.
-        ignoreInfo.addAll(lineNumber, codes);
-      }
-    }
-    for (Match match in fileMatches) {
-      Iterable<String> codes = match
-          .group(1)
-          .split(',')
-          .map((String code) => code.trim().toLowerCase());
-      ignoreInfo.addAllForFile(codes);
-    }
-    return ignoreInfo;
-  }
-}
-
-/**
  * A task that ensures that all of the inferable instance members in a
  * compilation unit have had their type inferred.
  */