@@ -29,7 +29,6 @@ import 'package:analyzer/src/dart/constant/value.dart';
29
29
import 'package:analyzer/src/dart/element/display_string_builder.dart' ;
30
30
import 'package:analyzer/src/dart/element/field_name_non_promotability_info.dart' ;
31
31
import 'package:analyzer/src/dart/element/inheritance_manager3.dart' ;
32
- import 'package:analyzer/src/dart/element/member.dart' ;
33
32
import 'package:analyzer/src/dart/element/name_union.dart' ;
34
33
import 'package:analyzer/src/dart/element/scope.dart' ;
35
34
import 'package:analyzer/src/dart/element/since_sdk_version.dart' ;
@@ -1084,7 +1083,7 @@ class ConstructorFragmentImpl extends ExecutableFragmentImpl
1084
1083
}
1085
1084
1086
1085
@override
1087
- int get offset => isSynthetic ? enclosingElement3.offset : _nameOffset ;
1086
+ int get offset => isSynthetic ? enclosingElement3.offset : nameOffset ;
1088
1087
1089
1088
@override
1090
1089
InterfaceTypeImpl get returnType {
@@ -2305,7 +2304,7 @@ abstract class ExecutableFragmentImpl extends _ExistingFragmentImpl
2305
2304
}
2306
2305
2307
2306
@override
2308
- int get offset => _nameOffset ;
2307
+ int get offset => nameOffset ;
2309
2308
2310
2309
/// The formal parameters defined by this executable fragment.
2311
2310
List <FormalParameterFragmentImpl > get parameters {
@@ -2940,7 +2939,7 @@ class FieldFragmentImpl extends PropertyInducingFragmentImpl
2940
2939
super .nextFragment as FieldFragmentImpl ? ;
2941
2940
2942
2941
@override
2943
- int get offset => isSynthetic ? enclosingFragment.offset : _nameOffset ;
2942
+ int get offset => isSynthetic ? enclosingFragment.offset : nameOffset ;
2944
2943
2945
2944
@override
2946
2945
FieldFragmentImpl ? get previousFragment =>
@@ -3580,10 +3579,10 @@ mixin FragmentedTypeParameterizedElementMixin<
3580
3579
}
3581
3580
}
3582
3581
3583
- abstract class FragmentImpl implements FragmentOrMember {
3582
+ abstract class FragmentImpl implements Fragment {
3584
3583
static int _NEXT_ID = 0 ;
3585
3584
3586
- @override
3585
+ /// The unique integer identifier of this fragment.
3587
3586
final int id = _NEXT_ID ++ ;
3588
3587
3589
3588
/// The element that either physically or logically encloses this element.
@@ -3597,14 +3596,16 @@ abstract class FragmentImpl implements FragmentOrMember {
3597
3596
FragmentImpl ? enclosingElement3;
3598
3597
3599
3598
/// The offset of the name of this element in the file that contains the
3600
- /// declaration of this element.
3601
- int _nameOffset = 0 ;
3599
+ /// declaration of this element, or `-1` if this element is synthetic, does
3600
+ /// not have a name, or otherwise does not have an offset.
3601
+ int nameOffset = 0 ;
3602
3602
3603
3603
/// The modifiers associated with this element.
3604
3604
EnumSet <Modifier > _modifiers = EnumSet .empty ();
3605
3605
3606
- /// The documentation comment for this element.
3607
- String ? _docComment;
3606
+ /// The content of the documentation comment (including delimiters) for this
3607
+ /// element, or `null` if this element does not or cannot have documentation.
3608
+ String ? documentationComment;
3608
3609
3609
3610
/// The offset of the beginning of the element's code in the file that
3610
3611
/// contains the element, or `null` if the element is synthetic.
@@ -3615,7 +3616,7 @@ abstract class FragmentImpl implements FragmentOrMember {
3615
3616
3616
3617
/// Initialize a newly created element to have the given [name] at the given
3617
3618
/// [_nameOffset] .
3618
- FragmentImpl ({required int nameOffset}) : _nameOffset = nameOffset ;
3619
+ FragmentImpl ({required this . nameOffset});
3619
3620
3620
3621
/// The length of the element's code, or `null` if the element is synthetic.
3621
3622
int ? get codeLength => _codeLength;
@@ -3624,25 +3625,28 @@ abstract class FragmentImpl implements FragmentOrMember {
3624
3625
/// contains the element, or `null` if the element is synthetic.
3625
3626
int ? get codeOffset => _codeOffset;
3626
3627
3627
- @override
3628
+ /// The analysis context in which this element is defined.
3628
3629
AnalysisContext get context {
3629
3630
return library! .context;
3630
3631
}
3631
3632
3632
- @override
3633
+ /// The declaration of this element.
3634
+ ///
3635
+ /// If the element is a view on an element, e.g. a method from an interface
3636
+ /// type, with substituted type parameters, return the corresponding element
3637
+ /// from the class, without any substitutions. If this element is already a
3638
+ /// declaration (or a synthetic element, e.g. a synthetic property accessor),
3639
+ /// return itself.
3633
3640
FragmentImpl get declaration => this ;
3634
3641
3635
- @override
3642
+ /// The display name of this element, possibly the empty string if the
3643
+ /// element does not have a name.
3644
+ ///
3645
+ /// In most cases the name and the display name are the same. Differences
3646
+ /// though are cases such as setters where the name of some setter `set f(x)`
3647
+ /// is `f=` , instead of `f` .
3636
3648
String get displayName => name2 ?? '' ;
3637
3649
3638
- @override
3639
- String ? get documentationComment => _docComment;
3640
-
3641
- /// The documentation comment source for this element.
3642
- set documentationComment (String ? doc) {
3643
- _docComment = doc;
3644
- }
3645
-
3646
3650
/// Return the enclosing unit element (which might be the same as `this` ), or
3647
3651
/// `null` if this element is not contained in any compilation unit.
3648
3652
LibraryFragmentImpl get enclosingUnit {
@@ -3653,7 +3657,10 @@ abstract class FragmentImpl implements FragmentOrMember {
3653
3657
return library! .featureSet.isEnabled (Feature .nonfunction_type_aliases);
3654
3658
}
3655
3659
3656
- @override
3660
+ /// Whether the element is private.
3661
+ ///
3662
+ /// Private elements are visible only within the library in which they are
3663
+ /// declared.
3657
3664
bool get isPrivate {
3658
3665
var name = name2;
3659
3666
if (name == null ) {
@@ -3662,10 +3669,17 @@ abstract class FragmentImpl implements FragmentOrMember {
3662
3669
return Identifier .isPrivateName (name);
3663
3670
}
3664
3671
3665
- @override
3672
+ /// Whether the element is public.
3673
+ ///
3674
+ /// Public elements are visible within any library that imports the library
3675
+ /// in which they are declared.
3666
3676
bool get isPublic => ! isPrivate;
3667
3677
3668
- @override
3678
+ /// Whether the element is synthetic.
3679
+ ///
3680
+ /// A synthetic element is an element that is not represented in the source
3681
+ /// code explicitly, but is implied by the source code, such as the default
3682
+ /// constructor for a class that does not explicitly define any constructors.
3669
3683
bool get isSynthetic {
3670
3684
return hasModifier (Modifier .SYNTHETIC );
3671
3685
}
@@ -3675,38 +3689,50 @@ abstract class FragmentImpl implements FragmentOrMember {
3675
3689
setModifier (Modifier .SYNTHETIC , isSynthetic);
3676
3690
}
3677
3691
3692
+ /// The kind of element that this is.
3693
+ // TODO(scheglov): remove it
3694
+ ElementKind get kind;
3695
+
3678
3696
LibraryElementImpl ? get library;
3679
3697
3680
- @override
3698
+ /// If this target is associated with a library, return the source of the
3699
+ /// library's defining compilation unit; otherwise return `null` .
3681
3700
Source ? get librarySource => library? .source;
3682
3701
3683
3702
String ? get lookupName {
3684
3703
return name2;
3685
3704
}
3686
3705
3687
- @override
3706
+ /// The length of the name of this element in the file that contains the
3707
+ /// declaration of this element, or `0` if this element does not have a name.
3688
3708
int get nameLength => displayName.length;
3689
3709
3690
- @override
3691
- int get nameOffset => _nameOffset;
3692
-
3693
- /// Sets the offset of the name of this element in the file that contains the
3694
- /// declaration of this element.
3695
- set nameOffset (int offset) {
3696
- _nameOffset = offset;
3697
- }
3698
-
3699
- @override
3710
+ /// The analysis session in which this element is defined.
3700
3711
AnalysisSession ? get session {
3701
3712
return enclosingElement3? .session;
3702
3713
}
3703
3714
3704
- @override
3715
+ /// The version where this SDK API was added.
3716
+ ///
3717
+ /// A `@Since()` annotation can be applied to a library declaration,
3718
+ /// any public declaration in a library, or in a class, or to an optional
3719
+ /// parameter, etc.
3720
+ ///
3721
+ /// The returned version is "effective", so that if a library is annotated
3722
+ /// then all elements of the library inherit it; or if a class is annotated
3723
+ /// then all members and constructors of the class inherit it.
3724
+ ///
3725
+ /// If multiple `@Since()` annotations apply to the same element, the latest
3726
+ /// version takes precedence.
3727
+ ///
3728
+ /// Returns `null` if the element is not declared in SDK, or does not have
3729
+ /// a `@Since()` annotation applicable to it.
3705
3730
Version ? get sinceSdkVersion {
3706
3731
return asElement2.ifTypeOrNull <HasSinceSdkVersion >()? .sinceSdkVersion;
3707
3732
}
3708
3733
3709
- @override
3734
+ /// Return the source associated with this target, or `null` if this target is
3735
+ /// not associated with a source.
3710
3736
Source ? get source {
3711
3737
return enclosingElement3? .source;
3712
3738
}
@@ -3739,7 +3765,22 @@ abstract class FragmentImpl implements FragmentOrMember {
3739
3765
}
3740
3766
}
3741
3767
3742
- @override
3768
+ /// Returns the presentation of this element as it should appear when
3769
+ /// presented to users.
3770
+ ///
3771
+ /// If [withNullability] is `true` , then [NullabilitySuffix.question] and
3772
+ /// [NullabilitySuffix.star] in types will be represented as `?` and `*` .
3773
+ /// [NullabilitySuffix.none] does not have any explicit presentation.
3774
+ ///
3775
+ /// If [withNullability] is `false` , nullability suffixes will not be
3776
+ /// included into the presentation.
3777
+ ///
3778
+ /// If [multiline] is `true` , the string may be wrapped over multiple lines
3779
+ /// with newlines to improve formatting. For example function signatures may
3780
+ /// be formatted as if they had trailing commas.
3781
+ ///
3782
+ /// Clients should not depend on the content of the returned value as it will
3783
+ /// be changed if doing so would improve the UX.
3743
3784
String getDisplayString ({
3744
3785
@Deprecated ('Only non-nullable by default mode is supported' )
3745
3786
bool withNullability = true ,
@@ -3783,118 +3824,6 @@ abstract class FragmentImpl implements FragmentOrMember {
3783
3824
}
3784
3825
}
3785
3826
3786
- /// A shared internal interface of `Element` and [Member] .
3787
- /// Used during migration to avoid referencing `Element` .
3788
- abstract class FragmentOrMember implements Fragment {
3789
- /// The analysis context in which this element is defined.
3790
- AnalysisContext get context;
3791
-
3792
- /// The declaration of this element.
3793
- ///
3794
- /// If the element is a view on an element, e.g. a method from an interface
3795
- /// type, with substituted type parameters, return the corresponding element
3796
- /// from the class, without any substitutions. If this element is already a
3797
- /// declaration (or a synthetic element, e.g. a synthetic property accessor),
3798
- /// return itself.
3799
- FragmentOrMember ? get declaration;
3800
-
3801
- /// The display name of this element, possibly the empty string if the
3802
- /// element does not have a name.
3803
- ///
3804
- /// In most cases the name and the display name are the same. Differences
3805
- /// though are cases such as setters where the name of some setter `set f(x)`
3806
- /// is `f=` , instead of `f` .
3807
- String get displayName;
3808
-
3809
- /// The content of the documentation comment (including delimiters) for this
3810
- /// element, or `null` if this element does not or cannot have documentation.
3811
- String ? get documentationComment;
3812
-
3813
- /// The unique integer identifier of this element.
3814
- int get id;
3815
-
3816
- /// Whether the element is private.
3817
- ///
3818
- /// Private elements are visible only within the library in which they are
3819
- /// declared.
3820
- bool get isPrivate;
3821
-
3822
- /// Whether the element is public.
3823
- ///
3824
- /// Public elements are visible within any library that imports the library
3825
- /// in which they are declared.
3826
- bool get isPublic;
3827
-
3828
- /// Whether the element is synthetic.
3829
- ///
3830
- /// A synthetic element is an element that is not represented in the source
3831
- /// code explicitly, but is implied by the source code, such as the default
3832
- /// constructor for a class that does not explicitly define any constructors.
3833
- bool get isSynthetic;
3834
-
3835
- /// The kind of element that this is.
3836
- ElementKind get kind;
3837
-
3838
- /// If this target is associated with a library, return the source of the
3839
- /// library's defining compilation unit; otherwise return `null` .
3840
- Source ? get librarySource;
3841
-
3842
- /// The length of the name of this element in the file that contains the
3843
- /// declaration of this element, or `0` if this element does not have a name.
3844
- int get nameLength;
3845
-
3846
- /// The offset of the name of this element in the file that contains the
3847
- /// declaration of this element, or `-1` if this element is synthetic, does
3848
- /// not have a name, or otherwise does not have an offset.
3849
- int get nameOffset;
3850
-
3851
- /// The analysis session in which this element is defined.
3852
- AnalysisSession ? get session;
3853
-
3854
- /// The version where this SDK API was added.
3855
- ///
3856
- /// A `@Since()` annotation can be applied to a library declaration,
3857
- /// any public declaration in a library, or in a class, or to an optional
3858
- /// parameter, etc.
3859
- ///
3860
- /// The returned version is "effective", so that if a library is annotated
3861
- /// then all elements of the library inherit it; or if a class is annotated
3862
- /// then all members and constructors of the class inherit it.
3863
- ///
3864
- /// If multiple `@Since()` annotations apply to the same element, the latest
3865
- /// version takes precedence.
3866
- ///
3867
- /// Returns `null` if the element is not declared in SDK, or does not have
3868
- /// a `@Since()` annotation applicable to it.
3869
- Version ? get sinceSdkVersion;
3870
-
3871
- /// Return the source associated with this target, or `null` if this target is
3872
- /// not associated with a source.
3873
- Source ? get source;
3874
-
3875
- /// Returns the presentation of this element as it should appear when
3876
- /// presented to users.
3877
- ///
3878
- /// If [withNullability] is `true` , then [NullabilitySuffix.question] and
3879
- /// [NullabilitySuffix.star] in types will be represented as `?` and `*` .
3880
- /// [NullabilitySuffix.none] does not have any explicit presentation.
3881
- ///
3882
- /// If [withNullability] is `false` , nullability suffixes will not be
3883
- /// included into the presentation.
3884
- ///
3885
- /// If [multiline] is `true` , the string may be wrapped over multiple lines
3886
- /// with newlines to improve formatting. For example function signatures may
3887
- /// be formatted as if they had trailing commas.
3888
- ///
3889
- /// Clients should not depend on the content of the returned value as it will
3890
- /// be changed if doing so would improve the UX.
3891
- String getDisplayString ({
3892
- @Deprecated ('Only non-nullable by default mode is supported' )
3893
- bool withNullability = true ,
3894
- bool multiline = false ,
3895
- });
3896
- }
3897
-
3898
3827
sealed class FunctionFragmentImpl extends ExecutableFragmentImpl
3899
3828
implements FunctionTypedFragmentImpl {
3900
3829
@override
@@ -4109,7 +4038,7 @@ class GenericFunctionTypeFragmentImpl extends _ExistingFragmentImpl
4109
4038
GenericFunctionTypeFragmentImpl ? get nextFragment => null ;
4110
4039
4111
4040
@override
4112
- int get offset => _nameOffset ;
4041
+ int get offset => nameOffset ;
4113
4042
4114
4043
@override
4115
4044
List <FormalParameterFragmentImpl > get parameters {
@@ -4855,7 +4784,7 @@ abstract class InstanceFragmentImpl extends _ExistingFragmentImpl
4855
4784
List <MethodFragment > get methods2 => methods.cast <MethodFragment >();
4856
4785
4857
4786
@override
4858
- int get offset => _nameOffset ;
4787
+ int get offset => nameOffset ;
4859
4788
4860
4789
@override
4861
4790
List <SetterFragmentImpl > get setters {
@@ -5633,7 +5562,7 @@ class LabelFragmentImpl extends FragmentImpl implements LabelFragment {
5633
5562
LabelFragmentImpl ? get nextFragment => null ;
5634
5563
5635
5564
@override
5636
- int get offset => _nameOffset ;
5565
+ int get offset => nameOffset ;
5637
5566
5638
5567
@override
5639
5568
LabelFragmentImpl ? get previousFragment => null ;
@@ -8582,7 +8511,7 @@ sealed class PropertyAccessorFragmentImpl extends ExecutableFragmentImpl
8582
8511
}
8583
8512
return variable.firstFragment.offset;
8584
8513
}
8585
- return _nameOffset ;
8514
+ return nameOffset ;
8586
8515
}
8587
8516
}
8588
8517
0 commit comments