Skip to content

Commit

Permalink
Migrate the last file in analyzer_cli
Browse files Browse the repository at this point in the history
Change-Id: If0cacfab048174128be6eb0666893465929efaf9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391200
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
bwilkerson authored and Commit Queue committed Oct 21, 2024
1 parent 1c86ca0 commit a92ef52
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions pkg/analyzer_cli/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/analyzer.dart
lib/src/analyzer_impl.dart
lib/src/ansi.dart
lib/src/batch_mode.dart
lib/src/driver.dart
Expand Down
52 changes: 29 additions & 23 deletions pkg/analyzer_cli/lib/src/analyzer_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'dart:io';

import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
Expand Down Expand Up @@ -50,15 +50,15 @@ class AnalyzerImpl {
this.options, this.stats, this.startTime);

void addCompilationUnitSource(
CompilationUnitElement unit, Set<CompilationUnitElement> units) {
LibraryFragment unit, Set<LibraryFragment> units) {
if (!units.add(unit)) {
return;
}
files.add(unit.source.fullName);
}

void addLibrarySources(LibraryElement library, Set<LibraryElement> libraries,
Set<CompilationUnitElement> units) {
void addLibrarySources(LibraryElement2 library,
Set<LibraryElement2> libraries, Set<LibraryFragment> units) {
if (!libraries.add(library)) {
return;
}
Expand All @@ -67,18 +67,24 @@ class AnalyzerImpl {
return;
}
// Add compilation units.
for (final unitElement in library.units) {
addCompilationUnitSource(unitElement, units);
}
// Add imported libraries.
var importedLibraries = library.importedLibraries;
for (var child in importedLibraries) {
addLibrarySources(child, libraries, units);
}
// Add exported libraries.
var exportedLibraries = library.exportedLibraries;
for (var child in exportedLibraries) {
addLibrarySources(child, libraries, units);
for (final fragment in library.fragments) {
addCompilationUnitSource(fragment, units);
// Add imported libraries.
var importedLibraries = fragment.libraryImports2;
for (var child in importedLibraries) {
var importedLibrary = child.importedLibrary2;
if (importedLibrary != null) {
addLibrarySources(importedLibrary, libraries, units);
}
}
// Add exported libraries.
var exportedLibraries = fragment.libraryExports2;
for (var child in exportedLibraries) {
var exportedLibrary = child.exportedLibrary2;
if (exportedLibrary != null) {
addLibrarySources(exportedLibrary, libraries, units);
}
}
}
}

Expand Down Expand Up @@ -118,9 +124,9 @@ class AnalyzerImpl {
}

/// Fills [files].
void prepareSources(LibraryElement library) {
var units = <CompilationUnitElement>{};
var libraries = <LibraryElement>{};
void prepareSources(LibraryElement2 library) {
var units = <LibraryFragment>{};
var libraries = <LibraryElement2>{};
addLibrarySources(library, libraries, units);
}

Expand Down Expand Up @@ -163,8 +169,8 @@ class AnalyzerImpl {
determineProcessedSeverity(error, options, analysisOptions);

/// Returns true if we want to report diagnostics for this library.
bool _isAnalyzedLibrary(LibraryElement library) {
var source = library.source;
bool _isAnalyzedLibrary(LibraryElement2 library) {
var source = library.firstFragment.source;
if (source.uri.isScheme('dart')) {
return false;
} else if (source.uri.isScheme('package')) {
Expand Down Expand Up @@ -197,12 +203,12 @@ class AnalyzerImpl {
outSink.writeln('total-cold:$totalTime');
}

Future<LibraryElement> _resolveLibrary() async {
Future<LibraryElement2> _resolveLibrary() async {
var libraryPath = libraryFile.path;
analysisDriver.priorityFiles = [libraryPath];
var elementResult =
await analysisDriver.getUnitElement(libraryPath) as UnitElementResult;
return elementResult.element.library;
return elementResult.fragment.element;
}

/// Return `true` if the given [pathName] is in the Pub cache.
Expand Down

0 comments on commit a92ef52

Please sign in to comment.