remove `DartProject`


See: https://github.com/dart-lang/linter/issues/3395

Change-Id: I6e4213983abae2b48e4bbbbbc766784e1756b0ed
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245240
Commit-Queue: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/lint/analysis.dart b/pkg/analyzer/lib/src/lint/analysis.dart
index b51a93a..e11bd6e 100644
--- a/pkg/analyzer/lib/src/lint/analysis.dart
+++ b/pkg/analyzer/lib/src/lint/analysis.dart
@@ -5,7 +5,6 @@
 import 'dart:io' as io;
 
 import 'package:analyzer/dart/analysis/results.dart';
-import 'package:analyzer/dart/analysis/session.dart';
 import 'package:analyzer/file_system/physical_file_system.dart';
 import 'package:analyzer/instrumentation/instrumentation.dart';
 import 'package:analyzer/src/analysis_options/analysis_options_provider.dart';
@@ -15,8 +14,6 @@
 import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/lint/io.dart';
 import 'package:analyzer/src/lint/linter.dart';
-import 'package:analyzer/src/lint/project.dart';
-import 'package:analyzer/src/lint/registry.dart';
 import 'package:analyzer/src/task/options.dart';
 import 'package:yaml/yaml.dart';
 
@@ -124,18 +121,9 @@
       },
     );
 
-    AnalysisSession? projectAnalysisSession;
     for (io.File file in files) {
       var path = _absoluteNormalizedPath(file.path);
       _filesAnalyzed.add(path);
-      var analysisContext = contextCollection.contextFor(path);
-      var analysisSession = analysisContext.currentSession;
-      projectAnalysisSession = analysisSession;
-    }
-
-    if (projectAnalysisSession != null) {
-      // ignore: deprecated_member_use_from_same_package
-      await _visitProject(projectAnalysisSession);
     }
 
     var result = <AnalysisErrorInfo>[];
@@ -161,24 +149,6 @@
     path = pathContext.normalize(path);
     return path;
   }
-
-  @Deprecated('DartProject is deprecated. This is slated for removal')
-  Future<void> _visitProject(AnalysisSession projectAnalysisSession) async {
-    Future<DartProject> createProject() async {
-      return await DartProject.create(
-        projectAnalysisSession,
-        _filesAnalyzed.toList(),
-      );
-    }
-
-    DartProject? project;
-    for (var lint in Registry.ruleRegistry) {
-      if (lint is ProjectVisitor) {
-        project ??= await createProject();
-        (lint as ProjectVisitor).visit(project);
-      }
-    }
-  }
 }
 
 /// Prints logging information comments to the [outSink] and error messages to
diff --git a/pkg/analyzer/lib/src/lint/linter.dart b/pkg/analyzer/lib/src/lint/linter.dart
index bbbb005..cab3bd7 100644
--- a/pkg/analyzer/lib/src/lint/linter.dart
+++ b/pkg/analyzer/lib/src/lint/linter.dart
@@ -35,7 +35,6 @@
 import 'package:analyzer/src/lint/config.dart';
 import 'package:analyzer/src/lint/io.dart';
 import 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
-import 'package:analyzer/src/lint/project.dart';
 import 'package:analyzer/src/lint/pub.dart';
 import 'package:analyzer/src/lint/registry.dart';
 import 'package:analyzer/src/services/lint.dart' show Linter;
@@ -627,11 +626,6 @@
     return name.compareTo(other.name);
   }
 
-  /// Return a visitor to be passed to provide access to Dart project context
-  /// and to perform project-level analyses.
-  @Deprecated('Use LinterContext instead')
-  ProjectVisitor? getProjectVisitor() => null;
-
   /// Return a visitor to be passed to pubspecs to perform lint
   /// analysis.
   /// Lint errors are reported via this [Linter]'s error [reporter].
diff --git a/pkg/analyzer/lib/src/lint/project.dart b/pkg/analyzer/lib/src/lint/project.dart
deleted file mode 100644
index 17f95be..0000000
--- a/pkg/analyzer/lib/src/lint/project.dart
+++ /dev/null
@@ -1,154 +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:io';
-
-import 'package:analyzer/dart/analysis/results.dart';
-import 'package:analyzer/dart/analysis/session.dart';
-import 'package:analyzer/dart/element/element.dart';
-import 'package:analyzer/src/dart/resolver/scope.dart';
-import 'package:analyzer/src/lint/io.dart';
-import 'package:analyzer/src/lint/pub.dart';
-import 'package:collection/collection.dart';
-import 'package:path/path.dart' as p;
-
-Pubspec? _findAndParsePubspec(Directory root) {
-  if (root.existsSync()) {
-    var pubspec = root
-        .listSync(followLinks: false)
-        .whereType<File>()
-        .firstWhereOrNull((f) => isPubspecFile(f));
-    if (pubspec != null) {
-      return Pubspec.parse(pubspec.readAsStringSync(),
-          sourceUrl: p.toUri(pubspec.path));
-    }
-  }
-  return null;
-}
-
-/// A semantic representation of a Dart project.
-///
-/// Projects provide a semantic model of a Dart project based on the
-/// [pub package layout conventions](https://dart.dev/tools/pub/package-layout).
-/// This model allows clients to traverse project contents in a convenient and
-/// standardized way, access global information (such as whether elements are
-/// in the "public API") and resources that have special meanings in the
-/// context of pub package layout conventions.
-@Deprecated('Use LinterContext instead')
-class DartProject {
-  late final _ApiModel _apiModel;
-  String? _name;
-  Pubspec? _pubspec;
-
-  /// Project root.
-  final Directory root;
-
-  /// Create a Dart project for the corresponding [analysisSession] and [files].
-  /// If a [dir] is unspecified the current working directory will be
-  /// used.
-  ///
-  /// Note: clients should call [create] which performs API model initialization.
-  DartProject._(AnalysisSession analysisSession, List<String> files,
-      {Directory? dir})
-      : root = dir ?? Directory.current {
-    _pubspec = _findAndParsePubspec(root);
-    _apiModel = _ApiModel(analysisSession, files, root);
-  }
-
-  /// The project's name.
-  ///
-  /// Project names correspond to the package name as specified in the project's
-  /// [pubspec]. The pubspec is found relative to the project [root].  If no
-  /// pubspec can be found, the name defaults to the project root basename.
-  String get name => _name ??= _calculateName();
-
-  /// The project's pubspec.
-  Pubspec? get pubspec => _pubspec;
-
-  /// Returns `true` if the given element is part of this project's public API.
-  ///
-  /// Public API elements are defined as all elements that are in the packages's
-  /// `lib` directory, *less* those in `lib/src` (which are treated as private
-  /// *implementation files*), plus elements having been explicitly exported
-  /// via an `export` directive.
-  bool isApi(Element element) => _apiModel.contains(element);
-
-  String _calculateName() {
-    final pubspec = this.pubspec;
-    if (pubspec != null) {
-      var nameEntry = pubspec.name;
-      if (nameEntry != null) {
-        return nameEntry.value.text!;
-      }
-    }
-    return p.basename(root.path);
-  }
-
-  /// Create an initialized Dart project for the corresponding [analysisSession]
-  /// and [files].
-  /// If a [dir] is unspecified the current working directory will be
-  /// used.
-  static Future<DartProject> create(
-      AnalysisSession analysisSession, List<String> files,
-      {Directory? dir}) async {
-    DartProject project = DartProject._(analysisSession, files, dir: dir);
-    await project._apiModel._calculate();
-    return project;
-  }
-}
-
-/// An object that can be used to visit Dart project structure.
-@Deprecated('Use LinterContext instead')
-abstract class ProjectVisitor<T> {
-  T? visit(DartProject project) => null;
-}
-
-/// Captures the project's API as defined by pub package layout standards.
-class _ApiModel {
-  final AnalysisSession analysisSession;
-  final List<String> files;
-  final Directory root;
-  final Set<Element> elements = {};
-
-  _ApiModel(this.analysisSession, this.files, this.root) {
-    _calculate();
-  }
-
-  /// Return `true` if this element is part of the public API for this package.
-  bool contains(Element? element) {
-    while (element != null) {
-      if (!element.isPrivate && elements.contains(element)) {
-        return true;
-      }
-      element = element.enclosingElement;
-    }
-    return false;
-  }
-
-  Future<void> _calculate() async {
-    if (files.isEmpty) {
-      return;
-    }
-
-    String libDir = '${root.path}/lib';
-    String libSrcDir = '$libDir/src';
-
-    for (var file in files) {
-      if (file.startsWith(libDir) && !file.startsWith(libSrcDir)) {
-        var result = await analysisSession.getResolvedUnit(file);
-        if (result is ResolvedUnitResult) {
-          LibraryElement library = result.libraryElement;
-
-          NamespaceBuilder namespaceBuilder = NamespaceBuilder();
-          Namespace exports =
-              namespaceBuilder.createExportNamespaceForLibrary(library);
-          Namespace public =
-              namespaceBuilder.createPublicNamespaceForLibrary(library);
-          elements.addAll(exports.definedNames.values);
-          elements.addAll(public.definedNames.values);
-        }
-      }
-    }
-  }
-}
diff --git a/pkg/analyzer/test/src/lint/project_test.dart b/pkg/analyzer/test/src/lint/project_test.dart
deleted file mode 100644
index 8b6d01a..0000000
--- a/pkg/analyzer/test/src/lint/project_test.dart
+++ /dev/null
@@ -1,68 +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:io';
-
-import 'package:analyzer/dart/analysis/session.dart';
-import 'package:analyzer/src/lint/project.dart';
-import 'package:test/test.dart';
-
-main() {
-//  defineTests();
-}
-
-defineTests() {
-  group('project', () {
-    group('basic', () {
-      // TODO(brianwilkerson) These tests fail on the bots because the cwd is
-      // not the same there as when we run tests locally.
-      group('cwd', () async {
-        // ignore: deprecated_member_use_from_same_package
-        var project = await DartProject.create(_AnalysisSessionMock(), []);
-        test('name', () {
-          expect(project.name, 'analyzer');
-        });
-        test('spec', () {
-          expect(project.pubspec, isNotNull);
-        });
-        test('root', () {
-          expect(project.root.path, Directory.current.path);
-        });
-      });
-      // TODO(brianwilkerson) Rewrite these to use a memory resource provider.
-//      group('p1', () {
-//        var project =
-//            new DartProject(null, null, dir: new Directory('test/_data/p1'));
-//        test('name', () {
-//          expect(project.name, 'p1');
-//        });
-//        test('spec', () {
-//          expect(project.pubspec, isNotNull);
-//          expect(project.pubspec.name.value.text, 'p1');
-//        });
-//        test('root', () {
-//          expect(project.root.path, 'test/_data/p1');
-//        });
-//      });
-//      group('no pubspec', () {
-//        var project = new DartProject(null, null,
-//            dir: new Directory('test/_data/p1/src'));
-//        test('name', () {
-//          expect(project.name, 'src');
-//        });
-//        test('spec', () {
-//          expect(project.pubspec, isNull);
-//        });
-//        test('root', () {
-//          expect(project.root.path, 'test/_data/p1/src');
-//        });
-//      });
-    });
-  });
-}
-
-class _AnalysisSessionMock implements AnalysisSession {
-  @override
-  noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
-}
diff --git a/pkg/analyzer/test/src/lint/test_all.dart b/pkg/analyzer/test/src/lint/test_all.dart
index 6b1afdc..801f080 100644
--- a/pkg/analyzer/test/src/lint/test_all.dart
+++ b/pkg/analyzer/test/src/lint/test_all.dart
@@ -8,7 +8,6 @@
 import 'io_test.dart' as io;
 import 'lint_rule_test.dart' as lint_rule;
 import 'linter/test_all.dart' as linter;
-import 'project_test.dart' as project;
 import 'pub_test.dart' as pub;
 
 main() {
@@ -17,7 +16,6 @@
     io.main();
     lint_rule.main();
     linter.main();
-    project.main();
     pub.main();
   }, name: 'lint');
 }