55import 'dart:io' ;
66
77import 'package:analyzer/dart/analysis/results.dart' ;
8- import 'package:analyzer/dart/element/element .dart' ;
8+ import 'package:analyzer/dart/element/element2 .dart' ;
99import 'package:analyzer/error/error.dart' ;
1010import 'package:analyzer/instrumentation/instrumentation.dart' ;
1111import 'package:analyzer/src/dart/analysis/driver.dart' ;
@@ -50,15 +50,15 @@ class AnalyzerImpl {
5050 this .options, this .stats, this .startTime);
5151
5252 void addCompilationUnitSource (
53- CompilationUnitElement unit, Set <CompilationUnitElement > units) {
53+ LibraryFragment unit, Set <LibraryFragment > units) {
5454 if (! units.add (unit)) {
5555 return ;
5656 }
5757 files.add (unit.source.fullName);
5858 }
5959
60- void addLibrarySources (LibraryElement library, Set < LibraryElement > libraries ,
61- Set <CompilationUnitElement > units) {
60+ void addLibrarySources (LibraryElement2 library,
61+ Set <LibraryElement2 > libraries, Set < LibraryFragment > units) {
6262 if (! libraries.add (library)) {
6363 return ;
6464 }
@@ -67,18 +67,24 @@ class AnalyzerImpl {
6767 return ;
6868 }
6969 // Add compilation units.
70- for (final unitElement in library.units) {
71- addCompilationUnitSource (unitElement, units);
72- }
73- // Add imported libraries.
74- var importedLibraries = library.importedLibraries;
75- for (var child in importedLibraries) {
76- addLibrarySources (child, libraries, units);
77- }
78- // Add exported libraries.
79- var exportedLibraries = library.exportedLibraries;
80- for (var child in exportedLibraries) {
81- addLibrarySources (child, libraries, units);
70+ for (final fragment in library.fragments) {
71+ addCompilationUnitSource (fragment, units);
72+ // Add imported libraries.
73+ var importedLibraries = fragment.libraryImports2;
74+ for (var child in importedLibraries) {
75+ var importedLibrary = child.importedLibrary2;
76+ if (importedLibrary != null ) {
77+ addLibrarySources (importedLibrary, libraries, units);
78+ }
79+ }
80+ // Add exported libraries.
81+ var exportedLibraries = fragment.libraryExports2;
82+ for (var child in exportedLibraries) {
83+ var exportedLibrary = child.exportedLibrary2;
84+ if (exportedLibrary != null ) {
85+ addLibrarySources (exportedLibrary, libraries, units);
86+ }
87+ }
8288 }
8389 }
8490
@@ -118,9 +124,9 @@ class AnalyzerImpl {
118124 }
119125
120126 /// Fills [files] .
121- void prepareSources (LibraryElement library) {
122- var units = < CompilationUnitElement > {};
123- var libraries = < LibraryElement > {};
127+ void prepareSources (LibraryElement2 library) {
128+ var units = < LibraryFragment > {};
129+ var libraries = < LibraryElement2 > {};
124130 addLibrarySources (library, libraries, units);
125131 }
126132
@@ -163,8 +169,8 @@ class AnalyzerImpl {
163169 determineProcessedSeverity (error, options, analysisOptions);
164170
165171 /// Returns true if we want to report diagnostics for this library.
166- bool _isAnalyzedLibrary (LibraryElement library) {
167- var source = library.source;
172+ bool _isAnalyzedLibrary (LibraryElement2 library) {
173+ var source = library.firstFragment. source;
168174 if (source.uri.isScheme ('dart' )) {
169175 return false ;
170176 } else if (source.uri.isScheme ('package' )) {
@@ -197,12 +203,12 @@ class AnalyzerImpl {
197203 outSink.writeln ('total-cold:$totalTime ' );
198204 }
199205
200- Future <LibraryElement > _resolveLibrary () async {
206+ Future <LibraryElement2 > _resolveLibrary () async {
201207 var libraryPath = libraryFile.path;
202208 analysisDriver.priorityFiles = [libraryPath];
203209 var elementResult =
204210 await analysisDriver.getUnitElement (libraryPath) as UnitElementResult ;
205- return elementResult.element.library ;
211+ return elementResult.fragment.element ;
206212 }
207213
208214 /// Return `true` if the given [pathName] is in the Pub cache.
0 commit comments