5
5
import 'package:analyzer/dart/analysis/results.dart' ;
6
6
import 'package:analyzer/dart/ast/ast.dart' ;
7
7
import 'package:analyzer/dart/element/element.dart' ;
8
+ import 'package:analyzer/dart/element/type_system.dart' ;
8
9
import 'package:analyzer/dart/element/visitor.dart' ;
9
10
import 'package:analyzer/source/line_info.dart' ;
10
11
import 'package:analyzer/src/dart/analysis/driver.dart' ;
@@ -77,11 +78,11 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
77
78
// Initialize the list of elements defined in this library and
78
79
// exported via its export directives.
79
80
Set <Element > exportedAndLocalElements =
80
- _libraryElement .exportNamespace.definedNames.values.toSet ();
81
+ element .exportNamespace.definedNames.values.toSet ();
81
82
// TODO(jcollins-g): Consider switch to [_libraryElement.topLevelElements].
82
83
exportedAndLocalElements
83
- .addAll (getDefinedElements (_libraryElement .definingCompilationUnit));
84
- for (CompilationUnitElement cu in _libraryElement .parts) {
84
+ .addAll (getDefinedElements (element .definingCompilationUnit));
85
+ for (CompilationUnitElement cu in element .parts) {
85
86
exportedAndLocalElements.addAll (getDefinedElements (cu));
86
87
}
87
88
_exportedAndLocalElements = exportedAndLocalElements.toList ();
@@ -105,7 +106,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
105
106
106
107
List <String > _allOriginalModelElementNames;
107
108
108
- bool get isInSdk => _libraryElement .isInSdk;
109
+ bool get isInSdk => element .isInSdk;
109
110
110
111
final Package _package;
111
112
@@ -160,11 +161,14 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
160
161
161
162
@override
162
163
CompilationUnitElement get compilationUnitElement =>
163
- ( element as LibraryElement ) .definingCompilationUnit;
164
+ element.definingCompilationUnit;
164
165
165
166
@override
166
167
Iterable <Class > get classes => allClasses.where ((c) => ! c.isErrorOrException);
167
168
169
+ @override
170
+ LibraryElement get element => super .element;
171
+
168
172
List <Extension > _extensions;
169
173
170
174
@override
@@ -240,10 +244,8 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
240
244
if (_importedExportedLibraries == null ) {
241
245
_importedExportedLibraries = Set ();
242
246
Set <LibraryElement > importedExportedLibraryElements = Set ();
243
- importedExportedLibraryElements
244
- .addAll ((element as LibraryElement ).importedLibraries);
245
- importedExportedLibraryElements
246
- .addAll ((element as LibraryElement ).exportedLibraries);
247
+ importedExportedLibraryElements.addAll (element.importedLibraries);
248
+ importedExportedLibraryElements.addAll (element.exportedLibraries);
247
249
for (LibraryElement l in importedExportedLibraryElements) {
248
250
Library lib = ModelElement .from (l, library, packageGraph);
249
251
_importedExportedLibraries.add (lib);
@@ -260,7 +262,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
260
262
if (_prefixToLibrary == null ) {
261
263
_prefixToLibrary = {};
262
264
// It is possible to have overlapping prefixes.
263
- for (ImportElement i in ( element as LibraryElement ) .imports) {
265
+ for (ImportElement i in element.imports) {
264
266
// Ignore invalid imports.
265
267
if (i.prefix? .name != null && i.importedLibrary != null ) {
266
268
_prefixToLibrary.putIfAbsent (i.prefix? .name, () => Set ());
@@ -401,8 +403,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
401
403
402
404
InheritanceManager3 get inheritanceManager {
403
405
if (_inheritanceManager == null ) {
404
- var typeSystem = element.context.typeSystem;
405
- _inheritanceManager = InheritanceManager3 (typeSystem);
406
+ _inheritanceManager = InheritanceManager3 ();
406
407
}
407
408
return _inheritanceManager;
408
409
}
@@ -479,6 +480,8 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
479
480
return _typedefs;
480
481
}
481
482
483
+ TypeSystem get typeSystem => element.typeSystem;
484
+
482
485
List <Class > _classes;
483
486
484
487
List <Class > get allClasses {
@@ -493,8 +496,6 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
493
496
return _classes;
494
497
}
495
498
496
- LibraryElement get _libraryElement => (element as LibraryElement );
497
-
498
499
Class getClassByName (String name) {
499
500
return allClasses.firstWhere ((it) => it.name == name, orElse: () => null );
500
501
}
0 commit comments