2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // ignore_for_file: analyzer_use_new_elements
6
-
7
5
import 'dart:collection' ;
8
6
9
7
import 'package:analyzer/dart/analysis/analysis_context.dart' ;
10
- import 'package:analyzer/dart/element/element.dart' ;
11
8
import 'package:analyzer/dart/element/element2.dart' ;
12
9
import 'package:analyzer/file_system/file_system.dart' ;
13
10
import 'package:analyzer/source/source.dart' ;
@@ -20,8 +17,6 @@ import 'package:analyzer/src/dart/element/inheritance_manager3.dart'
20
17
import 'package:analyzer/src/generated/sdk.dart' show DartSdk, SdkLibrary;
21
18
// ignore: implementation_imports
22
19
import 'package:analyzer/src/generated/timestamped_data.dart' ;
23
- // ignore: implementation_imports
24
- import 'package:analyzer/src/utilities/extensions/element.dart' ;
25
20
import 'package:collection/collection.dart' ;
26
21
import 'package:dartdoc/src/dartdoc_options.dart' ;
27
22
import 'package:dartdoc/src/failure.dart' ;
@@ -112,15 +107,15 @@ class PackageGraph with CommentReferable, Nameable {
112
107
}
113
108
var package = Package .fromPackageMeta (packageMeta, this );
114
109
var library = Library .fromLibraryResult (resolvedLibrary, this , package);
115
- if (_shouldIncludeLibrary (resolvedLibrary.element )) {
110
+ if (_shouldIncludeLibrary (resolvedLibrary.element2 )) {
116
111
package.libraries.add (library);
117
112
}
118
113
_allLibraries[libraryElement2.firstFragment.source.fullName] = library;
119
114
}
120
115
121
116
/// Whether [libraryElement] should be included in the libraries-to-document.
122
- bool _shouldIncludeLibrary (LibraryElement libraryElement) =>
123
- config.include.isEmpty || config.include.contains (libraryElement.name );
117
+ bool _shouldIncludeLibrary (LibraryElement2 libraryElement) =>
118
+ config.include.isEmpty || config.include.contains (libraryElement.name3 );
124
119
125
120
/// Call after all libraries are added.
126
121
Future <void > initializePackageGraph () async {
@@ -206,7 +201,7 @@ class PackageGraph with CommentReferable, Nameable {
206
201
207
202
// Many ModelElements have the same ModelNode; don't build/cache this data
208
203
// more than once for them.
209
- final Map <Element , ModelNode > _modelNodes = {};
204
+ final Map <Element2 , ModelNode > _modelNodes = {};
210
205
211
206
/// The Object class declared in the Dart SDK's 'dart:core' library.
212
207
late InheritingContainer objectClass;
@@ -227,7 +222,7 @@ class PackageGraph with CommentReferable, Nameable {
227
222
// is no harm in grabbing ModelNode for each.
228
223
var commentData = directive.documentationComment? .data;
229
224
_modelNodes.putIfAbsent (
230
- resolvedLibrary.element ,
225
+ resolvedLibrary.element2 ,
231
226
() => ModelNode (
232
227
directive,
233
228
resolvedLibrary.element2,
@@ -244,7 +239,7 @@ class PackageGraph with CommentReferable, Nameable {
244
239
_populateModelNodeFor (member);
245
240
}
246
241
case EnumDeclaration ():
247
- if (declaration.declaredElement ? .isPublic ?? false ) {
242
+ if (declaration.declaredFragment ? .element .isPublic ?? false ) {
248
243
for (var constant in declaration.constants) {
249
244
_populateModelNodeFor (constant);
250
245
}
@@ -257,13 +252,13 @@ class PackageGraph with CommentReferable, Nameable {
257
252
_populateModelNodeFor (member);
258
253
}
259
254
case ExtensionDeclaration ():
260
- if (declaration.declaredElement ? .isPublic ?? false ) {
255
+ if (declaration.declaredFragment ? .element .isPublic ?? false ) {
261
256
for (var member in declaration.members) {
262
257
_populateModelNodeFor (member);
263
258
}
264
259
}
265
260
case ExtensionTypeDeclaration ():
266
- if (declaration.declaredElement ? .isPublic ?? false ) {
261
+ if (declaration.declaredFragment ? .element .isPublic ?? false ) {
267
262
for (var member in declaration.members) {
268
263
_populateModelNodeFor (member);
269
264
}
@@ -282,7 +277,7 @@ class PackageGraph with CommentReferable, Nameable {
282
277
throw StateError ("Expected '$declaration ' to declare an element" );
283
278
}
284
279
_modelNodes.putIfAbsent (
285
- element.asElement ! ,
280
+ element,
286
281
() => ModelNode (
287
282
declaration,
288
283
element,
@@ -309,10 +304,7 @@ class PackageGraph with CommentReferable, Nameable {
309
304
addModelNode (declaration);
310
305
}
311
306
312
- ModelNode ? getModelNodeFor (Element element) => _modelNodes[element];
313
-
314
- ModelNode ? getModelNodeFor2 (Element2 element2) =>
315
- _modelNodes[element2.asElement];
307
+ ModelNode ? getModelNodeFor (Element2 element2) => _modelNodes[element2];
316
308
317
309
/// It is safe to cache values derived from the [_implementers] table if this
318
310
/// is true.
@@ -399,14 +391,14 @@ class PackageGraph with CommentReferable, Nameable {
399
391
late final PackageWarningCounter packageWarningCounter =
400
392
PackageWarningCounter (this );
401
393
402
- final Set <(Element ? element, PackageWarning packageWarning, String ? message)>
394
+ final Set <(Element2 ? element, PackageWarning packageWarning, String ? message)>
403
395
_warnAlreadySeen = {};
404
396
405
397
void warnOnElement (Warnable ? warnable, PackageWarning kind,
406
398
{String ? message,
407
399
Iterable <Locatable > referredFrom = const [],
408
400
Iterable <String > extendedDebug = const []}) {
409
- var newEntry = (warnable? .element , kind, message);
401
+ var newEntry = (warnable? .element2 , kind, message);
410
402
if (_warnAlreadySeen.contains (newEntry)) {
411
403
return ;
412
404
}
@@ -515,7 +507,7 @@ class PackageGraph with CommentReferable, Nameable {
515
507
Iterable <Package > get _documentedPackages =>
516
508
packages.where ((p) => p.documentedWhere != DocumentLocation .missing);
517
509
518
- /// A mapping from a [LibraryElement ] to all of the [Library] s that export it.
510
+ /// A mapping from a [LibraryElement2 ] to all of the [Library] s that export it.
519
511
Map <LibraryElement2 , Set <Library >> _libraryExports = {};
520
512
521
513
/// Marks [publicLibrary] as a library that exports [libraryElement] and all
@@ -550,7 +542,7 @@ class PackageGraph with CommentReferable, Nameable {
550
542
551
543
int _previousSizeOfAllLibraries = 0 ;
552
544
553
- /// A mapping from a [LibraryElement ] to all of the [Library] s that export it,
545
+ /// A mapping from a [LibraryElement2 ] to all of the [Library] s that export it,
554
546
/// which is created if it is not yet populated.
555
547
Map <LibraryElement2 , Set <Library >> get libraryExports {
556
548
// The map must be reset if we're still in the middle of adding libraries
@@ -569,7 +561,7 @@ class PackageGraph with CommentReferable, Nameable {
569
561
return _libraryExports;
570
562
}
571
563
572
- /// A mapping from a [LibraryElement ] to all of the [Library] s that export it,
564
+ /// A mapping from a [LibraryElement2 ] to all of the [Library] s that export it,
573
565
/// which is created if it is not yet populated.
574
566
Map <LibraryElement2 , Set <Library >> get libraryExports2 {
575
567
// The map must be reset if we're still in the middle of adding libraries
@@ -639,7 +631,7 @@ class PackageGraph with CommentReferable, Nameable {
639
631
var list = _implementers.putIfAbsent (implemented, () => []);
640
632
// TODO(srawlins): This would be more efficient if we created a
641
633
// SplayTreeSet keyed off of `.element`.
642
- if (! list.any ((l) => l.element == implementer.element )) {
634
+ if (! list.any ((l) => l.element2 == implementer.element2 )) {
643
635
list.add (implementer);
644
636
}
645
637
}
@@ -708,8 +700,8 @@ class PackageGraph with CommentReferable, Nameable {
708
700
'Object' ;
709
701
710
702
bool isAnnotationVisible (Class class_) =>
711
- class_.element.name == 'pragma' &&
712
- class_.element.library.name == 'dart.core' ;
703
+ class_.element2.name3 == 'pragma' &&
704
+ class_.element2.library2.name3 == 'dart.core' ;
713
705
714
706
@override
715
707
String toString () {
@@ -741,7 +733,7 @@ class PackageGraph with CommentReferable, Nameable {
741
733
{Container ? preferredClass}) {
742
734
assert (allLibrariesAdded);
743
735
if (modelElement == null ) return null ;
744
- var element = modelElement.element ;
736
+ var element = modelElement.element2 ;
745
737
if (preferredClass != null ) {
746
738
var canonicalClass =
747
739
findCanonicalModelElementFor (preferredClass) as Container ? ;
@@ -754,39 +746,43 @@ class PackageGraph with CommentReferable, Nameable {
754
746
library = preferredClass.canonicalLibrary;
755
747
}
756
748
// For elements defined in extensions, they are canonical.
757
- var enclosingElement = element.enclosingElement3 ;
758
- if (enclosingElement is ExtensionElement ) {
759
- library ?? = getModelForElement (enclosingElement.library ) as Library ? ;
749
+ var enclosingElement = element.enclosingElement2 ;
750
+ if (enclosingElement is ExtensionElement2 ) {
751
+ library ?? = getModelForElement2 (enclosingElement.library2 ) as Library ? ;
760
752
// TODO(keertip): Find a better way to exclude members of extensions
761
753
// when libraries are specified using the "--include" flag.
762
754
if (library != null && library.isDocumented) {
763
- return getModelFor (element, library,
755
+ return getModelFor2 (element, library,
764
756
enclosingContainer: preferredClass);
765
757
}
766
758
}
767
759
// TODO(jcollins-g): The data structures should be changed to eliminate
768
760
// guesswork with member elements.
769
- var declaration = element.declaration ;
761
+ var declaration = element.baseElement ;
770
762
ModelElement ? canonicalModelElement;
771
- if (declaration != null &&
772
- (element is ClassMemberElement || element is PropertyAccessorElement )) {
773
- var declarationModelElement = getModelForElement (declaration);
774
- element = declarationModelElement.element;
763
+ if (element is ConstructorElement2 ||
764
+ element is MethodElement2 ||
765
+ element is FieldElement2 ||
766
+ element is PropertyAccessorElement2 ) {
767
+ var declarationModelElement = getModelForElement2 (declaration);
768
+ element = declarationModelElement.element2;
775
769
canonicalModelElement = _findCanonicalModelElementForAmbiguous (
776
770
declarationModelElement, library,
777
771
preferredClass: preferredClass as InheritingContainer ? );
778
772
} else {
779
773
if (library != null ) {
780
- if (element case PropertyInducingElement (: var getter, : var setter)) {
781
- var getterElement =
782
- getter == null ? null : getModelFor (getter, library) as Accessor ;
783
- var setterElement =
784
- setter == null ? null : getModelFor (setter, library) as Accessor ;
785
- canonicalModelElement = getModelForPropertyInducingElement (
774
+ if (element case PropertyInducingElement2 (: var getter2, : var setter2)) {
775
+ var getterElement = getter2 == null
776
+ ? null
777
+ : getModelFor2 (getter2, library) as Accessor ;
778
+ var setterElement = setter2 == null
779
+ ? null
780
+ : getModelFor2 (setter2, library) as Accessor ;
781
+ canonicalModelElement = getModelForPropertyInducingElement2 (
786
782
element, library,
787
783
getter: getterElement, setter: setterElement);
788
784
} else {
789
- canonicalModelElement = getModelFor (element, library);
785
+ canonicalModelElement = getModelFor2 (element, library);
790
786
}
791
787
}
792
788
assert (canonicalModelElement is ! Inheritable );
@@ -795,7 +791,7 @@ class PackageGraph with CommentReferable, Nameable {
795
791
}
796
792
}
797
793
// Prefer fields and top-level variables.
798
- if (element is PropertyAccessorElement &&
794
+ if (element is PropertyAccessorElement2 &&
799
795
canonicalModelElement is Accessor ) {
800
796
canonicalModelElement = canonicalModelElement.enclosingCombo;
801
797
}
@@ -805,7 +801,7 @@ class PackageGraph with CommentReferable, Nameable {
805
801
ModelElement ? _findCanonicalModelElementForAmbiguous (
806
802
ModelElement modelElement, Library ? lib,
807
803
{InheritingContainer ? preferredClass}) {
808
- var element = modelElement.element ;
804
+ var element = modelElement.element2 ;
809
805
var candidates = < ModelElement > {};
810
806
if (lib != null ) {
811
807
var constructedWithKey = allConstructedModelElements[
@@ -830,7 +826,7 @@ class PackageGraph with CommentReferable, Nameable {
830
826
findCanonicalModelElementFor (modelElement.enclosingElement);
831
827
if (canonicalClass is InheritingContainer ) {
832
828
candidates.addAll (canonicalClass.allCanonicalModelElements
833
- .where ((m) => m.element == element));
829
+ .where ((m) => m.element2 == element));
834
830
}
835
831
836
832
var matches = {...candidates.where ((me) => me.isCanonical)};
@@ -879,9 +875,9 @@ class PackageGraph with CommentReferable, Nameable {
879
875
/// This is used when we might need a Library object that isn't actually
880
876
/// a documentation entry point (for elements that have no Library within the
881
877
/// set of canonical Libraries).
882
- Library ? findButDoNotCreateLibraryFor (Element e) {
878
+ Library ? findButDoNotCreateLibraryFor (Element2 e) {
883
879
// This is just a cache to avoid creating lots of libraries over and over.
884
- return _allLibraries[e.library ? .source.fullName];
880
+ return _allLibraries[e.library2 ? .firstFragment .source.fullName];
885
881
}
886
882
887
883
/// Gathers all of the model elements found in all of the libraries of all
@@ -1022,7 +1018,7 @@ class PackageGraph with CommentReferable, Nameable {
1022
1018
}
1023
1019
1024
1020
class ConstructedModelElementsKey {
1025
- final Element element;
1021
+ final Element2 element;
1026
1022
final Container ? enclosingElement;
1027
1023
1028
1024
ConstructedModelElementsKey (this .element, this .enclosingElement);
@@ -1039,7 +1035,7 @@ class ConstructedModelElementsKey {
1039
1035
}
1040
1036
1041
1037
class InheritableElementsKey {
1042
- final Element element;
1038
+ final Element2 element;
1043
1039
final Library library;
1044
1040
1045
1041
InheritableElementsKey (this .element, this .library);
0 commit comments