-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathelement.dart
2655 lines (2162 loc) · 93.9 KB
/
element.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2014, 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.
// ignore_for_file: analyzer_use_new_elements
/// Defines the element model. The element model describes the semantic (as
/// opposed to syntactic) structure of Dart code. The syntactic structure of the
/// code is modeled by the [AST
/// structure](../dart_ast_ast/dart_ast_ast-library.html).
///
/// The element model consists of two closely related kinds of objects: elements
/// (instances of a subclass of [Element]) and types. This library defines the
/// elements, the types are defined in
/// [type.dart](../dart_element_type/dart_element_type-library.html).
///
/// Generally speaking, an element represents something that is declared in the
/// code, such as a class, method, or variable. Elements are organized in a tree
/// structure in which the children of an element are the elements that are
/// logically (and often syntactically) part of the declaration of the parent.
/// For example, the elements representing the methods and fields in a class are
/// children of the element representing the class.
///
/// Every complete element structure is rooted by an instance of the class
/// [LibraryElement]. A library element represents a single Dart library. Every
/// library is defined by one or more compilation units (the library and all of
/// its parts). The compilation units are represented by the class
/// [CompilationUnitElement] and are children of the library that is defined by
/// them. Each compilation unit can contain zero or more top-level declarations,
/// such as classes, functions, and variables. Each of these is in turn
/// represented as an element that is a child of the compilation unit. Classes
/// contain methods and fields, methods can contain local variables, etc.
///
/// The element model does not contain everything in the code, only those things
/// that are declared by the code. For example, it does not include any
/// representation of the statements in a method body, but if one of those
/// statements declares a local variable then the local variable will be
/// represented by an element.
library;
import 'package:_fe_analyzer_shared/src/base/analyzer_public_api.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/scope.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/dart/element/type_provider.dart';
import 'package:analyzer/dart/element/type_system.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/source/source.dart';
import 'package:analyzer/src/dart/constant/evaluation.dart';
import 'package:analyzer/src/dart/resolver/scope.dart' show Namespace;
import 'package:analyzer/src/generated/engine.dart' show AnalysisContext;
import 'package:analyzer/src/generated/utilities_dart.dart';
import 'package:analyzer/src/task/api/model.dart' show AnalysisTarget;
import 'package:meta/meta.dart';
import 'package:pub_semver/pub_semver.dart';
/// The result of applying augmentations to a [ClassElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class AugmentedClassElement implements AugmentedInterfaceElement {
@override
ClassElement get firstFragment;
}
/// The result of applying augmentations to an [EnumElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class AugmentedEnumElement implements AugmentedInterfaceElement {
/// The enum constants declared in this element.
List<FieldElement> get constants;
@override
EnumElement get firstFragment;
}
/// The result of applying augmentations to an [ExtensionElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class AugmentedExtensionElement implements AugmentedInstanceElement {
/// The type that is extended by this extension.
DartType get extendedType;
}
/// The result of applying augmentations to an [ExtensionTypeElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class AugmentedExtensionTypeElement
implements AugmentedInterfaceElement {
@override
ExtensionTypeElement get firstFragment;
/// The primary constructor of this extension.
ConstructorElement get primaryConstructor;
/// The representation of this extension.
FieldElement get representation;
/// The extension type erasure, obtained by recursively replacing every
/// subterm which is an extension type by the corresponding representation
/// type.
DartType get typeErasure;
}
/// The result of applying augmentations to a [InstanceElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class AugmentedInstanceElement {
/// The accessors (getters and setters) declared in this element.
///
/// [PropertyAccessorElement]s replace corresponding elements,
/// other [PropertyAccessorElement]s are appended.
List<PropertyAccessorElement> get accessors;
/// The fields declared in this element.
///
/// `FieldAugmentationElement`s replace corresponding elements, other
/// [FieldElement]s are appended.
List<FieldElement> get fields;
/// The declaration (not augmentation) that owns this result.
InstanceElement get firstFragment;
/// The metadata associated with this element.
///
/// This is a union of annotations associated with the class declaration and
/// all its augmentations.
List<ElementAnnotation> get metadata;
/// The methods declared in this element.
///
/// `MethodAugmentationElement`s replace corresponding elements, other
/// [MethodElement]s are appended.
List<MethodElement> get methods;
/// The type of `this` expression.
DartType get thisType;
/// Returns the field from [fields] that has the given [name].
FieldElement? getField(String name);
/// Returns the getter from [accessors] that has the given [name].
PropertyAccessorElement? getGetter(String name);
/// Returns the method from [methods] that has the given [name].
MethodElement? getMethod(String name);
/// Returns the setter from [accessors] that has the given [name].
PropertyAccessorElement? getSetter(String name);
/// Returns the element representing the getter that results from looking up
/// the given [name] in this class with respect to the given [library],
/// or `null` if the look up fails.
///
/// The behavior of this method is defined by the Dart Language Specification
/// in section 17.18 Lookup.
PropertyAccessorElement? lookUpGetter({
required String name,
required LibraryElement library,
});
/// Returns the element representing the method that results from looking up
/// the given [name] in this class with respect to the given [library],
/// or `null` if the look up fails.
///
/// The behavior of this method is defined by the Dart Language Specification
/// in section 17.18 Lookup.
MethodElement? lookUpMethod({
required String name,
required LibraryElement library,
});
/// Returns the element representing the setter that results from looking up
/// the given [name] in this class with respect to the given [library],
/// or `null` if the look up fails.
///
/// The behavior of this method is defined by the Dart Language Specification
/// in section 17.18 Lookup.
PropertyAccessorElement? lookUpSetter({
required String name,
required LibraryElement library,
});
}
/// The result of applying augmentations to a [InterfaceElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class AugmentedInterfaceElement implements AugmentedInstanceElement {
/// The constructors declared in this element.
///
/// `ConstructorAugmentationElement`s replace corresponding elements,
/// other [ConstructorElement]s are appended.
List<ConstructorElement> get constructors;
@override
InterfaceElement get firstFragment;
/// The interfaces implemented by this element.
///
/// This is a union of interfaces declared by the class declaration and
/// all its augmentations.
List<InterfaceType> get interfaces;
/// The mixins applied by this class or in its augmentations.
///
/// This is a union of mixins applied by the class declaration and all its
/// augmentations.
List<InterfaceType> get mixins;
@override
InterfaceType get thisType;
/// The unnamed constructor from [constructors].
ConstructorElement? get unnamedConstructor;
/// Returns the constructor from [constructors] that has the given [name].
ConstructorElement? getNamedConstructor(String name);
}
/// The result of applying augmentations to a [MixinElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class AugmentedMixinElement extends AugmentedInterfaceElement {
/// The superclass constraints of this element.
///
/// This is a union of constraints declared by the class declaration and
/// all its augmentations.
List<InterfaceType> get superclassConstraints;
}
/// A pattern variable that is explicitly declared.
///
/// Clients may not extend, implement or mix-in this class.
abstract class BindPatternVariableElement implements PatternVariableElement {}
/// An element that represents a class or a mixin. The class can be defined by
/// either a class declaration (with a class body), a mixin application (without
/// a class body), a mixin declaration, or an enum declaration.
///
/// Clients may not extend, implement or mix-in this class.
abstract class ClassElement implements InterfaceElement {
@experimental
@override
ClassElement? get augmentation;
@experimental
@override
ClassElement? get augmentationTarget;
@experimental
@override
AugmentedClassElement get augmented;
/// Whether the class or its superclass declares a non-final instance field.
bool get hasNonFinalField;
/// Whether the class is abstract. A class is abstract if it has an
/// explicit `abstract` modifier. Note, that this definition of
/// <i>abstract</i> is different from <i>has unimplemented members</i>.
bool get isAbstract;
/// Whether this class is a base class.
///
/// A class is a base class if it has an explicit `base` modifier, or the
/// class has a `base` induced modifier and [isSealed] is `true` as well.
/// The base modifier allows the class to be extended but not implemented.
bool get isBase;
/// Whether the class can be instantiated.
bool get isConstructable;
/// Whether the class represents the class 'Enum' defined in `dart:core`.
bool get isDartCoreEnum;
/// Whether the class represents the class 'Object' defined in `dart:core`.
bool get isDartCoreObject;
/// Whether the class has the property where, in a switch, if you cover all
/// of the subtypes of this element, then the compiler knows that you have
/// covered all possible instances of the type.
bool get isExhaustive;
/// Whether the class is a final class.
///
/// A class is a final class if it has an explicit `final` modifier, or the
/// class has a `final` induced modifier and [isSealed] is `true` as well.
/// The final modifier prohibits this class from being extended, implemented,
/// or mixed in.
bool get isFinal;
/// Whether the class is an interface class.
///
/// A class is an interface class if it has an explicit `interface` modifier,
/// or the class has an `interface` induced modifier and [isSealed] is `true`
/// as well. The interface modifier allows the class to be implemented, but
/// not extended or mixed in.
bool get isInterface;
/// Whether the class is a mixin application.
///
/// A class is a mixin application if it was declared using the syntax
/// `class A = B with C;`.
bool get isMixinApplication;
/// Whether the class is a mixin class.
///
/// A class is a mixin class if it has an explicit `mixin` modifier.
bool get isMixinClass;
/// Whether the class is a sealed class.
///
/// A class is a sealed class if it has an explicit `sealed` modifier.
bool get isSealed;
/// Whether the class can validly be used as a mixin when defining
/// another class.
///
/// For classes defined by a class declaration or a mixin application, the
/// behavior of this method is defined by the Dart Language Specification
/// in section 9:
/// <blockquote>
/// It is a compile-time error if a declared or derived mixin refers to super.
/// It is a compile-time error if a declared or derived mixin explicitly
/// declares a constructor. It is a compile-time error if a mixin is derived
/// from a class whose superclass is not Object.
/// </blockquote>
bool get isValidMixin;
/// Whether the class, assuming that it is within scope, is extendable to
/// classes in the given [library].
bool isExtendableIn(LibraryElement library);
/// Whether the class, assuming that it is within scope, is
/// implementable to classes, mixins, and enums in the given [library].
bool isImplementableIn(LibraryElement library);
/// Whether the class, assuming that it is within scope, is able to be
/// mixed-in by classes and enums in the given [library].
bool isMixableIn(LibraryElement library);
}
/// An element that is contained within a [ClassElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class ClassMemberElement implements Element {
// TODO(brianwilkerson): Either remove this class or rename it to something
// more correct.
@override
Element get enclosingElement3;
/// Whether the element is a static element.
///
/// A static element is an element that is not associated with a particular
/// instance, but rather with an entire library or class.
bool get isStatic;
}
/// An element representing a compilation unit.
///
/// Clients may not extend, implement or mix-in this class.
abstract class CompilationUnitElement implements UriReferencedElement {
/// The extension elements accessible within this unit.
List<ExtensionElement> get accessibleExtensions;
/// The top-level accessors (getters and setters) declared in this
/// compilation unit.
List<PropertyAccessorElement> get accessors;
/// The classes declared in this compilation unit.
List<ClassElement> get classes;
/// The [CompilationUnitElement] that uses `part` directive to include this
/// element, or `null` if this element is the defining unit of the library.
@override
CompilationUnitElement? get enclosingElement3;
/// The enums declared in this compilation unit.
List<EnumElement> get enums;
/// The extensions declared in this compilation unit.
List<ExtensionElement> get extensions;
/// The extension types declared in this compilation unit.
@experimental
List<ExtensionTypeElement> get extensionTypes;
/// The top-level functions declared in this compilation unit.
List<FunctionElement> get functions;
/// The libraries exported by this unit.
List<LibraryExportElement> get libraryExports;
/// The prefixes used by [libraryImports].
///
/// Each prefix can be used in more than one `import` directive.
List<PrefixElement> get libraryImportPrefixes;
/// The libraries imported by this unit.
List<LibraryImportElement> get libraryImports;
/// The [LineInfo] for the [source].
LineInfo get lineInfo;
/// The mixins declared in this compilation unit.
List<MixinElement> get mixins;
/// The parts included by this unit.
List<PartElement> get parts;
/// The scope used to resolve names within this compilation unit.
///
/// It includes all of the elements that are declared in the library, and all
/// of the elements imported into this unit or parent units.
Scope get scope;
@override
AnalysisSession get session;
/// The top-level variables declared in this compilation unit.
List<TopLevelVariableElement> get topLevelVariables;
/// The type aliases declared in this compilation unit.
List<TypeAliasElement> get typeAliases;
/// Returns the class defined in this compilation unit that has the given
/// [name], or `null` if this compilation unit does not define a class with
/// the given name.
ClassElement? getClass(String name);
/// Returns the enum defined in this compilation unit that has the given
/// [name], or `null` if this compilation unit does not define an enum with
/// the given name.
EnumElement? getEnum(String name);
}
/// An element representing a constructor or a factory method defined within a
/// class.
///
/// Clients may not extend, implement or mix-in this class.
abstract class ConstructorElement
implements ClassMemberElement, ExecutableElement, ConstantEvaluationTarget {
@experimental
@override
ConstructorElement? get augmentation;
@experimental
@override
ConstructorElement? get augmentationTarget;
@override
ConstructorElement get declaration;
@override
String get displayName;
@override
InterfaceElement get enclosingElement3;
/// Whether the constructor is a const constructor.
bool get isConst;
/// Whether the constructor can be used as a default constructor - unnamed,
/// and has no required parameters.
bool get isDefaultConstructor;
/// Whether the constructor represents a factory constructor.
bool get isFactory;
/// Whether the constructor represents a generative constructor.
bool get isGenerative;
@override
String get name;
/// The offset of the character immediately following the last character of
/// this constructor's name, or `null` if not named.
///
// TODO(migration): encapsulate [nameEnd] and [periodOffset]?
int? get nameEnd;
/// The offset of the `.` before this constructor name, or `null` if not
/// named.
int? get periodOffset;
/// The constructor to which this constructor is redirecting, or `null` if
/// this constructor does not redirect to another constructor or if the
/// library containing this constructor has not yet been resolved.
ConstructorElement? get redirectedConstructor;
@override
InterfaceType get returnType;
/// The constructor of the superclass that this constructor invokes, or
/// `null` if this constructor redirects to another constructor, or if the
/// library containing this constructor has not yet been resolved.
ConstructorElement? get superConstructor;
}
/// [ImportElementPrefix] that is used together with `deferred`.
///
/// Clients may not extend, implement or mix-in this class.
abstract class DeferredImportElementPrefix implements ImportElementPrefix {}
/// Meaning of a URI referenced in a directive.
///
/// Clients may not extend, implement or mix-in this class.
abstract class DirectiveUri {}
/// [DirectiveUriWithSource] that references a [LibraryElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class DirectiveUriWithLibrary extends DirectiveUriWithSource {
/// The library referenced by the [source].
LibraryElement get library;
/// The library referenced by the [source].
LibraryElement2 get library2;
}
/// [DirectiveUriWithRelativeUriString] that can be parsed into a relative URI.
///
/// Clients may not extend, implement or mix-in this class.
abstract class DirectiveUriWithRelativeUri
extends DirectiveUriWithRelativeUriString {
/// The relative URI, parsed from [relativeUriString].
Uri get relativeUri;
}
/// [DirectiveUri] for which we can get its relative URI string.
///
/// Clients may not extend, implement or mix-in this class.
abstract class DirectiveUriWithRelativeUriString extends DirectiveUri {
/// The relative URI string specified in code.
String get relativeUriString;
}
/// [DirectiveUriWithRelativeUri] that resolves to a [Source].
///
/// Clients may not extend, implement or mix-in this class.
abstract class DirectiveUriWithSource extends DirectiveUriWithRelativeUri {
/// The result of resolving [relativeUri] against the enclosing URI.
Source get source;
}
/// [DirectiveUriWithSource] that references a [CompilationUnitElement].
///
/// Clients may not extend, implement or mix-in this class.
abstract class DirectiveUriWithUnit extends DirectiveUriWithSource {
/// The library fragment referenced by the [source].
@experimental
LibraryFragment get libraryFragment;
/// The unit referenced by the [source].
CompilationUnitElement get unit;
}
/// The base class for all of the elements in the element model. Generally
/// speaking, the element model is a semantic model of the program that
/// represents things that are declared with a name and hence can be referenced
/// elsewhere in the code.
///
/// There are two exceptions to the general case. First, there are elements in
/// the element model that are created for the convenience of various kinds of
/// analysis but that do not have any corresponding declaration within the
/// source code. Such elements are marked as being <i>synthetic</i>. Examples of
/// synthetic elements include
/// * default constructors in classes that do not define any explicit
/// constructors,
/// * getters and setters that are induced by explicit field declarations,
/// * fields that are induced by explicit declarations of getters and setters,
/// and
/// * functions representing the initialization expression for a variable.
///
/// Second, there are elements in the element model that do not have a name.
/// These correspond to unnamed functions and exist in order to more accurately
/// represent the semantic structure of the program.
///
/// Clients may not extend, implement or mix-in this class.
abstract class Element implements AnalysisTarget {
/// A list of this element's children.
///
/// There is no guarantee of the order in which the children will be included.
List<Element> get children;
/// The analysis context in which this element is defined.
AnalysisContext get context;
/// The declaration of this element.
///
/// If the element is a view on an element, e.g. a method from an interface
/// type, with substituted type parameters, return the corresponding element
/// from the class, without any substitutions. If this element is already a
/// declaration (or a synthetic element, e.g. a synthetic property accessor),
/// return itself.
Element? get declaration;
/// The display name of this element, possibly the empty string if the
/// element does not have a name.
///
/// In most cases the name and the display name are the same. Differences
/// though are cases such as setters where the name of some setter `set f(x)`
/// is `f=`, instead of `f`.
String get displayName;
/// The content of the documentation comment (including delimiters) for this
/// element, or `null` if this element does not or cannot have documentation.
String? get documentationComment;
/// The element that either physically or logically encloses this element.
///
/// For [LibraryElement] returns `null`, because libraries are the top-level
/// elements in the model.
///
/// For [CompilationUnitElement] returns the [CompilationUnitElement] that
/// uses `part` directive to include this element, or `null` if this element
/// is the defining unit of the library.
Element? get enclosingElement3;
/// Whether the element has an annotation of the form `@alwaysThrows`.
bool get hasAlwaysThrows;
/// Whether the element has an annotation of the form `@deprecated`
/// or `@Deprecated('..')`.
bool get hasDeprecated;
/// Whether the element has an annotation of the form `@doNotStore`.
bool get hasDoNotStore;
/// Whether the element has an annotation of the form `@doNotSubmit`.
bool get hasDoNotSubmit;
/// Whether the element has an annotation of the form `@factory`.
bool get hasFactory;
/// Whether the element has an annotation of the form `@immutable`.
bool get hasImmutable;
/// Whether the element has an annotation of the form `@internal`.
bool get hasInternal;
/// Whether the element has an annotation of the form `@isTest`.
bool get hasIsTest;
/// Whether the element has an annotation of the form `@isTestGroup`.
bool get hasIsTestGroup;
/// Whether the element has an annotation of the form `@JS(..)`.
bool get hasJS;
/// Whether the element has an annotation of the form `@literal`.
bool get hasLiteral;
/// Whether the element has an annotation of the form `@mustBeConst`.
bool get hasMustBeConst;
/// Whether the element has an annotation of the form `@mustBeOverridden`.
bool get hasMustBeOverridden;
/// Whether the element has an annotation of the form `@mustCallSuper`.
bool get hasMustCallSuper;
/// Whether the element has an annotation of the form `@nonVirtual`.
bool get hasNonVirtual;
/// Whether the element has an annotation of the form `@optionalTypeArgs`.
bool get hasOptionalTypeArgs;
/// Whether the element has an annotation of the form `@override`.
bool get hasOverride;
/// Whether the element has an annotation of the form `@protected`.
bool get hasProtected;
/// Whether the element has an annotation of the form `@redeclare`.
bool get hasRedeclare;
/// Whether the element has an annotation of the form `@reopen`.
bool get hasReopen;
/// Whether the element has an annotation of the form `@required`.
bool get hasRequired;
/// Whether the element has an annotation of the form `@sealed`.
bool get hasSealed;
/// Whether the element has an annotation of the form `@useResult`
/// or `@UseResult('..')`.
bool get hasUseResult;
/// Whether the element has an annotation of the form `@visibleForOverriding`.
bool get hasVisibleForOverriding;
/// Whether the element has an annotation of the form `@visibleForTemplate`.
bool get hasVisibleForTemplate;
/// Whether the element has an annotation of the form `@visibleForTesting`.
bool get hasVisibleForTesting;
/// Whether the element has an annotation of the form
/// `@visibleOutsideTemplate`.
bool get hasVisibleOutsideTemplate;
/// The unique integer identifier of this element.
int get id;
/// Whether the element is private.
///
/// Private elements are visible only within the library in which they are
/// declared.
bool get isPrivate;
/// Whether the element is public.
///
/// Public elements are visible within any library that imports the library
/// in which they are declared.
bool get isPublic;
/// Whether the element is synthetic.
///
/// A synthetic element is an element that is not represented in the source
/// code explicitly, but is implied by the source code, such as the default
/// constructor for a class that does not explicitly define any constructors.
bool get isSynthetic;
/// The kind of element that this is.
ElementKind get kind;
/// Library that contains this element.
///
/// This will be the element itself if it is a library element. This will be
/// `null` if this element is [MultiplyDefinedElement] that is not contained
/// in a library.
LibraryElement? get library;
/// The location of this element in the element model.
///
/// The object can be used to locate this element at a later time.
ElementLocation? get location;
/// All of the metadata associated with this element.
///
/// The array will be empty if the element does not have any metadata or if
/// the library containing this element has not yet been resolved.
List<ElementAnnotation> get metadata;
/// The name of this element, or `null` if this element does not have a name.
String? get name;
/// The length of the name of this element in the file that contains the
/// declaration of this element, or `0` if this element does not have a name.
int get nameLength;
/// The offset of the name of this element in the file that contains the
/// declaration of this element, or `-1` if this element is synthetic, does
/// not have a name, or otherwise does not have an offset.
int get nameOffset;
/// The non-synthetic element that caused this element to be created.
///
/// If this element is not synthetic, then the element itself is returned.
///
/// If this element is synthetic, then the corresponding non-synthetic
/// element is returned. For example, for a synthetic getter of a
/// non-synthetic field the field is returned; for a synthetic constructor
/// the enclosing class is returned.
Element get nonSynthetic;
/// The analysis session in which this element is defined.
AnalysisSession? get session;
/// The version where this SDK API was added.
///
/// A `@Since()` annotation can be applied to a library declaration,
/// any public declaration in a library, or in a class, or to an optional
/// parameter, etc.
///
/// The returned version is "effective", so that if a library is annotated
/// then all elements of the library inherit it; or if a class is annotated
/// then all members and constructors of the class inherit it.
///
/// If multiple `@Since()` annotations apply to the same element, the latest
/// version takes precedence.
///
/// Returns `null` if the element is not declared in SDK, or does not have
/// a `@Since()` annotation applicable to it.
Version? get sinceSdkVersion;
@override
Source? get source;
/// Uses the given [visitor] to visit this element.
///
/// Returns the value returned by the visitor as a result of visiting this
/// element.
T? accept<T>(ElementVisitor<T> visitor);
/// Returns the presentation of this element as it should appear when
/// presented to users.
///
/// If [withNullability] is `true`, then [NullabilitySuffix.question] and
/// [NullabilitySuffix.star] in types will be represented as `?` and `*`.
/// [NullabilitySuffix.none] does not have any explicit presentation.
///
/// If [withNullability] is `false`, nullability suffixes will not be
/// included into the presentation.
///
/// If [multiline] is `true`, the string may be wrapped over multiple lines
/// with newlines to improve formatting. For example function signatures may
/// be formatted as if they had trailing commas.
///
/// Clients should not depend on the content of the returned value as it will
/// be changed if doing so would improve the UX.
String getDisplayString({
@Deprecated('Only non-nullable by default mode is supported')
bool withNullability = true,
bool multiline = false,
});
/// Returns a display name for the given element that includes the path to the
/// compilation unit in which the type is defined. If [shortName] is `null`
/// then [displayName] will be used as the name of this element. Otherwise
/// the provided name will be used.
// TODO(brianwilkerson): Make the parameter optional.
String getExtendedDisplayName(String? shortName);
/// Whether the element, assuming that it is within scope, is accessible to
/// code in the given [library].
///
/// This is defined by the Dart Language Specification in section 6.2:
/// <blockquote>
/// A declaration <i>m</i> is accessible to a library <i>L</i> if <i>m</i> is
/// declared in <i>L</i> or if <i>m</i> is public.
/// </blockquote>
bool isAccessibleIn(LibraryElement library);
/// Returns either this element or the most immediate ancestor of this element
/// for which the [predicate] returns `true`, or `null` if there is no such
/// element.
E? thisOrAncestorMatching<E extends Element>(
bool Function(Element) predicate,
);
/// Returns either this element or the most immediate ancestor of this element
/// for which the [predicate] returns `true`, or `null` if there is no such
/// element.
E? thisOrAncestorMatching3<E extends Element>(
bool Function(Element) predicate,
);
/// Returns either this element or the most immediate ancestor of this element
/// that has the given type, or `null` if there is no such element.
E? thisOrAncestorOfType<E extends Element>();
/// Returns either this element or the most immediate ancestor of this element
/// that has the given type, or `null` if there is no such element.
E? thisOrAncestorOfType3<E extends Element>();
/// Uses the given [visitor] to visit all of the children of this element.
/// There is no guarantee of the order in which the children will be visited.
void visitChildren(ElementVisitor visitor);
}
/// A single annotation associated with an element.
///
/// Clients may not extend, implement or mix-in this class.
abstract class ElementAnnotation implements ConstantEvaluationTarget {
/// The errors that were produced while computing a value for this
/// annotation, or `null` if no value has been computed.
///
/// If a value has been produced but no errors were generated, then the
/// list will be empty.
List<AnalysisError>? get constantEvaluationErrors;
/// Returns the element referenced by this annotation.
///
/// In valid code this element can be a [PropertyAccessorElement] getter
/// of a constant top-level variable, or a constant static field of a
/// class; or a constant [ConstructorElement].
///
/// In invalid code this element can be `null`, or a reference to any
/// other element.
Element? get element;
/// Returns the element referenced by this annotation.
///
/// In valid code this element can be a [GetterElement] of a constant
/// top-level variable, or a constant static field of a class; or a
/// constant [ConstructorElement].
///
/// In invalid code this element can be `null`, or a reference to any
/// other element.
Element2? get element2;
/// Whether the annotation marks the associated function as always throwing.
bool get isAlwaysThrows;
/// Whether the annotation marks the associated element as being deprecated.
bool get isDeprecated;
/// Whether the annotation marks the associated element as not to be stored.
bool get isDoNotStore;
/// Whether the annotation marks the associated member as not to be used.
bool get isDoNotSubmit;
/// Whether the annotation marks the associated member as a factory.
bool get isFactory;
/// Whether the annotation marks the associated class and its subclasses as
/// being immutable.
bool get isImmutable;
/// Whether the annotation marks the associated element as being internal to
/// its package.
bool get isInternal;
/// Whether the annotation marks the associated member as running a single
/// test.
bool get isIsTest;
/// Whether the annotation marks the associated member as running a test
/// group.
bool get isIsTestGroup;
/// Whether the annotation marks the associated element with the `JS`
/// annotation.
bool get isJS;
/// Whether the annotation marks the associated constructor as being literal.
bool get isLiteral;
/// Whether the annotation marks the associated returned element as
/// requiring a constant argument.
bool get isMustBeConst;
/// Whether the annotation marks the associated member as requiring
/// subclasses to override this member.
bool get isMustBeOverridden;
/// Whether the annotation marks the associated member as requiring
/// overriding methods to call super.
bool get isMustCallSuper;
/// Whether the annotation marks the associated member as being non-virtual.
bool get isNonVirtual;
/// Whether the annotation marks the associated type as having "optional"
/// type arguments.
bool get isOptionalTypeArgs;
/// Whether the annotation marks the associated method as being expected to
/// override an inherited method.
bool get isOverride;
/// Whether the annotation marks the associated member as being protected.
bool get isProtected;
/// Whether the annotation marks the associated class as implementing a proxy
/// object.
bool get isProxy;
/// Whether the annotation marks the associated member as redeclaring.
bool get isRedeclare;
/// Whether the annotation marks the associated member as being reopened.
bool get isReopen;
/// Whether the annotation marks the associated member as being required.
bool get isRequired;
/// Whether the annotation marks the associated class as being sealed.
bool get isSealed;
/// Whether the annotation marks the associated class as being intended to
/// be used as an annotation.
bool get isTarget;
/// Whether the annotation marks the associated returned element as
/// requiring use.
bool get isUseResult;
/// Whether the annotation marks the associated member as being visible for
/// overriding only.
bool get isVisibleForOverriding;
/// Whether the annotation marks the associated member as being visible for
/// template files.
bool get isVisibleForTemplate;
/// Whether the annotation marks the associated member as being visible for
/// testing.
bool get isVisibleForTesting;
/// Whether the annotation marks the associated member as being visible
/// outside of template files.