Skip to content

Commit f7c4bcf

Browse files
bwilkersonCommit Queue
authored andcommitted
Implement LibraryElement2 and LibraryFragment
This adds documentation comments for the related classes. I also had to rename several members in order to avoid collisions. I believe that we are now at a point where we could update the tests to print the library and library fragments (but none of their children), but I have not included those changes at this point. I'm happy to add those changes after you've reviewed what's already here, either in this CL or in a follow-on CL. Please let me know whether you have a preference. Change-Id: I135e9b998865ac5413ada57f9233dd6d634652d1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/377621 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent fc4caff commit f7c4bcf

File tree

2 files changed

+350
-10
lines changed

2 files changed

+350
-10
lines changed

pkg/analyzer/lib/dart/element/element2.dart

Lines changed: 140 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,50 @@ abstract class FormalParameterElement
396396
abstract class FormalParameterFragment
397397
implements PromotableFragment, _Annotatable {}
398398

399+
/// A fragment that wholly or partially defines an element.
400+
///
401+
/// When an element is defined by one or more fragments, those fragments form an
402+
/// augmentation chain. This is represented in the element model as a
403+
/// doubly-linked list.
404+
///
405+
/// In valid code the first fragment is the base declaration and all of the
406+
/// other fragments are augmentations. This can be violated in the element model
407+
/// in the case of invalid code, such as when an augmentation is declared even
408+
/// though there is no base declaration.
399409
abstract class Fragment {
400-
List<Fragment> get children;
410+
/// The children of this fragment.
411+
///
412+
/// There is no guarantee of the order in which the children will be returned.
413+
/// For example, they are not guaranteed to be in lexical order.
414+
List<Fragment> get children3;
401415

416+
/// The element composed from this fragment and possibly other fragments.
402417
Element2 get element;
403418

419+
/// The fragment that either physically or logically encloses this fragment.
420+
///
421+
/// Returns `null` if this fragment is the root fragment of a library because
422+
/// there are no fragments above the root fragment of a library.
404423
Fragment? get enclosingFragment;
405424

425+
/// The library fragment that contains this fragment.
426+
///
427+
/// This will be the fragment itself if it is a library fragment.
406428
LibraryFragment get libraryFragment;
407429

430+
/// The offset of the name in this fragment.
431+
///
432+
/// Returns `null` if the fragment has no name.
408433
int? get nameOffset;
409434

435+
/// The next fragment in the augmentation chain.
436+
///
437+
/// Returns `null` if this is the last fragment in the chain.
410438
Fragment? get nextFragment;
411439

440+
/// The previous fragment in the augmentation chain.
441+
///
442+
/// Returns `null` if this is the first fragment in the chain.
412443
Fragment? get previousFragment;
413444
}
414445

@@ -519,56 +550,133 @@ abstract class LabelElement2 implements Element2 {
519550
LibraryElement2 get library2;
520551
}
521552

553+
/// A library.
554+
///
555+
/// Clients may not extend, implement or mix-in this class.
522556
abstract class LibraryElement2 implements Element2, _Annotatable, _Fragmented {
523-
List<ExtensionElement2> get accessibleExtensions;
557+
/// The extension elements accessible within this library.
558+
List<ExtensionElement2> get accessibleExtensions2;
524559

560+
/// The classes defined in this library.
561+
///
562+
/// There is no guarantee of the order in which the classes will be returned.
563+
/// For example, they are not guaranteed to be in lexical order.
525564
List<ClassElement2> get classes;
526565

527-
TopLevelFunctionElement? get entryPoint;
566+
/// The entry point for this library.
567+
///
568+
/// Returns `null` if this library doesn't have an entry point.
569+
///
570+
/// The entry point is defined to be a zero, one, or two argument top-level
571+
/// function whose name is `main`.
572+
TopLevelFunctionElement? get entryPoint2;
528573

574+
/// The enums defined in this library.
575+
///
576+
/// There is no guarantee of the order in which the enums will be returned.
577+
/// For example, they are not guaranteed to be in lexical order.
529578
List<EnumElement2> get enums;
530579

580+
/// The libraries that are exported from this library.
581+
///
582+
/// There is no guarantee of the order in which the libraries will be
583+
/// returned. For example, they are not guaranteed to be in lexical order.
531584
List<LibraryElement2> get exportedLibraries2;
532585

586+
/// The export [Namespace] of this library.
533587
Namespace get exportNamespace;
534588

589+
/// The extensions defined in this library.
590+
///
591+
/// There is no guarantee of the order in which the extensions will be
592+
/// returned. For example, they are not guaranteed to be in lexical order.
535593
List<ExtensionElement2> get extensions;
536594

595+
/// The extension types defined in this library.
596+
///
597+
/// There is no guarantee of the order in which the extension types will be
598+
/// returned. For example, they are not guaranteed to be in lexical order.
537599
List<ExtensionTypeElement2> get extensionTypes;
538600

601+
/// The set of features available to this library.
602+
///
603+
/// Determined by the combination of the language version for the enclosing
604+
/// package, enabled experiments, and the presence of a `// @dart` language
605+
/// version override comment at the top of the files that make up the library.
539606
FeatureSet get featureSet;
540607

608+
@override
609+
LibraryFragment get firstFragment;
610+
611+
/// The functions defined in this library.
612+
///
613+
/// There is no guarantee of the order in which the functions will be
614+
/// returned. For example, they are not guaranteed to be in lexical order.
541615
List<TopLevelFunctionElement> get functions;
542616

617+
/// The getters defined in this library.
618+
///
619+
/// There is no guarantee of the order in which the getters will be returned.
620+
/// For example, they are not guaranteed to be in lexical order.
543621
List<GetterElement> get getters;
544622

623+
/// The identifier that uniquely identifies this element among the children
624+
/// of this element's parent.
545625
String get identifier;
546626

627+
/// Whether the library is the `dart:async` library.
547628
bool get isDartAsync;
548629

630+
/// Whether the library is the `dart:core` library.
549631
bool get isDartCore;
550632

633+
/// Whether the library is part of the SDK.
551634
bool get isInSdk;
552635

636+
/// The language version for this library.
553637
LibraryLanguageVersion get languageVersion;
554638

555639
@override
556640
LibraryElement2 get library2;
557641

558-
TopLevelFunctionElement get loadLibraryFunction;
642+
/// The element representing the synthetic function `loadLibrary`.
643+
///
644+
/// Technically the function is implicitly defined for this library only if
645+
/// the library is imported using a deferred import, but the element is always
646+
/// defined for performance reasons.
647+
TopLevelFunctionElement get loadLibraryFunction2;
559648

649+
/// The mixins defined in this library.
650+
///
651+
/// There is no guarantee of the order in which the mixins will be returned.
652+
/// For example, they are not guaranteed to be in lexical order.
560653
List<MixinElement2> get mixins;
561654

655+
/// The public [Namespace] of this library.
562656
Namespace get publicNamespace;
563657

658+
/// The setters defined in this library.
659+
///
660+
/// There is no guarantee of the order in which the setters will be returned.
661+
/// For example, they are not guaranteed to be in lexical order.
564662
List<SetterElement> get setters;
565663

664+
/// The top level variables defined in this library.
665+
///
666+
/// There is no guarantee of the order in which the top level variables will
667+
/// be returned. For example, they are not guaranteed to be in lexical order.
566668
List<TopLevelVariableElement2> get topLevelVariables;
567669

670+
/// The type aliases defined in this library.
671+
///
672+
/// There is no guarantee of the order in which the type aliases will be
673+
/// returned. For example, they are not guaranteed to be in lexical order.
568674
List<TypeAliasElement2> get typeAliases;
569675

676+
/// The [TypeProvider] that is used in this library.
570677
TypeProvider get typeProvider;
571678

679+
/// The [TypeSystem] that is used in this library.
572680
TypeSystem get typeSystem;
573681
}
574682

@@ -582,37 +690,63 @@ abstract class LibraryExport {
582690
DirectiveUri get uri;
583691
}
584692

693+
/// The portion of a [LibraryElement2] coming from a single compilation unit.
585694
abstract class LibraryFragment implements Fragment, _Annotatable {
695+
/// The fragments of the classes declared in this fragment.
586696
List<ClassFragment> get classes2;
587697

698+
@override
699+
LibraryFragment? get enclosingFragment;
700+
701+
/// The fragments of the enums declared in this fragment.
588702
List<EnumFragment> get enums2;
589703

704+
/// The fragments of the extensions declared in this fragment.
590705
List<ExtensionFragment> get extensions2;
591706

707+
/// The fragments of the extension types declared in this fragment.
592708
List<ExtensionTypeFragment> get extensionTypes2;
593709

710+
/// The fragments of the top-level functions declared in this fragment.
594711
List<TopLevelFunctionFragment> get functions2;
595712

713+
/// The fragments of the top-level getters declared in this fragment.
596714
List<GetterFragment> get getters;
597715

598-
List<LibraryExport> get libraryExports;
716+
/// The libraries exported by this unit.
717+
List<LibraryExport> get libraryExports2;
599718

600-
List<LibraryImport> get libraryImports;
719+
/// The libraries imported by this unit.
720+
List<LibraryImport> get libraryImports2;
601721

722+
/// The [LineInfo] for the fragment.
602723
LineInfo get lineInfo;
603724

725+
/// The fragments of the mixins declared in this fragment.
604726
List<MixinFragment> get mixins2;
605727

728+
/// The parts included by this unit.
606729
List<PartInclude> get partIncludes;
607730

731+
/// The prefixes used by [libraryImports].
732+
///
733+
/// Each prefix can be used in more than one `import` directive.
608734
List<PrefixElement2> get prefixes;
609735

736+
/// The scope used to resolve names within the fragment.
737+
///
738+
/// It includes all of the elements that are declared in the library, and all
739+
/// of the elements imported into this fragment or parent fragments.
610740
Scope get scope;
611741

742+
/// The fragments of the top-level setters declared in this fragment.
612743
List<SetterFragment> get setters;
613744

745+
/// The fragments of the top-level variables declared in this compilation
746+
/// unit.
614747
List<TopLevelVariableFragment> get topLevelVariables2;
615748

749+
/// The fragments of the type aliases declared in this fragment.
616750
List<TypeAliasFragment> get typeAliases2;
617751
}
618752

0 commit comments

Comments
 (0)